Skip to content

feat(viewer): add review comments display to session detail page - #627

Merged
lizhengfeng101 merged 1 commit into
mainfrom
feat/viewer-comments-display
Jul 31, 2026
Merged

lizhengfeng101 merged 1 commit into
mainfrom
feat/viewer-comments-display

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Summary

  • Parse review_item_done and review_item_reused JSONL records in the viewer's LoadSession to extract structured review comments (model.LlmComment)
  • Display comments in the session detail page as a dedicated section between Token Usage and Files Reviewed, grouped by file path
  • Each comment card shows severity/category badges, line range, content, and a side-by-side code diff panel (existing code vs suggested change)
  • Add comment count to SessionSummary and display it in the sessions list page
  • Full dark mode support and responsive layout for the new UI components

Test plan

  • make check passes (format + vet)
  • make test — all existing viewer tests pass
  • Manual: run ocr viewer on a session that has review comments, verify comments render correctly
  • Manual: verify dark mode styling
  • Manual: verify responsive layout on narrow viewport

🤖 Generated with Claude Code

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.
@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 5 issue(s) in this PR.

  • ✅ Successfully posted inline: 5 comment(s)

Comment thread internal/viewer/server.go
Comment on lines +191 to +202
"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"
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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.

Comment on lines +840 to +843
.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); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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 on lines +945 to +950
.comment-code-diff {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.75rem;
margin-top: 0.85rem;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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.

Comment thread internal/viewer/store.go
Comment on lines +175 to 182
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)
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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:

  1. Adding an "Other" or "Unspecified" bucket in severityCounts for unrecognized/empty severities, or
  2. Changing the heading to say "Review Comments" without the count, letting the severity bar speak for itself.

@MuoDoo MuoDoo 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

@lizhengfeng101
lizhengfeng101 merged commit c8dd936 into main Jul 31, 2026
12 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/viewer-comments-display branch July 31, 2026 08:27
Gongyl01 added a commit to Gongyl01/open-code-review that referenced this pull request Jul 31, 2026
冲突解决:
- 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 ./... 全部通过。
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
…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.
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