mandrel 2.94.0 → 2.95.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 (110) hide show
  1. package/.agents/runtime-deps.json +6 -6
  2. package/.agents/scripts/agents-bootstrap-github.js +1 -1
  3. package/.agents/scripts/board-backfill.js +1 -1
  4. package/.agents/scripts/boot-sweep.js +1 -1
  5. package/.agents/scripts/check-arch-cycles.js +69 -41
  6. package/.agents/scripts/check-doc-links.js +5 -7
  7. package/.agents/scripts/check-gherkin-corpus.js +2 -11
  8. package/.agents/scripts/clean-temp.js +1 -1
  9. package/.agents/scripts/cleanup-repo-test-temp.js +1 -1
  10. package/.agents/scripts/diagnose-friction.js +1 -1
  11. package/.agents/scripts/generate-lens-checklists.js +4 -4
  12. package/.agents/scripts/generate-skills-index.js +3 -2
  13. package/.agents/scripts/generate-workflows-doc.js +2 -1
  14. package/.agents/scripts/lib/audit-baselines/read.js +2 -1
  15. package/.agents/scripts/lib/audit-exceptions/adapters/tool-config.js +13 -3
  16. package/.agents/scripts/lib/audit-exceptions/globs.js +12 -1
  17. package/.agents/scripts/lib/audit-exceptions/probe.js +24 -2
  18. package/.agents/scripts/lib/audit-exceptions/read.js +2 -2
  19. package/.agents/scripts/lib/audit-to-stories/group-findings.js +77 -67
  20. package/.agents/scripts/lib/baselines/components.js +21 -19
  21. package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -8
  22. package/.agents/scripts/lib/baselines/kinds/maintainability.js +2 -3
  23. package/.agents/scripts/lib/baselines/preview-gates.js +2 -2
  24. package/.agents/scripts/lib/baselines/refresh-service.js +4 -7
  25. package/.agents/scripts/lib/baselines/writer.js +2 -7
  26. package/.agents/scripts/lib/bdd-runner-detect.js +2 -2
  27. package/.agents/scripts/lib/bdd-step-index.js +3 -7
  28. package/.agents/scripts/lib/bootstrap/baseline-merge-driver.js +11 -7
  29. package/.agents/scripts/lib/bootstrap/install-ledger.js +19 -4
  30. package/.agents/scripts/lib/bootstrap/json-io.js +14 -0
  31. package/.agents/scripts/lib/bootstrap/project-bootstrap.js +20 -44
  32. package/.agents/scripts/lib/bootstrap/quality-bootstrap.js +38 -54
  33. package/.agents/scripts/lib/branch-name-guard.js +2 -3
  34. package/.agents/scripts/lib/claude/agents-projection.js +1 -12
  35. package/.agents/scripts/lib/codex/agents-projection.js +2 -5
  36. package/.agents/scripts/lib/codex/skills-projection.js +4 -12
  37. package/.agents/scripts/lib/config/defaults.js +2 -1
  38. package/.agents/scripts/lib/config/qa.js +4 -5
  39. package/.agents/scripts/lib/config-schema.js +1 -8
  40. package/.agents/scripts/lib/config-settings-schema.js +0 -3
  41. package/.agents/scripts/lib/coverage-baseline.js +2 -3
  42. package/.agents/scripts/lib/coverage-utils.js +2 -1
  43. package/.agents/scripts/lib/cpu-pool.js +0 -1
  44. package/.agents/scripts/lib/cyclomatic-scope.js +2 -1
  45. package/.agents/scripts/lib/doc-tiers.js +2 -1
  46. package/.agents/scripts/lib/gh-exec.js +21 -1
  47. package/.agents/scripts/lib/git/sync-from-base.js +1 -1
  48. package/.agents/scripts/lib/import-graph.js +13 -28
  49. package/.agents/scripts/lib/json-utils.js +11 -0
  50. package/.agents/scripts/lib/label-constants.js +7 -1
  51. package/.agents/scripts/lib/maintainability-utils.js +14 -22
  52. package/.agents/scripts/lib/observability/runtime-friction.js +37 -1
  53. package/.agents/scripts/lib/orchestration/check-baselines/phases/parse-args.js +25 -1
  54. package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +9 -12
  55. package/.agents/scripts/lib/orchestration/code-review.js +1 -6
  56. package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
  57. package/.agents/scripts/lib/orchestration/git-cleanup/phases/fast-forward.js +7 -14
  58. package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes-ff.js +2 -21
  59. package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +11 -20
  60. package/.agents/scripts/lib/orchestration/git-cleanup/phases/phase-drivers.js +65 -86
  61. package/.agents/scripts/lib/orchestration/git-cleanup/phases/prompts.js +2 -2
  62. package/.agents/scripts/lib/orchestration/git-cleanup/phases/stashes.js +15 -6
  63. package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-unlanded.js +5 -2
  64. package/.agents/scripts/lib/orchestration/merge-block-class.js +47 -48
  65. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +20 -1
  66. package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +2 -3
  67. package/.agents/scripts/lib/orchestration/review-providers/parse-findings.js +4 -2
  68. package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -2
  69. package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +3 -3
  70. package/.agents/scripts/lib/orchestration/story-handoff.js +18 -5
  71. package/.agents/scripts/lib/orchestration/ticketing/transition.js +17 -21
  72. package/.agents/scripts/lib/runtime-deps/dep-resolution.js +19 -5
  73. package/.agents/scripts/lib/runtime-deps/scan-imports.js +4 -10
  74. package/.agents/scripts/lib/skills/parse-skill.js +2 -2
  75. package/.agents/scripts/lib/skills/walk-skill-files.js +7 -23
  76. package/.agents/scripts/lib/story-body/story-body.js +4 -14
  77. package/.agents/scripts/lib/util/atomic-write.js +14 -3
  78. package/.agents/scripts/lib/util/regex.js +4 -0
  79. package/.agents/scripts/notify.js +1 -1
  80. package/.agents/scripts/plan-context.js +1 -1
  81. package/.agents/scripts/plan-critics.js +3 -11
  82. package/.agents/scripts/providers/github/auth.js +0 -4
  83. package/.agents/scripts/providers/github/project-board.js +0 -1
  84. package/.agents/scripts/providers/github/tickets.js +0 -2
  85. package/.agents/scripts/resync-status-column.js +1 -1
  86. package/.agents/scripts/run-tests.js +1 -1
  87. package/.agents/scripts/test-wrapper.js +1 -1
  88. package/.agents/scripts/update-ticket-state.js +4 -3
  89. package/.agents/scripts/validate-skills.js +2 -1
  90. package/.agents/skills/core/gates-and-baselines/reference.md +1 -0
  91. package/.agents/workflows/audit-baselines.md +21 -9
  92. package/.agents/workflows/clean-git.md +1 -1
  93. package/.agents/workflows/helpers/audit-lens-core.md +1 -1
  94. package/.agents/workflows/helpers/code-quality-guardrails.md +3 -3
  95. package/README.md +1 -1
  96. package/docs/CHANGELOG.md +34 -0
  97. package/lib/cli/claude-code-version.js +13 -7
  98. package/lib/cli/doctor-checks/llm-review.js +12 -5
  99. package/lib/cli/doctor-checks/merge-driver.js +10 -6
  100. package/lib/cli/doctor-checks/project-access.js +21 -8
  101. package/lib/cli/doctor-checks/read-json.js +2 -15
  102. package/lib/cli/doctor-checks/spawn.js +29 -9
  103. package/lib/cli/doctor-checks/test-credit-path.js +2 -1
  104. package/lib/cli/doctor-checks/toolchain.js +16 -12
  105. package/lib/cli/doctor.js +31 -8
  106. package/lib/cli/registry.js +7 -10
  107. package/lib/cli/sync.js +46 -10
  108. package/lib/cli/uninstall.js +259 -175
  109. package/lib/cli/update.js +3 -3
  110. package/package.json +23 -20
@@ -8,6 +8,7 @@
8
8
 
9
9
  import fs from 'node:fs';
10
10
  import path from 'node:path';
11
+ import { toPosix, walkFiles } from './util/paths.js';
11
12
 
12
13
  /**
13
14
  * The npm-published roots, resolved into one graph so cross-root cycles show.
@@ -21,26 +22,11 @@ export const DEFAULT_ROOTS = [path.join('.agents', 'scripts'), 'bin', 'lib'];
21
22
  * @returns {string[]} absolute paths, sorted
22
23
  */
23
24
  export function collectJsFiles(rootDir) {
24
- const out = [];
25
- const walk = (dir) => {
26
- let entries;
27
- try {
28
- entries = fs.readdirSync(dir, { withFileTypes: true });
29
- } catch {
30
- return;
31
- }
32
- for (const entry of entries) {
33
- if (entry.name === 'node_modules') continue;
34
- const full = path.join(dir, entry.name);
35
- if (entry.isDirectory()) {
36
- walk(full);
37
- } else if (entry.isFile() && entry.name.endsWith('.js')) {
38
- out.push(full);
39
- }
40
- }
41
- };
42
- walk(rootDir);
43
- return out.sort();
25
+ return walkFiles(rootDir, {
26
+ skipDirs: ['node_modules'],
27
+ filter: (abs, dirent) => dirent.isFile() && abs.endsWith('.js'),
28
+ onError: () => {},
29
+ }).sort();
44
30
  }
45
31
 
46
32
  const IMPORT_RE = /from\s+['"](\.\.?\/[^'"]+\.js)['"]/g;
@@ -67,11 +53,11 @@ export function parseRelativeImports(source) {
67
53
  */
68
54
  export function buildGraph(files, rootDir, { readFile } = {}) {
69
55
  const read = readFile ?? ((p) => fs.readFileSync(p, 'utf-8'));
70
- const toId = (abs) => path.relative(rootDir, abs).split(path.sep).join('/');
71
- const idSet = new Set(files.map(toId));
56
+ const ids = files.map((file) => toPosix(path.relative(rootDir, file)));
57
+ const idSet = new Set(ids);
72
58
  const graph = new Map();
73
- for (const file of files) {
74
- const id = toId(file);
59
+ for (const [i, file] of files.entries()) {
60
+ const id = ids[i];
75
61
  let source;
76
62
  try {
77
63
  source = read(file);
@@ -81,10 +67,9 @@ export function buildGraph(files, rootDir, { readFile } = {}) {
81
67
  }
82
68
  const edges = [];
83
69
  for (const spec of parseRelativeImports(source)) {
84
- const target = path
85
- .relative(rootDir, path.resolve(path.dirname(file), spec))
86
- .split(path.sep)
87
- .join('/');
70
+ const target = toPosix(
71
+ path.relative(rootDir, path.resolve(path.dirname(file), spec)),
72
+ );
88
73
  if (idSet.has(target) && target !== id) edges.push(target);
89
74
  }
90
75
  graph.set(id, [...new Set(edges)].sort());
@@ -3,6 +3,8 @@
3
3
  * Sets, RegExps or class instances).
4
4
  */
5
5
 
6
+ import fs from 'node:fs';
7
+
6
8
  /**
7
9
  * @param {unknown} v
8
10
  * @returns {boolean}
@@ -42,3 +44,12 @@ export function deepEqual(a, b) {
42
44
  }
43
45
  return true;
44
46
  }
47
+
48
+ /** Missing or unparsable → `null`; never throws. */
49
+ export function readJsonOrNull(file, fsImpl = fs) {
50
+ try {
51
+ return JSON.parse(fsImpl.readFileSync(file, 'utf8'));
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
@@ -17,7 +17,13 @@ export const AGENT_LABELS = {
17
17
  export const VALID_TRANSITIONS = {
18
18
  'agent::review-spec': ['agent::ready', 'agent::blocked'],
19
19
  'agent::ready': ['agent::executing', 'agent::blocked'],
20
- 'agent::executing': ['agent::closing', 'agent::done', 'agent::blocked'],
20
+ // `ready`: init's claim rollback after a provisioning failure.
21
+ 'agent::executing': [
22
+ 'agent::ready',
23
+ 'agent::closing',
24
+ 'agent::done',
25
+ 'agent::blocked',
26
+ ],
21
27
  'agent::closing': ['agent::done', 'agent::blocked'],
22
28
  'agent::blocked': [
23
29
  'agent::ready',
@@ -1,4 +1,3 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
3
2
  import picomatch from 'picomatch';
4
3
  import { canonicalise as canonicalisePath } from './baselines/path-canon.js';
@@ -8,6 +7,7 @@ import { scoreFile } from './maintainability-engine.js';
8
7
  import { isScored, reportUnscorable } from './maintainability-unscorable.js';
9
8
  import { isScorableSourceFile } from './source-extensions.js';
10
9
  import { CompilerMissingError } from './transpile.js';
10
+ import { walkFiles } from './util/paths.js';
11
11
 
12
12
  const MAINTAINABILITY_WORKER_URL = new URL(
13
13
  './workers/maintainability-worker.js',
@@ -110,6 +110,10 @@ export function isIgnoredByGlobs(filePath, ignoreGlobs = [], cwd) {
110
110
  );
111
111
  }
112
112
 
113
+ function skipVanishedDir(err) {
114
+ if (err?.code !== 'ENOENT') throw err;
115
+ }
116
+
113
117
  /**
114
118
  * Recursively collect scorable source files, using the shared extension set
115
119
  * so the walk, coverage freshness and CRAP projection cannot drift apart.
@@ -122,27 +126,15 @@ export function isIgnoredByGlobs(filePath, ignoreGlobs = [], cwd) {
122
126
  export function scanDirectory(dir, fileList = [], opts = {}) {
123
127
  const { ignoreGlobs = [], cwd: optsCwd } = opts;
124
128
  const matchCwd = optsCwd ?? process.cwd();
125
- let entries;
126
- try {
127
- entries = fs.readdirSync(dir, { withFileTypes: true });
128
- } catch (err) {
129
- if (err.code === 'ENOENT') return fileList;
130
- throw err;
131
- }
132
-
133
- for (const entry of entries) {
134
- const filePath = path.join(dir, entry.name);
135
- if (entry.isDirectory()) {
136
- if (!IGNORED_DIRS.has(entry.name)) {
137
- scanDirectory(filePath, fileList, opts);
138
- }
139
- } else if (entry.isFile() && isScorableSourceFile(entry.name)) {
140
- if (isIgnoredByGlobs(filePath, ignoreGlobs, matchCwd)) {
141
- continue;
142
- }
143
- fileList.push(filePath);
144
- }
145
- }
129
+ const found = walkFiles(dir, {
130
+ skipDirs: IGNORED_DIRS,
131
+ filter: (abs, dirent) =>
132
+ dirent.isFile() &&
133
+ isScorableSourceFile(dirent.name) &&
134
+ !isIgnoredByGlobs(abs, ignoreGlobs, matchCwd),
135
+ onError: skipVanishedDir,
136
+ });
137
+ for (const file of found) fileList.push(file);
146
138
  return fileList;
147
139
  }
148
140
 
@@ -8,8 +8,8 @@
8
8
  */
9
9
 
10
10
  import crypto from 'node:crypto';
11
-
12
11
  import { Logger } from '../Logger.js';
12
+ import { isValidTransition, VALID_TRANSITIONS } from '../label-constants.js';
13
13
  import { appendSignal, forEachLine } from './signals-writer.js';
14
14
 
15
15
  /**
@@ -27,6 +27,8 @@ export const RUNTIME_FRICTION_CATEGORIES = Object.freeze({
27
27
  REVIEW_BLOCKED: 'review-blocked',
28
28
  /** A human shipped over a review blocker; a rising count means miscalibration. */
29
29
  REVIEW_BLOCK_OVERRIDDEN: 'review-block-overridden',
30
+ /** An `agent::*` flip outside `VALID_TRANSITIONS`; observed, never refused. */
31
+ INVALID_AGENT_TRANSITION: 'invalid-agent-transition',
30
32
  });
31
33
 
32
34
  /**
@@ -153,6 +155,40 @@ export async function emitBlockRecoveredFriction({
153
155
  });
154
156
  }
155
157
 
158
+ /**
159
+ * Record an `agent::*` flip outside `VALID_TRANSITIONS` — observe-only, the
160
+ * label write already happened, and this never throws. A self-transition is
161
+ * an idempotent re-apply (resume, `--steal`, a rollback whose flip never
162
+ * landed), not a fault. `allowed` names the targets the table admits.
163
+ *
164
+ * @param {number} storyId
165
+ * @param {string|null} fromState Prior state label, or null.
166
+ * @param {string} toState
167
+ * @param {{ config?: object }} [opts]
168
+ * @returns {Promise<boolean>} true when a record was appended.
169
+ */
170
+ export async function emitInvalidTransitionFriction(
171
+ storyId,
172
+ fromState,
173
+ toState,
174
+ opts,
175
+ ) {
176
+ if (fromState === toState || isValidTransition(fromState, toState)) {
177
+ return false;
178
+ }
179
+ return emitRuntimeFriction({
180
+ storyId,
181
+ category: RUNTIME_FRICTION_CATEGORIES.INVALID_AGENT_TRANSITION,
182
+ tool: 'transitionTicketState',
183
+ details: {
184
+ fromState,
185
+ toState,
186
+ allowed: VALID_TRANSITIONS[fromState] ?? [],
187
+ },
188
+ config: opts?.config,
189
+ });
190
+ }
191
+
156
192
  /**
157
193
  * On land, emit a `recovered: true` marker in `category` so the retro nets
158
194
  * the `(category, storyId)` incident out. Hung off `runPostLandTail` because
@@ -82,6 +82,28 @@ function flattenGateTokens(raw) {
82
82
  return parts.length === 0 ? null : parts;
83
83
  }
84
84
 
85
+ /** Out-of-band ratchet kinds this dispatcher never evaluates, and their checkers. */
86
+ const RATCHET_CHECKERS = Object.freeze({
87
+ 'arch-cycles': 'check-arch-cycles.js',
88
+ 'context-budget': 'check-context-budget.js',
89
+ cyclomatic: 'check-cyclomatic.js',
90
+ 'dead-exports': 'check-dead-exports.js',
91
+ 'dead-exports-production': 'check-dead-exports.js --production',
92
+ });
93
+
94
+ /** Reject a mistyped kind rather than silently evaluating nothing. */
95
+ function assertKnownKinds(gates) {
96
+ const unknown = (gates ?? []).filter((k) => !KNOWN_KINDS.includes(k));
97
+ if (unknown.length === 0) return;
98
+ const checkers = Object.entries(RATCHET_CHECKERS)
99
+ .map(([kind, cmd]) => `${kind} (node .agents/scripts/${cmd})`)
100
+ .join(', ');
101
+ throw new Error(
102
+ `unknown --gate kind "${unknown.join(', ')}"; valid kinds: ${KNOWN_KINDS.join(', ')}. ` +
103
+ `Ratchet kinds run via their own checker: ${checkers}.`,
104
+ );
105
+ }
106
+
85
107
  /**
86
108
  * @param {string[]} argv process.argv.slice(2)
87
109
  * @returns {{
@@ -125,9 +147,11 @@ export function parseArgs(argv) {
125
147
  }
126
148
 
127
149
  const { values } = parsed;
150
+ const gates = flattenGateTokens(values.gate);
151
+ assertKnownKinds(gates);
128
152
  const out = {
129
153
  configPath: values.configPath ?? null,
130
- gates: flattenGateTokens(values.gate),
154
+ gates,
131
155
  format: values.format ?? 'json',
132
156
  friction: !values.noFriction,
133
157
  storyId: values.storyId,
@@ -13,18 +13,13 @@
13
13
  * dies with the digest). A missing SHA on either side fails closed.
14
14
  */
15
15
 
16
- import {
17
- existsSync,
18
- mkdirSync,
19
- readFileSync,
20
- rmSync,
21
- writeFileSync,
22
- } from 'node:fs';
16
+ import { existsSync, readFileSync, rmSync } from 'node:fs';
23
17
  import path from 'node:path';
24
18
  import { resolveConfig } from '../config-resolver.js';
25
19
  import { prSurfaceUsesRest, runGh } from '../gh-exec.js';
26
20
  import { Logger } from '../Logger.js';
27
21
  import { createProvider } from '../provider-factory.js';
22
+ import { writeFileAtomic } from '../util/atomic-write.js';
28
23
  import { isRerunPermitted } from './check-state.js';
29
24
  import {
30
25
  STATE_LABELS,
@@ -213,7 +208,10 @@ export function readCiDigest({ storyId = null, tempRoot, cwd }) {
213
208
  try {
214
209
  const parsed = JSON.parse(readFileSync(paths.jsonPath, 'utf8'));
215
210
  return parsed && typeof parsed === 'object' ? parsed : null;
216
- } catch {
211
+ } catch (err) {
212
+ Logger.warn(
213
+ `ignoring unreadable CI digest ${paths.jsonPath} (${err.message}) — treated as absent`,
214
+ );
217
215
  return null;
218
216
  }
219
217
  }
@@ -351,9 +349,8 @@ export function writeCiDigest({
351
349
  logTail,
352
350
  generatedAt: new Date().toISOString(),
353
351
  };
354
- mkdirSync(path.dirname(paths.jsonPath), { recursive: true });
355
- writeFileSync(paths.jsonPath, `${JSON.stringify(digest, null, 2)}\n`);
356
- writeFileSync(paths.mdPath, renderDigestMarkdown(digest, failures));
352
+ writeFileAtomic(paths.jsonPath, `${JSON.stringify(digest, null, 2)}\n`);
353
+ writeFileAtomic(paths.mdPath, renderDigestMarkdown(digest, failures));
357
354
  return { jsonPath: paths.jsonPath, mdPath: paths.mdPath };
358
355
  }
359
356
 
@@ -388,7 +385,7 @@ export function recordRerunAllowance({
388
385
  recordedAt: now().toISOString(),
389
386
  };
390
387
  try {
391
- writeFileSync(
388
+ writeFileAtomic(
392
389
  paths.jsonPath,
393
390
  `${JSON.stringify({ ...digest, rerunAllowance: allowance }, null, 2)}\n`,
394
391
  );
@@ -76,11 +76,6 @@ function resolveStoryScope(opts, config) {
76
76
  };
77
77
  }
78
78
 
79
- /** `'story'` is the only scope. */
80
- function resolveScopeEnvelope(opts, config) {
81
- return resolveStoryScope(opts, config);
82
- }
83
-
84
79
  /**
85
80
  * Run a Story-scope review. `headRef` is required; `baseRef` defaults to
86
81
  * the remote base branch; `commentTargetId` (e.g. a PR number) overrides
@@ -349,7 +344,7 @@ export async function runCodeReview(opts = {}) {
349
344
  const { resolveConfigFn = resolveConfig } = opts;
350
345
 
351
346
  const config = resolveConfigFn();
352
- const envelope = resolveScopeEnvelope(opts, config);
347
+ const envelope = resolveStoryScope(opts, config);
353
348
 
354
349
  return executeReviewPipeline({ opts, config, envelope });
355
350
  }
@@ -13,6 +13,7 @@ import {
13
13
  } from '../config/temp-paths.js';
14
14
  import { gh as defaultGh } from '../gh-exec.js';
15
15
  import { gitSpawn as defaultGitSpawn, getStoryBranch } from '../git-utils.js';
16
+ import { isObject } from '../json-utils.js';
16
17
  import { defaultSleep } from '../util/sleep.js';
17
18
  import {
18
19
  CHECKS_FAILED_CLASS,
@@ -226,7 +227,7 @@ export function probeCloseArtifacts({
226
227
  let envelopeMtimeMs = null;
227
228
  try {
228
229
  const parsed = JSON.parse(fsImpl.readFileSync(envelopePath, 'utf8'));
229
- if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
230
+ if (isObject(parsed)) {
230
231
  envelope = parsed;
231
232
  envelopeMtimeMs = fsImpl.statSync(envelopePath).mtimeMs;
232
233
  }
@@ -5,14 +5,7 @@
5
5
  */
6
6
 
7
7
  import { Logger } from '../../../Logger.js';
8
- import {
9
- canFastForward,
10
- checkoutBranch,
11
- currentBranch,
12
- fetchRef,
13
- isWorkingTreeClean,
14
- mergeFastForward,
15
- } from './git-probes.js';
8
+ import { defaultFfProbes } from './git-probes-ff.js';
16
9
 
17
10
  const TAG = '[git-cleanup]';
18
11
 
@@ -26,10 +19,10 @@ export function planFastForward(ctx) {
26
19
  cwd,
27
20
  baseBranch,
28
21
  remoteName = 'origin',
29
- isCleanFn = isWorkingTreeClean,
30
- currentBranchFn = currentBranch,
31
- fetchFn = fetchRef,
32
- canFastForwardFn = canFastForward,
22
+ isCleanFn = defaultFfProbes.isClean,
23
+ currentBranchFn = defaultFfProbes.currentBranch,
24
+ fetchFn = defaultFfProbes.fetch,
25
+ canFastForwardFn = defaultFfProbes.canFastForward,
33
26
  } = ctx;
34
27
  if (!isCleanFn(cwd)) return { runnable: false, reason: 'dirty-tree' };
35
28
  const fetchRes = fetchFn(cwd, remoteName, baseBranch);
@@ -111,8 +104,8 @@ export function executeFastForward(ctx) {
111
104
  baseBranch,
112
105
  remoteName = 'origin',
113
106
  plan,
114
- checkoutFn = checkoutBranch,
115
- mergeFn = mergeFastForward,
107
+ checkoutFn = defaultFfProbes.checkout,
108
+ mergeFn = defaultFfProbes.merge,
116
109
  logger = Logger,
117
110
  } = ctx;
118
111
  if (!plan.runnable) {
@@ -22,26 +22,6 @@ export function isWorktreeLockFailure(stderr) {
22
22
  return WORKTREE_LOCK_RE.test(stderr ?? '');
23
23
  }
24
24
 
25
- export function isWorkingTreeClean(cwd) {
26
- return defaultFfProbes.isClean(cwd);
27
- }
28
-
29
- export function fetchRef(cwd, remoteName, ref) {
30
- return defaultFfProbes.fetch(cwd, remoteName, ref);
31
- }
32
-
33
- export function canFastForward(cwd, baseBranch, remoteName) {
34
- return defaultFfProbes.canFastForward(cwd, baseBranch, remoteName);
35
- }
36
-
37
- export function checkoutBranch(cwd, branch) {
38
- return defaultFfProbes.checkout(cwd, branch);
39
- }
40
-
41
- export function mergeFastForward(cwd, ref) {
42
- return defaultFfProbes.merge(cwd, ref);
43
- }
44
-
45
25
  /**
46
26
  * The single implementation of the FF git wrappers; callers needing an
47
27
  * injected spawn use this factory rather than a parallel copy.
@@ -109,7 +89,8 @@ export function makeFfProbes(spawn = gitSpawn) {
109
89
  };
110
90
  }
111
91
 
112
- const defaultFfProbes = makeFfProbes(gitSpawn);
92
+ /** The FF wrappers bound to the real `gitSpawn` — the phase defaults. */
93
+ export const defaultFfProbes = makeFfProbes(gitSpawn);
113
94
 
114
95
  /**
115
96
  * The destructive worktree / prune / stash wrappers over an injected spawn,
@@ -1,6 +1,5 @@
1
1
  /**
2
- * Branch / worktree / PR probes for the git-cleanup branches planner; also
3
- * re-exports the fast-forward probes from `git-probes-ff.js`.
2
+ * Branch / worktree / PR probes for the git-cleanup branches planner.
4
3
  *
5
4
  * @module lib/orchestration/git-cleanup/phases/git-probes
6
5
  */
@@ -12,18 +11,10 @@ import { parseWorktreePorcelain } from '../../../worktree-manager.js';
12
11
  import { makeWorktreeOps } from './git-probes-ff.js';
13
12
  import { resolveMergedTip } from './merged-tip.js';
14
13
 
15
- export {
16
- canFastForward,
17
- checkoutBranch,
18
- fetchRef,
19
- isWorkingTreeClean,
20
- mergeFastForward,
21
- } from './git-probes-ff.js';
22
-
23
14
  export const { removeWorktree, pruneRemoteTracking, dropStash } =
24
15
  makeWorktreeOps(gitSpawn);
25
16
 
26
- /* node:coverage ignore next */
17
+ /* node:coverage ignore next -- thin git spawn shim; real-git run in git-cleanup-content-merged.integration.test.js */
27
18
  export function listLocalBranches(cwd) {
28
19
  const res = gitSpawn(
29
20
  cwd,
@@ -60,7 +51,7 @@ function shortRemoteNames(stdout, remoteName) {
60
51
  .filter(Boolean);
61
52
  }
62
53
 
63
- /* node:coverage ignore next */
54
+ /* node:coverage ignore next -- thin git spawn shim; parsing tested via __testing.shortRemoteNames */
64
55
  export function listRemoteBranches(cwd, remoteName = 'origin') {
65
56
  const res = gitSpawn(
66
57
  cwd,
@@ -82,7 +73,7 @@ export function listRemoteBranches(cwd, remoteName = 'origin') {
82
73
  * @param {string} [remoteName]
83
74
  * @returns {string[]}
84
75
  */
85
- /* node:coverage ignore next */
76
+ /* node:coverage ignore next -- thin git spawn shim; parsing tested via __testing.shortRemoteNames */
86
77
  export function listRemoteMergedBranches(cwd, base, remoteName = 'origin') {
87
78
  const res = gitSpawn(
88
79
  cwd,
@@ -96,7 +87,7 @@ export function listRemoteMergedBranches(cwd, base, remoteName = 'origin') {
96
87
  return shortRemoteNames(res.stdout, remoteName);
97
88
  }
98
89
 
99
- /* node:coverage ignore next */
90
+ /* node:coverage ignore next -- thin git spawn shim; real-git run in git-cleanup-content-merged.integration.test.js */
100
91
  export function listMergedBranches(cwd, base) {
101
92
  const res = gitSpawn(
102
93
  cwd,
@@ -135,14 +126,14 @@ export function freshAnchoredMergedSet({
135
126
  return set;
136
127
  }
137
128
 
138
- /* node:coverage ignore next */
129
+ /* node:coverage ignore next -- thin git spawn shim; real-git run in git-cleanup-content-merged.integration.test.js */
139
130
  export function currentBranch(cwd) {
140
131
  const res = gitSpawn(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD');
141
132
  if (res.status !== 0) return null;
142
133
  return res.stdout.trim() || null;
143
134
  }
144
135
 
145
- /* node:coverage ignore next */
136
+ /* node:coverage ignore next -- thin git spawn shim; real-git run in git-cleanup-content-merged.integration.test.js */
146
137
  export function readProtectedConfig(cwd) {
147
138
  const res = gitSpawn(cwd, 'config', '--get', 'branch.protectedBranches');
148
139
  if (res.status !== 0) return [];
@@ -152,7 +143,7 @@ export function readProtectedConfig(cwd) {
152
143
  .filter(Boolean);
153
144
  }
154
145
 
155
- /* node:coverage ignore next */
146
+ /* node:coverage ignore next -- thin git spawn shim; parsing tested via parseWorktreePorcelain */
156
147
  export function worktreesByBranch(cwd) {
157
148
  const res = gitSpawn(cwd, 'worktree', 'list', '--porcelain');
158
149
  if (res.status !== 0) return new Map();
@@ -165,8 +156,8 @@ export function worktreesByBranch(cwd) {
165
156
  return map;
166
157
  }
167
158
 
168
- /* node:coverage ignore next */
169
159
  // Synchronous on purpose: `planCleanup` is a sync planner.
160
+ /* node:coverage ignore next -- thin gh spawn shim; tests inject runGh */
170
161
  export function defaultGhRunner(args, { cwd }) {
171
162
  return runGhOrThrow(args, { cwd, encoding: 'utf8' }, execFileCapture);
172
163
  }
@@ -354,8 +345,8 @@ export function branchTipSha({
354
345
  return res.status !== 0 ? null : validSha(firstLsRemoteSha(res.stdout));
355
346
  }
356
347
 
357
- /* node:coverage ignore next */
358
348
  // Guards the `<remote>/<base>` ancestry union.
349
+ /* node:coverage ignore next -- thin git spawn shim; tests inject refExistsFn */
359
350
  export function refExists(cwd, ref) {
360
351
  const res = gitSpawn(cwd, 'rev-parse', '--verify', '--quiet', ref);
361
352
  return res.status === 0;
@@ -370,7 +361,7 @@ export function refExists(cwd, ref) {
370
361
  * @param {{ localExists?: boolean, remoteName?: string }} [opts]
371
362
  * @returns {string | null}
372
363
  */
373
- /* node:coverage ignore next */
364
+ /* node:coverage ignore next -- thin git spawn shim; real-git run in git-cleanup-content-merged.integration.test.js */
374
365
  export function branchLastCommitAt(cwd, branch, opts = {}) {
375
366
  const { localExists = true, remoteName = 'origin' } = opts;
376
367
  const ref = localExists