@gobing-ai/spur 0.4.8 → 0.4.10
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 +2 -2
- package/config/rules/README.md +1 -1
- package/config/rules/boundary/config-loading-ownership.yaml +1 -0
- package/config/rules/boundary/env-var-hygiene.yaml +0 -1
- package/config/rules/boundary/sp-plugin-standalone.yaml +1 -1
- package/config/rules/boundary/sp-script-placement.yaml +3 -3
- package/config/rules/docs/sourced-api-claims.yaml +29 -64
- package/config/rules/strict/runtime-boundaries.yaml +40 -1
- package/config/rules/structure/protected-files.yaml +1 -1
- package/config/rules/surface/check-cli-surface.yaml +33 -0
- package/config/rules/typescript/no-debugger.yaml +3 -0
- package/config/workflow-candidates.json +2 -2
- package/config/workflows/feature-verification.yaml +6 -19
- package/config/workflows/history-anatomy.yaml +14 -28
- package/config/workflows/idea-pipeline.yaml +6 -19
- package/config/workflows/pr-review.yaml +9 -16
- package/config/workflows/task-pipeline.yaml +18 -25
- package/config/workflows/wrapup-pipeline.yaml +21 -63
- package/package.json +3 -3
- package/plugins/sp/README.md +70 -37
- package/plugins/sp/agents/expert-spur.md +0 -1
- package/plugins/sp/agents/super-planner.md +5 -5
- package/plugins/sp/agents/super-reviewer.md +2 -2
- package/plugins/sp/commands/dev-changelog.md +1 -1
- package/plugins/sp/commands/dev-daily.md +1 -1
- package/plugins/sp/commands/dev-pr-review.md +1 -1
- package/plugins/sp/commands/dev-review-session.md +1 -1
- package/plugins/sp/commands/dev-runall.md +4 -4
- package/plugins/sp/commands/dev-verify.md +4 -6
- package/plugins/sp/commands/dev-verifyall.md +4 -5
- package/plugins/sp/hooks/hooks.json +11 -1
- package/plugins/sp/lib/context-post-tool.ts +1 -1
- package/plugins/sp/lib/context-session-start.ts +1 -1
- package/plugins/sp/lib/context-session-stop.ts +1 -1
- package/plugins/sp/lib/destructive-policy.ts +65 -1
- package/plugins/sp/plugin.json +2 -5
- package/plugins/sp/{hooks → scripts/hooks}/agent-lifecycle.ts +1 -1
- package/plugins/sp/scripts/hooks/careful-guard.ts +94 -0
- package/plugins/sp/{hooks → scripts/hooks}/context-post-tool.ts +2 -2
- package/plugins/sp/{hooks → scripts/hooks}/context-session-start.ts +1 -1
- package/plugins/sp/{hooks → scripts/hooks}/context-session-stop.ts +1 -1
- package/plugins/sp/{hooks → scripts/hooks}/fleet-guest-stop.ts +6 -4
- package/plugins/sp/{hooks → scripts/hooks}/task-write-guard.ts +38 -21
- package/plugins/sp/skills/brainstorm/SKILL.md +12 -11
- package/plugins/sp/skills/brainstorm/agents/openai.yaml +1 -1
- package/plugins/sp/skills/brainstorm/examples/ideation-example.md +0 -4
- package/plugins/sp/skills/brainstorm/metadata.openclaw +1 -1
- package/plugins/sp/skills/brainstorm/references/workflows.md +4 -14
- package/plugins/sp/skills/code-implementation/SKILL.md +1 -1
- package/plugins/sp/skills/code-verification/SKILL.md +8 -8
- package/plugins/sp/skills/code-verification/references/secu-review.md +4 -4
- package/plugins/sp/skills/code-verification/references/verdict-schema.md +9 -1
- package/plugins/sp/skills/daily-summary/SKILL.md +4 -5
- package/plugins/sp/skills/dogfood-testing/SKILL.md +9 -9
- package/plugins/sp/skills/dogfood-testing/references/report-template.md +1 -1
- package/plugins/sp/skills/history-anatomy/references/modes.md +2 -2
- package/plugins/sp/skills/history-anatomy/references/operations.md +3 -4
- package/plugins/sp/skills/history-anatomy/references/report-contract.md +2 -3
- package/plugins/sp/skills/issue-finding/SKILL.md +1 -1
- package/plugins/sp/skills/next-router/references/routing-table.md +1 -1
- package/plugins/sp/skills/parallel-execution/SKILL.md +2 -2
- package/plugins/sp/skills/parallel-execution/references/result-synthesis.md +9 -10
- package/plugins/sp/skills/pr-reviewing/SKILL.md +14 -15
- package/plugins/sp/skills/reverse-engineering/SKILL.md +4 -6
- package/plugins/sp/skills/session-review/SKILL.md +13 -29
- package/plugins/sp/skills/source-driven-development/SKILL.md +26 -27
- package/plugins/sp/skills/spur-check/SKILL.md +14 -13
- package/plugins/sp/skills/spur-cli/SKILL.md +1 -1
- package/plugins/sp/skills/spur-cli/references/agent.md +17 -2
- package/plugins/sp/skills/spur-cli/references/builder.md +27 -6
- package/plugins/sp/skills/spur-cli/references/features.md +6 -1
- package/plugins/sp/skills/spur-cli/references/history.md +3 -0
- package/plugins/sp/skills/spur-cli/references/self.md +5 -3
- package/plugins/sp/skills/spur-cli/references/tasks/verbs.md +3 -0
- package/plugins/sp/skills/spur-cli/references/tasks.md +13 -3
- package/plugins/sp/skills/spur-cli/references/workflows/authoring-workflows.md +1 -1
- package/plugins/sp/skills/spur-cli/references/workflows.md +36 -1
- package/plugins/sp/skills/spur-dev/SKILL.md +1 -1
- package/plugins/sp/skills/spur-dev/references/cross-cutting.md +1 -1
- package/plugins/sp/skills/spur-dev/references/dev-operations.md +12 -13
- package/plugins/sp/skills/spur-dev/references/execution-batch-report.md +10 -11
- package/plugins/sp/skills/spur-dev/references/execution-batch.md +16 -17
- package/plugins/sp/skills/spur-dev/references/execution-parallel-isolation.md +1 -1
- package/plugins/sp/skills/spur-dev/references/execution-worktree-landing.md +9 -12
- package/plugins/sp/skills/spur-dev/references/execution-worktree-setup.md +6 -8
- package/plugins/sp/skills/spur-dev/references/gate-checklists.md +1 -1
- package/plugins/sp/skills/spur-dev/references/inline-pipeline-driver.md +33 -40
- package/plugins/sp/skills/spur-dev/references/structured-trace-emission.md +24 -24
- package/plugins/sp/skills/spur-doctor/SKILL.md +5 -4
- package/spur.js +12726 -1456
- package/web/_astro/{BoardApp.CaNvQBD_.js → BoardApp.B5rTVNd_.js} +1 -1
- package/web/_astro/{BoardApp.C5jnkkKP.js → BoardApp.BMprmPRc.js} +141 -141
- package/web/_astro/{TaskDetail.DGKndhI8.js → TaskDetail.Ddsur8qd.js} +1 -1
- package/web/_astro/{arc.DHrwdg3G.js → arc.DLqVVBxP.js} +1 -1
- package/web/_astro/{architectureDiagram-3BPJPVTR.pvKpK1s5.js → architectureDiagram-3BPJPVTR.C-Pk3uAi.js} +1 -1
- package/web/_astro/{blockDiagram-GPEHLZMM.BQmRcZsS.js → blockDiagram-GPEHLZMM.BRO1i_Nm.js} +1 -1
- package/web/_astro/{c4Diagram-AAUBKEIU.CCLjHeH1.js → c4Diagram-AAUBKEIU.BU_cWu6e.js} +1 -1
- package/web/_astro/channel.Bs3Illhy.js +1 -0
- package/web/_astro/{chunk-2J33WTMH.DL6Yuoma.js → chunk-2J33WTMH.D2VXiQ2t.js} +1 -1
- package/web/_astro/{chunk-4BX2VUAB.CzlyEI7l.js → chunk-4BX2VUAB.BcHT772J.js} +1 -1
- package/web/_astro/{chunk-55IACEB6.B60EWxp1.js → chunk-55IACEB6.DhDtICmo.js} +1 -1
- package/web/_astro/{chunk-727SXJPM.c7v_fRLo.js → chunk-727SXJPM.BoKHp7gV.js} +1 -1
- package/web/_astro/{chunk-AQP2D5EJ.8BxLWdDc.js → chunk-AQP2D5EJ.Chu4JRpE.js} +1 -1
- package/web/_astro/{chunk-FMBD7UC4.DmKuxGFT.js → chunk-FMBD7UC4.wHdwKPlq.js} +1 -1
- package/web/_astro/{chunk-ND2GUHAM.1Zwd4mqV.js → chunk-ND2GUHAM.ffN-M1JB.js} +1 -1
- package/web/_astro/{chunk-QZHKN3VN.BvYLu-A1.js → chunk-QZHKN3VN.FRubwg4S.js} +1 -1
- package/web/_astro/{classDiagram-4FO5ZUOK.CEqRt0WU.js → classDiagram-4FO5ZUOK.c22tQsc_.js} +1 -1
- package/web/_astro/{classDiagram-v2-Q7XG4LA2.CEqRt0WU.js → classDiagram-v2-Q7XG4LA2.c22tQsc_.js} +1 -1
- package/web/_astro/{cose-bilkent-S5V4N54A.C7JiUdj2.js → cose-bilkent-S5V4N54A.B9c6fiSj.js} +1 -1
- package/web/_astro/{cynefin-OW5HDTMX.B6mZ-1be.js → cynefin-OW5HDTMX.DrZsrUHl.js} +1 -1
- package/web/_astro/{dagre-BM42HDAG.BuryfDy6.js → dagre-BM42HDAG.DG1U4b3y.js} +1 -1
- package/web/_astro/{diagram-2AECGRRQ.dao39YQM.js → diagram-2AECGRRQ.CH15b-K3.js} +1 -1
- package/web/_astro/{diagram-5GNKFQAL.lnGZe4At.js → diagram-5GNKFQAL.BH1j7twR.js} +1 -1
- package/web/_astro/{diagram-KO2AKTUF.uWfhzEfT.js → diagram-KO2AKTUF.q2zCkbAj.js} +1 -1
- package/web/_astro/{diagram-LMA3HP47.ppq8-198.js → diagram-LMA3HP47.BLaaZnHV.js} +1 -1
- package/web/_astro/{diagram-OG6HWLK6.CKSCqDt5.js → diagram-OG6HWLK6.BcpRdQwI.js} +1 -1
- package/web/_astro/{erDiagram-TEJ5UH35.sFSf2yBN.js → erDiagram-TEJ5UH35.D7KBlqfM.js} +1 -1
- package/web/_astro/{flowDiagram-I6XJVG4X.BJQjKLbz.js → flowDiagram-I6XJVG4X.D_gmuRqg.js} +1 -1
- package/web/_astro/{ganttDiagram-6RSMTGT7.DAHKNj2N.js → ganttDiagram-6RSMTGT7.DzgWYniD.js} +1 -1
- package/web/_astro/{gitGraphDiagram-PVQCEYII.BlmzcW_O.js → gitGraphDiagram-PVQCEYII.576i3hm3.js} +1 -1
- package/web/_astro/index.DiC1a6lh.css +1 -0
- package/web/_astro/{infoDiagram-5YYISTIA.DGhjaqsi.js → infoDiagram-5YYISTIA.DMCclBiz.js} +1 -1
- package/web/_astro/{ishikawaDiagram-YF4QCWOH.gKIpgt6F.js → ishikawaDiagram-YF4QCWOH.9Kyca4SH.js} +1 -1
- package/web/_astro/{journeyDiagram-JHISSGLW.DG3tmP0R.js → journeyDiagram-JHISSGLW.chbdG-8q.js} +1 -1
- package/web/_astro/{kanban-definition-UN3LZRKU.CgHDSxkR.js → kanban-definition-UN3LZRKU.Bds54-e0.js} +1 -1
- package/web/_astro/{linear.BuGEpcuM.js → linear.D5ND9GN_.js} +1 -1
- package/web/_astro/{mermaid.core.DBVqkWBp.js → mermaid.core.D9N_PGbj.js} +4 -4
- package/web/_astro/{mindmap-definition-RKZ34NQL.D-kOcji9.js → mindmap-definition-RKZ34NQL.t0xop5vp.js} +1 -1
- package/web/_astro/{pieDiagram-4H26LBE5.BvGPwtZt.js → pieDiagram-4H26LBE5.DqgKh6hM.js} +1 -1
- package/web/_astro/{quadrantDiagram-W4KKPZXB.BKb_9FV6.js → quadrantDiagram-W4KKPZXB.DeuHVi2t.js} +1 -1
- package/web/_astro/{requirementDiagram-4Y6WPE33.Cx0fvD8v.js → requirementDiagram-4Y6WPE33.BdYFSG4W.js} +1 -1
- package/web/_astro/{sankeyDiagram-5OEKKPKP.fatULi0W.js → sankeyDiagram-5OEKKPKP.k1LPPETJ.js} +1 -1
- package/web/_astro/{sequenceDiagram-3UESZ5HK.ChHyKqco.js → sequenceDiagram-3UESZ5HK.DdyfpzoG.js} +1 -1
- package/web/_astro/{stateDiagram-AJRCARHV.BdUpKWyj.js → stateDiagram-AJRCARHV.DSEI8il0.js} +1 -1
- package/web/_astro/{stateDiagram-v2-BHNVJYJU.fmJxqIm5.js → stateDiagram-v2-BHNVJYJU.CoMnQRKo.js} +1 -1
- package/web/_astro/{timeline-definition-PNZ67QCA.BayDn5-V.js → timeline-definition-PNZ67QCA.DM1AHNm-.js} +1 -1
- package/web/_astro/{vennDiagram-CIIHVFJN.Bm2Aggwa.js → vennDiagram-CIIHVFJN.C-cJmVtl.js} +1 -1
- package/web/_astro/{wardleyDiagram-YWT4CUSO.DI75O-uG.js → wardleyDiagram-YWT4CUSO.D0xMzKPb.js} +1 -1
- package/web/_astro/{xychartDiagram-2RQKCTM6.DL90E7Q7.js → xychartDiagram-2RQKCTM6.BH5xJcEq.js} +1 -1
- package/web/index.html +2 -2
- package/config/plugin-scripts.json +0 -116
- package/config/script-placement-baseline.json +0 -33
- package/plugins/sp/hooks/careful-guard.ts +0 -74
- package/plugins/sp/hooks/pi/guard-extension.ts +0 -304
- package/plugins/sp/lib/dogfood-pipeline.ts +0 -265
- package/plugins/sp/lib/dogfood-report.ts +0 -278
- package/plugins/sp/lib/history-anatomy.generated.d.mts +0 -112
- package/plugins/sp/lib/history-anatomy.generated.mjs +0 -691
- package/plugins/sp/lib/idea-handoff.generated.d.mts +0 -17
- package/plugins/sp/lib/idea-handoff.generated.mjs +0 -1446
- package/plugins/sp/lib/inline-run-app.ts +0 -68
- package/plugins/sp/lib/inline-run.generated.d.mts +0 -37
- package/plugins/sp/lib/inline-run.generated.mjs +0 -3103
- package/plugins/sp/lib/plan-projection.generated.d.mts +0 -197
- package/plugins/sp/lib/plan-projection.generated.mjs +0 -982
- package/plugins/sp/lib/quality-gate.generated.d.mts +0 -139
- package/plugins/sp/lib/quality-gate.generated.mjs +0 -30510
- package/plugins/sp/lib/residual-scan.generated.d.mts +0 -93
- package/plugins/sp/lib/residual-scan.generated.mjs +0 -383
- package/plugins/sp/lib/run-summary-core.ts +0 -225
- package/plugins/sp/lib/spur-bin.ts +0 -36
- package/plugins/sp/lib/step-profile.generated.d.mts +0 -71
- package/plugins/sp/lib/step-profile.generated.mjs +0 -174
- package/plugins/sp/lib/transcript.ts +0 -112
- package/plugins/sp/scripts/batch-plan.mjs +0 -1096
- package/plugins/sp/scripts/batch-plan.ts +0 -145
- package/plugins/sp/scripts/batch-preflight.mjs +0 -423
- package/plugins/sp/scripts/batch-preflight.ts +0 -270
- package/plugins/sp/scripts/commit-guard.mjs +0 -226
- package/plugins/sp/scripts/commit-guard.ts +0 -248
- package/plugins/sp/scripts/daily-summary/daily-summary.mjs +0 -626
- package/plugins/sp/scripts/daily-summary/daily-summary.ts +0 -855
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +0 -211
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +0 -110
- package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +0 -282
- package/plugins/sp/scripts/dogfood-testing/validate-report.ts +0 -98
- package/plugins/sp/scripts/feature-verification-steps.mjs +0 -82
- package/plugins/sp/scripts/feature-verification-steps.ts +0 -164
- package/plugins/sp/scripts/history-anatomy-cache.mjs +0 -931
- package/plugins/sp/scripts/history-anatomy-cache.ts +0 -247
- package/plugins/sp/scripts/idea-handoff.mjs +0 -32
- package/plugins/sp/scripts/idea-handoff.ts +0 -47
- package/plugins/sp/scripts/inline-run-dispatch.mjs +0 -131
- package/plugins/sp/scripts/inline-run-dispatch.ts +0 -115
- package/plugins/sp/scripts/inline-run-setup.mjs +0 -746
- package/plugins/sp/scripts/inline-run-setup.ts +0 -198
- package/plugins/sp/scripts/persist-out-check.mjs +0 -217
- package/plugins/sp/scripts/persist-out-check.ts +0 -249
- package/plugins/sp/scripts/pr-reviewing.mjs +0 -712
- package/plugins/sp/scripts/pr-reviewing.ts +0 -952
- package/plugins/sp/scripts/quality-gate.mjs +0 -30491
- package/plugins/sp/scripts/quality-gate.ts +0 -80
- package/plugins/sp/scripts/residual-scan.mjs +0 -634
- package/plugins/sp/scripts/residual-scan.ts +0 -248
- package/plugins/sp/scripts/run-summary.mjs +0 -758
- package/plugins/sp/scripts/run-summary.ts +0 -107
- package/plugins/sp/scripts/script-root.mjs +0 -129
- package/plugins/sp/scripts/script-root.ts +0 -199
- package/plugins/sp/scripts/session-timeline.mjs +0 -359
- package/plugins/sp/scripts/session-timeline.ts +0 -190
- package/plugins/sp/scripts/task-diffstat.mjs +0 -181
- package/plugins/sp/scripts/task-diffstat.ts +0 -219
- package/plugins/sp/scripts/workflow-step-profile.mjs +0 -338
- package/plugins/sp/scripts/workflow-step-profile.ts +0 -165
- package/plugins/sp/scripts/wrapup-drift-probe.mjs +0 -190
- package/plugins/sp/scripts/wrapup-drift-probe.ts +0 -261
- package/plugins/sp/scripts/wrapup-steps.mjs +0 -627
- package/plugins/sp/scripts/wrapup-steps.ts +0 -891
- package/web/_astro/channel.C7wG9RxA.js +0 -1
- package/web/_astro/index.BCY1JJHd.css +0 -1
|
@@ -1,691 +0,0 @@
|
|
|
1
|
-
// packages/app/src/services/history-anatomy.ts
|
|
2
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
3
|
-
import {
|
|
4
|
-
closeSync,
|
|
5
|
-
existsSync,
|
|
6
|
-
fsyncSync,
|
|
7
|
-
openSync,
|
|
8
|
-
readdirSync,
|
|
9
|
-
readFileSync,
|
|
10
|
-
renameSync,
|
|
11
|
-
rmSync,
|
|
12
|
-
statSync,
|
|
13
|
-
writeFileSync
|
|
14
|
-
} from "node:fs";
|
|
15
|
-
import { join } from "node:path";
|
|
16
|
-
|
|
17
|
-
// packages/domain/src/analytics/artifact-digest.ts
|
|
18
|
-
import { createHash } from "node:crypto";
|
|
19
|
-
var ARTIFACT_ARRAY_CLASSIFICATION = {
|
|
20
|
-
byTool: "ranked",
|
|
21
|
-
bySession: "ranked",
|
|
22
|
-
topStepsByTokens: "ranked",
|
|
23
|
-
topStepsByDuration: "ranked",
|
|
24
|
-
topSteps: "ranked",
|
|
25
|
-
bottlenecks: "ranked",
|
|
26
|
-
coverage: "set",
|
|
27
|
-
daily: "set",
|
|
28
|
-
loops: "set",
|
|
29
|
-
warnings: "set",
|
|
30
|
-
pairings: "set",
|
|
31
|
-
ladderSnapshot: "set",
|
|
32
|
-
stepSupport: "set",
|
|
33
|
-
phases: "set",
|
|
34
|
-
tools: "set",
|
|
35
|
-
skills: "set",
|
|
36
|
-
sources: "set",
|
|
37
|
-
models: "set"
|
|
38
|
-
};
|
|
39
|
-
var RANKED_ARTIFACT_KEYS = new Set(Object.entries(ARTIFACT_ARRAY_CLASSIFICATION).filter(([, kind]) => kind === "ranked").map(([key]) => key));
|
|
40
|
-
function canonicalize(value, key) {
|
|
41
|
-
if (key === "generatedAt" || key === "validatedAt" || key === "baselineArtifactDigest")
|
|
42
|
-
return null;
|
|
43
|
-
if (Array.isArray(value)) {
|
|
44
|
-
const raw = value.map((v) => JSON.stringify(canonicalize(v, "")));
|
|
45
|
-
return RANKED_ARTIFACT_KEYS.has(key) ? raw : [...raw].sort();
|
|
46
|
-
}
|
|
47
|
-
if (value !== null && typeof value === "object") {
|
|
48
|
-
const out = {};
|
|
49
|
-
for (const k of Object.keys(value).sort()) {
|
|
50
|
-
out[k] = canonicalize(value[k], k);
|
|
51
|
-
}
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
function semanticArtifactDigest(artifactJson) {
|
|
57
|
-
const material = JSON.stringify(canonicalize(artifactJson, "root"));
|
|
58
|
-
return createHash("sha256").update(material).digest("hex");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// packages/app/src/services/history-anatomy.ts
|
|
62
|
-
var REPORT_SECTIONS = [
|
|
63
|
-
"Scope and provenance",
|
|
64
|
-
"Executive summary",
|
|
65
|
-
"Baseline comparison",
|
|
66
|
-
"Findings",
|
|
67
|
-
"Recurrence ledger",
|
|
68
|
-
"Telemetry gaps",
|
|
69
|
-
"Remediation options",
|
|
70
|
-
"Performance analysis",
|
|
71
|
-
"Workflow and process improvements",
|
|
72
|
-
"Report-only advisories",
|
|
73
|
-
"Positive patterns",
|
|
74
|
-
"Evidence ledger"
|
|
75
|
-
];
|
|
76
|
-
var FINDING_FIELDS = [
|
|
77
|
-
"key",
|
|
78
|
-
"category",
|
|
79
|
-
"impact",
|
|
80
|
-
"trend",
|
|
81
|
-
"observation",
|
|
82
|
-
"inference",
|
|
83
|
-
"confidence",
|
|
84
|
-
"contradictions",
|
|
85
|
-
"evidenceAnchor",
|
|
86
|
-
"severity",
|
|
87
|
-
"reproCommand",
|
|
88
|
-
"ownerSurface"
|
|
89
|
-
];
|
|
90
|
-
function parseScalar(raw) {
|
|
91
|
-
const t = raw.trim();
|
|
92
|
-
if (t.startsWith('"') && t.endsWith('"'))
|
|
93
|
-
return t.slice(1, -1).replaceAll("\\\"", '"');
|
|
94
|
-
if (t === "null")
|
|
95
|
-
return null;
|
|
96
|
-
return t;
|
|
97
|
-
}
|
|
98
|
-
function parseBlock(text) {
|
|
99
|
-
const obj = {};
|
|
100
|
-
const lines = text.split(`
|
|
101
|
-
`);
|
|
102
|
-
for (let i = 0;i < lines.length; i++) {
|
|
103
|
-
const line = lines[i] ?? "";
|
|
104
|
-
if (/^\s*$/.test(line) || /^\s*#/.test(line) || /^-\s+/.test(line.trim()))
|
|
105
|
-
continue;
|
|
106
|
-
const indent = line.search(/\S/);
|
|
107
|
-
const eq = line.indexOf(":");
|
|
108
|
-
if (eq === -1)
|
|
109
|
-
continue;
|
|
110
|
-
const key = line.slice(0, eq).trim();
|
|
111
|
-
const val = parseScalar(line.slice(eq + 1).trim());
|
|
112
|
-
let consumed = 0;
|
|
113
|
-
const next = lines[i + 1];
|
|
114
|
-
if ((val === "" || val === undefined) && /^\s*-\s+/.test(next ?? "")) {
|
|
115
|
-
const items = [];
|
|
116
|
-
let j = i + 1;
|
|
117
|
-
while (j < lines.length && /^\s*-\s+/.test(lines[j] ?? "")) {
|
|
118
|
-
const entry = {};
|
|
119
|
-
for (const part of (lines[j] ?? "").trim().replace(/^-\s+/, "").split(",")) {
|
|
120
|
-
const e = part.indexOf(":");
|
|
121
|
-
if (e === -1)
|
|
122
|
-
continue;
|
|
123
|
-
entry[part.slice(0, e).trim()] = parseScalar(part.slice(e + 1).trim());
|
|
124
|
-
}
|
|
125
|
-
items.push(entry);
|
|
126
|
-
j++;
|
|
127
|
-
}
|
|
128
|
-
obj[key] = items;
|
|
129
|
-
consumed = j - i - 1;
|
|
130
|
-
} else if (val === "" || val === undefined) {
|
|
131
|
-
const block = [];
|
|
132
|
-
let j = i + 1;
|
|
133
|
-
while (j < lines.length) {
|
|
134
|
-
const nl = lines[j] ?? "";
|
|
135
|
-
if (nl.trim() === "") {
|
|
136
|
-
block.push("");
|
|
137
|
-
j++;
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const nind = nl.search(/\S/);
|
|
141
|
-
if (nind <= indent)
|
|
142
|
-
break;
|
|
143
|
-
block.push(nl);
|
|
144
|
-
j++;
|
|
145
|
-
}
|
|
146
|
-
obj[key] = parseBlock(block.join(`
|
|
147
|
-
`));
|
|
148
|
-
consumed = j - i - 1;
|
|
149
|
-
} else {
|
|
150
|
-
obj[key] = val;
|
|
151
|
-
}
|
|
152
|
-
i += consumed;
|
|
153
|
-
}
|
|
154
|
-
return obj;
|
|
155
|
-
}
|
|
156
|
-
function readSourceName(s) {
|
|
157
|
-
if (s !== null && typeof s === "object")
|
|
158
|
-
return String(s.source ?? "");
|
|
159
|
-
return String(s);
|
|
160
|
-
}
|
|
161
|
-
var DISPOSITIONS = ["hit", "miss", "forced-recompute"];
|
|
162
|
-
function optionalString(v) {
|
|
163
|
-
return v == null || v === "" ? undefined : String(v);
|
|
164
|
-
}
|
|
165
|
-
function parseProvenance(reportMarkdown) {
|
|
166
|
-
const match = reportMarkdown.match(/^---\n([\s\S]*?)\n---/);
|
|
167
|
-
if (match === null)
|
|
168
|
-
return null;
|
|
169
|
-
try {
|
|
170
|
-
const obj = parseBlock(match[1] ?? "");
|
|
171
|
-
const identity = obj.identity;
|
|
172
|
-
const coverage = obj.coverage;
|
|
173
|
-
if (identity === undefined || !Array.isArray(coverage))
|
|
174
|
-
return null;
|
|
175
|
-
const bounds = identity.bounds;
|
|
176
|
-
if (bounds === undefined || typeof bounds.since !== "string" || typeof bounds.until !== "string") {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
identity: {
|
|
181
|
-
contractVersion: String(identity.contractVersion ?? ""),
|
|
182
|
-
mode: identity.mode === "ad-hoc" ? "ad-hoc" : "daily",
|
|
183
|
-
date: String(identity.date ?? ""),
|
|
184
|
-
timezone: String(identity.timezone ?? ""),
|
|
185
|
-
bounds: { since: bounds.since, until: bounds.until },
|
|
186
|
-
sources: Array.isArray(identity.sources) ? identity.sources.map(readSourceName) : []
|
|
187
|
-
},
|
|
188
|
-
windowState: obj.windowState === "closed" ? "closed" : "provisional",
|
|
189
|
-
generatedAt: String(obj.generatedAt ?? ""),
|
|
190
|
-
validatedAt: String(obj.validatedAt ?? ""),
|
|
191
|
-
artifactDigest: String(obj.artifactDigest ?? ""),
|
|
192
|
-
baselineArtifactDigest: obj.baselineArtifactDigest == null ? null : String(obj.baselineArtifactDigest),
|
|
193
|
-
contractDigest: String(obj.contractDigest ?? ""),
|
|
194
|
-
skillDigest: String(obj.skillDigest ?? ""),
|
|
195
|
-
workflowDigest: String(obj.workflowDigest ?? ""),
|
|
196
|
-
helperDigest: String(obj.helperDigest ?? ""),
|
|
197
|
-
coverage: coverage.map((c) => ({
|
|
198
|
-
source: String(c.source ?? ""),
|
|
199
|
-
status: String(c.status ?? ""),
|
|
200
|
-
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt)
|
|
201
|
-
})),
|
|
202
|
-
runId: optionalString(obj.runId),
|
|
203
|
-
currentArtifactPath: optionalString(obj.currentArtifactPath),
|
|
204
|
-
baselineArtifactPath: obj.baselineArtifactPath == null ? null : String(obj.baselineArtifactPath),
|
|
205
|
-
spurVersion: optionalString(obj.spurVersion),
|
|
206
|
-
schemaVersion: obj.schemaVersion == null ? undefined : Number(obj.schemaVersion),
|
|
207
|
-
executor: optionalString(obj.executor),
|
|
208
|
-
model: optionalString(obj.model),
|
|
209
|
-
cacheDisposition: DISPOSITIONS.includes(obj.cacheDisposition) ? obj.cacheDisposition : undefined
|
|
210
|
-
};
|
|
211
|
-
} catch {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function decideCache(cached, current, opts) {
|
|
216
|
-
if (opts.recompute)
|
|
217
|
-
return { disposition: "forced-recompute", reasons: ["recompute"] };
|
|
218
|
-
if (cached === null)
|
|
219
|
-
return { disposition: "miss", reasons: ["no-cache"] };
|
|
220
|
-
const reasons = [];
|
|
221
|
-
const id = cached.identity;
|
|
222
|
-
const cur = current.identity;
|
|
223
|
-
if (id.contractVersion !== cur.contractVersion)
|
|
224
|
-
reasons.push("identity:contractVersion");
|
|
225
|
-
if (id.mode !== cur.mode)
|
|
226
|
-
reasons.push("identity:mode");
|
|
227
|
-
if (id.date !== cur.date)
|
|
228
|
-
reasons.push("identity:date");
|
|
229
|
-
if (id.timezone !== cur.timezone)
|
|
230
|
-
reasons.push("identity:timezone");
|
|
231
|
-
if (id.bounds.since !== cur.bounds.since || id.bounds.until !== cur.bounds.until)
|
|
232
|
-
reasons.push("identity:bounds");
|
|
233
|
-
if ([...id.sources].sort().join("\x00") !== [...cur.sources].sort().join("\x00"))
|
|
234
|
-
reasons.push("identity:sources");
|
|
235
|
-
if (cached.artifactDigest !== current.artifactDigest)
|
|
236
|
-
reasons.push("data-changed");
|
|
237
|
-
if (cached.contractDigest !== current.contractDigest)
|
|
238
|
-
reasons.push("logic-changed:contract");
|
|
239
|
-
if (cached.skillDigest !== current.skillDigest)
|
|
240
|
-
reasons.push("logic-changed:skill");
|
|
241
|
-
if (cached.workflowDigest !== current.workflowDigest)
|
|
242
|
-
reasons.push("logic-changed:workflow");
|
|
243
|
-
if (cached.helperDigest !== current.helperDigest)
|
|
244
|
-
reasons.push("logic-changed:helper");
|
|
245
|
-
const currentSources = new Set(current.coverage.map((c) => c.source));
|
|
246
|
-
if (cached.coverage.some((c) => !currentSources.has(c.source)))
|
|
247
|
-
reasons.push("coverage-degraded");
|
|
248
|
-
if (cached.windowState === "provisional" && opts.dayClosed)
|
|
249
|
-
reasons.push("window-closed");
|
|
250
|
-
return { disposition: reasons.length === 0 ? "hit" : "miss", reasons };
|
|
251
|
-
}
|
|
252
|
-
function escapeRe(s) {
|
|
253
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
254
|
-
}
|
|
255
|
-
var FINDING_CATEGORIES = [
|
|
256
|
-
"reliability",
|
|
257
|
-
"repetition",
|
|
258
|
-
"workflow",
|
|
259
|
-
"performance",
|
|
260
|
-
"coverage",
|
|
261
|
-
"telemetry",
|
|
262
|
-
"positive"
|
|
263
|
-
];
|
|
264
|
-
var FINDING_CONFIDENCES = ["high", "medium", "low"];
|
|
265
|
-
function checkReportStructure(reportMarkdown) {
|
|
266
|
-
const problems = [];
|
|
267
|
-
if (/TODO|PLACEHOLDER|FIXME|^\|\s*\|/im.test(reportMarkdown))
|
|
268
|
-
problems.push("placeholder-or-todo-present");
|
|
269
|
-
let lastIdx = -1;
|
|
270
|
-
for (const section of REPORT_SECTIONS) {
|
|
271
|
-
const re = new RegExp(`^#{2,3}\\s+${escapeRe(section)}\\s*$`, "m");
|
|
272
|
-
const m = reportMarkdown.match(re);
|
|
273
|
-
if (m === null || (m.index ?? -1) <= lastIdx) {
|
|
274
|
-
problems.push(`section-missing-or-out-of-order:${section}`);
|
|
275
|
-
} else if (m.index !== undefined) {
|
|
276
|
-
lastIdx = m.index;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const findingsIdx = reportMarkdown.search(/^##\s+Findings\s*$/im);
|
|
280
|
-
if (findingsIdx !== -1) {
|
|
281
|
-
const tail = reportMarkdown.slice(findingsIdx);
|
|
282
|
-
const nextSection = tail.slice(1).search(/^##\s+/im);
|
|
283
|
-
const findingsBody = nextSection === -1 ? tail : tail.slice(0, nextSection + 1);
|
|
284
|
-
const catAlt = FINDING_CATEGORIES.join("|");
|
|
285
|
-
const knownRows = findingsBody.match(new RegExp(`^\\|\\s*(?:${catAlt}):[^|]+`, "gm")) ?? [];
|
|
286
|
-
const invalidRows = findingsBody.match(/^\|\s*([^|:\s][^|:]*):[^|]+/gm) ?? [];
|
|
287
|
-
for (const row of [...new Set([...knownRows, ...invalidRows])]) {
|
|
288
|
-
const seg = row.match(/^\|\s*([^:|]+):/)?.[1];
|
|
289
|
-
if (seg !== undefined && !FINDING_CATEGORIES.includes(seg.trim())) {
|
|
290
|
-
problems.push(`finding-invalid-key-category:${seg.trim()}`);
|
|
291
|
-
}
|
|
292
|
-
const rowLower = row.toLowerCase();
|
|
293
|
-
for (const field of FINDING_FIELDS) {
|
|
294
|
-
if (!rowLower.includes(field.toLowerCase()))
|
|
295
|
-
problems.push(`finding-missing-field:${field}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const blocks = findingsBody.split(/^###\s+/m).slice(1);
|
|
299
|
-
for (const block of blocks) {
|
|
300
|
-
if (!block.includes("`key`") && !/\|\s*key\s*:/.test(block))
|
|
301
|
-
continue;
|
|
302
|
-
for (const field of FINDING_FIELDS) {
|
|
303
|
-
if (!block.includes(field))
|
|
304
|
-
problems.push(`finding-missing-field:${field}`);
|
|
305
|
-
}
|
|
306
|
-
if (!/(^|[\s`])P[123]([\s`.]|$)/.test(block) && !block.includes("symbolic-severity")) {
|
|
307
|
-
problems.push("finding-invalid-severity");
|
|
308
|
-
}
|
|
309
|
-
const confValue = block.match(/`confidence`\s*[:=]\s*`?([^`\n]*?)`?\s*(?:\n|$)/)?.[1]?.trim();
|
|
310
|
-
if (confValue !== undefined && confValue !== "" && !FINDING_CONFIDENCES.includes(confValue.toLowerCase())) {
|
|
311
|
-
problems.push(`finding-invalid-confidence:${confValue}`);
|
|
312
|
-
}
|
|
313
|
-
const catValue = block.match(/`category`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1];
|
|
314
|
-
if (catValue && !FINDING_CATEGORIES.includes(catValue.trim())) {
|
|
315
|
-
problems.push(`finding-invalid-category:${catValue.trim()}`);
|
|
316
|
-
}
|
|
317
|
-
const keyValue = block.match(/`key`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1] ?? "";
|
|
318
|
-
const firstSegment = keyValue.split(":")[0]?.trim() ?? "";
|
|
319
|
-
if (keyValue !== "" && !FINDING_CATEGORIES.includes(firstSegment)) {
|
|
320
|
-
problems.push(`finding-invalid-key-category:${firstSegment}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
const ledgerIdx = reportMarkdown.search(/^#{2,3}\s+Evidence\s+ledger/im);
|
|
325
|
-
if (ledgerIdx !== -1) {
|
|
326
|
-
const ledgerSection = reportMarkdown.slice(ledgerIdx);
|
|
327
|
-
const sep = ledgerSection.match(/^\|[\s:|-]+\|[ \t]*$/m);
|
|
328
|
-
const body = sep?.index === undefined ? ledgerSection : ledgerSection.slice(sep.index + sep[0].length);
|
|
329
|
-
const claimRows = body.match(/^[|>]\s+\S.*$/gm) ?? [];
|
|
330
|
-
for (const row of claimRows) {
|
|
331
|
-
const hasAnchor = /`[^`]+:\d+`|`[^`]+\.(md|ts|json)`|[a-z][a-z0-9_-]*\/[a-z][a-z0-9_./-]*:[0-9]+/i.test(row);
|
|
332
|
-
if (!hasAnchor) {
|
|
333
|
-
problems.push("evidence-claim-without-anchor");
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return { ok: problems.length === 0, problems };
|
|
339
|
-
}
|
|
340
|
-
var NOT_AVAILABLE = "not available";
|
|
341
|
-
function logicDigest(path) {
|
|
342
|
-
if (path === undefined || path === "" || !existsSync(path))
|
|
343
|
-
return NOT_AVAILABLE;
|
|
344
|
-
try {
|
|
345
|
-
const h = createHash2("sha256");
|
|
346
|
-
if (statSync(path).isDirectory()) {
|
|
347
|
-
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();
|
|
348
|
-
for (const f of walk(path)) {
|
|
349
|
-
h.update(f.slice(path.length));
|
|
350
|
-
h.update(readFileSync(f));
|
|
351
|
-
}
|
|
352
|
-
} else {
|
|
353
|
-
h.update(readFileSync(path));
|
|
354
|
-
}
|
|
355
|
-
return h.digest("hex");
|
|
356
|
-
} catch {
|
|
357
|
-
return NOT_AVAILABLE;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function importedSnapshotAsOf(coverage) {
|
|
361
|
-
const stamps = coverage.map((c) => c.lastImportedAt).filter((v) => typeof v === "string" && v !== "");
|
|
362
|
-
if (stamps.length === 0 || stamps.length !== coverage.length)
|
|
363
|
-
return NOT_AVAILABLE;
|
|
364
|
-
return [...stamps].sort()[0] ?? NOT_AVAILABLE;
|
|
365
|
-
}
|
|
366
|
-
function localDay(tz, at = new Date) {
|
|
367
|
-
try {
|
|
368
|
-
return new Intl.DateTimeFormat("en-CA", { timeZone: tz, dateStyle: "short" }).format(at);
|
|
369
|
-
} catch {
|
|
370
|
-
return at.toISOString().slice(0, 10);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function tzOffsetMs(tz, at) {
|
|
374
|
-
const parts = Object.fromEntries(new Intl.DateTimeFormat("en-US", {
|
|
375
|
-
timeZone: tz,
|
|
376
|
-
hour12: false,
|
|
377
|
-
year: "numeric",
|
|
378
|
-
month: "2-digit",
|
|
379
|
-
day: "2-digit",
|
|
380
|
-
hour: "2-digit",
|
|
381
|
-
minute: "2-digit",
|
|
382
|
-
second: "2-digit"
|
|
383
|
-
}).formatToParts(at).filter((p) => p.type !== "literal").map((p) => [p.type, p.value]));
|
|
384
|
-
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));
|
|
385
|
-
const atSec = Math.floor(at.getTime() / 1000) * 1000;
|
|
386
|
-
return asUtc - atSec;
|
|
387
|
-
}
|
|
388
|
-
function zonedDayStart(tz, ymd) {
|
|
389
|
-
const [y, m, d] = ymd.split("-").map(Number);
|
|
390
|
-
const utcMidnight = Date.UTC(y ?? 1970, (m ?? 1) - 1, d ?? 1);
|
|
391
|
-
const guess = new Date(utcMidnight - tzOffsetMs(tz, new Date(utcMidnight)));
|
|
392
|
-
return new Date(utcMidnight - tzOffsetMs(tz, guess));
|
|
393
|
-
}
|
|
394
|
-
function formatZonedIso(tz, at) {
|
|
395
|
-
const off = tzOffsetMs(tz, at);
|
|
396
|
-
const abs = Math.abs(off);
|
|
397
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
398
|
-
const offStr = `${off < 0 ? "-" : "+"}${pad(Math.floor(abs / 3600000))}:${pad(Math.floor(abs % 3600000 / 60000))}`;
|
|
399
|
-
return `${new Date(at.getTime() + off).toISOString().slice(0, 23)}${offStr}`;
|
|
400
|
-
}
|
|
401
|
-
function dayBounds(tz, ymd) {
|
|
402
|
-
const start = zonedDayStart(tz, ymd);
|
|
403
|
-
const nextYmd = localDay(tz, new Date(start.getTime() + 30 * 3600000));
|
|
404
|
-
return {
|
|
405
|
-
since: formatZonedIso(tz, start),
|
|
406
|
-
until: formatZonedIso(tz, new Date(zonedDayStart(tz, nextYmd).getTime() - 1))
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
function resolvePaths(opts) {
|
|
410
|
-
const m = opts.helper.match(/\/scripts\/(?:([^/]+)\/)?[^/]+$/);
|
|
411
|
-
const pluginRoot = m ? opts.helper.slice(0, m.index) : opts.helper;
|
|
412
|
-
const skill = `${pluginRoot}/skills/${m?.[1] ? `${m[1]}-history-anatomy` : "history-anatomy"}`;
|
|
413
|
-
const tz = opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
414
|
-
const date = opts.date !== undefined && opts.date !== "" ? opts.date : localDay(tz, opts.now ?? new Date);
|
|
415
|
-
const target = opts.output !== undefined && opts.output !== "" ? opts.output : `${opts.reportDir}/${date}-history-anatomy.md`;
|
|
416
|
-
const adHoc = opts.mode === "ad-hoc" && !!opts.since && !!opts.until;
|
|
417
|
-
let env = `HA_HELPER=${opts.helper}
|
|
418
|
-
HA_SKILL=${skill}
|
|
419
|
-
HA_TARGET=${target}
|
|
420
|
-
HA_DATE=${date}
|
|
421
|
-
`;
|
|
422
|
-
if (adHoc) {
|
|
423
|
-
return `${env}HA_SINCE=${opts.since}
|
|
424
|
-
HA_UNTIL=${opts.until}
|
|
425
|
-
`;
|
|
426
|
-
}
|
|
427
|
-
const current = dayBounds(tz, date);
|
|
428
|
-
const baseline = dayBounds(tz, localDay(tz, new Date(zonedDayStart(tz, date).getTime() - 12 * 3600000)));
|
|
429
|
-
env += `HA_SINCE=${current.since}
|
|
430
|
-
HA_UNTIL=${current.until}
|
|
431
|
-
`;
|
|
432
|
-
env += `HA_BASELINE_SINCE=${baseline.since}
|
|
433
|
-
HA_BASELINE_UNTIL=${baseline.until}
|
|
434
|
-
`;
|
|
435
|
-
return env;
|
|
436
|
-
}
|
|
437
|
-
function isRealDate(ymd) {
|
|
438
|
-
const m = ymd.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
439
|
-
if (!m)
|
|
440
|
-
return false;
|
|
441
|
-
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
442
|
-
const dt = new Date(Date.UTC(y, mo - 1, d));
|
|
443
|
-
return dt.getUTCFullYear() === y && dt.getUTCMonth() === mo - 1 && dt.getUTCDate() === d;
|
|
444
|
-
}
|
|
445
|
-
function validateSelector(opts) {
|
|
446
|
-
const errors = [];
|
|
447
|
-
const has = (v) => v !== undefined && v !== "";
|
|
448
|
-
const val = (v) => has(v) ? v : null;
|
|
449
|
-
const mode = has(opts.mode) ? opts.mode : "daily";
|
|
450
|
-
if (mode !== "daily" && mode !== "ad-hoc") {
|
|
451
|
-
return { ok: false, errors: [`--mode must be "daily" or "ad-hoc", got "${opts.mode}"`] };
|
|
452
|
-
}
|
|
453
|
-
const recompute = opts.recompute ?? "";
|
|
454
|
-
if (recompute !== "" && recompute !== "true" && recompute !== "false") {
|
|
455
|
-
errors.push(`--recompute must be "true" or "false", got "${recompute}"`);
|
|
456
|
-
}
|
|
457
|
-
if (mode === "daily") {
|
|
458
|
-
for (const [flag, v] of [
|
|
459
|
-
["--focus", opts.focus],
|
|
460
|
-
["--since", opts.since],
|
|
461
|
-
["--until", opts.until],
|
|
462
|
-
["--output", opts.output]
|
|
463
|
-
]) {
|
|
464
|
-
if (has(v))
|
|
465
|
-
errors.push(`daily mode rejects ${flag}`);
|
|
466
|
-
}
|
|
467
|
-
if (has(opts.date) && !isRealDate(opts.date)) {
|
|
468
|
-
errors.push(`--date must be a real YYYY-MM-DD calendar day, got "${opts.date}"`);
|
|
469
|
-
}
|
|
470
|
-
} else {
|
|
471
|
-
if (has(opts.date))
|
|
472
|
-
errors.push("ad-hoc mode rejects --date");
|
|
473
|
-
if (recompute === "true")
|
|
474
|
-
errors.push("ad-hoc mode rejects --recompute");
|
|
475
|
-
if (!has(opts.focus))
|
|
476
|
-
errors.push("ad-hoc mode requires a non-empty --focus");
|
|
477
|
-
const sinceOk = has(opts.since);
|
|
478
|
-
const untilOk = has(opts.until);
|
|
479
|
-
if (!sinceOk)
|
|
480
|
-
errors.push("ad-hoc mode requires --since (inclusive ISO instant)");
|
|
481
|
-
if (!untilOk)
|
|
482
|
-
errors.push("ad-hoc mode requires --until (inclusive ISO instant)");
|
|
483
|
-
if (sinceOk && untilOk) {
|
|
484
|
-
const since = new Date(opts.since ?? "");
|
|
485
|
-
const until = new Date(opts.until ?? "");
|
|
486
|
-
if (Number.isNaN(since.getTime()))
|
|
487
|
-
errors.push(`--since must be a parseable ISO instant, got "${opts.since}"`);
|
|
488
|
-
if (Number.isNaN(until.getTime()))
|
|
489
|
-
errors.push(`--until must be a parseable ISO instant, got "${opts.until}"`);
|
|
490
|
-
if (!Number.isNaN(since.getTime()) && !Number.isNaN(until.getTime()) && since.getTime() > until.getTime()) {
|
|
491
|
-
errors.push(`--since must not be after --until ("${opts.since}" > "${opts.until}")`);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (errors.length)
|
|
496
|
-
return { ok: false, errors };
|
|
497
|
-
return {
|
|
498
|
-
ok: true,
|
|
499
|
-
mode,
|
|
500
|
-
date: val(opts.date),
|
|
501
|
-
focus: val(opts.focus),
|
|
502
|
-
since: val(opts.since),
|
|
503
|
-
until: val(opts.until)
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
function buildProvenance(opts) {
|
|
507
|
-
let raw;
|
|
508
|
-
try {
|
|
509
|
-
raw = JSON.parse(readFileSync(opts.artifact, "utf8"));
|
|
510
|
-
} catch (err) {
|
|
511
|
-
throw new Error(`could not parse fresh analyze artifact at ${opts.artifact}: ${err.message}`);
|
|
512
|
-
}
|
|
513
|
-
const coverage = (raw.coverage ?? []).map((c) => ({
|
|
514
|
-
source: String(c.source ?? ""),
|
|
515
|
-
status: String(c.status ?? ""),
|
|
516
|
-
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt)
|
|
517
|
-
}));
|
|
518
|
-
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
519
|
-
const now = opts.now ?? new Date;
|
|
520
|
-
const date = opts.date !== undefined && opts.date !== "" ? opts.date : localDay(tz, now);
|
|
521
|
-
const windowState = opts.mode === "ad-hoc" || date < localDay(tz, now) ? "closed" : "provisional";
|
|
522
|
-
const nowIso = now.toISOString();
|
|
523
|
-
return {
|
|
524
|
-
identity: {
|
|
525
|
-
contractVersion: opts.contractVersion ?? "1",
|
|
526
|
-
mode: opts.mode,
|
|
527
|
-
date,
|
|
528
|
-
timezone: tz,
|
|
529
|
-
bounds: { since: String(raw.selector?.since ?? ""), until: String(raw.selector?.until ?? "") },
|
|
530
|
-
sources: coverage.map((c) => c.source).sort()
|
|
531
|
-
},
|
|
532
|
-
windowState,
|
|
533
|
-
generatedAt: nowIso,
|
|
534
|
-
validatedAt: nowIso,
|
|
535
|
-
artifactDigest: semanticArtifactDigest(raw),
|
|
536
|
-
baselineArtifactDigest: (() => {
|
|
537
|
-
if (!(opts.baseline !== undefined && existsSync(opts.baseline)))
|
|
538
|
-
return null;
|
|
539
|
-
try {
|
|
540
|
-
return semanticArtifactDigest(JSON.parse(readFileSync(opts.baseline, "utf8")));
|
|
541
|
-
} catch (err) {
|
|
542
|
-
throw new Error(`could not parse baseline artifact at ${opts.baseline}: ${err.message}`);
|
|
543
|
-
}
|
|
544
|
-
})(),
|
|
545
|
-
contractDigest: logicDigest(opts.contractFile),
|
|
546
|
-
skillDigest: logicDigest(opts.skillDir),
|
|
547
|
-
workflowDigest: logicDigest(opts.workflowFile),
|
|
548
|
-
helperDigest: logicDigest(opts.helperFile),
|
|
549
|
-
coverage,
|
|
550
|
-
runId: opts.runId,
|
|
551
|
-
currentArtifactPath: opts.artifact,
|
|
552
|
-
baselineArtifactPath: opts.baseline ?? null,
|
|
553
|
-
spurVersion: opts.spurVersion ?? NOT_AVAILABLE,
|
|
554
|
-
schemaVersion: typeof raw.schemaVersion === "number" ? raw.schemaVersion : undefined,
|
|
555
|
-
executor: opts.executor ?? NOT_AVAILABLE,
|
|
556
|
-
model: opts.model ?? NOT_AVAILABLE
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
function probe(opts) {
|
|
560
|
-
const current = buildProvenance(opts);
|
|
561
|
-
const cachedText = existsSync(opts.target) ? readFileSync(opts.target, "utf8") : null;
|
|
562
|
-
const cached = cachedText === null ? null : parseProvenance(cachedText);
|
|
563
|
-
const decision = opts.mode === "ad-hoc" ? { disposition: "miss", reasons: ["ad-hoc-never-cached"] } : decideCache(cached, current, {
|
|
564
|
-
recompute: opts.recompute,
|
|
565
|
-
dayClosed: current.windowState === "closed"
|
|
566
|
-
});
|
|
567
|
-
current.cacheDisposition = decision.disposition;
|
|
568
|
-
return { decision, current };
|
|
569
|
-
}
|
|
570
|
-
var YAML_KEYS = [
|
|
571
|
-
"windowState",
|
|
572
|
-
"generatedAt",
|
|
573
|
-
"validatedAt",
|
|
574
|
-
"artifactDigest",
|
|
575
|
-
"baselineArtifactDigest",
|
|
576
|
-
"contractDigest",
|
|
577
|
-
"skillDigest",
|
|
578
|
-
"workflowDigest",
|
|
579
|
-
"helperDigest",
|
|
580
|
-
"runId",
|
|
581
|
-
"currentArtifactPath",
|
|
582
|
-
"baselineArtifactPath",
|
|
583
|
-
"spurVersion",
|
|
584
|
-
"schemaVersion",
|
|
585
|
-
"executor",
|
|
586
|
-
"model",
|
|
587
|
-
"cacheDisposition"
|
|
588
|
-
];
|
|
589
|
-
function yamlScalar(v) {
|
|
590
|
-
if (v === null || v === undefined)
|
|
591
|
-
return "null";
|
|
592
|
-
if (typeof v === "number" || typeof v === "boolean")
|
|
593
|
-
return String(v);
|
|
594
|
-
return `"${String(v).replaceAll('"', "\\\"")}"`;
|
|
595
|
-
}
|
|
596
|
-
function renderProvenanceFrontmatter(p) {
|
|
597
|
-
const lines = [
|
|
598
|
-
"---",
|
|
599
|
-
"identity:",
|
|
600
|
-
` contractVersion: ${yamlScalar(p.identity.contractVersion)}`,
|
|
601
|
-
` mode: ${p.identity.mode}`,
|
|
602
|
-
` date: ${yamlScalar(p.identity.date)}`,
|
|
603
|
-
` timezone: ${p.identity.timezone}`,
|
|
604
|
-
" bounds:",
|
|
605
|
-
` since: ${p.identity.bounds.since}`,
|
|
606
|
-
` until: ${p.identity.bounds.until}`,
|
|
607
|
-
" sources:"
|
|
608
|
-
];
|
|
609
|
-
for (const s of p.identity.sources)
|
|
610
|
-
lines.push(` - source: ${s}`);
|
|
611
|
-
for (const k of YAML_KEYS) {
|
|
612
|
-
if (p[k] === undefined)
|
|
613
|
-
continue;
|
|
614
|
-
lines.push(`${k}: ${yamlScalar(p[k])}`);
|
|
615
|
-
}
|
|
616
|
-
lines.push("coverage:");
|
|
617
|
-
for (const c of p.coverage) {
|
|
618
|
-
lines.push(` - source: ${c.source}, status: ${c.status}, lastImportedAt: ${c.lastImportedAt ?? "null"}`);
|
|
619
|
-
}
|
|
620
|
-
lines.push("---");
|
|
621
|
-
return lines.join(`
|
|
622
|
-
`);
|
|
623
|
-
}
|
|
624
|
-
function bannerLine(p) {
|
|
625
|
-
return `> imported snapshot as of ${importedSnapshotAsOf(p.coverage)} · window ${p.windowState} · cache ${p.cacheDisposition ?? NOT_AVAILABLE}`;
|
|
626
|
-
}
|
|
627
|
-
function stripHeader(md) {
|
|
628
|
-
const body = md.replace(/^---\n[\s\S]*?\n---\n?/, "").replace(/^\n+/, "");
|
|
629
|
-
return body.replace(/^> imported snapshot as of [^\n]*\n+/, "");
|
|
630
|
-
}
|
|
631
|
-
function stampReport(candidateMarkdown, p) {
|
|
632
|
-
return `${renderProvenanceFrontmatter(p)}
|
|
633
|
-
|
|
634
|
-
${bannerLine(p)}
|
|
635
|
-
|
|
636
|
-
${stripHeader(candidateMarkdown).replace(/^\n+/, "")}`;
|
|
637
|
-
}
|
|
638
|
-
function refreshReport(publishedMarkdown, validatedAt, disposition) {
|
|
639
|
-
const cached = parseProvenance(publishedMarkdown);
|
|
640
|
-
if (cached === null)
|
|
641
|
-
return publishedMarkdown;
|
|
642
|
-
const refreshed = { ...cached, validatedAt, cacheDisposition: disposition };
|
|
643
|
-
return stampReport(publishedMarkdown, refreshed);
|
|
644
|
-
}
|
|
645
|
-
function publishAtomically(candidatePath, targetPath) {
|
|
646
|
-
const tmpPath = `${targetPath}.tmp`;
|
|
647
|
-
try {
|
|
648
|
-
writeFileSync(tmpPath, readFileSync(candidatePath));
|
|
649
|
-
const fd = openSync(tmpPath, "r");
|
|
650
|
-
try {
|
|
651
|
-
fsyncSync(fd);
|
|
652
|
-
} finally {
|
|
653
|
-
closeSync(fd);
|
|
654
|
-
}
|
|
655
|
-
renameSync(tmpPath, targetPath);
|
|
656
|
-
} catch (err) {
|
|
657
|
-
try {
|
|
658
|
-
rmSync(tmpPath, { force: true });
|
|
659
|
-
} catch {}
|
|
660
|
-
throw err;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function porcelainPaths(text) {
|
|
664
|
-
return new Set(text.split(`
|
|
665
|
-
`).map((line) => line.replace(/^\S+\s+/, "").trim()).filter((line) => line.length > 0));
|
|
666
|
-
}
|
|
667
|
-
function diffPorcelain(before, now, expects) {
|
|
668
|
-
const beforePaths = porcelainPaths(before);
|
|
669
|
-
return [...porcelainPaths(now)].filter((p) => !beforePaths.has(p) && !expects.has(p)).sort();
|
|
670
|
-
}
|
|
671
|
-
export {
|
|
672
|
-
FINDING_FIELDS,
|
|
673
|
-
REPORT_SECTIONS,
|
|
674
|
-
bannerLine,
|
|
675
|
-
buildProvenance,
|
|
676
|
-
checkReportStructure,
|
|
677
|
-
decideCache,
|
|
678
|
-
diffPorcelain,
|
|
679
|
-
importedSnapshotAsOf,
|
|
680
|
-
logicDigest,
|
|
681
|
-
parseProvenance,
|
|
682
|
-
porcelainPaths,
|
|
683
|
-
probe,
|
|
684
|
-
publishAtomically,
|
|
685
|
-
refreshReport,
|
|
686
|
-
renderProvenanceFrontmatter,
|
|
687
|
-
resolvePaths,
|
|
688
|
-
semanticArtifactDigest,
|
|
689
|
-
stampReport,
|
|
690
|
-
validateSelector
|
|
691
|
-
};
|