@jphutchins/code-review 0.1.0-alpha.5 → 0.1.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jphutchins/code-review",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "Deterministic commenter for agentic PR review — gather, render, inline, post, adapt, extract, cost, validate, print-schema",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -65,7 +65,9 @@ ignored); a version outside the supported set degrades to a §5.5 sticky notice.
65
65
  | Version | Status | Notes |
66
66
  |---|---|---|
67
67
  | `v0.1.0` | superseded | Initial schema. Matches the proven camas reference implementation. |
68
- | `v0.2.0` | **current** | Adds required `schema_version`; optional `code`/`code_url` finding fields; normative `suggestion` `""`/`null` semantics; abstract vendor-neutral envelope (see SPEC §6.1). |
68
+ | `v0.2.0` | superseded | Adds required `schema_version`; optional `code`/`code_url` finding fields; normative `suggestion` `""`/`null` semantics; abstract vendor-neutral envelope (see SPEC §6.1). |
69
+ | `v0.3.0` | superseded | Adds optional `reasoning` finding field. |
70
+ | `v0.4.0` | **current** | Breaking: renames finding `body` → `description`; makes `reasoning` and `confidence` **required**; adds optional `recommendation` (prose fix); removes the free-text `suggestion` field (a `patch`, now `string \| null`, is the sole mechanical fix, projected into a suggestion by the commenter). The CLI supports only `0.4` — `0.2`/`0.3` documents cannot supply the now-required `reasoning`/`confidence`, so they degrade to a §5.5 unsupported-version notice rather than being upcast. |
69
71
 
70
72
  ### Price-map schema
71
73
 
@@ -27,7 +27,16 @@
27
27
  "items": {
28
28
  "type": "object",
29
29
  "additionalProperties": false,
30
- "required": ["path", "start_line", "end_line", "severity", "title", "body"],
30
+ "required": [
31
+ "path",
32
+ "start_line",
33
+ "end_line",
34
+ "severity",
35
+ "title",
36
+ "description",
37
+ "reasoning",
38
+ "confidence"
39
+ ],
31
40
  "properties": {
32
41
  "path": {
33
42
  "type": "string",
@@ -47,7 +56,7 @@
47
56
  "type": "string",
48
57
  "enum": ["RIGHT", "LEFT"],
49
58
  "default": "RIGHT",
50
- "description": "RIGHT for added/changed lines, LEFT for removed lines; matches the GitHub pulls reviews API."
59
+ "description": "As in a unified-diff view: RIGHT for added/changed lines, LEFT for removed lines."
51
60
  },
52
61
  "severity": {
53
62
  "type": "string",
@@ -67,19 +76,27 @@
67
76
  "type": "string",
68
77
  "description": "One-line summary of the finding."
69
78
  },
70
- "body": {
79
+ "description": {
71
80
  "type": "string",
72
- "description": "Markdown explanation; rendered as the inline comment body."
81
+ "description": "Markdown explanation of what is wrong; rendered as the inline comment body."
73
82
  },
74
- "suggestion": {
75
- "type": ["string", "null"],
76
- "description": "null = no mechanical fix (render no suggestion block); \"\" (empty string) = delete start_line..end_line (render an empty suggestion block); non-empty = exact replacement text for start_line..end_line (render a GitHub suggestion block). A suggestion spanning more than GitHub's single-block line limit is demoted to the summary."
83
+ "recommendation": {
84
+ "type": "string",
85
+ "description": "Markdown prose describing what to do about the finding, in human terms distinct from `patch`, which is a machine-applicable unified diff. Use this when the fix is best explained rather than mechanically applied, or to accompany a `patch` with rationale."
77
86
  },
78
87
  "confidence": {
79
88
  "type": "number",
80
89
  "minimum": 0,
81
90
  "maximum": 1,
82
- "description": "Optional 0..1 confidence; a commenter MAY suppress findings below a configurable threshold to control noise, but MUST NOT suppress a critical-severity finding on confidence alone."
91
+ "description": "0..1 confidence; a commenter MAY suppress findings below a configurable threshold to control noise, but MUST NOT suppress a critical-severity finding on confidence alone."
92
+ },
93
+ "reasoning": {
94
+ "type": "string",
95
+ "description": "Rationale/evidence for why the finding holds, so a human or downstream agent can judge its soundness — distinct from `description`, which explains the finding to the reader."
96
+ },
97
+ "patch": {
98
+ "type": ["string", "null"],
99
+ "description": "Single-hunk unified diff of a mechanical fix, against this file's post-change (RIGHT-side) content, or null when there is no mechanical fix. Validated exactly against the file and deterministically projected into a suggestion (or dropped) by the commenter, so it never posts with wrong indentation or an over-wide range."
83
100
  }
84
101
  }
85
102
  }
@@ -0,0 +1,88 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://raw.githubusercontent.com/JPHutchins/code-review/schema-v0.2.0/schema/findings.schema.json",
4
+ "title": "Code Review — findings",
5
+ "description": "Structured output of an agentic PR review. The review agent emits this object (e.g. via a coding-agent CLI's structured-output mode, such as Claude Code's `--json-schema`, whose result lands in `.structured_output`); a deterministic commenter renders it into a sticky summary comment and inline PR review comments. Agent- and provider-agnostic: any model driven by a compatible CLI adapter may produce it. Kept free of $ref/$defs so the same file works for both JSON-Schema validators and CLI structured-output enforcement.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schema_version", "summary", "verdict", "findings"],
9
+ "properties": {
10
+ "schema_version": {
11
+ "type": "string",
12
+ "pattern": "^(0|[1-9]\\d*)\\.(\\d+)\\.(\\d+)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$",
13
+ "description": "Semver version of this findings schema the object conforms to (e.g. \"0.1.0\"). Lets a commenter detect a version mismatch rather than silently dropping fields."
14
+ },
15
+ "summary": {
16
+ "type": "string",
17
+ "description": "Markdown walkthrough of the change and the overall assessment; rendered as the body of the sticky summary comment."
18
+ },
19
+ "verdict": {
20
+ "type": "string",
21
+ "enum": ["approve", "comment", "changes"],
22
+ "description": "Overall stance. Advisory only: a conforming commenter posts the GitHub review as COMMENT and never REQUEST_CHANGES, surfacing this value as a badge."
23
+ },
24
+ "findings": {
25
+ "type": "array",
26
+ "description": "Zero or more specific findings. Each becomes one inline review comment when its line is inside the diff; otherwise it is demoted into the summary.",
27
+ "items": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": ["path", "start_line", "end_line", "severity", "title", "body"],
31
+ "properties": {
32
+ "path": {
33
+ "type": "string",
34
+ "description": "Repo-relative file path the finding anchors to."
35
+ },
36
+ "start_line": {
37
+ "type": "integer",
38
+ "minimum": 1,
39
+ "description": "1-indexed first line of the anchored range (post-change state when side is RIGHT)."
40
+ },
41
+ "end_line": {
42
+ "type": "integer",
43
+ "minimum": 1,
44
+ "description": "1-indexed last line of the range; MUST be >= start_line. A suggestion replaces exactly start_line..end_line."
45
+ },
46
+ "side": {
47
+ "type": "string",
48
+ "enum": ["RIGHT", "LEFT"],
49
+ "default": "RIGHT",
50
+ "description": "RIGHT for added/changed lines, LEFT for removed lines; matches the GitHub pulls reviews API."
51
+ },
52
+ "severity": {
53
+ "type": "string",
54
+ "enum": ["critical", "major", "minor", "nit"],
55
+ "description": "Used for grouping and for folding nits into a collapsed section."
56
+ },
57
+ "code": {
58
+ "type": "string",
59
+ "description": "Stable rule identifier (e.g. \"null-check-missing\") for rule-based filtering, suppression, and cross-run dedup."
60
+ },
61
+ "code_url": {
62
+ "type": "string",
63
+ "format": "uri",
64
+ "description": "URL documenting the rule named by code."
65
+ },
66
+ "title": {
67
+ "type": "string",
68
+ "description": "One-line summary of the finding."
69
+ },
70
+ "body": {
71
+ "type": "string",
72
+ "description": "Markdown explanation; rendered as the inline comment body."
73
+ },
74
+ "suggestion": {
75
+ "type": ["string", "null"],
76
+ "description": "null = no mechanical fix (render no suggestion block); \"\" (empty string) = delete start_line..end_line (render an empty suggestion block); non-empty = exact replacement text for start_line..end_line (render a GitHub suggestion block). A suggestion spanning more than GitHub's single-block line limit is demoted to the summary."
77
+ },
78
+ "confidence": {
79
+ "type": "number",
80
+ "minimum": 0,
81
+ "maximum": 1,
82
+ "description": "Optional 0..1 confidence; a commenter MAY suppress findings below a configurable threshold to control noise, but MUST NOT suppress a critical-severity finding on confidence alone."
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
@@ -1,9 +1,12 @@
1
1
  <!-- code-review -->
2
2
  <!-- reviewed-sha: <%= it.reviewedSha %> -->
3
+ <% if (it.findingsPointer) { -%>
4
+ <%~ it.findingsPointer %>
5
+ <% } -%>
3
6
 
4
7
  ### <%= it.verdictBadge(it.findings.verdict) %>
5
8
 
6
- <% const meta = [] %><% if (it.route) { meta.push('**Route:** ' + it.route) } %><% if (it.effort) { meta.push('**effort:** ' + it.effort) } %><% if (it.usageAvailable) { meta.push('**turns:** ' + it.envelope.turns); meta.push('**wall:** ' + it.formatDuration(it.envelope.duration_ms)) } else { meta.push('_usage unavailable_') } %><%~ meta.join(' · ') %>
9
+ <% const meta = [] %><% if (it.route) { meta.push('**Route:** ' + it.route) } %><% if (it.effort) { meta.push('**effort:** ' + it.effort) } %><% if (it.usageAvailable) { meta.push('**turns:** ' + it.envelope.turns); meta.push('**wall:** ' + it.formatDuration(it.envelope.duration_ms)); meta.push('**models:** ' + it.modelNames); meta.push('**cost:** ' + it.formatCost(it.costReport.totalCostUSD)) } else { meta.push('_usage unavailable_') } %><%~ meta.join(' · ') %>
7
10
 
8
11
  <%~ it.findings.summary %>
9
12
 
@@ -18,7 +21,7 @@ _No findings — clean review._
18
21
  <% } %>
19
22
 
20
23
  <% if (it.inlineDisposition && it.inlineDisposition.kind === 'posted') { %>
21
- → <%= it.inlineDisposition.count %> comment<%= it.inlineDisposition.count === 1 ? '' : 's' %> posted inline on `<%= it.inlineDisposition.sha.slice(0, 7) %>` — see the review.
24
+ → <%= it.inlineDisposition.count %> comment<%= it.inlineDisposition.count === 1 ? '' : 's' %> posted inline on `<%= it.inlineDisposition.sha.slice(0, 7) %>` — <% if (it.reviewUrl) { %>[see the review](<%~ it.reviewUrl %>)<% } else { %>see the review<% } %>.
22
25
  <% } else if (it.inlineDisposition && it.inlineDisposition.kind === 'none-in-diff') { %>
23
26
  → No inline comments — all findings are outside the diff (listed below).
24
27
  <% } else if (it.inlineDisposition && it.inlineDisposition.kind === 'suppressed-existing-review') { %>
@@ -31,7 +34,29 @@ _No findings — clean review._
31
34
  These findings are on lines not in the diff, so they can't be anchored as inline comments:
32
35
 
33
36
  <% it.strays.forEach(function(f) { -%>
34
- - <%= it.severityEmoji(f.severity) %> `<%= f.path %>:<%= f.start_line %><% if (f.start_line !== f.end_line) { %>–<%= f.end_line %><% } %>` — <%= f.title %>
37
+ - <%= it.severityEmoji(f.severity) %> `<%= f.path %>:<%= f.start_line %><% if (f.start_line !== f.end_line) { %>–<%= f.end_line %><% } %>` — <%= f.title %> · confidence <%= f.confidence %>
38
+ <details><summary>Reasoning</summary>
39
+
40
+ <% f.reasoning.split("\n").forEach(function(rl) { -%>
41
+ <%= rl %>
42
+ <% }) -%>
43
+
44
+ </details>
45
+ <% if (f.recommendation) { -%>
46
+
47
+ **Recommended fix:** <%~ f.recommendation %>
48
+ <% } -%>
49
+ <% if (f.patchProjection.kind === "suggestion") { -%>
50
+
51
+ ```suggestion
52
+ <%~ f.patchProjection.text %>
53
+ ```
54
+ <% } else if (f.patchProjection.kind === "patch") { -%>
55
+
56
+ ```patch
57
+ <%~ f.patchProjection.raw %>
58
+ ```
59
+ <% } -%>
35
60
  <% }) %>
36
61
  <% } %>
37
62
 
@@ -54,24 +79,24 @@ All <%= it.testReport.total %> tests passed.
54
79
 
55
80
  ---
56
81
 
57
- <% if (it.usageAvailable && it.costReport.lines.length > 0) { %>
58
- <sub>
59
-
60
- | Model | Input | Output | Cache read | Cache write | Cost |
61
- |---|--:|--:|--:|--:|--:|
82
+ > [!WARNING]
83
+ > **LLM Disclosure** — this review was produced by <%= it.modelNames || "unknown model" %>.
84
+ >
85
+ <% if (it.usageAvailable && it.costReport.lines.length > 0) { -%>
86
+ > | Model | Input | Output | Cache read | Cache write | Cost |
87
+ > |---|--:|--:|--:|--:|--:|
62
88
  <% it.costReport.lines.forEach(function(l) { -%>
63
- | <%= l.model %> | <%= it.formatTokens(l.inputTokens) %> | <%= it.formatTokens(l.outputTokens) %> | <%= it.formatTokens(l.cacheReadTokens) %> | <%= it.formatTokens(l.cacheWriteTokens) %> | <%= it.formatCost(l.costUSD) %> |
89
+ > | <%= l.model %> | <%= it.formatTokens(l.inputTokens) %> | <%= it.formatTokens(l.outputTokens) %> | <%= it.formatTokens(l.cacheReadTokens) %> | <%= it.formatTokens(l.cacheWriteTokens) %> | <%= it.formatCost(l.costUSD) %> |
64
90
  <% }) -%>
65
- | **Total** | **<%= it.formatTokens(it.costReport.totalInputTokens) %>** | **<%= it.formatTokens(it.costReport.totalOutputTokens) %>** | **<%= it.formatTokens(it.costReport.totalCacheReadTokens) %>** | **<%= it.formatTokens(it.costReport.totalCacheWriteTokens) %>** | **<%= it.formatCost(it.costReport.totalCostUSD) %>** |
66
-
67
- </sub>
68
- <% } else if (it.usageAvailable) { %>
69
- <sub>No per-model usage was recorded for this run.</sub>
70
- <% } else { %>
91
+ > | **Total** | **<%= it.formatTokens(it.costReport.totalInputTokens) %>** | **<%= it.formatTokens(it.costReport.totalOutputTokens) %>** | **<%= it.formatTokens(it.costReport.totalCacheReadTokens) %>** | **<%= it.formatTokens(it.costReport.totalCacheWriteTokens) %>** | **<%= it.formatCost(it.costReport.totalCostUSD) %>** |
92
+ <% } else if (it.usageAvailable) { -%>
93
+ > No per-model usage was recorded for this run.
94
+ <% } else { -%>
71
95
  > **Usage/cost unavailable** — the result envelope for this run was missing or malformed.
72
- <% } %>
73
-
74
- > [!NOTE]
75
- > **LLM Disclosure** — this review was produced by <%= it.modelNames || "unknown model" %> running
76
- > headless in an ephemeral, egress-locked CI runner with no write access to the repository. It is
77
- > advisory and does not block merge.
96
+ <% } -%>
97
+ <% if (it.usageAvailable && !it.pricesProvided) { -%>
98
+ >
99
+ > _Cost shown as **N/A**[No `.github/prices.json`](https://github.com/JPHutchins/code-review/blob/main/SPEC.md#62-price-map) price map to recompute from._
100
+ <% } -%>
101
+ >
102
+ > _Generated by [code-review](https://github.com/JPHutchins/code-review)<% if (it.runUrl) { %> · [view the run & traces](<%~ it.runUrl %>)<% } %>._
@@ -1,9 +1,32 @@
1
- <%~ it.body %>
1
+ <% if (it.findingsPointer) { -%>
2
+ <%~ it.findingsPointer %>
3
+ <% } -%>
4
+ <%= it.severityEmoji(it.severity) %> **<%= it.severity %>** — <%= it.title %>
5
+
6
+ <%~ it.description %>
7
+ <% if (it.recommendation) { -%>
8
+
9
+ **Recommended fix:** <%~ it.recommendation %>
10
+ <% } -%>
11
+ <% if (it.patchProjection.kind === "suggestion") { -%>
2
12
 
3
- <% if (it.suggestion !== null && it.suggestion !== undefined) { %>
4
13
  ```suggestion
5
- <%~ it.suggestion %>
14
+ <%~ it.patchProjection.text %>
15
+ ```
16
+ <% } else if (it.patchProjection.kind === "patch") { -%>
17
+
18
+ ```patch
19
+ <%~ it.patchProjection.raw %>
6
20
  ```
7
- <% } %>
21
+ <% } -%>
8
22
 
9
- <sub>🤖 AI-generated — advisory only</sub>
23
+ > [!TIP]
24
+ > Generated by <%~ it.modelsText %> at <%= it.confidence %> confidence.
25
+ > <details>
26
+ > <summary>Reasoning</summary>
27
+ >
28
+ <% it.reasoning.split("\n").forEach(function(rl) { -%>
29
+ > <%= rl %>
30
+ <% }) -%>
31
+ >
32
+ > </details>