Skip to content

Add agent quality eval foundation#177

Merged
gnanam1990 merged 3 commits into
mainfrom
feat/agent-quality-context-eval
Jun 12, 2026
Merged

Add agent quality eval foundation#177
gnanam1990 merged 3 commits into
mainfrom
feat/agent-quality-context-eval

Conversation

@Vasanthdev2004

@Vasanthdev2004 Vasanthdev2004 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • tighten Zero's core system prompt with explicit coding-agent quality rules and prompt contract coverage
  • add internal/workspaceseed, a pure deterministic workspace context seed builder for future prompt/session wiring
  • add internal/agenteval, an offline eval suite/scoring contract with sample fixture data and docs
  • add zero eval --suite <path> [--json] to validate and summarize offline eval suites

Notes

This PR does not run live model evals yet. It creates the suite/scoring contract and a CLI validation surface so future PRs can wire captured runs or headless executions without changing the JSON/report shape.

Validation

  • go test -count=1 ./internal/agenteval ./internal/cli ./internal/workspaceseed ./internal/agent
  • go run ./cmd/zero eval --suite internal/agenteval/testdata/sample_suite.json --json
  • go test ./...
  • git diff --check
  • gofmt -l internal/agent internal/agenteval internal/cli internal/workspaceseed
  • go run ./cmd/zero-release build
  • go run ./cmd/zero-release smoke

Subagent review

Used five scoped subagents for prompt, workspace seed, eval core, eval CLI, and docs/sample work, then a final reviewer pass. The final reviewer initially found two issues around overclaiming eval readiness and expectedChangedFiles validation; both were fixed and re-reviewed with no blockers.

Summary by CodeRabbit

  • New Features

    • New eval command to run offline agent evaluation suites and emit scored reports (pass/fail/blocked/error)
    • Deterministic workspace-context seeding to produce reproducible evaluations and compact workspace summaries
  • Documentation

    • Comprehensive Offline Agent Evals guide covering suite format, CLI usage, running/validating suites, and interpreting scores
    • Updated system-prompt guidance clarifying workflow, safety, and permission rules
  • Tests

    • Expanded test coverage for suite parsing/validation, scoring/reporting, CLI behavior, and workspace seeding

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 193f2c1d1da3
Changed files (12): docs/AGENT_EVALS.md, internal/agent/system_prompt.md, internal/agent/system_prompt_test.go, internal/agenteval/agenteval_test.go, internal/agenteval/score.go, internal/agenteval/suite.go, internal/agenteval/testdata/sample_suite.json, internal/cli/agent_eval.go, internal/cli/agent_eval_test.go, internal/cli/app.go, internal/workspaceseed/workspaceseed.go, internal/workspaceseed/workspaceseed_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 85633b7b-758f-4ea4-b4f7-2015f8ba7521

📥 Commits

Reviewing files that changed from the base of the PR and between 49a7f4e and 193f2c1.

📒 Files selected for processing (9)
  • docs/AGENT_EVALS.md
  • internal/agenteval/agenteval_test.go
  • internal/agenteval/score.go
  • internal/agenteval/suite.go
  • internal/cli/agent_eval.go
  • internal/cli/agent_eval_test.go
  • internal/cli/app.go
  • internal/workspaceseed/workspaceseed.go
  • internal/workspaceseed/workspaceseed_test.go
✅ Files skipped from review due to trivial changes (1)
  • docs/AGENT_EVALS.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • internal/cli/app.go
  • internal/cli/agent_eval_test.go
  • internal/cli/agent_eval.go
  • internal/agenteval/agenteval_test.go
  • internal/workspaceseed/workspaceseed_test.go
  • internal/workspaceseed/workspaceseed.go
  • internal/agenteval/suite.go
  • internal/agenteval/score.go

Walkthrough

Adds an offline agent-eval framework (suite model, loader/validator, scoring/reporting, CLI integration, and sample fixtures), updates the autonomous agent system prompt with a verification test, and introduces a deterministic workspace-seed package with rendering and tests.

Changes

Agent Eval Framework

Layer / File(s) Summary
Suite data model, loading, and validation
internal/agenteval/suite.go, internal/agenteval/testdata/sample_suite.json, internal/agenteval/agenteval_test.go
Suite, Task, Command types; LoadSuite uses DisallowUnknownFields and rejects trailing JSON; Suite.Validate() reports structural issues, enforces non-empty verificationCommands, unique IDs, and normalizes ExpectedChangedFiles (trim, backslash→slash, dedupe, sort) while rejecting absolute/colon/parent-traversal paths.
Report scoring and result aggregation
internal/agenteval/score.go, internal/agenteval/agenteval_test.go
Score(suite, input) selects task (auto-select single-task), scores verification commands and changed-files expectations, synthesizes unknown command results deterministically, and finalizes Summary and Status using blocked→error→fail→pass priority; exports report types and contract version.
Agent-eval tests and stable JSON
internal/agenteval/agenteval_test.go
Extensive tests for JSON parsing/normalization, trailing-JSON rejection, validation error messages, scoring outcomes (pass/fail/error/blocked), blocked/unknown-command handling, deterministic ordering, and exact stable JSON report serialization.

Agent eval CLI

Layer / File(s) Summary
CLI command and default runner
internal/cli/agent_eval.go, internal/cli/agent_eval_test.go
Implements zero eval parsing (--suite, --json, -h/--help), text and pretty-JSON outputs, exit-code conventions, and a default runner that loads suites and returns checks/task counts; includes CLI tests for help, missing-suite validation, JSON mode, integration-ready output, failing-suite exit behavior, and runner errors.
CLI wiring and app deps
internal/cli/app.go
Adds runAgentEval to appDeps (defaulted in defaults), wires eval into command dispatch, and updates help text to include the eval command.

Agent System Prompt Refinements

Layer / File(s) Summary
System prompt content updates
internal/agent/system_prompt.md
Reframes autonomy/persistence guidance, renames and rewrites workflow to “Workflow: plan then act” (inspect/plan/implement/verify/summarize), tightens editing/testing/tool-use guidance, and adds a “Permission and safety” section restricting destructive/external side effects without approval.
Prompt content verification
internal/agent/system_prompt_test.go
Adds TestCoreSystemPromptIncludesCodingQualityRules to assert the generated system prompt contains required coding-quality and behavior phrases (e.g., read-before-edit, inspect the target file, plan then act, narrow tool choice, edit verification, permission mode).

Workspace Context Seed Package

Layer / File(s) Summary
Seed building and rendering
internal/workspaceseed/workspaceseed.go, internal/workspaceseed/workspaceseed_test.go
Build(input) normalizes CWD and paths, derives deterministic top-level layout, selects project/memory files, formats git summary; BuildFromWorkspace scans via workspaceindex.Scan; Render(seed, options) formats labeled lines and enforces MaxLines/Width budgets with Unicode-safe clamping and ellipsis handling.
Workspace seed tests
internal/workspaceseed/workspaceseed_test.go
Tests ensure normalization and classification of paths, safe rendering without leaking absolute roots, rejection of absolute inputs without CWD, backslash normalization, MaxLines/Width clipping with ..., rune-boundary-safe truncation, BuildFromWorkspace integration, and test helpers.

Agent Evals User Documentation

Layer / File(s) Summary
Offline agent evals documentation
docs/AGENT_EVALS.md
Documents the offline agent-eval fixture system: JSON suite schema and constraints, how to run zero eval (text/JSON), example validation and go-test commands, and score semantics (pass, fail, blocked, error) with guidance to compare runs within the same suite revision.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Gitlawb/zero#129: Related to system-prompt generation and tests that assert prompt content.
  • Gitlawb/zero#139: Also touches system-prompt construction and preview utilities.
  • Gitlawb/zero#135: Prior changes to buildSystemPrompt and related tests; likely overlapping concerns.

Suggested reviewers

  • gnanam1990
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add agent quality eval foundation' accurately summarizes the main change—introducing the agent evaluation system with suite/scoring contracts, sample fixtures, and CLI support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/agent-quality-context-eval

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/agenteval/suite.go`:
- Around line 122-140: Suite.normalize currently canonicalizes
ExpectedChangedFiles via normalizeFiles but does not apply the same
normalizeEvalPath cleaning used during Validate, causing paths like
"docs/a/../b.md" to mismatch; update normalizeFiles (or Suite.normalize) to call
normalizeEvalPath on each file before trimming/replacing, deduplicate, and sort
so stored ExpectedChangedFiles matches validation normalization (use the
existing normalizeEvalPath function and keep existing dedupe/sort logic).
- Around line 52-55: The decoder currently only decodes the first JSON value and
ignores trailing JSON; after the existing Decode(&suite) call, attempt a second
decode (e.g., var extra interface{}; err = decoder.Decode(&extra)) and if that
second decode returns nil (meaning there was extra data) or returns an error
other than io.EOF, return an error indicating "trailing JSON after suite"
(include original err when appropriate). Keep references to json.NewDecoder,
decoder.DisallowUnknownFields, and the suite variable so you update the code
right after the Decode(&suite) call.

In `@internal/workspaceseed/workspaceseed.go`:
- Around line 171-180: The normalizePath logic incorrectly converts absolute
paths to non-absolute when cwd is empty; update normalizePath (the block that
checks cwd and filepath.IsAbs(value)) to immediately return "" for any absolute
value if cwd is empty instead of falling through to cleaning and trimming, and
add a regression test that calls Build with Input{Paths:
[]string{"/home/alice/repo/go.mod"}} and an empty CWD to assert the resulting
seed omits that path (i.e., normalizePath returns ""), ensuring host-specific
absolute paths are rejected when they cannot be relativized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f933abd-a056-4c43-9de7-7e254beb824f

📥 Commits

Reviewing files that changed from the base of the PR and between fcfdb87 and 6f84ea6.

📒 Files selected for processing (12)
  • docs/AGENT_EVALS.md
  • internal/agent/system_prompt.md
  • internal/agent/system_prompt_test.go
  • internal/agenteval/agenteval_test.go
  • internal/agenteval/score.go
  • internal/agenteval/suite.go
  • internal/agenteval/testdata/sample_suite.json
  • internal/cli/agent_eval.go
  • internal/cli/agent_eval_test.go
  • internal/cli/app.go
  • internal/workspaceseed/workspaceseed.go
  • internal/workspaceseed/workspaceseed_test.go

Comment thread internal/agenteval/suite.go
Comment thread internal/agenteval/suite.go
Comment thread internal/workspaceseed/workspaceseed.go Outdated
@Vasanthdev2004

Copy link
Copy Markdown
Collaborator Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
✅ Action performed

Comments resolved and changes approved.

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — agent quality eval foundation

Deep pass across the four areas (eval core, eval CLI, workspaceseed, prompt/docs), with each finding independently verified/reproduced before inclusion. CI is green; everything below is correctness / contract / coverage — no blockers, and the one security-flagged item was refuted down to a cosmetic determinism issue. 21 findings confirmed, 2 refuted.

The structural theme behind several findings

The zero eval CLI doesn't actually score — defaultRunAgentEval only loads + validates the suite and returns a hardcoded OK: true, Status: "ready"; it never calls agenteval.Score. That's a reasonable "foundation" scope, but the docs, help text, and part of the test suite read as if it scores. This single fact is the root of findings #2, #7#9, and the scoring↔exit-code coverage gap. Making the validator-only scope explicit (until Score is wired in) would resolve most of the doc/help items at once.

Real bugs (latent — exported API, no production caller yet)

  1. score.go:245 — single-task selection skips path normalization (medium; found independently by two reviewers, reproduced). selectTask's by-ID branch normalizes ExpectedChangedFiles, but the single-task fast path (taskID == "" && len(suite.Tasks) == 1) returns the task verbatim. Score always normalizes the actual side (score.go:86), so a hand-built single-task suite with an empty TaskID yields spurious mismatches (e.g. expected internal/a/../b.go vs actual internal/b.gofail). LoadSuite.normalize() masks it today, but Score is exported and documented to accept an arbitrary Suite. This is the residual half of the earlier expectedChangedFiles canonicalization concern — the divergence lives in selectTask. Fix: normalize in the single-task branch too, and add a Score test with an unnormalized in-memory single-task suite + empty TaskID.

  2. internal/cli/agent_eval.go:22--json drops zero-valued counters. Tasks/Checks/Total/Passed/Failed/Errors all carry omitempty, so a wholly-failing run emits JSON with no passed key — a consumer can't distinguish "0 passed" from "not reported," and the field most wanted on failure vanishes. Note the package's own agenteval.Summary uses no omitempty on the same counters. Fix: drop omitempty from the six counter fields (keep it on optional Name/Status/Failures).

  3. score.go:175 — blocked run still scores unknown command results as fail/error (low). unknownCommandResults ignores input.Blocked, so a blocked run with a stray command result yields Summary{Blocked:2, Failed:1}report.Status stays blocked but the summary is self-contradictory.

  4. score.go:175 — duplicate unknown command IDs produce duplicate result IDs (low). Expected commands dedupe via commandResultsByID; unknown ones don't, so two results with the same unknown ID both emit unknown_command.<id> and inflate the summary. Reachable via the exported ScoreInput.

  5. suite.go:151 — validation accepts entries that normalize to the same path (low). ["a/b.go", "a/./b.go"] both pass validation, then normalizeFiles silently collapses them to one — inconsistent with the duplicate-id detection already done for tasks/commands.

  6. workspaceseed.go:166 — backslash paths bypass the ../absolute guards (low). The "Windows escape" framing was refuted — Go's filepath handles backslashes correctly on Windows, so there's no traversal. The real impact is non-Windows output pollution / non-determinism (..\..\etc flows through as a literal layout entry). Cheap fix: convert \/ at the top of normalizePath (and treat a leading \\ as absolute).

Docs & help mismatches (low)

  1. docs/AGENT_EVALS.md documents the pass/fail/blocked/error "Score Interpretation" right after telling maintainers to run zero eval — which only prints status: ready. Those statuses come solely from agenteval.Score, which has no CLI entry point. State that scoring is library-only for now.
  2. Help verb inconsistencyapp.go lists "eval Run offline agent eval suites" while the subcommand help says "Validates …". Behavior is validate.
  3. defaultRunAgentEval help/description overstates what is currently a suite validator.

Test-coverage gaps

Sev Area Gap
med CLI No test asserts the exact JSON key set (hides #2), nor --help, unknown-flag/stray-arg, or the default runner on an invalid suite file
med workspaceseed The relative .. traversal guard (workspaceseed.go:192) has zero coverage
med score Task-selection error path (typo'd task id → StatusError, report.Error, Summary.Errors) entirely untested
med CLI The real runner can't produce a failing report, so scoring↔exit-code (exitProvider) is exercised only via mocks
low workspaceseed Truncated/MaxLayoutEntries, the dirty-summary branches, and the Windows-drive branch untested
low agenteval DisallowUnknownFields + empty-tasks validation untested (a typo'd key → empty ExpectedChangedFiles → tasks fail for the wrong reason)
low agenteval Command Error-field and unknown-command fail/error statuses unasserted
low agenteval The shipped sample fixture is already clean/sorted, so it doesn't guard normalization
nit agenteval Duplicate-task-id behavior at scoring time (first-match) is undocumented/untested
nit prompt system_prompt.md:54 "verify after edits" is redundant with the trigger clause and duplicates line 34 (which already satisfies the test)

Status of the earlier flagged items

Re-checked against the latest commit: trailing-JSON rejection and absolute-path rejection (CWD unavailable) appear addressed; expectedChangedFiles canonicalization is addressed except the residual selectTask single-task divergence (#1).

Refuted (not real issues)

  • Colon-containing relative paths rejected on Unix — intentional, defensible hardening against drive-letter ambiguity.
  • CLI report can't represent Blocked — purely hypothetical; the CLI never produces a blocked result today.

Net: a solid, deterministic foundation. Highest-value fixes are small — the selectTask normalization (#1) and --json omitempty (#2) — plus aligning the docs/help with the validator-only scope.

@Vasanthdev2004
Vasanthdev2004 marked this pull request as draft June 12, 2026 07:50

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving — the new commits address the review (incl. the selectTask single-task normalization and the --json counter serialization), CI is green, and CodeRabbit has approved. Thanks for the thorough foundation.

@gnanam1990
gnanam1990 marked this pull request as ready for review June 12, 2026 08:01
@gnanam1990
gnanam1990 merged commit 2192c10 into main Jun 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants