Skip to content

feat(session): add 'ocr session comments <id>' viewer - #528

Open
nitishagar wants to merge 1 commit into
alibaba:mainfrom
nitishagar:feat/505-session-comments-viewer
Open

feat(session): add 'ocr session comments <id>' viewer#528
nitishagar wants to merge 1 commit into
alibaba:mainfrom
nitishagar:feat/505-session-comments-viewer

Conversation

@nitishagar

Copy link
Copy Markdown
Contributor

Summary

Adds a read-only ocr session comments <id> subcommand that surfaces the content of review comments from a saved session, rendered in the same style as ocr review. Closes #505.

Today ocr session show prints only per-file comment counts; this surfaces the actual materialized comments without re-running the review.

Approach

Three small, additive changes (no existing function signatures changed):

  • Loader (internal/session/list.go): new standalone CommentEntry type + LoadComments(repoDir, sessionID) that returns per-record comment groups. Sources comments from review_item_done and review_item_reused records (the same records TotalComments counts), so the viewer's count matches the summary. ItemDetail.Comments stays intocr session show is unchanged.
  • CLI (cmd/opencodereview/session_cmd.go): new runSessionComments mirroring runSessionShow's flag wiring. Flags: --repo, --json, --severity, --category (single exact-match filters).
  • Rendering: text path reuses the existing renderComment ([category · severity] badge + diff excerpt). --json emits a focused {"session_id", "comments":[]} payload whose element schema matches the live review JSON. Empty / fully-filtered results print an explicit message (text) or the empty-array envelope (JSON), never a silent empty exit.

Why source from review_item_done.comments and not llm_response.tool_calls

The comment content is already materialized on disk as []model.LlmComment by WriteReviewItemDone / WriteReviewItemReused. Re-deriving from llm_response.tool_calls.arguments.comments (the framing in the issue body) would re-parse raw LLM tool-call JSON — strictly more fragile for zero benefit. The materialized objects sit one json.Unmarshal away in the very records the viewer already walks.

Verification

  • go fmt ./... && go vet ./... clean; go build ./... ok
  • go test -race ./... green (23 packages)
  • New tests cover every spec invariant: done+reused round-trip, failed excluded, TotalComments parity with LoadDetail, on-disk order preserved, text output parity ([category · severity] + path:line), JSON element-schema decode into []model.LlmComment, severity & category filters, empty session + filtered-to-empty (explicit message / [] envelope), missing session id.

Usage

ocr session comments <session-id>                  # view comments in ocr review style
ocr session comments <session-id> --severity high  # filter by severity
ocr session comments <session-id> --category bug   # filter by category
ocr session comments <session-id> --json           # emit JSON for scripting

README (EN + zh-CN/ja-JP/ko-KR/ru-RU) updated with examples.

Add a read-only subcommand that surfaces the materialized content of review
comments from a saved session's review_item_done and review_item_reused records,
rendered in the same style as 'ocr review'. Today 'ocr session show' prints only
per-file comment counts.

Loader (internal/session):
- New CommentEntry type + LoadComments(repoDir, sessionID) returning per-record
  comment groups. ItemDetail.Comments stays int (ocr session show unchanged).
- Sources comments from both done + reused records (matching TotalComments);
  failed records carry no comments and are naturally excluded.

CLI (cmd/opencodereview):
- New 'ocr session comments <id>' subcommand mirroring 'ocr session show'.
- Flags: --repo, --json, --severity, --category (exact-match filters).
- Text path reuses the existing renderComment ([category . severity] + excerpt).
- --json emits a focused {session_id, comments:[]} payload whose element schema
  matches the live review JSON. Empty/filtered-empty results are explicit.

Closes alibaba#505
@github-actions

Copy link
Copy Markdown
Contributor

OpenCodeReview: No comments generated. Looks good to me.

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.

feat: add command to view review comments from a saved session

1 participant