@gobing-ai/spur 0.3.91 → 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.
Files changed (148) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/config/pipeline-budgets.json +2 -9
  3. package/config/plugin-scripts.json +27 -1
  4. package/config/templates/AGENTS.md +4 -0
  5. package/config/templates/docs/02_ROADMAP.md +2 -0
  6. package/config/templates/docs/03_ARCHITECTURE.md +3 -1
  7. package/config/templates/docs/04_DESIGN.md +2 -0
  8. package/config/templates/docs/99_PROJECT_CONSTITUTION.md +10 -2
  9. package/config/workflow-candidates.json +72 -1
  10. package/config/workflows/feature-lifecycle.yaml +14 -5
  11. package/config/workflows/feature-verification.yaml +36 -27
  12. package/config/workflows/history-anatomy.yaml +16 -25
  13. package/config/workflows/idea-pipeline.yaml +76 -23
  14. package/config/workflows/pr-review.yaml +8 -0
  15. package/config/workflows/task-pipeline.yaml +362 -40
  16. package/config/workflows/wayfinder-resolution.yaml +5 -0
  17. package/config/workflows/wrapup-pipeline.yaml +102 -19
  18. package/package.json +9 -9
  19. package/plugins/sp/README.md +7 -2
  20. package/plugins/sp/agents/super-planner.md +14 -5
  21. package/plugins/sp/commands/dev-dogfood.md +4 -4
  22. package/plugins/sp/commands/dev-fixall.md +8 -5
  23. package/plugins/sp/commands/dev-run.md +8 -2
  24. package/plugins/sp/commands/dev-runall.md +14 -8
  25. package/plugins/sp/commands/dev-verify.md +9 -0
  26. package/plugins/sp/commands/dev-verifyall.md +5 -0
  27. package/plugins/sp/lib/idea-handoff.generated.mjs +306 -301
  28. package/plugins/sp/lib/inline-run.generated.d.mts +18 -0
  29. package/plugins/sp/lib/inline-run.generated.mjs +1468 -0
  30. package/plugins/sp/plugin.json +1 -1
  31. package/plugins/sp/references/environment-lens.md +1 -1
  32. package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +136 -0
  33. package/plugins/sp/scripts/dogfood-testing/validate-report.ts +196 -2
  34. package/plugins/sp/scripts/feature-verification-steps.mjs +174 -0
  35. package/plugins/sp/scripts/feature-verification-steps.ts +275 -0
  36. package/plugins/sp/scripts/history-anatomy-cache.mjs +104 -4
  37. package/plugins/sp/scripts/history-anatomy-cache.ts +137 -13
  38. package/plugins/sp/scripts/inline-pipeline-parity-check.ts +2 -1
  39. package/plugins/sp/scripts/inline-run-setup.mjs +421 -0
  40. package/plugins/sp/scripts/inline-run-setup.ts +325 -78
  41. package/plugins/sp/scripts/quality-gate.mjs +248 -6
  42. package/plugins/sp/scripts/quality-gate.ts +410 -9
  43. package/plugins/sp/scripts/record-feature-sync.mjs +63 -0
  44. package/plugins/sp/scripts/record-feature-sync.ts +84 -0
  45. package/plugins/sp/scripts/residual-scan.mjs +484 -0
  46. package/plugins/sp/scripts/residual-scan.ts +640 -0
  47. package/plugins/sp/scripts/task-diffstat.mjs +156 -0
  48. package/plugins/sp/scripts/task-diffstat.ts +229 -0
  49. package/plugins/sp/scripts/task-evidence-precheck.ts +8 -3
  50. package/plugins/sp/scripts/task-size-precheck.ts +8 -3
  51. package/plugins/sp/scripts/wrapup-drift-probe.mjs +181 -0
  52. package/plugins/sp/scripts/wrapup-drift-probe.ts +258 -0
  53. package/plugins/sp/scripts/wrapup-steps.mjs +60 -1
  54. package/plugins/sp/scripts/wrapup-steps.ts +89 -4
  55. package/plugins/sp/skills/brainstorm/SKILL.md +2 -0
  56. package/plugins/sp/skills/brainstorm/references/workflows.md +17 -2
  57. package/plugins/sp/skills/branch-workflow/SKILL.md +1 -0
  58. package/plugins/sp/skills/branch-workflow/references/worktree-patterns.md +2 -0
  59. package/plugins/sp/skills/code-implementation/SKILL.md +17 -0
  60. package/plugins/sp/skills/code-verification/SKILL.md +21 -0
  61. package/plugins/sp/skills/code-verification/references/secu-review.md +3 -2
  62. package/plugins/sp/skills/code-verification/references/verdict-schema.md +1 -0
  63. package/plugins/sp/skills/dogfood-testing/SKILL.md +5 -3
  64. package/plugins/sp/skills/dogfood-testing/references/monitor-ledger.md +63 -26
  65. package/plugins/sp/skills/dogfood-testing/references/report-template.md +33 -10
  66. package/plugins/sp/skills/history-anatomy/references/modes.md +5 -3
  67. package/plugins/sp/skills/next-feature/references/ranking-rubric.md +1 -1
  68. package/plugins/sp/skills/next-router/references/routing-table.md +7 -0
  69. package/plugins/sp/skills/parallel-execution/references/dispatch-surface.md +1 -1
  70. package/plugins/sp/skills/session-review/SKILL.md +12 -2
  71. package/plugins/sp/skills/spur-check/SKILL.md +112 -0
  72. package/plugins/sp/skills/spur-cli/references/features.md +1 -1
  73. package/plugins/sp/skills/spur-cli/references/projects.md +3 -1
  74. package/plugins/sp/skills/spur-cli/references/workflows.md +39 -19
  75. package/plugins/sp/skills/spur-dev/SKILL.md +13 -5
  76. package/plugins/sp/skills/spur-dev/references/cross-cutting.md +18 -3
  77. package/plugins/sp/skills/spur-dev/references/dev-operations.md +2 -2
  78. package/plugins/sp/skills/spur-dev/references/document-authoring.md +85 -0
  79. package/plugins/sp/skills/spur-dev/references/execution-batch.md +286 -58
  80. package/plugins/sp/skills/spur-dev/references/execution-workflow.md +1 -1
  81. package/plugins/sp/skills/spur-dev/references/flag-glossary.md +27 -4
  82. package/plugins/sp/skills/spur-dev/references/gate-checklists.md +3 -2
  83. package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +61 -16
  84. package/plugins/sp/skills/spur-dev/references/planning-workflow.md +10 -5
  85. package/plugins/sp/skills/spur-dev/templates/design.md +31 -0
  86. package/plugins/sp/skills/spur-dev/templates/plan.md +32 -0
  87. package/plugins/sp/skills/spur-doctor/SKILL.md +60 -14
  88. package/schemas/state-machine-workflow.schema.json +4 -0
  89. package/spur.js +22501 -19644
  90. package/web/_astro/BoardApp.CerSBgis.js +192 -0
  91. package/web/_astro/BoardApp.eoTz0pZs.js +1 -0
  92. package/web/_astro/{TaskDetail.CXGltuT_.js → TaskDetail.DCqiC-OZ.js} +1 -1
  93. package/web/_astro/arc.CPwg6Rw0.js +1 -0
  94. package/web/_astro/{architectureDiagram-3BPJPVTR.DJ8DHkWE.js → architectureDiagram-3BPJPVTR.DM_vp_hO.js} +1 -1
  95. package/web/_astro/{blockDiagram-GPEHLZMM.D8DHK3Jl.js → blockDiagram-GPEHLZMM.DXVIiv0p.js} +1 -1
  96. package/web/_astro/{c4Diagram-AAUBKEIU.BugQbX9u.js → c4Diagram-AAUBKEIU.BbF_zCxW.js} +1 -1
  97. package/web/_astro/channel.MYZLKNwy.js +1 -0
  98. package/web/_astro/{chunk-2J33WTMH.Mv26KlVn.js → chunk-2J33WTMH.CAgQHpPC.js} +1 -1
  99. package/web/_astro/{chunk-4BX2VUAB.CD51JoT_.js → chunk-4BX2VUAB.BN-5tpw4.js} +1 -1
  100. package/web/_astro/{chunk-55IACEB6.D_PFaIEe.js → chunk-55IACEB6.CnPkEEr0.js} +1 -1
  101. package/web/_astro/{chunk-727SXJPM.DemMW1ao.js → chunk-727SXJPM.BQzQeMVm.js} +4 -4
  102. package/web/_astro/{chunk-AQP2D5EJ.Iu2V5-ex.js → chunk-AQP2D5EJ.B6xNyDnL.js} +1 -1
  103. package/web/_astro/{chunk-FMBD7UC4.MsNgSP-E.js → chunk-FMBD7UC4.C7f9Ih78.js} +1 -1
  104. package/web/_astro/{chunk-ND2GUHAM.DfbRaAlm.js → chunk-ND2GUHAM.CNV1dFXT.js} +1 -1
  105. package/web/_astro/{chunk-QZHKN3VN.BbJAQ4h-.js → chunk-QZHKN3VN.Cudn2TkJ.js} +1 -1
  106. package/web/_astro/{classDiagram-4FO5ZUOK.CPurtiC2.js → classDiagram-4FO5ZUOK.D1NwP50q.js} +1 -1
  107. package/web/_astro/{classDiagram-v2-Q7XG4LA2.CPurtiC2.js → classDiagram-v2-Q7XG4LA2.D1NwP50q.js} +1 -1
  108. package/web/_astro/{cose-bilkent-S5V4N54A.CKKdx1bM.js → cose-bilkent-S5V4N54A.B1wSL-Xb.js} +1 -1
  109. package/web/_astro/{cynefin-OW5HDTMX.CoKMTg-R.js → cynefin-OW5HDTMX.BmK52w8G.js} +1 -1
  110. package/web/_astro/{dagre-BM42HDAG.D4h4_k56.js → dagre-BM42HDAG.Bfy5CTDT.js} +2 -2
  111. package/web/_astro/diagram-2AECGRRQ.DhNnvUvX.js +43 -0
  112. package/web/_astro/diagram-5GNKFQAL.lTX5KwnS.js +10 -0
  113. package/web/_astro/{diagram-KO2AKTUF.BFoCkiCr.js → diagram-KO2AKTUF.CW_vMJ4z.js} +3 -3
  114. package/web/_astro/{diagram-LMA3HP47.exHn9OVx.js → diagram-LMA3HP47.B_8ZGF67.js} +1 -1
  115. package/web/_astro/{diagram-OG6HWLK6.CeqO34nN.js → diagram-OG6HWLK6.BppnHsdS.js} +1 -1
  116. package/web/_astro/{erDiagram-TEJ5UH35.D_v7HqxR.js → erDiagram-TEJ5UH35.BEuHXcjJ.js} +5 -5
  117. package/web/_astro/{flowDiagram-I6XJVG4X.EUmrpbwh.js → flowDiagram-I6XJVG4X.CH-UlnGr.js} +4 -4
  118. package/web/_astro/{ganttDiagram-6RSMTGT7.BOCF5lII.js → ganttDiagram-6RSMTGT7.BO81S85v.js} +1 -1
  119. package/web/_astro/{gitGraphDiagram-PVQCEYII.Di7otYZD.js → gitGraphDiagram-PVQCEYII.XnPxPPZN.js} +1 -1
  120. package/web/_astro/index.Hjbr15fG.css +1 -0
  121. package/web/_astro/{infoDiagram-5YYISTIA.TcBkCAJk.js → infoDiagram-5YYISTIA.JyjYRu_T.js} +1 -1
  122. package/web/_astro/{ishikawaDiagram-YF4QCWOH.D-2y4M0c.js → ishikawaDiagram-YF4QCWOH.BBRBF-Fo.js} +5 -5
  123. package/web/_astro/{journeyDiagram-JHISSGLW.DPbJI_n2.js → journeyDiagram-JHISSGLW.C_iymSyp.js} +1 -1
  124. package/web/_astro/{kanban-definition-UN3LZRKU.EFxhQ9Fj.js → kanban-definition-UN3LZRKU.DdfW-Oqt.js} +7 -7
  125. package/web/_astro/{linear.DSAsQLzs.js → linear.C2_IkbZT.js} +1 -1
  126. package/web/_astro/mermaid.core.GAOYeSR0.js +303 -0
  127. package/web/_astro/{mindmap-definition-RKZ34NQL.CJY1N_7V.js → mindmap-definition-RKZ34NQL.DAZIxQSK.js} +2 -2
  128. package/web/_astro/{pieDiagram-4H26LBE5.567ZNoL2.js → pieDiagram-4H26LBE5.CN8sIhKM.js} +3 -3
  129. package/web/_astro/{quadrantDiagram-W4KKPZXB.mqfz9-MY.js → quadrantDiagram-W4KKPZXB.3dGcX5GP.js} +1 -1
  130. package/web/_astro/{requirementDiagram-4Y6WPE33.Bv1Gv9In.js → requirementDiagram-4Y6WPE33.BV2y4dd6.js} +3 -3
  131. package/web/_astro/{sankeyDiagram-5OEKKPKP.B6Gs4X4r.js → sankeyDiagram-5OEKKPKP.Cqo15Tvo.js} +4 -4
  132. package/web/_astro/{sequenceDiagram-3UESZ5HK.BhYj4v-m.js → sequenceDiagram-3UESZ5HK.CROCPMJB.js} +1 -1
  133. package/web/_astro/{stateDiagram-AJRCARHV.BPbBnkpw.js → stateDiagram-AJRCARHV.RfXZrkFE.js} +1 -1
  134. package/web/_astro/{stateDiagram-v2-BHNVJYJU.C4squMNK.js → stateDiagram-v2-BHNVJYJU.CPXmbBs9.js} +1 -1
  135. package/web/_astro/{timeline-definition-PNZ67QCA.C_SwIHgl.js → timeline-definition-PNZ67QCA.DdgKTiO8.js} +3 -3
  136. package/web/_astro/{vennDiagram-CIIHVFJN.Bz4NZGpQ.js → vennDiagram-CIIHVFJN.CPNVSHF1.js} +5 -5
  137. package/web/_astro/{wardleyDiagram-YWT4CUSO.CozMVZ3i.js → wardleyDiagram-YWT4CUSO.CQhA0Jyr.js} +3 -3
  138. package/web/_astro/{xychartDiagram-2RQKCTM6.BwMGBwjB.js → xychartDiagram-2RQKCTM6.n61BWyy4.js} +1 -1
  139. package/web/index.html +2 -2
  140. package/config/workflows/decision-routing-example.yaml +0 -134
  141. package/web/_astro/BoardApp.BEDWpzsr.js +0 -188
  142. package/web/_astro/BoardApp.DQG2xfEz.js +0 -1
  143. package/web/_astro/arc.C0rrflm_.js +0 -1
  144. package/web/_astro/channel.SRrg1P-w.js +0 -1
  145. package/web/_astro/diagram-2AECGRRQ.DJ0h9zgw.js +0 -43
  146. package/web/_astro/diagram-5GNKFQAL.DvPk1jYd.js +0 -10
  147. package/web/_astro/index.Bx6GY4RH.css +0 -1
  148. package/web/_astro/mermaid.core.kAZjgJHG.js +0 -301
@@ -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, execute the probe first (probe failure is the gate
17
- * failure, the gate loop is skipped), then execute the gate loop
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
- * Environment: `wbs` (required), `qualityGateCmd`, `gateProbeCmd` (recheck), `proofDigest`.
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
- return { status, attempts: gateAttempt, logFile, findingsFile, statusFile, attemptFile };
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
- runQualityGate(mode, env);
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
 
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ // plugins/sp/scripts/record-feature-sync.ts
3
+ import { spawnSync } from "node:child_process";
4
+ import { appendFileSync, existsSync } from "node:fs";
5
+
6
+ // plugins/sp/lib/env.ts
7
+ function getEnvVar(name, fallback) {
8
+ const raw = process.env[name];
9
+ return raw === undefined ? fallback : raw;
10
+ }
11
+
12
+ // plugins/sp/scripts/record-feature-sync.ts
13
+ function resolveSpurBin(argv) {
14
+ const flag = argv.indexOf("--spur-bin");
15
+ const value = flag !== -1 ? argv[flag + 1] : undefined;
16
+ return value ?? getEnvVar("spurBin") ?? "spur";
17
+ }
18
+ function main() {
19
+ const argv = process.argv.slice(2);
20
+ const spurBin = resolveSpurBin(argv);
21
+ const wbs = getEnvVar("wbs") ?? "";
22
+ if (wbs.length === 0) {
23
+ console.error("record-feature-sync: env `wbs` is required");
24
+ process.exit(0);
25
+ }
26
+ const reportPath = `.spur/run/${wbs}-report.txt`;
27
+ const report = (line) => {
28
+ appendFileSync(reportPath, `${line}
29
+ `);
30
+ };
31
+ const show = spawnSync(spurBin, ["task", "show", wbs, "--json"], {
32
+ encoding: "utf8",
33
+ stdio: ["ignore", "pipe", "ignore"]
34
+ });
35
+ let featureId = "";
36
+ try {
37
+ const parsed = JSON.parse(show.stdout ?? "");
38
+ featureId = String(parsed.feature_id ?? parsed.frontmatter?.feature_id ?? "");
39
+ } catch {
40
+ featureId = "";
41
+ }
42
+ if (featureId.length === 0) {
43
+ report(`Orphan task ${wbs} — no feature_id linked — proposal: consider linking to a parent feature.`);
44
+ return;
45
+ }
46
+ if (existsSync("plugins/sp/scripts/feature-sync-bounded.ts")) {
47
+ spawnSync("bun", ["plugins/sp/scripts/feature-sync-bounded.ts", featureId, "--spur-bin", spurBin, "--json"], {
48
+ stdio: "inherit"
49
+ });
50
+ return;
51
+ }
52
+ const staged = spawnSync("superskill", ["script", "path", "sp", "feature-sync-bounded.mjs"], {
53
+ encoding: "utf8",
54
+ stdio: ["ignore", "pipe", "ignore"]
55
+ });
56
+ const stagedPath = (staged.stdout ?? "").trim();
57
+ if (staged.status === 0 && stagedPath.length > 0 && existsSync(stagedPath)) {
58
+ spawnSync("node", [stagedPath, featureId, "--spur-bin", spurBin, "--json"], { stdio: "inherit" });
59
+ return;
60
+ }
61
+ spawnSync(spurBin, ["feature", "sync", featureId, "--json"], { stdio: "inherit" });
62
+ }
63
+ main();
@@ -0,0 +1,84 @@
1
+ /**
2
+ * record-feature-sync — record-step post-record feature sync owner (tasks 0328 / 0411 / 0931).
3
+ *
4
+ * Extracted from the record onEnter shell (0931 R5): ADR-115 caps one workflow shell at 10
5
+ * logical commands and 800 chars, and the deferFeatureSync guard plus the sync chain can no
6
+ * longer share it. The pipeline shell resolves this script (in-repo first, superskill-staged
7
+ * .mjs fallback), notes a deferral, and delegates the rest here:
8
+ *
9
+ * - A task with no feature_id gets the orphan proposal note (0328).
10
+ * - The sync routes through feature-sync-bounded.ts (0411 retry suppression), then the
11
+ * superskill-staged module, then bare `spur feature sync` (0328).
12
+ * - Best-effort by contract: a sync failure never fails the record step.
13
+ *
14
+ * Node-builtin imports only (ADR-065): this file is transpiled to a node-runnable .mjs twin
15
+ * by `superskill script convert`. Env: wbs (required), spurBin (default "spur"); the
16
+ * `--spur-bin <bin>` argument wins over the env var.
17
+ */
18
+
19
+ import { spawnSync } from 'node:child_process';
20
+ import { appendFileSync, existsSync } from 'node:fs';
21
+ import { getEnvVar } from '../lib/env';
22
+
23
+ function resolveSpurBin(argv: string[]): string {
24
+ const flag = argv.indexOf('--spur-bin');
25
+ const value = flag !== -1 ? argv[flag + 1] : undefined;
26
+ return value ?? getEnvVar('spurBin') ?? 'spur';
27
+ }
28
+
29
+ function main(): void {
30
+ const argv = process.argv.slice(2);
31
+ const spurBin = resolveSpurBin(argv);
32
+ const wbs = getEnvVar('wbs') ?? '';
33
+ if (wbs.length === 0) {
34
+ console.error('record-feature-sync: env `wbs` is required');
35
+ process.exit(0); // best-effort contract — never fail the record step
36
+ }
37
+
38
+ const reportPath = `.spur/run/${wbs}-report.txt`;
39
+ const report = (line: string): void => {
40
+ appendFileSync(reportPath, `${line}\n`);
41
+ };
42
+
43
+ const show = spawnSync(spurBin, ['task', 'show', wbs, '--json'], {
44
+ encoding: 'utf8',
45
+ stdio: ['ignore', 'pipe', 'ignore'],
46
+ });
47
+ let featureId = '';
48
+ try {
49
+ const parsed = JSON.parse(show.stdout ?? '') as {
50
+ feature_id?: string;
51
+ frontmatter?: { feature_id?: string };
52
+ };
53
+ featureId = String(parsed.feature_id ?? parsed.frontmatter?.feature_id ?? '');
54
+ } catch {
55
+ featureId = '';
56
+ }
57
+
58
+ if (featureId.length === 0) {
59
+ report(`Orphan task ${wbs} — no feature_id linked — proposal: consider linking to a parent feature.`);
60
+ return;
61
+ }
62
+
63
+ if (existsSync('plugins/sp/scripts/feature-sync-bounded.ts')) {
64
+ spawnSync('bun', ['plugins/sp/scripts/feature-sync-bounded.ts', featureId, '--spur-bin', spurBin, '--json'], {
65
+ stdio: 'inherit',
66
+ });
67
+ return;
68
+ }
69
+
70
+ const staged = spawnSync('superskill', ['script', 'path', 'sp', 'feature-sync-bounded.mjs'], {
71
+ encoding: 'utf8',
72
+ stdio: ['ignore', 'pipe', 'ignore'],
73
+ });
74
+ const stagedPath = (staged.stdout ?? '').trim();
75
+ if (staged.status === 0 && stagedPath.length > 0 && existsSync(stagedPath)) {
76
+ spawnSync('node', [stagedPath, featureId, '--spur-bin', spurBin, '--json'], { stdio: 'inherit' });
77
+ return;
78
+ }
79
+
80
+ spawnSync(spurBin, ['feature', 'sync', featureId, '--json'], { stdio: 'inherit' });
81
+ // Falls through with exit 0: a sync failure never fails the record step (0411).
82
+ }
83
+
84
+ main();