@planu/cli 5.7.12 → 5.7.14
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/CHANGELOG.md +33 -0
- package/dist/.planu-build.json +1 -1
- package/dist/cli/commands/doctor.d.ts +2 -1
- package/dist/cli/commands/doctor.js +51 -1
- package/dist/cli/commands/install.js +14 -0
- package/dist/config/negative-predicate-phrases.json +33 -0
- package/dist/config/registries/strict-audit-scripts.json +4 -0
- package/dist/engine/doctor/npm-cache-check.d.ts +10 -0
- package/dist/engine/doctor/npm-cache-check.js +109 -0
- package/dist/engine/ears-gate.d.ts +1 -0
- package/dist/engine/ears-gate.js +64 -2
- package/dist/engine/framework-detector.d.ts +1 -0
- package/dist/engine/framework-detector.js +1 -1
- package/dist/engine/handoff-artifacts/schemas.d.ts +2 -0
- package/dist/engine/handoff-artifacts/schemas.js +1 -1
- package/dist/engine/spec-format/bdd-parser.d.ts +2 -0
- package/dist/engine/spec-format/bdd-parser.js +70 -4
- package/dist/engine/spec-grounding/contract.js +3 -1
- package/dist/engine/spec-grounding/grounding-entry-parser.js +1 -0
- package/dist/engine/validator/analyzer.d.ts +0 -9
- package/dist/engine/validator/analyzer.js +33 -9
- package/dist/engine/validator/blast-radius-gate.js +181 -10
- package/dist/engine/validator/deep-code-checker.js +2 -5
- package/dist/engine/validator/negative-predicate.d.ts +18 -0
- package/dist/engine/validator/negative-predicate.js +240 -0
- package/dist/engine/validator/spec-compliance-runner.d.ts +1 -0
- package/dist/engine/validator/spec-compliance-runner.js +91 -26
- package/dist/engine/validator/strict-audits-gate.d.ts +3 -0
- package/dist/engine/validator/strict-audits-gate.js +74 -0
- package/dist/engine/validator/validation-report-writer.js +4 -2
- package/dist/storage/runtime-db.d.ts +1 -1
- package/dist/storage/runtime-db.js +15 -2
- package/dist/tools/challenge-spec/scenarios-data.js +4 -3
- package/dist/tools/challenge-spec/scenarios-utils.d.ts +1 -2
- package/dist/tools/challenge-spec/scenarios-utils.js +13 -2
- package/dist/tools/create-spec.js +10 -0
- package/dist/tools/jobs/handlers.d.ts +2 -1
- package/dist/tools/jobs/handlers.js +17 -3
- package/dist/tools/register-spec-tools/core-spec-tools.js +5 -0
- package/dist/tools/tool-registry/core-tools.js +28 -2
- package/dist/tools/update-status/batch.js +1 -0
- package/dist/tools/update-status/evidence-gate.js +13 -1
- package/dist/tools/update-status/file-sync.d.ts +1 -1
- package/dist/tools/update-status/file-sync.js +4 -2
- package/dist/tools/update-status/index.js +4 -1
- package/dist/tools/update-status/transition-guard.d.ts +0 -1
- package/dist/tools/update-status/transition-guard.js +42 -14
- package/dist/tools/validate.js +79 -2
- package/dist/types/analysis.d.ts +20 -0
- package/dist/types/errors/structured-error.d.ts +1 -1
- package/dist/types/handoff-artifacts.d.ts +1 -1
- package/dist/types/installation.d.ts +10 -0
- package/dist/types/plugin-configs.d.ts +4 -0
- package/dist/types/spec/inputs.d.ts +14 -0
- package/dist/types/spec-format.d.ts +1 -0
- package/dist/types/spec-grounding.d.ts +1 -1
- package/dist/types/validation-evidence.d.ts +32 -1
- package/package.json +2 -1
- package/planu-plugin.json +1 -1
- package/src/i18n/messages/en.json +1 -1
- package/src/i18n/messages/es.json +1 -1
- package/src/i18n/messages/pt.json +1 -1
|
@@ -49,6 +49,7 @@ async function buildBroadCache(projectPath) {
|
|
|
49
49
|
return cache;
|
|
50
50
|
}
|
|
51
51
|
import { deepCheckCriterion } from './deep-code-checker.js';
|
|
52
|
+
import { classifyNegativePredicate, checkTokensAbsent } from './negative-predicate.js';
|
|
52
53
|
import { ConfigLoader } from '../config-loader.js';
|
|
53
54
|
import { filterValidatedTestPaths, groundNumericLiteral, createProbeCache, groundAgainstDeclaredTests, findBacktickIdentifierEvidence, } from './test-evidence-grounding.js';
|
|
54
55
|
// ---------------------------------------------------------------------------
|
|
@@ -209,6 +210,30 @@ async function checkComponentMatch(criterion, projectPath, codeState, sharedFile
|
|
|
209
210
|
* buildFileContentsCache from criterion-matcher) to avoid a redundant
|
|
210
211
|
* glob+readFile pass when checking multiple criteria in the same call.
|
|
211
212
|
*/
|
|
213
|
+
async function resolveNegativePredicateEvidence(criterion, projectPath) {
|
|
214
|
+
const negative = classifyNegativePredicate(criterion);
|
|
215
|
+
if (!negative.isNegative) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const absence = await checkTokensAbsent(negative.tokens, projectPath);
|
|
219
|
+
if (absence.unverifiable) {
|
|
220
|
+
return { status: 'indeterminate', evidence: absence.evidence[0] };
|
|
221
|
+
}
|
|
222
|
+
return { status: absence.met ? 'proven' : 'missing', evidence: absence.evidence[0] };
|
|
223
|
+
}
|
|
224
|
+
async function resolveFileExistenceEvidence(criterion, projectPath) {
|
|
225
|
+
const fileMatch = /(?:create|add|implement)\s+(?:file\s+)?["']?([^\s"']+\.\w+)["']?/i.exec(criterion);
|
|
226
|
+
if (!fileMatch?.[1]) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
await stat(join(projectPath, fileMatch[1]));
|
|
231
|
+
return { status: 'proven' };
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return { status: 'missing' };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
212
237
|
export async function checkCriterionEvidence(criterion, projectPath, codeState, verifyBlock, sharedFileContents, declaredTestPaths, probeCache) {
|
|
213
238
|
// SPEC-1367 review finding 1: validate declared test paths ONCE, up front —
|
|
214
239
|
// they reach both a readFile call and a spawnSync argv further down. Every
|
|
@@ -218,17 +243,16 @@ export async function checkCriterionEvidence(criterion, projectPath, codeState,
|
|
|
218
243
|
const safeTestPaths = declaredTestPaths && declaredTestPaths.length > 0
|
|
219
244
|
? await filterValidatedTestPaths(projectPath, declaredTestPaths)
|
|
220
245
|
: [];
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
await stat(join(projectPath, fileMatch[1]));
|
|
226
|
-
return { status: 'proven' };
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
return { status: 'missing' };
|
|
246
|
+
if (!verifyBlock) {
|
|
247
|
+
const negativeResult = await resolveNegativePredicateEvidence(criterion, projectPath);
|
|
248
|
+
if (negativeResult) {
|
|
249
|
+
return negativeResult;
|
|
230
250
|
}
|
|
231
251
|
}
|
|
252
|
+
const fileExistenceResult = await resolveFileExistenceEvidence(criterion, projectPath);
|
|
253
|
+
if (fileExistenceResult) {
|
|
254
|
+
return fileExistenceResult;
|
|
255
|
+
}
|
|
232
256
|
// Check for component/function existence in code (legacy + SPEC-1367 backtick forms)
|
|
233
257
|
const componentResult = await checkComponentMatch(criterion, projectPath, codeState, sharedFileContents, safeTestPaths);
|
|
234
258
|
if (componentResult) {
|
|
@@ -2,10 +2,101 @@ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { isAbsolute, join, relative } from 'node:path';
|
|
4
4
|
import { runAbortableProcess } from '../abortable-process-runner.js';
|
|
5
|
+
import { assertLocalBuildFreshness } from '../build-freshness.js';
|
|
6
|
+
import { pmRunner } from '../framework-detector.js';
|
|
7
|
+
import { resolveProjectCommandPlan } from '../project-command-runtime.js';
|
|
5
8
|
import { technologyValue } from '../technology-registry.js';
|
|
6
9
|
const IMPORTABLE_SOURCE_PATTERN = /\.(?:ts|tsx|js|jsx|mjs|cjs)$/u;
|
|
10
|
+
const INTEGRATION_ONLY_ENV = 'PLANU_INTEGRATION_TESTS_ONLY';
|
|
11
|
+
const EXCLUDE_INTEGRATION_ENV = 'PLANU_EXCLUDE_INTEGRATION_TESTS';
|
|
12
|
+
const DIST_ROOT = 'dist';
|
|
13
|
+
const BUILD_SCRIPT_CANDIDATES = ['build:ts', 'build'];
|
|
7
14
|
function skippedResult(skipped) {
|
|
8
|
-
return {
|
|
15
|
+
return {
|
|
16
|
+
skipped,
|
|
17
|
+
selectedFiles: [],
|
|
18
|
+
passed: true,
|
|
19
|
+
timedOut: false,
|
|
20
|
+
failures: [],
|
|
21
|
+
integrationImporters: [],
|
|
22
|
+
warningReason: null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveBuildPlan(projectPath) {
|
|
26
|
+
let pkg;
|
|
27
|
+
try {
|
|
28
|
+
const raw = readFileSync(join(projectPath, 'package.json'), 'utf-8');
|
|
29
|
+
pkg = JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const scripts = pkg.scripts ?? {};
|
|
35
|
+
const script = BUILD_SCRIPT_CANDIDATES.find((candidate) => typeof scripts[candidate] === 'string');
|
|
36
|
+
if (script === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const packageManagerName = typeof pkg.packageManager === 'string' ? (pkg.packageManager.split('@')[0] ?? null) : null;
|
|
40
|
+
const runner = pmRunner(packageManagerName);
|
|
41
|
+
const plan = resolveProjectCommandPlan(projectPath, `${runner} run ${script}`);
|
|
42
|
+
return { executable: plan.executable, args: plan.args, script };
|
|
43
|
+
}
|
|
44
|
+
function staleDistFailure(selectedFiles, reason, detail) {
|
|
45
|
+
return {
|
|
46
|
+
skipped: null,
|
|
47
|
+
selectedFiles,
|
|
48
|
+
passed: false,
|
|
49
|
+
timedOut: false,
|
|
50
|
+
failures: [
|
|
51
|
+
{ file: 'dist', message: `stale-dist: ${reason}; ${detail}; run pnpm build:ts and retry` },
|
|
52
|
+
],
|
|
53
|
+
integrationImporters: [],
|
|
54
|
+
warningReason: 'stale-dist',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function ensureFreshDist(projectPath, selectedFiles, runProcess, options) {
|
|
58
|
+
const check = options.checkBuildFreshness ?? assertLocalBuildFreshness;
|
|
59
|
+
const distRoot = join(projectPath, DIST_ROOT);
|
|
60
|
+
const first = check(distRoot);
|
|
61
|
+
if (first.status !== 'stale') {
|
|
62
|
+
return { failure: null, remainingTimeoutMs: options.timeoutMs };
|
|
63
|
+
}
|
|
64
|
+
const plan = resolveBuildPlan(projectPath);
|
|
65
|
+
if (plan === null) {
|
|
66
|
+
return {
|
|
67
|
+
failure: staleDistFailure(selectedFiles, first.reason ?? 'stale build output', 'no build script found in package.json'),
|
|
68
|
+
remainingTimeoutMs: options.timeoutMs,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const startedAt = Date.now();
|
|
72
|
+
const build = await runProcess(plan.executable, plan.args, {
|
|
73
|
+
cwd: projectPath,
|
|
74
|
+
timeoutMs: options.timeoutMs,
|
|
75
|
+
maxBufferBytes: 16 * 1024 * 1024,
|
|
76
|
+
signal: options.signal,
|
|
77
|
+
env: process.env,
|
|
78
|
+
});
|
|
79
|
+
if (build.timedOut) {
|
|
80
|
+
return {
|
|
81
|
+
failure: staleDistFailure(selectedFiles, first.reason ?? 'stale build output', `${plan.script} timed out after ${options.timeoutMs} ms`),
|
|
82
|
+
remainingTimeoutMs: 0,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const second = check(distRoot);
|
|
86
|
+
const remainingTimeoutMs = Math.max(0, options.timeoutMs - (Date.now() - startedAt));
|
|
87
|
+
if (second.status === 'stale') {
|
|
88
|
+
return {
|
|
89
|
+
failure: staleDistFailure(selectedFiles, second.reason ?? 'stale build output', `${plan.script} did not refresh the build stamp`),
|
|
90
|
+
remainingTimeoutMs,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (remainingTimeoutMs === 0) {
|
|
94
|
+
return {
|
|
95
|
+
failure: staleDistFailure(selectedFiles, first.reason ?? 'stale build output', `${plan.script} consumed the ${options.timeoutMs} ms blast-radius budget`),
|
|
96
|
+
remainingTimeoutMs: 0,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return { failure: null, remainingTimeoutMs };
|
|
9
100
|
}
|
|
10
101
|
function normalizeCandidate(projectPath, file) {
|
|
11
102
|
const absolute = isAbsolute(file) ? file : join(projectPath, file);
|
|
@@ -54,6 +145,8 @@ function abortFailure(reportPath, signal, selectedFiles) {
|
|
|
54
145
|
passed: false,
|
|
55
146
|
timedOut: false,
|
|
56
147
|
failures: [{ file: reportPath, message }],
|
|
148
|
+
integrationImporters: [],
|
|
149
|
+
warningReason: null,
|
|
57
150
|
};
|
|
58
151
|
}
|
|
59
152
|
function exitStatusFailure(reportPath, status, selectedFiles) {
|
|
@@ -68,6 +161,8 @@ function exitStatusFailure(reportPath, status, selectedFiles) {
|
|
|
68
161
|
message: `vitest related exited with status ${status} without parseable failures`,
|
|
69
162
|
},
|
|
70
163
|
],
|
|
164
|
+
integrationImporters: [],
|
|
165
|
+
warningReason: null,
|
|
71
166
|
};
|
|
72
167
|
}
|
|
73
168
|
function reportFailure(reportPath, selectedFiles, error) {
|
|
@@ -80,6 +175,69 @@ function reportFailure(reportPath, selectedFiles, error) {
|
|
|
80
175
|
failures: [
|
|
81
176
|
{ file: reportPath, message: `blast radius report missing or unreadable: ${detail}` },
|
|
82
177
|
],
|
|
178
|
+
integrationImporters: [],
|
|
179
|
+
warningReason: null,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
async function runIntegrationPass(args) {
|
|
183
|
+
const budgetMs = args.options.integrationTimeoutMs ?? 0;
|
|
184
|
+
if (budgetMs <= 0) {
|
|
185
|
+
return { outcome: 'skipped' };
|
|
186
|
+
}
|
|
187
|
+
const reportDir = mkdtempSync(join(tmpdir(), 'planu-blast-radius-integration-'));
|
|
188
|
+
const reportPath = join(reportDir, 'blast-radius-integration.json');
|
|
189
|
+
try {
|
|
190
|
+
const { [EXCLUDE_INTEGRATION_ENV]: _excluded, ...envWithoutExclusion } = process.env;
|
|
191
|
+
const integrationEnv = {
|
|
192
|
+
...envWithoutExclusion,
|
|
193
|
+
[INTEGRATION_ONLY_ENV]: '1',
|
|
194
|
+
};
|
|
195
|
+
const result = await args.runProcess(args.vitestBin, [
|
|
196
|
+
'related',
|
|
197
|
+
'--run',
|
|
198
|
+
'--maxWorkers=6',
|
|
199
|
+
'--reporter=json',
|
|
200
|
+
`--outputFile.json=${reportPath}`,
|
|
201
|
+
...args.selectedFiles,
|
|
202
|
+
], {
|
|
203
|
+
cwd: args.projectPath,
|
|
204
|
+
timeoutMs: budgetMs,
|
|
205
|
+
maxBufferBytes: 64 * 1024 * 1024,
|
|
206
|
+
signal: args.options.signal,
|
|
207
|
+
env: integrationEnv,
|
|
208
|
+
});
|
|
209
|
+
if (result.timedOut || result.aborted || result.signal !== null) {
|
|
210
|
+
return { outcome: 'skipped' };
|
|
211
|
+
}
|
|
212
|
+
let report;
|
|
213
|
+
try {
|
|
214
|
+
report = JSON.parse(readFileSync(reportPath, 'utf-8'));
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return { outcome: 'skipped' };
|
|
218
|
+
}
|
|
219
|
+
const importers = [
|
|
220
|
+
...new Set((report.testResults ?? []).map((entry) => relativeReportPath(args.projectPath, entry.testFilePath ?? entry.name ?? ''))),
|
|
221
|
+
].filter((path) => path.length > 0);
|
|
222
|
+
const failures = parseVitestReport(args.projectPath, reportPath);
|
|
223
|
+
return { outcome: 'ran', importers, failures };
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
rmSync(reportDir, { recursive: true, force: true });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function buildSuccessResult(args) {
|
|
230
|
+
const integration = await runIntegrationPass(args);
|
|
231
|
+
const integrationFailures = integration.outcome === 'ran' ? integration.failures : [];
|
|
232
|
+
const allFailures = [...args.firstPassFailures, ...integrationFailures];
|
|
233
|
+
return {
|
|
234
|
+
skipped: null,
|
|
235
|
+
selectedFiles: args.selectedFiles,
|
|
236
|
+
passed: allFailures.length === 0,
|
|
237
|
+
timedOut: false,
|
|
238
|
+
failures: allFailures,
|
|
239
|
+
integrationImporters: integration.outcome === 'ran' ? integration.importers : [],
|
|
240
|
+
warningReason: integration.outcome === 'skipped' ? 'integration-importers-skipped' : null,
|
|
83
241
|
};
|
|
84
242
|
}
|
|
85
243
|
export async function runBlastRadiusGate(projectPath, candidateFiles, options) {
|
|
@@ -92,6 +250,10 @@ export async function runBlastRadiusGate(projectPath, candidateFiles, options) {
|
|
|
92
250
|
return skippedResult('vitest-not-installed');
|
|
93
251
|
}
|
|
94
252
|
const runProcess = options.runProcess ?? runAbortableProcess;
|
|
253
|
+
const preflight = await ensureFreshDist(projectPath, selectedFiles, runProcess, options);
|
|
254
|
+
if (preflight.failure !== null) {
|
|
255
|
+
return preflight.failure;
|
|
256
|
+
}
|
|
95
257
|
const reportDir = mkdtempSync(join(tmpdir(), 'planu-blast-radius-'));
|
|
96
258
|
const reportPath = join(reportDir, 'blast-radius.json');
|
|
97
259
|
try {
|
|
@@ -104,13 +266,21 @@ export async function runBlastRadiusGate(projectPath, candidateFiles, options) {
|
|
|
104
266
|
...selectedFiles,
|
|
105
267
|
], {
|
|
106
268
|
cwd: projectPath,
|
|
107
|
-
timeoutMs:
|
|
269
|
+
timeoutMs: preflight.remainingTimeoutMs,
|
|
108
270
|
maxBufferBytes: 64 * 1024 * 1024,
|
|
109
271
|
signal: options.signal,
|
|
110
|
-
env: { ...process.env,
|
|
272
|
+
env: { ...process.env, [EXCLUDE_INTEGRATION_ENV]: '1' },
|
|
111
273
|
});
|
|
112
274
|
if (result.timedOut) {
|
|
113
|
-
return {
|
|
275
|
+
return {
|
|
276
|
+
skipped: null,
|
|
277
|
+
selectedFiles,
|
|
278
|
+
passed: false,
|
|
279
|
+
timedOut: true,
|
|
280
|
+
failures: [],
|
|
281
|
+
integrationImporters: [],
|
|
282
|
+
warningReason: null,
|
|
283
|
+
};
|
|
114
284
|
}
|
|
115
285
|
if (result.aborted || result.signal !== null) {
|
|
116
286
|
return abortFailure(reportPath, result.signal, selectedFiles);
|
|
@@ -120,13 +290,14 @@ export async function runBlastRadiusGate(projectPath, candidateFiles, options) {
|
|
|
120
290
|
if (failures.length === 0 && result.status !== null && result.status !== 0) {
|
|
121
291
|
return exitStatusFailure(reportPath, result.status, selectedFiles);
|
|
122
292
|
}
|
|
123
|
-
return {
|
|
124
|
-
|
|
293
|
+
return await buildSuccessResult({
|
|
294
|
+
projectPath,
|
|
295
|
+
vitestBin,
|
|
125
296
|
selectedFiles,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
failures,
|
|
129
|
-
};
|
|
297
|
+
options,
|
|
298
|
+
runProcess,
|
|
299
|
+
firstPassFailures: failures,
|
|
300
|
+
});
|
|
130
301
|
}
|
|
131
302
|
catch (error) {
|
|
132
303
|
return reportFailure(reportPath, selectedFiles, error);
|
|
@@ -4,6 +4,7 @@ import { readFile, stat } from 'node:fs/promises';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { glob } from 'glob';
|
|
6
6
|
import { escapeRegex } from '../../core/shared/strings.js';
|
|
7
|
+
import { matchesLegacyAbsentPhrase } from './negative-predicate.js';
|
|
7
8
|
const DEFAULT_IGNORE = ['node_modules/**', 'dist/**', 'build/**', '.git/**', 'coverage/**'];
|
|
8
9
|
// ─── Numeric literal normalization (SPEC-1367) ───────────────────────────────
|
|
9
10
|
// Grounds criteria whose THEN names an explicit numeric timeout (e.g. "45_000")
|
|
@@ -39,11 +40,7 @@ export function extractNumericLiterals(text) {
|
|
|
39
40
|
export function classifyCriterion(text) {
|
|
40
41
|
const lower = text.toLowerCase();
|
|
41
42
|
// grep_absent: look for patterns that MUST NOT exist
|
|
42
|
-
if (lower
|
|
43
|
-
lower.includes('no literal') ||
|
|
44
|
-
lower.includes('no magic') ||
|
|
45
|
-
lower.includes('no raw') ||
|
|
46
|
-
lower.includes('remove all')) {
|
|
43
|
+
if (matchesLegacyAbsentPhrase(lower)) {
|
|
47
44
|
return { type: 'grep_absent', config: buildAbsentConfig(text) };
|
|
48
45
|
}
|
|
49
46
|
// SPEC-1367 review: a global numeric_timeout bucket used to live here,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TokenAbsenceResult } from '../../types/index.js';
|
|
2
|
+
export declare function loadNegativePredicatePhrases(): readonly string[];
|
|
3
|
+
export declare function matchesNegativePhrase(text: string): boolean;
|
|
4
|
+
export declare function matchesLegacyAbsentPhrase(text: string): boolean;
|
|
5
|
+
export declare function extractNegativeTokens(text: string): string[];
|
|
6
|
+
export declare function isPathShaped(token: string): boolean;
|
|
7
|
+
export declare function classifyNegativePredicate(text: string): {
|
|
8
|
+
isNegative: boolean;
|
|
9
|
+
tokens: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const NEGATIVE_TOKEN_SCOPE: readonly string[];
|
|
12
|
+
export declare const NEGATIVE_SCAN_IGNORE: readonly string[];
|
|
13
|
+
export declare const NEGATIVE_SCAN_FILE_LIMIT = 5000;
|
|
14
|
+
export declare function checkTokensAbsent(tokens: readonly string[], projectPath: string, options?: {
|
|
15
|
+
fileLimit?: number;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<TokenAbsenceResult>;
|
|
18
|
+
//# sourceMappingURL=negative-predicate.d.ts.map
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { readFile, lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ConfigLoader } from '../config-loader.js';
|
|
6
|
+
const NegativePredicatePhraseGroupSchema = z.object({
|
|
7
|
+
id: z.string().describe('Phrase group identifier (e.g. "deletion", "import-absence")'),
|
|
8
|
+
phrases: z
|
|
9
|
+
.array(z.string())
|
|
10
|
+
.describe('Lowercase phrases that mark a criterion as asserting absence'),
|
|
11
|
+
});
|
|
12
|
+
const NegativePredicatePhraseGroupArraySchema = z.array(NegativePredicatePhraseGroupSchema);
|
|
13
|
+
const loader = new ConfigLoader('negative-predicate-phrases', NegativePredicatePhraseGroupArraySchema);
|
|
14
|
+
export function loadNegativePredicatePhrases() {
|
|
15
|
+
return loader.load().flatMap((group) => group.phrases.map((phrase) => phrase.toLowerCase()));
|
|
16
|
+
}
|
|
17
|
+
export function matchesNegativePhrase(text) {
|
|
18
|
+
const lower = text.toLowerCase();
|
|
19
|
+
return loadNegativePredicatePhrases().some((phrase) => lower.includes(phrase));
|
|
20
|
+
}
|
|
21
|
+
const LEGACY_ABSENT_GROUP_ID = 'literal-absence';
|
|
22
|
+
export function matchesLegacyAbsentPhrase(text) {
|
|
23
|
+
const lower = text.toLowerCase();
|
|
24
|
+
return loader
|
|
25
|
+
.load()
|
|
26
|
+
.filter((group) => group.id === LEGACY_ABSENT_GROUP_ID)
|
|
27
|
+
.flatMap((group) => group.phrases.map((phrase) => phrase.toLowerCase()))
|
|
28
|
+
.some((phrase) => lower.includes(phrase));
|
|
29
|
+
}
|
|
30
|
+
const SLASH_JOINED_IDENTIFIER_PAIR = /^[A-Za-z_$][\w$]*(?:\/[A-Za-z_$][\w$]*)+$/;
|
|
31
|
+
const BARE_TOKEN_PATTERN = /(?:^|[\s(,])((?:@[\w.-]+\/)?[\w.@-]+(?:\/[\w.@*-]+)+)/g;
|
|
32
|
+
function normalizeToken(rawToken) {
|
|
33
|
+
return rawToken
|
|
34
|
+
.trim()
|
|
35
|
+
.replace(/[.,;:)]+$/, '')
|
|
36
|
+
.replace(/\*$/u, '');
|
|
37
|
+
}
|
|
38
|
+
function splitSlashJoinedIdentifiers(token) {
|
|
39
|
+
return SLASH_JOINED_IDENTIFIER_PAIR.test(token) ? token.split('/') : [token];
|
|
40
|
+
}
|
|
41
|
+
export function extractNegativeTokens(text) {
|
|
42
|
+
const rawTokens = [];
|
|
43
|
+
for (const match of text.matchAll(/`([^`]+)`/g)) {
|
|
44
|
+
rawTokens.push(match[1] ?? '');
|
|
45
|
+
}
|
|
46
|
+
for (const match of text.matchAll(/"([^"]+)"/g)) {
|
|
47
|
+
rawTokens.push(match[1] ?? '');
|
|
48
|
+
}
|
|
49
|
+
for (const match of text.matchAll(/'([^']+)'/g)) {
|
|
50
|
+
rawTokens.push(match[1] ?? '');
|
|
51
|
+
}
|
|
52
|
+
for (const match of text.matchAll(BARE_TOKEN_PATTERN)) {
|
|
53
|
+
rawTokens.push(match[1] ?? '');
|
|
54
|
+
}
|
|
55
|
+
const tokens = [];
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
for (const raw of rawTokens) {
|
|
58
|
+
const normalized = normalizeToken(raw);
|
|
59
|
+
for (const token of splitSlashJoinedIdentifiers(normalized)) {
|
|
60
|
+
if (token.length < 3 || seen.has(token)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
seen.add(token);
|
|
64
|
+
tokens.push(token);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return tokens;
|
|
68
|
+
}
|
|
69
|
+
export function isPathShaped(token) {
|
|
70
|
+
return (token.includes('/') &&
|
|
71
|
+
!token.includes('*') &&
|
|
72
|
+
!/\s/.test(token) &&
|
|
73
|
+
!token.includes('\\') &&
|
|
74
|
+
!token.startsWith('/') &&
|
|
75
|
+
!token.startsWith('@') &&
|
|
76
|
+
!token.split('/').includes('..'));
|
|
77
|
+
}
|
|
78
|
+
export function classifyNegativePredicate(text) {
|
|
79
|
+
const tokens = extractNegativeTokens(text);
|
|
80
|
+
return { isNegative: matchesNegativePhrase(text) && tokens.length > 0, tokens };
|
|
81
|
+
}
|
|
82
|
+
export const NEGATIVE_TOKEN_SCOPE = [
|
|
83
|
+
'src/**/*.{ts,tsx,mts,cts,js,mjs,cjs,jsx,json}',
|
|
84
|
+
'scripts/**/*.{ts,mts,cts,js,mjs,cjs,sh,json}',
|
|
85
|
+
'**/package.json',
|
|
86
|
+
'pnpm-workspace.yaml',
|
|
87
|
+
'tsconfig*.json',
|
|
88
|
+
];
|
|
89
|
+
export const NEGATIVE_SCAN_IGNORE = [
|
|
90
|
+
'**/node_modules/**',
|
|
91
|
+
'**/dist/**',
|
|
92
|
+
'**/build/**',
|
|
93
|
+
'**/coverage/**',
|
|
94
|
+
'**/.vitepress/cache/**',
|
|
95
|
+
'.git/**',
|
|
96
|
+
'planu/**',
|
|
97
|
+
'.planu/**',
|
|
98
|
+
'.worktrees/**',
|
|
99
|
+
];
|
|
100
|
+
export const NEGATIVE_SCAN_FILE_LIMIT = 5000;
|
|
101
|
+
function isOutside(root, candidate) {
|
|
102
|
+
const pathFromRoot = relative(root, candidate);
|
|
103
|
+
return pathFromRoot === '..' || pathFromRoot.startsWith(`..${sep}`) || isAbsolute(pathFromRoot);
|
|
104
|
+
}
|
|
105
|
+
async function projectEntryExists(projectPath, token) {
|
|
106
|
+
const candidate = join(projectPath, token);
|
|
107
|
+
try {
|
|
108
|
+
await lstat(candidate);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
const code = err.code;
|
|
112
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') {
|
|
113
|
+
return { status: 'absent' };
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
status: 'unverifiable',
|
|
117
|
+
evidence: `scan-unreadable: ${token} could not be stat'd — absence cannot be verified`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const [rootReal, parentReal] = await Promise.all([
|
|
122
|
+
realpath(projectPath),
|
|
123
|
+
realpath(dirname(candidate)),
|
|
124
|
+
]);
|
|
125
|
+
if (isOutside(rootReal, parentReal)) {
|
|
126
|
+
return {
|
|
127
|
+
status: 'unverifiable',
|
|
128
|
+
evidence: `scan-escaped: ${token} resolves outside the project — absence cannot be verified`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { status: 'present' };
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return {
|
|
135
|
+
status: 'unverifiable',
|
|
136
|
+
evidence: `scan-unreadable: ${token} could not be resolved — absence cannot be verified`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function scanContentHits(files, tokens, projectPath, signal) {
|
|
141
|
+
const contentHits = [];
|
|
142
|
+
for (const relPath of files) {
|
|
143
|
+
signal?.throwIfAborted();
|
|
144
|
+
let content;
|
|
145
|
+
try {
|
|
146
|
+
content = await readFile(join(projectPath, relPath), 'utf-8');
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
result: {
|
|
152
|
+
met: false,
|
|
153
|
+
unverifiable: true,
|
|
154
|
+
evidence: [`scan-unreadable: ${relPath} could not be read — absence cannot be verified`],
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
for (const token of tokens) {
|
|
159
|
+
const index = content.indexOf(token);
|
|
160
|
+
if (index !== -1) {
|
|
161
|
+
const line = content.slice(0, index).split('\n').length;
|
|
162
|
+
contentHits.push(`\`${token}\`: still present at ${relPath}:${line}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { ok: true, hits: contentHits };
|
|
167
|
+
}
|
|
168
|
+
async function scanPathHits(tokens, projectPath) {
|
|
169
|
+
const pathHits = [];
|
|
170
|
+
for (const token of tokens) {
|
|
171
|
+
if (!isPathShaped(token)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const entry = await projectEntryExists(projectPath, token);
|
|
175
|
+
if (entry.status === 'unverifiable') {
|
|
176
|
+
return {
|
|
177
|
+
ok: false,
|
|
178
|
+
result: { met: false, unverifiable: true, evidence: [entry.evidence] },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (entry.status === 'present') {
|
|
182
|
+
pathHits.push(`\`${token}\`: still present as project entry ${token}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { ok: true, hits: pathHits };
|
|
186
|
+
}
|
|
187
|
+
export async function checkTokensAbsent(tokens, projectPath, options) {
|
|
188
|
+
if (tokens.length === 0) {
|
|
189
|
+
return {
|
|
190
|
+
met: false,
|
|
191
|
+
unverifiable: true,
|
|
192
|
+
evidence: ['no tokens extracted — absence cannot be verified'],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const fileLimit = options?.fileLimit ?? NEGATIVE_SCAN_FILE_LIMIT;
|
|
196
|
+
let files;
|
|
197
|
+
try {
|
|
198
|
+
files = await glob([...NEGATIVE_TOKEN_SCOPE], {
|
|
199
|
+
cwd: projectPath,
|
|
200
|
+
nodir: true,
|
|
201
|
+
ignore: [...NEGATIVE_SCAN_IGNORE],
|
|
202
|
+
signal: options?.signal,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return {
|
|
207
|
+
met: false,
|
|
208
|
+
unverifiable: true,
|
|
209
|
+
evidence: [
|
|
210
|
+
'scan-error: glob failed over the negative-token scope — absence cannot be verified',
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (files.length > fileLimit) {
|
|
215
|
+
return {
|
|
216
|
+
met: false,
|
|
217
|
+
unverifiable: true,
|
|
218
|
+
evidence: [
|
|
219
|
+
`scan-truncated: ${files.length} files exceed the ${fileLimit}-file scan limit — absence cannot be verified`,
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const contentScan = await scanContentHits(files, tokens, projectPath, options?.signal);
|
|
224
|
+
if (!contentScan.ok) {
|
|
225
|
+
return contentScan.result;
|
|
226
|
+
}
|
|
227
|
+
const pathScan = await scanPathHits(tokens, projectPath);
|
|
228
|
+
if (!pathScan.ok) {
|
|
229
|
+
return pathScan.result;
|
|
230
|
+
}
|
|
231
|
+
const hits = [...contentScan.hits, ...pathScan.hits];
|
|
232
|
+
const met = hits.length === 0;
|
|
233
|
+
const evidence = met
|
|
234
|
+
? tokens.map((token) => isPathShaped(token)
|
|
235
|
+
? `\`${token}\`: absent — 0 matches in ${files.length} scanned files, and no project entry`
|
|
236
|
+
: `\`${token}\`: absent — 0 matches in ${files.length} scanned files`)
|
|
237
|
+
: hits;
|
|
238
|
+
return { met, unverifiable: false, evidence };
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=negative-predicate.js.map
|
|
@@ -6,6 +6,7 @@ export declare class ComplianceCommandTerminalError extends Error {
|
|
|
6
6
|
constructor(code: string);
|
|
7
7
|
}
|
|
8
8
|
export declare function parseFrontmatterScenarios(raw: string): FrontmatterScenario[];
|
|
9
|
+
export declare function parseJsonOutput(stdout: string): unknown;
|
|
9
10
|
export declare function runSpecCompliance(spec: Spec, projectPath: string, signal?: AbortSignal, canonicalProjectId?: string): Promise<SpecComplianceResult>;
|
|
10
11
|
export declare function findScenariosWithoutTests(raw: string): string[];
|
|
11
12
|
export declare function collectDeclaredSpecFiles(raw: string): string[];
|