mandrel 2.93.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 (130) hide show
  1. package/.agents/docs/configuration.md +8 -3
  2. package/.agents/runtime-deps.json +6 -6
  3. package/.agents/schemas/lifecycle/merge.unlanded.schema.json +2 -1
  4. package/.agents/schemas/story-deliver-terminal.schema.json +1 -0
  5. package/.agents/scripts/agents-bootstrap-github.js +1 -1
  6. package/.agents/scripts/board-backfill.js +1 -1
  7. package/.agents/scripts/boot-sweep.js +1 -1
  8. package/.agents/scripts/check-arch-cycles.js +69 -41
  9. package/.agents/scripts/check-doc-links.js +5 -7
  10. package/.agents/scripts/check-gherkin-corpus.js +2 -11
  11. package/.agents/scripts/clean-temp.js +1 -1
  12. package/.agents/scripts/cleanup-repo-test-temp.js +1 -1
  13. package/.agents/scripts/diagnose-friction.js +1 -1
  14. package/.agents/scripts/generate-lens-checklists.js +4 -4
  15. package/.agents/scripts/generate-skills-index.js +3 -2
  16. package/.agents/scripts/generate-workflows-doc.js +2 -1
  17. package/.agents/scripts/lib/audit-baselines/read.js +2 -1
  18. package/.agents/scripts/lib/audit-exceptions/adapters/tool-config.js +13 -3
  19. package/.agents/scripts/lib/audit-exceptions/globs.js +12 -1
  20. package/.agents/scripts/lib/audit-exceptions/probe.js +24 -2
  21. package/.agents/scripts/lib/audit-exceptions/read.js +2 -2
  22. package/.agents/scripts/lib/audit-to-stories/group-findings.js +77 -67
  23. package/.agents/scripts/lib/baselines/components.js +21 -19
  24. package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -8
  25. package/.agents/scripts/lib/baselines/kinds/maintainability.js +2 -3
  26. package/.agents/scripts/lib/baselines/preview-gates.js +2 -2
  27. package/.agents/scripts/lib/baselines/refresh-service.js +4 -7
  28. package/.agents/scripts/lib/baselines/writer.js +2 -7
  29. package/.agents/scripts/lib/bdd-runner-detect.js +2 -2
  30. package/.agents/scripts/lib/bdd-step-index.js +3 -7
  31. package/.agents/scripts/lib/bootstrap/baseline-merge-driver.js +11 -7
  32. package/.agents/scripts/lib/bootstrap/install-ledger.js +19 -4
  33. package/.agents/scripts/lib/bootstrap/json-io.js +14 -0
  34. package/.agents/scripts/lib/bootstrap/project-bootstrap.js +20 -44
  35. package/.agents/scripts/lib/bootstrap/quality-bootstrap.js +38 -54
  36. package/.agents/scripts/lib/branch-name-guard.js +2 -3
  37. package/.agents/scripts/lib/claude/agents-projection.js +1 -12
  38. package/.agents/scripts/lib/codex/agents-projection.js +2 -5
  39. package/.agents/scripts/lib/codex/skills-projection.js +4 -12
  40. package/.agents/scripts/lib/config/defaults.js +2 -1
  41. package/.agents/scripts/lib/config/qa.js +4 -5
  42. package/.agents/scripts/lib/config-schema.js +1 -8
  43. package/.agents/scripts/lib/config-settings-schema.js +0 -3
  44. package/.agents/scripts/lib/coverage-baseline.js +2 -3
  45. package/.agents/scripts/lib/coverage-utils.js +2 -1
  46. package/.agents/scripts/lib/cpu-pool.js +0 -1
  47. package/.agents/scripts/lib/cyclomatic-scope.js +2 -1
  48. package/.agents/scripts/lib/doc-tiers.js +2 -1
  49. package/.agents/scripts/lib/duplicate-search.js +52 -18
  50. package/.agents/scripts/lib/feedback-loop/prior-feedback-fetcher.js +47 -20
  51. package/.agents/scripts/lib/gh-exec.js +115 -25
  52. package/.agents/scripts/lib/gh-pr-rest.js +371 -0
  53. package/.agents/scripts/lib/git/sync-from-base.js +1 -1
  54. package/.agents/scripts/lib/import-graph.js +13 -28
  55. package/.agents/scripts/lib/json-utils.js +11 -0
  56. package/.agents/scripts/lib/label-constants.js +7 -1
  57. package/.agents/scripts/lib/maintainability-utils.js +14 -22
  58. package/.agents/scripts/lib/observability/runtime-friction.js +37 -1
  59. package/.agents/scripts/lib/orchestration/board-graphql-latch.js +75 -0
  60. package/.agents/scripts/lib/orchestration/check-baselines/phases/parse-args.js +25 -1
  61. package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +82 -41
  62. package/.agents/scripts/lib/orchestration/code-review.js +1 -6
  63. package/.agents/scripts/lib/orchestration/column-sync.js +23 -21
  64. package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
  65. package/.agents/scripts/lib/orchestration/git-cleanup/phases/fast-forward.js +7 -14
  66. package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes-ff.js +2 -21
  67. package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +11 -20
  68. package/.agents/scripts/lib/orchestration/git-cleanup/phases/phase-drivers.js +65 -86
  69. package/.agents/scripts/lib/orchestration/git-cleanup/phases/prompts.js +2 -2
  70. package/.agents/scripts/lib/orchestration/git-cleanup/phases/stashes.js +15 -6
  71. package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-unlanded.js +5 -2
  72. package/.agents/scripts/lib/orchestration/merge-block-class.js +48 -47
  73. package/.agents/scripts/lib/orchestration/merge-queue.js +49 -4
  74. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +20 -1
  75. package/.agents/scripts/lib/orchestration/project-meta-resolver.js +2 -2
  76. package/.agents/scripts/lib/orchestration/required-checks.js +72 -12
  77. package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +2 -3
  78. package/.agents/scripts/lib/orchestration/review-providers/parse-findings.js +4 -2
  79. package/.agents/scripts/lib/orchestration/single-story-close/phases/auto-merge.js +132 -58
  80. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +92 -9
  81. package/.agents/scripts/lib/orchestration/single-story-close/phases/graphql-preflight.js +41 -18
  82. package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -2
  83. package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +3 -3
  84. package/.agents/scripts/lib/orchestration/story-handoff.js +18 -5
  85. package/.agents/scripts/lib/orchestration/ticketing/transition.js +18 -22
  86. package/.agents/scripts/lib/runtime-deps/dep-resolution.js +19 -5
  87. package/.agents/scripts/lib/runtime-deps/scan-imports.js +4 -10
  88. package/.agents/scripts/lib/skills/parse-skill.js +2 -2
  89. package/.agents/scripts/lib/skills/walk-skill-files.js +7 -23
  90. package/.agents/scripts/lib/story-body/story-body.js +4 -14
  91. package/.agents/scripts/lib/util/atomic-write.js +14 -3
  92. package/.agents/scripts/lib/util/regex.js +4 -0
  93. package/.agents/scripts/notify.js +1 -1
  94. package/.agents/scripts/plan-context.js +1 -1
  95. package/.agents/scripts/plan-critics.js +3 -11
  96. package/.agents/scripts/providers/github/auth.js +0 -4
  97. package/.agents/scripts/providers/github/board-add.js +3 -3
  98. package/.agents/scripts/providers/github/compose.js +2 -0
  99. package/.agents/scripts/providers/github/errors.js +41 -0
  100. package/.agents/scripts/providers/github/project-board.js +0 -1
  101. package/.agents/scripts/providers/github/sub-issues-rest.js +55 -0
  102. package/.agents/scripts/providers/github/sub-issues.js +9 -1
  103. package/.agents/scripts/providers/github/tickets.js +0 -2
  104. package/.agents/scripts/resync-status-column.js +1 -1
  105. package/.agents/scripts/run-tests.js +1 -1
  106. package/.agents/scripts/single-story-confirm-merge.js +2 -0
  107. package/.agents/scripts/test-wrapper.js +1 -1
  108. package/.agents/scripts/update-ticket-state.js +4 -3
  109. package/.agents/scripts/validate-skills.js +2 -1
  110. package/.agents/skills/core/gates-and-baselines/reference.md +1 -0
  111. package/.agents/workflows/audit-baselines.md +21 -9
  112. package/.agents/workflows/clean-git.md +1 -1
  113. package/.agents/workflows/helpers/audit-lens-core.md +1 -1
  114. package/.agents/workflows/helpers/code-quality-guardrails.md +3 -3
  115. package/README.md +1 -1
  116. package/docs/CHANGELOG.md +46 -0
  117. package/lib/cli/claude-code-version.js +13 -7
  118. package/lib/cli/doctor-checks/llm-review.js +12 -5
  119. package/lib/cli/doctor-checks/merge-driver.js +10 -6
  120. package/lib/cli/doctor-checks/project-access.js +21 -8
  121. package/lib/cli/doctor-checks/read-json.js +2 -15
  122. package/lib/cli/doctor-checks/spawn.js +29 -9
  123. package/lib/cli/doctor-checks/test-credit-path.js +2 -1
  124. package/lib/cli/doctor-checks/toolchain.js +16 -12
  125. package/lib/cli/doctor.js +31 -8
  126. package/lib/cli/registry.js +7 -10
  127. package/lib/cli/sync.js +46 -10
  128. package/lib/cli/uninstall.js +259 -175
  129. package/lib/cli/update.js +3 -3
  130. package/package.json +23 -20
@@ -149,6 +149,73 @@ function detectDependencyEdges(groups) {
149
149
  return edges;
150
150
  }
151
151
 
152
+ /**
153
+ * File findings key by primary file; file-less findings join the best
154
+ * signature match or open a new topic key (seeding its signature bucket).
155
+ */
156
+ function resolveGroupKey(finding, sigBuckets) {
157
+ const primary = pickPrimaryFile(finding);
158
+ if (primary) return `file:${primary}`;
159
+ const { key: matchKey, sig } = bestSignatureGroupKey(finding, sigBuckets);
160
+ if (matchKey) return matchKey;
161
+ const key = `topic:${finding.dimension}:${finding.normalisedTitle.slice(0, 40)}`;
162
+ sigBuckets.set(key, sig);
163
+ return key;
164
+ }
165
+
166
+ function addFindingToGroups(groups, sigBuckets, key, finding) {
167
+ if (!groups.has(key)) {
168
+ groups.set(key, makeGroup(key));
169
+ if (!sigBuckets.has(key)) sigBuckets.set(key, rootCauseSignature(finding));
170
+ } else {
171
+ const existing = sigBuckets.get(key) ?? new Set();
172
+ for (const t of rootCauseSignature(finding)) existing.add(t);
173
+ sigBuckets.set(key, existing);
174
+ }
175
+ attachFindingToGroup(groups.get(key), finding);
176
+ }
177
+
178
+ function signatureOverlap(a, b) {
179
+ let overlap = 0;
180
+ for (const t of a) if (b.has(t)) overlap += 1;
181
+ return overlap;
182
+ }
183
+
184
+ // Merge single-finding groups into a same-directory group sharing ≥ 3
185
+ // signature tokens; returns the absorbed keys.
186
+ function mergeSameDirectorySingletons(groupArray, sigBuckets) {
187
+ const merged = new Set();
188
+ for (let i = 0; i < groupArray.length; i += 1) {
189
+ const target = groupArray[i];
190
+ if (merged.has(target.groupKey) || target.findings.length > 1) continue;
191
+ const targetDir = dirOf(pickPrimaryFile(target.findings[0]) ?? '');
192
+ if (!targetDir) continue;
193
+ const targetSig = sigBuckets.get(target.groupKey) ?? new Set();
194
+
195
+ for (let j = i + 1; j < groupArray.length; j += 1) {
196
+ const other = groupArray[j];
197
+ if (merged.has(other.groupKey)) continue;
198
+ const otherDir = dirOf(pickPrimaryFile(other.findings[0] ?? {}) ?? '');
199
+ if (otherDir !== targetDir) continue;
200
+ const otherSig = sigBuckets.get(other.groupKey) ?? new Set();
201
+ if (signatureOverlap(targetSig, otherSig) < 3) continue;
202
+
203
+ for (const f of other.findings) attachFindingToGroup(target, f);
204
+ merged.add(other.groupKey);
205
+ }
206
+ }
207
+ return merged;
208
+ }
209
+
210
+ function finalizeGroup(g) {
211
+ g.severity = highestSeverity(g.findings);
212
+ g.dimensions = [...g.dimensions].sort();
213
+ g.files = [...g.files];
214
+ g.title = synthesizeTitle(g);
215
+ delete g._signature;
216
+ return g;
217
+ }
218
+
152
219
  /**
153
220
  * @param {Array<{
154
221
  * dimension: string,
@@ -168,77 +235,20 @@ export function groupFindings(findings) {
168
235
 
169
236
  const groups = new Map();
170
237
  const sigBuckets = new Map();
171
-
172
238
  for (const finding of findings) {
173
- const primary = pickPrimaryFile(finding);
174
- let key;
175
-
176
- if (primary) {
177
- key = `file:${primary}`;
178
- } else {
179
- const { key: matchKey, sig } = bestSignatureGroupKey(finding, sigBuckets);
180
- if (matchKey) {
181
- key = matchKey;
182
- } else {
183
- key = `topic:${finding.dimension}:${finding.normalisedTitle.slice(0, 40)}`;
184
- sigBuckets.set(key, sig);
185
- }
186
- }
187
-
188
- if (!groups.has(key)) {
189
- groups.set(key, makeGroup(key));
190
- if (!sigBuckets.has(key))
191
- sigBuckets.set(key, rootCauseSignature(finding));
192
- } else {
193
- const existing = sigBuckets.get(key) ?? new Set();
194
- for (const t of rootCauseSignature(finding)) existing.add(t);
195
- sigBuckets.set(key, existing);
196
- }
197
-
198
- attachFindingToGroup(groups.get(key), finding);
239
+ addFindingToGroups(
240
+ groups,
241
+ sigBuckets,
242
+ resolveGroupKey(finding, sigBuckets),
243
+ finding,
244
+ );
199
245
  }
200
246
 
201
- // Merge single-finding groups into a same-directory group sharing ≥ 3
202
- // signature tokens.
203
247
  const groupArray = [...groups.values()];
204
- const merged = new Set();
205
- for (let i = 0; i < groupArray.length; i += 1) {
206
- if (merged.has(groupArray[i].groupKey)) continue;
207
- if (groupArray[i].findings.length > 1) continue;
208
- const targetDir = dirOf(pickPrimaryFile(groupArray[i].findings[0]) ?? '');
209
- if (!targetDir) continue;
210
- const targetSig = sigBuckets.get(groupArray[i].groupKey) ?? new Set();
211
-
212
- for (let j = i + 1; j < groupArray.length; j += 1) {
213
- if (merged.has(groupArray[j].groupKey)) continue;
214
- const otherDir = dirOf(
215
- pickPrimaryFile(groupArray[j].findings[0] ?? {}) ?? '',
216
- );
217
- if (otherDir !== targetDir) continue;
218
- const otherSig = sigBuckets.get(groupArray[j].groupKey) ?? new Set();
219
- let overlap = 0;
220
- for (const t of targetSig) if (otherSig.has(t)) overlap += 1;
221
- if (overlap < 3) continue;
222
-
223
- for (const f of groupArray[j].findings) {
224
- attachFindingToGroup(groupArray[i], f);
225
- }
226
- merged.add(groupArray[j].groupKey);
227
- }
228
- }
229
-
248
+ const merged = mergeSameDirectorySingletons(groupArray, sigBuckets);
230
249
  const finalGroups = groupArray
231
250
  .filter((g) => !merged.has(g.groupKey))
232
- .map((g) => {
233
- g.severity = highestSeverity(g.findings);
234
- g.dimensions = [...g.dimensions].sort();
235
- g.files = [...g.files];
236
- g.title = synthesizeTitle(g);
237
- delete g._signature;
238
- return g;
239
- });
240
-
241
- const edges = detectDependencyEdges(finalGroups);
242
-
243
- return { groups: finalGroups, edges };
251
+ .map(finalizeGroup);
252
+
253
+ return { groups: finalGroups, edges: detectDependencyEdges(finalGroups) };
244
254
  }
@@ -4,8 +4,6 @@
4
4
 
5
5
  import picomatch from 'picomatch';
6
6
 
7
- const DEFAULT_COMPONENTS = Object.freeze({ '*': Object.freeze(['**']) });
8
-
9
7
  /**
10
8
  * Compiled matchers keyed by glob: `groupRows` runs over tens of thousands of
11
9
  * rows, and re-parsing each glob per row dominated its cost.
@@ -57,6 +55,22 @@ function cloneDefault() {
57
55
  return { '*': ['**'] };
58
56
  }
59
57
 
58
+ function rowKey(row, field) {
59
+ const key = row && typeof row === 'object' ? row[field] : undefined;
60
+ if (typeof key !== 'string' || key.length === 0) return null;
61
+ return key.replace(/\\/g, '/');
62
+ }
63
+
64
+ function matchesAnyGlob(normalized, globs) {
65
+ if (!Array.isArray(globs)) return false;
66
+ return globs.some(
67
+ (glob) =>
68
+ typeof glob === 'string' &&
69
+ glob.length > 0 &&
70
+ matcherFor(glob)(normalized),
71
+ );
72
+ }
73
+
60
74
  /**
61
75
  * A row without a string `keyField` lands only in `*`.
62
76
  *
@@ -73,33 +87,21 @@ export function groupRows(rows, components, keyField = 'path') {
73
87
  components && typeof components === 'object' ? components : cloneDefault();
74
88
  const field =
75
89
  typeof keyField === 'string' && keyField.length > 0 ? keyField : 'path';
90
+ const entries = Object.entries(safeComponents);
76
91
 
77
92
  const buckets = {};
78
- for (const name of Object.keys(safeComponents)) {
93
+ for (const [name] of entries) {
79
94
  buckets[name] = [];
80
95
  }
81
96
 
82
97
  for (const row of safeRows) {
83
- for (const [name, globs] of Object.entries(safeComponents)) {
84
- if (name === '*') {
98
+ const normalized = rowKey(row, field);
99
+ for (const [name, globs] of entries) {
100
+ if (name === '*' || (normalized && matchesAnyGlob(normalized, globs))) {
85
101
  buckets[name].push(row);
86
- continue;
87
- }
88
- const key = row && typeof row === 'object' ? row[field] : undefined;
89
- if (typeof key !== 'string' || key.length === 0) continue;
90
- const normalized = key.replace(/\\/g, '/');
91
- const list = Array.isArray(globs) ? globs : [];
92
- for (const glob of list) {
93
- if (typeof glob !== 'string' || glob.length === 0) continue;
94
- if (matcherFor(glob)(normalized)) {
95
- buckets[name].push(row);
96
- break;
97
- }
98
102
  }
99
103
  }
100
104
  }
101
105
 
102
106
  return buckets;
103
107
  }
104
-
105
- export const _internals = Object.freeze({ DEFAULT_COMPONENTS });
@@ -7,6 +7,7 @@ import { createRequire } from 'node:module';
7
7
  import path from 'node:path';
8
8
  import { resolveDependencyVersion } from '../dependency-version.js';
9
9
  import { jscpdFormatsFor } from '../source-extensions.js';
10
+ import { toPosix } from '../util/paths.js';
10
11
 
11
12
  const DEFAULT_MIN_TOKENS = 50;
12
13
  /** Derived from the scorable-extension SSOT; deliberately not configurable. */
@@ -75,7 +76,7 @@ export function relativisePath(sourceId, cwd) {
75
76
  const rel = path.isAbsolute(sourceId)
76
77
  ? path.relative(cwd, sourceId)
77
78
  : sourceId;
78
- return rel.split(path.sep).join('/');
79
+ return toPosix(rel);
79
80
  }
80
81
 
81
82
  /**
@@ -187,11 +188,6 @@ export function readLineCount(absPath) {
187
188
  return lines.length;
188
189
  }
189
190
 
190
- /** fast-glob reads a backslash as an escape. */
191
- function toGlobPath(p) {
192
- return p.split(path.sep).join('/');
193
- }
194
-
195
191
  /**
196
192
  * jscpd 4's finder globs with `cwd: process.cwd()` and ignores its `cwd`
197
193
  * option, so a repo-relative ignore glob only ever matches the process tree.
@@ -207,7 +203,7 @@ function anchorIgnoreGlobs(ignoreGlobs, cwd) {
207
203
  return ignoreGlobs.map((glob) =>
208
204
  path.isAbsolute(glob) || glob.startsWith('**/')
209
205
  ? glob
210
- : toGlobPath(path.resolve(cwd, glob)),
206
+ : toPosix(path.resolve(cwd, glob)),
211
207
  );
212
208
  }
213
209
 
@@ -235,7 +231,7 @@ export async function scanDuplication({
235
231
  }
236
232
  const dirs = Array.isArray(targetDirs) ? targetDirs : [];
237
233
  const clones = await detect({
238
- path: dirs.map((dir) => toGlobPath(path.resolve(cwd, dir))),
234
+ path: dirs.map((dir) => toPosix(path.resolve(cwd, dir))),
239
235
  cwd,
240
236
  silent: true,
241
237
  gitignore: false,
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { readBaselineAtRef } from '../../baseline-loader.js';
8
8
  import { loadBaseline } from '../../gates/baseline-store.js';
9
+ import { isObject } from '../../json-utils.js';
9
10
  import { getBaseline } from '../maintainability-baseline-io.js';
10
11
  import { canonicalise } from '../path-canon.js';
11
12
  import { percentile } from './_shared-metric.js';
@@ -137,9 +138,7 @@ export function loadMaintainabilityBaseline({
137
138
  // An epic-ref read may return a non-object.
138
139
  if (epicRef && (parsed === null || typeof parsed !== 'object')) return {};
139
140
  if (
140
- parsed &&
141
- typeof parsed === 'object' &&
142
- !Array.isArray(parsed) &&
141
+ isObject(parsed) &&
143
142
  Array.isArray(parsed.rows) &&
144
143
  typeof parsed.$schema === 'string'
145
144
  ) {
@@ -5,11 +5,11 @@
5
5
  */
6
6
 
7
7
  import path from 'node:path';
8
-
9
8
  import { resolvePreviewScope } from '../changed-files.js';
10
9
  import { getBaselines, getQuality, resolveConfig } from '../config-resolver.js';
11
10
  import { KERNEL_VERSION, resolveEscomplexVersion } from '../crap-utils.js';
12
11
  import { calculateAll, scanDirectory } from '../maintainability-utils.js';
12
+ import { toPosix } from '../util/paths.js';
13
13
  import { computeCrapPreviewScan } from './crap-preview-scan.js';
14
14
  import {
15
15
  assertBaselineCompatible,
@@ -174,7 +174,7 @@ export async function runMaintainabilityPreview({
174
174
  const scores = {};
175
175
  for (const [key, mi] of Object.entries(rawScores)) {
176
176
  const rel = path.isAbsolute(key) ? path.relative(cwd, key) : key;
177
- const posixRel = rel.split(path.sep).join('/');
177
+ const posixRel = toPosix(rel);
178
178
  if (!MAINTAINABILITY_EXCLUSIONS.has(posixRel)) scores[key] = mi;
179
179
  }
180
180
  const stats = compareScores(scores, scopedBaseline, effectiveTolerance);
@@ -25,12 +25,14 @@ import {
25
25
  resolveTsTranspilerVersion,
26
26
  scanAndScore,
27
27
  } from '../crap-utils.js';
28
+ import { isObject } from '../json-utils.js';
28
29
  import {
29
30
  calculateAll as calculateAllMi,
30
31
  isIgnoredByGlobs as isIgnoredByGlobsMi,
31
32
  scanDirectory as scanDirectoryMi,
32
33
  } from '../maintainability-utils.js';
33
34
  import { isScorableSourceFile } from '../source-extensions.js';
35
+ import { toPosix } from '../util/paths.js';
34
36
  import { buildBundleSizeScorer } from './bundle-size-scorer.js';
35
37
  import { resolveDetectClones, scanDuplication } from './duplication-scanner.js';
36
38
  import { getKindModule } from './kernel.js';
@@ -214,7 +216,7 @@ function buildDefaultMaintainabilityScorer({ cwd, config, quality } = {}) {
214
216
  return filterExcludedRows(
215
217
  Object.entries(scores).map(([p, mi]) => {
216
218
  const rel = path.isAbsolute(p) ? path.relative(effectiveCwd, p) : p;
217
- return { path: rel.split(path.sep).join('/'), mi };
219
+ return { path: toPosix(rel), mi };
218
220
  }),
219
221
  );
220
222
  };
@@ -598,12 +600,7 @@ export function readPriorEnvelope(writePath, fs) {
598
600
  }
599
601
  try {
600
602
  const parsed = JSON.parse(raw);
601
- if (
602
- parsed &&
603
- typeof parsed === 'object' &&
604
- !Array.isArray(parsed) &&
605
- Array.isArray(parsed.rows)
606
- ) {
603
+ if (isObject(parsed) && Array.isArray(parsed.rows)) {
607
604
  return parsed;
608
605
  }
609
606
  return null;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import fs from 'node:fs';
9
9
  import path from 'node:path';
10
- import { deepEqual } from '../json-utils.js';
10
+ import { deepEqual, isObject } from '../json-utils.js';
11
11
  import { writeFileAtomic } from '../util/atomic-write.js';
12
12
  import { assertEnvelope, buildEnvelope } from './envelope.js';
13
13
  import { currentKernelVersion, getKindModule } from './kernel.js';
@@ -106,12 +106,7 @@ function resolvePriorEnvelope(priorEnvelope, prior) {
106
106
  }
107
107
 
108
108
  function isEnvelopeObject(value) {
109
- return (
110
- Boolean(value) &&
111
- typeof value === 'object' &&
112
- !Array.isArray(value) &&
113
- Array.isArray(value.rows)
114
- );
109
+ return isObject(value) && Array.isArray(value.rows);
115
110
  }
116
111
 
117
112
  /**
@@ -10,7 +10,7 @@
10
10
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
11
11
  import { readFile } from 'node:fs/promises';
12
12
  import path from 'node:path';
13
- import yaml from 'js-yaml';
13
+ import { load } from 'js-yaml';
14
14
  import picomatch from 'picomatch';
15
15
 
16
16
  import { Logger } from './Logger.js';
@@ -156,7 +156,7 @@ function readWorkspacePatterns(cwd, rootPkg, logger) {
156
156
  if (existsSync(yamlPath)) {
157
157
  try {
158
158
  const raw = readFileSync(yamlPath, 'utf8');
159
- const parsed = yaml.load(raw);
159
+ const parsed = load(raw);
160
160
  if (parsed && Array.isArray(parsed.packages)) {
161
161
  return parsed.packages.filter((p) => typeof p === 'string');
162
162
  }
@@ -13,6 +13,7 @@ import { readdirSync, readFileSync, statSync } from 'node:fs';
13
13
  import path from 'node:path';
14
14
 
15
15
  import { listFeatureFiles } from './bdd-scenario-scanner.js';
16
+ import { escapeRegExp } from './util/regex.js';
16
17
 
17
18
  export { listFeatureFiles };
18
19
 
@@ -47,10 +48,6 @@ const PARAMETER_PATTERNS = Object.freeze({
47
48
  const STEP_CALL_PATTERN =
48
49
  /\b(Given|When|Then|And|But|Step|defineStep)\s*\(\s*(?:(['"`])((?:\\.|(?!\2)[^\\])*)\2|\/((?:\\.|\[(?:\\.|[^\]\\])*\]|[^/\\[])+)\/([dgimsuvy]*))/g;
49
50
 
50
- function escapeRegExp(text) {
51
- return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
52
- }
53
-
54
51
  /**
55
52
  * @param {string} segment An alternation-free piece of an expression.
56
53
  * @returns {string}
@@ -135,9 +132,8 @@ function expressionToRegExp(expression) {
135
132
  }
136
133
 
137
134
  /**
138
- * Not `fs-walk.js`: that walker takes one extension, descends into
139
- * `node_modules`, and rethrows readdir failures, whereas an unreadable scope
140
- * here must surface as "zero step definitions" (the gate's fail-closed path).
135
+ * Not `walkFiles`: this walk follows symlinked directories. An unreadable
136
+ * scope yields zero step definitions (the gate's fail-closed path).
141
137
  *
142
138
  * @param {string[]} roots
143
139
  * @returns {string[]} absolute paths, sorted
@@ -81,19 +81,23 @@ function declaresBaselineMergeDriver(gitattributes) {
81
81
  }
82
82
 
83
83
  /**
84
- * Is the driver declared by the project and registered in this clone? Not
85
- * declared (or unreadable `.gitattributes`) means the project never opted in
86
- * and callers stay silent; declared with an empty command is the silent
87
- * text-merge fallback callers must flag.
84
+ * Is the driver declared and registered in this clone? Not declared (or
85
+ * unreadable `.gitattributes`) means the project never opted in and callers
86
+ * stay silent; declared with an empty command is the silent text-merge
87
+ * fallback callers must flag.
88
88
  *
89
89
  * @param {{
90
90
  * projectRoot: string,
91
91
  * fsImpl?: typeof fs,
92
92
  * runGit: (args: string[]) => { status?: number|null, stdout?: unknown },
93
93
  * }} ctx
94
- * @returns {{ declared: boolean, command: string }}
94
+ * @returns {Promise<{ declared: boolean, command: string }>}
95
95
  */
96
- export function probeBaselineMergeDriver({ projectRoot, fsImpl = fs, runGit }) {
96
+ export async function probeBaselineMergeDriver({
97
+ projectRoot,
98
+ fsImpl = fs,
99
+ runGit,
100
+ }) {
97
101
  let attributes = '';
98
102
  try {
99
103
  attributes = fsImpl.readFileSync(
@@ -106,7 +110,7 @@ export function probeBaselineMergeDriver({ projectRoot, fsImpl = fs, runGit }) {
106
110
  if (!declaresBaselineMergeDriver(attributes)) {
107
111
  return { declared: false, command: '' };
108
112
  }
109
- const configured = runGit([
113
+ const configured = await runGit([
110
114
  'config',
111
115
  '--get',
112
116
  BASELINE_MERGE_DRIVER_CONFIG_KEY,
@@ -9,6 +9,8 @@
9
9
  import fs from 'node:fs';
10
10
  import path from 'node:path';
11
11
 
12
+ import { writeFileAtomic } from '../util/atomic-write.js';
13
+
12
14
  /**
13
15
  * The `.gitignore` step keys off this exact POSIX path.
14
16
  *
@@ -104,17 +106,30 @@ export function buildLedgerRecord(args) {
104
106
  */
105
107
  export function writeInstallLedger(projectRoot, record) {
106
108
  const target = ledgerPath(projectRoot);
107
- fs.mkdirSync(path.dirname(target), { recursive: true });
108
- fs.writeFileSync(target, `${JSON.stringify(record, null, 2)}\n`, 'utf8');
109
+ writeFileAtomic(target, `${JSON.stringify(record, null, 2)}\n`);
109
110
  return { path: target, written: true, entryCount: record.entries.length };
110
111
  }
111
112
 
113
+ class InstallLedgerCorruptError extends Error {
114
+ constructor(target, cause) {
115
+ super(`${target} is not valid JSON (${cause.message})`, { cause });
116
+ this.name = 'InstallLedgerCorruptError';
117
+ this.path = target;
118
+ }
119
+ }
120
+
112
121
  /**
113
122
  * @param {string} projectRoot
114
- * @returns {ReturnType<typeof buildLedgerRecord>|null}
123
+ * @returns {ReturnType<typeof buildLedgerRecord>|null} `null` when absent.
124
+ * @throws {InstallLedgerCorruptError}
115
125
  */
116
126
  export function readInstallLedger(projectRoot) {
117
127
  const target = ledgerPath(projectRoot);
118
128
  if (!fs.existsSync(target)) return null;
119
- return JSON.parse(fs.readFileSync(target, 'utf8'));
129
+ const raw = fs.readFileSync(target, 'utf8');
130
+ try {
131
+ return JSON.parse(raw);
132
+ } catch (err) {
133
+ throw new InstallLedgerCorruptError(target, err);
134
+ }
120
135
  }
@@ -0,0 +1,14 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /** `null` when absent; parse errors propagate so a corrupt config fails loudly. */
5
+ export function readJsonIfExists(file, fsImpl = fs) {
6
+ if (!fsImpl.existsSync(file)) return null;
7
+ return JSON.parse(fsImpl.readFileSync(file, 'utf8'));
8
+ }
9
+
10
+ /** Pretty-printed with a trailing newline; creates the parent directory. */
11
+ export function writeJson(file, data, fsImpl = fs) {
12
+ fsImpl.mkdirSync(path.dirname(file), { recursive: true });
13
+ fsImpl.writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
14
+ }