mandrel 2.103.0 → 2.105.0

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.
Files changed (34) hide show
  1. package/.agents/agents/acceptance-critic.md +2 -0
  2. package/.agents/agents/auditor.md +2 -0
  3. package/.agents/agents/plan-critic.md +2 -0
  4. package/.agents/agents/story-worker.md +2 -0
  5. package/.agents/docs/configuration.md +1 -1
  6. package/.agents/docs/execution-reference.md +35 -0
  7. package/.agents/instructions.md +4 -2
  8. package/.agents/rules/testing-standards.md +7 -1
  9. package/.agents/schemas/agentrc.schema.json +1 -1
  10. package/.agents/scripts/lib/close-validation/test-delta.js +8 -2
  11. package/.agents/scripts/lib/config-settings-schema.js +1 -1
  12. package/.agents/scripts/lib/coverage-capture-affected.js +3 -2
  13. package/.agents/scripts/lib/coverage-capture-delta.js +101 -34
  14. package/.agents/scripts/lib/coverage-capture.js +14 -7
  15. package/.agents/scripts/lib/orchestration/code-review.js +56 -28
  16. package/.agents/scripts/lib/orchestration/evidence-stream.js +16 -7
  17. package/.agents/scripts/lib/orchestration/review-deposit.js +24 -7
  18. package/.agents/scripts/lib/orchestration/review-providers/claim-grounding.js +231 -0
  19. package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +2 -0
  20. package/.agents/scripts/lib/orchestration/review-providers/code-review.js +6 -1
  21. package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +11 -1
  22. package/.agents/scripts/lib/orchestration/review-providers/findings-renderer.js +4 -1
  23. package/.agents/scripts/lib/orchestration/review-providers/generated-diff.js +7 -3
  24. package/.agents/scripts/lib/orchestration/review-providers/parse-findings.js +7 -0
  25. package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +7 -20
  26. package/.agents/scripts/lib/orchestration/review-providers/types.js +9 -0
  27. package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +1 -0
  28. package/.agents/scripts/lib/orchestration/story-close/phases/review-core.js +13 -5
  29. package/.agents/scripts/lib/orchestration/story-handoff.js +77 -18
  30. package/.agents/workflows/helpers/code-review.md +8 -0
  31. package/.agents/workflows/helpers/deliver-digest.md +8 -8
  32. package/.agents/workflows/helpers/deliver-reference.md +21 -14
  33. package/docs/CHANGELOG.md +21 -0
  34. package/package.json +1 -1
@@ -3,10 +3,10 @@
3
3
  * time, and its identity.
4
4
  *
5
5
  * The identity is the **diff digest**: a sha256 of the exact
6
- * `git diff --no-color <base>...<head>` text the review provider is handed.
7
- * A clean base-sync merge moves HEAD without changing that text, while any
8
- * commit that changes the diff changes it — so close adopts a deposit, and
9
- * posts a held result, on digest equality, never on SHA equality.
6
+ * `git diff --no-color <base>...<head>` text, less generated files. A clean
7
+ * base-sync merge moves HEAD without changing that text, while any commit
8
+ * that changes the diff changes it — so close adopts a deposit, and posts a
9
+ * held result, on digest equality, never on SHA equality.
10
10
  *
11
11
  * The file lives beside the terminal envelope; nothing deletes it but the
12
12
  * Story temp purge. A mismatched deposit is simply not adopted.
@@ -18,6 +18,11 @@ import nodeFs from 'node:fs';
18
18
  import { storyReviewDepositPath } from '../config/temp-paths.js';
19
19
  import { writeFileAtomic } from '../util/atomic-write.js';
20
20
  import { resolveSharedBaseRef } from './review-base-ref.js';
21
+ import {
22
+ diffSections,
23
+ generatedPaths,
24
+ sectionPath,
25
+ } from './review-providers/generated-diff.js';
21
26
 
22
27
  const DEPOSIT_KIND = 'story-review-deposit';
23
28
 
@@ -41,6 +46,19 @@ export function resolveRefSha({ cwd, ref, gitSpawnFn }) {
41
46
  }
42
47
  }
43
48
 
49
+ /** Generated sections dropped; end-trimmed as the runner trims stdout. */
50
+ function reviewedText(diff, deps) {
51
+ const sections = diffSections(diff);
52
+ const generated = generatedPaths(
53
+ sections.map(sectionPath).filter(Boolean),
54
+ deps,
55
+ );
56
+ return sections
57
+ .filter((s) => !generated.has(sectionPath(s)))
58
+ .map((s) => s.trimEnd())
59
+ .join('\n');
60
+ }
61
+
44
62
  /**
45
63
  * sha256 of the three-dot diff text, spawned exactly as the review provider
46
64
  * spawns it. `null` when the diff cannot be read — an unknown identity that
@@ -60,9 +78,8 @@ export function computeReviewDiffDigest({ cwd, baseRef, headRef, gitSpawnFn }) {
60
78
  `${baseRef}...${headRef}`,
61
79
  );
62
80
  if (diff?.status !== 0) return null;
63
- return createHash('sha256')
64
- .update(String(diff.stdout ?? ''), 'utf8')
65
- .digest('hex');
81
+ const text = reviewedText(String(diff.stdout ?? ''), { cwd, gitSpawnFn });
82
+ return createHash('sha256').update(text, 'utf8').digest('hex');
66
83
  } catch {
67
84
  return null;
68
85
  }
@@ -0,0 +1,231 @@
1
+ /**
2
+ * review-providers/claim-grounding.js — checks a critical finding's
3
+ * structured `claim` against the reviewed head before it can halt. A
4
+ * refuted claim downgrades the finding to a suggestion; a confirmed claim,
5
+ * a git error or no claim leaves it unchanged. Prose is never parsed.
6
+ *
7
+ * @typedef {import('./types.js').Finding} Finding
8
+ * @typedef {import('./types.js').FindingClaim} FindingClaim
9
+ */
10
+
11
+ import { gitSpawn } from '../../git-utils.js';
12
+ import { isObject } from '../../json-utils.js';
13
+
14
+ const TRUNCATED_CONTEXT = 'reviewed-with-truncated-context';
15
+ const CLAIM_KINDS = ['path-absent', 'symbol-referenced'];
16
+
17
+ /** The optional `claim` property of the Claude findings schema. */
18
+ export const CLAIM_SCHEMA = {
19
+ type: 'object',
20
+ properties: {
21
+ kind: { enum: CLAIM_KINDS },
22
+ path: { type: 'string' },
23
+ symbol: { type: 'string' },
24
+ },
25
+ required: ['kind'],
26
+ };
27
+
28
+ /** Codex strict output: every property required, absence as `null`. */
29
+ export const STRICT_CLAIM_SCHEMA = {
30
+ type: ['object', 'null'],
31
+ additionalProperties: false,
32
+ required: ['kind', 'path', 'symbol'],
33
+ properties: {
34
+ kind: { type: 'string', enum: CLAIM_KINDS },
35
+ path: { type: ['string', 'null'] },
36
+ symbol: { type: ['string', 'null'] },
37
+ },
38
+ };
39
+
40
+ const nonBlank = (value) =>
41
+ typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
42
+
43
+ /**
44
+ * A claim is kept only when its `kind` is known and carries the field that
45
+ * kind is checked by; anything else is dropped, never grounded.
46
+ *
47
+ * @param {unknown} raw
48
+ * @returns {FindingClaim | null}
49
+ */
50
+ export function buildClaim(raw) {
51
+ if (!isObject(raw)) return null;
52
+ const path = nonBlank(raw.path);
53
+ const symbol = nonBlank(raw.symbol);
54
+ if (raw.kind === 'path-absent' && path) return { kind: raw.kind, path };
55
+ if (raw.kind !== 'symbol-referenced' || !symbol) return null;
56
+ return path ? { kind: raw.kind, symbol, path } : { kind: raw.kind, symbol };
57
+ }
58
+
59
+ /**
60
+ * Report lines saying why a finding did not block, or was reviewed blind.
61
+ *
62
+ * @param {Finding} finding
63
+ * @returns {string[]}
64
+ */
65
+ export function groundingNotes(finding) {
66
+ const notes = [];
67
+ if (finding.ungrounded) {
68
+ notes.push(`_Not blocking: ungrounded — ${finding.ungrounded}._`);
69
+ }
70
+ if (finding.context) notes.push(`_Context: ${finding.context}._`);
71
+ return notes;
72
+ }
73
+
74
+ /** @returns {string|null} evidence when the path exists at `headRef`. */
75
+ function refutePathAbsent(claim, headRef, git) {
76
+ const result = git('cat-file', '-e', `${headRef}:${claim.path}`);
77
+ return result?.status === 0 ? `git cat-file found ${claim.path}` : null;
78
+ }
79
+
80
+ /** `{ file, text }` of one `git grep <ref>` hit (`<ref>:<file>:<n>:<text>`). */
81
+ function parseHit(line, headRef) {
82
+ const rest = line.startsWith(`${headRef}:`)
83
+ ? line.slice(headRef.length + 1)
84
+ : line;
85
+ const match = /^(.*?):\d+:(.*)$/.exec(rest);
86
+ return match ? { file: match[1], text: match[2] } : { file: rest, text: '' };
87
+ }
88
+
89
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
90
+
91
+ /**
92
+ * Only the symbol's own declaration line in `claim.path` is discounted; any
93
+ * other hit there (a stale caller) still counts, so the check fails safe.
94
+ */
95
+ function isDeclaration(hit, claim) {
96
+ if (!claim.path || hit.file !== claim.path) return false;
97
+ const declares = new RegExp(
98
+ `\\b(?:function\\*?|class|const|let|var|def|type|interface|enum)\\s+${escapeRegExp(claim.symbol)}\\b`,
99
+ );
100
+ return declares.test(hit.text);
101
+ }
102
+
103
+ /** @returns {string|null} evidence when every hit is the declaration. */
104
+ function refuteSymbolReferenced(claim, headRef, git) {
105
+ const result = git(
106
+ 'grep',
107
+ '-n',
108
+ '-w',
109
+ '-F',
110
+ '-e',
111
+ claim.symbol,
112
+ headRef,
113
+ '--',
114
+ );
115
+ if (result?.status !== 0 && result?.status !== 1) return null;
116
+ const referenced = String(result.stdout ?? '')
117
+ .split('\n')
118
+ .filter((line) => line.length > 0)
119
+ .some((line) => !isDeclaration(parseHit(line, headRef), claim));
120
+ if (referenced) return null;
121
+ return claim.path
122
+ ? `git grep found no references outside ${claim.path}`
123
+ : 'git grep found no references';
124
+ }
125
+
126
+ const REFUTERS = {
127
+ 'path-absent': refutePathAbsent,
128
+ 'symbol-referenced': refuteSymbolReferenced,
129
+ };
130
+
131
+ /** @returns {Finding} */
132
+ function groundFinding(finding, headRef, git) {
133
+ if (!isGroundable(finding)) return finding;
134
+ const refute = REFUTERS[finding.claim.kind];
135
+ let evidence = null;
136
+ try {
137
+ evidence = refute(finding.claim, headRef, git);
138
+ } catch {
139
+ evidence = null;
140
+ }
141
+ if (!evidence) return finding;
142
+ return { ...finding, severity: 'suggestion', ungrounded: evidence };
143
+ }
144
+
145
+ const isGroundable = (finding) =>
146
+ finding?.severity === 'critical' && Boolean(REFUTERS[finding?.claim?.kind]);
147
+
148
+ function headResolves(git, headRef) {
149
+ try {
150
+ return (
151
+ git('rev-parse', '--verify', '--quiet', `${headRef}^{commit}`)?.status ===
152
+ 0
153
+ );
154
+ } catch {
155
+ return false;
156
+ }
157
+ }
158
+
159
+ /**
160
+ * `cat-file` exits 128 for a missing path and an unknown ref alike, so the
161
+ * head is checked on its own: an unresolvable head means every claim stays
162
+ * unrefuted for want of a repository, and that is reported, not silent.
163
+ * Probes only when some finding is groundable.
164
+ *
165
+ * @returns {import('./degraded-gates.js').GateDegradation[]}
166
+ */
167
+ function headDegradations({ findings, headRef, cwd, git }) {
168
+ if (!findings.some(isGroundable) || headResolves(git, headRef)) return [];
169
+ return [
170
+ {
171
+ tool: 'claim-grounding',
172
+ gate: 'claim-grounding',
173
+ surface: 'head-ref',
174
+ reason: `head ${headRef} not resolvable in ${cwd}`,
175
+ },
176
+ ];
177
+ }
178
+
179
+ /** Names a degradation reason carries, split on its list punctuation. */
180
+ function reasonTokens(degradations) {
181
+ return new Set(
182
+ degradations.flatMap((d) => String(d.reason).split(/[\s,()]+/)),
183
+ );
184
+ }
185
+
186
+ function annotateContext(finding, tokens) {
187
+ const names = [finding.file, finding.claim?.path, finding.claim?.symbol];
188
+ if (!names.some((name) => name && tokens.has(name))) return finding;
189
+ return { ...finding, context: TRUNCATED_CONTEXT };
190
+ }
191
+
192
+ function groundEach(findings, headRef, git, tokens) {
193
+ return findings.map((finding) => {
194
+ const grounded = groundFinding(finding, headRef, git);
195
+ return grounded && tokens.size > 0
196
+ ? annotateContext(grounded, tokens)
197
+ : grounded;
198
+ });
199
+ }
200
+
201
+ /**
202
+ * Ground every finding in `cwd`, the reviewed repository. `degradations`
203
+ * comes back with the head check's record appended when the head does not
204
+ * resolve there.
205
+ *
206
+ * @param {{
207
+ * findings: Finding[],
208
+ * headRef: string,
209
+ * degradations?: ReadonlyArray<{ reason: string }>,
210
+ * cwd?: string,
211
+ * gitSpawnFn?: typeof gitSpawn,
212
+ * }} args
213
+ * @returns {{ findings: Finding[], degradations: Array<{ reason: string }> }}
214
+ */
215
+ export function groundFindings({
216
+ findings,
217
+ headRef,
218
+ degradations = [],
219
+ cwd = process.cwd(),
220
+ gitSpawnFn = gitSpawn,
221
+ }) {
222
+ const git = (...args) => gitSpawnFn(cwd, ...args);
223
+ const all = [
224
+ ...degradations,
225
+ ...headDegradations({ findings, headRef, cwd, git }),
226
+ ];
227
+ return {
228
+ findings: groundEach(findings, headRef, git, reasonTokens(all)),
229
+ degradations: all,
230
+ };
231
+ }
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { isObject } from '../../json-utils.js';
9
+ import { CLAIM_SCHEMA } from './claim-grounding.js';
9
10
  import { buildFinding, unwrapEnvelope } from './parse-findings.js';
10
11
 
11
12
  export const FINDINGS_SCHEMA_JSON = JSON.stringify({
@@ -21,6 +22,7 @@ export const FINDINGS_SCHEMA_JSON = JSON.stringify({
21
22
  file: { type: 'string' },
22
23
  line: { type: 'integer' },
23
24
  category: { type: 'string' },
25
+ claim: CLAIM_SCHEMA,
24
26
  },
25
27
  required: ['title', 'body'],
26
28
  },
@@ -80,7 +80,12 @@ const PROMPT_HEAD =
80
80
  'The diff below is authoritative — files on disk may not reflect it. ' +
81
81
  'Answer with a JSON object of this exact shape, no prose around it:\n\n' +
82
82
  '{"findings":[{"title":"...","body":"Why it is wrong: ... How to show it ' +
83
- 'fails: ...","file":"...","line":1,"category":"bug"}]}\n\n' +
83
+ 'fails: ...","file":"...","line":1,"category":"bug","claim":null}]}\n\n' +
84
+ 'Set `claim` when the problem rests on a checkable fact: ' +
85
+ '{"kind":"path-absent","path":"<file>"} when a file the change needs is ' +
86
+ 'missing, or {"kind":"symbol-referenced","symbol":"<name>","path":"<its ' +
87
+ 'definition file>"} when a removed or renamed symbol still has callers. ' +
88
+ 'Otherwise leave it null.\n\n' +
84
89
  'Emit {"findings":[]} if there is nothing you would block the merge for.\n\n';
85
90
 
86
91
  /**
@@ -17,6 +17,7 @@ import { spawnCaptureAsync, spawnChild } from '../../child-exec.js';
17
17
  import { resolveAgentrcRoot } from '../../config/git-roots.js';
18
18
  import { resolvedTempRoot } from '../../config/temp-paths.js';
19
19
  import { resolveConfig } from '../../config-resolver.js';
20
+ import { STRICT_CLAIM_SCHEMA } from './claim-grounding.js';
20
21
  import { PROVIDER_SEVERITY_MAP } from './provider-severity.js';
21
22
  import { renderDepthDirective } from './review-depth.js';
22
23
 
@@ -47,7 +48,15 @@ const FINDINGS_SCHEMA = Object.freeze({
47
48
  items: {
48
49
  type: 'object',
49
50
  additionalProperties: false,
50
- required: ['severity', 'title', 'body', 'file', 'line', 'category'],
51
+ required: [
52
+ 'severity',
53
+ 'title',
54
+ 'body',
55
+ 'file',
56
+ 'line',
57
+ 'category',
58
+ 'claim',
59
+ ],
51
60
  properties: {
52
61
  severity: { type: 'string', enum: Object.keys(CODEX_SEVERITY_MAP) },
53
62
  title: { type: 'string' },
@@ -55,6 +64,7 @@ const FINDINGS_SCHEMA = Object.freeze({
55
64
  file: { type: ['string', 'null'] },
56
65
  line: { type: ['integer', 'null'] },
57
66
  category: { type: 'string' },
67
+ claim: STRICT_CLAIM_SCHEMA,
58
68
  },
59
69
  },
60
70
  },
@@ -7,6 +7,7 @@
7
7
  * @typedef {import('./types.js').Severity} Severity
8
8
  */
9
9
 
10
+ import { groundingNotes } from './claim-grounding.js';
10
11
  import {
11
12
  normalizeDegradations,
12
13
  renderDegradedGatesSection,
@@ -63,7 +64,9 @@ export function renderFinding(finding) {
63
64
  const attribution = buildAttribution(finding);
64
65
  const category = finding.category ? ` _[${finding.category}]_` : '';
65
66
  const header = `#### ${emoji} ${finding.title}${attribution}${category}`;
66
- return `${header}\n\n${finding.body}`;
67
+ return [`${header}\n\n${finding.body}`, ...groundingNotes(finding)].join(
68
+ '\n\n',
69
+ );
67
70
  }
68
71
 
69
72
  /**
@@ -2,11 +2,15 @@
2
2
 
3
3
  import { clip } from './claude-verdict.js';
4
4
 
5
- function sectionPath(section) {
5
+ export function diffSections(diff) {
6
+ return diff.split(/(?=^diff --git )/m);
7
+ }
8
+
9
+ export function sectionPath(section) {
6
10
  return /^diff --git a\/.+? b\/(.+)$/m.exec(section)?.[1] ?? null;
7
11
  }
8
12
 
9
- function generatedPaths(paths, { cwd, gitSpawnFn }) {
13
+ export function generatedPaths(paths, { cwd, gitSpawnFn }) {
10
14
  const generated = new Set();
11
15
  if (paths.length === 0) return generated;
12
16
  const result = gitSpawnFn(
@@ -29,7 +33,7 @@ function generatedPaths(paths, { cwd, gitSpawnFn }) {
29
33
 
30
34
  /** A failed attribute lookup leaves the diff whole. */
31
35
  function omitGeneratedFiles(diff, deps) {
32
- const sections = diff.split(/(?=^diff --git )/m);
36
+ const sections = diffSections(diff);
33
37
  const generated = generatedPaths(
34
38
  sections.map(sectionPath).filter(Boolean),
35
39
  deps,
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import { isObject } from '../../json-utils.js';
11
+ import { buildClaim } from './claim-grounding.js';
11
12
 
12
13
  /**
13
14
  * Unwrap a bare array, `{ findings }`, or either under `result`/`data`.
@@ -69,13 +70,19 @@ export function buildFinding(entry, { mapSeverity, defaultCategory }) {
69
70
  ? entry.category
70
71
  : defaultCategory;
71
72
  if (category !== undefined) finding.category = category;
73
+ return attachLocation(finding, entry);
74
+ }
72
75
 
76
+ /** Well-formed `file`, `line` and `claim` only. */
77
+ function attachLocation(finding, entry) {
73
78
  if (typeof entry.file === 'string' && entry.file.length > 0) {
74
79
  finding.file = entry.file;
75
80
  }
76
81
  if (Number.isInteger(entry.line) && entry.line > 0) {
77
82
  finding.line = entry.line;
78
83
  }
84
+ const claim = buildClaim(entry.claim);
85
+ if (claim) finding.claim = claim;
79
86
  return finding;
80
87
  }
81
88
 
@@ -198,31 +198,28 @@ export function buildProviderChain(entries, ctx) {
198
198
  }
199
199
 
200
200
  /**
201
- * @param {Record<string, number>} tally
202
- * @param {string} name
203
201
  * @param {Finding[]} findings
202
+ * @param {string} name
203
+ * @returns {Finding[]}
204
204
  */
205
- function recordCritical(tally, name, findings) {
206
- const critical = findings.filter((f) => f?.severity === 'critical').length;
207
- if (critical > 0) tally[name] = critical;
205
+ function stampProvider(findings, name) {
206
+ return findings.map((f) => ({ ...f, provider: name }));
208
207
  }
209
208
 
210
209
  /**
211
- * Inline findings merge in declaration order; prompt entries render via
210
+ * Inline findings merge in declaration order, each stamped with its entry's
211
+ * `provider` name for attribution; prompt entries render via
212
212
  * `getPromptMessages`.
213
213
  *
214
214
  * @param {ProviderChain} chain
215
215
  * @param {{ logger?: { info?: Function, warn?: Function } }} [opts]
216
216
  * @returns {ReviewProvider & {
217
217
  * getPromptMessages: (input: ReviewInput) => Promise<string[]>,
218
- * getCriticalByProvider: () => Record<string, number>,
219
218
  * chain: ProviderChain,
220
219
  * }}
221
220
  */
222
221
  export function createChainProvider(chain, opts = {}) {
223
222
  const logger = opts.logger;
224
- /** Critical findings per entry from the last `runReview`, for attribution. */
225
- let criticalByProvider = {};
226
223
 
227
224
  return {
228
225
  chain,
@@ -233,7 +230,6 @@ export function createChainProvider(chain, opts = {}) {
233
230
  async runReview(input) {
234
231
  /** @type {Finding[]} */
235
232
  const merged = [];
236
- criticalByProvider = {};
237
233
  const ctx = {
238
234
  scope: input?.scope,
239
235
  labels: /** @type {ReadonlyArray<string>} */ (
@@ -253,19 +249,10 @@ export function createChainProvider(chain, opts = {}) {
253
249
  `[code-review] Inline provider "${entry.name}" returned a non-array; expected Finding[].`,
254
250
  );
255
251
  }
256
- for (const f of findings) merged.push(f);
257
- recordCritical(criticalByProvider, entry.name, findings);
252
+ merged.push(...stampProvider(findings, entry.name));
258
253
  }
259
254
  return merged;
260
255
  },
261
- /**
262
- * Which entries raised the last run's critical findings, and how many.
263
- *
264
- * @returns {Record<string, number>}
265
- */
266
- getCriticalByProvider() {
267
- return { ...criticalByProvider };
268
- },
269
256
  /**
270
257
  * Called after `runReview`.
271
258
  *
@@ -11,6 +11,15 @@
11
11
  * @property {string=} file - Relative path, when attributable.
12
12
  * @property {number=} line - 1-based, when attributable.
13
13
  * @property {string=} category - e.g. 'security', 'lint'.
14
+ * @property {FindingClaim=} claim - Structured, checkable claim.
15
+ * @property {string=} ungrounded - Why a refuted critical was downgraded.
16
+ * @property {string=} context - 'reviewed-with-truncated-context'.
17
+ * @property {string=} provider - Chain entry that raised it.
18
+ *
19
+ * @typedef {object} FindingClaim
20
+ * @property {'path-absent'|'symbol-referenced'} kind
21
+ * @property {string=} path - Absent path, or the symbol's definition file.
22
+ * @property {string=} symbol
14
23
  *
15
24
  * @typedef {'story'} ReviewScope
16
25
  *
@@ -129,6 +129,7 @@ export async function computeStoryScopeReview({
129
129
  );
130
130
  const result = await runStoryReviewCore({
131
131
  storyId,
132
+ cwd,
132
133
  baseRef: base.ref,
133
134
  headRef,
134
135
  commentTargetId,
@@ -7,6 +7,11 @@ import { gitSpawn } from '../../../git-utils.js';
7
7
  import { computeChangeSet } from '../../change-set.js';
8
8
  import { runCodeReview } from '../../code-review.js';
9
9
 
10
+ const progressLogger = (progress, tag) => ({
11
+ info: (m) => progress(tag, m),
12
+ warn: (m) => progress(tag, `⚠️ ${m}`),
13
+ });
14
+
10
15
  /**
11
16
  * Run `runCodeReview` over one change set and return the review result.
12
17
  * Throws propagate; the caller picks the advisory posture. Review depth is
@@ -18,8 +23,12 @@ import { runCodeReview } from '../../code-review.js';
18
23
  * commit lands in between. An unenumerable diff injects `null` ("already
19
24
  * tried"), which the review honours without re-spawning git.
20
25
  *
26
+ * `cwd` is the reviewed repository: both the diff and claim grounding run
27
+ * there, never in the process cwd.
28
+ *
21
29
  * @param {{
22
30
  * storyId: number|string,
31
+ * cwd?: string,
23
32
  * baseRef: string,
24
33
  * headRef: string,
25
34
  * commentTargetId?: number|null,
@@ -35,6 +44,7 @@ import { runCodeReview } from '../../code-review.js';
35
44
  */
36
45
  export async function runStoryReviewCore({
37
46
  storyId,
47
+ cwd,
38
48
  baseRef,
39
49
  headRef,
40
50
  commentTargetId = null,
@@ -45,20 +55,18 @@ export async function runStoryReviewCore({
45
55
  computeChangeSetFn = computeChangeSet,
46
56
  runCodeReviewFn = runCodeReview,
47
57
  }) {
48
- const changeSet = computeChangeSetFn({ baseRef, headRef, gitSpawnFn });
58
+ const changeSet = computeChangeSetFn({ baseRef, headRef, cwd, gitSpawnFn });
49
59
 
50
60
  const opts = {
51
61
  scope: 'story',
52
62
  ticketId: Number(storyId),
63
+ cwd,
53
64
  baseRef,
54
65
  headRef,
55
66
  provider,
56
67
  changedFiles: changeSet.files,
57
68
  gitSpawnFn,
58
- logger: {
59
- info: (m) => progress(progressTag, m),
60
- warn: (m) => progress(progressTag, `⚠️ ${m}`),
61
- },
69
+ logger: progressLogger(progress, progressTag),
62
70
  };
63
71
  if (commentTargetId != null) {
64
72
  opts.commentTargetId = commentTargetId;