@dzhechkov/harness-core 0.5.0 → 0.5.2
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/.dz-manifest.json +339 -75
- package/README.md +47 -4
- package/dist/codex-hooks-assets.d.ts.map +1 -1
- package/dist/codex-hooks-assets.js +39 -2
- package/dist/codex-hooks-assets.js.map +1 -1
- package/dist/codex-hooks-verify.d.ts +23 -2
- package/dist/codex-hooks-verify.d.ts.map +1 -1
- package/dist/codex-hooks-verify.js +29 -0
- package/dist/codex-hooks-verify.js.map +1 -1
- package/dist/codex-hooks.d.ts +90 -7
- package/dist/codex-hooks.d.ts.map +1 -1
- package/dist/codex-hooks.js +171 -21
- package/dist/codex-hooks.js.map +1 -1
- package/dist/feature-adr-routing.d.ts +22 -0
- package/dist/feature-adr-routing.d.ts.map +1 -1
- package/dist/feature-adr-routing.js +45 -0
- package/dist/feature-adr-routing.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/dist/loop-blobs.generated.d.ts +1 -1
- package/dist/loop-blobs.generated.d.ts.map +1 -1
- package/dist/loop-blobs.generated.js +12 -3
- package/dist/loop-blobs.generated.js.map +1 -1
- package/dist/loop-plan.d.ts +70 -0
- package/dist/loop-plan.d.ts.map +1 -1
- package/dist/loop-plan.js +103 -0
- package/dist/loop-plan.js.map +1 -1
- package/dist/loop-render.d.ts.map +1 -1
- package/dist/loop-render.js +38 -130
- package/dist/loop-render.js.map +1 -1
- package/dist/loop-run-semantics.d.ts +130 -0
- package/dist/loop-run-semantics.d.ts.map +1 -0
- package/dist/loop-run-semantics.js +257 -0
- package/dist/loop-run-semantics.js.map +1 -0
- package/dist/loop-trace.d.ts +106 -5
- package/dist/loop-trace.d.ts.map +1 -1
- package/dist/loop-trace.js +151 -18
- package/dist/loop-trace.js.map +1 -1
- package/dist/managed-hooks.d.ts +10 -0
- package/dist/managed-hooks.d.ts.map +1 -1
- package/dist/managed-hooks.js +17 -5
- package/dist/managed-hooks.js.map +1 -1
- package/dist/named-lock.d.ts +57 -0
- package/dist/named-lock.d.ts.map +1 -0
- package/dist/named-lock.js +247 -0
- package/dist/named-lock.js.map +1 -0
- package/dist/operations.d.ts +81 -5
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +356 -38
- package/dist/operations.js.map +1 -1
- package/dist/parity.d.ts +70 -2
- package/dist/parity.d.ts.map +1 -1
- package/dist/parity.js +133 -2
- package/dist/parity.js.map +1 -1
- package/dist/qe-bridge.d.ts +291 -0
- package/dist/qe-bridge.d.ts.map +1 -0
- package/dist/qe-bridge.js +538 -0
- package/dist/qe-bridge.js.map +1 -0
- package/dist/score.d.ts.map +1 -1
- package/dist/score.js +43 -9
- package/dist/score.js.map +1 -1
- package/dist/trace-corroborate.d.ts +48 -0
- package/dist/trace-corroborate.d.ts.map +1 -0
- package/dist/trace-corroborate.js +172 -0
- package/dist/trace-corroborate.js.map +1 -0
- package/dist/workflow-run-dispatch.d.ts +230 -0
- package/dist/workflow-run-dispatch.d.ts.map +1 -0
- package/dist/workflow-run-dispatch.js +363 -0
- package/dist/workflow-run-dispatch.js.map +1 -0
- package/dist/workflow-run.d.ts +513 -0
- package/dist/workflow-run.d.ts.map +1 -0
- package/dist/workflow-run.js +1377 -0
- package/dist/workflow-run.js.map +1 -0
- package/package.json +2 -2
- package/sbom.json +740 -80
- package/src/codex-hooks-assets.ts +39 -2
- package/src/codex-hooks-verify.ts +55 -2
- package/src/codex-hooks.ts +172 -20
- package/src/feature-adr-routing.ts +55 -0
- package/src/index.ts +46 -1
- package/src/loop-blobs.generated.ts +12 -3
- package/src/loop-plan.ts +185 -0
- package/src/loop-render.ts +38 -128
- package/src/loop-run-semantics.ts +278 -0
- package/src/loop-trace.ts +207 -16
- package/src/managed-hooks.ts +26 -5
- package/src/named-lock.ts +277 -0
- package/src/operations.ts +441 -40
- package/src/parity.ts +177 -2
- package/src/qe-bridge.ts +737 -0
- package/src/score.ts +50 -9
- package/src/trace-corroborate.ts +205 -0
- package/src/workflow-run-dispatch.ts +459 -0
- package/src/workflow-run.ts +1773 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `loop-run-semantics` — the ONE home of loop-designer's ENACTMENT DECISIONS (feature
|
|
3
|
+
* dz-workflow-run, ADR-001 W4).
|
|
4
|
+
*
|
|
5
|
+
* Before this module these semantics existed ONLY as template strings inside
|
|
6
|
+
* `loop-render.ts:renderRuntime` — readable by the generated Claude-host script and by nobody
|
|
7
|
+
* else. A second enactor (`dz workflow run`) would have had to COPY them, and two copies of a
|
|
8
|
+
* gate-verdict grammar is exactly how a runner comes to synthesize a pass the render would have
|
|
9
|
+
* refused. So the decisions move here once and are consumed twice:
|
|
10
|
+
* • the generated script gets them as a BLOB (`scripts/gen-loop-blobs.mjs`, blob `loop-semantics`,
|
|
11
|
+
* always on — the base runtime references errText/classifyFailure in every script);
|
|
12
|
+
* • the dz runner imports them directly.
|
|
13
|
+
* "Imported, not copied" stops being an intention and becomes a fact a test can check.
|
|
14
|
+
*
|
|
15
|
+
* SCOPE, honestly (ADR-001 names it): what moves is DECISION semantics. `__drainAll`,
|
|
16
|
+
* `runStep` and `__settleStep` do NOT move — they are HOST-STRUCTURAL (they wrap the sandbox's
|
|
17
|
+
* `parallel()`/`agent()` and its settle discipline); the runner has its own structured concurrency
|
|
18
|
+
* and its own settle path.
|
|
19
|
+
*
|
|
20
|
+
* BLOB-SOURCE DISCIPLINE (same rule as `loop-trace.ts`): this module has NO RUNTIME IMPORT — its
|
|
21
|
+
* single `import type` is erased at compile time, so the generator can slice declarations out of it
|
|
22
|
+
* with no import to resolve. The generator's INV-12 output ban (fs / clock / randomness / process)
|
|
23
|
+
* holds here by construction: every function below is pure.
|
|
24
|
+
*
|
|
25
|
+
* One consequence of that discipline is visible in the signatures: the six BLOB-EXPORTED functions
|
|
26
|
+
* may not mention an IMPORTED type by bare name (the slicer would see an unresolvable cross-file
|
|
27
|
+
* reference and fail closed), so `classifyFailure` spells its return type as the inline import type
|
|
28
|
+
* `import('./loop-plan.js').FailureClass`. It is the SAME closed enum — one domain, not a restated
|
|
29
|
+
* copy — written in the one form the slicer can carry.
|
|
30
|
+
*/
|
|
31
|
+
/** Blob version stamp read by scripts/gen-loop-blobs.mjs. */
|
|
32
|
+
export const LOOP_RUN_SEMANTICS_BLOB_VERSION = '1.0.0';
|
|
33
|
+
/**
|
|
34
|
+
* TOTAL error-to-text (the ha-consilium 5b totality lesson): the writer's own settle event must
|
|
35
|
+
* survive a hostile error object. `String(err)` throws on a null-prototype object and a throwing
|
|
36
|
+
* `.message` getter throws on access — both are caught here, so rendering a message can never
|
|
37
|
+
* replace the original failure or lose the settle. `.message` is read ONCE into a local (a one-shot
|
|
38
|
+
* getter answered the `typeof` probe and vanished on the value read — snapshot-once defeats it).
|
|
39
|
+
*/
|
|
40
|
+
export function errText(err) {
|
|
41
|
+
try {
|
|
42
|
+
if (err !== null && typeof err === 'object') {
|
|
43
|
+
const m = err.message;
|
|
44
|
+
if (typeof m === 'string')
|
|
45
|
+
return m;
|
|
46
|
+
}
|
|
47
|
+
return String(err);
|
|
48
|
+
}
|
|
49
|
+
catch (_e) {
|
|
50
|
+
try {
|
|
51
|
+
return Object.prototype.toString.call(err);
|
|
52
|
+
}
|
|
53
|
+
catch (_e2) {
|
|
54
|
+
return '[unrenderable error]';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `err.cause` chain, bounded (depth 5), cycle-safe and getter-safe. The standard Node fetch
|
|
60
|
+
* shape `TypeError('fetch failed', { cause: { code: 'ECONNRESET' } })` hides its real class one
|
|
61
|
+
* link down, so classification must see the whole chain, not the outermost error.
|
|
62
|
+
*/
|
|
63
|
+
export function causeChain(err) {
|
|
64
|
+
const chain = [];
|
|
65
|
+
let cur = err;
|
|
66
|
+
for (let d = 0; d < 5; d++) {
|
|
67
|
+
if (cur === null || cur === undefined)
|
|
68
|
+
break;
|
|
69
|
+
if (chain.indexOf(cur) !== -1)
|
|
70
|
+
break; // cycle-safe
|
|
71
|
+
chain.push(cur);
|
|
72
|
+
try {
|
|
73
|
+
cur = typeof cur === 'object' ? cur.cause : undefined;
|
|
74
|
+
}
|
|
75
|
+
catch (_e) {
|
|
76
|
+
cur = undefined; // getter-safe
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return chain.length > 0 ? chain : [err];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* ONE snapshot PER FAILURE. The earlier shape snapshotted `.message` once per `errText` CALL, not
|
|
83
|
+
* once per failure — so logging read it, classification read it AGAIN, and a one-shot `.message`
|
|
84
|
+
* getter answered the log and defeated the classifier (2 getter reads, 1 attempt, MEASURED). The
|
|
85
|
+
* catch site builds this snapshot once; the log line and the classifier both consume the SNAPSHOT,
|
|
86
|
+
* so `.code` / `.name` / `.message` are each read exactly once per failure, over the whole chain.
|
|
87
|
+
*/
|
|
88
|
+
export function errSnap(err) {
|
|
89
|
+
const chain = causeChain(err);
|
|
90
|
+
const snap = [];
|
|
91
|
+
for (let ci = 0; ci < chain.length; ci++) {
|
|
92
|
+
let code = null;
|
|
93
|
+
try {
|
|
94
|
+
const c = chain[ci] !== null && typeof chain[ci] === 'object' ? chain[ci].code : null;
|
|
95
|
+
code = typeof c === 'string' ? c.toUpperCase() : null;
|
|
96
|
+
}
|
|
97
|
+
catch (_e) {
|
|
98
|
+
code = null;
|
|
99
|
+
}
|
|
100
|
+
let name = null;
|
|
101
|
+
try {
|
|
102
|
+
const n = chain[ci] !== null && typeof chain[ci] === 'object' ? chain[ci].name : null;
|
|
103
|
+
name = typeof n === 'string' ? n : null;
|
|
104
|
+
}
|
|
105
|
+
catch (_e) {
|
|
106
|
+
name = null;
|
|
107
|
+
}
|
|
108
|
+
snap.push({ code: code, name: name, text: errText(chain[ci]) });
|
|
109
|
+
}
|
|
110
|
+
return snap;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The CLOSED failure classification of `loop-plan/1` (timeout | transport | malformed-output |
|
|
114
|
+
* policy-refusal). THREE TIERS over the whole cause chain, strongest first:
|
|
115
|
+
* 1. error CODE — works on non-Error shapes like `{code:'ECONNRESET'}`, never message-dependent
|
|
116
|
+
* (`ETIMEDOUT` is a TRANSPORT code; an earlier message regex captured it as 'timeout' first);
|
|
117
|
+
* 2. error NAME — `SyntaxError` = parsing the model's output failed → malformed-output;
|
|
118
|
+
* 3. message patterns, DISJOINT by precedence transport > policy-refusal > malformed-output >
|
|
119
|
+
* timeout, every alternative WORD-BOUNDED (an unbounded `rate.?limit` matched
|
|
120
|
+
* 'delibeRATE LIMITation' — a substring must never smuggle a class).
|
|
121
|
+
* `outcome: 'null'` (a dead/empty agent) is a delivery failure ⇒ `transport`, retryable ONLY under
|
|
122
|
+
* `retryOn: ['transport']`. An UNCLASSIFIABLE failure returns null and is NEVER retried.
|
|
123
|
+
*/
|
|
124
|
+
export function classifyFailure(outcome, snap) {
|
|
125
|
+
if (outcome === 'null')
|
|
126
|
+
return 'transport';
|
|
127
|
+
const links = Array.isArray(snap) ? snap : [];
|
|
128
|
+
for (let ci = 0; ci < links.length; ci++) {
|
|
129
|
+
const code = links[ci].code;
|
|
130
|
+
if (code === 'ETIMEDOUT' || code === 'ECONNRESET' || code === 'ECONNREFUSED' || code === 'ENOTFOUND' || code === 'EPIPE' || code === 'ECONNABORTED' || code === 'EAI_AGAIN')
|
|
131
|
+
return 'transport';
|
|
132
|
+
}
|
|
133
|
+
for (let ci = 0; ci < links.length; ci++) {
|
|
134
|
+
if (links[ci].name === 'SyntaxError')
|
|
135
|
+
return 'malformed-output';
|
|
136
|
+
}
|
|
137
|
+
let msg = '';
|
|
138
|
+
for (let ci = 0; ci < links.length; ci++)
|
|
139
|
+
msg += (ci > 0 ? '\n' : '') + links[ci].text;
|
|
140
|
+
msg = msg.toLowerCase();
|
|
141
|
+
// rate[ -]?limit(ed|ing|s)? is RIGHT-BOUNDED: the open 'rate.?limit' matched
|
|
142
|
+
// 'rate limitation: invalid JSON' as transport — a malformed-output failure smuggled a class.
|
|
143
|
+
if (/\btransport\b|\beconnreset\b|\beconnrefused\b|\benotfound\b|\bepipe\b|\betimedout\b|\bsocket hang up\b|\bnetwork error\b|\brate[ -]?limit(ed|ing|s)?\b|\boverloaded\b|\bhttp 5[0-9][0-9]\b/.test(msg))
|
|
144
|
+
return 'transport';
|
|
145
|
+
if (/\bpolicy\b|\brefus(e|ed|es|al|ing)\b|\bdeclin(e|ed|es|ing)\b|\bcontent filter\b|\bsafety block\b/.test(msg))
|
|
146
|
+
return 'policy-refusal';
|
|
147
|
+
if (/\bmalformed\b|\bunparseable\b|\bparse error\b|\binvalid json\b|\bunexpected token\b|\bunexpected end of json\b|\bschema mismatch\b/.test(msg))
|
|
148
|
+
return 'malformed-output';
|
|
149
|
+
if (/\btimeout\b|\btimed out\b/.test(msg))
|
|
150
|
+
return 'timeout';
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gate verdict parsing — parse-NEVER-synthesize, with the EXACTLY-ONE-ENDING-LINE protocol
|
|
155
|
+
* enforced: the verdict must be an ANCHORED line ("GATE: PASS" or "GATE: FAIL" alone on its line),
|
|
156
|
+
* it must be the LAST non-empty line of the reply, and it must be the ONLY anchored verdict line.
|
|
157
|
+
* Embedded mid-reply "GATE: PASS" text never counts, "GATE: PASS" followed by trailing prose is
|
|
158
|
+
* invalid, and "GATE: FAIL … GATE: PASS" is an INVALID verdict (never a success) — routed like a
|
|
159
|
+
* failure (redo / fail route), never a pass.
|
|
160
|
+
*/
|
|
161
|
+
export function gateVerdict(reply) {
|
|
162
|
+
if (typeof reply !== 'string')
|
|
163
|
+
return 'invalid';
|
|
164
|
+
const vLines = reply.split('\n');
|
|
165
|
+
const vRe = /^\s*GATE:\s*(PASS|FAIL)\s*$/;
|
|
166
|
+
let vCount = 0;
|
|
167
|
+
let vLast = '';
|
|
168
|
+
for (let i = 0; i < vLines.length; i++) {
|
|
169
|
+
if (vRe.test(vLines[i]))
|
|
170
|
+
vCount++;
|
|
171
|
+
if (vLines[i].trim() !== '')
|
|
172
|
+
vLast = vLines[i];
|
|
173
|
+
}
|
|
174
|
+
const vEnd = vRe.exec(vLast);
|
|
175
|
+
if (vCount !== 1 || vEnd === null)
|
|
176
|
+
return 'invalid';
|
|
177
|
+
return vEnd[1] === 'PASS' ? 'pass' : 'fail';
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The join decision — explicit policy from the closed set; a dispatched branch is never skippable.
|
|
181
|
+
* `any` fails only when EVERY branch failed; `quorum:<n>` needs n non-failing branches; every other
|
|
182
|
+
* policy (the `all-*` family) fails on the first failing branch. Throws with a NAMED message, which
|
|
183
|
+
* the caller settles through its own single terminal exit.
|
|
184
|
+
*/
|
|
185
|
+
export function joinRegion(results, o) {
|
|
186
|
+
const policy = o && o.policy ? o.policy : 'all-activated';
|
|
187
|
+
const failures = [];
|
|
188
|
+
for (let i = 0; i < results.length; i++) {
|
|
189
|
+
if (results[i] === null || results[i] === undefined)
|
|
190
|
+
failures.push(i);
|
|
191
|
+
}
|
|
192
|
+
if (policy === 'any') {
|
|
193
|
+
if (failures.length === results.length)
|
|
194
|
+
throw new Error('join ' + o.region + ': every branch failed (policy any)');
|
|
195
|
+
return { ok: true, values: results, failures: failures };
|
|
196
|
+
}
|
|
197
|
+
const quorum = /^quorum:([1-9][0-9]*)$/.exec(policy);
|
|
198
|
+
if (quorum) {
|
|
199
|
+
const okN = results.length - failures.length;
|
|
200
|
+
if (okN < Number(quorum[1]))
|
|
201
|
+
throw new Error('join ' + o.region + ': quorum ' + quorum[1] + ' not met (' + okN + ' ok)');
|
|
202
|
+
return { ok: true, values: results, failures: failures };
|
|
203
|
+
}
|
|
204
|
+
if (failures.length > 0)
|
|
205
|
+
throw new Error('join ' + o.region + ': ' + failures.length + ' dispatched branch(es) failed under policy ' + policy + ' — a dispatched branch is never skippable');
|
|
206
|
+
return { ok: true, values: results, failures: [] };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* THE agent-visible contract TEXT lines (ADR-001 Confirmation-5) — byte-for-byte the strings the
|
|
210
|
+
* render splices after a step's USER prompt, minus the JS quoting. Both enactors assemble a step's
|
|
211
|
+
* prompt from the SAME function, so a dz-hosted step and a Claude-hosted step communicate the plan's
|
|
212
|
+
* declarations identically; a value-pinned wiring test compares the rendered USER-region contract
|
|
213
|
+
* lines against the runner-assembled ones.
|
|
214
|
+
*
|
|
215
|
+
* The tools line's second sentence is not decoration — it is the honesty clause the whole feature
|
|
216
|
+
* rests on: a declaration is not enforcement.
|
|
217
|
+
*/
|
|
218
|
+
export function stepContractLines(c) {
|
|
219
|
+
const lines = [];
|
|
220
|
+
const reads = c.reads ?? [];
|
|
221
|
+
const writes = c.writes ?? [];
|
|
222
|
+
const tools = c.tools ?? [];
|
|
223
|
+
if (reads.length > 0)
|
|
224
|
+
lines.push('declared inputs (plan artifacts.reads): ' + reads.join(', '));
|
|
225
|
+
if (writes.length > 0) {
|
|
226
|
+
const fileNote = (c.deliverable ?? 'return-value') === 'file' ? '; your deliverable is the written file(s), not your reply' : '';
|
|
227
|
+
lines.push('declared outputs (plan artifacts.writes): ' + writes.join(', ') + ' — write them' + fileNote + '. The loop verifies they land.');
|
|
228
|
+
}
|
|
229
|
+
if (tools.length > 0) {
|
|
230
|
+
lines.push('declared MCP tool allowlist (plan tools): ' + tools.join(', ') + ' — use NOTHING outside it. In this environment every one of these is a labeled STUB, not a live integration; enforcement lives at the MCP server, not here.');
|
|
231
|
+
}
|
|
232
|
+
if (c.gate !== null && c.gate !== undefined) {
|
|
233
|
+
lines.push('GATE PROTOCOL (kind: ' + (c.gate.kind ?? 'gate') + '): end your reply with exactly one line "GATE: PASS" or "GATE: FAIL" — the loop PARSES this verdict and never synthesizes one.');
|
|
234
|
+
}
|
|
235
|
+
return lines;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* THE budget ceiling formula (ADR-004 Confirmation-2): declared per-step budgets PLUS the declared
|
|
239
|
+
* gate-redo allowance — a plan-declared redo must be AFFORDABLE (an undeclared one still hits the
|
|
240
|
+
* guard loudly). A gate whose failRoute is a `terminal:` route reserves nothing: a terminal route
|
|
241
|
+
* ends the run, it does not re-run anything.
|
|
242
|
+
*
|
|
243
|
+
* This is the number the rendered script carries as `const __budget = { left: N }`; the runner reads
|
|
244
|
+
* it from HERE, so the two enactors cannot drift into two ceilings.
|
|
245
|
+
*/
|
|
246
|
+
export function computeBudgetTotal(plan) {
|
|
247
|
+
const stepBudget = plan.steps.reduce((n, s) => n + (s.budget?.maxAgents ?? 1), 0);
|
|
248
|
+
const byId = new Map(plan.steps.map((s) => [s.stepId, s]));
|
|
249
|
+
const gateRedoBudget = (plan.gates ?? []).reduce((n, g) => {
|
|
250
|
+
const redos = typeof g.maxRedos === 'number' && Number.isFinite(g.maxRedos) && g.maxRedos > 0 ? Math.floor(g.maxRedos) : 0;
|
|
251
|
+
if (redos === 0 || typeof g.failRoute !== 'string' || g.failRoute.startsWith('terminal:'))
|
|
252
|
+
return n;
|
|
253
|
+
return n + redos * ((byId.get(g.failRoute)?.budget?.maxAgents ?? 1) + (byId.get(g.stepId)?.budget?.maxAgents ?? 1));
|
|
254
|
+
}, 0);
|
|
255
|
+
return stepBudget + gateRedoBudget;
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=loop-run-semantics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-run-semantics.js","sourceRoot":"","sources":["../src/loop-run-semantics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,+BAA+B,GAAG,OAAO,CAAC;AAevD;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAY;IAClC,IAAI,CAAC;QACH,IAAI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,UAAU,CAAC,WAAW,CAAC;YAAE,OAAO,CAAC,CAAC;QACpG,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC;IACtH,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,OAAO,UAAU,GAAG,cAAc,CAAC;AACrC,CAAC"}
|
package/dist/loop-trace.d.ts
CHANGED
|
@@ -53,6 +53,14 @@ export interface TraceSettleEvent {
|
|
|
53
53
|
outcome: 'ok' | 'null' | 'error';
|
|
54
54
|
wallTime?: string | null;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* WHICH CODE PATH was meant to write this file. A HINT, never a trust statement — the rendered
|
|
58
|
+
* script's flush is performed BY AN AGENT, which therefore controls these bytes before the file
|
|
59
|
+
* exists and could write any value here. It is deliberately NOT called `attestedBy`, so nothing in
|
|
60
|
+
* the codebase can read it as provenance (ADR-001 round 1 made exactly that mistake). The trust
|
|
61
|
+
* question is answered by `deriveAttestation`, from an artifact the sandboxed script cannot write.
|
|
62
|
+
*/
|
|
63
|
+
export type TraceEmitterPath = 'dz-process' | 'rendered-script';
|
|
56
64
|
export interface TraceRunOpened {
|
|
57
65
|
v: 1;
|
|
58
66
|
runId: string;
|
|
@@ -60,6 +68,9 @@ export interface TraceRunOpened {
|
|
|
60
68
|
event: 'run.opened';
|
|
61
69
|
planDigest: string;
|
|
62
70
|
execFp: string;
|
|
71
|
+
/** Optional ON THE WIRE (NFR-1): an older reader ignores it, a newer reader over an older trace
|
|
72
|
+
* gets `unknown` — which is never `instrument`. */
|
|
73
|
+
emitterPath?: TraceEmitterPath;
|
|
63
74
|
}
|
|
64
75
|
export interface TraceRunClosed {
|
|
65
76
|
v: 1;
|
|
@@ -89,8 +100,14 @@ export declare function traceShellQuote(s: string): string;
|
|
|
89
100
|
* time — never a line repaired later. Returns an error string or null.
|
|
90
101
|
*/
|
|
91
102
|
export declare function traceValidateEvent(e: unknown): string | null;
|
|
92
|
-
/**
|
|
93
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Open a trace state and buffer the run.opened frame. Throws on an invalid runId (fail-closed).
|
|
105
|
+
*
|
|
106
|
+
* `emitterPath` is REQUIRED and has NO DEFAULT, on purpose: a default would be chosen once, by
|
|
107
|
+
* whoever added the parameter, and every future caller that forgot it would silently inherit that
|
|
108
|
+
* choice. A missing argument must be a compile error instead.
|
|
109
|
+
*/
|
|
110
|
+
export declare function traceInit(runId: string, planDigest: string, execFp: string, emitterPath: TraceEmitterPath): TraceState;
|
|
94
111
|
/**
|
|
95
112
|
* Allocate the DISPATCH seq and buffer the event — called SYNCHRONOUSLY immediately before the
|
|
96
113
|
* `agent()`/`parallel()` call (the same synchronous statement pair; AM-2). Returns the seq.
|
|
@@ -119,6 +136,15 @@ export declare function traceClose(state: TraceState): void;
|
|
|
119
136
|
* diagnostic only (INV-16). Returns null when the buffer is empty (no agent call to spend).
|
|
120
137
|
*/
|
|
121
138
|
export declare function traceFlushCmd(state: TraceState, traceFileAbs: string): string | null;
|
|
139
|
+
/**
|
|
140
|
+
* Drain the buffered, already-VALIDATED lines — the runner's flush primitive (W17/T0.1). The
|
|
141
|
+
* fs-less Claude host turns the same buffer into a shell command (`traceFlushCmd`); a host that
|
|
142
|
+
* HAS fs (the `dz workflow run` scheduler) appends exactly these lines itself. One buffer, two
|
|
143
|
+
* drains, zero second line-shape: a line this returns has already passed `traceValidateEvent`,
|
|
144
|
+
* because nothing else can enter the buffer. Empty buffer ⇒ `[]` (never a repeat of the last
|
|
145
|
+
* batch).
|
|
146
|
+
*/
|
|
147
|
+
export declare function traceDrain(state: TraceState): string[];
|
|
122
148
|
/**
|
|
123
149
|
* Build the feature-ADR live-panel telemetry leg. Totality comes from the caller's grouped splice:
|
|
124
150
|
* returning the bare command lets that splice preserve the trace flush's exit status while
|
|
@@ -152,16 +178,86 @@ export interface TraceRun {
|
|
|
152
178
|
/** No run.closed frame ⇒ the tail may be lost; truncated-window invariants report inconclusive. */
|
|
153
179
|
incomplete: boolean;
|
|
154
180
|
parseErrors: string[];
|
|
181
|
+
/** The self-declared HINT (see TraceEmitterPath) — null when absent. NEVER read as provenance. */
|
|
182
|
+
emitterPath: TraceEmitterPath | null;
|
|
183
|
+
/** Two `run.opened` frames that DISAGREE. The scan used to keep the last one silently, which
|
|
184
|
+
* would let a spliced frame overwrite the genuine one; a conflict now forbids `instrument`. */
|
|
185
|
+
openConflict: boolean;
|
|
155
186
|
}
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
187
|
+
/**
|
|
188
|
+
* Parse a trace.jsonl text. Tolerant of a missing run.closed (incomplete: true); a DUPLICATE
|
|
189
|
+
* settle for one invocation is a PARSE ERROR, never a silent merge (INV-15).
|
|
190
|
+
*
|
|
191
|
+
* W17 / AM-12 — `run.events` is CANONICALIZED by ascending `seq` after the line scan. The host's
|
|
192
|
+
* batched racing flush agents legitimately append out of seq order (MEASURED on the committed
|
|
193
|
+
* `pkg-audit-1` run: lines 1-2 are settles seq 7 and 6, ahead of `run.opened` seq 1), and the
|
|
194
|
+
* reader used to inherit that file order — so `invocations()` DROPPED every settle that preceded
|
|
195
|
+
* its own dispatch in the file, and a complete, successful run read as three FAIL verdicts. seq is
|
|
196
|
+
* the authoritative order (it is allocated synchronously at the lifecycle transition); file order
|
|
197
|
+
* is a durability artifact the flush design already blesses, and it stays recoverable only from the
|
|
198
|
+
* raw text.
|
|
199
|
+
*
|
|
200
|
+
* Order of the two bookkeeping passes is load-bearing:
|
|
201
|
+
* • LINE-SHAPE errors (unparseable / invalid event) are recorded in FILE order — they describe
|
|
202
|
+
* the bytes, and quoting them in file order is what lets a human find the line.
|
|
203
|
+
* • The duplicate-dispatch and duplicate-settle checks run AFTER canonicalization, so "which
|
|
204
|
+
* settle is the duplicate" is decided by seq, not by which flush batch happened to land first
|
|
205
|
+
* (before this, reversing the flush order changed WHICH event INV-15 refused).
|
|
206
|
+
* The sort is stable, so two events sharing one seq keep their file order relative to each other —
|
|
207
|
+
* the only ordering the file can still testify to. INV-14 fails such a trace on uniqueness anyway.
|
|
208
|
+
*/
|
|
158
209
|
export declare function parseTrace(text: string): TraceRun;
|
|
210
|
+
/**
|
|
211
|
+
* ATTESTATION — the trust question, answered by the READER, never by the file.
|
|
212
|
+
*
|
|
213
|
+
* `instrument` means, EXACTLY (ADR-001 round 3, wording taken from the cross-family reviewer):
|
|
214
|
+
* *the bytes read match the identifiers, the hash and the line count asserted by the co-located
|
|
215
|
+
* `run-state.json`.* It does NOT mean `dz` historically wrote those bytes, nor that this is the
|
|
216
|
+
* directory it wrote them in. A byte-identical replay passes. Copying the matched trace+run-state
|
|
217
|
+
* pair elsewhere passes. Both are accepted and tested, not patched.
|
|
218
|
+
*
|
|
219
|
+
* What it DOES buy: `run-state.json` is written by the dz process, and the rendered script runs in a
|
|
220
|
+
* sandbox with no filesystem — so an agent that mis-writes, truncates, reorders or invents its
|
|
221
|
+
* flush cannot reach `instrument`. What it cannot buy: a defence against an actor with write access
|
|
222
|
+
* to the run directory. On this machine the agent IS such an actor and the signing key is readable
|
|
223
|
+
* by the same account, so no local artifact — signature included — closes that. Named, not hidden.
|
|
224
|
+
*
|
|
225
|
+
* `unknown` is kept DISTINCT from `agent` (a legacy instrument run, a stripped field and explicit
|
|
226
|
+
* agent testimony are different facts) while sharing its conservative tier for every decision.
|
|
227
|
+
*/
|
|
228
|
+
export type TraceAttestation = 'instrument' | 'agent' | 'unknown';
|
|
229
|
+
/** The subset of `run-state.json` the attestation reads. Unknown-shaped input is not an error — it
|
|
230
|
+
* simply fails to bind, which yields `unknown`. */
|
|
231
|
+
export interface TraceRunStateBinding {
|
|
232
|
+
runId?: unknown;
|
|
233
|
+
planDigest?: unknown;
|
|
234
|
+
execFp?: unknown;
|
|
235
|
+
traceSha256?: unknown;
|
|
236
|
+
traceLines?: unknown;
|
|
237
|
+
}
|
|
238
|
+
/** What the CALLER measured about the trace text it actually read. Passed in rather than computed
|
|
239
|
+
* here so this module keeps its zero dependencies (no node:crypto) and stays trivially testable. */
|
|
240
|
+
export interface TraceObserved {
|
|
241
|
+
sha256: string;
|
|
242
|
+
lines: number;
|
|
243
|
+
}
|
|
244
|
+
export declare function deriveAttestation(run: TraceRun, state: TraceRunStateBinding | null | undefined, observed: TraceObserved): TraceAttestation;
|
|
159
245
|
export type InvariantStatus = 'pass' | 'fail' | 'inconclusive';
|
|
160
246
|
export interface InvariantVerdict {
|
|
161
247
|
id: string;
|
|
162
248
|
status: InvariantStatus;
|
|
163
249
|
message: string;
|
|
250
|
+
/**
|
|
251
|
+
* FR-3 — the qualifier travels IN the verdict, never beside it. A caller that stores a verdict
|
|
252
|
+
* and reads it back later must not be able to end up holding a bare `pass` whose attestation was
|
|
253
|
+
* dropped in transit. Optional only so a caller that has not derived one is a compile-time
|
|
254
|
+
* possibility; `stampAttestation` is how the reader attaches it.
|
|
255
|
+
*/
|
|
256
|
+
attestation?: TraceAttestation;
|
|
164
257
|
}
|
|
258
|
+
/** Attach one attestation to every verdict in a batch. Kept as a named function rather than a spread
|
|
259
|
+
* at each call site so a NEW verdict producer cannot silently ship unstamped verdicts. */
|
|
260
|
+
export declare function stampAttestation(verdicts: InvariantVerdict[], attestation: TraceAttestation): InvariantVerdict[];
|
|
165
261
|
/**
|
|
166
262
|
* Evaluate the plan-derived runtime invariants over an observed trace. Consumes ONLY
|
|
167
263
|
* `toTraceProjection(plan)` (AM-3) and ONLY runtime-assigned `seq` (never wallTime — INV-16).
|
|
@@ -211,7 +307,12 @@ export interface Timeline {
|
|
|
211
307
|
/**
|
|
212
308
|
* Merge one timeline: trace.jsonl is the AUTHORITATIVE order (rows sorted by seq); checkpoints,
|
|
213
309
|
* cost-ledger lines and usageEvents are appended as unordered context rows (seq 0); journal.jsonl
|
|
214
|
-
* contributes DIAGNOSTIC
|
|
310
|
+
* contributes a DIAGNOSTIC LINE COUNT only, never ordering (the ACL of 04 §8).
|
|
311
|
+
*
|
|
312
|
+
* Honesty fix (2026-08-20): this note used to promise "agentId correlation", which the code never
|
|
313
|
+
* did — it counts lines. A comment claiming an analysis that does not exist is the same defect class
|
|
314
|
+
* this feature was built to remove, one layer up. The real correlation now lives in
|
|
315
|
+
* `trace-corroborate.ts`, behind `dz workflow-trace --corroborate`, where it is scoped and tested.
|
|
215
316
|
*/
|
|
216
317
|
export declare function assembleTimeline(input: {
|
|
217
318
|
trace: string;
|
package/dist/loop-trace.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-trace.d.ts","sourceRoot":"","sources":["../src/loop-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,oFAAoF;AACpF,eAAO,MAAM,uBAAuB,UAAU,CAAC;AAE/C,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,oCAAoC;AACpC,eAAO,MAAM,cAAc,QAAsB,CAAC;AAClD;qFACqF;AACrF,eAAO,MAAM,YAAY,QAA0B,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,CAAC,CAAC;IACL,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B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