mandrel 2.90.0 → 2.92.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 (175) 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/single-story-close/phases/finish.js +4 -1
  106. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +49 -83
  107. package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -3
  108. package/.agents/scripts/lib/orchestration/story-close/format-autofix.js +41 -15
  109. package/.agents/scripts/lib/orchestration/story-deliver-terminal-schema.js +2 -4
  110. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +2 -13
  111. package/.agents/scripts/lib/orchestration/story-handoff.js +13 -5
  112. package/.agents/scripts/lib/orchestration/story-init-result.js +11 -0
  113. package/.agents/scripts/lib/orchestration/story-progress.js +3 -11
  114. package/.agents/scripts/lib/orchestration/ticketing/bulk.js +3 -5
  115. package/.agents/scripts/lib/orchestration/ticketing/transition.js +47 -21
  116. package/.agents/scripts/lib/orchestration/verify-credit.js +52 -28
  117. package/.agents/scripts/lib/single-story-sweep/protection-ctx.js +11 -11
  118. package/.agents/scripts/lib/single-story-sweep/protection.js +1 -9
  119. package/.agents/scripts/lib/single-story-sweep/sweep-lock.js +1 -5
  120. package/.agents/scripts/lib/source-extensions.js +30 -15
  121. package/.agents/scripts/lib/test-run-credit.js +1 -9
  122. package/.agents/scripts/lib/test-temp.js +22 -21
  123. package/.agents/scripts/lib/util/ajv.js +111 -0
  124. package/.agents/scripts/lib/util/atomic-write.js +30 -0
  125. package/.agents/scripts/lib/util/paths.js +51 -0
  126. package/.agents/scripts/lib/util/sleep.js +6 -0
  127. package/.agents/scripts/lib/util/slug.js +12 -0
  128. package/.agents/scripts/lib/validation-evidence.js +19 -40
  129. package/.agents/scripts/lib/worktree/lifecycle/force-drain.js +2 -1
  130. package/.agents/scripts/lib/worktree/lifecycle/pending-cleanup.js +10 -28
  131. package/.agents/scripts/lib/worktree/lifecycle/reap.js +2 -2
  132. package/.agents/scripts/lib/worktree/node-modules-strategy.js +21 -14
  133. package/.agents/scripts/lint-issue-body.js +2 -2
  134. package/.agents/scripts/plan-context.js +2 -7
  135. package/.agents/scripts/providers/github/auth.js +3 -3
  136. package/.agents/scripts/providers/github/errors.js +3 -1
  137. package/.agents/scripts/providers/github/gh-token-diagnostics.js +10 -7
  138. package/.agents/scripts/providers/github/issues.js +6 -2
  139. package/.agents/scripts/providers/github/mappers.js +1 -5
  140. package/.agents/scripts/providers/github/projects-v2-graphql.js +11 -3
  141. package/.agents/scripts/providers/github/search-budget.js +3 -1
  142. package/.agents/scripts/resolve-doc-tiers.js +7 -20
  143. package/.agents/scripts/single-story-init.js +18 -14
  144. package/.agents/scripts/sync-agentrc.js +5 -14
  145. package/.agents/scripts/sync-claude-agents.js +38 -150
  146. package/.agents/scripts/sync-claude-commands.js +35 -218
  147. package/.agents/scripts/update-coverage-baseline.js +1 -1
  148. package/.agents/scripts/update-crap-baseline.js +1 -1
  149. package/.agents/scripts/update-duplication-baseline.js +2 -16
  150. package/.agents/scripts/validate-skills.js +6 -10
  151. package/.agents/skills/core/code-review-and-quality/SKILL.md +3 -18
  152. package/.agents/skills/core/documentation-and-adrs/SKILL.md +4 -14
  153. package/.agents/workflows/audit-exceptions.md +9 -0
  154. package/.agents/workflows/audit-lean.md +129 -0
  155. package/.agents/workflows/helpers/audit-lens-core.md +7 -0
  156. package/.agents/workflows/helpers/code-quality-guardrails.md +21 -0
  157. package/.agents/workflows/helpers/code-review.md +15 -1
  158. package/.agents/workflows/helpers/deliver-digest.md +1 -1
  159. package/.agents/workflows/helpers/deliver-reference.md +2 -2
  160. package/.agents/workflows/helpers/deliver-story-reference.md +19 -8
  161. package/.agents/workflows/mandrel-plan.md +2 -2
  162. package/docs/CHANGELOG.md +42 -0
  163. package/lib/cli/doctor-checks/codex.js +6 -5
  164. package/lib/cli/doctor-checks/llm-review.js +102 -0
  165. package/lib/cli/doctor-checks/project-access.js +20 -10
  166. package/lib/cli/doctor-checks/sync-parity.js +65 -140
  167. package/lib/cli/doctor-checks/test-credit-path.js +69 -28
  168. package/lib/cli/doctor-checks/toolchain.js +5 -3
  169. package/lib/cli/registry.js +5 -0
  170. package/lib/migrations/helpers/retire-agentrc-key.js +3 -3
  171. package/lib/migrations/index.js +6 -0
  172. package/lib/migrations/steps/2.91.0-move-shared-crap-capture-script.js +84 -0
  173. package/lib/migrations/steps/2.91.0-retire-duplication-formats.js +23 -0
  174. package/lib/migrations/steps/2.91.0-unset-null-lint-command.js +54 -0
  175. package/package.json +1 -3
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Claude command projection: `.agents/workflows/` and `.agents/local/workflows/`
3
+ * become a flat `.claude/commands/` tree (flat, not a plugin tree, which some
4
+ * hosts lack). Payload wins a collision; `loops/` is the one recursed
5
+ * subdirectory. Node built-ins only, so the doctor can import it.
6
+ */
7
+
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ import { applyHeader, isCommandExcluded } from '../command-header.js';
12
+ import { dirExists } from '../util/paths.js';
13
+
14
+ export const CLAUDE_COMMANDS_DIR = '.claude/commands';
15
+
16
+ const HEADER =
17
+ '<!-- AUTO-GENERATED — do not edit. Source of truth: .agents/workflows/ -->\n<!-- Re-run: npm run sync:commands -->\n\n';
18
+
19
+ const LOCAL_HEADER =
20
+ '<!-- AUTO-GENERATED from .agents/local/ — do not edit. Source of truth: .agents/local/workflows/ -->\n<!-- Re-run: npm run sync:commands -->\n\n';
21
+
22
+ const LOOPS_NS = 'loops';
23
+
24
+ /**
25
+ * @param {string} dir
26
+ * @param {boolean} skipReadme
27
+ * @returns {string[]}
28
+ */
29
+ function mdFilesIn(dir, skipReadme) {
30
+ if (!dirExists(dir)) return [];
31
+ return fs
32
+ .readdirSync(dir, { withFileTypes: true })
33
+ .filter(
34
+ (e) =>
35
+ e.isFile() &&
36
+ e.name.endsWith('.md') &&
37
+ !(skipReadme && e.name.toLowerCase() === 'readme.md'),
38
+ )
39
+ .map((e) => e.name);
40
+ }
41
+
42
+ /**
43
+ * Flat commands, then `loops/<name>.md`.
44
+ *
45
+ * @param {string} dir
46
+ * @returns {string[]}
47
+ */
48
+ function commandRelsIn(dir) {
49
+ return [
50
+ ...mdFilesIn(dir, false),
51
+ ...mdFilesIn(path.join(dir, LOOPS_NS), true).map((f) => `${LOOPS_NS}/${f}`),
52
+ ];
53
+ }
54
+
55
+ /**
56
+ * Projected bytes keyed by destination-relative path. A `command: false` copy
57
+ * never claims its name.
58
+ *
59
+ * @param {{
60
+ * projectRoot: string,
61
+ * payloadSrc?: string,
62
+ * localSrc?: string,
63
+ * warn?: (line: string) => void,
64
+ * }} opts
65
+ * @returns {Map<string, string>}
66
+ */
67
+ export function expectedClaudeCommands({
68
+ projectRoot,
69
+ payloadSrc = path.join(projectRoot, '.agents', 'workflows'),
70
+ localSrc = path.join(projectRoot, '.agents', 'local', 'workflows'),
71
+ warn = () => {},
72
+ }) {
73
+ const expected = new Map();
74
+ for (const [dir, header] of [
75
+ [payloadSrc, HEADER],
76
+ [localSrc, LOCAL_HEADER],
77
+ ]) {
78
+ for (const rel of commandRelsIn(dir)) {
79
+ if (expected.has(rel)) {
80
+ warn(` shadowed ${rel} (local copy ignored; payload wins)`);
81
+ continue;
82
+ }
83
+ const content = fs.readFileSync(path.join(dir, rel), 'utf8');
84
+ if (isCommandExcluded(content)) {
85
+ warn(` excluded ${rel} (frontmatter command: false)`);
86
+ continue;
87
+ }
88
+ expected.set(rel, applyHeader(content, header));
89
+ }
90
+ }
91
+ return expected;
92
+ }
93
+
94
+ /**
95
+ * @param {string} destDir
96
+ * @returns {string[]}
97
+ */
98
+ export function listGeneratedClaudeCommands(destDir) {
99
+ return commandRelsIn(destDir)
100
+ .filter((rel) => !path.basename(rel).startsWith('.'))
101
+ .sort();
102
+ }
103
+
104
+ /**
105
+ * Remove a plugin projection, which would shadow the flat commands.
106
+ *
107
+ * @param {string} projectRoot
108
+ * @param {(line: string) => void} warn
109
+ * @returns {void}
110
+ */
111
+ function reapPluginTree(projectRoot, warn) {
112
+ const claudeDir = path.join(projectRoot, '.claude');
113
+ for (const target of [
114
+ path.join(claudeDir, 'plugins', 'mandrel'),
115
+ path.join(claudeDir, '.claude-plugin', 'marketplace.json'),
116
+ ]) {
117
+ try {
118
+ fs.rmSync(target, { recursive: true, force: true });
119
+ } catch (err) {
120
+ warn(` skip reap ${target}: ${err.message}`);
121
+ }
122
+ }
123
+ try {
124
+ fs.rmdirSync(path.join(claudeDir, '.claude-plugin'));
125
+ } catch {
126
+ /* not empty or absent — leave it */
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Write the projection, reap orphans, skip unchanged files.
132
+ *
133
+ * @param {{
134
+ * projectRoot: string,
135
+ * payloadSrc?: string,
136
+ * localSrc?: string,
137
+ * destDir?: string,
138
+ * log?: (line: string) => void,
139
+ * warn?: (line: string) => void,
140
+ * }} opts
141
+ * @returns {{ written: string[], removed: string[], total: number }}
142
+ */
143
+ export function syncClaudeCommands({
144
+ projectRoot,
145
+ payloadSrc,
146
+ localSrc,
147
+ destDir = path.join(projectRoot, ...CLAUDE_COMMANDS_DIR.split('/')),
148
+ log = () => {},
149
+ warn = log,
150
+ }) {
151
+ reapPluginTree(projectRoot, warn);
152
+ fs.mkdirSync(destDir, { recursive: true });
153
+ const expected = expectedClaudeCommands({
154
+ projectRoot,
155
+ payloadSrc,
156
+ localSrc,
157
+ warn,
158
+ });
159
+
160
+ const removed = [];
161
+ for (const rel of commandRelsIn(destDir)) {
162
+ if (expected.has(rel)) continue;
163
+ fs.unlinkSync(path.join(destDir, rel));
164
+ removed.push(rel);
165
+ log(` removed ${rel} (no longer in workflows)`);
166
+ }
167
+
168
+ const written = [];
169
+ for (const [rel, body] of expected) {
170
+ const dest = path.join(destDir, rel);
171
+ let current = null;
172
+ try {
173
+ current = fs.readFileSync(dest, 'utf8');
174
+ } catch (err) {
175
+ if (err.code !== 'ENOENT') throw err;
176
+ }
177
+ if (current === body) continue;
178
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
179
+ fs.writeFileSync(dest, body, 'utf8');
180
+ written.push(rel);
181
+ log(` synced ${rel}`);
182
+ }
183
+ return { written, removed, total: expected.size };
184
+ }
@@ -1,85 +1,35 @@
1
- /** Close-validation `project.commands.*` resolution and formatter file policy. */
1
+ /** Close-validation `project.commands.*` spawns and formatter file policy. */
2
2
 
3
- import { execFileSync } from 'node:child_process';
4
3
  import { diffNameOnly } from '../changed-files.js';
5
- import { getCommands } from '../config/commands.js';
6
-
7
- /** The typecheck and lint gates are mandatory, so they carry their own fallbacks. */
8
- const TYPECHECK_FALLBACK = 'npm run typecheck';
9
-
10
- /**
11
- * Must stay byte-identical: `commandConfigHash` covers it, and drift would
12
- * invalidate every recorded lint evidence record.
13
- */
14
- const LINT_FALLBACK = 'npm run lint';
15
-
16
- /**
17
- * Must stay byte-identical: it is the close `test` gate's argv and the credit
18
- * identity `test-run-credit` and `verify-credit` hash, so drift would
19
- * invalidate every recorded `test` evidence record.
20
- */
21
- const TEST_FALLBACK = 'npm test';
22
-
23
- export const FORMAT_CHECK_FALLBACK = 'npx biome format .';
24
-
25
- const FORMAT_WRITE_FALLBACK = 'npx biome format --write .';
4
+ import {
5
+ COMMANDS_DEFAULTS,
6
+ resolveProjectCommand,
7
+ } from '../config/commands.js';
26
8
 
27
9
  /** Derived from the write command so a Prettier repo is not told to run biome. */
28
10
  export function buildFormatHint(writeCmd) {
29
11
  const cmd =
30
- writeCmd && writeCmd.trim().length > 0 ? writeCmd : FORMAT_WRITE_FALLBACK;
12
+ writeCmd && writeCmd.trim().length > 0
13
+ ? writeCmd
14
+ : COMMANDS_DEFAULTS.formatWrite;
31
15
  return `Run \`${cmd}\` to auto-fix formatting drift.`;
32
16
  }
33
17
 
34
18
  /**
35
- * Falls back on a missing/empty value or malformed config.
19
+ * A disabled gate keeps the default argv as its (never-spawned) identity.
36
20
  *
37
- * @param {{ project?: { commands?: object } } | null | undefined} config
38
- * @param {string} key
39
- * @param {string} fallback
40
- * @returns {string}
21
+ * @param {object | null | undefined} config
22
+ * @param {keyof typeof COMMANDS_DEFAULTS} key
41
23
  */
42
- function resolveCommandWithFallback(config, key, fallback) {
43
- try {
44
- const cmds = getCommands(config);
45
- const value = cmds[key];
46
- if (typeof value === 'string' && value.trim().length > 0) {
47
- return value.trim();
48
- }
49
- } catch {
50
- // Malformed config — use the fallback.
51
- }
52
- return fallback;
24
+ export function resolveGateCommand(config, key) {
25
+ const { raw, disabled, argv } = resolveProjectCommand(config, key);
26
+ const [cmd, ...args] = disabled ? defaultArgv(key) : argv;
27
+ return { cmd, args, raw, disabled };
53
28
  }
54
29
 
55
- /**
56
- * @param {{ project?: { commands?: object } } | null | undefined} config
57
- * @returns {string}
58
- */
59
- export function resolveTypecheckCommand(config) {
60
- return resolveCommandWithFallback(config, 'typecheck', TYPECHECK_FALLBACK);
61
- }
62
-
63
- /**
64
- * Own-present explicit `null` only: `getCommands` collapses absent and `null`.
65
- *
66
- * @param {{ project?: { commands?: object } } | null | undefined} config
67
- * @returns {boolean}
68
- */
69
- export function isTypecheckDisabled(config) {
70
- const commands = config?.project?.commands;
71
- if (commands === null || typeof commands !== 'object') return false;
72
- return Object.hasOwn(commands, 'typecheck') && commands.typecheck === null;
73
- }
74
-
75
- /**
76
- * A consumer may point this at its hooks' scoped lint; CI keeps whole-repo drift.
77
- *
78
- * @param {{ project?: { commands?: object } } | null | undefined} config
79
- * @returns {string}
80
- */
81
- export function resolveLintCommand(config) {
82
- return resolveCommandWithFallback(config, 'lint', LINT_FALLBACK);
30
+ /** @param {keyof typeof COMMANDS_DEFAULTS} key */
31
+ function defaultArgv(key) {
32
+ return resolveProjectCommand(null, key).argv;
83
33
  }
84
34
 
85
35
  /**
@@ -90,46 +40,23 @@ export function resolveLintCommand(config) {
90
40
  * @returns {string}
91
41
  */
92
42
  export function resolveTestCommand(config) {
93
- return resolveCommandWithFallback(config, 'test', TEST_FALLBACK);
43
+ return resolveProjectCommand(config, 'test').raw;
94
44
  }
95
45
 
96
- /**
97
- * The argv close's `test` gate spawns — the one identity every `test`
98
- * credit (deposit, close probe, `verify[]` credit) hashes. Whitespace split,
99
- * as the gate builder splits every other `commands.*` key.
100
- *
101
- * @param {{ project?: { commands?: object } } | null | undefined} config
102
- * @returns {{ cmd: string, args: string[] }}
103
- */
46
+ /** The one identity every `test` credit hashes. @param {object|null|undefined} config */
104
47
  export function resolveTestGateArgv(config) {
105
- const [cmd, ...args] = resolveTestCommand(config)
106
- .split(/\s+/)
107
- .filter(Boolean);
48
+ const { cmd, args } = resolveGateCommand(config, 'test');
108
49
  return { cmd, args };
109
50
  }
110
51
 
111
- /**
112
- * @param {{ project?: { commands?: object } } | null | undefined} config
113
- * @returns {string}
114
- */
115
- export function resolveFormatCheckCommand(config) {
116
- return resolveCommandWithFallback(
117
- config,
118
- 'formatCheck',
119
- FORMAT_CHECK_FALLBACK,
120
- );
52
+ /** @param {object|null|undefined} config */
53
+ export function resolveFormatWriteCommand(config) {
54
+ return resolveProjectCommand(config, 'formatWrite').raw;
121
55
  }
122
56
 
123
- /**
124
- * @param {{ project?: { commands?: object } } | null | undefined} config
125
- * @returns {string}
126
- */
127
- export function resolveFormatWriteCommand(config) {
128
- return resolveCommandWithFallback(
129
- config,
130
- 'formatWrite',
131
- FORMAT_WRITE_FALLBACK,
132
- );
57
+ /** Only the default biome check gets a changed-file scope. */
58
+ export function isDefaultFormatCheck(formatCheckRaw) {
59
+ return formatCheckRaw === COMMANDS_DEFAULTS.formatCheck;
133
60
  }
134
61
 
135
62
  /**
@@ -143,23 +70,7 @@ export function listChangedFilesForFormatGate({ cwd, baseRef }) {
143
70
  if (!cwd) throw new Error('listChangedFilesForFormatGate: cwd is required');
144
71
  if (!baseRef)
145
72
  throw new Error('listChangedFilesForFormatGate: baseRef is required');
146
- const gitSpawn = (_cwd, ...args) => {
147
- try {
148
- const stdout = execFileSync('git', args, {
149
- cwd: _cwd,
150
- encoding: 'utf8',
151
- stdio: ['ignore', 'pipe', 'pipe'],
152
- });
153
- return { status: 0, stdout, stderr: '' };
154
- } catch (err) {
155
- return {
156
- status: err.status ?? 1,
157
- stdout: err.stdout ?? '',
158
- stderr: err.stderr ?? err.message,
159
- };
160
- }
161
- };
162
- return diffNameOnly({ baseRef, cwd, gitSpawn });
73
+ return diffNameOnly({ baseRef, cwd });
163
74
  }
164
75
 
165
76
  /**
@@ -6,22 +6,23 @@ import { _internals as baselineReaderInternals } from '../baselines/reader.js';
6
6
  import { getChangedFiles } from '../changed-files.js';
7
7
  import {
8
8
  COVERAGE_GATE_DEFAULTS,
9
- CRAP_GATE_DEFAULTS,
10
9
  getQuality,
10
+ resolveQuality,
11
11
  } from '../config/quality.js';
12
12
  import { filterFilesUnderTargets } from '../coverage-capture.js';
13
+ import {
14
+ isCaptureActive,
15
+ primaryCaptureSource,
16
+ } from '../coverage-capture-passes.js';
13
17
  import { hasNpmScript, readPackageScripts } from '../npm-scripts.js';
14
18
  import { KNOWN_KINDS } from '../orchestration/check-baselines/phases/parse-args.js';
15
19
  import { predictsTestEvidenceCredit } from '../test-run-credit.js';
16
20
  import {
17
21
  buildFormatHint,
18
- FORMAT_CHECK_FALLBACK,
19
- isTypecheckDisabled,
20
- resolveFormatCheckCommand,
22
+ isDefaultFormatCheck,
21
23
  resolveFormatWriteCommand,
22
- resolveLintCommand,
24
+ resolveGateCommand,
23
25
  resolveTestGateArgv,
24
- resolveTypecheckCommand,
25
26
  } from './commands.js';
26
27
 
27
28
  /**
@@ -74,33 +75,34 @@ export function isCrapGateEnabled(config) {
74
75
  }
75
76
 
76
77
  /**
77
- * The npm script that writes the CRAP coverage artifact —
78
- * `gates.crap.captureScript`, default `test:coverage`. Read
79
- * from the unresolved block for the same reason as {@link isCrapGateEnabled}.
78
+ * Resolves only the two gates capture reads, so a broken sibling gate block
79
+ * is left to the baselines partition's own fail-closed path.
80
80
  *
81
81
  * @param {object|undefined|null} config - Canonical resolved config.
82
- * @returns {string}
83
82
  */
84
- function crapCaptureScript(config) {
85
- const script = config?.delivery?.quality?.gates?.crap?.captureScript;
86
- return typeof script === 'string' && script.trim().length > 0
87
- ? script.trim()
88
- : CRAP_GATE_DEFAULTS.captureScript;
83
+ function captureQuality(config) {
84
+ const gates = config?.delivery?.quality?.gates ?? {};
85
+ const { crap, coverage } = gates;
86
+ return resolveQuality({ gates: { crap, coverage } });
89
87
  }
90
88
 
91
89
  /**
92
- * Coverage-capture registers when the CRAP gate is on AND the CRAP capture
93
- * script exists; {@link resolveCreditedDepositor} builds on it.
90
+ * Coverage-capture registers when the coverage or CRAP gate is on AND the
91
+ * primary capture script exists (the coverage gate's `captureScript`, or an
92
+ * own CRAP source's); {@link resolveCreditedDepositor} builds on it.
94
93
  *
95
94
  * @param {object|undefined|null} config - Canonical resolved config.
96
95
  * @param {Record<string, string>|null|undefined} scripts - `package.json` scripts.
97
96
  * @returns {boolean}
98
97
  */
99
98
  function isCoverageCaptureActive(config, scripts) {
100
- return (
101
- isCrapGateEnabled(config) &&
102
- hasNpmScript(scripts, crapCaptureScript(config))
103
- );
99
+ const { crap, coverage } = captureQuality(config);
100
+ return isCaptureActive({
101
+ crap,
102
+ coverage,
103
+ scripts,
104
+ hasNpmScriptImpl: hasNpmScript,
105
+ });
104
106
  }
105
107
 
106
108
  /**
@@ -260,14 +262,14 @@ function buildBaselinesGateEntries({ decision, kinds, env }) {
260
262
  }
261
263
 
262
264
  /**
263
- * Whitespace split; keeps an unconfigured consumer's `commandConfigHash` stable.
265
+ * The pre-decided skip an explicit `project.commands.<key>: null` registers.
264
266
  *
265
- * @param {string} commandString
266
- * @returns {{ cmd: string, args: string[] }}
267
+ * @param {{ disabled: boolean }} command
268
+ * @param {string} gateName
269
+ * @returns {{ skip?: { reason: string } }}
267
270
  */
268
- function splitCommand(commandString) {
269
- const [cmd, ...args] = commandString.split(/\s+/).filter(Boolean);
270
- return { cmd, args };
271
+ function disabledSkip(command, gateName) {
272
+ return command.disabled ? { skip: { reason: `${gateName}-disabled` } } : {};
271
273
  }
272
274
 
273
275
  /**
@@ -364,17 +366,19 @@ function coverageCaptureRunsSuite({
364
366
  /**
365
367
  * Names every suite the capture can run: under `captureScope: "affected"` a
366
368
  * red may come from a delta refresh the base-sync triggered, not the Story;
367
- * a non-default `gates.crap.captureScript` is named beside `test:coverage`.
369
+ * an own CRAP source's script is named beside the coverage gate's.
368
370
  *
369
- * @param {string} captureScript The CRAP capture script ({@link crapCaptureScript}).
371
+ * @param {object|undefined|null} config - Canonical resolved config.
370
372
  * @returns {string}
371
373
  */
372
- function coverageCaptureHint(captureScript) {
374
+ function coverageCaptureHint(config) {
375
+ const { crap, coverage } = captureQuality(config);
376
+ const primary = primaryCaptureSource({ crap, coverage });
373
377
  const crapScript =
374
- captureScript === CRAP_GATE_DEFAULTS.captureScript
378
+ primary.captureScript === coverage.captureScript
375
379
  ? ''
376
- : `, the CRAP gate's own \`npm run ${captureScript}\` (\`gates.crap.captureScript\`)`;
377
- return `Coverage capture failed — its suite run (\`npm run test:coverage\`${crapScript}, or \`npm run test:coverage:affected\` under \`captureScope: "affected"\`, including a delta refresh keyed on the stamped commit after a base-sync) exited non-zero. The coverage-capture log names which ran; fix the failing tests or coverage-threshold breaches, then re-run close.`;
380
+ : `, the CRAP gate's own \`${primary.captureScript}\` (\`gates.crap.captureScript\`)`;
381
+ return `Coverage capture failed — its suite run (the \`${coverage.captureScript}\` script, \`gates.coverage.captureScript\`${crapScript}, or the affected capture script under \`captureScope: "affected"\`, including a delta refresh keyed on the stamped commit after a base-sync) exited non-zero. The coverage-capture log names which ran; fix the failing tests or coverage-threshold breaches, then re-run close.`;
378
382
  }
379
383
 
380
384
  const COVERAGE_CAPTURE_ARGS = Object.freeze([
@@ -438,8 +442,8 @@ export const GATE_TIMEOUT_HINT = `The gate outran the suite timeout (\`delivery.
438
442
  /**
439
443
  * Build the close-validation gate list, cheapest fast-fail first: typecheck →
440
444
  * lint → [test] → format → [quality-preview-mi] → [coverage-capture →
441
- * quality-preview-crap] → check-baselines. Coverage-capture registers only when CRAP is enabled AND its
442
- * capture script (`gates.crap.captureScript`, default `test:coverage`) exists; it then carries test-failure signalling and
445
+ * quality-preview-crap] → check-baselines. Coverage-capture registers only when the coverage or CRAP gate is
446
+ * enabled AND its capture script (`gates.coverage.captureScript`) exists; it then carries test-failure signalling and
443
447
  * the plain `test` gate is dropped, so there is always exactly one test gate.
444
448
  *
445
449
  * @param {{ config?: object, baseBranch?: string, cwd?: string, packageScripts?: Record<string, string>, presentBaselines?: string[]|Set<string>, log?: (message: string) => void, getChangedFilesImpl?: typeof getChangedFiles }} [opts]
@@ -490,15 +494,13 @@ export function buildDefaultGates({
490
494
  '[close-validation] coverage-capture will take the incremental skip (no changed file under the CRAP target dirs) — registering the plain `test` gate so this close still runs the suite.',
491
495
  );
492
496
  }
493
- const typecheck = splitCommand(resolveTypecheckCommand(config));
494
- const lint = splitCommand(resolveLintCommand(config));
495
- const formatCheckString = resolveFormatCheckCommand(config);
496
- const format = splitCommand(formatCheckString);
497
+ const typecheck = resolveGateCommand(config, 'typecheck');
498
+ const lint = resolveGateCommand(config, 'lint');
499
+ const format = resolveGateCommand(config, 'formatCheck');
497
500
  const formatWriteString = resolveFormatWriteCommand(config);
498
- const formatChangedFileScope =
499
- formatCheckString === FORMAT_CHECK_FALLBACK
500
- ? buildChangedFileScope(baseBranch)
501
- : null;
501
+ const formatChangedFileScope = isDefaultFormatCheck(format.raw)
502
+ ? buildChangedFileScope(baseBranch)
503
+ : null;
502
504
  const baselinesGateEnv = buildBaselinesGateEnv(baseBranch);
503
505
  const baselineKinds = enabledBaselineKinds(config);
504
506
  const baselinesDecision = probeBaselinesGate({
@@ -520,13 +522,16 @@ export function buildDefaultGates({
520
522
  cmd: typecheck.cmd,
521
523
  args: typecheck.args,
522
524
  hint: TYPECHECK_HINT,
523
- ...(isTypecheckDisabled(config)
524
- ? { skip: { reason: 'typecheck-disabled' } }
525
- : {}),
525
+ ...disabledSkip(typecheck, 'typecheck'),
526
526
  },
527
527
  // Gate names stay generic though commands resolve from config, so the
528
528
  // log line, evidence keyspace and partition membership never shift.
529
- { name: 'lint', cmd: lint.cmd, args: lint.args },
529
+ {
530
+ name: 'lint',
531
+ cmd: lint.cmd,
532
+ args: lint.args,
533
+ ...disabledSkip(lint, 'lint'),
534
+ },
530
535
  ...buildTestGateEntry(
531
536
  coverageCaptureRunsSuite({
532
537
  coverageCaptureActive,
@@ -540,6 +545,7 @@ export function buildDefaultGates({
540
545
  cmd: format.cmd,
541
546
  args: format.args,
542
547
  hint: buildFormatHint(formatWriteString),
548
+ ...disabledSkip(format, 'format'),
543
549
  ...(formatChangedFileScope
544
550
  ? { changedFileScope: formatChangedFileScope }
545
551
  : {}),
@@ -551,7 +557,7 @@ export function buildDefaultGates({
551
557
  name: 'coverage-capture',
552
558
  cmd: 'node',
553
559
  args: [...COVERAGE_CAPTURE_ARGS],
554
- hint: coverageCaptureHint(crapCaptureScript(config)),
560
+ hint: coverageCaptureHint(config),
555
561
  lockEventChannel: true,
556
562
  ...(captureSkipPredicted
557
563
  ? { skip: { reason: 'incremental-no-crap-changes' } }
@@ -15,6 +15,7 @@ import {
15
15
  } from '../../baselines/kinds/crap.js';
16
16
  import { loadFile as loadBaselineFile } from '../../baselines/reader.js';
17
17
  import { diffNameOnly } from '../../changed-files.js';
18
+ import { COVERAGE_CAPTURE_DEFAULTS } from '../../config/gates/coverage.schema.js';
18
19
  import { loadCoverage } from '../../coverage-utils.js';
19
20
  import { scanAndScore } from '../../crap-utils.js';
20
21
  import { cachedGitFetchSync } from '../../git/cached-fetch.js';
@@ -78,7 +79,7 @@ export function createCrapScorer({
78
79
  targetDirs = [],
79
80
  ignoreGlobs = [],
80
81
  requireCoverage = true,
81
- coveragePath = 'coverage/coverage-final.json',
82
+ coveragePath = COVERAGE_CAPTURE_DEFAULTS.coveragePath,
82
83
  } = {}) {
83
84
  return async (files) => {
84
85
  const abs = path.isAbsolute(coveragePath)