mandrel 2.123.0 → 2.125.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 (105) hide show
  1. package/.agents/README.md +1 -1
  2. package/.agents/docs/agentrc-reference.json +2 -0
  3. package/.agents/docs/configuration.md +6 -3
  4. package/.agents/docs/runbooks/dispatch-board.md +174 -0
  5. package/.agents/docs/runbooks/dispatch.md +219 -0
  6. package/.agents/docs/runbooks/session-titles.md +52 -0
  7. package/.agents/runtime-deps.json +2 -2
  8. package/.agents/schemas/agentrc.schema.json +85 -3
  9. package/.agents/schemas/audit-rules.schema.json +1 -1
  10. package/.agents/schemas/story-deliver-terminal.schema.json +7 -2
  11. package/.agents/scripts/acceptance-eval.js +11 -2
  12. package/.agents/scripts/check-doc-links.js +4 -4
  13. package/.agents/scripts/dispatch.js +400 -0
  14. package/.agents/scripts/lib/audit-baselines/surface-entry.js +2 -2
  15. package/.agents/scripts/lib/audit-exceptions/globs.js +2 -2
  16. package/.agents/scripts/lib/audit-exceptions/scope.js +2 -2
  17. package/.agents/scripts/lib/audit-suite/selector.js +3 -3
  18. package/.agents/scripts/lib/baselines/bundle-size-scorer.js +3 -3
  19. package/.agents/scripts/lib/baselines/components.js +2 -2
  20. package/.agents/scripts/lib/baselines/kinds/_crap-new-method-gate.js +2 -2
  21. package/.agents/scripts/lib/bdd-runner-detect.js +3 -4
  22. package/.agents/scripts/lib/child-detached.js +48 -0
  23. package/.agents/scripts/lib/child-exec.js +11 -0
  24. package/.agents/scripts/lib/close-validation/base-sync-revalidation.js +2 -2
  25. package/.agents/scripts/lib/config/delivery-routing.js +15 -12
  26. package/.agents/scripts/lib/config/gates/coverage.schema.js +1 -1
  27. package/.agents/scripts/lib/config/handoff.js +21 -6
  28. package/.agents/scripts/lib/config/temp-paths.js +26 -0
  29. package/.agents/scripts/lib/config-settings-schema-delivery.js +64 -10
  30. package/.agents/scripts/lib/config-settings-schema-quality.js +1 -1
  31. package/.agents/scripts/lib/coverage-baseline.js +3 -3
  32. package/.agents/scripts/lib/coverage-capture-delta.js +2 -2
  33. package/.agents/scripts/lib/coverage-capture-own-fix.js +2 -2
  34. package/.agents/scripts/lib/dispatch/environments.js +135 -0
  35. package/.agents/scripts/lib/dispatch/launch-cloud.js +164 -0
  36. package/.agents/scripts/lib/dispatch/launch-local.js +77 -0
  37. package/.agents/scripts/lib/dispatch/liveness.js +21 -0
  38. package/.agents/scripts/lib/dispatch/record.js +54 -0
  39. package/.agents/scripts/lib/dispatch/status.js +285 -0
  40. package/.agents/scripts/lib/dispatch/targets.js +101 -0
  41. package/.agents/scripts/lib/dispatch/verdict.js +207 -0
  42. package/.agents/scripts/lib/generated/agentrc-validator.js +2 -2
  43. package/.agents/scripts/lib/git-test-guard.js +119 -0
  44. package/.agents/scripts/lib/git-utils.js +3 -0
  45. package/.agents/scripts/lib/maintainability-utils.js +4 -4
  46. package/.agents/scripts/lib/observability/handoff-telemetry.js +2 -0
  47. package/.agents/scripts/lib/observability/source-classifier.js +2 -0
  48. package/.agents/scripts/lib/orchestration/acceptance-eval-decision.js +3 -2
  49. package/.agents/scripts/lib/orchestration/block-class-recovery.js +44 -0
  50. package/.agents/scripts/lib/orchestration/code-review.js +35 -19
  51. package/.agents/scripts/lib/orchestration/diff-magnitude.js +1 -1
  52. package/.agents/scripts/lib/orchestration/git-cleanup/phases/filters.js +3 -3
  53. package/.agents/scripts/lib/orchestration/plan-persist/audit-attribution.js +3 -4
  54. package/.agents/scripts/lib/orchestration/review-history.js +9 -10
  55. package/.agents/scripts/lib/orchestration/review-providers/code-review.js +9 -2
  56. package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +8 -5
  57. package/.agents/scripts/lib/orchestration/review-providers/codex.js +3 -11
  58. package/.agents/scripts/lib/orchestration/review-providers/mi-exemptions.js +2 -2
  59. package/.agents/scripts/lib/orchestration/review-providers/review-depth.js +22 -0
  60. package/.agents/scripts/lib/orchestration/review-providers/security-review.js +10 -2
  61. package/.agents/scripts/lib/orchestration/review-providers/types.js +2 -0
  62. package/.agents/scripts/lib/orchestration/review-providers/ultrareview.js +13 -2
  63. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +40 -15
  64. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +2 -0
  65. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +8 -1
  66. package/.agents/scripts/lib/orchestration/story-handoff.js +222 -54
  67. package/.agents/scripts/lib/orchestration/story-stage-publish.js +147 -0
  68. package/.agents/scripts/lib/orchestration/ticketing/reads.js +2 -0
  69. package/.agents/scripts/lib/test-temp.js +5 -5
  70. package/.agents/scripts/lib/test-tiers.js +3 -3
  71. package/.agents/scripts/lib/util/glob-match.js +64 -0
  72. package/.agents/scripts/lib/wave-runner/footprint.js +3 -3
  73. package/.agents/scripts/run-tests.js +2 -1
  74. package/.agents/scripts/session-title.js +187 -0
  75. package/.agents/scripts/single-story-confirm-merge.js +7 -0
  76. package/.agents/scripts/single-story-init.js +6 -3
  77. package/.agents/workflows/helpers/audit-lens-core.md +4 -0
  78. package/.agents/workflows/helpers/code-review.md +8 -1
  79. package/.agents/workflows/helpers/deliver-digest.md +22 -23
  80. package/.agents/workflows/helpers/deliver-light.md +4 -1
  81. package/.agents/workflows/helpers/deliver-reference.md +55 -24
  82. package/.agents/workflows/helpers/deliver-story-reference.md +10 -3
  83. package/.agents/workflows/helpers/deliver-story.md +27 -7
  84. package/.agents/workflows/helpers/qa-core.md +2 -0
  85. package/.agents/workflows/mandrel-deliver.md +14 -4
  86. package/.agents/workflows/mandrel-orchestrate.md +2 -0
  87. package/.agents/workflows/mandrel-plan.md +4 -0
  88. package/README.md +8 -0
  89. package/bin/mandrel.js +35 -13
  90. package/docs/CHANGELOG.md +29 -0
  91. package/lib/cli/dispatch.js +27 -0
  92. package/lib/cli/ui/accounts.js +81 -0
  93. package/lib/cli/ui/board-model.js +372 -0
  94. package/lib/cli/ui/board.css +525 -0
  95. package/lib/cli/ui/board.html +80 -0
  96. package/lib/cli/ui/board.js +676 -0
  97. package/lib/cli/ui/log-tail.js +89 -0
  98. package/lib/cli/ui/panel-model.js +100 -0
  99. package/lib/cli/ui/preferences.js +136 -0
  100. package/lib/cli/ui/request-guard.js +108 -0
  101. package/lib/cli/ui/server.js +211 -0
  102. package/lib/cli/ui/sources.js +202 -0
  103. package/lib/cli/ui/story-detail.js +92 -0
  104. package/lib/cli/ui.js +114 -0
  105. package/package.json +2 -2
@@ -0,0 +1,119 @@
1
+ /**
2
+ * git-test-guard.js — refuses a branch- or ref-moving git command in the
3
+ * checkout under test.
4
+ *
5
+ * `run-tests.js` sets `MANDREL_TEST_GUARD_ROOT` to the repository it tests.
6
+ * A test that forgets its temp cwd would otherwise check out and fast-forward
7
+ * that checkout mid-suite, swapping the source tree under parallel tests.
8
+ * Production never sets the variable, so this is a no-op outside the suite.
9
+ */
10
+
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import { spawnCapture } from './child-exec.js';
14
+
15
+ const TEST_GUARD_ROOT_ENV = 'MANDREL_TEST_GUARD_ROOT';
16
+
17
+ const MOVING = new Set([
18
+ 'checkout',
19
+ 'switch',
20
+ 'merge',
21
+ 'reset',
22
+ 'rebase',
23
+ 'pull',
24
+ 'stash',
25
+ 'worktree',
26
+ 'commit',
27
+ 'update-ref',
28
+ ]);
29
+ const BRANCH_MOVING_FLAGS = new Set([
30
+ '-f',
31
+ '--force',
32
+ '-d',
33
+ '-D',
34
+ '--delete',
35
+ '-m',
36
+ '-M',
37
+ '--move',
38
+ ]);
39
+
40
+ /** First non-option argument, skipping `-c k=v` and `-C <dir>` pairs. */
41
+ function subcommandOf(args) {
42
+ for (let i = 0; i < args.length; i += 1) {
43
+ if (args[i] === '-c' || args[i] === '-C') i += 1;
44
+ else if (!String(args[i]).startsWith('-')) return { name: args[i], at: i };
45
+ }
46
+ return null;
47
+ }
48
+
49
+ function isMoving(args) {
50
+ const sub = subcommandOf(args);
51
+ if (!sub) return false;
52
+ if (MOVING.has(sub.name)) return true;
53
+ return (
54
+ sub.name === 'branch' &&
55
+ args.slice(sub.at + 1).some((a) => BRANCH_MOVING_FLAGS.has(a))
56
+ );
57
+ }
58
+
59
+ // `.native` expands Windows 8.3 short names (RUNNER~1) that git never prints.
60
+ function realpathOr(p) {
61
+ try {
62
+ return fs.realpathSync.native(path.resolve(p));
63
+ } catch {
64
+ return path.resolve(p);
65
+ }
66
+ }
67
+
68
+ /** Windows paths compare case-insensitively. */
69
+ function samePath(a, b) {
70
+ return process.platform === 'win32'
71
+ ? a?.toLowerCase() === b.toLowerCase()
72
+ : a === b;
73
+ }
74
+
75
+ /** The toplevel of the repository `cwd` sits in, or null outside one. */
76
+ function toplevelOf(cwd) {
77
+ const env = Object.fromEntries(
78
+ Object.entries(process.env).filter(([k]) => !k.startsWith('GIT_')),
79
+ );
80
+ const res = spawnCapture('git', ['rev-parse', '--show-toplevel'], {
81
+ cwd,
82
+ env,
83
+ });
84
+ return res.status === 0 ? realpathOr(res.stdout) : null;
85
+ }
86
+
87
+ /**
88
+ * Arm a test child env with the checkout under test: an inherited root wins,
89
+ * else the toplevel of the current directory.
90
+ *
91
+ * @param {NodeJS.ProcessEnv} env mutated in place
92
+ * @param {NodeJS.ProcessEnv} baseEnv
93
+ * @returns {NodeJS.ProcessEnv} `env`
94
+ */
95
+ export function armGitGuard(env, baseEnv) {
96
+ const root = baseEnv[TEST_GUARD_ROOT_ENV] ?? toplevelOf(process.cwd());
97
+ if (root) env[TEST_GUARD_ROOT_ENV] = root;
98
+ return env;
99
+ }
100
+
101
+ /**
102
+ * Throw before a moving git command runs in the guarded checkout. A nested
103
+ * fixture repository has its own toplevel, so it is never refused.
104
+ *
105
+ * @param {string} cwd
106
+ * @param {string[]} args
107
+ * @param {NodeJS.ProcessEnv} [env]
108
+ * @returns {void}
109
+ */
110
+ export function assertGitAllowed(cwd, args, env = process.env) {
111
+ const root = env[TEST_GUARD_ROOT_ENV];
112
+ if (!root || !isMoving(args)) return;
113
+ const dir = realpathOr(cwd ?? process.cwd());
114
+ if (!fs.existsSync(dir) || !samePath(toplevelOf(dir), realpathOr(root)))
115
+ return;
116
+ throw new Error(
117
+ `git ${subcommandOf(args).name} refused in the checkout under test (${root}) — pass a temp cwd`,
118
+ );
119
+ }
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { execFileSync, spawnSync } from 'node:child_process';
7
7
  import { execFileCapture, spawnCapture } from './child-exec.js';
8
+ import { assertGitAllowed } from './git-test-guard.js';
8
9
  import { defaultSleep } from './util/sleep.js';
9
10
 
10
11
  /**
@@ -62,6 +63,7 @@ export function __setGitRunners(exec, spawn) {
62
63
  * @returns {string}
63
64
  */
64
65
  function runGitSync(exec, cwd, args) {
66
+ assertGitAllowed(cwd, args);
65
67
  return String(
66
68
  execFileCapture('git', args, {
67
69
  run: exec,
@@ -79,6 +81,7 @@ function runGitSync(exec, cwd, args) {
79
81
  * @returns {GitResult}
80
82
  */
81
83
  function runGitSpawn(spawn, cwd, args) {
84
+ assertGitAllowed(cwd, args);
82
85
  return spawnCapture('git', args, {
83
86
  run: spawn,
84
87
  cwd,
@@ -1,5 +1,4 @@
1
1
  import path from 'node:path';
2
- import picomatch from 'picomatch';
3
2
  import { canonicalise as canonicalisePath } from './baselines/path-canon.js';
4
3
  import { POOL_SERIAL_THRESHOLD, runOnPool } from './cpu-pool.js';
5
4
  import { Logger } from './Logger.js';
@@ -7,6 +6,7 @@ import { scoreFile } from './maintainability-engine.js';
7
6
  import { isScored, reportUnscorable } from './maintainability-unscorable.js';
8
7
  import { isScorableSourceFile } from './source-extensions.js';
9
8
  import { CompilerMissingError } from './transpile.js';
9
+ import { globMatcher, isGlobMatch } from './util/glob-match.js';
10
10
  import { walkFiles } from './util/paths.js';
11
11
 
12
12
  const MAINTAINABILITY_WORKER_URL = new URL(
@@ -33,7 +33,7 @@ export const IGNORED_DIRS = new Set([
33
33
 
34
34
  /**
35
35
  * Compiled matchers plus a per-path verdict memo, keyed on the pattern list:
36
- * `picomatch.isMatch()` recompiles per call, and the gates ask about the
36
+ * `isGlobMatch()` recompiles per call, and the gates ask about the
37
37
  * same path once per CRAP row. Inputs are immutable config, so it is bounded.
38
38
  * `\u0000` is the join separator because it cannot occur in a glob, so two
39
39
  * different lists cannot collide onto one key.
@@ -55,7 +55,7 @@ function ignoreMatcherEntry(ignoreGlobs) {
55
55
  entry = {
56
56
  matchers: ignoreGlobs
57
57
  .filter((g) => typeof g === 'string')
58
- .map((g) => picomatch(g, { dot: true })),
58
+ .map((g) => globMatcher(g, { dot: true })),
59
59
  verdicts: new Map(),
60
60
  };
61
61
  IGNORE_MATCHER_CACHE.set(key, entry);
@@ -69,7 +69,7 @@ function ignoreMatcherEntry(ignoreGlobs) {
69
69
  * match.
70
70
  *
71
71
  * @param {string} filePath absolute or relative path to the source file
72
- * @param {string[]} ignoreGlobs picomatch patterns; empty/absent is a no-op
72
+ * @param {string[]} ignoreGlobs glob patterns; empty/absent is a no-op
73
73
  * @param {string} [cwd] root for repo-relative resolution; defaults to cwd
74
74
  * @returns {boolean} true when the file matches at least one ignore glob
75
75
  */
@@ -22,6 +22,7 @@ const HANDOFF_CAUSES = Object.freeze(
22
22
  'base-merge-conflict',
23
23
  'base-merge-failed',
24
24
  'preflight-unresolved',
25
+ 'first-check',
25
26
  'lint',
26
27
  'format',
27
28
  'quality-preview',
@@ -42,6 +43,7 @@ const HANDOFF_CAUSES = Object.freeze(
42
43
  'ref-behind',
43
44
  'push-hook',
44
45
  'review-critical',
46
+ 'review-cap',
45
47
  'other',
46
48
  ]),
47
49
  );
@@ -52,6 +52,7 @@ const FRAMEWORK_SCRIPT_BASENAMES = Object.freeze([
52
52
  'deliver-run.js',
53
53
  'diagnose-friction.js',
54
54
  'diagnose.js',
55
+ 'dispatch.js',
55
56
  'drain-pending-cleanup.js',
56
57
  'evidence-gate.js',
57
58
  'file-ci-gap.js',
@@ -79,6 +80,7 @@ const FRAMEWORK_SCRIPT_BASENAMES = Object.freeze([
79
80
  'review-dispositions-report.js',
80
81
  'role-scope-guard.js',
81
82
  'run-tests.js',
83
+ 'session-title.js',
82
84
  'single-story-close.js',
83
85
  'single-story-confirm-merge.js',
84
86
  'single-story-init.js',
@@ -17,12 +17,13 @@ const EPIC_SIGNALS_BASENAME = 'signals.ndjson';
17
17
  const MET_VERDICTS = Object.freeze(new Set(['met']));
18
18
 
19
19
  /**
20
- * Integer ≥ 1 — the last guard against an unbounded redraft loop.
20
+ * Integer ≥ 1 — the last guard against an unbounded redraft loop. Shared
21
+ * with the handoff's held-review round cap, so the two gates cannot drift.
21
22
  *
22
23
  * @param {unknown} value
23
24
  * @returns {number}
24
25
  */
25
- function effectiveCap(value) {
26
+ export function effectiveCap(value) {
26
27
  if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
27
28
  return 1;
28
29
  }
@@ -0,0 +1,44 @@
1
+ // .agents/scripts/lib/orchestration/block-class-recovery.js
2
+ /**
3
+ * block-class-recovery.js — who clears each terminal block class: the
4
+ * delivering session (`agent`) or a human (`operator`).
5
+ */
6
+
7
+ import {
8
+ ADVISORY_GATE_INCONCLUSIVE_CLASS,
9
+ ADVISORY_GATE_RED_CLASS,
10
+ CHECKS_FAILED_CLASS,
11
+ } from './merge-poll.js';
12
+
13
+ /**
14
+ * Who clears each block: `agent` classes have a remedy the delivering session
15
+ * executes itself (fix + push, rerun, re-confirm), so they are not the HITL
16
+ * pause; `operator` classes need a setting, approval or decision the agent
17
+ * cannot make.
18
+ */
19
+ export const BLOCK_CLASS_RECOVERY = Object.freeze({
20
+ [CHECKS_FAILED_CLASS]: 'agent',
21
+ 'checks-pending-timeout': 'agent',
22
+ 'branch-protection-human-required': 'operator',
23
+ 'arm-failure': 'operator',
24
+ 'api-race-other': 'agent',
25
+ 'predicate-refused': 'operator',
26
+ [ADVISORY_GATE_RED_CLASS]: 'agent',
27
+ [ADVISORY_GATE_INCONCLUSIVE_CLASS]: 'agent',
28
+ 'merge-queue-rest-unsupported': 'operator',
29
+ 'queue-ejected': 'agent',
30
+ 'merged-flip-failed': 'agent',
31
+ });
32
+
33
+ /**
34
+ * @param {string} blockClass
35
+ * @returns {'agent'|'operator'}
36
+ * @throws {Error} on a class the table does not cover.
37
+ */
38
+ export function recoveryOf(blockClass) {
39
+ const recovery = BLOCK_CLASS_RECOVERY[blockClass];
40
+ if (!recovery) {
41
+ throw new Error(`recoveryOf: unclassified block class "${blockClass}"`);
42
+ }
43
+ return recovery;
44
+ }
@@ -6,11 +6,11 @@
6
6
  * under `onNoVerdict: "block"`, a missing verdict (`haltCause`).
7
7
  */
8
8
 
9
- import picomatch from 'picomatch';
10
9
  import { hasSurvivingCritical } from '../audit-suite/findings.js';
11
10
  import { resolveConfig } from '../config-resolver.js';
12
11
  import { gitSpawn } from '../git-utils.js';
13
12
  import { PROJECT_ROOT } from '../project-root.js';
13
+ import { globMatcher } from '../util/glob-match.js';
14
14
  import { computeChangeSet } from './change-set.js';
15
15
  import { remoteBaseRef } from './review-base-ref.js';
16
16
  import {
@@ -183,9 +183,16 @@ function resolveInjectedChangedFiles({ opts, baseRef, headRef }) {
183
183
 
184
184
  /**
185
185
  * Build the `runReview` input with its depth; an unenumerable diff yields
186
- * `standard`.
186
+ * `standard`. A first pass is always `deep` and `exhaustive`.
187
187
  */
188
- function buildReviewInput({ opts, scope, ticketId, baseRef, headRef }) {
188
+ function buildReviewInput({
189
+ opts,
190
+ scope,
191
+ ticketId,
192
+ baseRef,
193
+ headRef,
194
+ firstPass,
195
+ }) {
189
196
  const changedFiles = resolveInjectedChangedFiles({ opts, baseRef, headRef });
190
197
  const changedFileCount =
191
198
  typeof opts.changedFileCount === 'number'
@@ -203,10 +210,14 @@ function buildReviewInput({ opts, scope, ticketId, baseRef, headRef }) {
203
210
  baseRef,
204
211
  headRef,
205
212
  labels: Array.isArray(opts.ticketLabels) ? opts.ticketLabels : [],
206
- depth,
213
+ ...depthFields(firstPass, depth),
207
214
  };
208
215
  }
209
216
 
217
+ /** A first pass reviews `deep` and exhaustively, whatever the diff derived. */
218
+ const depthFields = (firstPass, depth) =>
219
+ firstPass ? { depth: 'deep', exhaustive: true } : { depth };
220
+
210
221
  /**
211
222
  * Optional `getPromptMessages`; absent or throwing yields `[]`.
212
223
  */
@@ -336,7 +347,7 @@ function applySkipPaths(findings, skipPaths) {
336
347
  if (!Array.isArray(skipPaths) || skipPaths.length === 0) {
337
348
  return { findings, skipped: 0 };
338
349
  }
339
- const isSkipped = picomatch(skipPaths, { dot: true });
350
+ const isSkipped = globMatcher(skipPaths, { dot: true });
340
351
  const kept = findings.filter((f) => {
341
352
  const files = findingInstances(f).map((i) => i.file);
342
353
  return !(files.length > 0 && files.every((file) => isSkipped(file)));
@@ -353,6 +364,14 @@ function resolveHistoryDeps(opts, config) {
353
364
  return opts.reviewProvider ? null : { config };
354
365
  }
355
366
 
367
+ /** A first pass has a history seam and no recorded run. */
368
+ const isFirstPass = (history) => history?.runs.length === 0;
369
+
370
+ /** The Story's review history, or `null` without a history seam. */
371
+ function readHistory(ticketId, historyDeps) {
372
+ return historyDeps ? readReviewHistory(ticketId, historyDeps) : null;
373
+ }
374
+
356
375
  /** How the current run settles an earlier CRITICAL it raised again, if it did. */
357
376
  function settleInRun(entry, findings) {
358
377
  const again = findings.filter((f) => raisedAgain(f, entry.finding));
@@ -460,19 +479,12 @@ function earlierSection(history, outcomes) {
460
479
 
461
480
  /**
462
481
  * Mark repeats, then carry forward the open earlier CRITICALs. Without a
463
- * history seam the findings pass through unchanged.
482
+ * history seam (`history` null) the findings pass through unchanged.
464
483
  */
465
- async function applyHistory({
466
- findings,
467
- ticketId,
468
- historyDeps,
469
- reviewInput,
470
- opts,
471
- }) {
472
- if (!historyDeps) {
484
+ async function applyHistory({ findings, history, reviewInput, opts }) {
485
+ if (!history) {
473
486
  return { findings, outcomes: null, earlier: [], degradations: [] };
474
487
  }
475
- const history = readReviewHistory(ticketId, historyDeps);
476
488
  const carry = await carryForward({
477
489
  findings: markRepeats(findings, history),
478
490
  history,
@@ -492,6 +504,7 @@ function recordRun({
492
504
  headRef,
493
505
  findings,
494
506
  outcomes,
507
+ exhaustive,
495
508
  historyDeps,
496
509
  logger,
497
510
  }) {
@@ -499,7 +512,7 @@ function recordRun({
499
512
  try {
500
513
  appendReviewRun(
501
514
  ticketId,
502
- { headSha: headRef, findings, earlierCriticals: outcomes },
515
+ { headSha: headRef, findings, earlierCriticals: outcomes, exhaustive },
503
516
  historyDeps,
504
517
  );
505
518
  } catch (err) {
@@ -533,12 +546,16 @@ async function executeReviewPipeline({ opts, config, envelope }) {
533
546
  codeReviewConfig,
534
547
  root: opts.cwd ?? PROJECT_ROOT,
535
548
  });
549
+ // One history snapshot drives both the first-pass decision and carry-forward.
550
+ const historyDeps = resolveHistoryDeps(opts, config);
551
+ const history = readHistory(ticketId, historyDeps);
536
552
  const baseInput = buildReviewInput({
537
553
  opts,
538
554
  scope,
539
555
  ticketId,
540
556
  baseRef,
541
557
  headRef,
558
+ firstPass: isFirstPass(history),
542
559
  });
543
560
  const reviewInput = {
544
561
  ...baseInput,
@@ -573,11 +590,9 @@ async function executeReviewPipeline({ opts, config, envelope }) {
573
590
  ],
574
591
  });
575
592
  const skip = applySkipPaths(vetted.findings, codeReviewConfig?.skipPaths);
576
- const historyDeps = resolveHistoryDeps(opts, config);
577
593
  const carry = await applyHistory({
578
594
  findings: skip.findings,
579
- ticketId,
580
- historyDeps,
595
+ history,
581
596
  reviewInput,
582
597
  opts,
583
598
  });
@@ -607,6 +622,7 @@ async function executeReviewPipeline({ opts, config, envelope }) {
607
622
  headRef,
608
623
  findings,
609
624
  outcomes: carry.outcomes,
625
+ exhaustive: reviewInput.exhaustive,
610
626
  historyDeps,
611
627
  logger,
612
628
  });
@@ -7,7 +7,7 @@
7
7
  * Contracts: lines are additions + deletions, never net (a big deletion is
8
8
  * not trivial); a pure rename is free but its file still counts; exemption
9
9
  * is from counting, never from sensitive-path risk. Companion globs are a
10
- * positive list — a `!` picomatch pattern widens rather than narrows. Every
10
+ * positive list — a `!` glob pattern widens rather than narrows. Every
11
11
  * export is total.
12
12
  *
13
13
  * @module lib/orchestration/diff-magnitude
@@ -4,14 +4,14 @@
4
4
  * @module lib/orchestration/git-cleanup/phases/filters
5
5
  */
6
6
 
7
- import picomatch from 'picomatch';
7
+ import { globMatcher } from '../../../util/glob-match.js';
8
8
 
9
9
  /**
10
10
  * Pure: build a `(branch) => boolean` filter from include/exclude globs.
11
11
  */
12
12
  export function buildGlobFilter({ include = [], exclude = [] } = {}) {
13
- const includeMatch = include.length > 0 ? picomatch(include) : () => true;
14
- const excludeMatch = exclude.length > 0 ? picomatch(exclude) : () => false;
13
+ const includeMatch = include.length > 0 ? globMatcher(include) : () => true;
14
+ const excludeMatch = exclude.length > 0 ? globMatcher(exclude) : () => false;
15
15
  return (branch) => includeMatch(branch) && !excludeMatch(branch);
16
16
  }
17
17
 
@@ -6,8 +6,6 @@
6
6
  * the union path (`audit-provenance.js`).
7
7
  */
8
8
 
9
- import picomatch from 'picomatch';
10
-
11
9
  import { parseAuditFindingRecords } from '../../findings/audit-finding-record.js';
12
10
  import { ownedProvenanceSource } from '../../findings/provenance-field.js';
13
11
  import {
@@ -15,6 +13,7 @@ import {
15
13
  parseFingerprintFooter,
16
14
  parseSemanticKeyFooter,
17
15
  } from '../../findings/route-finding.js';
16
+ import { globMatcher } from '../../util/glob-match.js';
18
17
 
19
18
  /**
20
19
  * @param {unknown} changes — `changes[]` entries, strings or `{ path }`.
@@ -27,7 +26,7 @@ function coverageMatchers(changes) {
27
26
  .filter((p) => typeof p === 'string' && p.trim().length > 0)
28
27
  .map((p) => {
29
28
  const glob = p.trim();
30
- const match = picomatch(glob, { dot: true });
29
+ const match = globMatcher(glob, { dot: true });
31
30
  return (file) => file === glob || match(file);
32
31
  });
33
32
  }
@@ -83,7 +82,7 @@ function attributionApplies(storyCount, provenanceSource) {
83
82
  * Attribute each seed finding to the Stories that cover it. Order per Story:
84
83
  * an authored `provenance` wins outright; otherwise the Story owns every
85
84
  * finding one of whose files its `changes[]` covers (exact path, or a glob
86
- * under picomatch `dot: true`). A finding no Story owns is unattributed: it
85
+ * under `dot: true`). A finding no Story owns is unattributed: it
87
86
  * rides on every non-authored Story and is named in the warnings.
88
87
  *
89
88
  * @param {Array<{ provenance: object|null, changes?: unknown }>} stories — draft order.
@@ -13,7 +13,7 @@
13
13
  * @typedef {{ id: string, status: 'still-open'|'fixed'|'refuted',
14
14
  * reason?: string }} EarlierOutcome
15
15
  * @typedef {{ runs: { headSha: string, findings: HistoryFinding[],
16
- * earlierCriticals?: EarlierOutcome[] }[],
16
+ * earlierCriticals?: EarlierOutcome[], exhaustive?: true }[],
17
17
  * overridden: string[], overrideReason?: string }} ReviewHistory
18
18
  * @typedef {{ id: string, finding: HistoryFinding, headSha: string,
19
19
  * status: 'open'|'fixed'|'refuted'|'overridden', reason?: string }} EarlierCritical
@@ -136,24 +136,23 @@ function toHistoryFinding(f) {
136
136
  /**
137
137
  * @param {number} storyId
138
138
  * @param {{ headSha: string, findings: Finding[],
139
- * earlierCriticals?: EarlierOutcome[] }} run
139
+ * earlierCriticals?: EarlierOutcome[], exhaustive?: boolean }} entry
140
140
  * @param {{ config?: object, fsImpl?: typeof nodeFs }} [deps]
141
141
  */
142
- export function appendReviewRun(
143
- storyId,
144
- { headSha, findings, earlierCriticals },
145
- deps,
146
- ) {
147
- const run = toHistoryRun(headSha, findings, earlierCriticals);
142
+ export function appendReviewRun(storyId, entry, deps) {
143
+ const run = toHistoryRun(entry);
148
144
  updateReviewHistory(storyId, (h) => ({ ...h, runs: [...h.runs, run] }), deps);
149
145
  }
150
146
 
151
- function toHistoryRun(headSha, findings, earlierCriticals) {
147
+ function toHistoryRun({ headSha, findings, earlierCriticals, exhaustive }) {
152
148
  const run = { headSha, findings: findings.map(toHistoryFinding) };
153
149
  if (Array.isArray(earlierCriticals)) run.earlierCriticals = earlierCriticals;
154
- return run;
150
+ return { ...run, ...exhaustiveField(exhaustive) };
155
151
  }
156
152
 
153
+ const exhaustiveField = (exhaustive) =>
154
+ exhaustive ? { exhaustive: true } : {};
155
+
157
156
  const list = (v) => (Array.isArray(v) ? v : []);
158
157
  const RESOLVED = new Set(['fixed', 'refuted']);
159
158
 
@@ -44,7 +44,10 @@ import {
44
44
  } from './claude-verdict.js';
45
45
  import { readDiff } from './generated-diff.js';
46
46
  import { BUG_CLASS_RULE } from './parse-findings.js';
47
- import { renderDepthDirective } from './review-depth.js';
47
+ import {
48
+ renderDepthDirective,
49
+ renderExhaustiveDirective,
50
+ } from './review-depth.js';
48
51
  import { renderGuidanceBlock } from './review-guidance.js';
49
52
  import { probeClaudeCli } from './security-review.js';
50
53
 
@@ -220,7 +223,11 @@ function buildPrompt(
220
223
  .replace('{headRef}', input.headRef)
221
224
  .replace('{ticketId}', String(input.ticketId))
222
225
  .replace('{scopeNote}', scope)
223
- .replace('{depthDirective}', renderDepthDirective(input.depth))
226
+ .replace(
227
+ '{depthDirective}',
228
+ renderDepthDirective(input.depth) +
229
+ renderExhaustiveDirective(input.exhaustive),
230
+ )
224
231
  .replace('{guidance}', () => renderGuidanceBlock(input.guidance));
225
232
  return `${head}<diff>\n${body}${note}\n</diff>\n${callers}`;
226
233
  }
@@ -20,7 +20,10 @@ import { resolveConfig } from '../../config-resolver.js';
20
20
  import { STRICT_CLAIM_SCHEMA } from './claim-grounding.js';
21
21
  import { BUG_CLASS_RULE } from './parse-findings.js';
22
22
  import { PROVIDER_SEVERITY_MAP } from './provider-severity.js';
23
- import { renderDepthDirective } from './review-depth.js';
23
+ import {
24
+ renderDepthDirective,
25
+ renderExhaustiveDirective,
26
+ } from './review-depth.js';
24
27
  import { renderGuidanceBlock } from './review-guidance.js';
25
28
 
26
29
  const PROBE_TIMEOUT_MS = 5000;
@@ -109,14 +112,14 @@ export function defaultProbeCodexCommand(opts = {}) {
109
112
 
110
113
  /**
111
114
  * @param {{ baseRef: string, headRef: string, depth?: ReviewDepth,
112
- * guidance?: string|null }} args
115
+ * exhaustive?: boolean, guidance?: string|null }} args
113
116
  * @returns {string}
114
117
  */
115
- function buildReviewPrompt({ baseRef, headRef, depth, guidance }) {
118
+ function buildReviewPrompt({ baseRef, headRef, depth, exhaustive, guidance }) {
116
119
  return (
117
120
  `Review the code changes in the git diff \`${baseRef}...${headRef}\` ` +
118
121
  `of this repository (run \`git diff ${baseRef}...${headRef}\` to read ` +
119
- `it). ${renderDepthDirective(depth)}\n\n` +
122
+ `it). ${renderDepthDirective(depth)}${renderExhaustiveDirective(exhaustive)}\n\n` +
120
123
  'Report correctness, security, reliability and maintainability problems ' +
121
124
  'the change introduces. For each one give the file and line in the new ' +
122
125
  'version when attributable (otherwise null), a short title, a markdown ' +
@@ -146,7 +149,7 @@ function readIfPresent(file) {
146
149
  * file becomes `stdout`.
147
150
  *
148
151
  * @param {{ baseRef: string, headRef: string, depth?: ReviewDepth,
149
- * guidance?: string|null }} args
152
+ * exhaustive?: boolean, guidance?: string|null }} args
150
153
  * @param {{ run?: Function, tempRoot?: string, cwd?: string }} [deps]
151
154
  * @returns {Promise<InvokeResult>}
152
155
  */
@@ -66,7 +66,7 @@ export function parseCodexFindings(rawOutput) {
66
66
  /**
67
67
  * @param {{
68
68
  * probeFn?: () => boolean,
69
- * invokeFn?: (args: { baseRef: string, headRef: string, scope: string, ticketId: number, depth?: import('./types.js').ReviewDepth, guidance?: string|null }) => { status: number, stdout: string, stderr: string } | Promise<{ status: number, stdout: string, stderr: string }>,
69
+ * invokeFn?: (input: ReviewInput) => { status: number, stdout: string, stderr: string } | Promise<{ status: number, stdout: string, stderr: string }>,
70
70
  * logger?: { info?: Function, warn?: Function, error?: Function },
71
71
  * }} [deps]
72
72
  * @returns {ReviewProvider}
@@ -86,8 +86,7 @@ export function createCodexProvider(deps = {}) {
86
86
  * @returns {Promise<Finding[]>}
87
87
  */
88
88
  async runReview(input) {
89
- const { scope, ticketId, baseRef, headRef, depth, guidance } =
90
- input ?? {};
89
+ const { scope, ticketId, baseRef, headRef } = input ?? {};
91
90
  if (!baseRef || !headRef) {
92
91
  throw new TypeError(
93
92
  '[codex-review] runReview requires baseRef and headRef.',
@@ -104,14 +103,7 @@ export function createCodexProvider(deps = {}) {
104
103
  `for ${scope} #${ticketId}...`,
105
104
  );
106
105
 
107
- const result = await invokeFn({
108
- baseRef,
109
- headRef,
110
- scope,
111
- ticketId,
112
- depth,
113
- guidance,
114
- });
106
+ const result = await invokeFn(input);
115
107
  if (result.status !== 0) {
116
108
  throw new Error(
117
109
  `[codex-review] codex exec exited with status ${result.status}: ${
@@ -13,7 +13,7 @@ import { isIgnoredByGlobs } from '../../maintainability-utils.js';
13
13
  * scoring nothing would silently retire the dimension.
14
14
  *
15
15
  * @param {{ resolveConfigFn?: typeof resolveConfig, getQualityFn?: typeof getQuality }} [deps]
16
- * @returns {string[]} picomatch patterns; `[]` when unset or unresolvable.
16
+ * @returns {string[]} glob patterns; `[]` when unset or unresolvable.
17
17
  */
18
18
  export function resolveMaintainabilityIgnoreGlobs({
19
19
  resolveConfigFn = resolveConfig,
@@ -29,7 +29,7 @@ export function resolveMaintainabilityIgnoreGlobs({
29
29
 
30
30
  /**
31
31
  * Matches through `isIgnoredByGlobs`, the same rule the baseline uses; a
32
- * local `picomatch` would let the two surfaces disagree.
32
+ * local glob matcher would let the two surfaces disagree.
33
33
  *
34
34
  * @param {string[]} files
35
35
  * @param {string[]} ignoreGlobs