peaks-loop 4.1.12 → 4.1.13
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +53 -0
- package/dist/cli/commands/_register.js +2 -0
- package/dist/cli/commands/batch-commands.d.ts +6 -0
- package/dist/cli/commands/batch-commands.js +70 -0
- package/dist/cli/commands/batch-diagnose-command.d.ts +10 -0
- package/dist/cli/commands/batch-diagnose-command.js +196 -0
- package/dist/cli/commands/batch-diagnose-envelope.d.ts +25 -0
- package/dist/cli/commands/batch-diagnose-envelope.js +60 -0
- package/dist/cli/commands/batch-diagnose-record.d.ts +21 -0
- package/dist/cli/commands/batch-diagnose-record.js +51 -0
- package/dist/cli/commands/batch-item-input.d.ts +59 -0
- package/dist/cli/commands/batch-item-input.js +113 -0
- package/dist/cli/commands/batch-report-command.d.ts +22 -0
- package/dist/cli/commands/batch-report-command.js +199 -0
- package/dist/cli/commands/core/skill-context-verdict.d.ts +16 -1
- package/dist/cli/commands/core/skill-context-verdict.js +38 -8
- package/dist/cli/commands/lint-commands.js +8 -0
- package/dist/cli/commands/lint-rules-command.d.ts +14 -0
- package/dist/cli/commands/lint-rules-command.js +44 -0
- package/dist/services/batch/batch-active-batch.d.ts +55 -0
- package/dist/services/batch/batch-active-batch.js +127 -0
- package/dist/services/batch/batch-context-reminder.d.ts +85 -0
- package/dist/services/batch/batch-context-reminder.js +201 -0
- package/dist/services/batch/batch-diagnosis-finding.d.ts +25 -0
- package/dist/services/batch/batch-diagnosis-finding.js +227 -0
- package/dist/services/batch/batch-diagnosis-report-store.d.ts +49 -0
- package/dist/services/batch/batch-diagnosis-report-store.js +133 -0
- package/dist/services/batch/batch-diagnosis-summary.d.ts +31 -0
- package/dist/services/batch/batch-diagnosis-summary.js +129 -0
- package/dist/services/batch/batch-diagnosis.d.ts +36 -0
- package/dist/services/batch/batch-diagnosis.js +107 -0
- package/dist/services/batch/batch-entry.d.ts +22 -0
- package/dist/services/batch/batch-entry.js +42 -0
- package/dist/services/batch/batch-fix-agent.d.ts +39 -0
- package/dist/services/batch/batch-fix-agent.js +126 -0
- package/dist/services/batch/batch-fix-types.d.ts +85 -0
- package/dist/services/batch/batch-fix-types.js +11 -0
- package/dist/services/batch/batch-fix.d.ts +15 -0
- package/dist/services/batch/batch-fix.js +229 -0
- package/dist/services/batch/batch-phase-advance.d.ts +45 -0
- package/dist/services/batch/batch-phase-advance.js +105 -0
- package/dist/services/batch/batch-progress-store.d.ts +52 -0
- package/dist/services/batch/batch-progress-store.js +219 -0
- package/dist/services/batch/batch-progress-types.d.ts +79 -0
- package/dist/services/batch/batch-progress-types.js +10 -0
- package/dist/services/batch/batch-recovery.d.ts +5 -0
- package/dist/services/batch/batch-recovery.js +24 -0
- package/dist/services/batch/batch-verify.d.ts +93 -0
- package/dist/services/batch/batch-verify.js +216 -0
- package/dist/services/code/auto-compact-decision.d.ts +17 -0
- package/dist/services/code/auto-compact-decision.js +6 -0
- package/dist/services/code/auto-compact-orchestrator.js +6 -0
- package/dist/services/code/batch-compaction-point.d.ts +45 -0
- package/dist/services/code/batch-compaction-point.js +99 -0
- package/dist/services/context/context-schema.d.ts +1 -1
- package/dist/services/lint/curated-rule-reader.d.ts +37 -0
- package/dist/services/lint/curated-rule-reader.js +179 -0
- package/dist/services/lint/project-lint-declarations.d.ts +27 -0
- package/dist/services/lint/project-lint-declarations.js +217 -0
- package/dist/services/lint/project-lint-tool-detection.d.ts +14 -0
- package/dist/services/lint/project-lint-tool-detection.js +208 -0
- package/dist/services/lint/project-lint-tool-rules.d.ts +19 -0
- package/dist/services/lint/project-lint-tool-rules.js +199 -0
- package/dist/services/lint/rule-pre-read-types.d.ts +66 -0
- package/dist/services/lint/rule-pre-read-types.js +22 -0
- package/dist/services/lint/rule-pre-read.d.ts +20 -0
- package/dist/services/lint/rule-pre-read.js +145 -0
- package/dist/services/skill/skill-search-service.d.ts +3 -3
- package/package.json +5 -5
- package/skills/peaks-code/references/micro-cycle.md +13 -1
- package/skills/peaks-race-code/SKILL.md +40 -1
|
@@ -110,6 +110,12 @@ export function evaluateAutoCompactDecision(input) {
|
|
|
110
110
|
}
|
|
111
111
|
// pre-compact zone (0.85 ≤ ratio < 0.95): honor D6.e in-flight deferral.
|
|
112
112
|
if (probe?.hasInFlightBatch === true) {
|
|
113
|
+
// A phase boundary is the batch's BEST compaction point, not a reason to
|
|
114
|
+
// wait: the stage's agents are done, its results are on disk, and the
|
|
115
|
+
// window is heaviest right there. So the deferral does not apply.
|
|
116
|
+
if (input.atPhaseBoundary === true) {
|
|
117
|
+
return { shouldCompact: true, reason: 'pre-compact', trigger, action: 'auto-compact-now' };
|
|
118
|
+
}
|
|
113
119
|
return { shouldCompact: false, reason: 'in-flight-batch', trigger, action: 'defer' };
|
|
114
120
|
}
|
|
115
121
|
if (input.force) {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* and the envelopes in `auto-compact-envelopes.js`.
|
|
27
27
|
*/
|
|
28
28
|
import { getSessionIdCanonical } from '../session/session-manager.js';
|
|
29
|
+
import { resolveBatchCompactionBoundary } from '../batch/batch-active-batch.js';
|
|
29
30
|
import { resolveOuterSessionId } from '../session/binding-status-service.js';
|
|
30
31
|
import { resolveCanonicalProjectRoot } from '../config/config-service.js';
|
|
31
32
|
import { thresholdFor } from './auto-compact-modes.js';
|
|
@@ -182,6 +183,11 @@ async function openRun(input, sessionId, mode) {
|
|
|
182
183
|
force: input.force,
|
|
183
184
|
bypassRedLine: input.bypassRedLine,
|
|
184
185
|
mode,
|
|
186
|
+
// A batch at a compaction boundary is the batch's BEST compaction
|
|
187
|
+
// point: the stage's agents are done and its results are on disk, so
|
|
188
|
+
// the in-flight deferral must not apply there. Absent a batch, this
|
|
189
|
+
// is `false` and the behaviour is exactly what it was.
|
|
190
|
+
atPhaseBoundary: resolveBatchCompactionBoundary(input.projectRoot, sessionId),
|
|
185
191
|
// Tagged through so the decision can apply the source-aware carve-out for Mac's
|
|
186
192
|
// `transcript-estimate` signal.
|
|
187
193
|
source: probe.source
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BatchPhase } from '../batch/batch-progress-types.js';
|
|
2
|
+
import type { AutoCompactMode } from './auto-compact-modes.js';
|
|
3
|
+
/** Which rule decided the compaction point. */
|
|
4
|
+
export type BatchCompactionKind = 'silent' | 'ratio' | 'phase-boundary' | 'red-line';
|
|
5
|
+
/**
|
|
6
|
+
* The decision, in the shape the caller acts on.
|
|
7
|
+
*
|
|
8
|
+
* `action` uses the same vocabulary as `evaluateAutoCompactDecision`, so a
|
|
9
|
+
* caller that already handles that action handles this one.
|
|
10
|
+
*/
|
|
11
|
+
export interface BatchCompactionPoint {
|
|
12
|
+
readonly kind: BatchCompactionKind;
|
|
13
|
+
readonly shouldCompact: boolean;
|
|
14
|
+
readonly action: 'ok' | 'soft-warn' | 'auto-compact-now' | 'red-line';
|
|
15
|
+
readonly ratio: number;
|
|
16
|
+
/** Whether the batch is crossing one of the two compaction boundaries. */
|
|
17
|
+
readonly atBoundary: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The two phase transitions that are a compaction boundary.
|
|
21
|
+
*
|
|
22
|
+
* ①→② is the diagnosis giving way to the topology, ③→④ the fix giving
|
|
23
|
+
* way to the verification. The other two transitions (②→③, ④→done) are
|
|
24
|
+
* not boundaries: neither of them is followed by a stage that reads the
|
|
25
|
+
* stage before it back.
|
|
26
|
+
*
|
|
27
|
+
* @param fromPhase - The phase the batch was in.
|
|
28
|
+
* @param toPhase - The phase the batch is in now.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isBatchPhaseBoundary(fromPhase: BatchPhase, toPhase: BatchPhase): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Decide the batch's compaction point.
|
|
33
|
+
*
|
|
34
|
+
* @param input.ratio - The context ratio, 0..1.
|
|
35
|
+
* @param input.fromPhase - The phase the batch was in.
|
|
36
|
+
* @param input.toPhase - The phase the batch is in now; the same value as
|
|
37
|
+
* `fromPhase` when no transition happened.
|
|
38
|
+
* @param input.mode - The auto-compact mode; the thresholds come from it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function decideBatchCompactionPoint(input: {
|
|
41
|
+
readonly ratio: number;
|
|
42
|
+
readonly fromPhase: BatchPhase;
|
|
43
|
+
readonly toPhase: BatchPhase;
|
|
44
|
+
readonly mode?: AutoCompactMode;
|
|
45
|
+
}): BatchCompactionPoint;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/services/code/batch-compaction-point.ts
|
|
2
|
+
//
|
|
3
|
+
// WHEN a batch compacts. The compaction thresholds are not this file's to
|
|
4
|
+
// set: `evaluateCompactTrigger` already owns 0.80 / 0.85 / 0.95, and this
|
|
5
|
+
// file reads them.
|
|
6
|
+
//
|
|
7
|
+
// WHY THE COMPACTION POINT IS A PHASE BOUNDARY AND A RATIO. The batch's
|
|
8
|
+
// four phases end in two boundaries that are the cheapest moments to
|
|
9
|
+
// compact at: ①→② (diagnosis → topology) and ③→④ (fix → verify). At ①→②
|
|
10
|
+
// the N diagnosis reports have just been produced; at ③→④ the N fixes
|
|
11
|
+
// have just landed. Both are moments where the batch's own state is on
|
|
12
|
+
// disk (the progress record) and the window is at its heaviest — which is
|
|
13
|
+
// exactly why compacting there costs least and buys most. §7A.4 of the
|
|
14
|
+
// design calls the boundary the preferred compaction point; this file is
|
|
15
|
+
// how that preference is decided.
|
|
16
|
+
//
|
|
17
|
+
// THE THREE CASES, AND WHAT IS NOT CHANGED.
|
|
18
|
+
// - ratio ≥ red line (0.95): the red line. Unchanged, and the boundary
|
|
19
|
+
// does not defer it — at the red line the harness is asked NOW,
|
|
20
|
+
// because waiting for a boundary is how a window overflows.
|
|
21
|
+
// - ratio ≥ auto-fire (0.80) at a boundary: the boundary. This is the
|
|
22
|
+
// best point, so the compaction is attributed to it.
|
|
23
|
+
// - ratio ≥ auto-fire (0.80) away from a boundary: the existing
|
|
24
|
+
// auto-compact contract, unchanged. It compresses by itself; it never
|
|
25
|
+
// asks the user.
|
|
26
|
+
//
|
|
27
|
+
// WHY NOTHING IS DEFERRED. Deferring a compaction to the next boundary is
|
|
28
|
+
// what the existing in-flight-batch deferral did, and it is why a batch's
|
|
29
|
+
// window was systematically compressed too late: the reports arrive
|
|
30
|
+
// together, so the window is already at its worst before the boundary
|
|
31
|
+
// arrives. This file never says "wait" — it says where the compaction
|
|
32
|
+
// happens.
|
|
33
|
+
import { evaluateCompactTrigger } from './auto-compact-decision.js';
|
|
34
|
+
/**
|
|
35
|
+
* The two phase transitions that are a compaction boundary.
|
|
36
|
+
*
|
|
37
|
+
* ①→② is the diagnosis giving way to the topology, ③→④ the fix giving
|
|
38
|
+
* way to the verification. The other two transitions (②→③, ④→done) are
|
|
39
|
+
* not boundaries: neither of them is followed by a stage that reads the
|
|
40
|
+
* stage before it back.
|
|
41
|
+
*
|
|
42
|
+
* @param fromPhase - The phase the batch was in.
|
|
43
|
+
* @param toPhase - The phase the batch is in now.
|
|
44
|
+
*/
|
|
45
|
+
export function isBatchPhaseBoundary(fromPhase, toPhase) {
|
|
46
|
+
return ((fromPhase === 'diagnosis' && toPhase === 'topology') ||
|
|
47
|
+
(fromPhase === 'fix' && toPhase === 'verify'));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decide the batch's compaction point.
|
|
51
|
+
*
|
|
52
|
+
* @param input.ratio - The context ratio, 0..1.
|
|
53
|
+
* @param input.fromPhase - The phase the batch was in.
|
|
54
|
+
* @param input.toPhase - The phase the batch is in now; the same value as
|
|
55
|
+
* `fromPhase` when no transition happened.
|
|
56
|
+
* @param input.mode - The auto-compact mode; the thresholds come from it.
|
|
57
|
+
*/
|
|
58
|
+
export function decideBatchCompactionPoint(input) {
|
|
59
|
+
const mode = input.mode ?? 'standard';
|
|
60
|
+
const atBoundary = isBatchPhaseBoundary(input.fromPhase, input.toPhase);
|
|
61
|
+
// The trigger owns the thresholds. This file only asks which zone the
|
|
62
|
+
// ratio is in and whether the batch is at a boundary.
|
|
63
|
+
const trigger = evaluateCompactTrigger(input.ratio, mode);
|
|
64
|
+
const inAutoZone = trigger.kind === 'auto-fire' || trigger.kind === 'pre-compact';
|
|
65
|
+
if (trigger.kind === 'red-line') {
|
|
66
|
+
return {
|
|
67
|
+
kind: 'red-line',
|
|
68
|
+
shouldCompact: true,
|
|
69
|
+
action: 'red-line',
|
|
70
|
+
ratio: input.ratio,
|
|
71
|
+
atBoundary
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (atBoundary && inAutoZone) {
|
|
75
|
+
return {
|
|
76
|
+
kind: 'phase-boundary',
|
|
77
|
+
shouldCompact: true,
|
|
78
|
+
action: 'auto-compact-now',
|
|
79
|
+
ratio: input.ratio,
|
|
80
|
+
atBoundary
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (inAutoZone) {
|
|
84
|
+
return {
|
|
85
|
+
kind: 'ratio',
|
|
86
|
+
shouldCompact: true,
|
|
87
|
+
action: 'auto-compact-now',
|
|
88
|
+
ratio: input.ratio,
|
|
89
|
+
atBoundary
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
kind: 'silent',
|
|
94
|
+
shouldCompact: false,
|
|
95
|
+
action: trigger.kind === 'soft-warn' ? 'soft-warn' : 'ok',
|
|
96
|
+
ratio: input.ratio,
|
|
97
|
+
atBoundary
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EffectiveRule } from './rule-pre-read-types.js';
|
|
2
|
+
/** Where the curated rule sets live, or why they could not be found. */
|
|
3
|
+
export type CuratedRoot = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
};
|
|
10
|
+
/** One rule file, parsed into its declared patterns and its body. */
|
|
11
|
+
type CuratedRuleFile = {
|
|
12
|
+
readonly globs: readonly string[];
|
|
13
|
+
readonly body: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The curated rule root, resolved through the bundled `ecc-universal`
|
|
17
|
+
* dependency. The dependency ships the rules, so there is nothing to fetch.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveCuratedRulesRoot(): CuratedRoot;
|
|
20
|
+
/**
|
|
21
|
+
* Split a rule file into its declared patterns and its body.
|
|
22
|
+
*
|
|
23
|
+
* A file with no frontmatter has no declared patterns, which means it governs
|
|
24
|
+
* every file — that is how the `common/` layer is written.
|
|
25
|
+
*/
|
|
26
|
+
export declare function splitFrontmatter(text: string): CuratedRuleFile;
|
|
27
|
+
/**
|
|
28
|
+
* The curated rules that govern a file set.
|
|
29
|
+
*
|
|
30
|
+
* Returns the rules AND the reasons the read could not produce them, so a
|
|
31
|
+
* missing curated layer is never mistaken for "there are no curated rules".
|
|
32
|
+
*/
|
|
33
|
+
export declare function readCuratedRules(files: readonly string[], root: CuratedRoot): {
|
|
34
|
+
rules: readonly EffectiveRule[];
|
|
35
|
+
reasons: readonly string[];
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/services/lint/curated-rule-reader.ts
|
|
2
|
+
//
|
|
3
|
+
// L3 — the CURATED language rule sets (the ECC `rules/<lang>/` tree).
|
|
4
|
+
//
|
|
5
|
+
// The curated layer answers "what are the general rules for this language?".
|
|
6
|
+
// It is read the same way the other two layers are read: by asking the source
|
|
7
|
+
// what it declares. Each ECC rule file declares the file patterns it governs
|
|
8
|
+
// in its own frontmatter:
|
|
9
|
+
//
|
|
10
|
+
// ---
|
|
11
|
+
// paths:
|
|
12
|
+
// - "**/*.ts"
|
|
13
|
+
// - "**/*.tsx"
|
|
14
|
+
// ---
|
|
15
|
+
//
|
|
16
|
+
// So the file set is matched against those DECLARED patterns — there is no
|
|
17
|
+
// language table here, and no branch on the language of a file. A rule file
|
|
18
|
+
// with no `paths` (the `common/` layer) governs every file.
|
|
19
|
+
//
|
|
20
|
+
// ONE ENTRY PER RULE FILE, never one per file: the same rule text governs a
|
|
21
|
+
// whole family of files, and repeating it per file is what blows a fix prompt
|
|
22
|
+
// up.
|
|
23
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
import picomatch from 'picomatch';
|
|
26
|
+
import { resolveEccPackageRoot } from 'peaks-loop-mut';
|
|
27
|
+
/** The directory inside the ECC package that holds the curated rule sets. */
|
|
28
|
+
const CURATED_RULES_SUBDIR = 'rules';
|
|
29
|
+
/**
|
|
30
|
+
* The curated rule root, resolved through the bundled `ecc-universal`
|
|
31
|
+
* dependency. The dependency ships the rules, so there is nothing to fetch.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveCuratedRulesRoot() {
|
|
34
|
+
try {
|
|
35
|
+
return { ok: true, path: join(resolveEccPackageRoot(), CURATED_RULES_SUBDIR) };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reason: `the curated rule sets are not available: ${error instanceof Error ? error.message : String(error)}`
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The rule files of one curated language directory. */
|
|
45
|
+
function curatedRuleFiles(rulesDir, language, problems) {
|
|
46
|
+
const dir = join(rulesDir, language);
|
|
47
|
+
let entries;
|
|
48
|
+
try {
|
|
49
|
+
entries = readdirSync(dir);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
problems.push(`${language}: ${error instanceof Error ? error.message : String(error)}`);
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const files = [];
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (!entry.endsWith('.md'))
|
|
58
|
+
continue;
|
|
59
|
+
const read = readRuleFile(join(dir, entry));
|
|
60
|
+
if (!read.ok) {
|
|
61
|
+
problems.push(`${language}/${entry}: ${read.reason}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
files.push(read.ruleFile);
|
|
65
|
+
}
|
|
66
|
+
return files;
|
|
67
|
+
}
|
|
68
|
+
/** One rule file, or the reason it could not be read. */
|
|
69
|
+
function readRuleFile(path) {
|
|
70
|
+
try {
|
|
71
|
+
return { ok: true, ruleFile: splitFrontmatter(readFileSync(path, 'utf8')) };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Split a rule file into its declared patterns and its body.
|
|
82
|
+
*
|
|
83
|
+
* A file with no frontmatter has no declared patterns, which means it governs
|
|
84
|
+
* every file — that is how the `common/` layer is written.
|
|
85
|
+
*/
|
|
86
|
+
export function splitFrontmatter(text) {
|
|
87
|
+
const lines = text.split(/\r?\n/);
|
|
88
|
+
if (lines[0]?.trim() !== '---')
|
|
89
|
+
return { globs: [], body: text };
|
|
90
|
+
const end = lines.findIndex((line, index) => index > 0 && line.trim() === '---');
|
|
91
|
+
if (end === -1)
|
|
92
|
+
return { globs: [], body: text };
|
|
93
|
+
const globs = frontmatterGlobs(lines.slice(1, end));
|
|
94
|
+
return {
|
|
95
|
+
globs,
|
|
96
|
+
body: lines
|
|
97
|
+
.slice(end + 1)
|
|
98
|
+
.join('\n')
|
|
99
|
+
.trim()
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** The `paths:` list a rule file declares. */
|
|
103
|
+
function frontmatterGlobs(lines) {
|
|
104
|
+
const globs = [];
|
|
105
|
+
let inPaths = false;
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
const item = /^\s*-\s+(.*)$/.exec(line);
|
|
108
|
+
if (item?.[1] !== undefined) {
|
|
109
|
+
if (inPaths)
|
|
110
|
+
globs.push(unquote(item[1]));
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const inline = /^\s*paths\s*:\s*\[(.*)\]\s*$/.exec(line);
|
|
114
|
+
if (inline?.[1] !== undefined) {
|
|
115
|
+
for (const part of inline[1].split(',')) {
|
|
116
|
+
const glob = unquote(part.trim());
|
|
117
|
+
if (glob.length > 0)
|
|
118
|
+
globs.push(glob);
|
|
119
|
+
}
|
|
120
|
+
inPaths = false;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
inPaths = /^\s*paths\s*:/.test(line);
|
|
124
|
+
}
|
|
125
|
+
return globs;
|
|
126
|
+
}
|
|
127
|
+
function unquote(value) {
|
|
128
|
+
return value.trim().replace(/^['"]|['"]$/g, '');
|
|
129
|
+
}
|
|
130
|
+
/** Whether a rule file's declared patterns cover a file. */
|
|
131
|
+
function covers(ruleFile, file) {
|
|
132
|
+
if (ruleFile.globs.length === 0)
|
|
133
|
+
return true;
|
|
134
|
+
return ruleFile.globs.some((glob) => picomatch.isMatch(file, glob, { dot: true }));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The curated rules that govern a file set.
|
|
138
|
+
*
|
|
139
|
+
* Returns the rules AND the reasons the read could not produce them, so a
|
|
140
|
+
* missing curated layer is never mistaken for "there are no curated rules".
|
|
141
|
+
*/
|
|
142
|
+
export function readCuratedRules(files, root) {
|
|
143
|
+
if (!root.ok) {
|
|
144
|
+
return { rules: [], reasons: [root.reason] };
|
|
145
|
+
}
|
|
146
|
+
const rulesDir = root.path;
|
|
147
|
+
if (!existsSync(rulesDir)) {
|
|
148
|
+
return { rules: [], reasons: [`the curated rule directory is missing: ${rulesDir}`] };
|
|
149
|
+
}
|
|
150
|
+
const reasons = [];
|
|
151
|
+
const rules = [];
|
|
152
|
+
for (const language of curatedLanguages(rulesDir, reasons)) {
|
|
153
|
+
for (const ruleFile of curatedRuleFiles(rulesDir, language, reasons)) {
|
|
154
|
+
const covered = files.filter((file) => covers(ruleFile, file));
|
|
155
|
+
if (covered.length === 0)
|
|
156
|
+
continue;
|
|
157
|
+
rules.push({
|
|
158
|
+
layer: 'curated',
|
|
159
|
+
source: `ecc:${language}`,
|
|
160
|
+
pattern: ruleFile.globs.length === 0 ? '*' : ruleFile.globs.join(', '),
|
|
161
|
+
rule: ruleFile.body
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { rules, reasons };
|
|
166
|
+
}
|
|
167
|
+
/** The curated language directories, and the ones that could not be listed. */
|
|
168
|
+
function curatedLanguages(rulesDir, reasons) {
|
|
169
|
+
try {
|
|
170
|
+
return readdirSync(rulesDir, { withFileTypes: true })
|
|
171
|
+
.filter((entry) => entry.isDirectory())
|
|
172
|
+
.map((entry) => entry.name)
|
|
173
|
+
.sort();
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
reasons.push(`the curated rule directory could not be listed: ${error instanceof Error ? error.message : String(error)}`);
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One declaration the project ships: a script, a target, a table, a CI step. */
|
|
2
|
+
export type DeclaredCommand = {
|
|
3
|
+
/**
|
|
4
|
+
* The declaration's own name — the script name, the make target, the tool
|
|
5
|
+
* table. Empty for a CI step, which has no name of its own.
|
|
6
|
+
*/
|
|
7
|
+
readonly label: string;
|
|
8
|
+
/** The command line the project declared. */
|
|
9
|
+
readonly command: string;
|
|
10
|
+
/** Where the declaration was found. */
|
|
11
|
+
readonly declaredBy: string;
|
|
12
|
+
};
|
|
13
|
+
/** What one declaration site yielded. */
|
|
14
|
+
export type DeclarationScan = {
|
|
15
|
+
readonly commands: readonly DeclaredCommand[];
|
|
16
|
+
/** Sites that could not be read — reported, never swallowed. */
|
|
17
|
+
readonly problems: readonly string[];
|
|
18
|
+
};
|
|
19
|
+
/** Every declaration the project ships, and the sites that could not be read. */
|
|
20
|
+
export type ProjectDeclarations = {
|
|
21
|
+
readonly commands: readonly DeclaredCommand[];
|
|
22
|
+
readonly problems: readonly string[];
|
|
23
|
+
/** The `package.json` scripts by name, so `pnpm lint` can be resolved. */
|
|
24
|
+
readonly scripts: ReadonlyMap<string, string>;
|
|
25
|
+
};
|
|
26
|
+
/** Every declaration the project ships. */
|
|
27
|
+
export declare function readProjectDeclarations(projectRoot: string): ProjectDeclarations;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// src/services/lint/project-lint-declarations.ts
|
|
2
|
+
//
|
|
3
|
+
// The declaration sites a project ships — the raw material for L1.
|
|
4
|
+
//
|
|
5
|
+
// A project says what its gate runs in the files it ships. This module reads
|
|
6
|
+
// those files and reports the commands they declare; it does not judge them.
|
|
7
|
+
// Judging (is this a lint tool?) belongs to the caller.
|
|
8
|
+
//
|
|
9
|
+
// THE SITES, and why each one is here:
|
|
10
|
+
// - `package.json` scripts — the most common declaration of all.
|
|
11
|
+
// - `Makefile` targets — the Unix convention.
|
|
12
|
+
// - `pyproject.toml` `[tool.*]` tables — the Python convention.
|
|
13
|
+
// - `go.mod` `tool` directives — the Go 1.24+ convention.
|
|
14
|
+
// - CI workflow steps that RUN something — the gate as it actually executes.
|
|
15
|
+
//
|
|
16
|
+
// NOTHING HERE BRANCHES ON A LANGUAGE. The sites are the same for every
|
|
17
|
+
// project; a site that a project does not ship simply yields nothing.
|
|
18
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { normalizePath } from '../../shared/path-utils.js';
|
|
21
|
+
const EMPTY_SCAN = { commands: [], problems: [] };
|
|
22
|
+
function readText(path) {
|
|
23
|
+
if (!existsSync(path))
|
|
24
|
+
return { ok: false, reason: 'not present' };
|
|
25
|
+
try {
|
|
26
|
+
return { ok: true, text: readFileSync(path, 'utf8') };
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function errorText(error) {
|
|
33
|
+
return error instanceof Error ? error.message : String(error);
|
|
34
|
+
}
|
|
35
|
+
/** The `package.json` scripts — the most common declaration site. */
|
|
36
|
+
function packageJsonSite(root) {
|
|
37
|
+
const read = readText(join(root, 'package.json'));
|
|
38
|
+
if (!read.ok)
|
|
39
|
+
return EMPTY_SCAN;
|
|
40
|
+
let parsed;
|
|
41
|
+
try {
|
|
42
|
+
parsed = JSON.parse(read.text);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return { commands: [], problems: [`package.json is not valid JSON: ${errorText(error)}`] };
|
|
46
|
+
}
|
|
47
|
+
if (parsed === null || typeof parsed !== 'object') {
|
|
48
|
+
return { commands: [], problems: ['package.json is not a JSON object'] };
|
|
49
|
+
}
|
|
50
|
+
const scripts = parsed.scripts;
|
|
51
|
+
if (scripts === null || typeof scripts !== 'object' || Array.isArray(scripts))
|
|
52
|
+
return EMPTY_SCAN;
|
|
53
|
+
const commands = [];
|
|
54
|
+
for (const [label, value] of Object.entries(scripts)) {
|
|
55
|
+
if (typeof value !== 'string')
|
|
56
|
+
continue;
|
|
57
|
+
commands.push({ label, command: value, declaredBy: `package.json scripts.${label}` });
|
|
58
|
+
}
|
|
59
|
+
return { commands, problems: [] };
|
|
60
|
+
}
|
|
61
|
+
/** The `Makefile` targets and their recipes. */
|
|
62
|
+
function makefileSite(root) {
|
|
63
|
+
const commands = [];
|
|
64
|
+
for (const fileName of ['Makefile', 'makefile']) {
|
|
65
|
+
const read = readText(join(root, fileName));
|
|
66
|
+
if (!read.ok)
|
|
67
|
+
continue;
|
|
68
|
+
readMakefileTargets(read.text, fileName, commands);
|
|
69
|
+
}
|
|
70
|
+
return { commands, problems: [] };
|
|
71
|
+
}
|
|
72
|
+
function readMakefileTargets(text, fileName, commands) {
|
|
73
|
+
let target = null;
|
|
74
|
+
let recipe = [];
|
|
75
|
+
const flush = () => {
|
|
76
|
+
if (target === null)
|
|
77
|
+
return;
|
|
78
|
+
commands.push({
|
|
79
|
+
label: target,
|
|
80
|
+
command: recipe.join(' '),
|
|
81
|
+
declaredBy: `${fileName} ${target}`
|
|
82
|
+
});
|
|
83
|
+
target = null;
|
|
84
|
+
recipe = [];
|
|
85
|
+
};
|
|
86
|
+
for (const line of text.split(/\r?\n/)) {
|
|
87
|
+
const header = /^([A-Za-z0-9_./-]+):(?!=)\s*$/.exec(line);
|
|
88
|
+
if (header?.[1] !== undefined) {
|
|
89
|
+
flush();
|
|
90
|
+
target = header[1];
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (target !== null && /^\s+\S/.test(line))
|
|
94
|
+
recipe.push(line.trim());
|
|
95
|
+
}
|
|
96
|
+
flush();
|
|
97
|
+
}
|
|
98
|
+
/** The `pyproject.toml` `[tool.*]` tables. */
|
|
99
|
+
function pyprojectSite(root) {
|
|
100
|
+
const read = readText(join(root, 'pyproject.toml'));
|
|
101
|
+
if (!read.ok)
|
|
102
|
+
return EMPTY_SCAN;
|
|
103
|
+
const commands = [];
|
|
104
|
+
for (const line of read.text.split(/\r?\n/)) {
|
|
105
|
+
const match = /^\[tool\.([A-Za-z0-9_.-]+)\]/.exec(line.trim());
|
|
106
|
+
const table = match?.[1];
|
|
107
|
+
if (table === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
const label = table.split('.')[0] ?? table;
|
|
110
|
+
commands.push({ label, command: label, declaredBy: `pyproject.toml [tool.${table}]` });
|
|
111
|
+
}
|
|
112
|
+
return { commands, problems: [] };
|
|
113
|
+
}
|
|
114
|
+
/** The `go.mod` tool directives (Go 1.24+ `tool` blocks and single directives). */
|
|
115
|
+
function goModSite(root) {
|
|
116
|
+
const read = readText(join(root, 'go.mod'));
|
|
117
|
+
if (!read.ok)
|
|
118
|
+
return EMPTY_SCAN;
|
|
119
|
+
const commands = [];
|
|
120
|
+
let inToolBlock = false;
|
|
121
|
+
for (const raw of read.text.split(/\r?\n/)) {
|
|
122
|
+
const line = raw.trim();
|
|
123
|
+
if (line.startsWith('tool (')) {
|
|
124
|
+
inToolBlock = true;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (inToolBlock) {
|
|
128
|
+
if (line === ')') {
|
|
129
|
+
inToolBlock = false;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const label = line.split(/\s+/)[0];
|
|
133
|
+
if (label !== undefined && label.length > 0)
|
|
134
|
+
commands.push(goToolCommand(label));
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const single = /^tool\s+(\S+)/.exec(line);
|
|
138
|
+
if (single?.[1] !== undefined)
|
|
139
|
+
commands.push(goToolCommand(single[1]));
|
|
140
|
+
}
|
|
141
|
+
return { commands, problems: [] };
|
|
142
|
+
}
|
|
143
|
+
function goToolCommand(pkg) {
|
|
144
|
+
const label = pkg.split('/').pop() ?? pkg;
|
|
145
|
+
return { label, command: `go tool ${label}`, declaredBy: `go.mod tool ${pkg}` };
|
|
146
|
+
}
|
|
147
|
+
/** The CI workflow steps that RUN something. */
|
|
148
|
+
function ciSite(root) {
|
|
149
|
+
const commands = [];
|
|
150
|
+
const problems = [];
|
|
151
|
+
const found = ciFiles(root);
|
|
152
|
+
problems.push(...found.problems);
|
|
153
|
+
for (const file of found.files) {
|
|
154
|
+
const read = readText(file);
|
|
155
|
+
if (!read.ok) {
|
|
156
|
+
problems.push(`${normalizePath(file.slice(root.length + 1))}: ${read.reason}`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const relative = normalizePath(file.slice(root.length + 1));
|
|
160
|
+
read.text.split(/\r?\n/).forEach((line, index) => {
|
|
161
|
+
const command = ciRunCommand(line);
|
|
162
|
+
if (command === null)
|
|
163
|
+
return;
|
|
164
|
+
commands.push({ label: '', command, declaredBy: `${relative}:${String(index + 1)}` });
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return { commands, problems };
|
|
168
|
+
}
|
|
169
|
+
/** The CI files a project ships, plus the sites that could not be listed. */
|
|
170
|
+
function ciFiles(root) {
|
|
171
|
+
const files = [];
|
|
172
|
+
const problems = [];
|
|
173
|
+
const workflowDir = join(root, '.github', 'workflows');
|
|
174
|
+
if (existsSync(workflowDir)) {
|
|
175
|
+
try {
|
|
176
|
+
for (const entry of readdirSync(workflowDir)) {
|
|
177
|
+
if (entry.endsWith('.yml') || entry.endsWith('.yaml'))
|
|
178
|
+
files.push(join(workflowDir, entry));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
problems.push(`.github/workflows: ${errorText(error)}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const gitlab = join(root, '.gitlab-ci.yml');
|
|
186
|
+
if (existsSync(gitlab))
|
|
187
|
+
files.push(gitlab);
|
|
188
|
+
return { files, problems };
|
|
189
|
+
}
|
|
190
|
+
/** The command a CI line runs, or `null` when the line runs nothing. */
|
|
191
|
+
function ciRunCommand(line) {
|
|
192
|
+
const match = /^\s*(?:-\s*)?(?:run|script):\s*(.+)$/.exec(line);
|
|
193
|
+
const raw = match?.[1];
|
|
194
|
+
if (raw === undefined)
|
|
195
|
+
return null;
|
|
196
|
+
const command = raw.trim().replace(/^['"]|['"]$/g, '');
|
|
197
|
+
if (command.length === 0 || command === '|' || command === '>-')
|
|
198
|
+
return null;
|
|
199
|
+
return command;
|
|
200
|
+
}
|
|
201
|
+
/** Every declaration the project ships. */
|
|
202
|
+
export function readProjectDeclarations(projectRoot) {
|
|
203
|
+
const packageScan = packageJsonSite(projectRoot);
|
|
204
|
+
const scripts = new Map(packageScan.commands.map((entry) => [entry.label, entry.command]));
|
|
205
|
+
const scans = [
|
|
206
|
+
packageScan,
|
|
207
|
+
makefileSite(projectRoot),
|
|
208
|
+
pyprojectSite(projectRoot),
|
|
209
|
+
goModSite(projectRoot),
|
|
210
|
+
ciSite(projectRoot)
|
|
211
|
+
];
|
|
212
|
+
return {
|
|
213
|
+
commands: scans.flatMap((scan) => scan.commands),
|
|
214
|
+
problems: scans.flatMap((scan) => scan.problems),
|
|
215
|
+
scripts
|
|
216
|
+
};
|
|
217
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProjectLintToolDetection } from './rule-pre-read-types.js';
|
|
2
|
+
/** The reason a project with no lint tooling gets. Exact, and never empty. */
|
|
3
|
+
export declare const NO_LINT_TOOL_REASON = "no lint tool declared by this project";
|
|
4
|
+
/** The tool a command line invokes, or `null` when it invokes no known tool. */
|
|
5
|
+
export declare function toolNameFromCommand(command: string, scripts: ReadonlyMap<string, string>, depth?: number): string | null;
|
|
6
|
+
/** Whether a name is a lint tool's name. */
|
|
7
|
+
export declare function isLintToolName(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The project's own lint tooling, discovered from its declaration sites.
|
|
10
|
+
*
|
|
11
|
+
* A project that declares no lint tool gets an EXPLICIT reason, never a
|
|
12
|
+
* silent empty list.
|
|
13
|
+
*/
|
|
14
|
+
export declare function detectProjectLintTools(projectRoot: string): ProjectLintToolDetection;
|