mandrel 2.89.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.
- package/.agents/README.md +47 -7
- package/.agents/agents/story-worker.md +20 -0
- package/.agents/audit-checklists/lean.md +26 -0
- package/.agents/docs/agentrc-reference.json +5 -6
- package/.agents/docs/configuration.md +38 -30
- package/.agents/docs/workflows.md +7 -1
- package/.agents/instructions.md +3 -1
- package/.agents/runtime-deps.json +0 -2
- package/.agents/schemas/agentrc.schema.json +46 -45
- package/.agents/schemas/audit-rules.json +19 -0
- package/.agents/scripts/acceptance-eval.js +2 -6
- package/.agents/scripts/audit-exceptions.js +2 -4
- package/.agents/scripts/board-backfill.js +253 -0
- package/.agents/scripts/check-arch-cycles.js +1 -5
- package/.agents/scripts/check-context-budget.js +1 -5
- package/.agents/scripts/check-cyclomatic.js +1 -5
- package/.agents/scripts/check-dead-exports.js +23 -14
- package/.agents/scripts/check-doc-links.js +4 -4
- package/.agents/scripts/check-test-temp-hygiene.js +29 -33
- package/.agents/scripts/coverage-capture.js +14 -6
- package/.agents/scripts/diagnose-friction.js +8 -10
- package/.agents/scripts/generate-workflows-doc.js +5 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/index.js +2 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/inline-suppressions.js +36 -27
- package/.agents/scripts/lib/audit-exceptions/adapters/shortcut-markers.js +70 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/source-scan.js +26 -0
- package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +1 -0
- package/.agents/scripts/lib/baseline-schema-registry.js +3 -5
- package/.agents/scripts/lib/baselines/bundle-size-scorer.js +11 -28
- package/.agents/scripts/lib/baselines/components.js +5 -5
- package/.agents/scripts/lib/baselines/crap-preview-scan.js +4 -1
- package/.agents/scripts/lib/baselines/crap-updater-cli.js +6 -4
- package/.agents/scripts/lib/baselines/duplication-scanner.js +4 -10
- package/.agents/scripts/lib/baselines/kinds/crap.js +4 -2
- package/.agents/scripts/lib/baselines/kinds/duplication.js +4 -2
- package/.agents/scripts/lib/baselines/kinds/kind-factory.js +13 -6
- package/.agents/scripts/lib/baselines/refresh-service.js +10 -13
- package/.agents/scripts/lib/baselines/writer.js +4 -4
- package/.agents/scripts/lib/bdd-scenario-scanner.js +26 -31
- package/.agents/scripts/lib/bootstrap/gh-list.js +4 -5
- package/.agents/scripts/lib/bootstrap/gh-preflight.js +13 -8
- package/.agents/scripts/lib/child-exec.js +4 -4
- package/.agents/scripts/lib/claude/agents-projection.js +170 -0
- package/.agents/scripts/lib/claude/commands-projection.js +184 -0
- package/.agents/scripts/lib/close-validation/commands.js +28 -117
- package/.agents/scripts/lib/close-validation/gates.js +54 -48
- package/.agents/scripts/lib/close-validation/process.js +5 -1
- package/.agents/scripts/lib/close-validation/projections/crap.js +2 -1
- package/.agents/scripts/lib/close-validation/projections/maintainability.js +50 -15
- package/.agents/scripts/lib/config/agentrc-overlay.js +4 -7
- package/.agents/scripts/lib/config/commands.js +82 -7
- package/.agents/scripts/lib/config/explain.js +2 -1
- package/.agents/scripts/lib/config/gates/coverage.schema.js +39 -3
- package/.agents/scripts/lib/config/gates/crap-incremental-coverage.schema.js +1 -1
- package/.agents/scripts/lib/config/gates/crap.schema.js +5 -3
- package/.agents/scripts/lib/config/gates/duplication.schema.js +6 -11
- package/.agents/scripts/lib/config/gates/shared.js +2 -2
- package/.agents/scripts/lib/config/git-roots.js +120 -0
- package/.agents/scripts/lib/config/quality.js +46 -50
- package/.agents/scripts/lib/config/review-chain-default.js +4 -3
- package/.agents/scripts/lib/config/review-provider-clis.js +11 -0
- package/.agents/scripts/lib/config/temp-paths.js +3 -37
- package/.agents/scripts/lib/config-resolver.js +5 -9
- package/.agents/scripts/lib/config-settings-schema-delivery.js +2 -2
- package/.agents/scripts/lib/config-settings-schema-quality.js +3 -2
- package/.agents/scripts/lib/config-settings-schema.js +6 -7
- package/.agents/scripts/lib/coverage-baseline.js +2 -1
- package/.agents/scripts/lib/coverage-capture-affected.js +4 -3
- package/.agents/scripts/lib/coverage-capture-fullscope.js +3 -1
- package/.agents/scripts/lib/coverage-capture-passes.js +119 -34
- package/.agents/scripts/lib/coverage-capture-usage.js +1 -1
- package/.agents/scripts/lib/coverage-capture.js +80 -43
- package/.agents/scripts/lib/coverage-utils.js +34 -16
- package/.agents/scripts/lib/cpu-pool.js +2 -4
- package/.agents/scripts/lib/crap-engine.js +19 -1
- package/.agents/scripts/lib/crap-utils.js +2 -1
- package/.agents/scripts/lib/dead-exports-knip.js +29 -11
- package/.agents/scripts/lib/detect-package-manager.js +13 -0
- package/.agents/scripts/lib/feedback-loop/graduator-gh.js +4 -2
- package/.agents/scripts/lib/full-suite-lock.js +25 -9
- package/.agents/scripts/lib/gates/baseline-store.js +2 -10
- package/.agents/scripts/lib/generated/agentrc-validator.js +4 -1
- package/.agents/scripts/lib/gh-env.js +72 -0
- package/.agents/scripts/lib/gh-exec.js +26 -1
- package/.agents/scripts/lib/maintainability-utils.js +8 -8
- package/.agents/scripts/lib/npm-scripts.js +1 -1
- package/.agents/scripts/lib/observability/signal-validator.js +2 -6
- package/.agents/scripts/lib/observability/source-classifier.js +1 -0
- package/.agents/scripts/lib/observability/terse-result.js +2 -6
- package/.agents/scripts/lib/orchestration/board-access-latch.js +112 -0
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +10 -13
- package/.agents/scripts/lib/orchestration/column-sync.js +107 -52
- package/.agents/scripts/lib/orchestration/deliver-recover.js +2 -1
- package/.agents/scripts/lib/orchestration/git-cleanup/phases/git-probes.js +3 -3
- package/.agents/scripts/lib/orchestration/lifecycle/emit-ledger-event.js +2 -6
- package/.agents/scripts/lib/orchestration/light-suitability.js +5 -7
- package/.agents/scripts/lib/orchestration/pr-watch.js +7 -7
- package/.agents/scripts/lib/orchestration/project-meta-cache.js +2 -11
- package/.agents/scripts/lib/orchestration/project-meta-resolver.js +44 -17
- package/.agents/scripts/lib/orchestration/review-deposit.js +2 -9
- package/.agents/scripts/lib/orchestration/review-providers/callers-context.js +219 -0
- package/.agents/scripts/lib/orchestration/review-providers/code-review.js +53 -5
- package/.agents/scripts/lib/orchestration/review-providers/codex-cli.js +2 -2
- package/.agents/scripts/lib/orchestration/review-providers/llm-review.js +96 -0
- package/.agents/scripts/lib/orchestration/review-providers/mi-exemptions.js +2 -2
- package/.agents/scripts/lib/orchestration/review-providers/native.js +13 -19
- package/.agents/scripts/lib/orchestration/review-providers/review-depth.js +3 -2
- package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +2 -0
- package/.agents/scripts/lib/orchestration/review-providers/security-review.js +11 -3
- package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +2 -3
- package/.agents/scripts/lib/orchestration/story-close/format-autofix.js +41 -15
- package/.agents/scripts/lib/orchestration/story-deliver-terminal-schema.js +2 -4
- package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +2 -13
- package/.agents/scripts/lib/orchestration/story-handoff.js +27 -6
- package/.agents/scripts/lib/orchestration/story-progress.js +3 -11
- package/.agents/scripts/lib/orchestration/ticketing/bulk.js +3 -5
- package/.agents/scripts/lib/orchestration/verify-credit.js +52 -28
- package/.agents/scripts/lib/single-story-sweep/protection-ctx.js +11 -11
- package/.agents/scripts/lib/single-story-sweep/protection.js +1 -9
- package/.agents/scripts/lib/single-story-sweep/sweep-lock.js +1 -5
- package/.agents/scripts/lib/source-extensions.js +30 -15
- package/.agents/scripts/lib/test-run-credit.js +1 -9
- package/.agents/scripts/lib/test-temp.js +22 -21
- package/.agents/scripts/lib/util/ajv.js +111 -0
- package/.agents/scripts/lib/util/atomic-write.js +30 -0
- package/.agents/scripts/lib/util/paths.js +51 -0
- package/.agents/scripts/lib/util/sleep.js +6 -0
- package/.agents/scripts/lib/util/slug.js +12 -0
- package/.agents/scripts/lib/validation-evidence.js +19 -40
- package/.agents/scripts/lib/worktree/lifecycle/force-drain.js +2 -1
- package/.agents/scripts/lib/worktree/lifecycle/pending-cleanup.js +10 -28
- package/.agents/scripts/lib/worktree/lifecycle/reap.js +2 -2
- package/.agents/scripts/lib/worktree/node-modules-strategy.js +21 -14
- package/.agents/scripts/lint-issue-body.js +2 -2
- package/.agents/scripts/plan-context.js +2 -7
- package/.agents/scripts/providers/github/auth.js +3 -3
- package/.agents/scripts/providers/github/board-add.js +18 -9
- package/.agents/scripts/providers/github/errors.js +3 -1
- package/.agents/scripts/providers/github/gh-token-diagnostics.js +10 -7
- package/.agents/scripts/providers/github/issues.js +6 -2
- package/.agents/scripts/providers/github/mappers.js +1 -5
- package/.agents/scripts/providers/github/projects-v2-graphql.js +26 -6
- package/.agents/scripts/providers/github/search-budget.js +3 -1
- package/.agents/scripts/resolve-doc-tiers.js +7 -20
- package/.agents/scripts/sync-agentrc.js +5 -14
- package/.agents/scripts/sync-claude-agents.js +38 -150
- package/.agents/scripts/sync-claude-commands.js +35 -218
- package/.agents/scripts/update-coverage-baseline.js +1 -1
- package/.agents/scripts/update-crap-baseline.js +1 -1
- package/.agents/scripts/update-duplication-baseline.js +2 -16
- package/.agents/scripts/validate-skills.js +6 -10
- package/.agents/skills/core/code-review-and-quality/SKILL.md +3 -18
- package/.agents/skills/core/documentation-and-adrs/SKILL.md +4 -14
- package/.agents/workflows/audit-exceptions.md +9 -0
- package/.agents/workflows/audit-lean.md +129 -0
- package/.agents/workflows/helpers/audit-lens-core.md +7 -0
- package/.agents/workflows/helpers/code-quality-guardrails.md +21 -0
- package/.agents/workflows/helpers/code-review.md +15 -1
- package/.agents/workflows/helpers/deliver-digest.md +1 -1
- package/.agents/workflows/helpers/deliver-reference.md +2 -2
- package/.agents/workflows/mandrel-plan.md +2 -2
- package/docs/CHANGELOG.md +48 -0
- package/lib/cli/doctor-checks/codex.js +6 -5
- package/lib/cli/doctor-checks/llm-review.js +102 -0
- package/lib/cli/doctor-checks/project-access.js +124 -0
- package/lib/cli/doctor-checks/sync-parity.js +65 -140
- package/lib/cli/doctor-checks/test-credit-path.js +69 -28
- package/lib/cli/doctor-checks/toolchain.js +5 -3
- package/lib/cli/registry.js +11 -0
- package/lib/migrations/helpers/retire-agentrc-key.js +3 -3
- package/lib/migrations/index.js +6 -0
- package/lib/migrations/steps/2.91.0-move-shared-crap-capture-script.js +84 -0
- package/lib/migrations/steps/2.91.0-retire-duplication-formats.js +23 -0
- package/lib/migrations/steps/2.91.0-unset-null-lint-command.js +54 -0
- package/package.json +1 -3
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { insideString } from '../locate.js';
|
|
11
11
|
import { readText } from '../read.js';
|
|
12
12
|
import { makeRecord } from '../record.js';
|
|
13
|
+
import { sourceScanAdapter } from './source-scan.js';
|
|
13
14
|
|
|
14
15
|
const SCANNED_EXT_RE =
|
|
15
16
|
/\.(?:[cm]?[jt]sx?|vue|svelte|astro|mdx?|css|scss|html)$/;
|
|
@@ -63,10 +64,36 @@ function matchLine(line) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/** A pure comment line directly above, used when the directive carries no reason. */
|
|
67
|
+
function isPlainComment(text) {
|
|
68
|
+
return /^(?:\/\/|\/\*|\*|<!--)/.test(text) && !matchLine(text);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function commentBody(text) {
|
|
72
|
+
return text.replace(/^(?:\/\/+|\/\*+|\*+|<!--)\s*|\s*(?:\*\/|-->)$/g, '');
|
|
73
|
+
}
|
|
74
|
+
|
|
66
75
|
function reasonAbove(lines, i) {
|
|
67
76
|
const prev = lines[i - 1]?.trim() ?? '';
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
return isPlainComment(prev) ? commentBody(prev) : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function reasonFor(hit, lines, i) {
|
|
81
|
+
return (
|
|
82
|
+
hit.reason?.replace(/\s*(?:\*\/|-->)\s*$/, '') || reasonAbove(lines, i)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function suppressionRecord(file, line, hit, reason) {
|
|
87
|
+
return makeRecord({
|
|
88
|
+
adapter: 'inline-suppressions',
|
|
89
|
+
category: 'inline',
|
|
90
|
+
surface: hit.tool,
|
|
91
|
+
file,
|
|
92
|
+
line,
|
|
93
|
+
target: hit.rule,
|
|
94
|
+
rule: `${hit.tool}:${hit.rule}`,
|
|
95
|
+
justification: reason,
|
|
96
|
+
});
|
|
70
97
|
}
|
|
71
98
|
|
|
72
99
|
function fileRecords(ctx, file) {
|
|
@@ -74,34 +101,16 @@ function fileRecords(ctx, file) {
|
|
|
74
101
|
const records = [];
|
|
75
102
|
lines.forEach((line, i) => {
|
|
76
103
|
const hit = matchLine(line);
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
makeRecord({
|
|
82
|
-
adapter: 'inline-suppressions',
|
|
83
|
-
category: 'inline',
|
|
84
|
-
surface: hit.tool,
|
|
85
|
-
file,
|
|
86
|
-
line: i + 1,
|
|
87
|
-
target: hit.rule,
|
|
88
|
-
rule: `${hit.tool}:${hit.rule}`,
|
|
89
|
-
justification: reason,
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
104
|
+
if (hit)
|
|
105
|
+
records.push(
|
|
106
|
+
suppressionRecord(file, i + 1, hit, reasonFor(hit, lines, i)),
|
|
107
|
+
);
|
|
92
108
|
});
|
|
93
109
|
return records;
|
|
94
110
|
}
|
|
95
111
|
|
|
96
|
-
export const inlineSuppressions =
|
|
112
|
+
export const inlineSuppressions = sourceScanAdapter({
|
|
97
113
|
id: 'inline-suppressions',
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
ctx.scope.files.some((f) => SCANNED_EXT_RE.test(f))
|
|
101
|
-
? { applies: true, reason: 'source files present' }
|
|
102
|
-
: { applies: false, reason: 'no scannable source files' },
|
|
103
|
-
extract: (ctx) =>
|
|
104
|
-
ctx.scope.files
|
|
105
|
-
.filter((f) => SCANNED_EXT_RE.test(f))
|
|
106
|
-
.flatMap((f) => fileRecords(ctx, f)),
|
|
114
|
+
extRe: SCANNED_EXT_RE,
|
|
115
|
+
fileRecords,
|
|
107
116
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deliberate-shortcut markers: `shortcut: <ceiling>, <trigger>` comments. The
|
|
3
|
+
* trigger rides as the justification, so the shared classifier reads a named
|
|
4
|
+
* trigger as `live`, a passed date as `expired`, a closed `until #N` as
|
|
5
|
+
* `orphaned`, and a missing trigger as `unjustified`.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audit-exceptions/adapters/shortcut-markers
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { insideString } from '../locate.js';
|
|
11
|
+
import { readText } from '../read.js';
|
|
12
|
+
import { makeRecord } from '../record.js';
|
|
13
|
+
import { sourceScanAdapter } from './source-scan.js';
|
|
14
|
+
|
|
15
|
+
const SCANNED_EXT_RE =
|
|
16
|
+
/\.(?:[cm]?[jt]sx?|vue|svelte|astro|mdx?|css|scss|html|py|go|rs|rb|java|kt|swift|cs|php|sh)$/;
|
|
17
|
+
|
|
18
|
+
const MARKER_RE = /(?:\/\/+|\/\*+|#+|<!--|^\s*\*)\s*shortcut:\s*(.*)$/g;
|
|
19
|
+
|
|
20
|
+
function stripCloser(text) {
|
|
21
|
+
return text.replace(/\s*(?:\*\/|-->)\s*$/, '').trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A bare date or `when #N` trigger gets the `until` lead the expiry and ticket readers key on. */
|
|
25
|
+
function withUntilLead(trigger) {
|
|
26
|
+
return /^(?:when\s+)?(?:#\d|\d{4}-\d{2}-\d{2}\b)/.test(trigger)
|
|
27
|
+
? `until ${trigger}`
|
|
28
|
+
: trigger;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parse(text) {
|
|
32
|
+
const body = stripCloser(text);
|
|
33
|
+
const comma = body.indexOf(',');
|
|
34
|
+
if (comma === -1) return { ceiling: body, trigger: '' };
|
|
35
|
+
return {
|
|
36
|
+
ceiling: body.slice(0, comma).trim(),
|
|
37
|
+
trigger: withUntilLead(body.slice(comma + 1).trim()),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function markerRecord(file, line, { ceiling, trigger }) {
|
|
42
|
+
return makeRecord({
|
|
43
|
+
adapter: 'shortcut-markers',
|
|
44
|
+
category: 'inline',
|
|
45
|
+
surface: 'shortcut-marker',
|
|
46
|
+
file,
|
|
47
|
+
line,
|
|
48
|
+
target: ceiling,
|
|
49
|
+
rule: trigger ? 'has-trigger' : 'no-trigger',
|
|
50
|
+
justification: trigger || null,
|
|
51
|
+
probe: trigger ? { verdict: 'live', basis: 'trigger-named' } : null,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function fileRecords(ctx, file) {
|
|
56
|
+
const records = [];
|
|
57
|
+
(readText(ctx.root, file) ?? '').split('\n').forEach((line, i) => {
|
|
58
|
+
const hit = [...line.matchAll(MARKER_RE)][0];
|
|
59
|
+
if (hit && !insideString(line, hit.index)) {
|
|
60
|
+
records.push(markerRecord(file, i + 1, parse(hit[1])));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return records;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const shortcutMarkers = sourceScanAdapter({
|
|
67
|
+
id: 'shortcut-markers',
|
|
68
|
+
extRe: SCANNED_EXT_RE,
|
|
69
|
+
fileRecords,
|
|
70
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared shell of an adapter that scans source files line by line for an
|
|
3
|
+
* inline comment shape: it applies when any scoped file matches `extRe`, and
|
|
4
|
+
* extracts `fileRecords(ctx, file)` over each matching file.
|
|
5
|
+
*
|
|
6
|
+
* @module lib/audit-exceptions/adapters/source-scan
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {{ id: string, extRe: RegExp, fileRecords: (ctx: object, file: string) => object[] }} spec
|
|
11
|
+
* @returns {Readonly<object>}
|
|
12
|
+
*/
|
|
13
|
+
export function sourceScanAdapter({ id, extRe, fileRecords }) {
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
id,
|
|
16
|
+
category: 'inline',
|
|
17
|
+
applies: (ctx) =>
|
|
18
|
+
ctx.scope.files.some((f) => extRe.test(f))
|
|
19
|
+
? { applies: true, reason: 'source files present' }
|
|
20
|
+
: { applies: false, reason: 'no scannable source files' },
|
|
21
|
+
extract: (ctx) =>
|
|
22
|
+
ctx.scope.files
|
|
23
|
+
.filter((f) => extRe.test(f))
|
|
24
|
+
.flatMap((f) => fileRecords(ctx, f)),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import
|
|
9
|
-
import addFormats from 'ajv-formats';
|
|
8
|
+
import { createAjv } from './util/ajv.js';
|
|
10
9
|
|
|
11
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
11
|
const __dirname = path.dirname(__filename);
|
|
@@ -50,11 +49,10 @@ export const BASELINE_SCHEMA_FILES = Object.freeze([
|
|
|
50
49
|
* Build an AJV instance with the envelope and every per-kind baseline schema
|
|
51
50
|
* pre-registered. Throws if any schema file is unreadable or fails to compile.
|
|
52
51
|
*
|
|
53
|
-
* @returns {
|
|
52
|
+
* @returns {import('ajv').default} configured AJV with all baseline schemas registered.
|
|
54
53
|
*/
|
|
55
54
|
export function buildBaselineSchemaAjv() {
|
|
56
|
-
const ajv =
|
|
57
|
-
addFormats(ajv);
|
|
55
|
+
const ajv = createAjv({ allErrors: true, strict: false });
|
|
58
56
|
for (const filename of BASELINE_SCHEMA_FILES) {
|
|
59
57
|
const filePath = path.join(BASELINE_SCHEMAS_DIR, filename);
|
|
60
58
|
const schema = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
import nodeFs from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { gzipSync } from 'node:zlib';
|
|
13
|
-
import
|
|
13
|
+
import picomatch from 'picomatch';
|
|
14
|
+
import { toPosix, walkFiles } from '../util/paths.js';
|
|
14
15
|
|
|
15
16
|
/** Directories a bundle glob never descends into. */
|
|
16
|
-
const SKIPPED_DIRS =
|
|
17
|
+
const SKIPPED_DIRS = ['.git', 'node_modules'];
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @param {number} bytes
|
|
@@ -36,25 +37,6 @@ function staticBase(segments) {
|
|
|
36
37
|
return base.join('/');
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
/**
|
|
40
|
-
* @param {string} absDir
|
|
41
|
-
* @param {typeof nodeFs} fs
|
|
42
|
-
* @returns {string[]} Absolute file paths under `absDir`.
|
|
43
|
-
*/
|
|
44
|
-
function walkFiles(absDir, fs) {
|
|
45
|
-
if (!fs.existsSync(absDir)) return [];
|
|
46
|
-
const out = [];
|
|
47
|
-
for (const entry of fs.readdirSync(absDir, { withFileTypes: true })) {
|
|
48
|
-
const abs = path.join(absDir, entry.name);
|
|
49
|
-
if (entry.isDirectory()) {
|
|
50
|
-
if (!SKIPPED_DIRS.has(entry.name)) out.push(...walkFiles(abs, fs));
|
|
51
|
-
} else if (entry.isFile()) {
|
|
52
|
-
out.push(abs);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return out;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
40
|
/**
|
|
59
41
|
* Repo-relative files a bundle `path` (literal or glob) matches, sorted.
|
|
60
42
|
*
|
|
@@ -65,17 +47,18 @@ function walkFiles(absDir, fs) {
|
|
|
65
47
|
*/
|
|
66
48
|
function resolveBundleFiles(pattern, cwd, fs = nodeFs) {
|
|
67
49
|
const posix = pattern.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
68
|
-
|
|
69
|
-
if (!matcher.hasMagic()) {
|
|
50
|
+
if (!picomatch.scan(posix).isGlob) {
|
|
70
51
|
const abs = path.resolve(cwd, posix);
|
|
71
52
|
return fs.existsSync(abs) && fs.statSync(abs).isFile() ? [abs] : [];
|
|
72
53
|
}
|
|
54
|
+
const isMatch = picomatch(posix, { dot: true });
|
|
73
55
|
const base = staticBase(posix.split('/'));
|
|
74
|
-
return walkFiles(path.resolve(cwd, base),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
return walkFiles(path.resolve(cwd, base), {
|
|
57
|
+
skipDirs: SKIPPED_DIRS,
|
|
58
|
+
filter: (abs, dirent) =>
|
|
59
|
+
dirent.isFile() && isMatch(toPosix(path.relative(cwd, abs))),
|
|
60
|
+
fsImpl: fs,
|
|
61
|
+
}).sort();
|
|
79
62
|
}
|
|
80
63
|
|
|
81
64
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// buckets for per-component floors. The `*` component is the whole-repo
|
|
3
3
|
// rollup and matches every row; overlap between components is allowed.
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import picomatch from 'picomatch';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_COMPONENTS = Object.freeze({ '*': Object.freeze(['**']) });
|
|
8
8
|
|
|
@@ -10,18 +10,18 @@ const DEFAULT_COMPONENTS = Object.freeze({ '*': Object.freeze(['**']) });
|
|
|
10
10
|
* Compiled matchers keyed by glob: `groupRows` runs over tens of thousands of
|
|
11
11
|
* rows, and re-parsing each glob per row dominated its cost.
|
|
12
12
|
*
|
|
13
|
-
* @type {Map<string,
|
|
13
|
+
* @type {Map<string, (path: string) => boolean>}
|
|
14
14
|
*/
|
|
15
15
|
const GLOB_MATCHER_CACHE = new Map();
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @param {string} glob
|
|
19
|
-
* @returns {
|
|
19
|
+
* @returns {(path: string) => boolean}
|
|
20
20
|
*/
|
|
21
21
|
function matcherFor(glob) {
|
|
22
22
|
let matcher = GLOB_MATCHER_CACHE.get(glob);
|
|
23
23
|
if (!matcher) {
|
|
24
|
-
matcher =
|
|
24
|
+
matcher = picomatch(glob, { dot: true });
|
|
25
25
|
GLOB_MATCHER_CACHE.set(glob, matcher);
|
|
26
26
|
}
|
|
27
27
|
return matcher;
|
|
@@ -91,7 +91,7 @@ export function groupRows(rows, components, keyField = 'path') {
|
|
|
91
91
|
const list = Array.isArray(globs) ? globs : [];
|
|
92
92
|
for (const glob of list) {
|
|
93
93
|
if (typeof glob !== 'string' || glob.length === 0) continue;
|
|
94
|
-
if (matcherFor(glob)
|
|
94
|
+
if (matcherFor(glob)(normalized)) {
|
|
95
95
|
buckets[name].push(row);
|
|
96
96
|
break;
|
|
97
97
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* The scan → compare → report tail of `preview-gates.js#runCrapPreview`, once
|
|
3
3
|
* its baseline is loaded and judged compatible.
|
|
4
4
|
*/
|
|
5
|
+
|
|
5
6
|
import path from 'node:path';
|
|
7
|
+
import { COVERAGE_CAPTURE_DEFAULTS } from '../config/gates/coverage.schema.js';
|
|
6
8
|
import { loadCoverage } from '../coverage-utils.js';
|
|
7
9
|
import {
|
|
8
10
|
KERNEL_VERSION,
|
|
@@ -81,7 +83,8 @@ export async function computeCrapPreviewScan({
|
|
|
81
83
|
? crap.ignoreGlobs
|
|
82
84
|
: [];
|
|
83
85
|
const requireCoverage = crap.requireCoverage !== false;
|
|
84
|
-
const coveragePath =
|
|
86
|
+
const coveragePath =
|
|
87
|
+
crap.coveragePath ?? COVERAGE_CAPTURE_DEFAULTS.coveragePath;
|
|
85
88
|
const coverage = loadCoverage(path.resolve(cwd, coveragePath));
|
|
86
89
|
// The configured tolerance keeps the preview aligned with the authoritative
|
|
87
90
|
// gate: deltas at or under it are demoted, not failed.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import { COVERAGE_CAPTURE_DEFAULTS } from '../config/gates/coverage.schema.js';
|
|
9
10
|
import { getBaselines, getQuality, resolveConfig } from '../config-resolver.js';
|
|
10
11
|
import {
|
|
11
12
|
isCoverageFresh,
|
|
@@ -23,8 +24,6 @@ import {
|
|
|
23
24
|
SeatRefusal,
|
|
24
25
|
} from './seat-missing.js';
|
|
25
26
|
|
|
26
|
-
const DEFAULT_COVERAGE_PATH = 'coverage/coverage-final.json';
|
|
27
|
-
|
|
28
27
|
const DEFAULT_MIN_RESOLUTION_RATE = 0.75;
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -83,7 +82,9 @@ export function resolveCrapUpdaterOptions(
|
|
|
83
82
|
}
|
|
84
83
|
const baselinePath = args.baselinePath ?? baselines?.crap?.path;
|
|
85
84
|
const coveragePath =
|
|
86
|
-
args.coveragePath ??
|
|
85
|
+
args.coveragePath ??
|
|
86
|
+
crap.coveragePath ??
|
|
87
|
+
COVERAGE_CAPTURE_DEFAULTS.coveragePath;
|
|
87
88
|
return {
|
|
88
89
|
targetDirs: Array.isArray(crap.targetDirs) ? crap.targetDirs : [],
|
|
89
90
|
ignoreGlobs: Array.isArray(crap.ignoreGlobs) ? crap.ignoreGlobs : [],
|
|
@@ -91,7 +92,8 @@ export function resolveCrapUpdaterOptions(
|
|
|
91
92
|
minMethodResolutionRate:
|
|
92
93
|
crap.minMethodResolutionRate ?? DEFAULT_MIN_RESOLUTION_RATE,
|
|
93
94
|
coveragePath,
|
|
94
|
-
captureScript:
|
|
95
|
+
captureScript:
|
|
96
|
+
crap.captureScript ?? COVERAGE_CAPTURE_DEFAULTS.captureScript,
|
|
95
97
|
baselinePath,
|
|
96
98
|
absBaselinePath: path.isAbsolute(baselinePath)
|
|
97
99
|
? baselinePath
|
|
@@ -6,15 +6,11 @@ import { readFileSync } from 'node:fs';
|
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { resolveDependencyVersion } from '../dependency-version.js';
|
|
9
|
+
import { jscpdFormatsFor } from '../source-extensions.js';
|
|
9
10
|
|
|
10
11
|
const DEFAULT_MIN_TOKENS = 50;
|
|
11
|
-
/**
|
|
12
|
-
const
|
|
13
|
-
'javascript',
|
|
14
|
-
'jsx',
|
|
15
|
-
'typescript',
|
|
16
|
-
'tsx',
|
|
17
|
-
]);
|
|
12
|
+
/** Derived from the scorable-extension SSOT; deliberately not configurable. */
|
|
13
|
+
const SCAN_FORMATS = Object.freeze(jscpdFormatsFor());
|
|
18
14
|
|
|
19
15
|
const require = createRequire(import.meta.url);
|
|
20
16
|
|
|
@@ -220,7 +216,6 @@ function anchorIgnoreGlobs(ignoreGlobs, cwd) {
|
|
|
220
216
|
* targetDirs: string[],
|
|
221
217
|
* cwd?: string,
|
|
222
218
|
* minTokens?: number,
|
|
223
|
-
* formats?: string[],
|
|
224
219
|
* ignoreGlobs?: string[],
|
|
225
220
|
* detect: (opts: object) => Promise<Array<object>>,
|
|
226
221
|
* readLineCount?: (absPath: string) => number,
|
|
@@ -231,7 +226,6 @@ export async function scanDuplication({
|
|
|
231
226
|
targetDirs,
|
|
232
227
|
cwd = process.cwd(),
|
|
233
228
|
minTokens = DEFAULT_MIN_TOKENS,
|
|
234
|
-
formats = DEFAULT_FORMATS,
|
|
235
229
|
ignoreGlobs = [],
|
|
236
230
|
detect,
|
|
237
231
|
readLineCount: readLineCountFn = readLineCount,
|
|
@@ -246,7 +240,7 @@ export async function scanDuplication({
|
|
|
246
240
|
silent: true,
|
|
247
241
|
gitignore: false,
|
|
248
242
|
reporters: [],
|
|
249
|
-
format:
|
|
243
|
+
format: [...SCAN_FORMATS],
|
|
250
244
|
minTokens,
|
|
251
245
|
ignore: anchorIgnoreGlobs(ignoreGlobs, cwd),
|
|
252
246
|
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { COVERAGE_CAPTURE_DEFAULTS } from '../../config/gates/coverage.schema.js';
|
|
8
9
|
import {
|
|
9
10
|
COORDINATE_ORIGINAL,
|
|
10
11
|
COORDINATE_TRANSPILED,
|
|
@@ -461,7 +462,8 @@ export function assessComparisonBasis(compareResult, opts = {}) {
|
|
|
461
462
|
|
|
462
463
|
/**
|
|
463
464
|
* The CRAP capture script an operator hint names — the resolved
|
|
464
|
-
* `gates.crap.captureScript` when the caller passes it, else the
|
|
465
|
+
* `gates.crap.captureScript` when the caller passes it, else the coverage
|
|
466
|
+
* gate's default.
|
|
465
467
|
*
|
|
466
468
|
* @param {{ captureScript?: string } | undefined} ctx
|
|
467
469
|
* @returns {string}
|
|
@@ -469,7 +471,7 @@ export function assessComparisonBasis(compareResult, opts = {}) {
|
|
|
469
471
|
function captureScriptOf(ctx) {
|
|
470
472
|
return typeof ctx?.captureScript === 'string' && ctx.captureScript.length > 0
|
|
471
473
|
? ctx.captureScript
|
|
472
|
-
:
|
|
474
|
+
: COVERAGE_CAPTURE_DEFAULTS.captureScript;
|
|
473
475
|
}
|
|
474
476
|
|
|
475
477
|
/** @param {{ captureScript?: string } | undefined} ctx */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Per-kind module for the duplication baseline (jscpd). Row shape:
|
|
3
3
|
* `{ path, duplicatedLines, totalLines, percentage }`; lower is better. Bump
|
|
4
4
|
* the static kernel version when the row shape or rollup math changes.
|
|
5
|
+
* Regressions compare `duplicatedLines`; a ratio moves with the file's size.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { canonicalise } from '../path-canon.js';
|
|
@@ -72,12 +73,13 @@ export const {
|
|
|
72
73
|
} = makeBaselineKind({
|
|
73
74
|
keyField,
|
|
74
75
|
kernelVersion: '1.0.0',
|
|
75
|
-
axes: ['
|
|
76
|
+
axes: ['duplicatedLines'],
|
|
77
|
+
epsilonAxes: ['percentage'],
|
|
76
78
|
betterWhen: 'lower',
|
|
77
79
|
aggregate,
|
|
78
80
|
missingBasePolicy: 'addition',
|
|
79
81
|
removedRowPolicy: {
|
|
80
82
|
kind: 'improvement-when',
|
|
81
|
-
when: (b) => (b.
|
|
83
|
+
when: (b) => (b.duplicatedLines ?? 0) > 0,
|
|
82
84
|
},
|
|
83
85
|
});
|
|
@@ -8,11 +8,14 @@ import { mergeRowsByScope } from '../scope.js';
|
|
|
8
8
|
* (default; never a regression) or is classified against a `'perfect'` base.
|
|
9
9
|
* `removedRowPolicy`: a base row with no head row is classified against a
|
|
10
10
|
* perfect head, or is an improvement when `when(baseRow)` holds.
|
|
11
|
+
* `epsilonAxes`: the axes `applyEpsilon` measures (default `axes`); a prior
|
|
12
|
+
* row is kept only when every compared axis outside them is unchanged.
|
|
11
13
|
*
|
|
12
14
|
* @param {{
|
|
13
15
|
* keyField: string,
|
|
14
16
|
* kernelVersion: string | (() => string),
|
|
15
17
|
* axes: string[],
|
|
18
|
+
* epsilonAxes?: string[],
|
|
16
19
|
* betterWhen: 'higher' | 'lower',
|
|
17
20
|
* aggregate: (rows: object[]) => Record<string, number>,
|
|
18
21
|
* missingBasePolicy?: 'addition' | 'perfect',
|
|
@@ -35,6 +38,7 @@ export function makeBaselineKind({
|
|
|
35
38
|
keyField,
|
|
36
39
|
kernelVersion,
|
|
37
40
|
axes,
|
|
41
|
+
epsilonAxes = axes,
|
|
38
42
|
betterWhen,
|
|
39
43
|
aggregate,
|
|
40
44
|
missingBasePolicy = 'addition',
|
|
@@ -141,12 +145,7 @@ export function makeBaselineKind({
|
|
|
141
145
|
return regenRows.map((row) => {
|
|
142
146
|
const p = priorByKey.get(keyOf(row));
|
|
143
147
|
if (!p) return row;
|
|
144
|
-
|
|
145
|
-
for (const axis of axes) {
|
|
146
|
-
const d = Math.abs((row[axis] ?? 0) - (p[axis] ?? 0));
|
|
147
|
-
if (d > maxAxisDelta) maxAxisDelta = d;
|
|
148
|
-
}
|
|
149
|
-
return maxAxisDelta <= eps ? p : row;
|
|
148
|
+
return priorStillHolds(row, p, { axes, epsilonAxes, eps }) ? p : row;
|
|
150
149
|
});
|
|
151
150
|
}
|
|
152
151
|
|
|
@@ -169,3 +168,11 @@ export function makeBaselineKind({
|
|
|
169
168
|
mergeRows,
|
|
170
169
|
};
|
|
171
170
|
}
|
|
171
|
+
|
|
172
|
+
function priorStillHolds(row, prior, { axes, epsilonAxes, eps }) {
|
|
173
|
+
const drift = (axis) => Math.abs((row[axis] ?? 0) - (prior[axis] ?? 0));
|
|
174
|
+
if (epsilonAxes.some((axis) => drift(axis) > eps)) return false;
|
|
175
|
+
return axes.every(
|
|
176
|
+
(axis) => epsilonAxes.includes(axis) || row[axis] === prior[axis],
|
|
177
|
+
);
|
|
178
|
+
}
|
|
@@ -11,6 +11,7 @@ import nodeFs from 'node:fs';
|
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import { execFileCaptureAsync } from '../child-exec.js';
|
|
14
|
+
import { COVERAGE_CAPTURE_DEFAULTS } from '../config/gates/coverage.schema.js';
|
|
14
15
|
import { COVERAGE_GATE_DEFAULTS } from '../config/quality.js';
|
|
15
16
|
import { getQuality, resolveConfig } from '../config-resolver.js';
|
|
16
17
|
import {
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
isIgnoredByGlobs as isIgnoredByGlobsMi,
|
|
30
31
|
scanDirectory as scanDirectoryMi,
|
|
31
32
|
} from '../maintainability-utils.js';
|
|
33
|
+
import { isScorableSourceFile } from '../source-extensions.js';
|
|
32
34
|
import { buildBundleSizeScorer } from './bundle-size-scorer.js';
|
|
33
35
|
import { resolveDetectClones, scanDuplication } from './duplication-scanner.js';
|
|
34
36
|
import { getKindModule } from './kernel.js';
|
|
@@ -55,12 +57,13 @@ const SUPPORTED_KINDS = Object.freeze([
|
|
|
55
57
|
* @type {Record<string, (p: string) => boolean>}
|
|
56
58
|
*/
|
|
57
59
|
const KIND_FILE_PREDICATES = Object.freeze({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
// The scanner walks exactly this set, so a scoped file it never scores
|
|
61
|
+
// cannot trip the "produced no baseline rows" refusal.
|
|
62
|
+
maintainability: isScorableSourceFile,
|
|
63
|
+
crap: isScorableSourceFile,
|
|
64
|
+
coverage: isScorableSourceFile,
|
|
65
|
+
// jscpd's formats derive from the same set, so the scope matches the scan.
|
|
66
|
+
duplication: isScorableSourceFile,
|
|
64
67
|
// Bundle names are not paths: no changed file scopes a bundle row.
|
|
65
68
|
'bundle-size': () => false,
|
|
66
69
|
});
|
|
@@ -97,7 +100,7 @@ function buildDefaultCrapScorer({ cwd, config, quality } = {}) {
|
|
|
97
100
|
: [];
|
|
98
101
|
const requireCoverage = crapCfg.requireCoverage !== false;
|
|
99
102
|
const coverageRelPath =
|
|
100
|
-
crapCfg.coveragePath ??
|
|
103
|
+
crapCfg.coveragePath ?? COVERAGE_CAPTURE_DEFAULTS.coveragePath;
|
|
101
104
|
return async (files, opts) => {
|
|
102
105
|
const effectiveCwd = opts?.cwd ?? cwd ?? process.cwd();
|
|
103
106
|
const coverageAbs = path.isAbsolute(coverageRelPath)
|
|
@@ -648,17 +651,11 @@ function buildDefaultDuplicationScorer({ cwd, config, quality, detect } = {}) {
|
|
|
648
651
|
const ignoreGlobs = Array.isArray(dupCfg.ignoreGlobs)
|
|
649
652
|
? dupCfg.ignoreGlobs
|
|
650
653
|
: [];
|
|
651
|
-
// Absent or empty falls through to the scanner's own default.
|
|
652
|
-
const formats =
|
|
653
|
-
Array.isArray(dupCfg.formats) && dupCfg.formats.length > 0
|
|
654
|
-
? dupCfg.formats
|
|
655
|
-
: undefined;
|
|
656
654
|
return async (_files, opts) => {
|
|
657
655
|
const effectiveCwd = opts?.cwd ?? cwd ?? process.cwd();
|
|
658
656
|
return scanDuplication({
|
|
659
657
|
targetDirs,
|
|
660
658
|
cwd: effectiveCwd,
|
|
661
|
-
formats,
|
|
662
659
|
ignoreGlobs,
|
|
663
660
|
detect: detect ?? resolveDetectClones(),
|
|
664
661
|
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { deepEqual } from '../json-utils.js';
|
|
11
|
+
import { writeFileAtomic } from '../util/atomic-write.js';
|
|
11
12
|
import { assertEnvelope, buildEnvelope } from './envelope.js';
|
|
12
13
|
import { currentKernelVersion, getKindModule } from './kernel.js';
|
|
13
14
|
import { assertCanonical } from './path-canon.js';
|
|
@@ -144,10 +145,9 @@ export function writeFile(absPath, envelope, opts = {}) {
|
|
|
144
145
|
rows: envelope.rows,
|
|
145
146
|
};
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
fsImpl.renameSync(tmpPath, absPath);
|
|
148
|
+
writeFileAtomic(absPath, `${JSON.stringify(canonical, null, 2)}\n`, {
|
|
149
|
+
fsImpl,
|
|
150
|
+
});
|
|
151
151
|
return absPath;
|
|
152
152
|
}
|
|
153
153
|
|