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.
- package/.agents/docs/configuration.md +8 -3
- package/.agents/runtime-deps.json +6 -6
- package/.agents/schemas/lifecycle/merge.unlanded.schema.json +2 -1
- package/.agents/schemas/story-deliver-terminal.schema.json +1 -0
- package/.agents/scripts/agents-bootstrap-github.js +1 -1
- package/.agents/scripts/board-backfill.js +1 -1
- package/.agents/scripts/boot-sweep.js +1 -1
- package/.agents/scripts/check-arch-cycles.js +69 -41
- package/.agents/scripts/check-doc-links.js +5 -7
- package/.agents/scripts/check-gherkin-corpus.js +2 -11
- package/.agents/scripts/clean-temp.js +1 -1
- package/.agents/scripts/cleanup-repo-test-temp.js +1 -1
- package/.agents/scripts/diagnose-friction.js +1 -1
- package/.agents/scripts/generate-lens-checklists.js +4 -4
- package/.agents/scripts/generate-skills-index.js +3 -2
- package/.agents/scripts/generate-workflows-doc.js +2 -1
- package/.agents/scripts/lib/audit-baselines/read.js +2 -1
- package/.agents/scripts/lib/audit-exceptions/adapters/tool-config.js +13 -3
- package/.agents/scripts/lib/audit-exceptions/globs.js +12 -1
- package/.agents/scripts/lib/audit-exceptions/probe.js +24 -2
- package/.agents/scripts/lib/audit-exceptions/read.js +2 -2
- package/.agents/scripts/lib/audit-to-stories/group-findings.js +77 -67
- package/.agents/scripts/lib/baselines/components.js +21 -19
- package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -8
- package/.agents/scripts/lib/baselines/kinds/maintainability.js +2 -3
- package/.agents/scripts/lib/baselines/preview-gates.js +2 -2
- package/.agents/scripts/lib/baselines/refresh-service.js +4 -7
- package/.agents/scripts/lib/baselines/writer.js +2 -7
- package/.agents/scripts/lib/bdd-runner-detect.js +2 -2
- package/.agents/scripts/lib/bdd-step-index.js +3 -7
- package/.agents/scripts/lib/bootstrap/baseline-merge-driver.js +11 -7
- package/.agents/scripts/lib/bootstrap/install-ledger.js +19 -4
- package/.agents/scripts/lib/bootstrap/json-io.js +14 -0
- package/.agents/scripts/lib/bootstrap/project-bootstrap.js +20 -44
- package/.agents/scripts/lib/bootstrap/quality-bootstrap.js +38 -54
- package/.agents/scripts/lib/branch-name-guard.js +2 -3
- package/.agents/scripts/lib/claude/agents-projection.js +1 -12
- package/.agents/scripts/lib/codex/agents-projection.js +2 -5
- package/.agents/scripts/lib/codex/skills-projection.js +4 -12
- package/.agents/scripts/lib/config/defaults.js +2 -1
- package/.agents/scripts/lib/config/qa.js +4 -5
- package/.agents/scripts/lib/config-schema.js +1 -8
- package/.agents/scripts/lib/config-settings-schema.js +0 -3
- package/.agents/scripts/lib/coverage-baseline.js +2 -3
- package/.agents/scripts/lib/coverage-utils.js +2 -1
- package/.agents/scripts/lib/cpu-pool.js +0 -1
- package/.agents/scripts/lib/cyclomatic-scope.js +2 -1
- package/.agents/scripts/lib/doc-tiers.js +2 -1
- package/.agents/scripts/lib/duplicate-search.js +52 -18
- package/.agents/scripts/lib/feedback-loop/prior-feedback-fetcher.js +47 -20
- package/.agents/scripts/lib/gh-exec.js +115 -25
- package/.agents/scripts/lib/gh-pr-rest.js +371 -0
- package/.agents/scripts/lib/git/sync-from-base.js +1 -1
- package/.agents/scripts/lib/import-graph.js +13 -28
- package/.agents/scripts/lib/json-utils.js +11 -0
- package/.agents/scripts/lib/label-constants.js +7 -1
- package/.agents/scripts/lib/maintainability-utils.js +14 -22
- package/.agents/scripts/lib/observability/runtime-friction.js +37 -1
- package/.agents/scripts/lib/orchestration/board-graphql-latch.js +75 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/parse-args.js +25 -1
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +82 -41
- package/.agents/scripts/lib/orchestration/code-review.js +1 -6
- package/.agents/scripts/lib/orchestration/column-sync.js +23 -21
- package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/fast-forward.js +7 -14
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes-ff.js +2 -21
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +11 -20
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/phase-drivers.js +65 -86
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/prompts.js +2 -2
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/stashes.js +15 -6
- package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-unlanded.js +5 -2
- package/.agents/scripts/lib/orchestration/merge-block-class.js +48 -47
- package/.agents/scripts/lib/orchestration/merge-queue.js +49 -4
- package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +20 -1
- package/.agents/scripts/lib/orchestration/project-meta-resolver.js +2 -2
- package/.agents/scripts/lib/orchestration/required-checks.js +72 -12
- package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +2 -3
- package/.agents/scripts/lib/orchestration/review-providers/parse-findings.js +4 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/auto-merge.js +132 -58
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +92 -9
- package/.agents/scripts/lib/orchestration/single-story-close/phases/graphql-preflight.js +41 -18
- package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -2
- package/.agents/scripts/lib/orchestration/story-close/ratchet-shrink-writeback.js +3 -3
- package/.agents/scripts/lib/orchestration/story-handoff.js +18 -5
- package/.agents/scripts/lib/orchestration/ticketing/transition.js +18 -22
- package/.agents/scripts/lib/runtime-deps/dep-resolution.js +19 -5
- package/.agents/scripts/lib/runtime-deps/scan-imports.js +4 -10
- package/.agents/scripts/lib/skills/parse-skill.js +2 -2
- package/.agents/scripts/lib/skills/walk-skill-files.js +7 -23
- package/.agents/scripts/lib/story-body/story-body.js +4 -14
- package/.agents/scripts/lib/util/atomic-write.js +14 -3
- package/.agents/scripts/lib/util/regex.js +4 -0
- package/.agents/scripts/notify.js +1 -1
- package/.agents/scripts/plan-context.js +1 -1
- package/.agents/scripts/plan-critics.js +3 -11
- package/.agents/scripts/providers/github/auth.js +0 -4
- package/.agents/scripts/providers/github/board-add.js +3 -3
- package/.agents/scripts/providers/github/compose.js +2 -0
- package/.agents/scripts/providers/github/errors.js +41 -0
- package/.agents/scripts/providers/github/project-board.js +0 -1
- package/.agents/scripts/providers/github/sub-issues-rest.js +55 -0
- package/.agents/scripts/providers/github/sub-issues.js +9 -1
- package/.agents/scripts/providers/github/tickets.js +0 -2
- package/.agents/scripts/resync-status-column.js +1 -1
- package/.agents/scripts/run-tests.js +1 -1
- package/.agents/scripts/single-story-confirm-merge.js +2 -0
- package/.agents/scripts/test-wrapper.js +1 -1
- package/.agents/scripts/update-ticket-state.js +4 -3
- package/.agents/scripts/validate-skills.js +2 -1
- package/.agents/skills/core/gates-and-baselines/reference.md +1 -0
- package/.agents/workflows/audit-baselines.md +21 -9
- package/.agents/workflows/clean-git.md +1 -1
- package/.agents/workflows/helpers/audit-lens-core.md +1 -1
- package/.agents/workflows/helpers/code-quality-guardrails.md +3 -3
- package/README.md +1 -1
- package/docs/CHANGELOG.md +46 -0
- package/lib/cli/claude-code-version.js +13 -7
- package/lib/cli/doctor-checks/llm-review.js +12 -5
- package/lib/cli/doctor-checks/merge-driver.js +10 -6
- package/lib/cli/doctor-checks/project-access.js +21 -8
- package/lib/cli/doctor-checks/read-json.js +2 -15
- package/lib/cli/doctor-checks/spawn.js +29 -9
- package/lib/cli/doctor-checks/test-credit-path.js +2 -1
- package/lib/cli/doctor-checks/toolchain.js +16 -12
- package/lib/cli/doctor.js +31 -8
- package/lib/cli/registry.js +7 -10
- package/lib/cli/sync.js +46 -10
- package/lib/cli/uninstall.js +259 -175
- package/lib/cli/update.js +3 -3
- 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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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 =
|
|
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(
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
93
|
+
for (const [name] of entries) {
|
|
79
94
|
buckets[name] = [];
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
for (const row of safeRows) {
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
-
:
|
|
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) =>
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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 `
|
|
139
|
-
*
|
|
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
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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({
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|