Skip to content

feat(review): add --summary flag for project-level comment consolidation - #916

Closed
lizhengfeng101 wants to merge 5 commits into
mainfrom
feat/review-summary
Closed

lizhengfeng101 wants to merge 5 commits into
mainfrom
feat/review-summary

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Summary

Adds a --summary flag to ocr review that generates a project-level summary consolidating all per-file review comments into a structured overview.

When enabled, after all per-file reviews complete, an extra LLM call synthesizes the findings into a markdown document with sections for Top Issues, Cross-Cutting Concerns, Quick Wins, and Overall Assessment. The summary is appended after per-file comments in text mode and included in the project_summary field for JSON output.

Changes

  • Template layer: Added PROJECT_SUMMARY_TASK to the review Template struct with dedicated prompt files (project_summary_task_system.md, project_summary_task_user.md)
  • Agent layer: Implemented maybeRunProjectSummary() on the review Agent, with guards for budget-exceeded and context-cancelled states
  • CLI layer: Registered --summary boolean flag and wired it through to agent.Args.SummaryEnabled
  • Safety: Used rune-based truncation in buildSummaryCommentsList to handle multi-byte characters (CJK, emoji) without producing invalid UTF-8

Design Decisions

  • Supplement, not replace: Per-file comments are always output; the summary is appended as an additional section
  • No summary on zero comments: When no issues are found, existing "Looks good to me" behavior is preserved
  • Template-based prompt: Stored in task_template.json so users can customize via --tool-config
  • No output layer changes needed: Existing ProjectSummary() plumbing in emitRunResult handles text and JSON formats automatically

Test Plan

  • go build ./... compiles cleanly
  • go test ./... — all packages pass
  • ocr review --help shows the new --summary flag
  • Manual: ocr review --summary --format json produces project_summary field
  • Manual: ocr review --summary shows "Project Summary" section in terminal
  • Manual: ocr review --summary with no changes produces no summary (LGTM only)

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s).

@yingjiexu2002

Copy link
Copy Markdown
Collaborator

The mechanics check out. Two small suggestions below:

  • add tests for maybeRunProjectSummary / buildSummaryCommentsList
  • document --summary in cli-reference.md (all four locales)

Also, the ProjectSummary() comment in shared.go:328 still claims review mode returns empty — worth a one-line update.

lizhengfeng101 added a commit that referenced this pull request Aug 19, 2026
- Update stale ProjectSummary() comment in shared.go (no longer
  claims empty for review mode)
- Add tests for review-mode maybeRunProjectSummary and
  buildSummaryCommentsList in internal/agent/coverage_test.go
- Document --summary flag in cli-reference.md for all four locales
  (en, zh, ja, ru)
yingjiexu2002
yingjiexu2002 previously approved these changes Aug 20, 2026

@yingjiexu2002 yingjiexu2002 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.

LGTM. All feedback addressed — tests added, docs updated across four locales, and the rune-boundary truncation fix is a nice catch.

Add a new --summary flag to `ocr review` that generates a project-level
summary after all per-file comments are collected. When enabled, an extra
LLM call synthesizes the review findings into a structured markdown
overview (Top Issues, Cross-Cutting Concerns, Quick Wins, Overall
Assessment).

Implementation details:
- Add PROJECT_SUMMARY_TASK to the review Template struct with dedicated
  prompt files (system + user) embedded via task_template.json
- Add maybeRunProjectSummary() to the review Agent, mirroring the scan
  agent's existing pattern
- Guard against budget-exceeded and context-cancelled states before the
  summary LLM call
- Use rune-based truncation in buildSummaryCommentsList to safely handle
  multi-byte characters (CJK, emoji)
- Output layer requires no changes: existing ProjectSummary() plumbing
  in text and JSON formats handles the new content automatically

When no comments are produced, no summary is generated and existing
"Looks good to me" behavior is preserved unchanged.
- Update stale ProjectSummary() comment in shared.go (no longer
  claims empty for review mode)
- Add tests for review-mode maybeRunProjectSummary and
  buildSummaryCommentsList in internal/agent/coverage_test.go
- Document --summary flag in cli-reference.md for all four locales
  (en, zh, ja, ru)
verify-english-only.go flagged the Japanese character in the 280-rune
truncation fixture. The character is deliberate: an ASCII fixture would be
300 bytes and 300 runes alike, so it could not tell rune-based truncation
from byte-based. Add the marker comment the script documents as the first
choice for an encoding fixture, matching the nine existing precedents such
as manifest_test.go:695.
buildSummaryCommentsList capped content with oneLine[:280], slicing the
byte string. When byte 280 landed mid-character the prompt received
invalid UTF-8, and the budget was spent three times too fast on CJK
content: 280 bytes holds 93 characters, so a comment budgeted 280
characters arrived with 93 plus a broken trailing byte.

Count runes instead, matching the copy this PR adds in internal/agent.
The existing test could not catch this — its fixture is 400 ASCII
characters, where byte and rune truncation agree — so add one that
repeats a multibyte character and asserts both valid UTF-8 and the
rune count.
…failure

The --summary call was the only LLM request on the review path missing
llm.WithRequestMeta, so the retry observer dropped it and its retries and
failures never reached the run's retry report. It also had no telemetry
span, and reported failure only to stdout — which --format json and
--audience agent replace with io.Discard, so a summary the user paid for
and did not get vanished with no trace in the warnings array either.

- attach RequestMeta from the record the call created, matching plan and
  review-filter
- wrap the call in a project_summary.execute span plus an LLM span, with
  the span starting after the gates so an off-by-default flag does not add
  an empty span to every review
- record a project_summary_error warning on transport failure and on an
  empty model response
- skip the summary when dispatch returned a hard error, so a failed run
  does not spend one more request on a summary of results it never produced
- cover the failure, empty-body, budget-exceeded, cancelled-context and
  missing-template paths, and pin the request identity
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