@gobing-ai/spur 0.3.92 → 0.3.93
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 +1 -1
- package/config/pipeline-budgets.json +0 -7
- package/config/plugin-scripts.json +10 -0
- package/config/templates/AGENTS.md +4 -0
- package/config/templates/docs/02_ROADMAP.md +2 -0
- package/config/templates/docs/03_ARCHITECTURE.md +3 -1
- package/config/templates/docs/04_DESIGN.md +2 -0
- package/config/templates/docs/99_PROJECT_CONSTITUTION.md +10 -2
- package/config/workflow-candidates.json +72 -1
- package/config/workflows/feature-verification.yaml +1 -0
- package/config/workflows/history-anatomy.yaml +2 -0
- package/config/workflows/idea-pipeline.yaml +67 -18
- package/config/workflows/pr-review.yaml +8 -0
- package/config/workflows/task-pipeline.yaml +180 -39
- package/config/workflows/wayfinder-resolution.yaml +5 -0
- package/config/workflows/wrapup-pipeline.yaml +55 -14
- package/package.json +9 -9
- package/plugins/sp/README.md +7 -2
- package/plugins/sp/commands/dev-run.md +2 -2
- package/plugins/sp/commands/dev-runall.md +2 -2
- package/plugins/sp/lib/idea-handoff.generated.mjs +8 -4
- package/plugins/sp/lib/inline-run.generated.d.mts +1 -0
- package/plugins/sp/lib/inline-run.generated.mjs +24 -16
- package/plugins/sp/plugin.json +1 -1
- package/plugins/sp/scripts/inline-pipeline-parity-check.ts +1 -1
- package/plugins/sp/scripts/inline-run-setup.mjs +75 -3
- package/plugins/sp/scripts/inline-run-setup.ts +133 -3
- package/plugins/sp/scripts/quality-gate.mjs +248 -6
- package/plugins/sp/scripts/quality-gate.ts +410 -9
- package/plugins/sp/scripts/residual-scan.mjs +12 -4
- package/plugins/sp/scripts/residual-scan.ts +32 -6
- package/plugins/sp/scripts/task-diffstat.mjs +156 -0
- package/plugins/sp/scripts/task-diffstat.ts +229 -0
- package/plugins/sp/scripts/wrapup-drift-probe.mjs +181 -0
- package/plugins/sp/scripts/wrapup-drift-probe.ts +258 -0
- package/plugins/sp/scripts/wrapup-steps.mjs +60 -1
- package/plugins/sp/scripts/wrapup-steps.ts +89 -4
- package/plugins/sp/skills/brainstorm/SKILL.md +2 -0
- package/plugins/sp/skills/brainstorm/references/workflows.md +17 -2
- package/plugins/sp/skills/code-verification/SKILL.md +2 -2
- package/plugins/sp/skills/code-verification/references/secu-review.md +3 -2
- package/plugins/sp/skills/spur-check/SKILL.md +112 -0
- package/plugins/sp/skills/spur-dev/SKILL.md +2 -1
- package/plugins/sp/skills/spur-dev/references/cross-cutting.md +14 -2
- package/plugins/sp/skills/spur-dev/references/document-authoring.md +85 -0
- package/plugins/sp/skills/spur-dev/references/execution-batch.md +1 -1
- package/plugins/sp/skills/spur-dev/references/flag-glossary.md +8 -0
- package/plugins/sp/skills/spur-dev/references/gate-checklists.md +3 -2
- package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +19 -1
- package/plugins/sp/skills/spur-dev/references/planning-workflow.md +5 -5
- package/plugins/sp/skills/spur-dev/templates/design.md +31 -0
- package/plugins/sp/skills/spur-dev/templates/plan.md +32 -0
- package/plugins/sp/skills/spur-doctor/SKILL.md +60 -14
- package/schemas/state-machine-workflow.schema.json +4 -0
- package/spur.js +1117 -472
- package/config/workflows/decision-routing-example.yaml +0 -134
|
@@ -13,14 +13,36 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Modes:
|
|
15
15
|
* run reset the attempt counter, truncate the log, execute the gate loop
|
|
16
|
-
* recheck truncate the log
|
|
17
|
-
*
|
|
16
|
+
* recheck truncate the log; a full-tier FAIL receipt at the current digest is a
|
|
17
|
+
* no-progress skip straight to the FAIL write (0940 R2), otherwise the probe
|
|
18
|
+
* runs first (probe failure is the gate failure, the gate loop is skipped),
|
|
19
|
+
* then the gate loop
|
|
20
|
+
* light changed-scope tier (task 0939, ADR-124): biome on the changed files,
|
|
21
|
+
* per-workspace typecheck, and filename-mapped related tests run inside
|
|
22
|
+
* their workspace; merges rows under `tier: light`, soft-fails
|
|
23
|
+
* status print `{reuse, reason}` for the task's receipt and exit 0
|
|
18
24
|
*
|
|
19
25
|
* Retry contract: a failed attempt is retried (up to 5 total attempts) only when its
|
|
20
26
|
* output matches a SQLite busy/locked error; the delay defaults to 10 seconds and is
|
|
21
27
|
* overridable via `SPUR_QUALITY_GATE_RETRY_DELAY_MS` (tests).
|
|
22
28
|
*
|
|
23
|
-
*
|
|
29
|
+
* Check receipts (task 0939, ADR-124): `run` writes `.spur/run/<wbs>-check-receipt.json`
|
|
30
|
+
* (`check-receipt/v1`) when `proofDigest` is set; without a digest no receipt is written and the
|
|
31
|
+
* log says why. The gate executes `qualityGateCmd` as one unit, so the full-tier receipt carries
|
|
32
|
+
* a single `test` row for the whole `bun run spur-check` chain (lint | typecheck | test-pre-check
|
|
33
|
+
* | test | test-post-check). `light` accumulates: a sub-check already PASS in a light receipt at
|
|
34
|
+
* the same `{id, inputDigest}` is skipped, and light rows never make a receipt reusable for
|
|
35
|
+
* review — `status` reuses only `PASS` + `tier: full` + matching digest. Reuse observability
|
|
36
|
+
* (0940 R3): `status` reuse and light accumulation emit `check.reused`, and the no-progress
|
|
37
|
+
* recheck emits `check.skipped-no-progress`, in the gate log and on stdout (the action result
|
|
38
|
+
* `data`); both surfaces run this same script, so there is no surface branch.
|
|
39
|
+
*
|
|
40
|
+
* Standalone contract: the digest is consumed, never computed — the pipeline captures it with
|
|
41
|
+
* `proof.fingerprint` into `env.proofDigest`; standalone callers use
|
|
42
|
+
* `inline-run-setup.ts --fingerprint`. No `@gobing-ai/*` value imports.
|
|
43
|
+
*
|
|
44
|
+
* Environment: `wbs` (required), `qualityGateCmd`, `gateProbeCmd` (recheck), `proofDigest`,
|
|
45
|
+
* `runId` (receipt identity; falls back to `pipeline-<wbs>`).
|
|
24
46
|
* Soft-fail contract: the process always exits 0; the verdict lives in the status file.
|
|
25
47
|
*
|
|
26
48
|
* Node-builtin imports only; pure helpers are exported for unit testing (ADR-065).
|
|
@@ -65,6 +87,8 @@ export interface QualityGateEnv {
|
|
|
65
87
|
qualityGateCmd?: string;
|
|
66
88
|
gateProbeCmd?: string;
|
|
67
89
|
proofDigest?: string;
|
|
90
|
+
/** Receipt run identity; `pipeline-<wbs>` when absent (task-pipeline convention). */
|
|
91
|
+
runId?: string;
|
|
68
92
|
[key: string]: string | undefined;
|
|
69
93
|
}
|
|
70
94
|
|
|
@@ -80,6 +104,8 @@ export interface QualityGateResult {
|
|
|
80
104
|
findingsFile: string;
|
|
81
105
|
statusFile: string;
|
|
82
106
|
attemptFile: string;
|
|
107
|
+
/** Written only by `run` with `proofDigest` set (0939 R2). */
|
|
108
|
+
receiptFile?: string;
|
|
83
109
|
}
|
|
84
110
|
|
|
85
111
|
export function isTransientLock(attemptOutput: string): boolean {
|
|
@@ -156,6 +182,323 @@ export function scanCoverageShortfalls(logText: string, threshold: CoverageThres
|
|
|
156
182
|
return [...shortfalls.values()];
|
|
157
183
|
}
|
|
158
184
|
|
|
185
|
+
// ─── Check receipts + light tier (task 0939, ADR-124) ───
|
|
186
|
+
|
|
187
|
+
export const RECEIPT_SCHEMA_VERSION = 'check-receipt/v1';
|
|
188
|
+
|
|
189
|
+
export type ReceiptTier = 'full' | 'light';
|
|
190
|
+
export type CheckStatus = 'PASS' | 'FAIL';
|
|
191
|
+
/** Frozen non-reuse reasons of `status` mode (0939 R3). */
|
|
192
|
+
export type ReceiptReuseReason = 'missing' | 'failed' | 'stale' | 'light-only';
|
|
193
|
+
|
|
194
|
+
export interface CheckReceiptRow {
|
|
195
|
+
id: string;
|
|
196
|
+
cmd: string;
|
|
197
|
+
status: CheckStatus;
|
|
198
|
+
durationMs: number;
|
|
199
|
+
logPath: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface CheckReceipt {
|
|
203
|
+
schemaVersion: 'check-receipt/v1';
|
|
204
|
+
wbs: string;
|
|
205
|
+
runId: string;
|
|
206
|
+
tier: ReceiptTier;
|
|
207
|
+
inputDigest: string;
|
|
208
|
+
checks: CheckReceiptRow[];
|
|
209
|
+
status: CheckStatus;
|
|
210
|
+
completedAt: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface ReceiptReadStatus {
|
|
214
|
+
reuse: boolean;
|
|
215
|
+
/** `'ok'` only when reuse holds; otherwise one of the frozen reasons. */
|
|
216
|
+
reason: ReceiptReuseReason | 'ok';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface BuildReceiptInput {
|
|
220
|
+
wbs: string;
|
|
221
|
+
runId: string;
|
|
222
|
+
tier: ReceiptTier;
|
|
223
|
+
inputDigest: string;
|
|
224
|
+
checks: CheckReceiptRow[];
|
|
225
|
+
/** ISO-8601 completion timestamp; injected so receipts stay reproducible in tests. */
|
|
226
|
+
completedAt: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Stamp `check-receipt/v1`; the overall status derives from the rows (no rows → PASS). */
|
|
230
|
+
export function buildReceipt(input: BuildReceiptInput): CheckReceipt {
|
|
231
|
+
return {
|
|
232
|
+
schemaVersion: RECEIPT_SCHEMA_VERSION,
|
|
233
|
+
wbs: input.wbs,
|
|
234
|
+
runId: input.runId,
|
|
235
|
+
tier: input.tier,
|
|
236
|
+
inputDigest: input.inputDigest,
|
|
237
|
+
checks: input.checks,
|
|
238
|
+
status: input.checks.every((row) => row.status === 'PASS') ? 'PASS' : 'FAIL',
|
|
239
|
+
completedAt: input.completedAt,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Parse a check receipt; `null` when absent, unreadable, or corrupt. */
|
|
244
|
+
function readReceipt(receiptPath: string): CheckReceipt | null {
|
|
245
|
+
try {
|
|
246
|
+
return JSON.parse(readFileSync(receiptPath, 'utf8')) as CheckReceipt;
|
|
247
|
+
} catch {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 0940 R2 — no-progress recheck shape: a full-tier FAIL receipt bound to the current proof-input
|
|
254
|
+
* digest, i.e. the fix pass changed nothing tracked and the full chain can only reproduce the
|
|
255
|
+
* failure. `readReceiptStatus` cannot express this decision (a FAIL receipt is `reason: 'failed'`
|
|
256
|
+
* at every digest), so the two fields are compared directly. Light-tier receipts and any digest
|
|
257
|
+
* mismatch never skip — the probe and full gate run unchanged (anti-pattern: reusing a light
|
|
258
|
+
* receipt, or comparing against a digest captured before `test-fix`).
|
|
259
|
+
*/
|
|
260
|
+
export function receiptFailsAtDigest(receipt: CheckReceipt | null, currentDigest: string): boolean {
|
|
261
|
+
return (
|
|
262
|
+
receipt !== null &&
|
|
263
|
+
receipt.schemaVersion === RECEIPT_SCHEMA_VERSION &&
|
|
264
|
+
receipt.tier === 'full' &&
|
|
265
|
+
receipt.status === 'FAIL' &&
|
|
266
|
+
currentDigest.length > 0 &&
|
|
267
|
+
receipt.inputDigest === currentDigest
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Reuse verdict for `.spur/run/<wbs>-check-receipt.json` against the current proof-input digest.
|
|
273
|
+
* Evaluated missing → failed → stale → light-only; reuse requires `PASS` + `tier: full` + digest
|
|
274
|
+
* match, so light rows can never flip a receipt reusable (0939 invariant).
|
|
275
|
+
*/
|
|
276
|
+
export function readReceiptStatus(receiptPath: string, currentDigest: string): ReceiptReadStatus {
|
|
277
|
+
const receipt = readReceipt(receiptPath);
|
|
278
|
+
if (receipt === null || receipt.schemaVersion !== RECEIPT_SCHEMA_VERSION) {
|
|
279
|
+
return { reuse: false, reason: 'missing' };
|
|
280
|
+
}
|
|
281
|
+
if (receipt.status !== 'PASS') return { reuse: false, reason: 'failed' };
|
|
282
|
+
if (currentDigest.length === 0 || receipt.inputDigest !== currentDigest) {
|
|
283
|
+
return { reuse: false, reason: 'stale' };
|
|
284
|
+
}
|
|
285
|
+
if (receipt.tier !== 'full') return { reuse: false, reason: 'light-only' };
|
|
286
|
+
return { reuse: true, reason: 'ok' };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const TEST_FILE_PATTERN = /\.test\.tsx?$/;
|
|
290
|
+
|
|
291
|
+
export interface LightScope {
|
|
292
|
+
files: string[];
|
|
293
|
+
workspaces: string[];
|
|
294
|
+
tests: string[];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The bun workspace a changed file belongs to: the shortest directory prefix below the repo root
|
|
299
|
+
* that holds a package.json (`apps/*`, `packages/*`). Null for root-level files, which no
|
|
300
|
+
* workspace owns. Pure via the injected `exists` predicate.
|
|
301
|
+
*/
|
|
302
|
+
function workspaceOf(file: string, exists: (p: string) => boolean): string | null {
|
|
303
|
+
const segments = file.split('/');
|
|
304
|
+
for (let depth = 1; depth < segments.length; depth++) {
|
|
305
|
+
const prefix = segments.slice(0, depth).join('/');
|
|
306
|
+
if (exists(`${prefix}/package.json`)) return prefix;
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Light-tier scope from changed repo-relative paths: every touched workspace plus the related
|
|
313
|
+
* tests. `<ws>/src/**x.ts` maps to `<ws>/tests/**x.test.ts` by filename (refine decision —
|
|
314
|
+
* deterministic and cheap; the import graph is not consulted), and a changed `*.test.ts` under a
|
|
315
|
+
* workspace includes itself. The full tier stays the safety net for everything the mapping
|
|
316
|
+
* misses. Unmapped-but-existing candidates are dropped by the `exists` check.
|
|
317
|
+
*/
|
|
318
|
+
export function lightScope(changedFiles: string[], exists: (p: string) => boolean = existsSync): LightScope {
|
|
319
|
+
const files: string[] = [];
|
|
320
|
+
const workspaces = new Set<string>();
|
|
321
|
+
const tests = new Set<string>();
|
|
322
|
+
for (const file of changedFiles) {
|
|
323
|
+
files.push(file);
|
|
324
|
+
const workspace = workspaceOf(file, exists);
|
|
325
|
+
if (workspace === null) continue;
|
|
326
|
+
workspaces.add(workspace);
|
|
327
|
+
const rest = file.slice(workspace.length + 1);
|
|
328
|
+
if (rest.startsWith('src/')) {
|
|
329
|
+
const candidate = `${workspace}/tests/${rest.slice('src/'.length).replace(/\.tsx?$/, (ext) => `.test${ext}`)}`;
|
|
330
|
+
if (exists(candidate)) tests.add(candidate);
|
|
331
|
+
} else if (rest.startsWith('tests/') && TEST_FILE_PATTERN.test(rest)) {
|
|
332
|
+
tests.add(file);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return { files, workspaces: [...workspaces].sort(), tests: [...tests].sort() };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface LightCheckPlan {
|
|
339
|
+
id: string;
|
|
340
|
+
cmd: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Does the workspace package.json declare a `typecheck` script? (fs default; tests inject.) */
|
|
344
|
+
export function workspaceHasTypecheck(workspace: string): boolean {
|
|
345
|
+
try {
|
|
346
|
+
const pkg = JSON.parse(readFileSync(join(workspace, 'package.json'), 'utf8')) as {
|
|
347
|
+
scripts?: { typecheck?: string };
|
|
348
|
+
};
|
|
349
|
+
return typeof pkg.scripts?.typecheck === 'string';
|
|
350
|
+
} catch {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The light sub-checks for a scope, in run order: `format-lint:changed` (biome, repo root),
|
|
357
|
+
* `typecheck:<ws>` per workspace declaring the script, `test:<ws>` per workspace with related
|
|
358
|
+
* tests. Tests always run through `cd <ws> &&` — never from the repo root, whose bunfig preload
|
|
359
|
+
* does not apply inside the workspace.
|
|
360
|
+
*/
|
|
361
|
+
export function planLightChecks(
|
|
362
|
+
scope: LightScope,
|
|
363
|
+
hasTypecheck: (workspace: string) => boolean = workspaceHasTypecheck,
|
|
364
|
+
): LightCheckPlan[] {
|
|
365
|
+
const plans: LightCheckPlan[] = [];
|
|
366
|
+
if (scope.files.length > 0) {
|
|
367
|
+
plans.push({ id: 'format-lint:changed', cmd: `bunx biome check ${scope.files.join(' ')}` });
|
|
368
|
+
}
|
|
369
|
+
for (const workspace of scope.workspaces) {
|
|
370
|
+
if (hasTypecheck(workspace)) {
|
|
371
|
+
plans.push({ id: `typecheck:${workspace}`, cmd: `cd ${workspace} && bun run typecheck` });
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const testsByWorkspace = new Map<string, string[]>();
|
|
375
|
+
for (const test of scope.tests) {
|
|
376
|
+
const workspace = test.slice(0, test.indexOf('/tests/'));
|
|
377
|
+
const paths = testsByWorkspace.get(workspace) ?? [];
|
|
378
|
+
paths.push(test.slice(workspace.length + 1));
|
|
379
|
+
testsByWorkspace.set(workspace, paths);
|
|
380
|
+
}
|
|
381
|
+
for (const [workspace, paths] of testsByWorkspace) {
|
|
382
|
+
plans.push({ id: `test:${workspace}`, cmd: `cd ${workspace} && bun test ${paths.join(' ')}` });
|
|
383
|
+
}
|
|
384
|
+
return plans;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Changed paths for the light tier: `git diff --name-only HEAD` plus untracked; existing only. */
|
|
388
|
+
function gitChangedFiles(cwd: string | undefined): string[] {
|
|
389
|
+
const abs = (p: string): string => (cwd ? join(cwd, p) : p);
|
|
390
|
+
const changed = new Set<string>();
|
|
391
|
+
for (const cmd of ['git diff --name-only HEAD', 'git ls-files --others --exclude-standard']) {
|
|
392
|
+
const result = runShellCommand(cmd, cwd);
|
|
393
|
+
for (const line of result.output.split('\n')) {
|
|
394
|
+
const file = line.trim();
|
|
395
|
+
if (file.length > 0 && existsSync(abs(file))) changed.add(file);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return [...changed].sort();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function receiptRunId(env: QualityGateEnv): string {
|
|
402
|
+
return (env.runId ?? '').length > 0 ? (env.runId as string) : `pipeline-${env.wbs}`;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export interface LightGateResult {
|
|
406
|
+
status: CheckStatus;
|
|
407
|
+
scope: LightScope;
|
|
408
|
+
checks: CheckReceiptRow[];
|
|
409
|
+
logFile: string;
|
|
410
|
+
receiptFile: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Light tier (0939 R1): run the planned sub-checks, merge their rows into the receipt under
|
|
415
|
+
* `tier: light`, exit soft. A sub-check already PASS in a light receipt at the same
|
|
416
|
+
* `{id, inputDigest}` is skipped (accumulation, AC1); prior rows whose id left the plan are
|
|
417
|
+
* dropped with the rest of the old receipt.
|
|
418
|
+
*/
|
|
419
|
+
export function runLightGate(env: QualityGateEnv, options: QualityGateOptions = {}): LightGateResult {
|
|
420
|
+
const cwd = options.cwd;
|
|
421
|
+
const abs = (p: string): string => (cwd ? join(cwd, p) : p);
|
|
422
|
+
const runDir = join('.spur', 'run');
|
|
423
|
+
mkdirSync(abs(runDir), { recursive: true });
|
|
424
|
+
const logFile = join(runDir, `${env.wbs}-light-gate.log`);
|
|
425
|
+
const receiptFile = join(runDir, `${env.wbs}-check-receipt.json`);
|
|
426
|
+
writeFileSync(abs(logFile), '');
|
|
427
|
+
|
|
428
|
+
const digest = env.proofDigest ?? '';
|
|
429
|
+
const scope = lightScope(gitChangedFiles(cwd), (p) => existsSync(abs(p)));
|
|
430
|
+
// Bind the fs predicates to the gate cwd, not the process cwd (tests run gates in fixtures).
|
|
431
|
+
const plans = planLightChecks(scope, (workspace) => workspaceHasTypecheck(abs(workspace)));
|
|
432
|
+
|
|
433
|
+
const reusable = new Map<string, CheckReceiptRow>();
|
|
434
|
+
let preserveFullReceipt = false;
|
|
435
|
+
if (digest.length > 0) {
|
|
436
|
+
try {
|
|
437
|
+
const prior = JSON.parse(readFileSync(abs(receiptFile), 'utf8')) as CheckReceipt;
|
|
438
|
+
if (prior?.schemaVersion === RECEIPT_SCHEMA_VERSION && prior.inputDigest === digest) {
|
|
439
|
+
if (prior.tier === 'full') {
|
|
440
|
+
// A full-tier receipt at the same digest is boundary evidence read by status
|
|
441
|
+
// mode (0940/0943); light must never demote it to a tier-light receipt.
|
|
442
|
+
preserveFullReceipt = true;
|
|
443
|
+
} else {
|
|
444
|
+
for (const row of prior.checks ?? []) if (row.status === 'PASS') reusable.set(row.id, row);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
} catch {
|
|
448
|
+
// No prior receipt (or unreadable) — every planned sub-check runs.
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const checks: CheckReceiptRow[] = [];
|
|
453
|
+
let skipped = 0;
|
|
454
|
+
for (const plan of plans) {
|
|
455
|
+
const priorRow = reusable.get(plan.id);
|
|
456
|
+
if (priorRow !== undefined) {
|
|
457
|
+
checks.push(priorRow);
|
|
458
|
+
skipped++;
|
|
459
|
+
// 0940 R3: accumulation reuse is observable in the gate log and on stdout (the
|
|
460
|
+
// action result `data`); both surfaces run this same script.
|
|
461
|
+
const line = `--- light ${plan.id}: check.reused — skipped (PASS at the same input digest)\n`;
|
|
462
|
+
process.stdout.write(line); // tee: stdout and the log
|
|
463
|
+
appendFileSync(abs(logFile), line);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const startedAtMs = Date.now();
|
|
467
|
+
const result = runShellCommand(plan.cmd, cwd);
|
|
468
|
+
const durationMs = Date.now() - startedAtMs;
|
|
469
|
+
const status: CheckStatus = result.code === 0 ? 'PASS' : 'FAIL';
|
|
470
|
+
appendFileSync(abs(logFile), `--- light ${plan.id}: ${status} (${durationMs}ms)\n${result.output}`);
|
|
471
|
+
checks.push({ id: plan.id, cmd: plan.cmd, status, durationMs, logPath: logFile });
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const receipt = buildReceipt({
|
|
475
|
+
wbs: env.wbs,
|
|
476
|
+
runId: receiptRunId(env),
|
|
477
|
+
tier: 'light',
|
|
478
|
+
inputDigest: digest,
|
|
479
|
+
checks,
|
|
480
|
+
completedAt: new Date().toISOString(),
|
|
481
|
+
});
|
|
482
|
+
if (preserveFullReceipt) {
|
|
483
|
+
// Light ran for its log; the file keeps the full-tier receipt untouched.
|
|
484
|
+
appendFileSync(
|
|
485
|
+
abs(logFile),
|
|
486
|
+
'--- light receipt: not written — the full-tier receipt at the same input digest is preserved\n',
|
|
487
|
+
);
|
|
488
|
+
process.stdout.write(
|
|
489
|
+
`light gate ${receipt.status} (${scope.files.length} changed files; checks: ${checks.length},` +
|
|
490
|
+
` skipped: ${skipped}; receipt: ${receiptFile} preserved (full tier); log: ${logFile})\n`,
|
|
491
|
+
);
|
|
492
|
+
} else {
|
|
493
|
+
writeFileSync(abs(receiptFile), `${JSON.stringify(receipt, null, 2)}\n`);
|
|
494
|
+
process.stdout.write(
|
|
495
|
+
`light gate ${receipt.status} (${scope.files.length} changed files; checks: ${checks.length},` +
|
|
496
|
+
` skipped: ${skipped}; receipt: ${receiptFile}; log: ${logFile})\n`,
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
return { status: receipt.status, scope, checks, logFile, receiptFile };
|
|
500
|
+
}
|
|
501
|
+
|
|
159
502
|
function retryDelayMs(env: QualityGateEnv): number {
|
|
160
503
|
const raw = Number.parseInt(env[RETRY_DELAY_MS_ENV] ?? '', 10);
|
|
161
504
|
return Number.isFinite(raw) && raw >= 0 ? raw : RETRY_DELAY_MS_DEFAULT;
|
|
@@ -201,12 +544,28 @@ export function runQualityGate(
|
|
|
201
544
|
// run: `echo 0 > "$ATTEMPT_FILE" && : > "$LOG_FILE"`; recheck: truncate only.
|
|
202
545
|
writeFileSync(abs(logFile), '');
|
|
203
546
|
if (mode === 'run') writeFileSync(abs(attemptFile), '0\n');
|
|
547
|
+
const gateStartedAtMs = Date.now();
|
|
204
548
|
|
|
205
549
|
let gateRc = 0;
|
|
206
550
|
let gateAttempt = 0;
|
|
207
551
|
|
|
552
|
+
// 0940 R2 — no-progress skip, before the probe: a full-tier FAIL receipt at the current
|
|
553
|
+
// proof-input digest means the fix pass changed nothing tracked, so the full chain can only
|
|
554
|
+
// reproduce the failure. The marker tees to stdout (the action result `data`) and the log,
|
|
555
|
+
// then the shared FAIL path below writes findings/status/verdict exactly as a red gate does.
|
|
556
|
+
// The attempt counter is pipeline-owned (only the test-fix hop increments it; `recheck` never
|
|
557
|
+
// touches it), so the existing cap still bounds the loop.
|
|
558
|
+
const noProgressSkip =
|
|
559
|
+
mode === 'recheck' && receiptFailsAtDigest(readReceipt(abs(rel('-check-receipt.json'))), env.proofDigest ?? '');
|
|
560
|
+
if (noProgressSkip) {
|
|
561
|
+
const line = `check.skipped-no-progress — full-tier FAIL receipt at input digest ${env.proofDigest ?? ''}; recheck skipped\n`;
|
|
562
|
+
process.stdout.write(line); // tee: stdout and the log
|
|
563
|
+
appendFileSync(abs(logFile), line);
|
|
564
|
+
gateRc = 1;
|
|
565
|
+
}
|
|
566
|
+
|
|
208
567
|
// recheck probe: a probe failure is the gate failure; the gate loop is skipped.
|
|
209
|
-
if (mode === 'recheck' && (env.gateProbeCmd ?? '').length > 0) {
|
|
568
|
+
if (mode === 'recheck' && !noProgressSkip && (env.gateProbeCmd ?? '').length > 0) {
|
|
210
569
|
const probe = runShellCommand(env.gateProbeCmd ?? '', cwd);
|
|
211
570
|
writeFileSync(abs(`${logFile}.probe`), probe.output);
|
|
212
571
|
gateRc = probe.code;
|
|
@@ -263,15 +622,42 @@ export function runQualityGate(
|
|
|
263
622
|
writeFileSync(abs(statusFile), `${status}\n`);
|
|
264
623
|
appendFileSync(abs(logFile), `proof-digest: ${env.proofDigest ?? ''}\n`);
|
|
265
624
|
|
|
266
|
-
|
|
625
|
+
// 0939 R2: only `run` writes the full-tier receipt, and only with a digest to bind it to.
|
|
626
|
+
let receiptFile: string | undefined;
|
|
627
|
+
if (mode === 'run') {
|
|
628
|
+
if ((env.proofDigest ?? '').length > 0) {
|
|
629
|
+
receiptFile = join(runDir, `${env.wbs}-check-receipt.json`);
|
|
630
|
+
const receipt = buildReceipt({
|
|
631
|
+
wbs: env.wbs,
|
|
632
|
+
runId: receiptRunId(env),
|
|
633
|
+
tier: 'full',
|
|
634
|
+
inputDigest: env.proofDigest ?? '',
|
|
635
|
+
checks: [
|
|
636
|
+
{
|
|
637
|
+
id: 'test',
|
|
638
|
+
cmd: env.qualityGateCmd ?? '',
|
|
639
|
+
status,
|
|
640
|
+
durationMs: Date.now() - gateStartedAtMs,
|
|
641
|
+
logPath: logFile,
|
|
642
|
+
},
|
|
643
|
+
],
|
|
644
|
+
completedAt: new Date().toISOString(),
|
|
645
|
+
});
|
|
646
|
+
writeFileSync(abs(receiptFile), `${JSON.stringify(receipt, null, 2)}\n`);
|
|
647
|
+
} else {
|
|
648
|
+
appendFileSync(abs(logFile), 'check-receipt: not written — env `proofDigest` is not set\n');
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return { status, attempts: gateAttempt, logFile, findingsFile, statusFile, attemptFile, receiptFile };
|
|
267
653
|
}
|
|
268
654
|
|
|
269
655
|
export const QUALITY_GATE_USAGE =
|
|
270
|
-
'usage: quality-gate.ts <run|recheck> (env: wbs, qualityGateCmd, gateProbeCmd, proofDigest)';
|
|
656
|
+
'usage: quality-gate.ts <run|recheck|light|status> (env: wbs, qualityGateCmd, gateProbeCmd, proofDigest, runId)';
|
|
271
657
|
|
|
272
|
-
export function main(argv: string[], env: QualityGateEnv = getEnvVars()): number {
|
|
658
|
+
export function main(argv: string[], env: QualityGateEnv = getEnvVars(), options: QualityGateOptions = {}): number {
|
|
273
659
|
const mode = argv[0];
|
|
274
|
-
if (mode !== 'run' && mode !== 'recheck') {
|
|
660
|
+
if (mode !== 'run' && mode !== 'recheck' && mode !== 'light' && mode !== 'status') {
|
|
275
661
|
process.stderr.write(`${QUALITY_GATE_USAGE}\n`);
|
|
276
662
|
return 2;
|
|
277
663
|
}
|
|
@@ -279,7 +665,22 @@ export function main(argv: string[], env: QualityGateEnv = getEnvVars()): number
|
|
|
279
665
|
process.stderr.write('quality-gate: env `wbs` is required\n');
|
|
280
666
|
return 2;
|
|
281
667
|
}
|
|
282
|
-
|
|
668
|
+
if (mode === 'light') {
|
|
669
|
+
runLightGate(env);
|
|
670
|
+
} else if (mode === 'status') {
|
|
671
|
+
const runDir = join(options.cwd ?? '.', '.spur', 'run');
|
|
672
|
+
const verdict = readReceiptStatus(join(runDir, `${env.wbs}-check-receipt.json`), env.proofDigest ?? '');
|
|
673
|
+
if (verdict.reuse) {
|
|
674
|
+
// 0940 R3: reuse is observable in the gate log and on stdout (the action result
|
|
675
|
+
// `data`); the `{reuse, reason}` JSON stays the last stdout line for machine readers.
|
|
676
|
+
const line = `check.reused — full-tier receipt reused for input digest ${env.proofDigest ?? ''}\n`;
|
|
677
|
+
process.stdout.write(line); // tee: stdout and the log
|
|
678
|
+
appendFileSync(join(runDir, `${env.wbs}-test-gate.log`), line);
|
|
679
|
+
}
|
|
680
|
+
process.stdout.write(`${JSON.stringify(verdict)}\n`);
|
|
681
|
+
} else {
|
|
682
|
+
runQualityGate(mode, env);
|
|
683
|
+
}
|
|
283
684
|
return 0;
|
|
284
685
|
}
|
|
285
686
|
|
|
@@ -18,6 +18,9 @@ var RESIDUAL_SCAN_USAGE = "usage: residual-scan.ts <scan|fold|settle|report> <wb
|
|
|
18
18
|
var MARKER_PATTERN = /TODO|FIXME|XXX|HACK/;
|
|
19
19
|
var PRIORITY_PATTERN = /^P[1-4]/;
|
|
20
20
|
var NONE_FINDING = /^(none|\u2014)$/i;
|
|
21
|
+
var DISPOSITION_HEADER = /^(Disposition|Action|Status|Resolution|Fixed)$/i;
|
|
22
|
+
var RESOLVED_DISPOSITION = /^(FIXED|RESOLVED|DONE)\b/i;
|
|
23
|
+
var DEFERRED_DISPOSITION = /^DEFER(RED)?\b/i;
|
|
21
24
|
var ANCHOR_PATTERN = /[A-Za-z0-9_./-]+\.[A-Za-z]+:[0-9]+/g;
|
|
22
25
|
var RANGE_ANCHOR = /([A-Za-z0-9_./-]+\.[A-Za-z]+):([0-9]+)-[0-9]+/g;
|
|
23
26
|
var EXCLUDED_PATHS = ["docs/tasks", "docs/features/", ".spur/"];
|
|
@@ -68,6 +71,7 @@ function parseReviewFindings(taskContent) {
|
|
|
68
71
|
}
|
|
69
72
|
const findingCol = header.findIndex((h) => h.trim() === "Finding");
|
|
70
73
|
const locationCol = header.findIndex((h) => h.trim() === "Location");
|
|
74
|
+
const dispositionCol = header.findIndex((h) => DISPOSITION_HEADER.test(h.trim()));
|
|
71
75
|
i++;
|
|
72
76
|
const sep = lines[i];
|
|
73
77
|
if (sep !== undefined && /^\s*\|[\s:|-]+\|\s*$/.test(sep))
|
|
@@ -79,8 +83,10 @@ function parseReviewFindings(taskContent) {
|
|
|
79
83
|
const cells = splitRow(row);
|
|
80
84
|
const priority = (cells[priorityCol] ?? "").trim();
|
|
81
85
|
const finding = (cells[findingCol] ?? "").trim();
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
const disposition = dispositionCol === -1 ? "" : (cells[dispositionCol] ?? "").trim();
|
|
87
|
+
if (PRIORITY_PATTERN.test(priority) && !NONE_FINDING.test(finding) && finding.length > 0 && !RESOLVED_DISPOSITION.test(disposition)) {
|
|
88
|
+
const location = locationOf(cells[locationCol] ?? "", finding);
|
|
89
|
+
out.push(DEFERRED_DISPOSITION.test(disposition) ? { priority, location, text: finding, deferral: disposition } : { priority, location, text: finding });
|
|
84
90
|
}
|
|
85
91
|
i++;
|
|
86
92
|
}
|
|
@@ -193,7 +199,9 @@ function scanResiduals(root, wbs, tmpDir, taskContent, _env) {
|
|
|
193
199
|
const runDir = join(root, ".spur", "run");
|
|
194
200
|
const basePath = join(runDir, `${wbs}-base.sha`);
|
|
195
201
|
const base = existsSync(basePath) ? readFileSync(basePath, "utf8").trim() : null;
|
|
196
|
-
const
|
|
202
|
+
const reviewRows = parseReviewFindings(taskContent);
|
|
203
|
+
const tableDeferrals = reviewRows.flatMap((r) => r.deferral === undefined ? [] : [{ id: makeItemId("review-finding", r.location, r.text), reason: r.deferral }]);
|
|
204
|
+
const review = reviewRows.map((r) => ({
|
|
197
205
|
category: "review-finding",
|
|
198
206
|
priority: r.priority,
|
|
199
207
|
location: r.location,
|
|
@@ -214,7 +222,7 @@ function scanResiduals(root, wbs, tmpDir, taskContent, _env) {
|
|
|
214
222
|
location: p,
|
|
215
223
|
text: p
|
|
216
224
|
}));
|
|
217
|
-
const items = classify([...review, ...markers, ...boxes, ...residue], readDeferrals(runDir, wbs));
|
|
225
|
+
const items = classify([...review, ...markers, ...boxes, ...residue], [...tableDeferrals, ...readDeferrals(runDir, wbs)]);
|
|
218
226
|
const counts = { blocking: 0, deferrable: 0, advisory: 0, housekeeping: 0 };
|
|
219
227
|
for (const item of items)
|
|
220
228
|
counts[item.class]++;
|
|
@@ -65,6 +65,9 @@ export interface ScanOptions {
|
|
|
65
65
|
const MARKER_PATTERN = /TODO|FIXME|XXX|HACK/;
|
|
66
66
|
const PRIORITY_PATTERN = /^P[1-4]/;
|
|
67
67
|
const NONE_FINDING = /^(none|—)$/i;
|
|
68
|
+
const DISPOSITION_HEADER = /^(Disposition|Action|Status|Resolution|Fixed)$/i;
|
|
69
|
+
const RESOLVED_DISPOSITION = /^(FIXED|RESOLVED|DONE)\b/i;
|
|
70
|
+
const DEFERRED_DISPOSITION = /^DEFER(RED)?\b/i;
|
|
68
71
|
const ANCHOR_PATTERN = /[A-Za-z0-9_./-]+\.[A-Za-z]+:[0-9]+/g;
|
|
69
72
|
/** `path:12-18` range anchor → single-line `path:12`. */
|
|
70
73
|
const RANGE_ANCHOR = /([A-Za-z0-9_./-]+\.[A-Za-z]+):([0-9]+)-[0-9]+/g;
|
|
@@ -108,12 +111,16 @@ export function locationOf(locationCell: string, finding: string): string {
|
|
|
108
111
|
/**
|
|
109
112
|
* Extract review-finding rows: any `### Review` section table whose header carries a
|
|
110
113
|
* Priority column. Rows need `^P[1-4]` priority and a finding other than `none`/`—`.
|
|
114
|
+
* A disposition column (Disposition/Action/Status/Resolution/Fixed) is honored: `FIXED`/
|
|
115
|
+
* `RESOLVED`/`DONE` rows are dropped; `DEFER` rows carry the cell as an in-table deferral reason.
|
|
111
116
|
*/
|
|
112
|
-
export function parseReviewFindings(
|
|
117
|
+
export function parseReviewFindings(
|
|
118
|
+
taskContent: string,
|
|
119
|
+
): Array<{ priority: string; location: string; text: string; deferral?: string }> {
|
|
113
120
|
const section = taskContent.split(/^### Review\b/m)[1];
|
|
114
121
|
if (section === undefined) return [];
|
|
115
122
|
const body = section.split(/^### /m)[0];
|
|
116
|
-
const out: Array<{ priority: string; location: string; text: string }> = [];
|
|
123
|
+
const out: Array<{ priority: string; location: string; text: string; deferral?: string }> = [];
|
|
117
124
|
const lines = body.split('\n');
|
|
118
125
|
for (let i = 0; i < lines.length; i++) {
|
|
119
126
|
const line = lines[i];
|
|
@@ -127,6 +134,7 @@ export function parseReviewFindings(taskContent: string): Array<{ priority: stri
|
|
|
127
134
|
}
|
|
128
135
|
const findingCol = header.findIndex((h) => h.trim() === 'Finding');
|
|
129
136
|
const locationCol = header.findIndex((h) => h.trim() === 'Location');
|
|
137
|
+
const dispositionCol = header.findIndex((h) => DISPOSITION_HEADER.test(h.trim()));
|
|
130
138
|
i++; // skip header
|
|
131
139
|
const sep = lines[i];
|
|
132
140
|
if (sep !== undefined && /^\s*\|[\s:|-]+\|\s*$/.test(sep)) i++; // skip separator
|
|
@@ -136,8 +144,19 @@ export function parseReviewFindings(taskContent: string): Array<{ priority: stri
|
|
|
136
144
|
const cells = splitRow(row);
|
|
137
145
|
const priority = (cells[priorityCol] ?? '').trim();
|
|
138
146
|
const finding = (cells[findingCol] ?? '').trim();
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
const disposition = dispositionCol === -1 ? '' : (cells[dispositionCol] ?? '').trim();
|
|
148
|
+
if (
|
|
149
|
+
PRIORITY_PATTERN.test(priority) &&
|
|
150
|
+
!NONE_FINDING.test(finding) &&
|
|
151
|
+
finding.length > 0 &&
|
|
152
|
+
!RESOLVED_DISPOSITION.test(disposition)
|
|
153
|
+
) {
|
|
154
|
+
const location = locationOf(cells[locationCol] ?? '', finding);
|
|
155
|
+
out.push(
|
|
156
|
+
DEFERRED_DISPOSITION.test(disposition)
|
|
157
|
+
? { priority, location, text: finding, deferral: disposition }
|
|
158
|
+
: { priority, location, text: finding },
|
|
159
|
+
);
|
|
141
160
|
}
|
|
142
161
|
i++;
|
|
143
162
|
}
|
|
@@ -295,7 +314,11 @@ export function scanResiduals(
|
|
|
295
314
|
const runDir = join(root, '.spur', 'run');
|
|
296
315
|
const basePath = join(runDir, `${wbs}-base.sha`);
|
|
297
316
|
const base = existsSync(basePath) ? readFileSync(basePath, 'utf8').trim() : null;
|
|
298
|
-
const
|
|
317
|
+
const reviewRows = parseReviewFindings(taskContent);
|
|
318
|
+
const tableDeferrals = reviewRows.flatMap((r) =>
|
|
319
|
+
r.deferral === undefined ? [] : [{ id: makeItemId('review-finding', r.location, r.text), reason: r.deferral }],
|
|
320
|
+
);
|
|
321
|
+
const review = reviewRows.map((r) => ({
|
|
299
322
|
category: 'review-finding' as const,
|
|
300
323
|
priority: r.priority,
|
|
301
324
|
location: r.location,
|
|
@@ -319,7 +342,10 @@ export function scanResiduals(
|
|
|
319
342
|
location: p,
|
|
320
343
|
text: p,
|
|
321
344
|
}));
|
|
322
|
-
const items = classify(
|
|
345
|
+
const items = classify(
|
|
346
|
+
[...review, ...markers, ...boxes, ...residue],
|
|
347
|
+
[...tableDeferrals, ...readDeferrals(runDir, wbs)],
|
|
348
|
+
);
|
|
323
349
|
const counts = { blocking: 0, deferrable: 0, advisory: 0, housekeeping: 0 };
|
|
324
350
|
for (const item of items) counts[item.class]++;
|
|
325
351
|
return {
|