@gobing-ai/spur 0.3.61 → 0.3.63
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/config.global.yaml +64 -57
- package/config/corpus-baseline.json +601 -49
- package/config/plugin-scripts.json +2 -2
- package/config/rules/boundary/config-loading-ownership.yaml +21 -0
- package/config/workflows/history-anatomy.yaml +395 -0
- package/package.json +9 -9
- package/plugins/sp/README.md +19 -6
- package/plugins/sp/commands/dev-find-issue.md +25 -46
- package/plugins/sp/commands/dev-idea.md +3 -3
- package/plugins/sp/commands/dev-run.md +22 -3
- package/plugins/sp/lib/artifact-digest.generated.d.mts +7 -0
- package/plugins/sp/lib/artifact-digest.generated.mjs +48 -0
- package/plugins/sp/plugin.json +1 -1
- package/plugins/sp/references/environment-lens.md +66 -0
- package/plugins/sp/references/roles.md +5 -5
- package/plugins/sp/scripts/history-anatomy-cache.mjs +818 -0
- package/plugins/sp/scripts/history-anatomy-cache.ts +1014 -0
- package/plugins/sp/skills/dogfood-testing/references/report-template.md +30 -0
- package/plugins/sp/skills/history-anatomy/SKILL.md +67 -0
- package/plugins/sp/skills/history-anatomy/references/modes.md +82 -0
- package/plugins/sp/skills/history-anatomy/references/operations.md +80 -0
- package/plugins/sp/skills/history-anatomy/references/report-contract.md +183 -0
- package/plugins/sp/skills/spur-cli/references/agent.md +15 -6
- package/plugins/sp/skills/spur-cli/references/message.md +4 -2
- package/plugins/sp/skills/spur-dev/references/cross-cutting.md +6 -4
- package/plugins/sp/skills/spur-dev/references/dev-operations.md +2 -2
- package/plugins/sp/skills/spur-dev/references/execution-batch.md +14 -1
- package/plugins/sp/skills/spur-dev/references/execution-workflow.md +7 -0
- package/plugins/sp/skills/spur-dev/references/flag-glossary.md +25 -13
- package/spur.js +1958 -1133
- package/web/_astro/{BoardApp.CBIzcvqi.js → BoardApp.CKolAjUz.js} +102 -102
- package/web/_astro/BoardApp.DXD--ybM.js +1 -0
- package/web/_astro/{TaskDetail.D2N60cfE.js → TaskDetail.Bre7G4gC.js} +1 -1
- package/web/_astro/{arc.D-EfJJwf.js → arc.7luwOGiC.js} +1 -1
- package/web/_astro/{architectureDiagram-3BPJPVTR.CgvTTzqp.js → architectureDiagram-3BPJPVTR.F6KaHXp-.js} +1 -1
- package/web/_astro/{blockDiagram-GPEHLZMM.CnOohvvn.js → blockDiagram-GPEHLZMM.CCGHeRVi.js} +1 -1
- package/web/_astro/{c4Diagram-AAUBKEIU.BFcBGUy_.js → c4Diagram-AAUBKEIU.CpqewGmd.js} +1 -1
- package/web/_astro/channel.DxfOFf1l.js +1 -0
- package/web/_astro/{chunk-2J33WTMH.C-6MR-XY.js → chunk-2J33WTMH.CB9vKa5F.js} +1 -1
- package/web/_astro/{chunk-4BX2VUAB.BN4LP5AR.js → chunk-4BX2VUAB.ifGXoUA3.js} +1 -1
- package/web/_astro/{chunk-55IACEB6.tUJ_CTtZ.js → chunk-55IACEB6.VIaRo7l8.js} +1 -1
- package/web/_astro/{chunk-727SXJPM.BNCk-sxv.js → chunk-727SXJPM.DzPE41OS.js} +1 -1
- package/web/_astro/{chunk-AQP2D5EJ.BkpFIbNa.js → chunk-AQP2D5EJ.UF2QRXYF.js} +1 -1
- package/web/_astro/{chunk-FMBD7UC4.DcSZ87PN.js → chunk-FMBD7UC4.D2zXKa1R.js} +1 -1
- package/web/_astro/{chunk-ND2GUHAM.BkLvHFFf.js → chunk-ND2GUHAM.Cb9bDyvx.js} +1 -1
- package/web/_astro/{chunk-QZHKN3VN.HOdgszax.js → chunk-QZHKN3VN.nUKFBiLD.js} +1 -1
- package/web/_astro/{classDiagram-4FO5ZUOK.CWfRiY6b.js → classDiagram-4FO5ZUOK.DZg9K9mO.js} +1 -1
- package/web/_astro/{classDiagram-v2-Q7XG4LA2.CWfRiY6b.js → classDiagram-v2-Q7XG4LA2.DZg9K9mO.js} +1 -1
- package/web/_astro/{cose-bilkent-S5V4N54A.C6j4PxoN.js → cose-bilkent-S5V4N54A.D9STo90d.js} +1 -1
- package/web/_astro/{dagre-BM42HDAG.BATZG1II.js → dagre-BM42HDAG.D3IbwhHz.js} +1 -1
- package/web/_astro/{diagram-2AECGRRQ.B0f5yY6x.js → diagram-2AECGRRQ.BWTDxBe9.js} +1 -1
- package/web/_astro/{diagram-5GNKFQAL.Bewupqv0.js → diagram-5GNKFQAL.XnXlonHG.js} +1 -1
- package/web/_astro/{diagram-KO2AKTUF.C23r1tB2.js → diagram-KO2AKTUF.CywOngCO.js} +1 -1
- package/web/_astro/{diagram-LMA3HP47.DUErdBOR.js → diagram-LMA3HP47.DY1D21Iu.js} +1 -1
- package/web/_astro/{diagram-OG6HWLK6.BubmwAjb.js → diagram-OG6HWLK6.DQxb59KA.js} +1 -1
- package/web/_astro/{erDiagram-TEJ5UH35.BE_Qs5mv.js → erDiagram-TEJ5UH35.CF2U-pQZ.js} +1 -1
- package/web/_astro/{flowDiagram-I6XJVG4X.COWdbzon.js → flowDiagram-I6XJVG4X.BJK4M3in.js} +1 -1
- package/web/_astro/{ganttDiagram-6RSMTGT7.5EGYC4MK.js → ganttDiagram-6RSMTGT7.BSniMzdB.js} +1 -1
- package/web/_astro/{gitGraphDiagram-PVQCEYII.bUUV7iEw.js → gitGraphDiagram-PVQCEYII.Dxg-yRov.js} +1 -1
- package/web/_astro/index.BVXdIsZV.css +1 -0
- package/web/_astro/{infoDiagram-5YYISTIA.CbiInFvz.js → infoDiagram-5YYISTIA.BY4CgO_n.js} +1 -1
- package/web/_astro/{ishikawaDiagram-YF4QCWOH.CB7lrSsJ.js → ishikawaDiagram-YF4QCWOH.BmWDZtwF.js} +1 -1
- package/web/_astro/{journeyDiagram-JHISSGLW.rhGZgWt8.js → journeyDiagram-JHISSGLW.CpB1YWDP.js} +1 -1
- package/web/_astro/{kanban-definition-UN3LZRKU.DPeZD_lP.js → kanban-definition-UN3LZRKU.k-fukQX9.js} +1 -1
- package/web/_astro/{linear.l60Nyp5b.js → linear.BNNCobvI.js} +1 -1
- package/web/_astro/{mermaid.core.DmtMJcmL.js → mermaid.core.DnpzzuPU.js} +4 -4
- package/web/_astro/{mindmap-definition-RKZ34NQL.Cc47AcCn.js → mindmap-definition-RKZ34NQL.D9NnlLBu.js} +1 -1
- package/web/_astro/{pieDiagram-4H26LBE5.B8cN-S9g.js → pieDiagram-4H26LBE5.CKhoMiyC.js} +1 -1
- package/web/_astro/{quadrantDiagram-W4KKPZXB.DY1FN89L.js → quadrantDiagram-W4KKPZXB.BkAygRlm.js} +1 -1
- package/web/_astro/{requirementDiagram-4Y6WPE33.CnM6VbV8.js → requirementDiagram-4Y6WPE33.CX8ibmwc.js} +1 -1
- package/web/_astro/{sankeyDiagram-5OEKKPKP.B9DcGfNV.js → sankeyDiagram-5OEKKPKP.Dvurpa0Y.js} +1 -1
- package/web/_astro/{sequenceDiagram-3UESZ5HK.ymxaNlAY.js → sequenceDiagram-3UESZ5HK.veO8c2tk.js} +1 -1
- package/web/_astro/{stateDiagram-AJRCARHV.DDOJ3d8P.js → stateDiagram-AJRCARHV.DpMr4CO3.js} +1 -1
- package/web/_astro/{stateDiagram-v2-BHNVJYJU.Ck0Nb_KY.js → stateDiagram-v2-BHNVJYJU.CKjso86_.js} +1 -1
- package/web/_astro/{timeline-definition-PNZ67QCA.BNOvZwAN.js → timeline-definition-PNZ67QCA.DayoPp_2.js} +1 -1
- package/web/_astro/{vennDiagram-CIIHVFJN.D3k5ivSF.js → vennDiagram-CIIHVFJN.XNHf04O9.js} +1 -1
- package/web/_astro/{wardley-L42UT6IY.BylaxVqn.js → wardley-L42UT6IY.CpM_031g.js} +1 -1
- package/web/_astro/{wardleyDiagram-YWT4CUSO.HLNtFUm9.js → wardleyDiagram-YWT4CUSO.lIAjSkZJ.js} +1 -1
- package/web/_astro/{xychartDiagram-2RQKCTM6.B-WooKSU.js → xychartDiagram-2RQKCTM6.D8_2K6U1.js} +1 -1
- package/web/index.html +2 -2
- package/plugins/sp/commands/dev-history-load.md +0 -63
- package/plugins/sp/scripts/history-load.mjs +0 -268
- package/plugins/sp/scripts/history-load.ts +0 -400
- package/web/_astro/BoardApp.BtRfVADq.js +0 -1
- package/web/_astro/channel.kIu33Gui.js +0 -1
- package/web/_astro/index.Cestp9nh.css +0 -1
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// plugins/sp/scripts/history-anatomy-cache.ts
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
8
|
+
import {
|
|
9
|
+
closeSync,
|
|
10
|
+
existsSync,
|
|
11
|
+
fsyncSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readdirSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
renameSync,
|
|
16
|
+
rmSync,
|
|
17
|
+
statSync,
|
|
18
|
+
writeFileSync
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
|
|
22
|
+
// plugins/sp/lib/artifact-digest.generated.mjs
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
var ARTIFACT_ARRAY_CLASSIFICATION = {
|
|
25
|
+
byTool: "ranked",
|
|
26
|
+
bySession: "ranked",
|
|
27
|
+
topStepsByTokens: "ranked",
|
|
28
|
+
topStepsByDuration: "ranked",
|
|
29
|
+
topSteps: "ranked",
|
|
30
|
+
bottlenecks: "ranked",
|
|
31
|
+
coverage: "set",
|
|
32
|
+
daily: "set",
|
|
33
|
+
loops: "set",
|
|
34
|
+
warnings: "set",
|
|
35
|
+
pairings: "set",
|
|
36
|
+
ladderSnapshot: "set",
|
|
37
|
+
stepSupport: "set",
|
|
38
|
+
phases: "set",
|
|
39
|
+
tools: "set",
|
|
40
|
+
skills: "set",
|
|
41
|
+
sources: "set",
|
|
42
|
+
models: "set"
|
|
43
|
+
};
|
|
44
|
+
var RANKED_ARTIFACT_KEYS = new Set(Object.entries(ARTIFACT_ARRAY_CLASSIFICATION).filter(([, kind]) => kind === "ranked").map(([key]) => key));
|
|
45
|
+
function canonicalize(value, key) {
|
|
46
|
+
if (key === "generatedAt" || key === "validatedAt" || key === "baselineArtifactDigest")
|
|
47
|
+
return null;
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
const raw = value.map((v) => JSON.stringify(canonicalize(v, "")));
|
|
50
|
+
return RANKED_ARTIFACT_KEYS.has(key) ? raw : [...raw].sort();
|
|
51
|
+
}
|
|
52
|
+
if (value !== null && typeof value === "object") {
|
|
53
|
+
const out = {};
|
|
54
|
+
for (const k of Object.keys(value).sort()) {
|
|
55
|
+
out[k] = canonicalize(value[k], k);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function semanticArtifactDigest(artifactJson) {
|
|
62
|
+
const material = JSON.stringify(canonicalize(artifactJson, "root"));
|
|
63
|
+
return createHash("sha256").update(material).digest("hex");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// plugins/sp/scripts/history-anatomy-cache.ts
|
|
67
|
+
var REPORT_SECTIONS = [
|
|
68
|
+
"Scope and provenance",
|
|
69
|
+
"Executive summary",
|
|
70
|
+
"Baseline comparison",
|
|
71
|
+
"Findings",
|
|
72
|
+
"Recurrence ledger",
|
|
73
|
+
"Telemetry gaps",
|
|
74
|
+
"Remediation options",
|
|
75
|
+
"Performance analysis",
|
|
76
|
+
"Workflow and process improvements",
|
|
77
|
+
"Report-only advisories",
|
|
78
|
+
"Positive patterns",
|
|
79
|
+
"Evidence ledger"
|
|
80
|
+
];
|
|
81
|
+
var FINDING_FIELDS = [
|
|
82
|
+
"key",
|
|
83
|
+
"category",
|
|
84
|
+
"impact",
|
|
85
|
+
"trend",
|
|
86
|
+
"observation",
|
|
87
|
+
"inference",
|
|
88
|
+
"confidence",
|
|
89
|
+
"contradictions",
|
|
90
|
+
"evidenceAnchor",
|
|
91
|
+
"severity",
|
|
92
|
+
"reproCommand",
|
|
93
|
+
"ownerSurface"
|
|
94
|
+
];
|
|
95
|
+
function parseScalar(raw) {
|
|
96
|
+
const t = raw.trim();
|
|
97
|
+
if (t.startsWith('"') && t.endsWith('"'))
|
|
98
|
+
return t.slice(1, -1).replaceAll("\\\"", '"');
|
|
99
|
+
if (t === "null")
|
|
100
|
+
return null;
|
|
101
|
+
return t;
|
|
102
|
+
}
|
|
103
|
+
function parseBlock(text) {
|
|
104
|
+
const obj = {};
|
|
105
|
+
const lines = text.split(`
|
|
106
|
+
`);
|
|
107
|
+
for (let i = 0;i < lines.length; i++) {
|
|
108
|
+
const line = lines[i] ?? "";
|
|
109
|
+
if (/^\s*$/.test(line) || /^\s*#/.test(line) || /^-\s+/.test(line.trim()))
|
|
110
|
+
continue;
|
|
111
|
+
const indent = line.search(/\S/);
|
|
112
|
+
const eq = line.indexOf(":");
|
|
113
|
+
if (eq === -1)
|
|
114
|
+
continue;
|
|
115
|
+
const key = line.slice(0, eq).trim();
|
|
116
|
+
const val = parseScalar(line.slice(eq + 1).trim());
|
|
117
|
+
let consumed = 0;
|
|
118
|
+
const next = lines[i + 1];
|
|
119
|
+
if ((val === "" || val === undefined) && /^\s*-\s+/.test(next ?? "")) {
|
|
120
|
+
const items = [];
|
|
121
|
+
let j = i + 1;
|
|
122
|
+
while (j < lines.length && /^\s*-\s+/.test(lines[j] ?? "")) {
|
|
123
|
+
const entry = {};
|
|
124
|
+
for (const part of (lines[j] ?? "").trim().replace(/^-\s+/, "").split(",")) {
|
|
125
|
+
const e = part.indexOf(":");
|
|
126
|
+
if (e === -1)
|
|
127
|
+
continue;
|
|
128
|
+
entry[part.slice(0, e).trim()] = parseScalar(part.slice(e + 1).trim());
|
|
129
|
+
}
|
|
130
|
+
items.push(entry);
|
|
131
|
+
j++;
|
|
132
|
+
}
|
|
133
|
+
obj[key] = items;
|
|
134
|
+
consumed = j - i - 1;
|
|
135
|
+
} else if (val === "" || val === undefined) {
|
|
136
|
+
const block = [];
|
|
137
|
+
let j = i + 1;
|
|
138
|
+
while (j < lines.length) {
|
|
139
|
+
const nl = lines[j] ?? "";
|
|
140
|
+
if (nl.trim() === "") {
|
|
141
|
+
block.push("");
|
|
142
|
+
j++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const nind = nl.search(/\S/);
|
|
146
|
+
if (nind <= indent)
|
|
147
|
+
break;
|
|
148
|
+
block.push(nl);
|
|
149
|
+
j++;
|
|
150
|
+
}
|
|
151
|
+
obj[key] = parseBlock(block.join(`
|
|
152
|
+
`));
|
|
153
|
+
consumed = j - i - 1;
|
|
154
|
+
} else {
|
|
155
|
+
obj[key] = val;
|
|
156
|
+
}
|
|
157
|
+
i += consumed;
|
|
158
|
+
}
|
|
159
|
+
return obj;
|
|
160
|
+
}
|
|
161
|
+
function readSourceName(s) {
|
|
162
|
+
if (s !== null && typeof s === "object")
|
|
163
|
+
return String(s.source ?? "");
|
|
164
|
+
return String(s);
|
|
165
|
+
}
|
|
166
|
+
var DISPOSITIONS = ["hit", "miss", "forced-recompute"];
|
|
167
|
+
function optionalString(v) {
|
|
168
|
+
return v == null || v === "" ? undefined : String(v);
|
|
169
|
+
}
|
|
170
|
+
function parseProvenance(reportMarkdown) {
|
|
171
|
+
const match = reportMarkdown.match(/^---\n([\s\S]*?)\n---/);
|
|
172
|
+
if (match === null)
|
|
173
|
+
return null;
|
|
174
|
+
try {
|
|
175
|
+
const obj = parseBlock(match[1] ?? "");
|
|
176
|
+
const identity = obj.identity;
|
|
177
|
+
const coverage = obj.coverage;
|
|
178
|
+
if (identity === undefined || !Array.isArray(coverage))
|
|
179
|
+
return null;
|
|
180
|
+
const bounds = identity.bounds;
|
|
181
|
+
if (bounds === undefined || typeof bounds.since !== "string" || typeof bounds.until !== "string") {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
identity: {
|
|
186
|
+
contractVersion: String(identity.contractVersion ?? ""),
|
|
187
|
+
mode: identity.mode === "ad-hoc" ? "ad-hoc" : "daily",
|
|
188
|
+
date: String(identity.date ?? ""),
|
|
189
|
+
timezone: String(identity.timezone ?? ""),
|
|
190
|
+
bounds: { since: bounds.since, until: bounds.until },
|
|
191
|
+
sources: Array.isArray(identity.sources) ? identity.sources.map(readSourceName) : []
|
|
192
|
+
},
|
|
193
|
+
windowState: obj.windowState === "closed" ? "closed" : "provisional",
|
|
194
|
+
generatedAt: String(obj.generatedAt ?? ""),
|
|
195
|
+
validatedAt: String(obj.validatedAt ?? ""),
|
|
196
|
+
artifactDigest: String(obj.artifactDigest ?? ""),
|
|
197
|
+
baselineArtifactDigest: obj.baselineArtifactDigest == null ? null : String(obj.baselineArtifactDigest),
|
|
198
|
+
contractDigest: String(obj.contractDigest ?? ""),
|
|
199
|
+
skillDigest: String(obj.skillDigest ?? ""),
|
|
200
|
+
workflowDigest: String(obj.workflowDigest ?? ""),
|
|
201
|
+
coverage: coverage.map((c) => ({
|
|
202
|
+
source: String(c.source ?? ""),
|
|
203
|
+
status: String(c.status ?? ""),
|
|
204
|
+
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt)
|
|
205
|
+
})),
|
|
206
|
+
runId: optionalString(obj.runId),
|
|
207
|
+
currentArtifactPath: optionalString(obj.currentArtifactPath),
|
|
208
|
+
baselineArtifactPath: obj.baselineArtifactPath == null ? null : String(obj.baselineArtifactPath),
|
|
209
|
+
spurVersion: optionalString(obj.spurVersion),
|
|
210
|
+
schemaVersion: obj.schemaVersion == null ? undefined : Number(obj.schemaVersion),
|
|
211
|
+
executor: optionalString(obj.executor),
|
|
212
|
+
model: optionalString(obj.model),
|
|
213
|
+
cacheDisposition: DISPOSITIONS.includes(obj.cacheDisposition) ? obj.cacheDisposition : undefined
|
|
214
|
+
};
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function decideCache(cached, current, opts) {
|
|
220
|
+
if (opts.recompute)
|
|
221
|
+
return { disposition: "forced-recompute", reasons: ["recompute"] };
|
|
222
|
+
if (cached === null)
|
|
223
|
+
return { disposition: "miss", reasons: ["no-cache"] };
|
|
224
|
+
const reasons = [];
|
|
225
|
+
const id = cached.identity;
|
|
226
|
+
const cur = current.identity;
|
|
227
|
+
if (id.contractVersion !== cur.contractVersion)
|
|
228
|
+
reasons.push("identity:contractVersion");
|
|
229
|
+
if (id.mode !== cur.mode)
|
|
230
|
+
reasons.push("identity:mode");
|
|
231
|
+
if (id.date !== cur.date)
|
|
232
|
+
reasons.push("identity:date");
|
|
233
|
+
if (id.timezone !== cur.timezone)
|
|
234
|
+
reasons.push("identity:timezone");
|
|
235
|
+
if (id.bounds.since !== cur.bounds.since || id.bounds.until !== cur.bounds.until)
|
|
236
|
+
reasons.push("identity:bounds");
|
|
237
|
+
if ([...id.sources].sort().join("\x00") !== [...cur.sources].sort().join("\x00"))
|
|
238
|
+
reasons.push("identity:sources");
|
|
239
|
+
if (cached.artifactDigest !== current.artifactDigest)
|
|
240
|
+
reasons.push("data-changed");
|
|
241
|
+
if (cached.contractDigest !== current.contractDigest)
|
|
242
|
+
reasons.push("logic-changed:contract");
|
|
243
|
+
if (cached.skillDigest !== current.skillDigest)
|
|
244
|
+
reasons.push("logic-changed:skill");
|
|
245
|
+
if (cached.workflowDigest !== current.workflowDigest)
|
|
246
|
+
reasons.push("logic-changed:workflow");
|
|
247
|
+
const currentSources = new Set(current.coverage.map((c) => c.source));
|
|
248
|
+
if (cached.coverage.some((c) => !currentSources.has(c.source)))
|
|
249
|
+
reasons.push("coverage-degraded");
|
|
250
|
+
if (cached.windowState === "provisional" && opts.dayClosed)
|
|
251
|
+
reasons.push("window-closed");
|
|
252
|
+
return { disposition: reasons.length === 0 ? "hit" : "miss", reasons };
|
|
253
|
+
}
|
|
254
|
+
function escapeRe(s) {
|
|
255
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
256
|
+
}
|
|
257
|
+
var FINDING_CATEGORIES = [
|
|
258
|
+
"reliability",
|
|
259
|
+
"repetition",
|
|
260
|
+
"workflow",
|
|
261
|
+
"performance",
|
|
262
|
+
"coverage",
|
|
263
|
+
"telemetry",
|
|
264
|
+
"positive"
|
|
265
|
+
];
|
|
266
|
+
function checkReportStructure(reportMarkdown) {
|
|
267
|
+
const problems = [];
|
|
268
|
+
if (/TODO|PLACEHOLDER|FIXME|^\|\s*\|/im.test(reportMarkdown))
|
|
269
|
+
problems.push("placeholder-or-todo-present");
|
|
270
|
+
let lastIdx = -1;
|
|
271
|
+
for (const section of REPORT_SECTIONS) {
|
|
272
|
+
const re = new RegExp(`^#{2,3}\\s+${escapeRe(section)}\\s*$`, "m");
|
|
273
|
+
const m = reportMarkdown.match(re);
|
|
274
|
+
if (m === null || (m.index ?? -1) <= lastIdx) {
|
|
275
|
+
problems.push(`section-missing-or-out-of-order:${section}`);
|
|
276
|
+
} else if (m.index !== undefined) {
|
|
277
|
+
lastIdx = m.index;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const findingsIdx = reportMarkdown.search(/^##\s+Findings\s*$/im);
|
|
281
|
+
if (findingsIdx !== -1) {
|
|
282
|
+
const tail = reportMarkdown.slice(findingsIdx);
|
|
283
|
+
const nextSection = tail.slice(1).search(/^##\s+/im);
|
|
284
|
+
const findingsBody = nextSection === -1 ? tail : tail.slice(0, nextSection + 1);
|
|
285
|
+
const catAlt = FINDING_CATEGORIES.join("|");
|
|
286
|
+
const knownRows = findingsBody.match(new RegExp(`^\\|\\s*(?:${catAlt}):[^|]+`, "gm")) ?? [];
|
|
287
|
+
const invalidRows = findingsBody.match(/^\|\s*([^|:\s][^|:]*):[^|]+/gm) ?? [];
|
|
288
|
+
for (const row of [...new Set([...knownRows, ...invalidRows])]) {
|
|
289
|
+
const segMatch = row.match(/^\|\s*([^:|]+):/);
|
|
290
|
+
if (segMatch && !FINDING_CATEGORIES.includes(segMatch[1].trim())) {
|
|
291
|
+
problems.push(`finding-invalid-key-category:${segMatch[1].trim()}`);
|
|
292
|
+
}
|
|
293
|
+
const rowLower = row.toLowerCase();
|
|
294
|
+
for (const field of FINDING_FIELDS) {
|
|
295
|
+
if (!rowLower.includes(field.toLowerCase()))
|
|
296
|
+
problems.push(`finding-missing-field:${field}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const blocks = findingsBody.split(/^###\s+/m).slice(1);
|
|
300
|
+
for (const block of blocks) {
|
|
301
|
+
if (!block.includes("`key`") && !/\|\s*key\s*:/.test(block))
|
|
302
|
+
continue;
|
|
303
|
+
for (const field of FINDING_FIELDS) {
|
|
304
|
+
if (!block.includes(field))
|
|
305
|
+
problems.push(`finding-missing-field:${field}`);
|
|
306
|
+
}
|
|
307
|
+
if (!/(^|[\s`])P[123]([\s`.]|$)/.test(block) && !block.includes("symbolic-severity")) {
|
|
308
|
+
problems.push("finding-invalid-severity");
|
|
309
|
+
}
|
|
310
|
+
const catValue = block.match(/`category`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1];
|
|
311
|
+
if (catValue && !FINDING_CATEGORIES.includes(catValue.trim())) {
|
|
312
|
+
problems.push(`finding-invalid-category:${catValue.trim()}`);
|
|
313
|
+
}
|
|
314
|
+
const keyValue = block.match(/`key`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1] ?? "";
|
|
315
|
+
const firstSegment = keyValue.split(":")[0]?.trim() ?? "";
|
|
316
|
+
if (keyValue !== "" && !FINDING_CATEGORIES.includes(firstSegment)) {
|
|
317
|
+
problems.push(`finding-invalid-key-category:${firstSegment}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const ledgerIdx = reportMarkdown.search(/^#{2,3}\s+Evidence\s+ledger/im);
|
|
322
|
+
if (ledgerIdx !== -1) {
|
|
323
|
+
const ledgerSection = reportMarkdown.slice(ledgerIdx);
|
|
324
|
+
const sep = ledgerSection.match(/^\|[\s:|-]+\|[ \t]*$/m);
|
|
325
|
+
const body = sep?.index === undefined ? ledgerSection : ledgerSection.slice(sep.index + sep[0].length);
|
|
326
|
+
const claimRows = body.match(/^[|>]\s+\S.*$/gm) ?? [];
|
|
327
|
+
for (const row of claimRows) {
|
|
328
|
+
const hasAnchor = /`[^`]+:\d+`|`[^`]+\.(md|ts|json)`|[a-z][a-z0-9_-]*\/[a-z][a-z0-9_./-]*:[0-9]+/i.test(row);
|
|
329
|
+
if (!hasAnchor) {
|
|
330
|
+
problems.push("evidence-claim-without-anchor");
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return { ok: problems.length === 0, problems };
|
|
336
|
+
}
|
|
337
|
+
var NOT_AVAILABLE = "not available";
|
|
338
|
+
function logicDigest(path) {
|
|
339
|
+
if (path === undefined || path === "" || !existsSync(path))
|
|
340
|
+
return NOT_AVAILABLE;
|
|
341
|
+
try {
|
|
342
|
+
const h = createHash2("sha256");
|
|
343
|
+
if (statSync(path).isDirectory()) {
|
|
344
|
+
const walk = (dir) => readdirSync(dir, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? walk(join(dir, e.name)) : /\.(md|ya?ml)$/.test(e.name) ? [join(dir, e.name)] : []).sort();
|
|
345
|
+
for (const f of walk(path)) {
|
|
346
|
+
h.update(f.slice(path.length));
|
|
347
|
+
h.update(readFileSync(f));
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
h.update(readFileSync(path));
|
|
351
|
+
}
|
|
352
|
+
return h.digest("hex");
|
|
353
|
+
} catch {
|
|
354
|
+
return NOT_AVAILABLE;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function importedSnapshotAsOf(coverage) {
|
|
358
|
+
const stamps = coverage.map((c) => c.lastImportedAt).filter((v) => typeof v === "string" && v !== "");
|
|
359
|
+
if (stamps.length === 0 || stamps.length !== coverage.length)
|
|
360
|
+
return NOT_AVAILABLE;
|
|
361
|
+
return [...stamps].sort()[0] ?? NOT_AVAILABLE;
|
|
362
|
+
}
|
|
363
|
+
function localDay(tz, at = new Date) {
|
|
364
|
+
try {
|
|
365
|
+
return new Intl.DateTimeFormat("en-CA", { timeZone: tz, dateStyle: "short" }).format(at);
|
|
366
|
+
} catch {
|
|
367
|
+
return at.toISOString().slice(0, 10);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function tzOffsetMs(tz, at) {
|
|
371
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat("en-US", {
|
|
372
|
+
timeZone: tz,
|
|
373
|
+
hour12: false,
|
|
374
|
+
year: "numeric",
|
|
375
|
+
month: "2-digit",
|
|
376
|
+
day: "2-digit",
|
|
377
|
+
hour: "2-digit",
|
|
378
|
+
minute: "2-digit",
|
|
379
|
+
second: "2-digit"
|
|
380
|
+
}).formatToParts(at).filter((p) => p.type !== "literal").map((p) => [p.type, p.value]));
|
|
381
|
+
const asUtc = Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day), parts.hour === "24" ? 0 : Number(parts.hour), Number(parts.minute), Number(parts.second));
|
|
382
|
+
const atSec = Math.floor(at.getTime() / 1000) * 1000;
|
|
383
|
+
return asUtc - atSec;
|
|
384
|
+
}
|
|
385
|
+
function zonedDayStart(tz, ymd) {
|
|
386
|
+
const [y, m, d] = ymd.split("-").map(Number);
|
|
387
|
+
const utcMidnight = Date.UTC(y ?? 1970, (m ?? 1) - 1, d ?? 1);
|
|
388
|
+
const guess = new Date(utcMidnight - tzOffsetMs(tz, new Date(utcMidnight)));
|
|
389
|
+
return new Date(utcMidnight - tzOffsetMs(tz, guess));
|
|
390
|
+
}
|
|
391
|
+
function formatZonedIso(tz, at) {
|
|
392
|
+
const off = tzOffsetMs(tz, at);
|
|
393
|
+
const abs = Math.abs(off);
|
|
394
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
395
|
+
const offStr = `${off < 0 ? "-" : "+"}${pad(Math.floor(abs / 3600000))}:${pad(Math.floor(abs % 3600000 / 60000))}`;
|
|
396
|
+
return `${new Date(at.getTime() + off).toISOString().slice(0, 23)}${offStr}`;
|
|
397
|
+
}
|
|
398
|
+
function dayBounds(tz, ymd) {
|
|
399
|
+
const start = zonedDayStart(tz, ymd);
|
|
400
|
+
const nextYmd = localDay(tz, new Date(start.getTime() + 30 * 3600000));
|
|
401
|
+
return {
|
|
402
|
+
since: formatZonedIso(tz, start),
|
|
403
|
+
until: formatZonedIso(tz, new Date(zonedDayStart(tz, nextYmd).getTime() - 1))
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function resolvePaths(opts) {
|
|
407
|
+
const pluginRoot = opts.helper.replace(/\/scripts\/[^/]+$/, "");
|
|
408
|
+
const skill = `${pluginRoot}/skills/history-anatomy`;
|
|
409
|
+
const tz = opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
410
|
+
const date = opts.date !== undefined && opts.date !== "" ? opts.date : localDay(tz, opts.now ?? new Date);
|
|
411
|
+
const target = opts.output !== undefined && opts.output !== "" ? opts.output : `${opts.reportDir}/${date}-history-anatomy.md`;
|
|
412
|
+
const adHoc = opts.mode === "ad-hoc" && !!opts.since && !!opts.until;
|
|
413
|
+
let env = `HA_HELPER=${opts.helper}
|
|
414
|
+
HA_SKILL=${skill}
|
|
415
|
+
HA_TARGET=${target}
|
|
416
|
+
HA_DATE=${date}
|
|
417
|
+
`;
|
|
418
|
+
if (adHoc) {
|
|
419
|
+
return `${env}HA_SINCE=${opts.since}
|
|
420
|
+
HA_UNTIL=${opts.until}
|
|
421
|
+
`;
|
|
422
|
+
}
|
|
423
|
+
const current = dayBounds(tz, date);
|
|
424
|
+
const baseline = dayBounds(tz, localDay(tz, new Date(zonedDayStart(tz, date).getTime() - 12 * 3600000)));
|
|
425
|
+
env += `HA_SINCE=${current.since}
|
|
426
|
+
HA_UNTIL=${current.until}
|
|
427
|
+
`;
|
|
428
|
+
env += `HA_BASELINE_SINCE=${baseline.since}
|
|
429
|
+
HA_BASELINE_UNTIL=${baseline.until}
|
|
430
|
+
`;
|
|
431
|
+
return env;
|
|
432
|
+
}
|
|
433
|
+
function buildProvenance(opts) {
|
|
434
|
+
let raw;
|
|
435
|
+
try {
|
|
436
|
+
raw = JSON.parse(readFileSync(opts.artifact, "utf8"));
|
|
437
|
+
} catch (err) {
|
|
438
|
+
throw new Error(`could not parse fresh analyze artifact at ${opts.artifact}: ${err.message}`);
|
|
439
|
+
}
|
|
440
|
+
const coverage = (raw.coverage ?? []).map((c) => ({
|
|
441
|
+
source: String(c.source ?? ""),
|
|
442
|
+
status: String(c.status ?? ""),
|
|
443
|
+
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt)
|
|
444
|
+
}));
|
|
445
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
446
|
+
const now = opts.now ?? new Date;
|
|
447
|
+
const date = opts.date !== undefined && opts.date !== "" ? opts.date : localDay(tz, now);
|
|
448
|
+
const windowState = opts.mode === "ad-hoc" || date < localDay(tz, now) ? "closed" : "provisional";
|
|
449
|
+
const nowIso = now.toISOString();
|
|
450
|
+
return {
|
|
451
|
+
identity: {
|
|
452
|
+
contractVersion: opts.contractVersion ?? "1",
|
|
453
|
+
mode: opts.mode,
|
|
454
|
+
date,
|
|
455
|
+
timezone: tz,
|
|
456
|
+
bounds: { since: String(raw.selector?.since ?? ""), until: String(raw.selector?.until ?? "") },
|
|
457
|
+
sources: coverage.map((c) => c.source).sort()
|
|
458
|
+
},
|
|
459
|
+
windowState,
|
|
460
|
+
generatedAt: nowIso,
|
|
461
|
+
validatedAt: nowIso,
|
|
462
|
+
artifactDigest: semanticArtifactDigest(raw),
|
|
463
|
+
baselineArtifactDigest: (() => {
|
|
464
|
+
if (!(opts.baseline !== undefined && existsSync(opts.baseline)))
|
|
465
|
+
return null;
|
|
466
|
+
try {
|
|
467
|
+
return semanticArtifactDigest(JSON.parse(readFileSync(opts.baseline, "utf8")));
|
|
468
|
+
} catch (err) {
|
|
469
|
+
throw new Error(`could not parse baseline artifact at ${opts.baseline}: ${err.message}`);
|
|
470
|
+
}
|
|
471
|
+
})(),
|
|
472
|
+
contractDigest: logicDigest(opts.contractFile),
|
|
473
|
+
skillDigest: logicDigest(opts.skillDir),
|
|
474
|
+
workflowDigest: logicDigest(opts.workflowFile),
|
|
475
|
+
coverage,
|
|
476
|
+
runId: opts.runId,
|
|
477
|
+
currentArtifactPath: opts.artifact,
|
|
478
|
+
baselineArtifactPath: opts.baseline ?? null,
|
|
479
|
+
spurVersion: opts.spurVersion ?? NOT_AVAILABLE,
|
|
480
|
+
schemaVersion: typeof raw.schemaVersion === "number" ? raw.schemaVersion : undefined,
|
|
481
|
+
executor: opts.executor ?? NOT_AVAILABLE,
|
|
482
|
+
model: opts.model ?? NOT_AVAILABLE
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function probe(opts) {
|
|
486
|
+
const current = buildProvenance(opts);
|
|
487
|
+
const cachedText = existsSync(opts.target) ? readFileSync(opts.target, "utf8") : null;
|
|
488
|
+
const cached = cachedText === null ? null : parseProvenance(cachedText);
|
|
489
|
+
const decision = opts.mode === "ad-hoc" ? { disposition: "miss", reasons: ["ad-hoc-never-cached"] } : decideCache(cached, current, {
|
|
490
|
+
recompute: opts.recompute,
|
|
491
|
+
dayClosed: current.windowState === "closed"
|
|
492
|
+
});
|
|
493
|
+
current.cacheDisposition = decision.disposition;
|
|
494
|
+
return { decision, current };
|
|
495
|
+
}
|
|
496
|
+
var YAML_KEYS = [
|
|
497
|
+
"windowState",
|
|
498
|
+
"generatedAt",
|
|
499
|
+
"validatedAt",
|
|
500
|
+
"artifactDigest",
|
|
501
|
+
"baselineArtifactDigest",
|
|
502
|
+
"contractDigest",
|
|
503
|
+
"skillDigest",
|
|
504
|
+
"workflowDigest",
|
|
505
|
+
"runId",
|
|
506
|
+
"currentArtifactPath",
|
|
507
|
+
"baselineArtifactPath",
|
|
508
|
+
"spurVersion",
|
|
509
|
+
"schemaVersion",
|
|
510
|
+
"executor",
|
|
511
|
+
"model",
|
|
512
|
+
"cacheDisposition"
|
|
513
|
+
];
|
|
514
|
+
function yamlScalar(v) {
|
|
515
|
+
if (v === null || v === undefined)
|
|
516
|
+
return "null";
|
|
517
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
518
|
+
return String(v);
|
|
519
|
+
return `"${String(v).replaceAll('"', "\\\"")}"`;
|
|
520
|
+
}
|
|
521
|
+
function renderProvenanceFrontmatter(p) {
|
|
522
|
+
const lines = [
|
|
523
|
+
"---",
|
|
524
|
+
"identity:",
|
|
525
|
+
` contractVersion: ${yamlScalar(p.identity.contractVersion)}`,
|
|
526
|
+
` mode: ${p.identity.mode}`,
|
|
527
|
+
` date: ${yamlScalar(p.identity.date)}`,
|
|
528
|
+
` timezone: ${p.identity.timezone}`,
|
|
529
|
+
" bounds:",
|
|
530
|
+
` since: ${p.identity.bounds.since}`,
|
|
531
|
+
` until: ${p.identity.bounds.until}`,
|
|
532
|
+
" sources:"
|
|
533
|
+
];
|
|
534
|
+
for (const s of p.identity.sources)
|
|
535
|
+
lines.push(` - source: ${s}`);
|
|
536
|
+
for (const k of YAML_KEYS) {
|
|
537
|
+
if (p[k] === undefined)
|
|
538
|
+
continue;
|
|
539
|
+
lines.push(`${k}: ${yamlScalar(p[k])}`);
|
|
540
|
+
}
|
|
541
|
+
lines.push("coverage:");
|
|
542
|
+
for (const c of p.coverage) {
|
|
543
|
+
lines.push(` - source: ${c.source}, status: ${c.status}, lastImportedAt: ${c.lastImportedAt ?? "null"}`);
|
|
544
|
+
}
|
|
545
|
+
lines.push("---");
|
|
546
|
+
return lines.join(`
|
|
547
|
+
`);
|
|
548
|
+
}
|
|
549
|
+
function bannerLine(p) {
|
|
550
|
+
return `> imported snapshot as of ${importedSnapshotAsOf(p.coverage)} · window ${p.windowState} · cache ${p.cacheDisposition ?? NOT_AVAILABLE}`;
|
|
551
|
+
}
|
|
552
|
+
function stripHeader(md) {
|
|
553
|
+
const body = md.replace(/^---\n[\s\S]*?\n---\n?/, "").replace(/^\n+/, "");
|
|
554
|
+
return body.replace(/^> imported snapshot as of [^\n]*\n+/, "");
|
|
555
|
+
}
|
|
556
|
+
function stampReport(candidateMarkdown, p) {
|
|
557
|
+
return `${renderProvenanceFrontmatter(p)}
|
|
558
|
+
|
|
559
|
+
${bannerLine(p)}
|
|
560
|
+
|
|
561
|
+
${stripHeader(candidateMarkdown).replace(/^\n+/, "")}`;
|
|
562
|
+
}
|
|
563
|
+
function refreshReport(publishedMarkdown, validatedAt, disposition) {
|
|
564
|
+
const cached = parseProvenance(publishedMarkdown);
|
|
565
|
+
if (cached === null)
|
|
566
|
+
return publishedMarkdown;
|
|
567
|
+
const refreshed = { ...cached, validatedAt, cacheDisposition: disposition };
|
|
568
|
+
return stampReport(publishedMarkdown, refreshed);
|
|
569
|
+
}
|
|
570
|
+
function publishAtomically(candidatePath, targetPath) {
|
|
571
|
+
const tmpPath = `${targetPath}.tmp`;
|
|
572
|
+
try {
|
|
573
|
+
writeFileSync(tmpPath, readFileSync(candidatePath));
|
|
574
|
+
const fd = openSync(tmpPath, "r");
|
|
575
|
+
try {
|
|
576
|
+
fsyncSync(fd);
|
|
577
|
+
} finally {
|
|
578
|
+
closeSync(fd);
|
|
579
|
+
}
|
|
580
|
+
renameSync(tmpPath, targetPath);
|
|
581
|
+
} catch (err) {
|
|
582
|
+
try {
|
|
583
|
+
rmSync(tmpPath, { force: true });
|
|
584
|
+
} catch {}
|
|
585
|
+
throw err;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function porcelainPaths(text) {
|
|
589
|
+
return new Set(text.split(`
|
|
590
|
+
`).map((line) => line.replace(/^\S+\s+/, "").trim()).filter((line) => line.length > 0));
|
|
591
|
+
}
|
|
592
|
+
function diffPorcelain(before, now, expects) {
|
|
593
|
+
const beforePaths = porcelainPaths(before);
|
|
594
|
+
return [...porcelainPaths(now)].filter((p) => !beforePaths.has(p) && !expects.has(p)).sort();
|
|
595
|
+
}
|
|
596
|
+
var VALID_COMMANDS = "digest, check, paths, assert-clean, probe, stamp, refresh, publish";
|
|
597
|
+
var PROBE_USAGE = "<script> probe --artifact <a.json> --target <report.md> [--baseline <b.json>] [--mode daily|ad-hoc] " + "[--date <YYYY-MM-DD>] [--recompute true] [--out <prov.json>] [--skill-dir <d>] [--contract <f>] [--workflow <f>]";
|
|
598
|
+
function parseFlags(args) {
|
|
599
|
+
const out = {};
|
|
600
|
+
for (let i = 0;i < args.length; i++) {
|
|
601
|
+
const a = args[i] ?? "";
|
|
602
|
+
if (!a.startsWith("--"))
|
|
603
|
+
continue;
|
|
604
|
+
const key = a.slice(2);
|
|
605
|
+
const next = args[i + 1];
|
|
606
|
+
if (next === undefined || next.startsWith("--")) {
|
|
607
|
+
out[key] = "true";
|
|
608
|
+
} else {
|
|
609
|
+
out[key] = next;
|
|
610
|
+
i++;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return out;
|
|
614
|
+
}
|
|
615
|
+
function runCacheCli(argv) {
|
|
616
|
+
const [cmd, a, b] = argv;
|
|
617
|
+
switch (cmd) {
|
|
618
|
+
case "digest": {
|
|
619
|
+
if (a === undefined) {
|
|
620
|
+
return { exitCode: 1, stdout: "", stderr: `usage: <script> digest <artifact.json>
|
|
621
|
+
` };
|
|
622
|
+
}
|
|
623
|
+
let artifact;
|
|
624
|
+
try {
|
|
625
|
+
artifact = JSON.parse(readFileSync(a, "utf8"));
|
|
626
|
+
} catch {
|
|
627
|
+
return { exitCode: 1, stdout: "", stderr: `could not parse artifact at ${a}
|
|
628
|
+
` };
|
|
629
|
+
}
|
|
630
|
+
const digest = semanticArtifactDigest(artifact);
|
|
631
|
+
return { exitCode: 0, stdout: `${digest}
|
|
632
|
+
`, stderr: "" };
|
|
633
|
+
}
|
|
634
|
+
case "check": {
|
|
635
|
+
if (a === undefined) {
|
|
636
|
+
return { exitCode: 1, stdout: "", stderr: `usage: <script> check <report.md>
|
|
637
|
+
` };
|
|
638
|
+
}
|
|
639
|
+
const result = checkReportStructure(readFileSync(a, "utf8"));
|
|
640
|
+
const stdout = `${result.ok ? "PASS" : "FAIL"}
|
|
641
|
+
${result.problems.map((p) => `- ${p}
|
|
642
|
+
`).join("")}`;
|
|
643
|
+
return { exitCode: result.ok ? 0 : 1, stdout, stderr: "" };
|
|
644
|
+
}
|
|
645
|
+
case "publish": {
|
|
646
|
+
if (a === undefined || b === undefined) {
|
|
647
|
+
return { exitCode: 1, stdout: "", stderr: `usage: <script> publish <candidate.md> <target.md>
|
|
648
|
+
` };
|
|
649
|
+
}
|
|
650
|
+
publishAtomically(a, b);
|
|
651
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
652
|
+
}
|
|
653
|
+
case "assert-clean": {
|
|
654
|
+
const f = parseFlags(argv.slice(1));
|
|
655
|
+
if (f.baseline === undefined) {
|
|
656
|
+
return {
|
|
657
|
+
exitCode: 1,
|
|
658
|
+
stdout: "",
|
|
659
|
+
stderr: `usage: <script> assert-clean --baseline <porcelain.txt> [--expect <path>]...
|
|
660
|
+
`
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
const expects = new Set;
|
|
664
|
+
for (const arg of argv.slice(1)) {
|
|
665
|
+
if (arg.startsWith("--expect="))
|
|
666
|
+
expects.add(arg.slice("--expect=".length));
|
|
667
|
+
}
|
|
668
|
+
let now;
|
|
669
|
+
try {
|
|
670
|
+
now = spawnSync("git", ["status", "--porcelain"], {
|
|
671
|
+
encoding: "utf8",
|
|
672
|
+
...f.cwd !== undefined ? { cwd: f.cwd } : {}
|
|
673
|
+
}).stdout ?? "";
|
|
674
|
+
} catch {
|
|
675
|
+
return { exitCode: 0, stdout: "", stderr: `assert-clean: git unavailable; skipped
|
|
676
|
+
` };
|
|
677
|
+
}
|
|
678
|
+
const undeclared = diffPorcelain(readFileSync(f.baseline, "utf8"), now, expects);
|
|
679
|
+
if (undeclared.length > 0) {
|
|
680
|
+
return {
|
|
681
|
+
exitCode: 1,
|
|
682
|
+
stdout: "",
|
|
683
|
+
stderr: undeclared.map((p) => `undeclared write: ${p}
|
|
684
|
+
`).join("")
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
return { exitCode: 0, stdout: `clean
|
|
688
|
+
`, stderr: "" };
|
|
689
|
+
}
|
|
690
|
+
case "paths": {
|
|
691
|
+
const f = parseFlags(argv.slice(1));
|
|
692
|
+
if (f.helper === undefined || f.out === undefined) {
|
|
693
|
+
return {
|
|
694
|
+
exitCode: 1,
|
|
695
|
+
stdout: "",
|
|
696
|
+
stderr: `usage: <script> paths --helper <p> --out <env> [--report-dir <d>] [--date <d>] [--output <p>] [--mode <m>] [--since <s>] [--until <u>]
|
|
697
|
+
`
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
writeFileSync(f.out, resolvePaths({
|
|
701
|
+
helper: f.helper,
|
|
702
|
+
reportDir: f["report-dir"] ?? "docs/report",
|
|
703
|
+
date: f.date,
|
|
704
|
+
output: f.output,
|
|
705
|
+
mode: f.mode,
|
|
706
|
+
since: f.since,
|
|
707
|
+
until: f.until
|
|
708
|
+
}));
|
|
709
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
710
|
+
}
|
|
711
|
+
case "probe": {
|
|
712
|
+
const f = parseFlags(argv.slice(1));
|
|
713
|
+
if (f.artifact === undefined || f.target === undefined) {
|
|
714
|
+
return { exitCode: 1, stdout: "", stderr: `usage: ${PROBE_USAGE}
|
|
715
|
+
` };
|
|
716
|
+
}
|
|
717
|
+
let result;
|
|
718
|
+
try {
|
|
719
|
+
result = probe({
|
|
720
|
+
artifact: f.artifact,
|
|
721
|
+
target: f.target,
|
|
722
|
+
baseline: f.baseline,
|
|
723
|
+
mode: f.mode === "ad-hoc" ? "ad-hoc" : "daily",
|
|
724
|
+
date: f.date,
|
|
725
|
+
recompute: f.recompute === "true",
|
|
726
|
+
executor: f.executor,
|
|
727
|
+
model: f.model,
|
|
728
|
+
skillDir: f["skill-dir"],
|
|
729
|
+
contractFile: f.contract,
|
|
730
|
+
workflowFile: f.workflow,
|
|
731
|
+
contractVersion: f["contract-version"],
|
|
732
|
+
runId: f["run-id"],
|
|
733
|
+
spurVersion: f["spur-version"]
|
|
734
|
+
});
|
|
735
|
+
} catch {
|
|
736
|
+
return { exitCode: 1, stdout: "", stderr: `could not read artifact at ${f.artifact}
|
|
737
|
+
` };
|
|
738
|
+
}
|
|
739
|
+
if (f.out !== undefined)
|
|
740
|
+
writeFileSync(f.out, `${JSON.stringify(result.current, null, 2)}
|
|
741
|
+
`);
|
|
742
|
+
const reasons = result.decision.reasons.map((r) => `- ${r}
|
|
743
|
+
`).join("");
|
|
744
|
+
return { exitCode: 0, stdout: `${result.decision.disposition}
|
|
745
|
+
${reasons}`, stderr: "" };
|
|
746
|
+
}
|
|
747
|
+
case "stamp": {
|
|
748
|
+
const f = parseFlags(argv.slice(1));
|
|
749
|
+
if (f.candidate === undefined || f.provenance === undefined || f.out === undefined) {
|
|
750
|
+
return {
|
|
751
|
+
exitCode: 1,
|
|
752
|
+
stdout: "",
|
|
753
|
+
stderr: `usage: <script> stamp --candidate <c.md> --provenance <p.json> --out <o.md>
|
|
754
|
+
`
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
try {
|
|
758
|
+
const p = JSON.parse(readFileSync(f.provenance, "utf8"));
|
|
759
|
+
writeFileSync(f.out, `${stampReport(readFileSync(f.candidate, "utf8"), p)}
|
|
760
|
+
`);
|
|
761
|
+
} catch {
|
|
762
|
+
return { exitCode: 1, stdout: "", stderr: `stamp: could not read candidate or provenance
|
|
763
|
+
` };
|
|
764
|
+
}
|
|
765
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
766
|
+
}
|
|
767
|
+
case "refresh": {
|
|
768
|
+
const f = parseFlags(argv.slice(1));
|
|
769
|
+
if (f.report === undefined || f.out === undefined) {
|
|
770
|
+
return {
|
|
771
|
+
exitCode: 1,
|
|
772
|
+
stdout: "",
|
|
773
|
+
stderr: `usage: <script> refresh --report <published.md> --out <o.md> [--disposition hit]
|
|
774
|
+
`
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
try {
|
|
778
|
+
const disposition = f.disposition ?? "hit";
|
|
779
|
+
const refreshed = refreshReport(readFileSync(f.report, "utf8"), f["validated-at"] ?? new Date().toISOString(), disposition);
|
|
780
|
+
writeFileSync(f.out, refreshed.endsWith(`
|
|
781
|
+
`) ? refreshed : `${refreshed}
|
|
782
|
+
`);
|
|
783
|
+
} catch {
|
|
784
|
+
return { exitCode: 1, stdout: "", stderr: `refresh: could not read report at ${f.report}
|
|
785
|
+
` };
|
|
786
|
+
}
|
|
787
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
788
|
+
}
|
|
789
|
+
default:
|
|
790
|
+
return { exitCode: 1, stdout: "", stderr: `valid commands: ${VALID_COMMANDS}
|
|
791
|
+
` };
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
{
|
|
795
|
+
const { exitCode, stdout, stderr } = runCacheCli(process.argv.slice(2));
|
|
796
|
+
process.stdout.write(stdout);
|
|
797
|
+
process.stderr.write(stderr);
|
|
798
|
+
process.exitCode = exitCode;
|
|
799
|
+
}
|
|
800
|
+
export {
|
|
801
|
+
stampReport,
|
|
802
|
+
semanticArtifactDigest,
|
|
803
|
+
runCacheCli,
|
|
804
|
+
resolvePaths,
|
|
805
|
+
renderProvenanceFrontmatter,
|
|
806
|
+
refreshReport,
|
|
807
|
+
publishAtomically,
|
|
808
|
+
probe,
|
|
809
|
+
porcelainPaths,
|
|
810
|
+
parseProvenance,
|
|
811
|
+
logicDigest,
|
|
812
|
+
importedSnapshotAsOf,
|
|
813
|
+
diffPorcelain,
|
|
814
|
+
decideCache,
|
|
815
|
+
checkReportStructure,
|
|
816
|
+
buildProvenance,
|
|
817
|
+
bannerLine
|
|
818
|
+
};
|