peaks-loop 4.1.11 → 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.
Files changed (80) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +88 -0
  3. package/README-en.md +1 -1
  4. package/README.md +1 -1
  5. package/dist/cli/commands/_register.js +2 -0
  6. package/dist/cli/commands/batch-commands.d.ts +6 -0
  7. package/dist/cli/commands/batch-commands.js +70 -0
  8. package/dist/cli/commands/batch-diagnose-command.d.ts +10 -0
  9. package/dist/cli/commands/batch-diagnose-command.js +196 -0
  10. package/dist/cli/commands/batch-diagnose-envelope.d.ts +25 -0
  11. package/dist/cli/commands/batch-diagnose-envelope.js +60 -0
  12. package/dist/cli/commands/batch-diagnose-record.d.ts +21 -0
  13. package/dist/cli/commands/batch-diagnose-record.js +51 -0
  14. package/dist/cli/commands/batch-item-input.d.ts +59 -0
  15. package/dist/cli/commands/batch-item-input.js +113 -0
  16. package/dist/cli/commands/batch-report-command.d.ts +22 -0
  17. package/dist/cli/commands/batch-report-command.js +199 -0
  18. package/dist/cli/commands/core/skill-context-verdict.d.ts +16 -1
  19. package/dist/cli/commands/core/skill-context-verdict.js +38 -8
  20. package/dist/cli/commands/lint-commands.js +8 -0
  21. package/dist/cli/commands/lint-rules-command.d.ts +14 -0
  22. package/dist/cli/commands/lint-rules-command.js +44 -0
  23. package/dist/services/batch/batch-active-batch.d.ts +55 -0
  24. package/dist/services/batch/batch-active-batch.js +127 -0
  25. package/dist/services/batch/batch-context-reminder.d.ts +85 -0
  26. package/dist/services/batch/batch-context-reminder.js +201 -0
  27. package/dist/services/batch/batch-diagnosis-finding.d.ts +25 -0
  28. package/dist/services/batch/batch-diagnosis-finding.js +227 -0
  29. package/dist/services/batch/batch-diagnosis-report-store.d.ts +49 -0
  30. package/dist/services/batch/batch-diagnosis-report-store.js +133 -0
  31. package/dist/services/batch/batch-diagnosis-summary.d.ts +31 -0
  32. package/dist/services/batch/batch-diagnosis-summary.js +129 -0
  33. package/dist/services/batch/batch-diagnosis.d.ts +36 -0
  34. package/dist/services/batch/batch-diagnosis.js +107 -0
  35. package/dist/services/batch/batch-entry.d.ts +22 -0
  36. package/dist/services/batch/batch-entry.js +42 -0
  37. package/dist/services/batch/batch-fix-agent.d.ts +39 -0
  38. package/dist/services/batch/batch-fix-agent.js +126 -0
  39. package/dist/services/batch/batch-fix-types.d.ts +85 -0
  40. package/dist/services/batch/batch-fix-types.js +11 -0
  41. package/dist/services/batch/batch-fix.d.ts +15 -0
  42. package/dist/services/batch/batch-fix.js +229 -0
  43. package/dist/services/batch/batch-phase-advance.d.ts +45 -0
  44. package/dist/services/batch/batch-phase-advance.js +105 -0
  45. package/dist/services/batch/batch-progress-store.d.ts +52 -0
  46. package/dist/services/batch/batch-progress-store.js +219 -0
  47. package/dist/services/batch/batch-progress-types.d.ts +79 -0
  48. package/dist/services/batch/batch-progress-types.js +10 -0
  49. package/dist/services/batch/batch-recovery.d.ts +5 -0
  50. package/dist/services/batch/batch-recovery.js +24 -0
  51. package/dist/services/batch/batch-verify.d.ts +93 -0
  52. package/dist/services/batch/batch-verify.js +216 -0
  53. package/dist/services/code/auto-compact-decision.d.ts +17 -0
  54. package/dist/services/code/auto-compact-decision.js +6 -0
  55. package/dist/services/code/auto-compact-orchestrator.js +6 -0
  56. package/dist/services/code/batch-compaction-point.d.ts +45 -0
  57. package/dist/services/code/batch-compaction-point.js +99 -0
  58. package/dist/services/code/orchestrator-can-do-probes.d.ts +10 -0
  59. package/dist/services/code/orchestrator-can-do-probes.js +12 -2
  60. package/dist/services/context/context-schema.d.ts +1 -1
  61. package/dist/services/lint/curated-rule-reader.d.ts +37 -0
  62. package/dist/services/lint/curated-rule-reader.js +179 -0
  63. package/dist/services/lint/project-lint-declarations.d.ts +27 -0
  64. package/dist/services/lint/project-lint-declarations.js +217 -0
  65. package/dist/services/lint/project-lint-tool-detection.d.ts +14 -0
  66. package/dist/services/lint/project-lint-tool-detection.js +208 -0
  67. package/dist/services/lint/project-lint-tool-rules.d.ts +19 -0
  68. package/dist/services/lint/project-lint-tool-rules.js +199 -0
  69. package/dist/services/lint/rule-pre-read-types.d.ts +66 -0
  70. package/dist/services/lint/rule-pre-read-types.js +22 -0
  71. package/dist/services/lint/rule-pre-read.d.ts +20 -0
  72. package/dist/services/lint/rule-pre-read.js +145 -0
  73. package/dist/services/scan/archetype-service.js +24 -8
  74. package/dist/services/scan/frontend-evidence.d.ts +19 -0
  75. package/dist/services/scan/frontend-evidence.js +142 -0
  76. package/dist/services/scan/scan-types.d.ts +8 -1
  77. package/dist/services/skill/skill-search-service.d.ts +3 -3
  78. package/package.json +5 -5
  79. package/skills/peaks-code/references/micro-cycle.md +13 -1
  80. 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
+ }
@@ -10,6 +10,16 @@
10
10
  * tests import them from the same path, so the surface below must stay
11
11
  * reachable from there.
12
12
  */
13
+ /**
14
+ * Budget for the Q2 sub-agent probe. macOS CI runs this whole suite in parallel;
15
+ * there the old 5 s budget killed the probe at 5035 ms while the 10 s Q4 probe
16
+ * passed in the same run, so "slow" was reported as "unavailable". A healthy CLI
17
+ * answers in well under a second — this ceiling only bounds a hung one, so it is
18
+ * the worst case, not the expected cost.
19
+ */
20
+ export declare const SUB_AGENT_PROBE_TIMEOUT_MS = 15000;
21
+ /** Budget for the Q4 context probe. Unchanged; Q2 must stay at least this large. */
22
+ export declare const CONTEXT_RATIO_PROBE_TIMEOUT_MS = 10000;
13
23
  export interface ContextProbe {
14
24
  /** 0.0–1.0; ≥0.85 = pre-compact; ≥0.95 = red-line. */
15
25
  readonly ratio: number;
@@ -23,6 +23,16 @@ import { cliEntryPath, interpreterArgs } from '../web/daemon-supervisor.js';
23
23
  const execFileAsync = promisify(execFile);
24
24
  /** Sentinel: no explicit binary was injected, so resolve this tree's own CLI. */
25
25
  const DEFAULT_PEAKS_BIN = 'peaks';
26
+ /**
27
+ * Budget for the Q2 sub-agent probe. macOS CI runs this whole suite in parallel;
28
+ * there the old 5 s budget killed the probe at 5035 ms while the 10 s Q4 probe
29
+ * passed in the same run, so "slow" was reported as "unavailable". A healthy CLI
30
+ * answers in well under a second — this ceiling only bounds a hung one, so it is
31
+ * the worst case, not the expected cost.
32
+ */
33
+ export const SUB_AGENT_PROBE_TIMEOUT_MS = 15_000;
34
+ /** Budget for the Q4 context probe. Unchanged; Q2 must stay at least this large. */
35
+ export const CONTEXT_RATIO_PROBE_TIMEOUT_MS = 10_000;
26
36
  /**
27
37
  * Spawn argv for the peaks CLI. An explicitly injected `peaksBin` (the
28
38
  * `--peaks-bin` test seam) is spawned verbatim; the default sentinel resolves
@@ -44,7 +54,7 @@ export async function probeSubAgentAvailable(projectRoot, peaksBin = DEFAULT_PEA
44
54
  const { command, args } = peaksSpawn(peaksBin);
45
55
  await execFileAsync(command, [...args, 'sub-agent', 'dispatch', '--role', 'rd', '--help'], {
46
56
  cwd: projectRoot,
47
- timeout: 5000,
57
+ timeout: SUB_AGENT_PROBE_TIMEOUT_MS,
48
58
  windowsHide: true
49
59
  });
50
60
  return true;
@@ -63,7 +73,7 @@ export async function probeContextRatio(projectRoot, peaksBin = DEFAULT_PEAKS_BI
63
73
  const { command, args } = peaksSpawn(peaksBin);
64
74
  const { stdout } = await execFileAsync(command, [...args, 'code', 'context-now', '--project', projectRoot, '--json'], {
65
75
  cwd: projectRoot,
66
- timeout: 10000,
76
+ timeout: CONTEXT_RATIO_PROBE_TIMEOUT_MS,
67
77
  windowsHide: true
68
78
  });
69
79
  const parsed = JSON.parse(stdout);
@@ -14,8 +14,8 @@ export declare const ContextJsonSchema: z.ZodObject<{
14
14
  kind: z.ZodEnum<{
15
15
  doc: "doc";
16
16
  source: "source";
17
- config: "config";
18
17
  test: "test";
18
+ config: "config";
19
19
  }>;
20
20
  lines: z.ZodNumber;
21
21
  hash: z.ZodString;
@@ -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;