rungate 0.7.0 → 0.8.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 (63) hide show
  1. package/hooks/ActionVerificationGate.hook.ts +96 -0
  2. package/hooks/AgentBriefGuard.hook.ts +38 -0
  3. package/hooks/AgentVerdictCapture.hook.ts +87 -0
  4. package/hooks/AutoVerifyGate.hook.ts +79 -0
  5. package/hooks/BashToolGuard.hook.ts +65 -0
  6. package/hooks/BashWriteGuard.hook.ts +60 -0
  7. package/hooks/CommitEnforcement.hook.ts +130 -0
  8. package/hooks/DocHygiene.hook.ts +148 -0
  9. package/hooks/GateEnforcement.hook.ts +58 -0
  10. package/hooks/GateResultProtection.hook.ts +69 -0
  11. package/hooks/HarnessAFKGate.hook.ts +85 -0
  12. package/hooks/HookCurrency.hook.ts +99 -0
  13. package/hooks/IssueCloseGuard.hook.ts +149 -0
  14. package/hooks/MergeGuard.hook.ts +58 -0
  15. package/hooks/PostCompact.hook.ts +60 -0
  16. package/hooks/ProjectStateSync.hook.ts +103 -0
  17. package/hooks/SkillGuard.hook.ts +69 -0
  18. package/hooks/SpecConformityTrigger.hook.ts +43 -0
  19. package/hooks/SpecSCGuard.hook.ts +123 -0
  20. package/hooks/StaleTTLCleanup.hook.ts +141 -0
  21. package/hooks/TaskCompleted.hook.ts +51 -0
  22. package/hooks/TeamInit.hook.ts +85 -0
  23. package/hooks/TestSuiteGuard.hook.ts +70 -0
  24. package/hooks/TestSuiteRelease.hook.ts +85 -0
  25. package/hooks/TopLevelCdGuard.hook.ts +108 -0
  26. package/hooks/VerifyPhaseLock.hook.ts +84 -0
  27. package/hooks/WorkflowStateGuard.hook.ts +40 -0
  28. package/hooks/lib/agent-config.json +9 -0
  29. package/hooks/lib/agentDetection.ts +201 -0
  30. package/hooks/lib/comment-template.ts +86 -0
  31. package/hooks/lib/findWorkflow.ts +101 -0
  32. package/hooks/lib/parseStdin.ts +37 -0
  33. package/hooks/lib/paths.ts +111 -0
  34. package/hooks/lib/utils.ts +338 -0
  35. package/lib/affected-tests.ts +29 -0
  36. package/lib/bash-write-guard.ts +373 -0
  37. package/lib/branch-cleanup.ts +279 -7
  38. package/lib/config-trackable.ts +9 -0
  39. package/lib/distribution-currency.ts +55 -5
  40. package/lib/failure-intake.ts +7 -1
  41. package/lib/gate-enforcement.ts +222 -28
  42. package/lib/gate-names.ts +72 -0
  43. package/lib/gate-result-protection.ts +427 -0
  44. package/lib/intake-sources.ts +380 -0
  45. package/lib/late-env-spawn.ts +331 -0
  46. package/lib/launch-base.ts +128 -5
  47. package/lib/paths.ts +96 -3
  48. package/lib/phase2-decomposition.ts +1 -1
  49. package/lib/published-artifact.ts +162 -18
  50. package/lib/sc-id-cross-tree.ts +84 -8
  51. package/lib/scaffold/ai-review-findings.ts +7 -1
  52. package/lib/scaffold/ai-review-step.ts +861 -116
  53. package/lib/scaffold/defaults.ts +82 -1
  54. package/lib/scaffold/steps.ts +436 -44
  55. package/lib/security-verdict.ts +1 -1
  56. package/lib/shell-path-interpolation.ts +594 -0
  57. package/lib/text-dependents.ts +875 -0
  58. package/lib/workflow-security.ts +29 -0
  59. package/lib/workflow-taint.ts +732 -0
  60. package/lib/worktree-cleanup.ts +65 -38
  61. package/lib/worktree-repo.ts +32 -2
  62. package/package.json +3 -1
  63. package/scripts/check-installed-hook-currency.ts +825 -0
@@ -327,6 +327,37 @@ export function contentDifference(local: ArtifactFile[], published: ArtifactFile
327
327
 
328
328
  export type ArtifactReading = "MATCHED" | "DIVERGED" | "AHEAD" | "BEHIND" | "UNMEASURED";
329
329
 
330
+ /**
331
+ * WHICH condition produced a red (#1117). Never a verdict.
332
+ *
333
+ * #875 refuses two conditions that arrive looking alike — a registry nobody
334
+ * could reach, and a registry serving different software under this tree's
335
+ * version string. On 2026-10-21 they arrived together, were collapsed into
336
+ * one, and the first reading on four PRs was "my change broke something".
337
+ * They are not the same fact and they do not have the same remedy: a re-run
338
+ * clears the first and will never clear the second.
339
+ *
340
+ * Nothing here is consulted by `artifactViolations` or by `currencyRefusal`.
341
+ * A cause changes no verdict; it says whose red it is.
342
+ */
343
+ export type StandingCause =
344
+ /** The registry could not be read. External to this branch; a re-run may clear it. */
345
+ | "REGISTRY"
346
+ /** This checkout could not be packed — `npm`, the working tree, the runner. */
347
+ | "TOOLCHAIN"
348
+ /** The two version strings exist and cannot be ordered against each other. */
349
+ | "VERSIONS"
350
+ /** The comparison WAS taken and the two differ. Only a release clears it. */
351
+ | "CONTENT"
352
+ /** A reason arrived with no cause attached. Never attributed to a cause that did not claim it. */
353
+ | "UNCLASSIFIED";
354
+
355
+ /** A reason and the condition that produced it. */
356
+ export interface UnmeasuredReason {
357
+ cause: StandingCause;
358
+ text: string;
359
+ }
360
+
330
361
  export interface ArtifactStanding {
331
362
  reading: ArtifactReading;
332
363
  /** `package.json`'s version in the tree that was packed. */
@@ -340,9 +371,69 @@ export interface ArtifactStanding {
340
371
  /** Why `commitsAhead` is null, when it is. Reported; never gated on. */
341
372
  distanceNote: string | null;
342
373
  /** Non-empty exactly when `reading` is `UNMEASURED`. */
374
+ unmeasured: UnmeasuredReason[];
375
+ /**
376
+ * The same list, rendered. A projection of `unmeasured` computed in
377
+ * `artifactStanding` and nowhere else, so the two cannot disagree about
378
+ * what was wrong — a second list built beside it would always agree with
379
+ * this one and would survive any mutation of it.
380
+ */
343
381
  unmeasuredReasons: string[];
344
382
  }
345
383
 
384
+ /**
385
+ * One sentence per condition, declared once.
386
+ *
387
+ * A total `Record`, so a new `StandingCause` is a build error rather than a
388
+ * red with no sentence beside it — `.claude/rules/config-access.md`.
389
+ */
390
+ export const STANDING_CAUSE_HEADLINE: Record<StandingCause, string> = {
391
+ REGISTRY:
392
+ "REGISTRY — the npm registry could not be read from this runner. This is not your branch: " +
393
+ "nothing in the diff can cause it or clear it, and a re-run may.",
394
+ TOOLCHAIN:
395
+ "TOOLCHAIN — this checkout could not be packed, so there was nothing to compare the registry " +
396
+ "against. Your branch only if it changed packaging.",
397
+ VERSIONS:
398
+ "VERSIONS — the tree's version and the registry's cannot be ordered against each other. " +
399
+ "This tree; a re-run will not clear it.",
400
+ CONTENT:
401
+ "CONTENT — the registry and this tree are DIFFERENT SOFTWARE under one version string. " +
402
+ "This repository, standing, and not your branch: only a release clears it, and a re-run never will.",
403
+ UNCLASSIFIED:
404
+ "UNCLASSIFIED — a reason arrived with no condition attached, so nobody can say whose red this " +
405
+ "is. Treat it as unmeasured and tag the reason at the point that produces it.",
406
+ };
407
+
408
+ /**
409
+ * The single binding that says which condition produced a standing's red.
410
+ *
411
+ * One binding, so there is one thing to mutate. It reads the causes the
412
+ * producers attached; it does not re-derive them from the rendered text,
413
+ * which would be a second decider that agrees with the first on every input
414
+ * anyone has — and a detector narrower than what it detects besides.
415
+ *
416
+ * Empty for a standing that does not refuse. Order is the order the reasons
417
+ * arrived in, de-duplicated, so a standing with two registry reasons names
418
+ * the registry once.
419
+ */
420
+ export function standingCauses(s: ArtifactStanding): StandingCause[] {
421
+ if (s.reading === "UNMEASURED") {
422
+ const seen: StandingCause[] = [];
423
+ for (const r of s.unmeasured) if (!seen.includes(r.cause)) seen.push(r.cause);
424
+ return seen;
425
+ }
426
+ if (s.reading === "DIVERGED") return ["CONTENT"];
427
+ return [];
428
+ }
429
+
430
+ /** Every condition behind a red, as sentences. `""` when nothing refuses. */
431
+ export function standingHeadline(s: ArtifactStanding): string {
432
+ return standingCauses(s)
433
+ .map(c => STANDING_CAUSE_HEADLINE[c])
434
+ .join(" ");
435
+ }
436
+
346
437
  /** `0.6.0` → `[0,6,0]`; anything else → `null`. Prerelease suffixes are ignored. */
347
438
  function parts(v: string): [number, number, number] | null {
348
439
  const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
@@ -360,6 +451,21 @@ export function compareVersions(a: string, b: string): -1 | 0 | 1 | null {
360
451
  return 0;
361
452
  }
362
453
 
454
+ /**
455
+ * The only place the two reason views are built, so they cannot disagree.
456
+ *
457
+ * `unmeasuredReasons` is the repo-wide shape every other `UNMEASURED` reading
458
+ * in this tree carries, and callers of it are unchanged; `unmeasured` is the
459
+ * same list with the condition still attached. Deriving one from the other
460
+ * here is the difference between two projections and two deciders.
461
+ */
462
+ function project(reasons: UnmeasuredReason[]): {
463
+ unmeasured: UnmeasuredReason[];
464
+ unmeasuredReasons: string[];
465
+ } {
466
+ return { unmeasured: reasons, unmeasuredReasons: reasons.map(r => r.text) };
467
+ }
468
+
363
469
  /**
364
470
  * The single place that turns the readings into a verdict.
365
471
  *
@@ -372,6 +478,14 @@ export function artifactStanding(input: {
372
478
  difference: ContentDifference | null;
373
479
  commitsAhead?: number | null;
374
480
  distanceNote?: string | null;
481
+ /** Reasons carrying the condition that produced them. Preferred (#1117). */
482
+ unmeasured?: UnmeasuredReason[];
483
+ /**
484
+ * Reasons with no condition attached. Accepted, and classified
485
+ * `UNCLASSIFIED` rather than folded into whichever cause looks likeliest —
486
+ * a reason attributed to a condition that did not claim it is worse than
487
+ * one that says nobody tagged it.
488
+ */
375
489
  unmeasuredReasons?: string[];
376
490
  }): ArtifactStanding {
377
491
  const base = {
@@ -381,12 +495,30 @@ export function artifactStanding(input: {
381
495
  commitsAhead: input.commitsAhead ?? null,
382
496
  distanceNote: input.distanceNote ?? null,
383
497
  };
384
- const reasons = [...(input.unmeasuredReasons ?? [])];
385
- if (input.treeVersion === null) reasons.push("the tree's version could not be read");
386
- if (input.publishedVersion === null) reasons.push("the registry's published version could not be read");
387
- if (input.difference === null) reasons.push("the content comparison was not performed");
498
+ /** One list. `unmeasured` and `unmeasuredReasons` are both read off it. */
499
+ const reasons: UnmeasuredReason[] = [
500
+ ...(input.unmeasured ?? []),
501
+ ...(input.unmeasuredReasons ?? []).map(text => ({ cause: "UNCLASSIFIED" as const, text })),
502
+ ];
503
+ // The three below are CONSEQUENCES of a reading that failed, so each is
504
+ // attributed to the input that failed and never to `CONTENT`. `CONTENT` is
505
+ // reachable only from `DIVERGED` — a comparison that was taken. That is
506
+ // what stops an unreachable registry reporting a divergence it never
507
+ // measured, which is #1117's whole complaint.
508
+ if (input.treeVersion === null) {
509
+ reasons.push({ cause: "TOOLCHAIN", text: "the tree's version could not be read" });
510
+ }
511
+ if (input.publishedVersion === null) {
512
+ reasons.push({ cause: "REGISTRY", text: "the registry's published version could not be read" });
513
+ }
514
+ if (input.difference === null) {
515
+ reasons.push({
516
+ cause: input.treeVersion === null ? "TOOLCHAIN" : "REGISTRY",
517
+ text: "the content comparison was not performed",
518
+ });
519
+ }
388
520
  if (reasons.length > 0) {
389
- return { ...base, reading: "UNMEASURED", unmeasuredReasons: reasons };
521
+ return { ...base, reading: "UNMEASURED", ...project(reasons) };
390
522
  }
391
523
 
392
524
  const order = compareVersions(input.treeVersion!, input.publishedVersion!);
@@ -394,17 +526,20 @@ export function artifactStanding(input: {
394
526
  return {
395
527
  ...base,
396
528
  reading: "UNMEASURED",
397
- unmeasuredReasons: [
398
- `cannot order ${JSON.stringify(input.treeVersion)} against ${JSON.stringify(input.publishedVersion)}`,
399
- ],
529
+ ...project([
530
+ {
531
+ cause: "VERSIONS",
532
+ text: `cannot order ${JSON.stringify(input.treeVersion)} against ${JSON.stringify(input.publishedVersion)}`,
533
+ },
534
+ ]),
400
535
  };
401
536
  }
402
- if (order > 0) return { ...base, reading: "AHEAD", unmeasuredReasons: [] };
403
- if (order < 0) return { ...base, reading: "BEHIND", unmeasuredReasons: [] };
537
+ if (order > 0) return { ...base, reading: "AHEAD", ...project([]) };
538
+ if (order < 0) return { ...base, reading: "BEHIND", ...project([]) };
404
539
  return {
405
540
  ...base,
406
541
  reading: contentAgrees(input.difference!) ? "MATCHED" : "DIVERGED",
407
- unmeasuredReasons: [],
542
+ ...project([]),
408
543
  };
409
544
  }
410
545
 
@@ -414,11 +549,16 @@ export function artifactStanding(input: {
414
549
  * A projection of `reading` and nothing else — a second predicate over the
415
550
  * same facts would always agree with this one and would survive any mutation
416
551
  * of it.
552
+ *
553
+ * `standingHeadline` leads each message (#1117) and is not consulted by the
554
+ * branch above it: the set of states this refuses is exactly what it was.
555
+ * A cause makes a red legible; it never makes one go away.
417
556
  */
418
557
  export function artifactViolations(s: ArtifactStanding): string[] {
419
558
  if (s.reading === "UNMEASURED") {
420
559
  return [
421
- `UNMEASURED: the published artifact was not compared against this tree — ` +
560
+ `${standingHeadline(s)} ` +
561
+ `UNMEASURED: the published artifact was not compared against this tree — ` +
422
562
  s.unmeasuredReasons.join("; ") +
423
563
  `. A comparison that could not be taken is not one that passed.`,
424
564
  ];
@@ -426,7 +566,8 @@ export function artifactViolations(s: ArtifactStanding): string[] {
426
566
  if (s.reading === "DIVERGED") {
427
567
  const d = s.difference!;
428
568
  return [
429
- `rungate@${s.publishedVersion} on the registry and the ${s.treeVersion} tree are ` +
569
+ `${standingHeadline(s)} ` +
570
+ `rungate@${s.publishedVersion} on the registry and the ${s.treeVersion} tree are ` +
430
571
  `DIFFERENT SOFTWARE under the SAME version string: ${d.differing.length} of the published ` +
431
572
  `artifact's ${d.publishedCount} files differ in content, ${d.onlyLocal.length} files the ` +
432
573
  `tree would publish are absent from it, and ${d.onlyPublished.length} of its files are gone ` +
@@ -480,7 +621,10 @@ export async function measureArtifactStanding(opts: {
480
621
  let treeVersion: string | null = null;
481
622
  let publishedVersion: string | null = null;
482
623
  let difference: ContentDifference | null = null;
483
- const reasons: string[] = [];
624
+ // Each catch tags its own reason, because the catch is the only position
625
+ // that knows which reading failed. A classifier downstream would have to
626
+ // guess from the text, which is a detector narrower than what it detects.
627
+ const reasons: UnmeasuredReason[] = [];
484
628
 
485
629
  let local: ArtifactFile[] = [];
486
630
  try {
@@ -488,13 +632,13 @@ export async function measureArtifactStanding(opts: {
488
632
  treeVersion = pack.version;
489
633
  local = pack.files;
490
634
  } catch (e) {
491
- reasons.push((e as Error).message);
635
+ reasons.push({ cause: "TOOLCHAIN", text: (e as Error).message });
492
636
  }
493
637
 
494
638
  try {
495
639
  publishedVersion = await opts.latestVersion(opts.pkg);
496
640
  } catch (e) {
497
- reasons.push(`registry: ${(e as Error).message}`);
641
+ reasons.push({ cause: "REGISTRY", text: `registry: ${(e as Error).message}` });
498
642
  }
499
643
 
500
644
  if (publishedVersion !== null && local.length > 0) {
@@ -505,7 +649,7 @@ export async function measureArtifactStanding(opts: {
505
649
  });
506
650
  difference = contentDifference(local, remote);
507
651
  } catch (e) {
508
- reasons.push((e as Error).message);
652
+ reasons.push({ cause: "REGISTRY", text: (e as Error).message });
509
653
  }
510
654
  }
511
655
 
@@ -520,6 +664,6 @@ export async function measureArtifactStanding(opts: {
520
664
  difference,
521
665
  commitsAhead: distance.commits,
522
666
  distanceNote: distance.note,
523
- unmeasuredReasons: reasons,
667
+ unmeasured: reasons,
524
668
  });
525
669
  }
@@ -51,7 +51,7 @@
51
51
  * on, which is the fastest way to build a refusal everyone learns to click
52
52
  * past. Fix the allocator that mints collisions; do not alarm on the fossils.
53
53
  */
54
- import { execFileSync } from "child_process";
54
+ import { execFileSync, spawnSync } from "child_process";
55
55
  import { existsSync, readdirSync, readFileSync, statSync } from "fs";
56
56
  import { join } from "path";
57
57
 
@@ -175,22 +175,92 @@ function idsInSpecsDir(specsDir: string): string[] {
175
175
  return ids;
176
176
  }
177
177
 
178
+ /**
179
+ * One ref per distinct `specs/` tree, and `null` if that cannot be worked out.
180
+ *
181
+ * `git grep <ref>` searches that ref's tree from scratch. Two refs whose
182
+ * `specs/` is the SAME tree object therefore do the same search twice and
183
+ * return the same lines, because the ids are a pure function of the bytes
184
+ * under `specs/` and a tree SHA is a hash of exactly those bytes. Dropping
185
+ * the second is not a narrowing of what is read — it is the same reading with
186
+ * the repeats removed, which is why it needs no judgement call about which
187
+ * branches "matter". Measured on this repository: 1638 refs, 326 distinct
188
+ * trees, identical id set of 1656 — 0 missing, 0 extra (#1132).
189
+ *
190
+ * 533 of those refs resolve to no `specs/` at all and are dropped outright. A
191
+ * ref with no `specs/` directory cannot match `-- specs/*.md`, so grepping it
192
+ * was always going to return nothing.
193
+ *
194
+ * `null` means the question could not be answered — a `git` that does not
195
+ * support the batching, or output that does not line up with the input. The
196
+ * caller then greps every ref, which is slow and correct. Guessing at a
197
+ * partial mapping would be fast and wrong, and the wrongness is a reissued
198
+ * id rather than an error anyone would see.
199
+ */
200
+ function refsByDistinctSpecsTree(root: string, refs: string[]): string[] | null {
201
+ const probe = spawnSync("git", ["cat-file", "--batch-check=%(objectname) %(objecttype)"], {
202
+ cwd: root,
203
+ input: refs.map(r => `${r}^{tree}:specs\n`).join(""),
204
+ encoding: "utf-8",
205
+ timeout: 120_000,
206
+ maxBuffer: 64 * 1024 * 1024,
207
+ });
208
+ if (probe.error || probe.status !== 0) return null;
209
+ const lines = (probe.stdout ?? "").split("\n").filter(l => l !== "");
210
+ // One line in, one line out. If that does not hold, the index below is
211
+ // pairing a SHA with the wrong ref, and a representative chosen for the
212
+ // wrong tree drops ids that are really there.
213
+ if (lines.length !== refs.length) return null;
214
+
215
+ const representative = new Map<string, string>();
216
+ for (let i = 0; i < lines.length; i++) {
217
+ // `<sha> tree` for a ref that has one; `<input> missing` for a ref that
218
+ // does not. Only the first shape is a tree worth searching.
219
+ const match = /^([0-9a-f]{40}) tree$/.exec(lines[i]);
220
+ if (match === null) continue;
221
+ if (!representative.has(match[1])) representative.set(match[1], refs[i]);
222
+ }
223
+ return [...representative.values()];
224
+ }
225
+
178
226
  /**
179
227
  * Ids declared in `specs/` on any ref this repository holds — local branches
180
228
  * and remote-tracking branches both.
181
229
  *
182
230
  * One `git grep` over every ref at once rather than a checkout each: measured
183
231
  * at 0.17s over 1087 refs, against minutes for the obvious implementation.
232
+ *
233
+ * ## …and at 1638 refs that was 7.3s, on the hot path of allocating one id
234
+ *
235
+ * The comment above aged into a wrong number rather than a stale one (#1132).
236
+ * `git grep` over N refs costs N tree searches, and this repository grew from
237
+ * 1087 refs to 1638 while the work per ref stayed the same, so allocating a
238
+ * single SC id came to 17.4s end to end — past the 15s its own caller allows
239
+ * it. The cost is in the ref COUNT, and the ref count is a fact about how
240
+ * many branches are in flight, not about the change being made.
241
+ *
242
+ * `refsByDistinctSpecsTree` removes the repeats rather than picking a
243
+ * narrower population, so the id set is unchanged by construction. The
244
+ * tempting fix is to read `origin/main` only; measured here that reads 1646
245
+ * ids of 1656, and the ten it loses are the ids on unmerged branches, which
246
+ * are precisely the ones this leg exists to see (#503). Its highest id
247
+ * happened to match, so the allocated number was identical and the loss would
248
+ * not have shown up as a wrong answer until the day it collided.
249
+ *
250
+ * `grepped` is reported next to `refs` so a test can bind the scoping without
251
+ * binding a clock — a wall-clock assertion over this is flaky by
252
+ * construction, and the thing that makes it slow is the count.
184
253
  */
185
- function idsInRefs(root: string): { ids: string[]; refs: number; failure: string | null } {
254
+ export function idsInRefs(root: string): { ids: string[]; refs: number; grepped: number; failure: string | null } {
186
255
  let refList: string;
187
256
  try {
188
257
  refList = git(root, ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/remotes"]);
189
258
  } catch (err) {
190
- return { ids: [], refs: 0, failure: (err as Error).message.split("\n")[0] };
259
+ return { ids: [], refs: 0, grepped: 0, failure: (err as Error).message.split("\n")[0] };
191
260
  }
192
- const refs = refList.split("\n").filter(r => r.trim() !== "");
193
- if (refs.length === 0) return { ids: [], refs: 0, failure: null };
261
+ const allRefs = refList.split("\n").filter(r => r.trim() !== "");
262
+ if (allRefs.length === 0) return { ids: [], refs: 0, grepped: 0, failure: null };
263
+ const refs = refsByDistinctSpecsTree(root, allRefs) ?? allRefs;
194
264
 
195
265
  const ids: string[] = [];
196
266
  // Batched: a ref list this long overruns the argument limit in one call.
@@ -214,12 +284,12 @@ function idsInRefs(root: string): { ids: string[]; refs: number; failure: string
214
284
  // a failure. Anything else is a failure, and the caller must hear it.
215
285
  const status = (err as { status?: number }).status;
216
286
  if (status === 1) continue;
217
- return { ids, refs: refs.length, failure: (err as Error).message.split("\n")[0] };
287
+ return { ids, refs: allRefs.length, grepped: refs.length, failure: (err as Error).message.split("\n")[0] };
218
288
  }
219
289
  for (const m of out.matchAll(scDeclarationPattern())) ids.push(m[2]);
220
290
  for (const m of out.matchAll(scHeadingDeclarationPattern())) ids.push(m[1]);
221
291
  }
222
- return { ids, refs: refs.length, failure: null };
292
+ return { ids, refs: allRefs.length, grepped: refs.length, failure: null };
223
293
  }
224
294
 
225
295
  /**
@@ -283,7 +353,13 @@ export function readScNamespace(root: string): ScNamespaceReading {
283
353
  } else {
284
354
  for (const id of refs.ids) record(id, "refs");
285
355
  sources.push({
286
- label: `refs (${refs.refs} local and remote-tracking)`,
356
+ // Both numbers, because they are different facts. `refs` is how wide
357
+ // the reading was; `grepped` is how many searches that cost. Printing
358
+ // only the second would read as a narrower reading than it is, and
359
+ // printing only the first hides the one number #1132 was about.
360
+ label: refs.grepped === refs.refs
361
+ ? `refs (${refs.refs} local and remote-tracking)`
362
+ : `refs (${refs.refs} local and remote-tracking, ${refs.grepped} distinct specs/ trees searched)`,
287
363
  kind: "refs",
288
364
  status: "read",
289
365
  found: new Set(refs.ids).size,
@@ -66,6 +66,7 @@ import {
66
66
  AI_REVIEW_BLOCK_VERDICT,
67
67
  AI_REVIEW_FINDING_FIELDS,
68
68
  AI_REVIEW_FINDINGS_KEY,
69
+ AI_REVIEW_OUTCOME_LINE,
69
70
  AI_REVIEW_PASS_VERDICT,
70
71
  AI_REVIEW_REQUIRED_EXIT,
71
72
  AI_REVIEW_SEVERITIES,
@@ -77,6 +78,7 @@ export {
77
78
  AI_REVIEW_BLOCK_VERDICT,
78
79
  AI_REVIEW_FINDING_FIELDS,
79
80
  AI_REVIEW_FINDINGS_KEY,
81
+ AI_REVIEW_OUTCOME_LINE,
80
82
  AI_REVIEW_PASS_VERDICT,
81
83
  AI_REVIEW_SEVERITIES,
82
84
  AI_REVIEW_SEVERITY_KEY,
@@ -384,7 +386,11 @@ export function main(argv: string[]): number {
384
386
  )
385
387
  : readAiReviewFindingsFile(path);
386
388
 
387
- console.log(`ai-review findings outcome: ${reading.outcome}`);
389
+ // FIRST, and before any branch below can return. The generated workflow step
390
+ // greps its own output for this prefix and will not read the exit code as a
391
+ // verdict without it (#1013) — an adjudicator that could not run and one that
392
+ // refused both exit non-zero, and only this line tells them apart.
393
+ console.log(`${AI_REVIEW_OUTCOME_LINE} ${reading.outcome}`);
388
394
 
389
395
  // The ONE place a value reaches a workflow command. Everything upstream of
390
396
  // here — `renderFinding`, every `detail` sentence, `aiReviewRefusal` — builds