mandrel 2.90.0 → 2.91.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 (169) hide show
  1. package/.agents/README.md +47 -7
  2. package/.agents/agents/story-worker.md +20 -0
  3. package/.agents/audit-checklists/lean.md +26 -0
  4. package/.agents/docs/agentrc-reference.json +5 -6
  5. package/.agents/docs/configuration.md +31 -30
  6. package/.agents/docs/workflows.md +7 -1
  7. package/.agents/instructions.md +3 -1
  8. package/.agents/runtime-deps.json +0 -2
  9. package/.agents/schemas/agentrc.schema.json +46 -45
  10. package/.agents/schemas/audit-rules.json +19 -0
  11. package/.agents/scripts/acceptance-eval.js +2 -6
  12. package/.agents/scripts/audit-exceptions.js +2 -4
  13. package/.agents/scripts/check-arch-cycles.js +1 -5
  14. package/.agents/scripts/check-context-budget.js +1 -5
  15. package/.agents/scripts/check-cyclomatic.js +1 -5
  16. package/.agents/scripts/check-dead-exports.js +23 -14
  17. package/.agents/scripts/check-doc-links.js +4 -4
  18. package/.agents/scripts/check-test-temp-hygiene.js +29 -33
  19. package/.agents/scripts/coverage-capture.js +14 -6
  20. package/.agents/scripts/diagnose-friction.js +8 -10
  21. package/.agents/scripts/generate-workflows-doc.js +5 -0
  22. package/.agents/scripts/lib/audit-exceptions/adapters/index.js +2 -0
  23. package/.agents/scripts/lib/audit-exceptions/adapters/inline-suppressions.js +36 -27
  24. package/.agents/scripts/lib/audit-exceptions/adapters/shortcut-markers.js +70 -0
  25. package/.agents/scripts/lib/audit-exceptions/adapters/source-scan.js +26 -0
  26. package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +1 -0
  27. package/.agents/scripts/lib/baseline-schema-registry.js +3 -5
  28. package/.agents/scripts/lib/baselines/bundle-size-scorer.js +11 -28
  29. package/.agents/scripts/lib/baselines/components.js +5 -5
  30. package/.agents/scripts/lib/baselines/crap-preview-scan.js +4 -1
  31. package/.agents/scripts/lib/baselines/crap-updater-cli.js +6 -4
  32. package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -10
  33. package/.agents/scripts/lib/baselines/kinds/crap.js +4 -2
  34. package/.agents/scripts/lib/baselines/kinds/duplication.js +4 -2
  35. package/.agents/scripts/lib/baselines/kinds/kind-factory.js +13 -6
  36. package/.agents/scripts/lib/baselines/refresh-service.js +10 -13
  37. package/.agents/scripts/lib/baselines/writer.js +4 -4
  38. package/.agents/scripts/lib/bdd-scenario-scanner.js +26 -31
  39. package/.agents/scripts/lib/bootstrap/gh-list.js +4 -5
  40. package/.agents/scripts/lib/bootstrap/gh-preflight.js +13 -8
  41. package/.agents/scripts/lib/child-exec.js +4 -4
  42. package/.agents/scripts/lib/claude/agents-projection.js +170 -0
  43. package/.agents/scripts/lib/claude/commands-projection.js +184 -0
  44. package/.agents/scripts/lib/close-validation/commands.js +28 -117
  45. package/.agents/scripts/lib/close-validation/gates.js +54 -48
  46. package/.agents/scripts/lib/close-validation/projections/crap.js +2 -1
  47. package/.agents/scripts/lib/close-validation/projections/maintainability.js +50 -15
  48. package/.agents/scripts/lib/config/agentrc-overlay.js +4 -7
  49. package/.agents/scripts/lib/config/commands.js +82 -7
  50. package/.agents/scripts/lib/config/explain.js +2 -1
  51. package/.agents/scripts/lib/config/gates/coverage.schema.js +39 -3
  52. package/.agents/scripts/lib/config/gates/crap-incremental-coverage.schema.js +1 -1
  53. package/.agents/scripts/lib/config/gates/crap.schema.js +5 -3
  54. package/.agents/scripts/lib/config/gates/duplication.schema.js +6 -11
  55. package/.agents/scripts/lib/config/gates/shared.js +2 -2
  56. package/.agents/scripts/lib/config/git-roots.js +120 -0
  57. package/.agents/scripts/lib/config/quality.js +46 -50
  58. package/.agents/scripts/lib/config/review-chain-default.js +4 -3
  59. package/.agents/scripts/lib/config/review-provider-clis.js +11 -0
  60. package/.agents/scripts/lib/config/temp-paths.js +3 -37
  61. package/.agents/scripts/lib/config-resolver.js +5 -9
  62. package/.agents/scripts/lib/config-settings-schema-delivery.js +2 -2
  63. package/.agents/scripts/lib/config-settings-schema-quality.js +3 -2
  64. package/.agents/scripts/lib/config-settings-schema.js +6 -7
  65. package/.agents/scripts/lib/coverage-baseline.js +2 -1
  66. package/.agents/scripts/lib/coverage-capture-affected.js +4 -3
  67. package/.agents/scripts/lib/coverage-capture-fullscope.js +3 -1
  68. package/.agents/scripts/lib/coverage-capture-passes.js +119 -34
  69. package/.agents/scripts/lib/coverage-capture-usage.js +1 -1
  70. package/.agents/scripts/lib/coverage-capture.js +31 -20
  71. package/.agents/scripts/lib/coverage-utils.js +34 -16
  72. package/.agents/scripts/lib/cpu-pool.js +2 -4
  73. package/.agents/scripts/lib/crap-engine.js +19 -1
  74. package/.agents/scripts/lib/crap-utils.js +2 -1
  75. package/.agents/scripts/lib/dead-exports-knip.js +29 -11
  76. package/.agents/scripts/lib/detect-package-manager.js +13 -0
  77. package/.agents/scripts/lib/feedback-loop/graduator-gh.js +4 -2
  78. package/.agents/scripts/lib/full-suite-lock.js +25 -9
  79. package/.agents/scripts/lib/gates/baseline-store.js +2 -10
  80. package/.agents/scripts/lib/generated/agentrc-validator.js +4 -1
  81. package/.agents/scripts/lib/gh-env.js +72 -0
  82. package/.agents/scripts/lib/gh-exec.js +26 -1
  83. package/.agents/scripts/lib/maintainability-utils.js +8 -8
  84. package/.agents/scripts/lib/npm-scripts.js +1 -1
  85. package/.agents/scripts/lib/observability/signal-validator.js +2 -6
  86. package/.agents/scripts/lib/observability/terse-result.js +2 -6
  87. package/.agents/scripts/lib/orchestration/board-access-latch.js +19 -8
  88. package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +10 -13
  89. package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
  90. package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +3 -3
  91. package/.agents/scripts/lib/orchestration/lifecycle/emit-ledger-event.js +2 -6
  92. package/.agents/scripts/lib/orchestration/light-suitability.js +5 -7
  93. package/.agents/scripts/lib/orchestration/pr-watch.js +7 -7
  94. package/.agents/scripts/lib/orchestration/project-meta-cache.js +2 -11
  95. package/.agents/scripts/lib/orchestration/review-deposit.js +2 -9
  96. package/.agents/scripts/lib/orchestration/review-providers/callers-context.js +219 -0
  97. package/.agents/scripts/lib/orchestration/review-providers/code-review.js +53 -5
  98. package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +2 -2
  99. package/.agents/scripts/lib/orchestration/review-providers/llm-review.js +96 -0
  100. package/.agents/scripts/lib/orchestration/review-providers/mi-exemptions.js +2 -2
  101. package/.agents/scripts/lib/orchestration/review-providers/native.js +13 -19
  102. package/.agents/scripts/lib/orchestration/review-providers/review-depth.js +3 -2
  103. package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +2 -0
  104. package/.agents/scripts/lib/orchestration/review-providers/security-review.js +11 -3
  105. package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -3
  106. package/.agents/scripts/lib/orchestration/story-close/format-autofix.js +41 -15
  107. package/.agents/scripts/lib/orchestration/story-deliver-terminal-schema.js +2 -4
  108. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +2 -13
  109. package/.agents/scripts/lib/orchestration/story-handoff.js +13 -5
  110. package/.agents/scripts/lib/orchestration/story-progress.js +3 -11
  111. package/.agents/scripts/lib/orchestration/ticketing/bulk.js +3 -5
  112. package/.agents/scripts/lib/orchestration/verify-credit.js +52 -28
  113. package/.agents/scripts/lib/single-story-sweep/protection-ctx.js +11 -11
  114. package/.agents/scripts/lib/single-story-sweep/protection.js +1 -9
  115. package/.agents/scripts/lib/single-story-sweep/sweep-lock.js +1 -5
  116. package/.agents/scripts/lib/source-extensions.js +30 -15
  117. package/.agents/scripts/lib/test-run-credit.js +1 -9
  118. package/.agents/scripts/lib/test-temp.js +22 -21
  119. package/.agents/scripts/lib/util/ajv.js +111 -0
  120. package/.agents/scripts/lib/util/atomic-write.js +30 -0
  121. package/.agents/scripts/lib/util/paths.js +51 -0
  122. package/.agents/scripts/lib/util/sleep.js +6 -0
  123. package/.agents/scripts/lib/util/slug.js +12 -0
  124. package/.agents/scripts/lib/validation-evidence.js +19 -40
  125. package/.agents/scripts/lib/worktree/lifecycle/force-drain.js +2 -1
  126. package/.agents/scripts/lib/worktree/lifecycle/pending-cleanup.js +10 -28
  127. package/.agents/scripts/lib/worktree/lifecycle/reap.js +2 -2
  128. package/.agents/scripts/lib/worktree/node-modules-strategy.js +21 -14
  129. package/.agents/scripts/lint-issue-body.js +2 -2
  130. package/.agents/scripts/plan-context.js +2 -7
  131. package/.agents/scripts/providers/github/auth.js +3 -3
  132. package/.agents/scripts/providers/github/errors.js +3 -1
  133. package/.agents/scripts/providers/github/gh-token-diagnostics.js +10 -7
  134. package/.agents/scripts/providers/github/issues.js +6 -2
  135. package/.agents/scripts/providers/github/mappers.js +1 -5
  136. package/.agents/scripts/providers/github/projects-v2-graphql.js +11 -3
  137. package/.agents/scripts/providers/github/search-budget.js +3 -1
  138. package/.agents/scripts/resolve-doc-tiers.js +7 -20
  139. package/.agents/scripts/sync-agentrc.js +5 -14
  140. package/.agents/scripts/sync-claude-agents.js +38 -150
  141. package/.agents/scripts/sync-claude-commands.js +35 -218
  142. package/.agents/scripts/update-coverage-baseline.js +1 -1
  143. package/.agents/scripts/update-crap-baseline.js +1 -1
  144. package/.agents/scripts/update-duplication-baseline.js +2 -16
  145. package/.agents/scripts/validate-skills.js +6 -10
  146. package/.agents/skills/core/code-review-and-quality/SKILL.md +3 -18
  147. package/.agents/skills/core/documentation-and-adrs/SKILL.md +4 -14
  148. package/.agents/workflows/audit-exceptions.md +9 -0
  149. package/.agents/workflows/audit-lean.md +129 -0
  150. package/.agents/workflows/helpers/audit-lens-core.md +7 -0
  151. package/.agents/workflows/helpers/code-quality-guardrails.md +21 -0
  152. package/.agents/workflows/helpers/code-review.md +15 -1
  153. package/.agents/workflows/helpers/deliver-digest.md +1 -1
  154. package/.agents/workflows/helpers/deliver-reference.md +2 -2
  155. package/.agents/workflows/mandrel-plan.md +2 -2
  156. package/docs/CHANGELOG.md +35 -0
  157. package/lib/cli/doctor-checks/codex.js +6 -5
  158. package/lib/cli/doctor-checks/llm-review.js +102 -0
  159. package/lib/cli/doctor-checks/project-access.js +20 -10
  160. package/lib/cli/doctor-checks/sync-parity.js +65 -140
  161. package/lib/cli/doctor-checks/test-credit-path.js +69 -28
  162. package/lib/cli/doctor-checks/toolchain.js +5 -3
  163. package/lib/cli/registry.js +5 -0
  164. package/lib/migrations/helpers/retire-agentrc-key.js +3 -3
  165. package/lib/migrations/index.js +6 -0
  166. package/lib/migrations/steps/2.91.0-move-shared-crap-capture-script.js +84 -0
  167. package/lib/migrations/steps/2.91.0-retire-duplication-formats.js +23 -0
  168. package/lib/migrations/steps/2.91.0-unset-null-lint-command.js +54 -0
  169. package/package.json +1 -3
@@ -1,13 +1,16 @@
1
1
  /**
2
2
  * `delivery.quality` resolver. Every `gates.<tier>` shares `enabled`,
3
- * `baselinePath`, `tolerance` (`{ kind, value }`) and workspace-keyed
4
- * `floors`; the resolver flattens them into the legacy bag callers read
3
+ * `baselinePath`, `tolerance` (`{ kind, value }`) and the
4
+ * component-keyed `floors` / `components` pair (threshold and membership); the resolver flattens them into the legacy bag callers read
5
5
  * (scalar `tolerance`, `crap.coveragePath` cross-read from the coverage gate).
6
6
  */
7
7
 
8
8
  import { Logger } from '../Logger.js';
9
+ import { COVERAGE_GATE_DEFAULTS } from './gates/coverage.schema.js';
9
10
  import { resolveListValue } from './shared.js';
10
11
 
12
+ export { COVERAGE_GATE_DEFAULTS };
13
+
11
14
  const GATE_SCOPING = Object.freeze({ scope: 'diff', diffRef: 'main' });
12
15
 
13
16
  /** Commit-subject substring acknowledging a deliberate baseline refresh. */
@@ -16,10 +19,7 @@ const BASELINE_REFRESH_TAG = 'baseline-refresh:';
16
19
  const DEFAULT_CRAP_TOLERANCE = Object.freeze({ kind: 'absolute', value: 0.05 });
17
20
  const DEFAULT_MI_TOLERANCE = Object.freeze({ kind: 'absolute', value: 0.5 });
18
21
 
19
- /** Injected when a declared gate omits a workspace key (usually `'*'`). */
20
- const DEFAULT_COVERAGE_FLOORS = Object.freeze({
21
- '*': Object.freeze({ lines: 90, branches: 85, functions: 90 }),
22
- });
22
+ /** Injected when a declared gate omits a component key (usually `'*'`). */
23
23
  const DEFAULT_CRAP_FLOORS = Object.freeze({
24
24
  '*': Object.freeze({ max: 30, p95: 20, methodsAbove20: 50 }),
25
25
  });
@@ -58,20 +58,6 @@ export const CRAP_GATE_DEFAULTS = Object.freeze({
58
58
  // Healthy runs resolve ~98%; a coordinate mismatch resolves 4–6%.
59
59
  minMethodResolutionRate: 0.75,
60
60
  incrementalCoverage: DEFAULT_INCREMENTAL_COVERAGE,
61
- // npm script that writes the CRAP coverage artifact (never a shell command).
62
- captureScript: 'test:coverage',
63
- });
64
-
65
- export const COVERAGE_GATE_DEFAULTS = Object.freeze({
66
- enabled: true,
67
- baselinePath: 'baselines/coverage.json',
68
- tolerance: Object.freeze({ kind: 'absolute', value: 0 }),
69
- floors: DEFAULT_COVERAGE_FLOORS,
70
- coveragePath: 'coverage/coverage-final.json',
71
- // `affected` runs the consumer's `test:coverage:affected` instead.
72
- captureScope: 'full',
73
- // On expiry `runCapture` exits 124 so callers can tell a hang from a failure.
74
- timeoutMs: 600_000,
75
61
  });
76
62
 
77
63
  export const MAINTAINABILITY_GATE_DEFAULTS = Object.freeze({
@@ -109,6 +95,7 @@ const COVERAGE_GATE_KEYS = new Set([
109
95
  'floors',
110
96
  'components',
111
97
  'coveragePath',
98
+ 'captureScript',
112
99
  'captureScope',
113
100
  'timeoutMs',
114
101
  ]);
@@ -186,40 +173,41 @@ function nonEmptyString(value) {
186
173
  : null;
187
174
  }
188
175
 
189
- /** Directory part of a repo-relative path, separator-agnostic. */
190
- function artifactDir(relPath) {
191
- const parts = relPath.replace(/\\/g, '/').split('/').filter(Boolean);
192
- parts.pop();
193
- return parts.filter((p) => p !== '.').join('/');
176
+ /** @param {string} relPath @returns {string} forward-slash form. */
177
+ function slashed(relPath) {
178
+ return relPath.replace(/\\/g, '/');
194
179
  }
195
180
 
181
+ const CRAP_CAPTURE_SCRIPT_KEY = 'delivery.quality.gates.crap.captureScript';
182
+ const CRAP_COVERAGE_PATH_KEY = 'delivery.quality.gates.crap.coveragePath';
183
+
196
184
  /**
197
- * The CRAP gate's coverage source. A user `coveragePath` that
198
- * differs from the coverage gate's is an OWN source; one in the same
199
- * directory would share the per-directory capture stamp and cross-credit
200
- * freshness, so it is refused here rather than silently falling back.
185
+ * The CRAP gate's coverage source. A user `coveragePath` that differs from
186
+ * the coverage gate's is an OWN source with its own capture stamp. Without
187
+ * one the CRAP gate reads the coverage gate's artifact, captured by the
188
+ * coverage gate's `captureScript` — so a `crap.captureScript` there has no
189
+ * artifact to write and is refused rather than silently ignored.
201
190
  *
202
191
  * @param {{ coveragePath?: unknown, captureScript?: unknown }} userCrap
203
- * @param {string} coverageGatePath
192
+ * @param {{ coveragePath: string, captureScript: string }} coverageGate
204
193
  * @returns {{ coveragePath: string, captureScript: string, ownCoverageSource: boolean }}
205
194
  */
206
- function resolveCrapCoverageSource(userCrap, coverageGatePath) {
195
+ function resolveCrapCoverageSource(userCrap, coverageGate) {
207
196
  const userPath = nonEmptyString(userCrap?.coveragePath);
208
- const captureScript =
209
- nonEmptyString(userCrap?.captureScript) ?? CRAP_GATE_DEFAULTS.captureScript;
210
- const coveragePath = userPath ?? coverageGatePath;
197
+ const userScript = nonEmptyString(userCrap?.captureScript);
211
198
  const ownCoverageSource =
212
199
  userPath !== null &&
213
- userPath.replace(/\\/g, '/') !== coverageGatePath.replace(/\\/g, '/');
214
- if (
215
- ownCoverageSource &&
216
- artifactDir(userPath) === artifactDir(coverageGatePath)
217
- ) {
200
+ slashed(userPath) !== slashed(coverageGate.coveragePath);
201
+ if (userScript !== null && !ownCoverageSource) {
218
202
  throw new Error(
219
- `[config] delivery.quality.gates.crap.coveragePath '${userPath}' sits in the same directory as delivery.quality.gates.coverage.coveragePath '${coverageGatePath}'. The capture stamp is per directory, so an own CRAP coverage source must live in its own directory.`,
203
+ `[config] ${CRAP_CAPTURE_SCRIPT_KEY} '${userScript}' is set without an own ${CRAP_COVERAGE_PATH_KEY}. A CRAP capture script only writes a CRAP coverage artifact distinct from delivery.quality.gates.coverage.coveragePath — set ${CRAP_COVERAGE_PATH_KEY} to that artifact, or move it to delivery.quality.gates.coverage.captureScript (\`npx mandrel update\` migrates it).`,
220
204
  );
221
205
  }
222
- return { coveragePath, captureScript, ownCoverageSource };
206
+ return {
207
+ coveragePath: userPath ?? coverageGate.coveragePath,
208
+ captureScript: userScript ?? coverageGate.captureScript,
209
+ ownCoverageSource,
210
+ };
223
211
  }
224
212
 
225
213
  /**
@@ -229,7 +217,12 @@ function resolveCrapCoverageSource(userCrap, coverageGatePath) {
229
217
  */
230
218
  export function resolveMaintainabilityCrap(userCrap, coverageGate) {
231
219
  const defaults = CRAP_GATE_DEFAULTS;
232
- const coverage = coverageGate ?? COVERAGE_GATE_DEFAULTS;
220
+ const coverage = {
221
+ coveragePath:
222
+ coverageGate?.coveragePath ?? COVERAGE_GATE_DEFAULTS.coveragePath,
223
+ captureScript:
224
+ coverageGate?.captureScript ?? COVERAGE_GATE_DEFAULTS.captureScript,
225
+ };
233
226
  const fixed = {
234
227
  refreshTag: defaults.refreshTag,
235
228
  defaultScope: GATE_SCOPING.scope,
@@ -241,7 +234,7 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
241
234
  targetDirs: [...defaults.targetDirs],
242
235
  newMethodCeiling: defaults.newMethodCeiling,
243
236
  coveragePath: coverage.coveragePath,
244
- captureScript: defaults.captureScript,
237
+ captureScript: coverage.captureScript,
245
238
  ownCoverageSource: false,
246
239
  tolerance: toleranceScalar(
247
240
  defaults.tolerance,
@@ -261,7 +254,7 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
261
254
  enabled: userCrap.enabled ?? defaults.enabled,
262
255
  targetDirs: resolveListValue(defaults.targetDirs, userCrap.targetDirs),
263
256
  newMethodCeiling: userCrap.newMethodCeiling ?? defaults.newMethodCeiling,
264
- ...resolveCrapCoverageSource(userCrap, coverage.coveragePath),
257
+ ...resolveCrapCoverageSource(userCrap, coverage),
265
258
  tolerance: toleranceScalar(
266
259
  userCrap.tolerance,
267
260
  toleranceScalar(defaults.tolerance, DEFAULT_CRAP_TOLERANCE.value),
@@ -320,6 +313,7 @@ function resolveCoverageGate(userBlock) {
320
313
  enabled: defaults.enabled,
321
314
  baselinePath: defaults.baselinePath,
322
315
  coveragePath: defaults.coveragePath,
316
+ captureScript: defaults.captureScript,
323
317
  captureScope: defaults.captureScope,
324
318
  tolerance: toleranceScalar(defaults.tolerance, 0),
325
319
  timeoutMs: defaults.timeoutMs,
@@ -330,6 +324,8 @@ function resolveCoverageGate(userBlock) {
330
324
  enabled: userBlock.enabled ?? defaults.enabled,
331
325
  baselinePath: userBlock.baselinePath ?? defaults.baselinePath,
332
326
  coveragePath: userBlock.coveragePath ?? defaults.coveragePath,
327
+ captureScript:
328
+ nonEmptyString(userBlock.captureScript) ?? defaults.captureScript,
333
329
  captureScope: userBlock.captureScope ?? defaults.captureScope,
334
330
  tolerance: toleranceScalar(
335
331
  userBlock.tolerance,
@@ -380,7 +376,7 @@ function resolveBaselinesFromGates(gates) {
380
376
  }
381
377
 
382
378
  /**
383
- * Consumer entries win per workspace key. Returns a fresh object so callers
379
+ * Consumer entries win per component key. Returns a fresh object so callers
384
380
  * cannot mutate the frozen defaults.
385
381
  *
386
382
  * @param {object | undefined | null} userFloors
@@ -389,22 +385,22 @@ function resolveBaselinesFromGates(gates) {
389
385
  */
390
386
  function mergeFloorsWithDefaults(userFloors, defaults) {
391
387
  const defaultsCopy = {};
392
- for (const [workspace, axes] of Object.entries(defaults)) {
393
- defaultsCopy[workspace] = { ...axes };
388
+ for (const [component, axes] of Object.entries(defaults)) {
389
+ defaultsCopy[component] = { ...axes };
394
390
  }
395
391
  if (userFloors == null || typeof userFloors !== 'object') {
396
392
  return defaultsCopy;
397
393
  }
398
- for (const [workspace, axes] of Object.entries(userFloors)) {
394
+ for (const [component, axes] of Object.entries(userFloors)) {
399
395
  if (axes != null && typeof axes === 'object') {
400
- defaultsCopy[workspace] = { ...axes };
396
+ defaultsCopy[component] = { ...axes };
401
397
  }
402
398
  }
403
399
  return defaultsCopy;
404
400
  }
405
401
 
406
402
  const FLOOR_DEFAULTS_BY_KIND = Object.freeze({
407
- coverage: DEFAULT_COVERAGE_FLOORS,
403
+ coverage: COVERAGE_GATE_DEFAULTS.floors,
408
404
  crap: DEFAULT_CRAP_FLOORS,
409
405
  maintainability: DEFAULT_MI_FLOORS,
410
406
  });
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * The one default review chain: the factory's unset/empty fallback and the
3
- * runtime schema's declared default. `code-review` is `optional` so hosts
4
- * without the `claude` CLI close on `native` alone.
3
+ * runtime schema's declared default. `llm-review` (the first available of
4
+ * `claude` then `codex`) is `optional` so hosts with neither CLI close on
5
+ * `native` alone.
5
6
  */
6
7
  export const DEFAULT_REVIEW_PROVIDERS = Object.freeze([
7
8
  Object.freeze({ name: 'native' }),
8
9
  Object.freeze({
9
- name: 'code-review',
10
+ name: 'llm-review',
10
11
  scopes: Object.freeze(['story']),
11
12
  optional: true,
12
13
  }),
@@ -0,0 +1,11 @@
1
+ /** Each review provider's CLIs, in probe order. Built-ins only, for doctor. */
2
+ const clis = {
3
+ 'code-review': ['claude'],
4
+ 'security-review': ['claude'],
5
+ codex: ['codex'],
6
+ 'llm-review': ['claude', 'codex'],
7
+ };
8
+
9
+ for (const order of Object.values(clis)) Object.freeze(order);
10
+
11
+ export const REVIEW_PROVIDER_CLIS = Object.freeze(clis);
@@ -8,52 +8,18 @@
8
8
  * worktree and the host reading from the main checkout converge on one file.
9
9
  */
10
10
 
11
- import { execFileSync } from 'node:child_process';
12
11
  import { mkdtempSync } from 'node:fs';
13
12
  import os from 'node:os';
14
13
  import path from 'node:path';
15
14
 
16
15
  import { reapOnExit } from '../test-temp.js';
16
+ import { _clearGitRootCaches, mainCheckoutRoot } from './git-roots.js';
17
17
 
18
- /** Keyed by cwd; a cached `null` records a non-repo miss. */
19
- const _mainCheckoutRootCache = new Map();
20
-
21
- /**
22
- * Parent of `--git-common-dir`, which is the main checkout root from both the
23
- * main checkout and any linked worktree. `null` outside a repo.
24
- *
25
- * @param {string} [cwd=process.cwd()]
26
- * @param {{ exec?: typeof execFileSync }} [deps]
27
- * @returns {string|null}
28
- */
29
- export function mainCheckoutRoot(cwd = process.cwd(), deps = {}) {
30
- const exec = deps.exec ?? execFileSync;
31
- // Only the real resolver is memoized.
32
- const memoize = !deps.exec;
33
- if (memoize && _mainCheckoutRootCache.has(cwd)) {
34
- return _mainCheckoutRootCache.get(cwd);
35
- }
36
- let resolved = null;
37
- try {
38
- const out = exec('git', ['rev-parse', '--git-common-dir'], {
39
- cwd,
40
- encoding: 'utf8',
41
- stdio: ['ignore', 'pipe', 'ignore'],
42
- }).trim();
43
- if (out) {
44
- const commonDir = path.isAbsolute(out) ? out : path.resolve(cwd, out);
45
- resolved = path.dirname(commonDir);
46
- }
47
- } catch {
48
- resolved = null;
49
- }
50
- if (memoize) _mainCheckoutRootCache.set(cwd, resolved);
51
- return resolved;
52
- }
18
+ export { mainCheckoutRoot } from './git-roots.js';
53
19
 
54
20
  /** Test-only. */
55
21
  export function _clearMainCheckoutRootCache() {
56
- _mainCheckoutRootCache.clear();
22
+ _clearGitRootCaches();
57
23
  }
58
24
 
59
25
  /**
@@ -12,14 +12,13 @@ import {
12
12
  } from './config/agentrc-overlay.js';
13
13
  import { getCiDelivery } from './config/ci.js';
14
14
  import { getCommands } from './config/commands.js';
15
- import { applyGhConfigDir } from './config/gh-config-dir.js';
15
+ import { overlayRoot, resolveAgentrcRoot } from './config/git-roots.js';
16
16
  import { getGitHub } from './config/github.js';
17
17
  import { resolvePaths } from './config/paths.js';
18
18
  import { validateOrchestrationConfig } from './config/validate-orchestration.js';
19
19
  import { getWorktreeIsolation } from './config/worktree-isolation.js';
20
20
  import { getAgentrcValidator } from './config-schema.js';
21
21
  import { loadEnv } from './env-loader.js';
22
- import { PROJECT_ROOT } from './project-root.js';
23
22
 
24
23
  export { getAcceptanceEval } from './config/acceptance-eval.js';
25
24
  export { BASELINES_DEFAULTS, getBaselines } from './config/baselines.js';
@@ -147,7 +146,7 @@ function applyDefaults(raw) {
147
146
  */
148
147
  function readRawConfig(fsImpl, root) {
149
148
  const agentrcPath = path.join(root, '.agentrc.json');
150
- const localPath = path.join(root, '.agentrc.local.json');
149
+ const localPath = path.join(overlayRoot(root), '.agentrc.local.json');
151
150
  const hasAgentrc = fsImpl.existsSync(agentrcPath);
152
151
  const hasLocal = fsImpl.existsSync(localPath);
153
152
  if (!hasAgentrc) {
@@ -203,15 +202,13 @@ function ensureEnvLoaded(root) {
203
202
  /**
204
203
  * Returns `{ project, github, planning, delivery, qa?, raw, source }`. A
205
204
  * missing file falls back to defaults; malformed JSON or a schema failure
206
- * throws. A set `github.cliConfigDir` is applied to `GH_CONFIG_DIR`. A call with an injected `ctx.fs` neither reads nor fills the
207
- * shared cache.
205
+ * throws. The root is `resolveAgentrcRoot`'s; `GH_CONFIG_DIR` is gh-exec's. A call
206
+ * with an injected `ctx.fs` neither reads nor fills the shared cache.
208
207
  *
209
208
  * @param {{ bustCache?: boolean, cwd?: string, validate?: boolean, ctx?: object }} [opts]
210
209
  */
211
210
  export function resolveConfig(opts) {
212
- const root = path.resolve(
213
- opts?.cwd ?? process.env.AP_AGENTRC_CWD ?? PROJECT_ROOT,
214
- );
211
+ const root = resolveAgentrcRoot({ cwd: opts?.cwd });
215
212
  const validate = opts?.validate !== false;
216
213
  const injectedFs = opts?.ctx?.fs;
217
214
  const key = `${root}\0${validate}`;
@@ -223,7 +220,6 @@ export function resolveConfig(opts) {
223
220
  readRawConfig(injectedFs ?? fs, root),
224
221
  validate,
225
222
  );
226
- applyGhConfigDir(resolved.github, root, { fsImpl: injectedFs ?? fs });
227
223
  if (!injectedFs) _cacheByKey.set(key, resolved);
228
224
  return resolved;
229
225
  }
@@ -30,7 +30,7 @@ const EXECUTION_SCHEMA = {
30
30
  fullSuiteLock: {
31
31
  type: 'boolean',
32
32
  description:
33
- 'Serialize full-suite spawns (`npm test` / `npm run test:coverage`) behind a repository-level advisory lock shared by every worktree, so two concurrent deliveries do not run two suites against the same cores (see `capacity` / `workloads` for declared runs that may overlap). The lock queues, it never overlaps: a wait that expires with a live holder spawns nothing and exits 75 (resumable), naming the holder. A dead or non-heartbeating holder is taken over, and a broken lockfile proceeds unserialized, so the lock can never fail a delivery. Set false — or export `MANDREL_FULL_SUITE_LOCK=0` for one invocation — to disable.',
33
+ "Serialize full-suite spawns (`npm test` / the coverage gate's `captureScript`) behind a repository-level advisory lock shared by every worktree, so two concurrent deliveries do not run two suites against the same cores (see `capacity` / `workloads` for declared runs that may overlap). The lock queues, it never overlaps: a wait that expires with a live holder spawns nothing and exits 75 (resumable), naming the holder. A dead or non-heartbeating holder is taken over, and a broken lockfile proceeds unserialized, so the lock can never fail a delivery. Set false — or export `MANDREL_FULL_SUITE_LOCK=0` for one invocation — to disable.",
34
34
  default: true,
35
35
  },
36
36
  capacity: {
@@ -51,7 +51,7 @@ const EXECUTION_SCHEMA = {
51
51
  ...SAFE_STRING,
52
52
  minLength: 1,
53
53
  description:
54
- 'The exact suite argv, as `project.commands.test` spells it (or `npm run test:coverage` for coverage capture).',
54
+ 'The exact suite argv, as `project.commands.test` spells it (or `<pm> run <captureScript>` for coverage capture).',
55
55
  },
56
56
  weight: {
57
57
  type: 'integer',
@@ -85,11 +85,12 @@ export const CODE_REVIEW_SCHEMA = {
85
85
  'native',
86
86
  'code-review',
87
87
  'codex',
88
+ 'llm-review',
88
89
  'security-review',
89
90
  'ultrareview',
90
91
  ],
91
92
  description:
92
- 'Registered provider key. Inline: native, code-review, codex, security-review. Manual-prompt: ultrareview.',
93
+ 'Registered provider key. Inline: native, code-review, codex, llm-review, security-review. Manual-prompt: ultrareview.',
93
94
  },
94
95
  scopes: {
95
96
  type: 'array',
@@ -132,7 +133,7 @@ export const CODE_REVIEW_SCHEMA = {
132
133
  additionalProperties: false,
133
134
  },
134
135
  description:
135
- "Review-provider chain (Story #2871). When unset or empty, falls back to this default: `native` (maintainability scoring of the changed files) then an optional story-scoped `code-review` — a low-effort `claude --print` bug review whose every finding is critical and halts close before auto-merge; hosts without the `claude` CLI skip it. `security-review` and `ultrareview` are opt-in. The orchestrator iterates inline entries in declaration order and merges their Finding[] before posting one structured comment; manual-prompt entries (e.g. ultrareview) contribute a trailing 'Manual review suggestions' section. Selecting an adapter whose probe fails hard-fails at factory construction unless declared `optional: true` in the chain.",
136
+ "Review-provider chain (Story #2871). When unset or empty, falls back to this default: `native` (maintainability scoring of the changed files) then an optional story-scoped `llm-review` — the first available of `code-review` (a low-effort `claude --print` bug review whose every finding is critical and halts close before auto-merge) and `codex` (`codex exec`), so a host with both CLIs runs one LLM review and a host with neither skips it. Pin `code-review` or `codex` to choose the CLI. `security-review` and `ultrareview` are opt-in. The orchestrator iterates inline entries in declaration order and merges their Finding[] before posting one structured comment; manual-prompt entries (e.g. ultrareview) contribute a trailing 'Manual review suggestions' section. Selecting an adapter whose probe fails hard-fails at factory construction unless declared `optional: true` in the chain.",
136
137
  default: DEFAULT_REVIEW_PROVIDERS,
137
138
  },
138
139
  autoFixSeverity: {
@@ -80,32 +80,31 @@ const PATHS_SCHEMA = {
80
80
  const COMMANDS_SCHEMA = {
81
81
  type: 'object',
82
82
  description:
83
- 'Shell commands the close-validation chain spawns. Each is run from the repo root.',
83
+ 'Shell commands the close-validation chain spawns, each run from the repo root. One tri-state per key: absent uses the default shown; an explicit `null` disables an optional gate (`typecheck`, `lint`, `formatCheck`) — close reports it as skipped (`<gate>-disabled`) and runs nothing; a string is that command. Like every command here it must be a single argv (no `;`, `&&`, pipes or substitution), so wrap a multi-tool pair in one script and name that.',
84
84
  properties: {
85
85
  test: {
86
86
  ...SAFE_STRING,
87
87
  minLength: 1,
88
88
  description:
89
- "Full test-suite command close's `test` gate spawns, and the identity its `test` credit is hashed under — the deposit `run-tests.js` makes, close's credit probe and `verify[]` credit all key on it, as does `mandrel doctor`'s `test-credit-path` check. Set it for a non-npm project (e.g. `python3 scripts/validation.py`); unset, it is `npm test`. Like every command here it must be a single argv (no `;`, `&&`, pipes or substitution).",
89
+ "Full test-suite command close's `test` gate spawns, and the identity its `test` credit is hashed under — the deposit `run-tests.js` makes, close's credit probe and `verify[]` credit all key on it, as does `mandrel doctor`'s `test-credit-path` check. Set it for a non-npm project (e.g. `python3 scripts/validation.py`). Mandatory: `null` is rejected.",
90
90
  default: COMMANDS_DEFAULTS.test,
91
91
  },
92
92
  typecheck: {
93
93
  ...NULLABLE_NONEMPTY_SAFE_STRING,
94
94
  description:
95
- 'Static type-check command run as a close-validation gate. Left unset (the `null` default), it falls back to `npm run typecheck`. An explicit `null` disables the gate for projects with no type layer: close reports it as skipped (`typecheck-disabled`) and runs nothing. The empty string is rejected so a typo cannot silently disable it.',
95
+ 'Static type-check command run as a close-validation gate. An explicit `null` disables the gate for projects with no type layer (skip reason `typecheck-disabled`). The empty string is rejected so a typo cannot silently disable it.',
96
96
  default: COMMANDS_DEFAULTS.typecheck,
97
97
  },
98
98
  lint: {
99
99
  ...NULLABLE_NONEMPTY_SAFE_STRING,
100
100
  description:
101
- 'Lint command run as a close-validation gate. `null` (the default) uses `npm run lint`; the gate is mandatory, so unlike `typecheck` this key cannot disable it. Point it at the scoped command your hooks already run to stop paying for a third whole-repo lint at close — the gate still lints the diff, and CI still owns whole-repo drift. Like every command here it must be a single argv (no `;`, `&&`, pipes or substitution), so wrap a multi-linter pair in one npm script and name that.',
101
+ 'Lint command run as a close-validation gate and by the handoff preflight. An explicit `null` disables both (skip reason `lint-disabled`). Point it at the scoped command your hooks already run to stop paying for a third whole-repo lint at close — the gate still lints the diff, and CI still owns whole-repo drift.',
102
102
  default: COMMANDS_DEFAULTS.lint,
103
103
  },
104
104
  formatCheck: {
105
- ...SAFE_STRING,
106
- minLength: 1,
105
+ ...NULLABLE_NONEMPTY_SAFE_STRING,
107
106
  description:
108
- 'Non-mutating format verification run as a close-validation gate.',
107
+ 'Non-mutating format verification run as a close-validation gate. An explicit `null` disables the gate (skip reason `format-disabled`).',
109
108
  default: COMMANDS_DEFAULTS.formatCheck,
110
109
  },
111
110
  formatWrite: {
@@ -7,12 +7,13 @@ import fs from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import picomatch from 'picomatch';
9
9
  import { write, writeFile } from './baselines/writer.js';
10
+ import { COVERAGE_CAPTURE_DEFAULTS } from './config/gates/coverage.schema.js';
10
11
  import {
11
12
  captureStampPath,
12
13
  MissingCoverageArtifactError,
13
14
  } from './coverage-capture.js';
14
15
 
15
- const COVERAGE_FINAL_PATH = 'coverage/coverage-final.json';
16
+ const COVERAGE_FINAL_PATH = COVERAGE_CAPTURE_DEFAULTS.coveragePath;
16
17
  const COVERAGE_BASELINE_PATH = 'baselines/coverage.json';
17
18
  // Percentage points; baselines store two decimals.
18
19
  export const COVERAGE_TOLERANCE = 0.01;
@@ -6,6 +6,7 @@
6
6
  import fs from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import { resolveChangedFilesRef } from './changed-files.js';
9
+ import { COVERAGE_CAPTURE_DEFAULTS } from './config/gates/coverage.schema.js';
9
10
  import {
10
11
  captureStampPath,
11
12
  reportCaptureFailure,
@@ -19,7 +20,7 @@ import {
19
20
  } from './coverage-capture-delta.js';
20
21
  import { tryIncrementalCapture } from './coverage-capture-incremental.js';
21
22
 
22
- const AFFECTED_CAPTURE_SCRIPT = 'test:coverage:affected';
23
+ const AFFECTED_CAPTURE_SCRIPT = COVERAGE_CAPTURE_DEFAULTS.affectedCaptureScript;
23
24
  const COVERAGE_BASE_REF_ENV = 'MANDREL_COVERAGE_BASE_REF';
24
25
 
25
26
  /** A configured scope with no script warns, and the caller runs full scope. */
@@ -32,7 +33,7 @@ function shouldCaptureAffected({
32
33
  if (coverage?.captureScope !== 'affected') return false;
33
34
  if (hasNpmScriptImpl(scripts, AFFECTED_CAPTURE_SCRIPT)) return true;
34
35
  logger.warn(
35
- `[coverage-capture] ⚠ captureScope is "affected" but package.json has no "${AFFECTED_CAPTURE_SCRIPT}" script — running the full npm run test:coverage instead.`,
36
+ `[coverage-capture] ⚠ captureScope is "affected" but package.json has no "${AFFECTED_CAPTURE_SCRIPT}" script — running the full ${coverage.captureScript} capture instead.`,
36
37
  );
37
38
  return false;
38
39
  }
@@ -163,7 +164,7 @@ function writeMerged({
163
164
  const scoped = readArtifact(artifactAbs, fsImpl);
164
165
  if (scoped === null) {
165
166
  logger.error(
166
- `[coverage-capture] ✖ npm run ${AFFECTED_CAPTURE_SCRIPT} exited 0 but wrote no readable artifact at ${crap.coveragePath} — point its coverage output there.`,
167
+ `[coverage-capture] ✖ the ${AFFECTED_CAPTURE_SCRIPT} script exited 0 but wrote no readable artifact at ${crap.coveragePath} — point its coverage output there.`,
167
168
  );
168
169
  return false;
169
170
  }
@@ -1,6 +1,8 @@
1
1
  /** Full-scope (default) capture path for `coverage-capture.js`. */
2
+
2
3
  import path from 'node:path';
3
4
  import { resolveChangedFilesRef } from './changed-files.js';
5
+ import { COVERAGE_CAPTURE_DEFAULTS } from './config/gates/coverage.schema.js';
4
6
  import {
5
7
  anyChangedUnderTargets,
6
8
  describeFreshness,
@@ -96,7 +98,7 @@ export async function runFullScopeCapture({
96
98
  }
97
99
 
98
100
  logger.info(
99
- `[coverage-capture] Coverage at ${crap.coveragePath} is ${describeFreshness(freshness, crap.targetDirs)}; running npm run ${crap.captureScript ?? 'test:coverage'}… ${detail}`,
101
+ `[coverage-capture] Coverage at ${crap.coveragePath} is ${describeFreshness(freshness, crap.targetDirs)}; running the ${crap.captureScript ?? COVERAGE_CAPTURE_DEFAULTS.captureScript} capture script… ${detail}`,
100
102
  );
101
103
  const tree = snapshotCapturedTree({
102
104
  cwd: args.cwd,