mandrel 2.104.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.
@@ -80,11 +80,14 @@ function resolveStoryScope(opts, config) {
80
80
  /**
81
81
  * Run a Story-scope review. `headRef` is required; `baseRef` defaults to
82
82
  * the remote base branch; `commentTargetId` (e.g. a PR number) overrides
83
- * the post target while `ticketId` still labels the header.
83
+ * the post target while `ticketId` still labels the header. `cwd` is the
84
+ * reviewed repository the diff and claim grounding run in; unset, they fall
85
+ * back to `process.cwd()`.
84
86
  *
85
87
  * @param {{
86
88
  * scope?: 'story',
87
89
  * ticketId: number,
90
+ * cwd?: string,
88
91
  * baseRef?: string|null,
89
92
  * headRef?: string|null,
90
93
  * commentTargetId?: number|null,
@@ -144,8 +147,12 @@ function resolveProviderName(codeReviewConfig, reviewProvider) {
144
147
  */
145
148
  function resolveInjectedChangedFiles({ opts, baseRef, headRef }) {
146
149
  if (opts.changedFiles === undefined) {
147
- return computeChangeSet({ baseRef, headRef, gitSpawnFn: opts.gitSpawnFn })
148
- .files;
150
+ return computeChangeSet({
151
+ baseRef,
152
+ headRef,
153
+ cwd: opts.cwd,
154
+ gitSpawnFn: opts.gitSpawnFn,
155
+ }).files;
149
156
  }
150
157
  return Array.isArray(opts.changedFiles) ? opts.changedFiles : null;
151
158
  }
@@ -258,6 +265,24 @@ function resolveCriticalByProvider({ findings, providerName, severity }) {
258
265
  return tally;
259
266
  }
260
267
 
268
+ /** Tally, halt verdict and per-provider criticals of grounded findings. */
269
+ function scoreFindings(findings, providerName) {
270
+ const severity = countBySeverity(findings);
271
+ const halted = hasSurvivingCritical(severity);
272
+ return {
273
+ severity,
274
+ halted,
275
+ criticalByProvider: resolveCriticalByProvider({
276
+ findings,
277
+ providerName,
278
+ severity,
279
+ }),
280
+ blockerReason: halted
281
+ ? `code-review reported ${severity.critical} critical blocker(s)`
282
+ : null,
283
+ };
284
+ }
285
+
261
286
  async function executeReviewPipeline({ opts, config, envelope }) {
262
287
  const {
263
288
  provider,
@@ -300,23 +325,14 @@ async function executeReviewPipeline({ opts, config, envelope }) {
300
325
  );
301
326
 
302
327
  // Degraded gates ride beside the findings, never inside them.
303
- const degradations = await collectProviderDegradations(
304
- reviewProvider,
305
- logger,
306
- );
307
- const findings = groundFindings({
328
+ const { findings, degradations } = groundFindings({
308
329
  findings: rawFindings,
309
330
  headRef,
310
- degradations,
331
+ cwd: opts.cwd,
332
+ degradations: await collectProviderDegradations(reviewProvider, logger),
311
333
  gitSpawnFn: opts.gitSpawnFn,
312
334
  });
313
- const severity = countBySeverity(findings);
314
- const halted = hasSurvivingCritical(severity);
315
- const criticalByProvider = resolveCriticalByProvider({
316
- findings,
317
- providerName,
318
- severity,
319
- });
335
+ const scored = scoreFindings(findings, providerName);
320
336
  const report = renderFindingsFn({
321
337
  scope,
322
338
  ticketId,
@@ -338,19 +354,17 @@ async function executeReviewPipeline({ opts, config, envelope }) {
338
354
 
339
355
  return {
340
356
  status: 'ok',
341
- severity,
357
+ severity: scored.severity,
342
358
  findings,
343
359
  providerName,
344
360
  report,
345
361
  posted,
346
362
  postedCommentId,
347
363
  commentTargetId,
348
- halted,
349
- criticalByProvider,
364
+ halted: scored.halted,
365
+ criticalByProvider: scored.criticalByProvider,
350
366
  ...degradationEnvelope(degradations),
351
- blockerReason: halted
352
- ? `code-review reported ${severity.critical} critical blocker(s)`
353
- : null,
367
+ blockerReason: scored.blockerReason,
354
368
  };
355
369
  }
356
370
 
@@ -130,8 +130,8 @@ const REFUTERS = {
130
130
 
131
131
  /** @returns {Finding} */
132
132
  function groundFinding(finding, headRef, git) {
133
- const refute = REFUTERS[finding?.claim?.kind];
134
- if (finding?.severity !== 'critical' || !refute) return finding;
133
+ if (!isGroundable(finding)) return finding;
134
+ const refute = REFUTERS[finding.claim.kind];
135
135
  let evidence = null;
136
136
  try {
137
137
  evidence = refute(finding.claim, headRef, git);
@@ -142,6 +142,40 @@ function groundFinding(finding, headRef, git) {
142
142
  return { ...finding, severity: 'suggestion', ungrounded: evidence };
143
143
  }
144
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
+
145
179
  /** Names a degradation reason carries, split on its list punctuation. */
146
180
  function reasonTokens(degradations) {
147
181
  return new Set(
@@ -155,7 +189,20 @@ function annotateContext(finding, tokens) {
155
189
  return { ...finding, context: TRUNCATED_CONTEXT };
156
190
  }
157
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
+
158
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
+ *
159
206
  * @param {{
160
207
  * findings: Finding[],
161
208
  * headRef: string,
@@ -163,7 +210,7 @@ function annotateContext(finding, tokens) {
163
210
  * cwd?: string,
164
211
  * gitSpawnFn?: typeof gitSpawn,
165
212
  * }} args
166
- * @returns {Finding[]}
213
+ * @returns {{ findings: Finding[], degradations: Array<{ reason: string }> }}
167
214
  */
168
215
  export function groundFindings({
169
216
  findings,
@@ -173,11 +220,12 @@ export function groundFindings({
173
220
  gitSpawnFn = gitSpawn,
174
221
  }) {
175
222
  const git = (...args) => gitSpawnFn(cwd, ...args);
176
- const tokens = reasonTokens(degradations);
177
- return findings.map((finding) => {
178
- const grounded = groundFinding(finding, headRef, git);
179
- return grounded && tokens.size > 0
180
- ? annotateContext(grounded, tokens)
181
- : grounded;
182
- });
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
+ };
183
231
  }
@@ -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;
package/docs/CHANGELOG.md CHANGED
@@ -15,6 +15,13 @@ All notable changes to this project will be documented in this file.
15
15
  -->
16
16
  <!-- markdownlint-disable-file MD004 MD012 MD037 -->
17
17
 
18
+ ## [2.105.0](https://github.com/dsj1984/mandrel/compare/mandrel-v2.104.0...mandrel-v2.105.0) (2026-10-26)
19
+
20
+
21
+ ### Fixed
22
+
23
+ * ground held-review claims in the reviewed repository's cwd, not the process cwd ([#5909](https://github.com/dsj1984/mandrel/issues/5909)) ([#5910](https://github.com/dsj1984/mandrel/issues/5910)) ([a86c601](https://github.com/dsj1984/mandrel/commit/a86c60138abc68ed3ec9c6ffd332cc4d98c5a37c))
24
+
18
25
  ## [2.104.0](https://github.com/dsj1984/mandrel/compare/mandrel-v2.103.0...mandrel-v2.104.0) (2026-10-25)
19
26
 
20
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mandrel",
3
- "version": "2.104.0",
3
+ "version": "2.105.0",
4
4
  "description": "Claude Code-first opinionated workflow framework: instructions, skills, rules, and SDLC workflows that govern AI coding assistants.",
5
5
  "files": [
6
6
  ".agents/",