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
@@ -2,90 +2,50 @@
2
2
 
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
- import { isCommandExcluded } from '../../../.agents/scripts/lib/command-header.js';
5
+ import {
6
+ CLAUDE_AGENTS_DIR,
7
+ expectedClaudeAgents,
8
+ listGeneratedClaudeAgents,
9
+ } from '../../../.agents/scripts/lib/claude/agents-projection.js';
10
+ import {
11
+ CLAUDE_COMMANDS_DIR,
12
+ expectedClaudeCommands,
13
+ listGeneratedClaudeCommands,
14
+ } from '../../../.agents/scripts/lib/claude/commands-projection.js';
6
15
  import { getDeliveryRouting } from '../../../.agents/scripts/lib/config/delivery-routing.js';
16
+ import { projectionParity, readTextOrNull } from './codex.js';
7
17
  import { readJsonSafe } from './read-json.js';
8
18
 
19
+ const COMMANDS_REMEDY =
20
+ 'Run `npm run sync:commands` to regenerate the `.claude/commands/` tree.';
21
+ const AGENTS_REMEDY =
22
+ 'Run `mandrel sync-agents` to regenerate the `.claude/agents/` tree.';
23
+
9
24
  // check: commands-in-sync
10
25
 
11
26
  /**
12
- * Parity of `.claude/commands/*.md` against the union of `.agents/workflows/`
13
- * and `.agents/local/workflows/`. A basename is expected iff at least one
14
- * source copy is not `command: false`, mirroring the sync script's
15
- * payload-wins shadowing; an unreadable source counts as projected.
27
+ * Parity of `.claude/commands/` against what the command projection would
28
+ * write now — byte-for-byte, so a same-name file with stale content fails as
29
+ * well as a missing or extra one.
16
30
  *
17
31
  * The root defaults to `process.cwd()`, never `resolveProjectRoot()` — that
18
32
  * lands on `node_modules/mandrel/` in an installed consumer, where the
19
33
  * command tree never exists, producing a permanent false "not synced".
20
34
  *
21
- * @param {{ projectRoot?: string, cwd?: () => string, readDir?: (dir: string) => string[], readFile?: (file: string) => string | null }} [opts]
35
+ * @param {{ projectRoot?: string, cwd?: () => string }} [opts]
22
36
  * @returns {{ ok: boolean, detail: string, remedy?: string }}
23
37
  */
24
- export function runCommandsInSync({
25
- projectRoot,
26
- cwd,
27
- readDir,
28
- readFile,
29
- } = {}) {
30
- const getCwd = cwd ?? (() => process.cwd());
31
- const root = projectRoot ?? getCwd();
32
- const listDir =
33
- readDir ??
34
- ((dir) => {
35
- try {
36
- return fs.readdirSync(dir).filter((f) => f.endsWith('.md'));
37
- } catch {
38
- return [];
39
- }
40
- });
41
- const readSource =
42
- readFile ??
43
- ((file) => {
44
- try {
45
- return fs.readFileSync(file, 'utf8');
46
- } catch {
47
- return null;
48
- }
49
- });
50
-
51
- const srcDirs = [
52
- path.join(root, '.agents', 'workflows'),
53
- path.join(root, '.agents', 'local', 'workflows'),
54
- ];
55
- const destDir = path.join(root, '.claude', 'commands');
56
-
57
- // Top-level .md only (helpers/ are included modules, not commands).
58
- const expected = new Set();
59
- for (const srcDir of srcDirs) {
60
- for (const f of listDir(srcDir)) {
61
- if (f.startsWith('.')) continue;
62
- const content = readSource(path.join(srcDir, f));
63
- if (content != null && isCommandExcluded(content)) continue;
64
- expected.add(f);
65
- }
66
- }
67
- const sources = [...expected].sort();
68
- const dests = listDir(destDir)
69
- .filter((f) => !f.startsWith('.'))
70
- .sort();
71
-
72
- const dstSet = new Set(dests);
73
- const missing = sources.filter((f) => !dstSet.has(f));
74
- const extra = dests.filter((f) => !expected.has(f));
75
-
76
- if (missing.length === 0 && extra.length === 0) {
77
- return { ok: true, detail: `${sources.length} commands up to date` };
78
- }
79
-
80
- const parts = [];
81
- if (missing.length > 0) parts.push(`${missing.length} not synced`);
82
- if (extra.length > 0) parts.push(`${extra.length} stale`);
83
- return {
84
- ok: false,
85
- detail: parts.join(', '),
86
- remedy:
87
- 'Run `npm run sync:commands` to regenerate the `.claude/commands/` tree.',
88
- };
38
+ export function runCommandsInSync({ projectRoot, cwd } = {}) {
39
+ const root = projectRoot ?? (cwd ?? (() => process.cwd()))();
40
+ const destDir = path.join(root, ...CLAUDE_COMMANDS_DIR.split('/'));
41
+ return projectionParity({
42
+ expected: () => expectedClaudeCommands({ projectRoot: root }),
43
+ onDisk: listGeneratedClaudeCommands(destDir),
44
+ readEntry: (rel) => readTextOrNull(path.join(destDir, rel)),
45
+ noun: 'commands',
46
+ where: `${CLAUDE_COMMANDS_DIR}/`,
47
+ remedy: COMMANDS_REMEDY,
48
+ });
89
49
  }
90
50
 
91
51
  // check: agents-in-sync
@@ -97,15 +57,11 @@ export function runCommandsInSync({
97
57
  * `.agentrc.local.json` (local wins).
98
58
  *
99
59
  * @param {string} projectRoot
100
- * @param {typeof fs} fsImpl
101
60
  * @returns {boolean}
102
61
  */
103
- function resolveRoleScopedAgentsFlag(projectRoot, fsImpl) {
104
- const base = readJsonSafe(path.join(projectRoot, '.agentrc.json'), fsImpl);
105
- const local = readJsonSafe(
106
- path.join(projectRoot, '.agentrc.local.json'),
107
- fsImpl,
108
- );
62
+ function resolveRoleScopedAgentsFlag(projectRoot) {
63
+ const base = readJsonSafe(path.join(projectRoot, '.agentrc.json'), fs);
64
+ const local = readJsonSafe(path.join(projectRoot, '.agentrc.local.json'), fs);
109
65
  const merged = {
110
66
  delivery: {
111
67
  routing: {
@@ -118,88 +74,57 @@ function resolveRoleScopedAgentsFlag(projectRoot, fsImpl) {
118
74
  }
119
75
 
120
76
  /**
121
- * Parity of `.claude/agents/*.md` against `.agents/agents/*.md` (root anchored
122
- * at `process.cwd()` as in `commands-in-sync`). A never-materialized tree is
123
- * fatal while `roleScopedAgents` is on — the acceptance critic would silently
124
- * fail to spawn and fall back to a weaker inline critic — and advisory when it
125
- * is off. Drift in a materialized tree always fails.
77
+ * Parity of `.claude/agents/` against what the agent projection would write
78
+ * now (root anchored at `process.cwd()` as in `commands-in-sync`),
79
+ * byte-for-byte. A never-materialized tree is fatal while `roleScopedAgents`
80
+ * is on — the acceptance critic would silently fail to spawn and fall back to
81
+ * a weaker inline critic — and advisory when it is off. Drift in a
82
+ * materialized tree always fails.
126
83
  *
127
84
  * @param {{
128
85
  * projectRoot?: string,
129
86
  * cwd?: () => string,
130
- * readDir?: (dir: string) => string[],
131
- * fsImpl?: typeof fs,
132
87
  * roleScopedAgents?: boolean,
133
88
  * }} [opts]
134
89
  * @returns {{ ok: boolean, detail: string, remedy?: string }}
135
90
  */
136
- export function runAgentsInSync({
137
- projectRoot,
138
- cwd,
139
- readDir,
140
- fsImpl = fs,
141
- roleScopedAgents,
142
- } = {}) {
143
- const getCwd = cwd ?? (() => process.cwd());
144
- const root = projectRoot ?? getCwd();
145
- const listDir =
146
- readDir ??
147
- ((dir) => {
148
- try {
149
- return fsImpl.readdirSync(dir).filter((f) => f.endsWith('.md'));
150
- } catch {
151
- return [];
152
- }
153
- });
154
-
155
- const srcDir = path.join(root, '.agents', 'agents');
156
- const destDir = path.join(root, '.claude', 'agents');
157
-
158
- const sources = listDir(srcDir)
159
- .filter((f) => !f.startsWith('.'))
160
- .sort();
161
- const dests = listDir(destDir)
162
- .filter((f) => !f.startsWith('.'))
163
- .sort();
164
-
165
- if (dests.length === 0) {
166
- if (sources.length === 0) {
167
- return { ok: true, detail: '0 agents up to date' };
91
+ export function runAgentsInSync({ projectRoot, cwd, roleScopedAgents } = {}) {
92
+ const root = projectRoot ?? (cwd ?? (() => process.cwd()))();
93
+ const destDir = path.join(root, ...CLAUDE_AGENTS_DIR.split('/'));
94
+ const onDisk = listGeneratedClaudeAgents(destDir);
95
+ const expected = () => expectedClaudeAgents({ projectRoot: root });
96
+
97
+ if (onDisk.length === 0) {
98
+ let size;
99
+ try {
100
+ size = expected().size;
101
+ } catch (err) {
102
+ return { ok: false, detail: err.message, remedy: AGENTS_REMEDY };
168
103
  }
104
+ if (size === 0) return { ok: true, detail: '0 agents up to date' };
169
105
  const resolvedFlag =
170
106
  typeof roleScopedAgents === 'boolean'
171
107
  ? roleScopedAgents
172
- : resolveRoleScopedAgentsFlag(root, fsImpl);
108
+ : resolveRoleScopedAgentsFlag(root);
173
109
  if (!resolvedFlag) {
174
110
  return {
175
111
  ok: true,
176
- detail: `${sources.length} agent def(s) not materialized (roleScopedAgents is disabled)`,
112
+ detail: `${size} agent def(s) not materialized (roleScopedAgents is disabled)`,
177
113
  };
178
114
  }
179
115
  return {
180
116
  ok: false,
181
- detail: `${sources.length} agent def(s) not yet materialized in .claude/agents/`,
182
- remedy:
183
- 'Run `mandrel sync-agents` to regenerate the `.claude/agents/` tree.',
117
+ detail: `${size} agent def(s) not yet materialized in .claude/agents/`,
118
+ remedy: AGENTS_REMEDY,
184
119
  };
185
120
  }
186
121
 
187
- const srcSet = new Set(sources);
188
- const dstSet = new Set(dests);
189
- const missing = sources.filter((f) => !dstSet.has(f));
190
- const extra = dests.filter((f) => !srcSet.has(f));
191
-
192
- if (missing.length === 0 && extra.length === 0) {
193
- return { ok: true, detail: `${sources.length} agents up to date` };
194
- }
195
-
196
- const parts = [];
197
- if (missing.length > 0) parts.push(`${missing.length} not synced`);
198
- if (extra.length > 0) parts.push(`${extra.length} stale`);
199
- return {
200
- ok: false,
201
- detail: parts.join(', '),
202
- remedy:
203
- 'Run `mandrel sync-agents` to regenerate the `.claude/agents/` tree.',
204
- };
122
+ return projectionParity({
123
+ expected,
124
+ onDisk,
125
+ readEntry: (name) => readTextOrNull(path.join(destDir, name)),
126
+ noun: 'agents',
127
+ where: `${CLAUDE_AGENTS_DIR}/`,
128
+ remedy: AGENTS_REMEDY,
129
+ });
205
130
  }
@@ -2,6 +2,9 @@
2
2
 
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
+ import { COMMANDS_DEFAULTS } from '../../../.agents/scripts/lib/config/commands.js';
6
+ import { COVERAGE_CAPTURE_DEFAULTS } from '../../../.agents/scripts/lib/config/gates/coverage.schema.js';
7
+ import { packageScriptArgv } from '../../../.agents/scripts/lib/detect-package-manager.js';
5
8
  import { readJsonSafe } from './read-json.js';
6
9
 
7
10
  // check: test-credit-path
@@ -10,7 +13,7 @@ import { readJsonSafe } from './read-json.js';
10
13
  const MANDREL_TEST_RUNNER = 'run-tests.js';
11
14
 
12
15
  /** The close `test` gate's command when `project.commands.test` is unset. */
13
- const DEFAULT_TEST_COMMAND = 'npm test';
16
+ const DEFAULT_TEST_COMMAND = COMMANDS_DEFAULTS.test;
14
17
 
15
18
  /**
16
19
  * The deposit command that works on any runner, wrapping `command`.
@@ -88,45 +91,80 @@ function scriptNamed(scripts, name) {
88
91
  }
89
92
 
90
93
  /**
91
- * `delivery.quality.gates.crap.enabled` from `.agentrc.json` overlaid by
92
- * `.agentrc.local.json`, defaulting on — the predicate close registers
93
- * `coverage-capture` on. Read without `resolveConfig()` (built-ins only).
94
+ * The last boolean/string a key path holds across `.agentrc.json` overlaid by
95
+ * `.agentrc.local.json`. Read without `resolveConfig()` (built-ins only).
94
96
  *
95
97
  * @param {string} projectRoot
96
98
  * @param {typeof fs.readFileSync} readFileImpl
97
- * @returns {boolean}
99
+ * @param {(config: object|undefined) => unknown} pick
100
+ * @param {(value: unknown) => boolean} accept
101
+ * @returns {unknown} `undefined` when neither file sets an accepted value.
98
102
  */
99
- function isCrapEnabled(projectRoot, readFileImpl) {
100
- let enabled = true;
103
+ function overlaidValue(projectRoot, readFileImpl, pick, accept) {
104
+ let value;
101
105
  for (const file of ['.agentrc.json', '.agentrc.local.json']) {
102
- const value = readJsonSafe(path.join(projectRoot, file), {
103
- readFileSync: readFileImpl,
104
- })?.delivery?.quality?.gates?.crap?.enabled;
105
- if (typeof value === 'boolean') enabled = value;
106
+ const candidate = pick(
107
+ readJsonSafe(path.join(projectRoot, file), {
108
+ readFileSync: readFileImpl,
109
+ }),
110
+ );
111
+ if (accept(candidate)) value = candidate;
106
112
  }
107
- return enabled;
113
+ return value;
114
+ }
115
+
116
+ const isBoolean = (v) => typeof v === 'boolean';
117
+ const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;
118
+
119
+ /**
120
+ * The coverage-capture registration inputs close reads: whether the coverage
121
+ * or CRAP gate is on (each defaults on) and the coverage gate's
122
+ * `captureScript`.
123
+ *
124
+ * @param {string} projectRoot
125
+ * @param {typeof fs.readFileSync} readFileImpl
126
+ * @returns {{ captureEnabled: boolean, captureScript: string }}
127
+ */
128
+ function readCaptureConfig(projectRoot, readFileImpl) {
129
+ const gate = (name) => (c) => c?.delivery?.quality?.gates?.[name];
130
+ const enabled = (name) =>
131
+ overlaidValue(
132
+ projectRoot,
133
+ readFileImpl,
134
+ (c) => gate(name)(c)?.enabled,
135
+ isBoolean,
136
+ ) !== false;
137
+ const script = overlaidValue(
138
+ projectRoot,
139
+ readFileImpl,
140
+ (c) => gate('coverage')(c)?.captureScript,
141
+ isNonEmptyString,
142
+ );
143
+ return {
144
+ captureEnabled: enabled('coverage') || enabled('crap'),
145
+ captureScript: script?.trim() ?? COVERAGE_CAPTURE_DEFAULTS.captureScript,
146
+ };
108
147
  }
109
148
 
110
149
  /**
111
150
  * `project.commands.test` from `.agentrc.json` overlaid by
112
151
  * `.agentrc.local.json` — the command close's `test` gate spawns. Read without
113
- * `resolveConfig()` (built-ins only), like {@link isCrapEnabled}.
152
+ * `resolveConfig()` (built-ins only), like {@link readCaptureConfig}.
114
153
  *
115
154
  * @param {string} projectRoot
116
155
  * @param {typeof fs.readFileSync} readFileImpl
117
156
  * @returns {string|null} The configured command, or null when unset/default.
118
157
  */
119
158
  function configuredTestCommand(projectRoot, readFileImpl) {
120
- let command = null;
121
- for (const file of ['.agentrc.json', '.agentrc.local.json']) {
122
- const value = readJsonSafe(path.join(projectRoot, file), {
123
- readFileSync: readFileImpl,
124
- })?.project?.commands?.test;
125
- if (typeof value === 'string' && value.trim().length > 0) {
126
- command = value.trim();
127
- }
128
- }
129
- return command === DEFAULT_TEST_COMMAND ? null : command;
159
+ const command = overlaidValue(
160
+ projectRoot,
161
+ readFileImpl,
162
+ (c) => c?.project?.commands?.test,
163
+ isNonEmptyString,
164
+ )?.trim();
165
+ return command === undefined || command === DEFAULT_TEST_COMMAND
166
+ ? null
167
+ : command;
130
168
  }
131
169
 
132
170
  /**
@@ -153,13 +191,15 @@ function describeConfiguredTestCommand(command) {
153
191
  /**
154
192
  * Which depositor digest § 5 selects, stated with its exact command.
155
193
  *
156
- * @param {{ scripts: Record<string, string>, crapEnabled: boolean, testCommand: string|null }} probe
194
+ * @param {{ root: string, scripts: Record<string, string>, capture: { captureEnabled: boolean, captureScript: string }, testCommand: string|null }} probe
157
195
  * @returns {{ detail: string, remedy?: string }}
158
196
  */
159
- function describeCreditedRun({ scripts, crapEnabled, testCommand }) {
160
- if (crapEnabled && scriptNamed(scripts, 'test:coverage') !== null) {
197
+ function describeCreditedRun({ root, scripts, capture, testCommand }) {
198
+ const { captureEnabled, captureScript } = capture;
199
+ if (captureEnabled && scriptNamed(scripts, captureScript) !== null) {
200
+ const spawn = packageScriptArgv(root, captureScript).join(' ');
161
201
  return {
162
- detail: `the CRAP gate is enabled and \`test:coverage\` exists, so close registers \`coverage-capture\` and the credited run is the coverage capture: \`${COVERAGE_CAPTURE_COMMAND}\` — its fresh stamp lets close's capture skip the suite`,
202
+ detail: `the coverage or CRAP gate is enabled and the \`${captureScript}\` capture script exists, so close registers \`coverage-capture\` (spawning \`${spawn}\`) and the credited run is the coverage capture: \`${COVERAGE_CAPTURE_COMMAND}\` — its fresh stamp lets close's capture skip the suite`,
163
203
  };
164
204
  }
165
205
  return testCommand !== null
@@ -255,8 +295,9 @@ export function runTestCreditPath({
255
295
  detail: `the worker's \`${STORY_HANDOFF_COMMAND}\` runs the credited run close reads`,
256
296
  },
257
297
  describeCreditedRun({
298
+ root,
258
299
  scripts: readProjectScripts(root, readFile),
259
- crapEnabled: isCrapEnabled(root, readFile),
300
+ capture: readCaptureConfig(root, readFile),
260
301
  testCommand: configuredTestCommand(root, readFile),
261
302
  }),
262
303
  describePrePushHook(root, readFile),
@@ -1,10 +1,12 @@
1
1
  // lib/cli/doctor-checks/toolchain.js — Doctor checks: node-version, git-available, gh-available, github-token, gh-auth.
2
+ // Every `gh` probe goes through `runGh`, so it runs with the configured `GH_CONFIG_DIR`.
2
3
 
3
4
  import {
4
5
  REQUIRED_NODE_CEILING_MAJOR,
5
6
  REQUIRED_NODE_FLOOR,
6
7
  satisfiesNodeEngine,
7
8
  } from '../../../.agents/scripts/lib/bootstrap/project-bootstrap.js';
9
+ import { runGh } from '../../../.agents/scripts/lib/gh-exec.js';
8
10
  import { spawn } from './spawn.js';
9
11
 
10
12
  // check: node-version
@@ -50,7 +52,7 @@ export function runGitAvailable({ runner = spawn } = {}) {
50
52
  * @returns {{ ok: boolean, detail: string, remedy?: string }}
51
53
  */
52
54
  export function runGhAvailable({ runner = spawn } = {}) {
53
- const r = runner('gh', ['--version']);
55
+ const r = runGh(['--version'], {}, runner);
54
56
  if (r.error?.code === 'ENOENT' || r.status !== 0) {
55
57
  const snippet = (r.stderr || r.stdout || '').trim().slice(0, 120);
56
58
  return {
@@ -80,7 +82,7 @@ export function runGithubToken({ env = process.env, runner = spawn } = {}) {
80
82
  if (envToken && envToken.length > 0) {
81
83
  return { ok: true, detail: 'GITHUB_TOKEN set' };
82
84
  }
83
- const r = runner('gh', ['auth', 'token']);
85
+ const r = runGh(['auth', 'token'], {}, runner);
84
86
  const ghToken = !r.error && r.status === 0 ? (r.stdout || '').trim() : '';
85
87
  if (ghToken.length > 0) {
86
88
  return { ok: true, detail: 'token resolved via `gh auth token`' };
@@ -106,7 +108,7 @@ export function runGithubToken({ env = process.env, runner = spawn } = {}) {
106
108
  * @returns {{ ok: boolean, detail: string, remedy?: string }}
107
109
  */
108
110
  export function runGhAuth({ runner = spawn, env = process.env } = {}) {
109
- const r = runner('gh', ['auth', 'status']);
111
+ const r = runGh(['auth', 'status'], {}, runner);
110
112
  if (r.error?.code === 'ENOENT') {
111
113
  return {
112
114
  ok: false,
@@ -17,6 +17,7 @@ import {
17
17
  runCodexInstructions,
18
18
  runCodexSkillsInSync,
19
19
  } from './doctor-checks/codex.js';
20
+ import { runLlmReviewProvider } from './doctor-checks/llm-review.js';
20
21
  import { runMergeDriver } from './doctor-checks/merge-driver.js';
21
22
  import { runAgentsDrift, runPinCurrent } from './doctor-checks/payload.js';
22
23
  import { runProjectAccess } from './doctor-checks/project-access.js';
@@ -118,6 +119,10 @@ export const registry = [
118
119
  ...opts,
119
120
  }),
120
121
  },
122
+ {
123
+ name: 'llm-review-provider',
124
+ run: (opts) => runLlmReviewProvider(opts),
125
+ },
121
126
  {
122
127
  name: 'merge-driver',
123
128
  run: (opts) => runMergeDriver(opts),
@@ -15,7 +15,7 @@ export const AGENTRC_BASE_FILENAME = '.agentrc.json';
15
15
 
16
16
  const AGENTRC_LOCAL_FILENAME = '.agentrc.local.json';
17
17
 
18
- const AGENTRC_FILENAMES = Object.freeze([
18
+ export const AGENTRC_FILENAMES = Object.freeze([
19
19
  AGENTRC_BASE_FILENAME,
20
20
  AGENTRC_LOCAL_FILENAME,
21
21
  ]);
@@ -25,7 +25,7 @@ const AGENTRC_FILENAMES = Object.freeze([
25
25
  * @param {string} filename
26
26
  * @returns {string}
27
27
  */
28
- function resolveAgentrcPath(ctx, filename) {
28
+ export function resolveAgentrcPath(ctx, filename) {
29
29
  const projectRoot = ctx?.projectRoot ?? process.cwd();
30
30
  return path.join(projectRoot, filename);
31
31
  }
@@ -38,7 +38,7 @@ function resolveAgentrcPath(ctx, filename) {
38
38
  * @param {typeof nodeFs} fsImpl
39
39
  * @returns {object | null}
40
40
  */
41
- function readAgentrcConfig(ctx, filename, fsImpl) {
41
+ export function readAgentrcConfig(ctx, filename, fsImpl) {
42
42
  try {
43
43
  const raw = fsImpl.readFileSync(resolveAgentrcPath(ctx, filename), 'utf8');
44
44
  return JSON.parse(raw);
@@ -20,6 +20,9 @@ import { foldClaudeMdIntoAgentsMdStep } from './steps/2.65.0-fold-claude-md-into
20
20
  import { retireAuditLedger } from './steps/2.70.0-retire-audit-ledger.js';
21
21
  import { containerSafeProjections } from './steps/2.79.0-container-safe-projections.js';
22
22
  import { hoistSystemPromptBlockStep } from './steps/2.84.0-hoist-system-prompt-block.js';
23
+ import { moveSharedCrapCaptureScript } from './steps/2.91.0-move-shared-crap-capture-script.js';
24
+ import { retireDuplicationFormats } from './steps/2.91.0-retire-duplication-formats.js';
25
+ import { unsetNullLintCommand } from './steps/2.91.0-unset-null-lint-command.js';
23
26
  import { stripRemovedAgentrcKeys } from './steps/strip-removed-agentrc-keys.js';
24
27
 
25
28
  /**
@@ -48,6 +51,9 @@ export const migrations = [
48
51
  retireAuditLedger,
49
52
  containerSafeProjections,
50
53
  hoistSystemPromptBlockStep,
54
+ moveSharedCrapCaptureScript,
55
+ unsetNullLintCommand,
56
+ retireDuplicationFormats,
51
57
  ];
52
58
 
53
59
  export { compareVersions };
@@ -0,0 +1,84 @@
1
+ // lib/migrations/steps/2.91.0-move-shared-crap-capture-script.js
2
+ /**
3
+ * Move a `delivery.quality.gates.crap.captureScript` that has no own CRAP
4
+ * artifact to `delivery.quality.gates.coverage.captureScript`. A shared
5
+ * artifact has one writer — the coverage gate — so the resolver now refuses
6
+ * the CRAP key without an own `crap.coveragePath`. An explicit coverage
7
+ * `captureScript` wins; the CRAP key is dropped either way. Each config
8
+ * surface is rewritten on its own. Builtins only.
9
+ */
10
+
11
+ import nodeFs from 'node:fs';
12
+ import { COVERAGE_CAPTURE_DEFAULTS } from '../../../.agents/scripts/lib/config/gates/coverage.schema.js';
13
+ import {
14
+ AGENTRC_FILENAMES,
15
+ resolveAgentrcPath as agentrcPath,
16
+ readAgentrcConfig as readConfig,
17
+ } from '../helpers/retire-agentrc-key.js';
18
+
19
+ /** @param {object|null} config */
20
+ function gatesOf(config) {
21
+ const gates = config?.delivery?.quality?.gates;
22
+ return gates && typeof gates === 'object' ? gates : null;
23
+ }
24
+
25
+ /** @param {unknown} value */
26
+ function slashed(value) {
27
+ return typeof value === 'string' ? value.trim().replace(/\\/g, '/') : '';
28
+ }
29
+
30
+ /**
31
+ * The CRAP gate's `captureScript` with no own artifact, or `null`.
32
+ *
33
+ * @param {object|null} config
34
+ * @returns {string|null}
35
+ */
36
+ function sharedCrapScript(config) {
37
+ const gates = gatesOf(config);
38
+ const script = gates?.crap?.captureScript;
39
+ if (typeof script !== 'string') return null;
40
+ const own = slashed(gates.crap.coveragePath);
41
+ const shared =
42
+ slashed(gates.coverage?.coveragePath) ||
43
+ COVERAGE_CAPTURE_DEFAULTS.coveragePath;
44
+ return own === '' || own === shared ? script : null;
45
+ }
46
+
47
+ /** @param {object} config @param {string} script */
48
+ function moveScript(config, script) {
49
+ const gates = gatesOf(config);
50
+ delete gates.crap.captureScript;
51
+ gates.coverage = gates.coverage ?? {};
52
+ if (gates.coverage.captureScript === undefined) {
53
+ gates.coverage.captureScript = script;
54
+ }
55
+ }
56
+
57
+ export const moveSharedCrapCaptureScript = {
58
+ version: '2.91.0',
59
+ description:
60
+ 'move a crap.captureScript with no own crap.coveragePath to ' +
61
+ 'coverage.captureScript — the coverage gate now owns its capture script ' +
62
+ '(Story #5737)',
63
+ /** @param {{ projectRoot?: string, fs?: typeof nodeFs }} [ctx] */
64
+ detect(ctx) {
65
+ const fsImpl = ctx?.fs ?? nodeFs;
66
+ return AGENTRC_FILENAMES.some(
67
+ (name) => sharedCrapScript(readConfig(ctx, name, fsImpl)) !== null,
68
+ );
69
+ },
70
+ /** @param {{ projectRoot?: string, fs?: typeof nodeFs }} [ctx] */
71
+ apply(ctx) {
72
+ const fsImpl = ctx?.fs ?? nodeFs;
73
+ for (const name of AGENTRC_FILENAMES) {
74
+ const config = readConfig(ctx, name, fsImpl);
75
+ const script = sharedCrapScript(config);
76
+ if (script === null) continue;
77
+ moveScript(config, script);
78
+ fsImpl.writeFileSync(
79
+ agentrcPath(ctx, name),
80
+ `${JSON.stringify(config, null, 2)}\n`,
81
+ );
82
+ }
83
+ },
84
+ };
@@ -0,0 +1,23 @@
1
+ // lib/migrations/steps/2.91.0-retire-duplication-formats.js
2
+ /**
3
+ * Strip `delivery.quality.gates.duplication.formats`: the jscpd formats are
4
+ * now derived from the scorable-extension list every other gate scores, and
5
+ * the gate block is `additionalProperties: false`. An emptied `duplication`
6
+ * block is pruned; its parents keep their other gates.
7
+ */
8
+
9
+ import { createRetireAgentrcKeyStep } from '../helpers/retire-agentrc-key.js';
10
+
11
+ export const retireDuplicationFormats = createRetireAgentrcKeyStep({
12
+ version: '2.91.0',
13
+ description:
14
+ 'strip retired delivery.quality.gates.duplication.formats from ' +
15
+ '.agentrc.json and .agentrc.local.json (the jscpd formats now derive ' +
16
+ 'from the scorable-extension list — Story #5738)',
17
+ keys: [
18
+ {
19
+ path: ['delivery', 'quality', 'gates', 'duplication', 'formats'],
20
+ pruneDepth: 1,
21
+ },
22
+ ],
23
+ });