@gobing-ai/knowledge-kit 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +120 -26
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +22187 -0
- package/plugins/generations/content-gen/plugin.json +1 -1
- package/plugins/generations/core-facts-gen/dist/index.js +22068 -0
- package/plugins/generations/core-facts-gen/plugin.json +1 -1
- package/plugins/generations/daily-article-gen/dist/index.js +22050 -0
- package/plugins/generations/daily-article-gen/plugin.json +1 -1
- package/plugins/generations/daily-article-gen/src/index.ts +13 -1
- package/plugins/generations/dailynews-gen/dist/index.js +22344 -0
- package/plugins/generations/dailynews-gen/plugin.json +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +22503 -0
- package/plugins/generations/episode-plan-gen/plugin.json +1 -1
- package/plugins/generations/episode-plan-gen/src/index.ts +11 -0
- package/plugins/generations/image-gen/config.example.yaml +75 -0
- package/plugins/generations/image-gen/dist/index.js +24862 -0
- package/plugins/generations/image-gen/package.json +17 -0
- package/plugins/generations/image-gen/plugin.json +7 -0
- package/plugins/generations/image-gen/presets/formats/cover.yaml +57 -0
- package/plugins/generations/image-gen/presets/formats/free.yaml +46 -0
- package/plugins/generations/image-gen/presets/formats/illustration.yaml +48 -0
- package/plugins/generations/image-gen/presets/styles/clean-webapp-ui.yaml +28 -0
- package/plugins/generations/image-gen/presets/styles/cute.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/editorial.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/fresh.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/minimalist.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/photorealistic.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/sketch.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/technical-diagram.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/vibrant.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/warm.yaml +3 -0
- package/plugins/generations/image-gen/src/bytes.ts +19 -0
- package/plugins/generations/image-gen/src/index.ts +319 -0
- package/plugins/generations/image-gen/src/job.ts +143 -0
- package/plugins/generations/image-gen/src/paths.ts +31 -0
- package/plugins/generations/image-gen/src/presets.ts +344 -0
- package/plugins/generations/image-gen/src/providers/agnes.ts +110 -0
- package/plugins/generations/image-gen/src/providers/azure.ts +153 -0
- package/plugins/generations/image-gen/src/providers/codex-cli.ts +170 -0
- package/plugins/generations/image-gen/src/providers/dashscope.ts +485 -0
- package/plugins/generations/image-gen/src/providers/google.ts +268 -0
- package/plugins/generations/image-gen/src/providers/huggingface.ts +59 -0
- package/plugins/generations/image-gen/src/providers/jimeng.ts +259 -0
- package/plugins/generations/image-gen/src/providers/minimax.ts +171 -0
- package/plugins/generations/image-gen/src/providers/openai.ts +319 -0
- package/plugins/generations/image-gen/src/providers/openrouter.ts +257 -0
- package/plugins/generations/image-gen/src/providers/refs.ts +24 -0
- package/plugins/generations/image-gen/src/providers/replicate.ts +279 -0
- package/plugins/generations/image-gen/src/providers/seedream.ts +128 -0
- package/plugins/generations/image-gen/src/providers/types.ts +286 -0
- package/plugins/generations/image-gen/src/providers/zai.ts +237 -0
- package/plugins/generations/image-gen/tsconfig.json +8 -0
- package/plugins/generations/news-report-gen/dist/index.js +22193 -0
- package/plugins/generations/news-report-gen/package.json +17 -0
- package/plugins/generations/news-report-gen/plugin.json +7 -0
- package/plugins/generations/news-report-gen/src/index.ts +308 -0
- package/plugins/generations/news-report-gen/tsconfig.json +4 -0
- package/plugins/generations/omni-voice-gen/Makefile +14 -0
- package/plugins/generations/omni-voice-gen/README.md +112 -0
- package/plugins/generations/omni-voice-gen/bin/omni-voice-gen +2 -0
- package/plugins/generations/omni-voice-gen/dist/omni-voice-gen-prr8skpb. +2 -0
- package/plugins/generations/omni-voice-gen/dist/omni-voice-gen.js +6 -0
- package/plugins/generations/omni-voice-gen/plugin.json +6 -0
- package/plugins/generations/omni-voice-gen/profiles.json +12 -0
- package/plugins/generations/omni-voice-gen/pyproject.toml +25 -0
- package/plugins/generations/omni-voice-gen/scripts/coverage_gate.py +74 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__init__.py +1 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__main__.py +39 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/audio.py +190 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/backend.py +150 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/contract.py +76 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/mp3.py +60 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/pipeline.py +289 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/profiles.py +100 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/qc.py +234 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/voicescript.py +352 -0
- package/plugins/generations/omni-voice-gen/uv.lock +3510 -0
- package/plugins/generations/voice-gen/dist/index.js +23055 -0
- package/plugins/generations/voice-gen/plugin.json +1 -1
- package/plugins/generations/voice-gen/src/index.ts +16 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +3 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +22378 -0
- package/plugins/ingestions/aihot-ingest/plugin.json +1 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +22125 -0
- package/plugins/ingestions/horizon-ingest/plugin.json +1 -1
- package/plugins/ingestions/karakeep-local/dist/index.js +24204 -0
- package/plugins/ingestions/karakeep-local/plugin.json +1 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +22070 -0
- package/plugins/ingestions/last30days-ingest/plugin.json +1 -1
- package/plugins/ingestions/web-search/dist/index.js +24399 -0
- package/plugins/ingestions/web-search/plugin.json +1 -1
- package/plugins/kk/commands/image-extract.md +40 -0
- package/plugins/kk/commands/image-generate.md +32 -0
- package/plugins/kk/config.example.yaml +80 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/skills/image-authoring/SKILL.md +257 -0
- package/plugins/kk/skills/image-authoring/references/format-drafting.md +57 -0
- package/plugins/kk/skills/image-authoring/references/illustration-positions.md +87 -0
- package/plugins/kk/skills/image-authoring/references/migrating-from-wt.md +31 -0
- package/plugins/kk/skills/image-authoring/references/providers.md +52 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +139 -0
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +130 -30
- package/plugins/publishings/emdash-pub/dist/index.js +22263 -0
- package/plugins/publishings/emdash-pub/plugin.json +1 -1
- package/plugins/publishings/podcast-pub/dist/index.js +22650 -0
- package/plugins/publishings/podcast-pub/plugin.json +8 -2
- package/plugins/publishings/podcast-pub/src/index.ts +18 -2
- package/plugins/publishings/podcast-pub/src/show-notes.ts +56 -9
- package/plugins/publishings/qiita-pub/dist/index.js +22101 -0
- package/plugins/publishings/qiita-pub/plugin.json +1 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +22323 -0
- package/plugins/publishings/surfdash-pub/plugin.json +1 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +109 -9
- package/plugins/publishings/zenn-pub/dist/index.js +22142 -0
- package/plugins/publishings/zenn-pub/plugin.json +1 -1
- package/plugins/sp/scripts/batch-preflight.mjs +346 -0
- package/plugins/sp/scripts/batch-preflight.ts +459 -0
- package/plugins/sp/scripts/daily-summary/daily-summary.mjs +615 -0
- package/plugins/sp/scripts/daily-summary/daily-summary.ts +846 -0
- package/plugins/sp/scripts/daily-summary/logger.ts +28 -0
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +223 -0
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +367 -0
- package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +132 -0
- package/plugins/sp/scripts/dogfood-testing/validate-report.ts +169 -0
- package/plugins/sp/scripts/feature-dev-precheck.mjs +171 -0
- package/plugins/sp/scripts/feature-dev-precheck.ts +238 -0
- package/plugins/sp/scripts/feature-sync-bounded.mjs +285 -0
- package/plugins/sp/scripts/feature-sync-bounded.ts +478 -0
- package/plugins/sp/scripts/history-anatomy-cache.mjs +902 -0
- package/plugins/sp/scripts/history-anatomy-cache.ts +1028 -0
- package/plugins/sp/scripts/idea-handoff.mjs +22 -0
- package/plugins/sp/scripts/idea-handoff.ts +44 -0
- package/plugins/sp/scripts/inline-pipeline-parity-check.ts +185 -0
- package/plugins/sp/scripts/inline-run-setup.ts +198 -0
- package/plugins/sp/scripts/pr-reviewing.mjs +769 -0
- package/plugins/sp/scripts/pr-reviewing.ts +925 -0
- package/plugins/sp/scripts/quality-gate.mjs +179 -0
- package/plugins/sp/scripts/quality-gate.ts +217 -0
- package/plugins/sp/scripts/script-contract-check.ts +319 -0
- package/plugins/sp/scripts/stage-registry-adapter.ts +1533 -0
- package/plugins/sp/scripts/surface-drift-inventory.ts +929 -0
- package/plugins/sp/scripts/task-evidence-precheck.ts +181 -0
- package/plugins/sp/scripts/task-size-precheck.ts +175 -0
- package/plugins/sp/scripts/transition-shim-check.ts +238 -0
- package/plugins/sp/scripts/validate-commands.ts +689 -0
- package/plugins/sp/scripts/validate-flag-contracts.ts +878 -0
- package/plugins/sp/scripts/verify-answer-lint.ts +530 -0
- package/plugins/sp/scripts/workflow-step-profile.mjs +316 -0
- package/plugins/sp/scripts/workflow-step-profile.ts +456 -0
- package/plugins/sp/scripts/wrapup-steps.mjs +373 -0
- package/plugins/sp/scripts/wrapup-steps.ts +466 -0
|
@@ -0,0 +1,902 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
|
|
4
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
// plugins/sp/scripts/history-anatomy-cache.ts
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
// plugins/sp/lib/artifact-digest.generated.mjs
|
|
9
|
+
import { createHash, createHash as createHash2 } from 'node:crypto';
|
|
10
|
+
import {
|
|
11
|
+
closeSync,
|
|
12
|
+
existsSync,
|
|
13
|
+
fsyncSync,
|
|
14
|
+
openSync,
|
|
15
|
+
readdirSync,
|
|
16
|
+
readFileSync,
|
|
17
|
+
renameSync,
|
|
18
|
+
rmSync,
|
|
19
|
+
statSync,
|
|
20
|
+
writeFileSync,
|
|
21
|
+
} from 'node:fs';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
|
|
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(
|
|
45
|
+
Object.entries(ARTIFACT_ARRAY_CLASSIFICATION)
|
|
46
|
+
.filter(([, kind]) => kind === 'ranked')
|
|
47
|
+
.map(([key]) => key),
|
|
48
|
+
);
|
|
49
|
+
function canonicalize(value, key) {
|
|
50
|
+
if (key === 'generatedAt' || key === 'validatedAt' || key === 'baselineArtifactDigest') return null;
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
const raw = value.map((v) => JSON.stringify(canonicalize(v, '')));
|
|
53
|
+
return RANKED_ARTIFACT_KEYS.has(key) ? raw : [...raw].sort();
|
|
54
|
+
}
|
|
55
|
+
if (value !== null && typeof value === 'object') {
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const k of Object.keys(value).sort()) {
|
|
58
|
+
out[k] = canonicalize(value[k], k);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
function semanticArtifactDigest(artifactJson) {
|
|
65
|
+
const material = JSON.stringify(canonicalize(artifactJson, 'root'));
|
|
66
|
+
return createHash('sha256').update(material).digest('hex');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// plugins/sp/scripts/history-anatomy-cache.ts
|
|
70
|
+
var REPORT_SECTIONS = [
|
|
71
|
+
'Scope and provenance',
|
|
72
|
+
'Executive summary',
|
|
73
|
+
'Baseline comparison',
|
|
74
|
+
'Findings',
|
|
75
|
+
'Recurrence ledger',
|
|
76
|
+
'Telemetry gaps',
|
|
77
|
+
'Remediation options',
|
|
78
|
+
'Performance analysis',
|
|
79
|
+
'Workflow and process improvements',
|
|
80
|
+
'Report-only advisories',
|
|
81
|
+
'Positive patterns',
|
|
82
|
+
'Evidence ledger',
|
|
83
|
+
];
|
|
84
|
+
var FINDING_FIELDS = [
|
|
85
|
+
'key',
|
|
86
|
+
'category',
|
|
87
|
+
'impact',
|
|
88
|
+
'trend',
|
|
89
|
+
'observation',
|
|
90
|
+
'inference',
|
|
91
|
+
'confidence',
|
|
92
|
+
'contradictions',
|
|
93
|
+
'evidenceAnchor',
|
|
94
|
+
'severity',
|
|
95
|
+
'reproCommand',
|
|
96
|
+
'ownerSurface',
|
|
97
|
+
];
|
|
98
|
+
function parseScalar(raw) {
|
|
99
|
+
const t = raw.trim();
|
|
100
|
+
if (t.startsWith('"') && t.endsWith('"')) return t.slice(1, -1).replaceAll('\\"', '"');
|
|
101
|
+
if (t === 'null') return null;
|
|
102
|
+
return t;
|
|
103
|
+
}
|
|
104
|
+
function parseBlock(text) {
|
|
105
|
+
const obj = {};
|
|
106
|
+
const lines = text.split(`
|
|
107
|
+
`);
|
|
108
|
+
for (let i = 0; i < lines.length; i++) {
|
|
109
|
+
const line = lines[i] ?? '';
|
|
110
|
+
if (/^\s*$/.test(line) || /^\s*#/.test(line) || /^-\s+/.test(line.trim())) continue;
|
|
111
|
+
const indent = line.search(/\S/);
|
|
112
|
+
const eq = line.indexOf(':');
|
|
113
|
+
if (eq === -1) continue;
|
|
114
|
+
const key = line.slice(0, eq).trim();
|
|
115
|
+
const val = parseScalar(line.slice(eq + 1).trim());
|
|
116
|
+
let consumed = 0;
|
|
117
|
+
const next = lines[i + 1];
|
|
118
|
+
if ((val === '' || val === undefined) && /^\s*-\s+/.test(next ?? '')) {
|
|
119
|
+
const items = [];
|
|
120
|
+
let j = i + 1;
|
|
121
|
+
while (j < lines.length && /^\s*-\s+/.test(lines[j] ?? '')) {
|
|
122
|
+
const entry = {};
|
|
123
|
+
for (const part of (lines[j] ?? '').trim().replace(/^-\s+/, '').split(',')) {
|
|
124
|
+
const e = part.indexOf(':');
|
|
125
|
+
if (e === -1) continue;
|
|
126
|
+
entry[part.slice(0, e).trim()] = parseScalar(part.slice(e + 1).trim());
|
|
127
|
+
}
|
|
128
|
+
items.push(entry);
|
|
129
|
+
j++;
|
|
130
|
+
}
|
|
131
|
+
obj[key] = items;
|
|
132
|
+
consumed = j - i - 1;
|
|
133
|
+
} else if (val === '' || val === undefined) {
|
|
134
|
+
const block = [];
|
|
135
|
+
let j = i + 1;
|
|
136
|
+
while (j < lines.length) {
|
|
137
|
+
const nl = lines[j] ?? '';
|
|
138
|
+
if (nl.trim() === '') {
|
|
139
|
+
block.push('');
|
|
140
|
+
j++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const nind = nl.search(/\S/);
|
|
144
|
+
if (nind <= indent) break;
|
|
145
|
+
block.push(nl);
|
|
146
|
+
j++;
|
|
147
|
+
}
|
|
148
|
+
obj[key] = parseBlock(
|
|
149
|
+
block.join(`
|
|
150
|
+
`),
|
|
151
|
+
);
|
|
152
|
+
consumed = j - i - 1;
|
|
153
|
+
} else {
|
|
154
|
+
obj[key] = val;
|
|
155
|
+
}
|
|
156
|
+
i += consumed;
|
|
157
|
+
}
|
|
158
|
+
return obj;
|
|
159
|
+
}
|
|
160
|
+
function readSourceName(s) {
|
|
161
|
+
if (s !== null && typeof s === 'object') return String(s.source ?? '');
|
|
162
|
+
return String(s);
|
|
163
|
+
}
|
|
164
|
+
var DISPOSITIONS = ['hit', 'miss', 'forced-recompute'];
|
|
165
|
+
function optionalString(v) {
|
|
166
|
+
return v == null || v === '' ? undefined : String(v);
|
|
167
|
+
}
|
|
168
|
+
function parseProvenance(reportMarkdown) {
|
|
169
|
+
const match = reportMarkdown.match(/^---\n([\s\S]*?)\n---/);
|
|
170
|
+
if (match === null) return null;
|
|
171
|
+
try {
|
|
172
|
+
const obj = parseBlock(match[1] ?? '');
|
|
173
|
+
const identity = obj.identity;
|
|
174
|
+
const coverage = obj.coverage;
|
|
175
|
+
if (identity === undefined || !Array.isArray(coverage)) return null;
|
|
176
|
+
const bounds = identity.bounds;
|
|
177
|
+
if (bounds === undefined || typeof bounds.since !== 'string' || typeof bounds.until !== 'string') {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
identity: {
|
|
182
|
+
contractVersion: String(identity.contractVersion ?? ''),
|
|
183
|
+
mode: identity.mode === 'ad-hoc' ? 'ad-hoc' : 'daily',
|
|
184
|
+
date: String(identity.date ?? ''),
|
|
185
|
+
timezone: String(identity.timezone ?? ''),
|
|
186
|
+
bounds: { since: bounds.since, until: bounds.until },
|
|
187
|
+
sources: Array.isArray(identity.sources) ? identity.sources.map(readSourceName) : [],
|
|
188
|
+
},
|
|
189
|
+
windowState: obj.windowState === 'closed' ? 'closed' : 'provisional',
|
|
190
|
+
generatedAt: String(obj.generatedAt ?? ''),
|
|
191
|
+
validatedAt: String(obj.validatedAt ?? ''),
|
|
192
|
+
artifactDigest: String(obj.artifactDigest ?? ''),
|
|
193
|
+
baselineArtifactDigest: obj.baselineArtifactDigest == null ? null : String(obj.baselineArtifactDigest),
|
|
194
|
+
contractDigest: String(obj.contractDigest ?? ''),
|
|
195
|
+
skillDigest: String(obj.skillDigest ?? ''),
|
|
196
|
+
workflowDigest: String(obj.workflowDigest ?? ''),
|
|
197
|
+
helperDigest: String(obj.helperDigest ?? ''),
|
|
198
|
+
coverage: coverage.map((c) => ({
|
|
199
|
+
source: String(c.source ?? ''),
|
|
200
|
+
status: String(c.status ?? ''),
|
|
201
|
+
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt),
|
|
202
|
+
})),
|
|
203
|
+
runId: optionalString(obj.runId),
|
|
204
|
+
currentArtifactPath: optionalString(obj.currentArtifactPath),
|
|
205
|
+
baselineArtifactPath: obj.baselineArtifactPath == null ? null : String(obj.baselineArtifactPath),
|
|
206
|
+
spurVersion: optionalString(obj.spurVersion),
|
|
207
|
+
schemaVersion: obj.schemaVersion == null ? undefined : Number(obj.schemaVersion),
|
|
208
|
+
executor: optionalString(obj.executor),
|
|
209
|
+
model: optionalString(obj.model),
|
|
210
|
+
cacheDisposition: DISPOSITIONS.includes(obj.cacheDisposition) ? obj.cacheDisposition : undefined,
|
|
211
|
+
};
|
|
212
|
+
} catch {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function decideCache(cached, current, opts) {
|
|
217
|
+
if (opts.recompute) return { disposition: 'forced-recompute', reasons: ['recompute'] };
|
|
218
|
+
if (cached === null) return { disposition: 'miss', reasons: ['no-cache'] };
|
|
219
|
+
const reasons = [];
|
|
220
|
+
const id = cached.identity;
|
|
221
|
+
const cur = current.identity;
|
|
222
|
+
if (id.contractVersion !== cur.contractVersion) reasons.push('identity:contractVersion');
|
|
223
|
+
if (id.mode !== cur.mode) reasons.push('identity:mode');
|
|
224
|
+
if (id.date !== cur.date) reasons.push('identity:date');
|
|
225
|
+
if (id.timezone !== cur.timezone) reasons.push('identity:timezone');
|
|
226
|
+
if (id.bounds.since !== cur.bounds.since || id.bounds.until !== cur.bounds.until) reasons.push('identity:bounds');
|
|
227
|
+
if ([...id.sources].sort().join('\x00') !== [...cur.sources].sort().join('\x00')) reasons.push('identity:sources');
|
|
228
|
+
if (cached.artifactDigest !== current.artifactDigest) reasons.push('data-changed');
|
|
229
|
+
if (cached.contractDigest !== current.contractDigest) reasons.push('logic-changed:contract');
|
|
230
|
+
if (cached.skillDigest !== current.skillDigest) reasons.push('logic-changed:skill');
|
|
231
|
+
if (cached.workflowDigest !== current.workflowDigest) reasons.push('logic-changed:workflow');
|
|
232
|
+
if (cached.helperDigest !== current.helperDigest) reasons.push('logic-changed:helper');
|
|
233
|
+
const currentSources = new Set(current.coverage.map((c) => c.source));
|
|
234
|
+
if (cached.coverage.some((c) => !currentSources.has(c.source))) reasons.push('coverage-degraded');
|
|
235
|
+
if (cached.windowState === 'provisional' && opts.dayClosed) reasons.push('window-closed');
|
|
236
|
+
return { disposition: reasons.length === 0 ? 'hit' : 'miss', reasons };
|
|
237
|
+
}
|
|
238
|
+
function escapeRe(s) {
|
|
239
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
240
|
+
}
|
|
241
|
+
var FINDING_CATEGORIES = ['reliability', 'repetition', 'workflow', 'performance', 'coverage', 'telemetry', 'positive'];
|
|
242
|
+
function checkReportStructure(reportMarkdown) {
|
|
243
|
+
const problems = [];
|
|
244
|
+
if (/TODO|PLACEHOLDER|FIXME|^\|\s*\|/im.test(reportMarkdown)) problems.push('placeholder-or-todo-present');
|
|
245
|
+
let lastIdx = -1;
|
|
246
|
+
for (const section of REPORT_SECTIONS) {
|
|
247
|
+
const re = new RegExp(`^#{2,3}\\s+${escapeRe(section)}\\s*$`, 'm');
|
|
248
|
+
const m = reportMarkdown.match(re);
|
|
249
|
+
if (m === null || (m.index ?? -1) <= lastIdx) {
|
|
250
|
+
problems.push(`section-missing-or-out-of-order:${section}`);
|
|
251
|
+
} else if (m.index !== undefined) {
|
|
252
|
+
lastIdx = m.index;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const findingsIdx = reportMarkdown.search(/^##\s+Findings\s*$/im);
|
|
256
|
+
if (findingsIdx !== -1) {
|
|
257
|
+
const tail = reportMarkdown.slice(findingsIdx);
|
|
258
|
+
const nextSection = tail.slice(1).search(/^##\s+/im);
|
|
259
|
+
const findingsBody = nextSection === -1 ? tail : tail.slice(0, nextSection + 1);
|
|
260
|
+
const catAlt = FINDING_CATEGORIES.join('|');
|
|
261
|
+
const knownRows = findingsBody.match(new RegExp(`^\\|\\s*(?:${catAlt}):[^|]+`, 'gm')) ?? [];
|
|
262
|
+
const invalidRows = findingsBody.match(/^\|\s*([^|:\s][^|:]*):[^|]+/gm) ?? [];
|
|
263
|
+
for (const row of [...new Set([...knownRows, ...invalidRows])]) {
|
|
264
|
+
const segMatch = row.match(/^\|\s*([^:|]+):/);
|
|
265
|
+
if (segMatch && !FINDING_CATEGORIES.includes(segMatch[1].trim())) {
|
|
266
|
+
problems.push(`finding-invalid-key-category:${segMatch[1].trim()}`);
|
|
267
|
+
}
|
|
268
|
+
const rowLower = row.toLowerCase();
|
|
269
|
+
for (const field of FINDING_FIELDS) {
|
|
270
|
+
if (!rowLower.includes(field.toLowerCase())) problems.push(`finding-missing-field:${field}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const blocks = findingsBody.split(/^###\s+/m).slice(1);
|
|
274
|
+
for (const block of blocks) {
|
|
275
|
+
if (!block.includes('`key`') && !/\|\s*key\s*:/.test(block)) continue;
|
|
276
|
+
for (const field of FINDING_FIELDS) {
|
|
277
|
+
if (!block.includes(field)) problems.push(`finding-missing-field:${field}`);
|
|
278
|
+
}
|
|
279
|
+
if (!/(^|[\s`])P[123]([\s`.]|$)/.test(block) && !block.includes('symbolic-severity')) {
|
|
280
|
+
problems.push('finding-invalid-severity');
|
|
281
|
+
}
|
|
282
|
+
const catValue = block.match(/`category`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1];
|
|
283
|
+
if (catValue && !FINDING_CATEGORIES.includes(catValue.trim())) {
|
|
284
|
+
problems.push(`finding-invalid-category:${catValue.trim()}`);
|
|
285
|
+
}
|
|
286
|
+
const keyValue = block.match(/`key`\s*[:=]\s*`?([^`\n]+?)`?\s*(?:\n|$)/)?.[1] ?? '';
|
|
287
|
+
const firstSegment = keyValue.split(':')[0]?.trim() ?? '';
|
|
288
|
+
if (keyValue !== '' && !FINDING_CATEGORIES.includes(firstSegment)) {
|
|
289
|
+
problems.push(`finding-invalid-key-category:${firstSegment}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const ledgerIdx = reportMarkdown.search(/^#{2,3}\s+Evidence\s+ledger/im);
|
|
294
|
+
if (ledgerIdx !== -1) {
|
|
295
|
+
const ledgerSection = reportMarkdown.slice(ledgerIdx);
|
|
296
|
+
const sep = ledgerSection.match(/^\|[\s:|-]+\|[ \t]*$/m);
|
|
297
|
+
const body = sep?.index === undefined ? ledgerSection : ledgerSection.slice(sep.index + sep[0].length);
|
|
298
|
+
const claimRows = body.match(/^[|>]\s+\S.*$/gm) ?? [];
|
|
299
|
+
for (const row of claimRows) {
|
|
300
|
+
const hasAnchor = /`[^`]+:\d+`|`[^`]+\.(md|ts|json)`|[a-z][a-z0-9_-]*\/[a-z][a-z0-9_./-]*:[0-9]+/i.test(
|
|
301
|
+
row,
|
|
302
|
+
);
|
|
303
|
+
if (!hasAnchor) {
|
|
304
|
+
problems.push('evidence-claim-without-anchor');
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { ok: problems.length === 0, problems };
|
|
310
|
+
}
|
|
311
|
+
var NOT_AVAILABLE = 'not available';
|
|
312
|
+
function logicDigest(path) {
|
|
313
|
+
if (path === undefined || path === '' || !existsSync(path)) return NOT_AVAILABLE;
|
|
314
|
+
try {
|
|
315
|
+
const h = createHash2('sha256');
|
|
316
|
+
if (statSync(path).isDirectory()) {
|
|
317
|
+
const walk = (dir) =>
|
|
318
|
+
readdirSync(dir, { withFileTypes: true })
|
|
319
|
+
.flatMap((e) =>
|
|
320
|
+
e.isDirectory()
|
|
321
|
+
? walk(join(dir, e.name))
|
|
322
|
+
: /\.(md|ya?ml)$/.test(e.name)
|
|
323
|
+
? [join(dir, e.name)]
|
|
324
|
+
: [],
|
|
325
|
+
)
|
|
326
|
+
.sort();
|
|
327
|
+
for (const f of walk(path)) {
|
|
328
|
+
h.update(f.slice(path.length));
|
|
329
|
+
h.update(readFileSync(f));
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
h.update(readFileSync(path));
|
|
333
|
+
}
|
|
334
|
+
return h.digest('hex');
|
|
335
|
+
} catch {
|
|
336
|
+
return NOT_AVAILABLE;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function importedSnapshotAsOf(coverage) {
|
|
340
|
+
const stamps = coverage.map((c) => c.lastImportedAt).filter((v) => typeof v === 'string' && v !== '');
|
|
341
|
+
if (stamps.length === 0 || stamps.length !== coverage.length) return NOT_AVAILABLE;
|
|
342
|
+
return [...stamps].sort()[0] ?? NOT_AVAILABLE;
|
|
343
|
+
}
|
|
344
|
+
function localDay(tz, at = new Date()) {
|
|
345
|
+
try {
|
|
346
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone: tz, dateStyle: 'short' }).format(at);
|
|
347
|
+
} catch {
|
|
348
|
+
return at.toISOString().slice(0, 10);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function tzOffsetMs(tz, at) {
|
|
352
|
+
const parts = Object.fromEntries(
|
|
353
|
+
new Intl.DateTimeFormat('en-US', {
|
|
354
|
+
timeZone: tz,
|
|
355
|
+
hour12: false,
|
|
356
|
+
year: 'numeric',
|
|
357
|
+
month: '2-digit',
|
|
358
|
+
day: '2-digit',
|
|
359
|
+
hour: '2-digit',
|
|
360
|
+
minute: '2-digit',
|
|
361
|
+
second: '2-digit',
|
|
362
|
+
})
|
|
363
|
+
.formatToParts(at)
|
|
364
|
+
.filter((p) => p.type !== 'literal')
|
|
365
|
+
.map((p) => [p.type, p.value]),
|
|
366
|
+
);
|
|
367
|
+
const asUtc = Date.UTC(
|
|
368
|
+
Number(parts.year),
|
|
369
|
+
Number(parts.month) - 1,
|
|
370
|
+
Number(parts.day),
|
|
371
|
+
parts.hour === '24' ? 0 : Number(parts.hour),
|
|
372
|
+
Number(parts.minute),
|
|
373
|
+
Number(parts.second),
|
|
374
|
+
);
|
|
375
|
+
const atSec = Math.floor(at.getTime() / 1000) * 1000;
|
|
376
|
+
return asUtc - atSec;
|
|
377
|
+
}
|
|
378
|
+
function zonedDayStart(tz, ymd) {
|
|
379
|
+
const [y, m, d] = ymd.split('-').map(Number);
|
|
380
|
+
const utcMidnight = Date.UTC(y ?? 1970, (m ?? 1) - 1, d ?? 1);
|
|
381
|
+
const guess = new Date(utcMidnight - tzOffsetMs(tz, new Date(utcMidnight)));
|
|
382
|
+
return new Date(utcMidnight - tzOffsetMs(tz, guess));
|
|
383
|
+
}
|
|
384
|
+
function formatZonedIso(tz, at) {
|
|
385
|
+
const off = tzOffsetMs(tz, at);
|
|
386
|
+
const abs = Math.abs(off);
|
|
387
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
388
|
+
const offStr = `${off < 0 ? '-' : '+'}${pad(Math.floor(abs / 3600000))}:${pad(Math.floor((abs % 3600000) / 60000))}`;
|
|
389
|
+
return `${new Date(at.getTime() + off).toISOString().slice(0, 23)}${offStr}`;
|
|
390
|
+
}
|
|
391
|
+
function dayBounds(tz, ymd) {
|
|
392
|
+
const start = zonedDayStart(tz, ymd);
|
|
393
|
+
const nextYmd = localDay(tz, new Date(start.getTime() + 30 * 3600000));
|
|
394
|
+
return {
|
|
395
|
+
since: formatZonedIso(tz, start),
|
|
396
|
+
until: formatZonedIso(tz, new Date(zonedDayStart(tz, nextYmd).getTime() - 1)),
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function resolvePaths(opts) {
|
|
400
|
+
const m = opts.helper.match(/\/scripts\/(?:([^/]+)\/)?[^/]+$/);
|
|
401
|
+
const pluginRoot = m ? opts.helper.slice(0, m.index) : opts.helper;
|
|
402
|
+
const skill = `${pluginRoot}/skills/${m?.[1] ? `${m[1]}-history-anatomy` : 'history-anatomy'}`;
|
|
403
|
+
const tz = opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? 'UTC';
|
|
404
|
+
const date = opts.date !== undefined && opts.date !== '' ? opts.date : localDay(tz, opts.now ?? new Date());
|
|
405
|
+
const target =
|
|
406
|
+
opts.output !== undefined && opts.output !== '' ? opts.output : `${opts.reportDir}/${date}-history-anatomy.md`;
|
|
407
|
+
const adHoc = opts.mode === 'ad-hoc' && !!opts.since && !!opts.until;
|
|
408
|
+
let env = `HA_HELPER=${opts.helper}
|
|
409
|
+
HA_SKILL=${skill}
|
|
410
|
+
HA_TARGET=${target}
|
|
411
|
+
HA_DATE=${date}
|
|
412
|
+
`;
|
|
413
|
+
if (adHoc) {
|
|
414
|
+
return `${env}HA_SINCE=${opts.since}
|
|
415
|
+
HA_UNTIL=${opts.until}
|
|
416
|
+
`;
|
|
417
|
+
}
|
|
418
|
+
const current = dayBounds(tz, date);
|
|
419
|
+
const baseline = dayBounds(tz, localDay(tz, new Date(zonedDayStart(tz, date).getTime() - 12 * 3600000)));
|
|
420
|
+
env += `HA_SINCE=${current.since}
|
|
421
|
+
HA_UNTIL=${current.until}
|
|
422
|
+
`;
|
|
423
|
+
env += `HA_BASELINE_SINCE=${baseline.since}
|
|
424
|
+
HA_BASELINE_UNTIL=${baseline.until}
|
|
425
|
+
`;
|
|
426
|
+
return env;
|
|
427
|
+
}
|
|
428
|
+
function buildProvenance(opts) {
|
|
429
|
+
let raw;
|
|
430
|
+
try {
|
|
431
|
+
raw = JSON.parse(readFileSync(opts.artifact, 'utf8'));
|
|
432
|
+
} catch (err) {
|
|
433
|
+
throw new Error(`could not parse fresh analyze artifact at ${opts.artifact}: ${err.message}`);
|
|
434
|
+
}
|
|
435
|
+
const coverage = (raw.coverage ?? []).map((c) => ({
|
|
436
|
+
source: String(c.source ?? ''),
|
|
437
|
+
status: String(c.status ?? ''),
|
|
438
|
+
lastImportedAt: c.lastImportedAt == null ? null : String(c.lastImportedAt),
|
|
439
|
+
}));
|
|
440
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone ?? 'UTC';
|
|
441
|
+
const now = opts.now ?? new Date();
|
|
442
|
+
const date = opts.date !== undefined && opts.date !== '' ? opts.date : localDay(tz, now);
|
|
443
|
+
const windowState = opts.mode === 'ad-hoc' || date < localDay(tz, now) ? 'closed' : 'provisional';
|
|
444
|
+
const nowIso = now.toISOString();
|
|
445
|
+
return {
|
|
446
|
+
identity: {
|
|
447
|
+
contractVersion: opts.contractVersion ?? '1',
|
|
448
|
+
mode: opts.mode,
|
|
449
|
+
date,
|
|
450
|
+
timezone: tz,
|
|
451
|
+
bounds: { since: String(raw.selector?.since ?? ''), until: String(raw.selector?.until ?? '') },
|
|
452
|
+
sources: coverage.map((c) => c.source).sort(),
|
|
453
|
+
},
|
|
454
|
+
windowState,
|
|
455
|
+
generatedAt: nowIso,
|
|
456
|
+
validatedAt: nowIso,
|
|
457
|
+
artifactDigest: semanticArtifactDigest(raw),
|
|
458
|
+
baselineArtifactDigest: (() => {
|
|
459
|
+
if (!(opts.baseline !== undefined && existsSync(opts.baseline))) return null;
|
|
460
|
+
try {
|
|
461
|
+
return semanticArtifactDigest(JSON.parse(readFileSync(opts.baseline, 'utf8')));
|
|
462
|
+
} catch (err) {
|
|
463
|
+
throw new Error(`could not parse baseline artifact at ${opts.baseline}: ${err.message}`);
|
|
464
|
+
}
|
|
465
|
+
})(),
|
|
466
|
+
contractDigest: logicDigest(opts.contractFile),
|
|
467
|
+
skillDigest: logicDigest(opts.skillDir),
|
|
468
|
+
workflowDigest: logicDigest(opts.workflowFile),
|
|
469
|
+
helperDigest: logicDigest(opts.helperFile),
|
|
470
|
+
coverage,
|
|
471
|
+
runId: opts.runId,
|
|
472
|
+
currentArtifactPath: opts.artifact,
|
|
473
|
+
baselineArtifactPath: opts.baseline ?? null,
|
|
474
|
+
spurVersion: opts.spurVersion ?? NOT_AVAILABLE,
|
|
475
|
+
schemaVersion: typeof raw.schemaVersion === 'number' ? raw.schemaVersion : undefined,
|
|
476
|
+
executor: opts.executor ?? NOT_AVAILABLE,
|
|
477
|
+
model: opts.model ?? NOT_AVAILABLE,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function probe(opts) {
|
|
481
|
+
const current = buildProvenance(opts);
|
|
482
|
+
const cachedText = existsSync(opts.target) ? readFileSync(opts.target, 'utf8') : null;
|
|
483
|
+
const cached = cachedText === null ? null : parseProvenance(cachedText);
|
|
484
|
+
const decision =
|
|
485
|
+
opts.mode === 'ad-hoc'
|
|
486
|
+
? { disposition: 'miss', reasons: ['ad-hoc-never-cached'] }
|
|
487
|
+
: decideCache(cached, current, {
|
|
488
|
+
recompute: opts.recompute,
|
|
489
|
+
dayClosed: current.windowState === 'closed',
|
|
490
|
+
});
|
|
491
|
+
current.cacheDisposition = decision.disposition;
|
|
492
|
+
return { decision, current };
|
|
493
|
+
}
|
|
494
|
+
var YAML_KEYS = [
|
|
495
|
+
'windowState',
|
|
496
|
+
'generatedAt',
|
|
497
|
+
'validatedAt',
|
|
498
|
+
'artifactDigest',
|
|
499
|
+
'baselineArtifactDigest',
|
|
500
|
+
'contractDigest',
|
|
501
|
+
'skillDigest',
|
|
502
|
+
'workflowDigest',
|
|
503
|
+
'helperDigest',
|
|
504
|
+
'runId',
|
|
505
|
+
'currentArtifactPath',
|
|
506
|
+
'baselineArtifactPath',
|
|
507
|
+
'spurVersion',
|
|
508
|
+
'schemaVersion',
|
|
509
|
+
'executor',
|
|
510
|
+
'model',
|
|
511
|
+
'cacheDisposition',
|
|
512
|
+
];
|
|
513
|
+
function yamlScalar(v) {
|
|
514
|
+
if (v === null || v === undefined) return 'null';
|
|
515
|
+
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
|
|
516
|
+
return `"${String(v).replaceAll('"', '\\"')}"`;
|
|
517
|
+
}
|
|
518
|
+
function renderProvenanceFrontmatter(p) {
|
|
519
|
+
const lines = [
|
|
520
|
+
'---',
|
|
521
|
+
'identity:',
|
|
522
|
+
` contractVersion: ${yamlScalar(p.identity.contractVersion)}`,
|
|
523
|
+
` mode: ${p.identity.mode}`,
|
|
524
|
+
` date: ${yamlScalar(p.identity.date)}`,
|
|
525
|
+
` timezone: ${p.identity.timezone}`,
|
|
526
|
+
' bounds:',
|
|
527
|
+
` since: ${p.identity.bounds.since}`,
|
|
528
|
+
` until: ${p.identity.bounds.until}`,
|
|
529
|
+
' sources:',
|
|
530
|
+
];
|
|
531
|
+
for (const s of p.identity.sources) lines.push(` - source: ${s}`);
|
|
532
|
+
for (const k of YAML_KEYS) {
|
|
533
|
+
if (p[k] === undefined) continue;
|
|
534
|
+
lines.push(`${k}: ${yamlScalar(p[k])}`);
|
|
535
|
+
}
|
|
536
|
+
lines.push('coverage:');
|
|
537
|
+
for (const c of p.coverage) {
|
|
538
|
+
lines.push(` - source: ${c.source}, status: ${c.status}, lastImportedAt: ${c.lastImportedAt ?? 'null'}`);
|
|
539
|
+
}
|
|
540
|
+
lines.push('---');
|
|
541
|
+
return lines.join(`
|
|
542
|
+
`);
|
|
543
|
+
}
|
|
544
|
+
function bannerLine(p) {
|
|
545
|
+
return `> imported snapshot as of ${importedSnapshotAsOf(p.coverage)} · window ${p.windowState} · cache ${p.cacheDisposition ?? NOT_AVAILABLE}`;
|
|
546
|
+
}
|
|
547
|
+
function stripHeader(md) {
|
|
548
|
+
const body = md.replace(/^---\n[\s\S]*?\n---\n?/, '').replace(/^\n+/, '');
|
|
549
|
+
return body.replace(/^> imported snapshot as of [^\n]*\n+/, '');
|
|
550
|
+
}
|
|
551
|
+
function stampReport(candidateMarkdown, p) {
|
|
552
|
+
return `${renderProvenanceFrontmatter(p)}
|
|
553
|
+
|
|
554
|
+
${bannerLine(p)}
|
|
555
|
+
|
|
556
|
+
${stripHeader(candidateMarkdown).replace(/^\n+/, '')}`;
|
|
557
|
+
}
|
|
558
|
+
function refreshReport(publishedMarkdown, validatedAt, disposition) {
|
|
559
|
+
const cached = parseProvenance(publishedMarkdown);
|
|
560
|
+
if (cached === null) return publishedMarkdown;
|
|
561
|
+
const refreshed = { ...cached, validatedAt, cacheDisposition: disposition };
|
|
562
|
+
return stampReport(publishedMarkdown, refreshed);
|
|
563
|
+
}
|
|
564
|
+
function publishAtomically(candidatePath, targetPath) {
|
|
565
|
+
const tmpPath = `${targetPath}.tmp`;
|
|
566
|
+
try {
|
|
567
|
+
writeFileSync(tmpPath, readFileSync(candidatePath));
|
|
568
|
+
const fd = openSync(tmpPath, 'r');
|
|
569
|
+
try {
|
|
570
|
+
fsyncSync(fd);
|
|
571
|
+
} finally {
|
|
572
|
+
closeSync(fd);
|
|
573
|
+
}
|
|
574
|
+
renameSync(tmpPath, targetPath);
|
|
575
|
+
} catch (err) {
|
|
576
|
+
try {
|
|
577
|
+
rmSync(tmpPath, { force: true });
|
|
578
|
+
} catch {}
|
|
579
|
+
throw err;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function porcelainPaths(text) {
|
|
583
|
+
return new Set(
|
|
584
|
+
text
|
|
585
|
+
.split(`
|
|
586
|
+
`)
|
|
587
|
+
.map((line) => line.replace(/^\S+\s+/, '').trim())
|
|
588
|
+
.filter((line) => line.length > 0),
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
function diffPorcelain(before, now, expects) {
|
|
592
|
+
const beforePaths = porcelainPaths(before);
|
|
593
|
+
return [...porcelainPaths(now)].filter((p) => !beforePaths.has(p) && !expects.has(p)).sort();
|
|
594
|
+
}
|
|
595
|
+
var VALID_COMMANDS = 'digest, check, paths, assert-clean, probe, stamp, refresh, publish';
|
|
596
|
+
var PROBE_USAGE =
|
|
597
|
+
'<script> probe --artifact <a.json> --target <report.md> [--baseline <b.json>] [--mode daily|ad-hoc] ' +
|
|
598
|
+
'[--date <YYYY-MM-DD>] [--recompute true] [--out <prov.json>] [--skill-dir <d>] [--contract <f>] [--workflow <f>] [--helper <f>]';
|
|
599
|
+
function parseFlags(args) {
|
|
600
|
+
const out = {};
|
|
601
|
+
for (let i = 0; i < args.length; i++) {
|
|
602
|
+
const a = args[i] ?? '';
|
|
603
|
+
if (!a.startsWith('--')) 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 {
|
|
621
|
+
exitCode: 1,
|
|
622
|
+
stdout: '',
|
|
623
|
+
stderr: `usage: <script> digest <artifact.json>
|
|
624
|
+
`,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
let artifact;
|
|
628
|
+
try {
|
|
629
|
+
artifact = JSON.parse(readFileSync(a, 'utf8'));
|
|
630
|
+
} catch {
|
|
631
|
+
return {
|
|
632
|
+
exitCode: 1,
|
|
633
|
+
stdout: '',
|
|
634
|
+
stderr: `could not parse artifact at ${a}
|
|
635
|
+
`,
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
const digest = semanticArtifactDigest(artifact);
|
|
639
|
+
return {
|
|
640
|
+
exitCode: 0,
|
|
641
|
+
stdout: `${digest}
|
|
642
|
+
`,
|
|
643
|
+
stderr: '',
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
case 'check': {
|
|
647
|
+
if (a === undefined) {
|
|
648
|
+
return {
|
|
649
|
+
exitCode: 1,
|
|
650
|
+
stdout: '',
|
|
651
|
+
stderr: `usage: <script> check <report.md>
|
|
652
|
+
`,
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
const result = checkReportStructure(readFileSync(a, 'utf8'));
|
|
656
|
+
const stdout = `${result.ok ? 'PASS' : 'FAIL'}
|
|
657
|
+
${result.problems
|
|
658
|
+
.map(
|
|
659
|
+
(p) => `- ${p}
|
|
660
|
+
`,
|
|
661
|
+
)
|
|
662
|
+
.join('')}`;
|
|
663
|
+
return { exitCode: result.ok ? 0 : 1, stdout, stderr: '' };
|
|
664
|
+
}
|
|
665
|
+
case 'publish': {
|
|
666
|
+
if (a === undefined || b === undefined) {
|
|
667
|
+
return {
|
|
668
|
+
exitCode: 1,
|
|
669
|
+
stdout: '',
|
|
670
|
+
stderr: `usage: <script> publish <candidate.md> <target.md>
|
|
671
|
+
`,
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
publishAtomically(a, b);
|
|
675
|
+
return { exitCode: 0, stdout: '', stderr: '' };
|
|
676
|
+
}
|
|
677
|
+
case 'assert-clean': {
|
|
678
|
+
const f = parseFlags(argv.slice(1));
|
|
679
|
+
if (f.baseline === undefined) {
|
|
680
|
+
return {
|
|
681
|
+
exitCode: 1,
|
|
682
|
+
stdout: '',
|
|
683
|
+
stderr: `usage: <script> assert-clean --baseline <porcelain.txt> [--expect <path>]...
|
|
684
|
+
`,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
const expects = new Set();
|
|
688
|
+
for (const arg of argv.slice(1)) {
|
|
689
|
+
if (arg.startsWith('--expect=')) expects.add(arg.slice('--expect='.length));
|
|
690
|
+
}
|
|
691
|
+
let now;
|
|
692
|
+
try {
|
|
693
|
+
now =
|
|
694
|
+
spawnSync('git', ['status', '--porcelain'], {
|
|
695
|
+
encoding: 'utf8',
|
|
696
|
+
...(f.cwd !== undefined ? { cwd: f.cwd } : {}),
|
|
697
|
+
}).stdout ?? '';
|
|
698
|
+
} catch {
|
|
699
|
+
return {
|
|
700
|
+
exitCode: 0,
|
|
701
|
+
stdout: '',
|
|
702
|
+
stderr: `assert-clean: git unavailable; skipped
|
|
703
|
+
`,
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
const undeclared = diffPorcelain(readFileSync(f.baseline, 'utf8'), now, expects);
|
|
707
|
+
if (undeclared.length > 0) {
|
|
708
|
+
return {
|
|
709
|
+
exitCode: 1,
|
|
710
|
+
stdout: '',
|
|
711
|
+
stderr: undeclared
|
|
712
|
+
.map(
|
|
713
|
+
(p) => `undeclared write: ${p}
|
|
714
|
+
`,
|
|
715
|
+
)
|
|
716
|
+
.join(''),
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
exitCode: 0,
|
|
721
|
+
stdout: `clean
|
|
722
|
+
`,
|
|
723
|
+
stderr: '',
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
case 'paths': {
|
|
727
|
+
const f = parseFlags(argv.slice(1));
|
|
728
|
+
if (f.helper === undefined || f.out === undefined) {
|
|
729
|
+
return {
|
|
730
|
+
exitCode: 1,
|
|
731
|
+
stdout: '',
|
|
732
|
+
stderr: `usage: <script> paths --helper <p> --out <env> [--report-dir <d>] [--date <d>] [--output <p>] [--mode <m>] [--since <s>] [--until <u>]
|
|
733
|
+
`,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
writeFileSync(
|
|
737
|
+
f.out,
|
|
738
|
+
resolvePaths({
|
|
739
|
+
helper: f.helper,
|
|
740
|
+
reportDir: f['report-dir'] ?? 'docs/report',
|
|
741
|
+
date: f.date,
|
|
742
|
+
output: f.output,
|
|
743
|
+
mode: f.mode,
|
|
744
|
+
since: f.since,
|
|
745
|
+
until: f.until,
|
|
746
|
+
}),
|
|
747
|
+
);
|
|
748
|
+
return { exitCode: 0, stdout: '', stderr: '' };
|
|
749
|
+
}
|
|
750
|
+
case 'probe': {
|
|
751
|
+
const f = parseFlags(argv.slice(1));
|
|
752
|
+
if (f.artifact === undefined || f.target === undefined) {
|
|
753
|
+
return {
|
|
754
|
+
exitCode: 1,
|
|
755
|
+
stdout: '',
|
|
756
|
+
stderr: `usage: ${PROBE_USAGE}
|
|
757
|
+
`,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
let result;
|
|
761
|
+
try {
|
|
762
|
+
result = probe({
|
|
763
|
+
artifact: f.artifact,
|
|
764
|
+
target: f.target,
|
|
765
|
+
baseline: f.baseline,
|
|
766
|
+
mode: f.mode === 'ad-hoc' ? 'ad-hoc' : 'daily',
|
|
767
|
+
date: f.date,
|
|
768
|
+
recompute: f.recompute === 'true',
|
|
769
|
+
executor: f.executor,
|
|
770
|
+
model: f.model,
|
|
771
|
+
skillDir: f['skill-dir'],
|
|
772
|
+
contractFile: f.contract,
|
|
773
|
+
workflowFile: f.workflow,
|
|
774
|
+
helperFile: f.helper,
|
|
775
|
+
contractVersion: f['contract-version'],
|
|
776
|
+
runId: f['run-id'],
|
|
777
|
+
spurVersion: f['spur-version'],
|
|
778
|
+
});
|
|
779
|
+
} catch {
|
|
780
|
+
return {
|
|
781
|
+
exitCode: 1,
|
|
782
|
+
stdout: '',
|
|
783
|
+
stderr: `could not read artifact at ${f.artifact}
|
|
784
|
+
`,
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
if (f.out !== undefined)
|
|
788
|
+
writeFileSync(
|
|
789
|
+
f.out,
|
|
790
|
+
`${JSON.stringify(result.current, null, 2)}
|
|
791
|
+
`,
|
|
792
|
+
);
|
|
793
|
+
const reasons = result.decision.reasons
|
|
794
|
+
.map(
|
|
795
|
+
(r) => `- ${r}
|
|
796
|
+
`,
|
|
797
|
+
)
|
|
798
|
+
.join('');
|
|
799
|
+
return {
|
|
800
|
+
exitCode: 0,
|
|
801
|
+
stdout: `${result.decision.disposition}
|
|
802
|
+
${reasons}`,
|
|
803
|
+
stderr: '',
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
case 'stamp': {
|
|
807
|
+
const f = parseFlags(argv.slice(1));
|
|
808
|
+
if (f.candidate === undefined || f.provenance === undefined || f.out === undefined) {
|
|
809
|
+
return {
|
|
810
|
+
exitCode: 1,
|
|
811
|
+
stdout: '',
|
|
812
|
+
stderr: `usage: <script> stamp --candidate <c.md> --provenance <p.json> --out <o.md>
|
|
813
|
+
`,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
try {
|
|
817
|
+
const p = JSON.parse(readFileSync(f.provenance, 'utf8'));
|
|
818
|
+
writeFileSync(
|
|
819
|
+
f.out,
|
|
820
|
+
`${stampReport(readFileSync(f.candidate, 'utf8'), p)}
|
|
821
|
+
`,
|
|
822
|
+
);
|
|
823
|
+
} catch {
|
|
824
|
+
return {
|
|
825
|
+
exitCode: 1,
|
|
826
|
+
stdout: '',
|
|
827
|
+
stderr: `stamp: could not read candidate or provenance
|
|
828
|
+
`,
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
return { exitCode: 0, stdout: '', stderr: '' };
|
|
832
|
+
}
|
|
833
|
+
case 'refresh': {
|
|
834
|
+
const f = parseFlags(argv.slice(1));
|
|
835
|
+
if (f.report === undefined || f.out === undefined) {
|
|
836
|
+
return {
|
|
837
|
+
exitCode: 1,
|
|
838
|
+
stdout: '',
|
|
839
|
+
stderr: `usage: <script> refresh --report <published.md> --out <o.md> [--disposition hit]
|
|
840
|
+
`,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
try {
|
|
844
|
+
const disposition = f.disposition ?? 'hit';
|
|
845
|
+
const refreshed = refreshReport(
|
|
846
|
+
readFileSync(f.report, 'utf8'),
|
|
847
|
+
f['validated-at'] ?? new Date().toISOString(),
|
|
848
|
+
disposition,
|
|
849
|
+
);
|
|
850
|
+
writeFileSync(
|
|
851
|
+
f.out,
|
|
852
|
+
refreshed.endsWith(`
|
|
853
|
+
`)
|
|
854
|
+
? refreshed
|
|
855
|
+
: `${refreshed}
|
|
856
|
+
`,
|
|
857
|
+
);
|
|
858
|
+
} catch {
|
|
859
|
+
return {
|
|
860
|
+
exitCode: 1,
|
|
861
|
+
stdout: '',
|
|
862
|
+
stderr: `refresh: could not read report at ${f.report}
|
|
863
|
+
`,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
return { exitCode: 0, stdout: '', stderr: '' };
|
|
867
|
+
}
|
|
868
|
+
default:
|
|
869
|
+
return {
|
|
870
|
+
exitCode: 1,
|
|
871
|
+
stdout: '',
|
|
872
|
+
stderr: `valid commands: ${VALID_COMMANDS}
|
|
873
|
+
`,
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
{
|
|
878
|
+
const { exitCode, stdout, stderr } = runCacheCli(process.argv.slice(2));
|
|
879
|
+
process.stdout.write(stdout);
|
|
880
|
+
process.stderr.write(stderr);
|
|
881
|
+
process.exitCode = exitCode;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
export {
|
|
885
|
+
bannerLine,
|
|
886
|
+
buildProvenance,
|
|
887
|
+
checkReportStructure,
|
|
888
|
+
decideCache,
|
|
889
|
+
diffPorcelain,
|
|
890
|
+
importedSnapshotAsOf,
|
|
891
|
+
logicDigest,
|
|
892
|
+
parseProvenance,
|
|
893
|
+
porcelainPaths,
|
|
894
|
+
probe,
|
|
895
|
+
publishAtomically,
|
|
896
|
+
refreshReport,
|
|
897
|
+
renderProvenanceFrontmatter,
|
|
898
|
+
resolvePaths,
|
|
899
|
+
runCacheCli,
|
|
900
|
+
semanticArtifactDigest,
|
|
901
|
+
stampReport,
|
|
902
|
+
};
|