Repository navigation
feat(viewer): add review comments display to session detail page - #627
Conversation
Parse review_item_done/review_item_reused JSONL records to extract LLM-generated review comments. Display them in the session detail page grouped by file, with severity/category badges, line ranges, and side-by-side code diff panels (existing vs suggested). Also add a comment count column to the sessions list page.
|
🔍 OpenCodeReview found 5 issue(s) in this PR.
|
| "categoryClass": func(s string) string { | ||
| switch s { | ||
| case "bug": | ||
| return "cat-bug" | ||
| case "security": | ||
| return "cat-security" | ||
| case "performance": | ||
| return "cat-performance" | ||
| default: | ||
| return "cat-default" | ||
| } | ||
| }, |
There was a problem hiding this comment.
[maintainability · low]
The categoryClass function only maps 3 of the 8 documented category values (bug, security, performance). According to the ReviewComment struct comment and model.LlmComment, valid categories also include maintainability, test, style, documentation, and other. These will all silently fall through to cat-default, losing visual distinction in the UI.
Consider adding CSS classes for the remaining categories, or at minimum document that they intentionally share the default style.
| .severity-critical { background: #fef2f2; color: #dc2626; } | ||
| .severity-high { background: #fff7ed; color: #ea580c; } | ||
| .severity-medium { background: #fefce8; color: #a16207; } | ||
| .severity-low { background: var(--badge-neutral-bg); color: var(--badge-neutral-fg); } |
There was a problem hiding this comment.
[maintainability · medium]
Maintainability: The project already defines a CSS custom property system for badge/severity colors in :root (e.g., --badge-error-bg, --badge-error-fg, --badge-neutral-bg). However, these new severity and category classes use hardcoded hex/rgba values directly instead of leveraging or extending that variable system.
Consider defining new CSS variables like --severity-critical-bg, --severity-critical-fg, --cat-bug-bg, --cat-security-bg, etc. in both :root and the dark mode block. This would:
- Keep all color definitions centralized for easier theme maintenance
- Be consistent with the existing pattern used by
--badge-*variables - Make future customization (e.g., user-defined themes) much simpler
| .comment-code-diff { | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr; | ||
| gap: 0.75rem; | ||
| margin-top: 0.85rem; | ||
| } |
There was a problem hiding this comment.
[maintainability · low]
Usability/Responsive: The .comment-code-diff grid collapses from 2 columns to 1 column only at max-width: 768px. Code panels displayed side-by-side can become quite cramped on intermediate viewports (e.g., tablets or resized browser windows between ~768px–1024px), especially since code content benefits from wider horizontal space. Consider adding an intermediate breakpoint (e.g., at max-width: 1024px) that switches to a single-column layout earlier, or use grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) to let the grid adapt more fluidly.
| if len(line) > 0 && (bytes.Contains(line, []byte(`"review_item_done"`)) || bytes.Contains(line, []byte(`"review_item_reused"`))) { | ||
| var rec map[string]any | ||
| if err := json.Unmarshal(line, &rec); err == nil { | ||
| if comments, ok := rec["comments"].([]any); ok { | ||
| summary.CommentCount += len(comments) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
[bug · medium]
The bytes.Contains pre-filter can produce false positives: any JSONL line containing the literal substring "review_item_done" or "review_item_reused" (e.g., in an LLM response's text content, a file path, or a tool result) will be parsed and checked for a comments array. If such a non-review-item record happens to have a comments field that is an array, CommentCount will be inflated.
This creates an inconsistency between peekSession (used by ListSessions) and LoadSession (which uses exact rec["type"] matching via the switch statement). The session list could show a different comment count than the session detail view.
Consider parsing the JSON and checking rec["type"] directly, or use a more specific pre-filter like checking for "type":"review_item_done" to reduce false positive risk.
|
|
||
| {{if .Session.Comments}} | ||
| <div class="comments-section"> | ||
| <h3>Review Comments ({{len .Session.Comments}} findings)</h3> |
There was a problem hiding this comment.
[maintainability · low]
Minor UX inconsistency: The heading displays the total number of comments (len .Session.Comments), but the severity bar only shows counts for recognized severities (critical/high/medium/low). If any comment has an empty or unrecognized severity value, the sum of the severity badges will be less than the heading count, which may confuse users.
Consider either:
- Adding an "Other" or "Unspecified" bucket in
severityCountsfor unrecognized/empty severities, or - Changing the heading to say "Review Comments" without the count, letting the severity bar speak for itself.
冲突解决: - cmd/opencodereview/flags.go: 接受 upstream 删除(alibaba#625 迁移到 Cobra), 将 --max-tokens-budget 的说明文案迁移到 shared_flags.go 的 addConcurrencyFlags - internal/viewer/store.go: SessionSummary 取双方字段并集(manifest 终态 + CommentCount); LoadSession 同时保留 CommentCount 统计与 readErr 返回 - internal/viewer/templates/sessions.html: 同时保留 Status 与 Comments 两列 另修复两处自动合并后编译失败: - store.go ListSessions: 本分支已将 scanner 循环重构为 readJSONLLines 回调, alibaba#627 新增的 continue 落入闭包,改为 return - compat_test.go: 补 runReview 兼容包装(alibaba#625 已拆为 reviewCmd + executeReview) go build / go vet / go test ./... 全部通过。
…baba#627) Parse review_item_done/review_item_reused JSONL records to extract LLM-generated review comments. Display them in the session detail page grouped by file, with severity/category badges, line ranges, and side-by-side code diff panels (existing vs suggested). Also add a comment count column to the sessions list page.
Summary
review_item_doneandreview_item_reusedJSONL records in the viewer'sLoadSessionto extract structured review comments (model.LlmComment)SessionSummaryand display it in the sessions list pageTest plan
make checkpasses (format + vet)make test— all existing viewer tests passocr vieweron a session that has review comments, verify comments render correctly🤖 Generated with Claude Code