Skip to content

feat(review): add structured category and severity fields to findings#311

Merged
lizhengfeng101 merged 1 commit into
mainfrom
feat/structured-category-severity
Jul 7, 2026
Merged

feat(review): add structured category and severity fields to findings#311
lizhengfeng101 merged 1 commit into
mainfrom
feat/structured-category-severity

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Summary

Adds two structured fields, category and severity, to every review finding so CI integrations (GitHub Actions, GitLab CI, etc.) can sort, group, filter, or gate builds without re-parsing natural-language comment text.

This reworks #29 based on maintainer feedback in that thread.

Allowed values:

  • category: bug, security, performance, maintainability, test, style, documentation, other
  • severity: critical, high, medium, low

What changed

  • Tool schema (tools.json): category and severity are added as enum-constrained, required properties of code_comment. Relying on the schema (rather than prompt guidance) is sufficient to drive reliable population.
  • severity drops info: limited to critical/high/medium/low, since LLMs consistently struggle to distinguish low from info — fewer options yield more decisive, reliable output.
  • System prompt untouched: task_template.json is intentionally left unchanged to avoid the review-quality regression observed on the benchmark suite. The tool schema alone drives field population.
  • JSON output: category/severity are flat siblings of content, start_line, etc., and are omitted entirely when empty (omitempty), so existing consumers are unaffected.
  • CLI output: findings render an inline [category · severity] badge before the comment text, colored by severity (critical=bold red, high=red, medium=yellow, low=blue).
  • Docs: all five README locales (en, zh-CN, ja-JP, ko-KR, ru-RU) document the fields and allowed values.

Testing

  • make check — passes
  • make test — all packages pass
  • New unit tests: parsing (present/absent), JSON serialization (set/omitted), buildBadge, severityColor, and inline badge rendering in renderComment.

Fixes #16

Add two structured fields, category and severity, to every review finding
so CI integrations can sort, group, filter, or gate builds without
re-parsing natural-language comment text.

- Tool schema (tools.json): add category/severity as enum-constrained,
  required properties of code_comment. severity is limited to
  critical/high/medium/low (info dropped, since LLMs struggle to
  distinguish low from info).
- System prompt (task_template.json) is intentionally left untouched to
  avoid the review-quality regression observed on the benchmark suite;
  the tool schema alone drives field population.
- JSON output: category/severity are flat siblings of content/start_line,
  omitted entirely when empty (backward compatible).
- CLI output: render an inline [category - severity] badge before the
  comment, colored by severity.
- Sync docs across all five README locales.

@github-actions github-actions Bot left a comment

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.

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

  • ✅ 1 posted as inline comment(s)
  • 📝 0 posted as summary

Comment on lines +118 to +119
func severityColor(severity string) string {
switch severity {

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.

The severityColor function performs case-sensitive matching against lowercase severity values ("critical", "high", etc.), but the severity value comes directly from LLM output without any normalization (see internal/tool/code_comment.go). If the LLM returns "Critical", "HIGH", or "Medium", the color will silently fall back to dim (\033[2m) while the badge still displays the original casing.

Consider normalizing the severity to lowercase before matching, e.g.:

switch strings.ToLower(severity) {

This makes the color assignment resilient to LLM casing variations.

Suggestion:

Suggested change
func severityColor(severity string) string {
switch severity {
func severityColor(severity string) string {
switch strings.ToLower(severity) {

@ScarletCarpet

Copy link
Copy Markdown
Contributor

as #16 mentioned, want a filter flag. is it needed? last time i impled one.

@ScarletCarpet

Copy link
Copy Markdown
Contributor

and want a rank function for output. first severity then category.

@ScarletCarpet

Copy link
Copy Markdown
Contributor

lack changes of memory_compression_task_system.md which has already defined serverity:
image

lack changes of plan_task_system.md whcih has already defined serverity but category:
image

@MuoDoo
MuoDoo requested a review from Copilot July 7, 2026 03:51

Copilot AI 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.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds structured category and severity metadata to review findings so CI systems can reliably sort/filter/gate results without parsing free-form text.

Changes:

  • Extends the finding model + parsing logic to carry Category/Severity, and adds JSON omitempty behavior.
  • Updates the tool schema (tools.json) with enum constraints and required fields for category/severity.
  • Enhances CLI rendering to show a colorized inline [category · severity] badge and adds unit tests + docs updates across locales.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/tool/code_comment.go Parses category/severity from LLM tool output into the comment model.
internal/model/review.go Adds Category/Severity fields with JSON serialization behavior.
internal/config/toolsconfig/tools.json Enforces enum values and marks the new fields as required in the tool schema.
cmd/opencodereview/output.go Renders a severity-colored badge inline before comment text.
cmd/opencodereview/output_test.go Adds tests for badge building, severity colors, and inline rendering.
internal/tool/code_comment_test.go Adds tests for parsing and JSON serialization of the new fields.
README*.md Documents the new structured fields and their allowed values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 80 to 85
"required": [
"content",
"existing_code"
"existing_code",
"category",
"severity"
]
Comment on lines +71 to +76
if category, ok := obj["category"].(string); ok {
cm.Category = category
}
if severity, ok := obj["severity"].(string); ok {
cm.Severity = severity
}
Comment on lines +71 to 78
lines := wrapByRunes(content, 100)
for i, ln := range lines {
if i == 0 && badge != "" && strings.HasPrefix(ln, badge) {
color := severityColor(comment.Severity)
ln = color + badge + "\033[0m" + ln[len(badge):]
}
fmt.Printf("%s\n", ln)
}
@lizhengfeng101
lizhengfeng101 merged commit a2e08b7 into main Jul 7, 2026
8 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/structured-category-severity branch July 7, 2026 05:08
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(agent): add structured category and severity fields to review output

4 participants