@planu/cli 5.7.11 → 5.7.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 (63) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/.planu-build.json +1 -1
  3. package/dist/cli/commands/doctor.d.ts +2 -1
  4. package/dist/cli/commands/doctor.js +51 -1
  5. package/dist/cli/commands/install.js +14 -0
  6. package/dist/cli/commands/package-handoff.js +10 -3
  7. package/dist/config/registries/strict-audit-scripts.json +4 -0
  8. package/dist/config/runtime-policy.json +2 -1
  9. package/dist/engine/abortable-process-runner.js +1 -0
  10. package/dist/engine/bump-carrier-binding.d.ts +10 -0
  11. package/dist/engine/bump-carrier-binding.js +276 -0
  12. package/dist/engine/doctor/npm-cache-check.d.ts +10 -0
  13. package/dist/engine/doctor/npm-cache-check.js +109 -0
  14. package/dist/engine/ears-gate.d.ts +1 -0
  15. package/dist/engine/ears-gate.js +64 -2
  16. package/dist/engine/framework-detector.d.ts +1 -0
  17. package/dist/engine/framework-detector.js +1 -1
  18. package/dist/engine/handoff-artifacts/schemas.d.ts +22 -0
  19. package/dist/engine/handoff-artifacts/schemas.js +13 -1
  20. package/dist/engine/runtime-policy.js +4 -0
  21. package/dist/engine/source-quality-binding.d.ts +26 -0
  22. package/dist/engine/source-quality-binding.js +162 -0
  23. package/dist/engine/source-quality-receipt-reader.d.ts +3 -0
  24. package/dist/engine/source-quality-receipt-reader.js +51 -0
  25. package/dist/engine/spec-format/bdd-parser.js +7 -4
  26. package/dist/engine/spec-format/technical-md-populator.js +114 -3
  27. package/dist/engine/spec-format/unified-spec-builder.js +33 -6
  28. package/dist/engine/spec-grounding/contract.js +3 -1
  29. package/dist/engine/spec-grounding/grounding-entry-parser.js +1 -0
  30. package/dist/engine/validator/blast-radius-gate.d.ts +3 -0
  31. package/dist/engine/validator/blast-radius-gate.js +225 -0
  32. package/dist/engine/validator/spec-compliance-runner.d.ts +2 -0
  33. package/dist/engine/validator/spec-compliance-runner.js +78 -25
  34. package/dist/engine/validator/strict-audits-gate.d.ts +3 -0
  35. package/dist/engine/validator/strict-audits-gate.js +74 -0
  36. package/dist/engine/validator/validation-report-writer.d.ts +2 -0
  37. package/dist/engine/validator/validation-report-writer.js +72 -32
  38. package/dist/storage/runtime-db.js +7 -3
  39. package/dist/storage/spec-store.js +6 -2
  40. package/dist/tools/challenge-spec/scenarios-data.js +4 -3
  41. package/dist/tools/challenge-spec/scenarios-utils.d.ts +1 -0
  42. package/dist/tools/challenge-spec/scenarios-utils.js +47 -3
  43. package/dist/tools/register-spec-tools/core-spec-tools.js +5 -0
  44. package/dist/tools/update-status/batch.js +1 -0
  45. package/dist/tools/update-status/file-sync.d.ts +1 -1
  46. package/dist/tools/update-status/file-sync.js +4 -2
  47. package/dist/tools/update-status/index.js +4 -1
  48. package/dist/tools/update-status/transition-guard.d.ts +0 -1
  49. package/dist/tools/update-status/transition-guard.js +9 -5
  50. package/dist/tools/validate-lint.js +19 -0
  51. package/dist/tools/validate.js +111 -4
  52. package/dist/types/abortable-process.d.ts +1 -0
  53. package/dist/types/handoff-artifacts.d.ts +11 -1
  54. package/dist/types/installation.d.ts +10 -0
  55. package/dist/types/runtime-policy.d.ts +1 -0
  56. package/dist/types/spec-format.d.ts +10 -0
  57. package/dist/types/spec-grounding.d.ts +1 -1
  58. package/dist/types/validation-evidence.d.ts +51 -1
  59. package/package.json +2 -2
  60. package/planu-plugin.json +1 -1
  61. package/src/i18n/messages/en.json +1 -1
  62. package/src/i18n/messages/es.json +1 -1
  63. package/src/i18n/messages/pt.json +1 -1
@@ -26,8 +26,70 @@ export function checkCopulaViolation(scenarioText) {
26
26
  function stripLeadingBullet(line) {
27
27
  return line.replace(/^-\s*(\[[ x]\]\s*)?/i, '').trim();
28
28
  }
29
+ const QUOTE_MASK_CHAR = '#';
30
+ const QUOTE_DELIMITERS = ["'", '"', '`'];
31
+ const WORD_CHARACTER = /[A-Za-z0-9]/;
32
+ function isSingleQuoteOpener(text, index) {
33
+ return index === 0 || !WORD_CHARACTER.test(text.charAt(index - 1));
34
+ }
35
+ function findClosingQuote(text, delimiter, openIndex) {
36
+ let cursor = openIndex + 1;
37
+ while (cursor < text.length) {
38
+ const candidate = text.indexOf(delimiter, cursor);
39
+ if (candidate === -1) {
40
+ return -1;
41
+ }
42
+ if (delimiter === "'" && WORD_CHARACTER.test(text.charAt(candidate + 1))) {
43
+ cursor = candidate + 1;
44
+ continue;
45
+ }
46
+ return candidate;
47
+ }
48
+ return -1;
49
+ }
50
+ export function maskQuotedSpans(text) {
51
+ let result = '';
52
+ let index = 0;
53
+ while (index < text.length) {
54
+ const char = text.charAt(index);
55
+ if (!QUOTE_DELIMITERS.includes(char)) {
56
+ result += char;
57
+ index += 1;
58
+ continue;
59
+ }
60
+ if (char === "'" && !isSingleQuoteOpener(text, index)) {
61
+ result += char;
62
+ index += 1;
63
+ continue;
64
+ }
65
+ const closeIndex = findClosingQuote(text, char, index);
66
+ if (closeIndex === -1) {
67
+ result += text.slice(index);
68
+ break;
69
+ }
70
+ const span = text.slice(index, closeIndex + 1);
71
+ result += span.replace(/\S/g, QUOTE_MASK_CHAR);
72
+ index = closeIndex + 1;
73
+ }
74
+ return result;
75
+ }
76
+ function stripVerbOutsideQuotes(text, verb) {
77
+ const masked = maskQuotedSpans(text);
78
+ const ranges = [];
79
+ for (const match of masked.matchAll(new RegExp(`\\b${verb}\\b\\s*`, 'gi'))) {
80
+ ranges.push([match.index, match.index + match[0].length]);
81
+ }
82
+ let result = '';
83
+ let cursor = 0;
84
+ for (const [start, end] of ranges) {
85
+ result += text.slice(cursor, start);
86
+ cursor = end;
87
+ }
88
+ result += text.slice(cursor);
89
+ return result.trim();
90
+ }
29
91
  function rewriteToGwt(text, vagueWord) {
30
- const withoutModal = text.replace(new RegExp(`\\b${vagueWord}\\s*`, 'gi'), '').trim();
92
+ const withoutModal = stripVerbOutsideQuotes(text, vagueWord);
31
93
  return `GIVEN <precondition> WHEN <trigger> THEN ${withoutModal}`;
32
94
  }
33
95
  /**
@@ -41,7 +103,7 @@ export function runEarsGate(criteriaLines) {
41
103
  if (line === 'bdd-scenario') {
42
104
  continue;
43
105
  }
44
- const lower = line.toLowerCase();
106
+ const lower = maskQuotedSpans(line).toLowerCase();
45
107
  const found = EARS_VAGUE_VERBS.filter((verb) => new RegExp(`\\b${verb}\\b`).test(lower));
46
108
  if (found.length === 0) {
47
109
  continue;
@@ -31,4 +31,5 @@ export declare function detectTestCommand(projectPath: string, packageManager: s
31
31
  * Detect lint command from project config files.
32
32
  */
33
33
  export declare function detectLintCommand(projectPath: string, packageManager: string | null): Promise<string | null>;
34
+ export declare function pmRunner(packageManager: string | null): string;
34
35
  //# sourceMappingURL=framework-detector.d.ts.map
@@ -253,7 +253,7 @@ export async function detectLintCommand(projectPath, packageManager) {
253
253
  }
254
254
  return null;
255
255
  }
256
- function pmRunner(packageManager) {
256
+ export function pmRunner(packageManager) {
257
257
  if (packageManager === 'pnpm') {
258
258
  return 'pnpm';
259
259
  }
@@ -116,6 +116,7 @@ export declare const ValidationReportV1Schema: z.ZodObject<{
116
116
  title: z.ZodString;
117
117
  verdict: z.ZodEnum<{
118
118
  fail: "fail";
119
+ indeterminate: "indeterminate";
119
120
  missing: "missing";
120
121
  pass: "pass";
121
122
  }>;
@@ -181,6 +182,16 @@ export declare const ValidationReportV1Schema: z.ZodObject<{
181
182
  }, z.core.$strip>>;
182
183
  score: z.ZodOptional<z.ZodNumber>;
183
184
  completedAt: z.ZodISODateTime;
185
+ blastRadius: z.ZodOptional<z.ZodObject<{
186
+ selectedFiles: z.ZodNumber;
187
+ passed: z.ZodBoolean;
188
+ timedOut: z.ZodBoolean;
189
+ skipped: z.ZodOptional<z.ZodString>;
190
+ failures: z.ZodArray<z.ZodObject<{
191
+ file: z.ZodString;
192
+ message: z.ZodString;
193
+ }, z.core.$strip>>;
194
+ }, z.core.$strip>>;
184
195
  }, z.core.$strip>;
185
196
  export declare const ReconciliationReceiptV1Schema: z.ZodType<ReconciliationReceiptV1>;
186
197
  export declare const ARTIFACT_SCHEMAS: {
@@ -274,6 +285,7 @@ export declare const ARTIFACT_SCHEMAS: {
274
285
  title: z.ZodString;
275
286
  verdict: z.ZodEnum<{
276
287
  fail: "fail";
288
+ indeterminate: "indeterminate";
277
289
  missing: "missing";
278
290
  pass: "pass";
279
291
  }>;
@@ -339,6 +351,16 @@ export declare const ARTIFACT_SCHEMAS: {
339
351
  }, z.core.$strip>>;
340
352
  score: z.ZodOptional<z.ZodNumber>;
341
353
  completedAt: z.ZodISODateTime;
354
+ blastRadius: z.ZodOptional<z.ZodObject<{
355
+ selectedFiles: z.ZodNumber;
356
+ passed: z.ZodBoolean;
357
+ timedOut: z.ZodBoolean;
358
+ skipped: z.ZodOptional<z.ZodString>;
359
+ failures: z.ZodArray<z.ZodObject<{
360
+ file: z.ZodString;
361
+ message: z.ZodString;
362
+ }, z.core.$strip>>;
363
+ }, z.core.$strip>>;
342
364
  }, z.core.$strip>;
343
365
  readonly implementation_review: z.ZodObject<{
344
366
  schema_version: z.ZodString;
@@ -88,7 +88,7 @@ export const ValidationReportV1Schema = z.object({
88
88
  command: z.string(),
89
89
  scenarios: z.array(z.object({
90
90
  title: z.string(),
91
- verdict: z.enum(['pass', 'fail', 'missing']),
91
+ verdict: z.enum(['pass', 'fail', 'missing', 'indeterminate']),
92
92
  evidence: z.array(z.string()),
93
93
  unverifiable: z.literal(true).optional(),
94
94
  })),
@@ -136,6 +136,18 @@ export const ValidationReportV1Schema = z.object({
136
136
  .optional(),
137
137
  score: z.number().optional(),
138
138
  completedAt: z.iso.datetime(),
139
+ blastRadius: z
140
+ .object({
141
+ selectedFiles: z.number(),
142
+ passed: z.boolean(),
143
+ timedOut: z.boolean(),
144
+ skipped: z.string().optional(),
145
+ failures: z.array(z.object({
146
+ file: z.string(),
147
+ message: z.string(),
148
+ })),
149
+ })
150
+ .optional(),
139
151
  });
140
152
  export const ReconciliationReceiptV1Schema = z.object({
141
153
  schema_version: z.literal('1.0.0'),
@@ -63,8 +63,12 @@ const runtimePolicySchema = z
63
63
  receiptPublicationDeadlineMs: z.number().int().positive(),
64
64
  receiptCheckpointLogMaxBytes: z.number().int().positive(),
65
65
  receiptCheckpointResultMaxBytes: z.number().int().positive(),
66
+ blastRadiusTimeoutMs: z.number().int().positive(),
66
67
  })
67
68
  .strict()
69
+ .refine((value) => value.blastRadiusTimeoutMs < value.complianceCommandTimeoutMs, {
70
+ message: 'blastRadiusTimeoutMs must be below complianceCommandTimeoutMs',
71
+ })
68
72
  .refine((value) => value.submissionLockPollMs < value.submissionLockWaitMs, {
69
73
  message: 'submissionLockPollMs must be below submissionLockWaitMs',
70
74
  })
@@ -0,0 +1,26 @@
1
+ export declare class SourceQualityBindingError extends Error {
2
+ }
3
+ export declare function runIdentity(command: string, args: string[], cwd: string): string;
4
+ export declare function sha256(value: string | Buffer): string;
5
+ export declare function assertCleanSource(projectPath: string): void;
6
+ export declare function readPolicy(projectPath: string): {
7
+ sourceQualityPlan: {
8
+ id: string;
9
+ executable: string;
10
+ args: string[];
11
+ timeoutSeconds: number;
12
+ }[];
13
+ sourceReceiptInputPatterns: string[];
14
+ };
15
+ export declare function computeBinding(projectPath: string): {
16
+ source: {
17
+ maskedTreeDigest: string;
18
+ };
19
+ inputs: {
20
+ path: string;
21
+ sha256: string;
22
+ }[];
23
+ commandPlan: ReturnType<typeof readPolicy>['sourceQualityPlan'];
24
+ toolchain: Record<string, unknown>;
25
+ };
26
+ //# sourceMappingURL=source-quality-binding.d.ts.map
@@ -0,0 +1,162 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync } from 'node:fs';
4
+ import { basename, join } from 'node:path';
5
+ import { BUMP_CARRIER_STRUCTURAL_PATHS, canonical, filterMaskedTreeEntries, isExcludedCarrierPath, isStructuralCarrierPath, normalizeCarrierBytes, } from './bump-carrier-binding.js';
6
+ export class SourceQualityBindingError extends Error {
7
+ }
8
+ const IDENTITY_PROBE_TIMEOUT_MS = 30_000;
9
+ function fail(message) {
10
+ throw new SourceQualityBindingError(message);
11
+ }
12
+ function cleanChildEnv() {
13
+ const env = { ...process.env };
14
+ delete env.NODE_OPTIONS;
15
+ delete env.NODE_PATH;
16
+ delete env.BASH_ENV;
17
+ delete env.ENV;
18
+ return env;
19
+ }
20
+ export function runIdentity(command, args, cwd) {
21
+ const result = spawnSync(command, args, {
22
+ cwd,
23
+ encoding: 'utf8',
24
+ env: cleanChildEnv(),
25
+ stdio: ['ignore', 'pipe', 'pipe'],
26
+ timeout: IDENTITY_PROBE_TIMEOUT_MS,
27
+ });
28
+ if (result.error) {
29
+ fail(`cannot identify ${basename(command)}: ${result.error.message}`);
30
+ }
31
+ if (result.signal) {
32
+ fail(`cannot identify ${basename(command)}: timed out after ${String(IDENTITY_PROBE_TIMEOUT_MS)}ms`);
33
+ }
34
+ if (result.status !== 0) {
35
+ const detail = (result.stderr || result.stdout).trim().split(/\r?\n/u)[0];
36
+ fail(`cannot identify ${basename(command)}${detail ? `: ${detail}` : ''}`);
37
+ }
38
+ return result.stdout.trim();
39
+ }
40
+ export function sha256(value) {
41
+ return createHash('sha256').update(value).digest('hex');
42
+ }
43
+ export function assertCleanSource(projectPath) {
44
+ const result = spawnSync('git', ['status', '--porcelain', '--untracked-files=normal'], {
45
+ cwd: projectPath,
46
+ encoding: 'utf8',
47
+ timeout: IDENTITY_PROBE_TIMEOUT_MS,
48
+ });
49
+ if (result.error) {
50
+ fail(`cannot check source cleanliness: ${result.error.message}`);
51
+ }
52
+ if (result.signal) {
53
+ fail(`cannot check source cleanliness: timed out after ${String(IDENTITY_PROBE_TIMEOUT_MS)}ms`);
54
+ }
55
+ if (result.status !== 0 || result.stdout.trim()) {
56
+ fail('requires a clean exact release commit');
57
+ }
58
+ }
59
+ function computeMaskedTreeDigest(projectPath) {
60
+ const entries = runIdentity('git', ['ls-tree', '-r', '-z', 'HEAD'], projectPath)
61
+ .split('\0')
62
+ .filter(Boolean);
63
+ return sha256(filterMaskedTreeEntries(entries).join('\0'));
64
+ }
65
+ function isPlanStep(value) {
66
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
67
+ return false;
68
+ }
69
+ const step = value;
70
+ return (Object.keys(step).sort().join(',') === 'args,executable,id,timeoutSeconds' &&
71
+ typeof step.id === 'string' &&
72
+ /^[a-z][a-z0-9-]*$/u.test(step.id) &&
73
+ typeof step.executable === 'string' &&
74
+ /^[A-Za-z0-9._+-]+$/u.test(step.executable) &&
75
+ Array.isArray(step.args) &&
76
+ step.args.every((argument) => typeof argument === 'string' && !argument.includes('\0')) &&
77
+ Number.isSafeInteger(step.timeoutSeconds) &&
78
+ Number(step.timeoutSeconds) > 0);
79
+ }
80
+ function isNonEmptyStringArray(value) {
81
+ return (Array.isArray(value) &&
82
+ value.length > 0 &&
83
+ value.every((entry) => typeof entry === 'string' && !!entry));
84
+ }
85
+ export function readPolicy(projectPath) {
86
+ const policyPath = join(projectPath, 'src/config/release-policy.json');
87
+ let optimization;
88
+ try {
89
+ const policy = JSON.parse(readFileSync(policyPath, 'utf8'));
90
+ optimization = policy.releaseOptimization ?? {};
91
+ }
92
+ catch {
93
+ fail('policy is missing or malformed');
94
+ }
95
+ const plan = optimization.sourceQualityPlan;
96
+ const patterns = optimization.sourceReceiptInputPatterns;
97
+ const validPlan = Array.isArray(plan) &&
98
+ plan.length > 0 &&
99
+ plan.every(isPlanStep) &&
100
+ new Set(plan.map(({ id }) => id)).size === plan.length;
101
+ if (!validPlan || !isNonEmptyStringArray(patterns)) {
102
+ fail('policy does not define one canonical structured source-gate plan');
103
+ }
104
+ const validate = plan.filter(({ executable, args }) => executable === 'pnpm' && canonical(args) === canonical(['validate']));
105
+ const strict = plan.filter(({ executable, args }) => executable === 'pnpm' && canonical(args) === canonical(['check:strict']));
106
+ if (validate.length !== 1 || strict.length !== 1) {
107
+ fail('policy must execute pnpm validate and pnpm check:strict exactly once');
108
+ }
109
+ return {
110
+ sourceQualityPlan: plan,
111
+ sourceReceiptInputPatterns: patterns,
112
+ };
113
+ }
114
+ function conciseIdentity(command, args, cwd) {
115
+ const output = runIdentity(command, args, cwd);
116
+ const lines = output.split(/\r?\n/u).filter(Boolean);
117
+ const version = lines[0] ?? '';
118
+ if (!version) {
119
+ fail(`returned an empty identity for ${basename(command)}`);
120
+ }
121
+ return { version, outputSha256: sha256(output) };
122
+ }
123
+ function collectToolchain(cwd) {
124
+ return {
125
+ node: { version: process.version, versionsSha256: sha256(canonical(process.versions)) },
126
+ npm: conciseIdentity('npm', ['--version'], cwd),
127
+ pnpm: conciseIdentity('pnpm', ['--version'], cwd),
128
+ };
129
+ }
130
+ function collectInputs(projectPath, patterns) {
131
+ let matchers;
132
+ try {
133
+ matchers = patterns.map((pattern) => new RegExp(pattern, 'u'));
134
+ }
135
+ catch {
136
+ fail('policy contains an invalid source input pattern');
137
+ }
138
+ const tracked = runIdentity('git', ['ls-files', '-z'], projectPath).split('\0').filter(Boolean);
139
+ const trackedSet = new Set(tracked);
140
+ const patternSelected = tracked.filter((path) => matchers.some((matcher) => matcher.test(path)) && !isExcludedCarrierPath(path));
141
+ const structuralSelected = BUMP_CARRIER_STRUCTURAL_PATHS.filter((path) => trackedSet.has(path));
142
+ const selected = [...new Set([...patternSelected, ...structuralSelected])].sort();
143
+ if (selected.length === 0 || !selected.includes('src/config/release-policy.json')) {
144
+ fail('input plan does not bind the release policy');
145
+ }
146
+ return selected.map((path) => {
147
+ const raw = readFileSync(join(projectPath, path));
148
+ const bytes = isStructuralCarrierPath(path) ? normalizeCarrierBytes(path, raw) : raw;
149
+ return { path, sha256: sha256(bytes) };
150
+ });
151
+ }
152
+ export function computeBinding(projectPath) {
153
+ assertCleanSource(projectPath);
154
+ const policy = readPolicy(projectPath);
155
+ return {
156
+ source: { maskedTreeDigest: computeMaskedTreeDigest(projectPath) },
157
+ inputs: collectInputs(projectPath, policy.sourceReceiptInputPatterns),
158
+ commandPlan: policy.sourceQualityPlan,
159
+ toolchain: collectToolchain(projectPath),
160
+ };
161
+ }
162
+ //# sourceMappingURL=source-quality-binding.js.map
@@ -0,0 +1,3 @@
1
+ import type { SourceQualityReceiptMatch } from '../types/index.js';
2
+ export declare function readMatchingSourceQualityReceipt(projectPath: string, command: string): SourceQualityReceiptMatch | null;
3
+ //# sourceMappingURL=source-quality-receipt-reader.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
2
+ import { isAbsolute, join } from 'node:path';
3
+ import { canonical } from './bump-carrier-binding.js';
4
+ import { computeBinding, runIdentity, sha256 } from './source-quality-binding.js';
5
+ import { VALIDATION_COMMANDS } from './validation-impact-planner.js';
6
+ function successfulResults(commandPlan) {
7
+ return commandPlan.map(({ id, executable, args }) => ({ id, executable, args, exitCode: 0 }));
8
+ }
9
+ function gitDirectory(projectPath) {
10
+ const value = runIdentity('git', ['rev-parse', '--git-dir'], projectPath);
11
+ return realpathSync(isAbsolute(value) ? value : join(projectPath, value));
12
+ }
13
+ function isCanonicalReceiptFile(path) {
14
+ return (existsSync(path) &&
15
+ !lstatSync(path).isSymbolicLink() &&
16
+ lstatSync(path).isFile() &&
17
+ realpathSync(path) === path &&
18
+ (statSync(path).mode & 0o777) === 0o600);
19
+ }
20
+ function receiptDirectoryHasReceipts(receiptDirectory) {
21
+ return (existsSync(receiptDirectory) &&
22
+ readdirSync(receiptDirectory).some((entry) => entry.endsWith('.json')));
23
+ }
24
+ export function readMatchingSourceQualityReceipt(projectPath, command) {
25
+ if (command !== VALIDATION_COMMANDS.lint) {
26
+ return null;
27
+ }
28
+ try {
29
+ const receiptDirectory = join(gitDirectory(projectPath), 'planu-release-artifacts', 'source-quality');
30
+ if (!receiptDirectoryHasReceipts(receiptDirectory)) {
31
+ return null;
32
+ }
33
+ const binding = computeBinding(projectPath);
34
+ const results = successfulResults(binding.commandPlan);
35
+ const key = sha256(canonical({ binding, results }));
36
+ const path = join(receiptDirectory, `${key}.json`);
37
+ if (!isCanonicalReceiptFile(path)) {
38
+ return null;
39
+ }
40
+ const actual = JSON.parse(readFileSync(path, 'utf8'));
41
+ const expected = { schemaVersion: 1, key, binding, results };
42
+ if (canonical(actual) !== canonical(expected)) {
43
+ return null;
44
+ }
45
+ return { key, path };
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ }
51
+ //# sourceMappingURL=source-quality-receipt-reader.js.map
@@ -41,8 +41,11 @@ function hasThenSignal(scenario) {
41
41
  function isSingleLineGivenWhenThenText(text) {
42
42
  return WHEN_WORD_RE.test(text) && THEN_WORD_RE.test(text);
43
43
  }
44
- function opensHeaderlessScenario(rawKeyword, text) {
45
- return rawKeyword === 'given' || isSingleLineGivenWhenThenText(text);
44
+ const UPPERCASE_WHEN_LINE_RE = /^WHEN\s/;
45
+ function opensHeaderlessScenario(rawKeyword, text, rawLine) {
46
+ return (rawKeyword === 'given' ||
47
+ isSingleLineGivenWhenThenText(text) ||
48
+ UPPERCASE_WHEN_LINE_RE.test(rawLine));
46
49
  }
47
50
  function suffixedTitle(thenText, steps) {
48
51
  return `${thenText} (given ${steps.find((step) => step.keyword === 'given')?.text ?? ''})`;
@@ -64,7 +67,7 @@ export function parseBddScenarios(markdown) {
64
67
  for (const raw of lines) {
65
68
  const line = raw.trim();
66
69
  // Detect scenario header
67
- const scenarioMatch = /^scenario:\s*(.+)$/i.exec(line);
70
+ const scenarioMatch = /^(?:#{1,6}\s*)?scenario(?:\s+\d+)?:\s*(.+)$/i.exec(line);
68
71
  if (scenarioMatch) {
69
72
  closeCurrent();
70
73
  current = { title: (scenarioMatch[1] ?? '').trim(), steps: [], done: false };
@@ -85,7 +88,7 @@ export function parseBddScenarios(markdown) {
85
88
  closeCurrent();
86
89
  }
87
90
  if (!current) {
88
- if (!opensHeaderlessScenario(rawKeyword, text)) {
91
+ if (!opensHeaderlessScenario(rawKeyword, text, line)) {
89
92
  continue;
90
93
  }
91
94
  current = { title: text, steps: [], done: false };
@@ -37,6 +37,115 @@ function extractPathsFromSection(sectionText) {
37
37
  }
38
38
  return paths;
39
39
  }
40
+ const LABELED_LIST_LINE_RE = /^\s*-?\s*(?:Files to (create|modify)|(Create|Modify|Test))\s*:\s*(.*)$/i;
41
+ const NONE_TOKEN_RE = /^none\.?$/i;
42
+ const TRAILING_LIST_PUNCTUATION_RE = /[.,;:]+$/;
43
+ function labeledBucketKind(labelMatch) {
44
+ const kind = (labelMatch[1] ?? labelMatch[2])?.toLowerCase();
45
+ return kind === 'create' || kind === 'modify' || kind === 'test' ? kind : null;
46
+ }
47
+ function stripLabeledListToken(token) {
48
+ return token
49
+ .replace(/\([^)]*\)/g, '')
50
+ .trim()
51
+ .replace(/^`|`$/g, '')
52
+ .trim()
53
+ .replace(TRAILING_LIST_PUNCTUATION_RE, '');
54
+ }
55
+ const LABELED_PATH_SHAPE_RE = /^[\w./-]+$/;
56
+ function isPathShapedLabelToken(token) {
57
+ return (LABELED_PATH_SHAPE_RE.test(token) && (token.includes('/') || /\.[a-zA-Z0-9]+$/.test(token)));
58
+ }
59
+ function splitLabeledList(text) {
60
+ return text
61
+ .split(',')
62
+ .map(stripLabeledListToken)
63
+ .filter((token) => token.length > 0 && !NONE_TOKEN_RE.test(token) && isPathShapedLabelToken(token));
64
+ }
65
+ function consumeLabeledBulletLines(lines, start) {
66
+ const paths = [];
67
+ let i = start;
68
+ while (i < lines.length && (lines[i] ?? '').trim().length > 0) {
69
+ const line = lines[i] ?? '';
70
+ if (LABELED_LIST_LINE_RE.test(line)) {
71
+ break;
72
+ }
73
+ const bulletMatch = /^\s*-\s*(.+)$/.exec(line);
74
+ if (!bulletMatch?.[1]) {
75
+ break;
76
+ }
77
+ paths.push(...splitLabeledList(bulletMatch[1]));
78
+ i += 1;
79
+ }
80
+ return { paths, next: i };
81
+ }
82
+ function parseLabeledFileLists(body) {
83
+ const lines = body.split('\n');
84
+ const lists = { create: [], modify: [], test: [] };
85
+ let found = false;
86
+ for (let i = 0; i < lines.length; i += 1) {
87
+ const labelMatch = LABELED_LIST_LINE_RE.exec(lines[i] ?? '');
88
+ if (!labelMatch) {
89
+ continue;
90
+ }
91
+ const kind = labeledBucketKind(labelMatch);
92
+ if (!kind || labelMatch[3] === undefined) {
93
+ continue;
94
+ }
95
+ found = true;
96
+ const inline = labelMatch[3].trim();
97
+ if (inline.length > 0) {
98
+ lists[kind].push(...splitLabeledList(inline));
99
+ continue;
100
+ }
101
+ const { paths, next } = consumeLabeledBulletLines(lines, i + 1);
102
+ lists[kind].push(...paths);
103
+ i = next - 1;
104
+ }
105
+ return found ? lists : null;
106
+ }
107
+ function buildEntriesFromLabeledLists(labeled) {
108
+ const create = [];
109
+ const modify = [];
110
+ const test = labeled.test.map((p) => ({ path: p, status: 'pending' }));
111
+ for (const p of labeled.create) {
112
+ create.push({ path: p, status: 'pending' });
113
+ if (isExecutableTestPath(p)) {
114
+ test.push({ path: p, status: 'pending' });
115
+ }
116
+ }
117
+ for (const p of labeled.modify) {
118
+ modify.push({ path: p, status: 'pending' });
119
+ if (isExecutableTestPath(p)) {
120
+ test.push({ path: p, status: 'pending' });
121
+ }
122
+ }
123
+ return { create, modify, test };
124
+ }
125
+ function dedupeByPath(entries) {
126
+ const seen = new Set();
127
+ const result = [];
128
+ for (const entry of entries) {
129
+ if (!seen.has(entry.path)) {
130
+ seen.add(entry.path);
131
+ result.push(entry);
132
+ }
133
+ }
134
+ return result;
135
+ }
136
+ function mergeStructuredAndLabeled(structured, labeled) {
137
+ if (structured === null && labeled === null) {
138
+ return null;
139
+ }
140
+ const fromLabels = labeled === null ? null : buildEntriesFromLabeledLists(labeled);
141
+ const base = structured ?? { create: [], modify: [], test: [] };
142
+ const extra = fromLabels ?? { create: [], modify: [], test: [] };
143
+ return {
144
+ create: dedupeByPath([...base.create, ...extra.create]),
145
+ modify: dedupeByPath([...base.modify, ...extra.modify]),
146
+ test: dedupeByPath([...base.test, ...extra.test]),
147
+ };
148
+ }
40
149
  function parseSectionedFileLists(body) {
41
150
  const filesRange = findMarkdownSectionRange(body, 'Files') ??
42
151
  findMarkdownSectionRange(body, 'Files likely to change');
@@ -189,9 +298,11 @@ export function extractMarkerDeclaredPaths(description) {
189
298
  */
190
299
  export async function extractFilesFromSpecBody(specBody, projectPath) {
191
300
  const structured = parseSectionedFileLists(specBody);
192
- if (structured !== null &&
193
- (structured.create.length > 0 || structured.modify.length > 0 || structured.test.length > 0)) {
194
- return structured;
301
+ const labeled = parseLabeledFileLists(specBody);
302
+ const merged = mergeStructuredAndLabeled(structured, labeled);
303
+ if (merged !== null &&
304
+ (merged.create.length > 0 || merged.modify.length > 0 || merged.test.length > 0)) {
305
+ return merged;
195
306
  }
196
307
  const candidates = [
197
308
  ...new Set(Array.from(stripFencedBlocks(specBody).matchAll(FILE_PATH_RE), (m) => m[0])),