@tangle-network/agent-eval 0.174.0 → 0.176.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http.d.ts +1 -1
  4. package/dist/agent-profile-cell-0gSi5ffD.js +374 -0
  5. package/dist/agent-profile-cell-0gSi5ffD.js.map +1 -0
  6. package/dist/analyst/index.d.ts +3 -3
  7. package/dist/analyst/index.js +4 -4
  8. package/dist/{benchmark-command-mZIlR-ra.js → benchmark-command-yPqjcZnC.js} +7 -7
  9. package/dist/{benchmark-command-mZIlR-ra.js.map → benchmark-command-yPqjcZnC.js.map} +1 -1
  10. package/dist/benchmarks/index.d.ts +1 -1
  11. package/dist/benchmarks/index.js +3 -3
  12. package/dist/campaign/index.d.ts +3 -3
  13. package/dist/campaign/index.js +9 -9
  14. package/dist/{campaign-BzMSCejE.js → campaign-85igdlgG.js} +12 -12
  15. package/dist/{campaign-BzMSCejE.js.map → campaign-85igdlgG.js.map} +1 -1
  16. package/dist/campaign-evidence-D8DBLqLI.js +2083 -0
  17. package/dist/campaign-evidence-D8DBLqLI.js.map +1 -0
  18. package/dist/{opencode-sqlite-eK6HW6dr.js → claude-jsonl-CxZZrDJ3.js} +9 -149
  19. package/dist/claude-jsonl-CxZZrDJ3.js.map +1 -0
  20. package/dist/cli.js +9 -2
  21. package/dist/cli.js.map +1 -1
  22. package/dist/contract/index.d.ts +4 -4
  23. package/dist/contract/index.js +9 -9
  24. package/dist/{default-registry-CrAp0pYq.js → default-registry-DBqVI4pq.js} +2 -2
  25. package/dist/{default-registry-CrAp0pYq.js.map → default-registry-DBqVI4pq.js.map} +1 -1
  26. package/dist/{define-agent-eval-V1jQyCDR.d.ts → define-agent-eval-CCbl8k2E.d.ts} +11 -4
  27. package/dist/define-agent-eval-CCbl8k2E.d.ts.map +1 -0
  28. package/dist/{define-agent-eval-ox5McL6e.js → define-agent-eval-DEMsu5eA.js} +54 -36
  29. package/dist/define-agent-eval-DEMsu5eA.js.map +1 -0
  30. package/dist/{dspy-rlm-engine-Caz2pl4L.js → dspy-rlm-engine-DqjER2sV.js} +2 -2
  31. package/dist/{dspy-rlm-engine-Caz2pl4L.js.map → dspy-rlm-engine-DqjER2sV.js.map} +1 -1
  32. package/dist/{eval-campaign-BeAjdhzC.js → eval-campaign-Cs-7MiCs.js} +4 -5
  33. package/dist/{eval-campaign-BeAjdhzC.js.map → eval-campaign-Cs-7MiCs.js.map} +1 -1
  34. package/dist/experiment/index.d.ts +3 -68
  35. package/dist/experiment/index.d.ts.map +1 -1
  36. package/dist/experiment/index.js +6 -128
  37. package/dist/experiment/index.js.map +1 -1
  38. package/dist/{attestation-XSUpbc4o.js → experiment-tracker-BKEumQug.js} +2 -96
  39. package/dist/experiment-tracker-BKEumQug.js.map +1 -0
  40. package/dist/{attestation-c1QvaBdX.d.ts → experiment-tracker-CNwqCZFD.d.ts} +2 -78
  41. package/dist/experiment-tracker-CNwqCZFD.d.ts.map +1 -0
  42. package/dist/{external-optimizer-process-CxnFL1hd.js → external-optimizer-process-Dlz8YxrT.js} +3 -3
  43. package/dist/{external-optimizer-process-CxnFL1hd.js.map → external-optimizer-process-Dlz8YxrT.js.map} +1 -1
  44. package/dist/{external-optimizer-subprocess-CQi27uEI.js → external-optimizer-subprocess-q3VzlGAO.js} +2 -2
  45. package/dist/{external-optimizer-subprocess-CQi27uEI.js.map → external-optimizer-subprocess-q3VzlGAO.js.map} +1 -1
  46. package/dist/{index-Bn-nlnSV.d.ts → index-BAAiSF3_.d.ts} +2 -2
  47. package/dist/{index-Bn-nlnSV.d.ts.map → index-BAAiSF3_.d.ts.map} +1 -1
  48. package/dist/{index-DKXuBPXf.d.ts → index-Bg6OT2Dd.d.ts} +23 -10
  49. package/dist/{index-DKXuBPXf.d.ts.map → index-Bg6OT2Dd.d.ts.map} +1 -1
  50. package/dist/{index-BTrx5s8m.d.ts → index-DBkcm_9H.d.ts} +4 -4
  51. package/dist/{index-BTrx5s8m.d.ts.map → index-DBkcm_9H.d.ts.map} +1 -1
  52. package/dist/{index-D-UdhAmg.d.ts → index-u0d1Jp4F.d.ts} +4 -2
  53. package/dist/{index-D-UdhAmg.d.ts.map → index-u0d1Jp4F.d.ts.map} +1 -1
  54. package/dist/index.d.ts +5 -5
  55. package/dist/index.js +15 -16
  56. package/dist/index.js.map +1 -1
  57. package/dist/{integrity-BWywb34E.js → integrity-DsHWCebQ.js} +11 -435
  58. package/dist/integrity-DsHWCebQ.js.map +1 -0
  59. package/dist/ledger-core/index.d.ts +2 -2
  60. package/dist/ledger-core/index.js +2 -2
  61. package/dist/{ledger-core-PIfjCbKn.js → ledger-core-Cs9f7385.js} +60 -47
  62. package/dist/{ledger-core-PIfjCbKn.js.map → ledger-core-Cs9f7385.js.map} +1 -1
  63. package/dist/{llm-judge-DmNaBrXB.js → llm-judge-DliimmRb.js} +994 -1517
  64. package/dist/llm-judge-DliimmRb.js.map +1 -0
  65. package/dist/{mint-vWOdD8Ae.js → mint-Cc1_zwRQ.js} +2 -2
  66. package/dist/{mint-vWOdD8Ae.js.map → mint-Cc1_zwRQ.js.map} +1 -1
  67. package/dist/openapi.json +1 -1
  68. package/dist/opencode-sqlite-CNw3vubS.js +145 -0
  69. package/dist/opencode-sqlite-CNw3vubS.js.map +1 -0
  70. package/dist/{produced-state-B8mw6zj9.js → produced-state-DrMqa2HD.js} +3 -2
  71. package/dist/{produced-state-B8mw6zj9.js.map → produced-state-DrMqa2HD.js.map} +1 -1
  72. package/dist/profile-cell.js +1 -268
  73. package/dist/{promotion-policy-LY9mVQ7W.js → promotion-policy-DWOm70gx.js} +2 -2
  74. package/dist/{promotion-policy-LY9mVQ7W.js.map → promotion-policy-DWOm70gx.js.map} +1 -1
  75. package/dist/{release-confidence-BsGEg_xg.js → release-confidence-BcGCclTB.js} +2 -2
  76. package/dist/{release-confidence-BsGEg_xg.js.map → release-confidence-BcGCclTB.js.map} +1 -1
  77. package/dist/report-command-DKlXfU5r.js +1528 -0
  78. package/dist/report-command-DKlXfU5r.js.map +1 -0
  79. package/dist/reporting.js +2 -2
  80. package/dist/{reward-hacking-CKW4teig.js → reward-hacking-D0XwhVWE.js} +2 -215
  81. package/dist/reward-hacking-D0XwhVWE.js.map +1 -0
  82. package/dist/rl.js +5 -4
  83. package/dist/rl.js.map +1 -1
  84. package/dist/rollout/index.js +4 -3
  85. package/dist/{rollout-C-znbbYg.js → rollout-DmoJVqrF.js} +4 -3
  86. package/dist/{rollout-C-znbbYg.js.map → rollout-DmoJVqrF.js.map} +1 -1
  87. package/dist/run-record-CR63CpHK.js +216 -0
  88. package/dist/run-record-CR63CpHK.js.map +1 -0
  89. package/dist/{run-record-ZIsR9Fif.js → run-record-DQpSf7t-.js} +2 -2
  90. package/dist/{run-record-ZIsR9Fif.js.map → run-record-DQpSf7t-.js.map} +1 -1
  91. package/dist/{semantic-concept-judge-E3s_fEjB.js → semantic-concept-judge-Dw-f7TEs.js} +3 -3
  92. package/dist/{semantic-concept-judge-E3s_fEjB.js.map → semantic-concept-judge-Dw-f7TEs.js.map} +1 -1
  93. package/dist/{sequential-B51qAYE4.js → sequential-B5gXgcyp.js} +3 -3
  94. package/dist/{sequential-B51qAYE4.js.map → sequential-B5gXgcyp.js.map} +1 -1
  95. package/dist/{skillopt-optimization-method-f7399oGb.js → skillopt-optimization-method-CV7go7ex.js} +6 -749
  96. package/dist/skillopt-optimization-method-CV7go7ex.js.map +1 -0
  97. package/dist/{statistical-heldout-Cqb73yE9.d.ts → statistical-heldout-Z9NROFFS.d.ts} +156 -3
  98. package/dist/statistical-heldout-Z9NROFFS.d.ts.map +1 -0
  99. package/dist/{summary-report-Bgh8CpNK.js → summary-report-B16xy9Kd.js} +2 -2
  100. package/dist/{summary-report-Bgh8CpNK.js.map → summary-report-B16xy9Kd.js.map} +1 -1
  101. package/dist/supervisor-run/index.d.ts +71 -6
  102. package/dist/supervisor-run/index.d.ts.map +1 -1
  103. package/dist/supervisor-run/index.js +6 -1357
  104. package/dist/supervisor-run/index.js.map +1 -1
  105. package/dist/terminal-record-Ce9_UjRz.js +539 -0
  106. package/dist/terminal-record-Ce9_UjRz.js.map +1 -0
  107. package/dist/traces.js +1 -1
  108. package/dist/{types-CoPUTiXb.d.ts → types-vUdAx2Cj.d.ts} +65 -3
  109. package/dist/types-vUdAx2Cj.d.ts.map +1 -0
  110. package/docs/public-api.md +62 -39
  111. package/docs/search-history-receipts.md +48 -1
  112. package/package.json +1 -1
  113. package/dist/attestation-XSUpbc4o.js.map +0 -1
  114. package/dist/attestation-c1QvaBdX.d.ts.map +0 -1
  115. package/dist/define-agent-eval-V1jQyCDR.d.ts.map +0 -1
  116. package/dist/define-agent-eval-ox5McL6e.js.map +0 -1
  117. package/dist/integrity-BWywb34E.js.map +0 -1
  118. package/dist/llm-judge-DmNaBrXB.js.map +0 -1
  119. package/dist/opencode-sqlite-eK6HW6dr.js.map +0 -1
  120. package/dist/power-preflight-CFXm0Vjo.js +0 -502
  121. package/dist/power-preflight-CFXm0Vjo.js.map +0 -1
  122. package/dist/pre-registration-D94b7Of5.js +0 -110
  123. package/dist/pre-registration-D94b7Of5.js.map +0 -1
  124. package/dist/profile-cell.js.map +0 -1
  125. package/dist/reward-hacking-CKW4teig.js.map +0 -1
  126. package/dist/skillopt-optimization-method-f7399oGb.js.map +0 -1
  127. package/dist/statistical-heldout-Cqb73yE9.d.ts.map +0 -1
  128. package/dist/types-CoPUTiXb.d.ts.map +0 -1
@@ -0,0 +1,539 @@
1
+ //#region src/supervisor-run/source-facts.ts
2
+ function asRecord(v) {
3
+ return typeof v === "object" && v !== null ? v : {};
4
+ }
5
+ function num(v) {
6
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
7
+ }
8
+ function readSpend(v) {
9
+ const rec = asRecord(v);
10
+ const tok = asRecord(rec.tokens);
11
+ const cacheRead = tok.cacheRead ?? tok.cache_read;
12
+ const cacheWrite = tok.cacheWrite ?? tok.cache_write;
13
+ return {
14
+ tokens: {
15
+ input: num(tok.input),
16
+ output: num(tok.output),
17
+ cacheRead: num(cacheRead),
18
+ cacheWrite: num(cacheWrite),
19
+ hasCache: cacheRead !== void 0 || cacheWrite !== void 0,
20
+ breakdownKnown: tok.cacheBreakdownKnown !== false
21
+ },
22
+ tokensKnown: rec.tokensKnown !== false,
23
+ usd: num(rec.usd),
24
+ usdKnown: rec.usdKnown !== false
25
+ };
26
+ }
27
+ function parseJsonl(text) {
28
+ return parseJsonlWithDiagnostics(text).rows;
29
+ }
30
+ function parseJsonlWithDiagnostics(text) {
31
+ if (text === null) return {
32
+ rows: [],
33
+ invalidRows: 0
34
+ };
35
+ const out = [];
36
+ let invalidRows = 0;
37
+ for (const line of text.split("\n")) {
38
+ const trimmed = line.trim();
39
+ if (!trimmed) continue;
40
+ try {
41
+ const parsed = JSON.parse(trimmed);
42
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) out.push(parsed);
43
+ else invalidRows += 1;
44
+ } catch {
45
+ invalidRows += 1;
46
+ }
47
+ }
48
+ return {
49
+ rows: out,
50
+ invalidRows
51
+ };
52
+ }
53
+ function parseJson(text) {
54
+ if (text === null) return null;
55
+ try {
56
+ const parsed = JSON.parse(text);
57
+ return typeof parsed === "object" && parsed !== null ? parsed : null;
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ function ms(at) {
63
+ if (typeof at !== "string") return null;
64
+ const t = Date.parse(at);
65
+ return Number.isFinite(t) ? t : null;
66
+ }
67
+ function readVerdict(v) {
68
+ if (typeof v === "string") return {
69
+ label: v,
70
+ valid: null,
71
+ score: null,
72
+ raw: v
73
+ };
74
+ if (typeof v !== "object" || v === null) return {
75
+ label: null,
76
+ valid: null,
77
+ score: null,
78
+ raw: null
79
+ };
80
+ const rec = v;
81
+ const valid = typeof rec.valid === "boolean" ? rec.valid : null;
82
+ return {
83
+ label: valid === null ? null : valid ? "valid" : "invalid",
84
+ valid,
85
+ score: typeof rec.score === "number" && Number.isFinite(rec.score) ? rec.score : null,
86
+ raw: v
87
+ };
88
+ }
89
+ function workerSourceKey(worker) {
90
+ return worker.workerId ?? worker.label;
91
+ }
92
+ /** Event kinds this parser folds into the tree. */
93
+ const TREE_EVENT_KINDS = [
94
+ "spawned",
95
+ "settled",
96
+ "cancelled",
97
+ "metered"
98
+ ];
99
+ /**
100
+ * Event kinds `agent-runtime` journals that this parser recognizes but does not model as
101
+ * tree nodes: `waiting` arms a wait node and `woken` settles it. They are counted by kind
102
+ * rather than dropped, so "understood, not modeled" can never be mistaken for "absent".
103
+ */
104
+ const UNMODELLED_EVENT_KINDS = ["waiting", "woken"];
105
+ function treeEventKind(value) {
106
+ return TREE_EVENT_KINDS.includes(value) ? value : null;
107
+ }
108
+ /**
109
+ * Classify one parsed journal row. Every row lands in exactly one outcome — interpreted,
110
+ * recognized-but-not-modeled, or unreadable — because a row that falls through silently is
111
+ * how a run with events reads as a run with none.
112
+ */
113
+ function readJournalRow(row) {
114
+ const kind = row.kind;
115
+ if (typeof kind !== "string") return { outcome: "unreadable" };
116
+ if (kind === "begin" && typeof row.root === "string") return {
117
+ outcome: "ignored",
118
+ dialect: "runtime-envelope",
119
+ kind: "begin"
120
+ };
121
+ if (kind === "event") {
122
+ const inner = row.event;
123
+ if (typeof inner !== "object" || inner === null || Array.isArray(inner)) return { outcome: "unreadable" };
124
+ const innerKind = inner.kind;
125
+ if (typeof innerKind !== "string") return { outcome: "unreadable" };
126
+ const tree = treeEventKind(innerKind);
127
+ if (tree !== null) return {
128
+ outcome: "event",
129
+ dialect: "runtime-envelope",
130
+ kind: tree,
131
+ event: inner
132
+ };
133
+ return {
134
+ outcome: "ignored",
135
+ dialect: "runtime-envelope",
136
+ kind: innerKind
137
+ };
138
+ }
139
+ const tree = treeEventKind(kind);
140
+ if (tree !== null) return {
141
+ outcome: "event",
142
+ dialect: "flat",
143
+ kind: tree,
144
+ event: row
145
+ };
146
+ if (UNMODELLED_EVENT_KINDS.includes(kind)) return {
147
+ outcome: "ignored",
148
+ dialect: "flat",
149
+ kind
150
+ };
151
+ return { outcome: "unreadable" };
152
+ }
153
+ function summarizeDialect(seen) {
154
+ if (seen.size === 0) return "none";
155
+ if (seen.size > 1) return "mixed";
156
+ return seen.has("runtime-envelope") ? "runtime-envelope" : "flat";
157
+ }
158
+ function parseSupervisorTree(src) {
159
+ const parsedJournal = parseJsonlWithDiagnostics(src.journal);
160
+ const events = parsedJournal.rows;
161
+ const state = parseJson(src.state);
162
+ const spawns = [];
163
+ const closes = [];
164
+ let brainIn = 0;
165
+ let brainOut = 0;
166
+ let brainCacheRead = 0;
167
+ let brainCacheWrite = 0;
168
+ let brainHasCache = false;
169
+ let brainCacheBreakdownKnown = true;
170
+ let brainTokensKnownCount = 0;
171
+ let brainTokensUnknownCount = 0;
172
+ let brainUsd = 0;
173
+ let brainUsdKnownCount = 0;
174
+ let brainUsdUnknownCount = 0;
175
+ let meteredCount = 0;
176
+ let rootId = null;
177
+ let unreadableRows = 0;
178
+ const ignoredByKind = /* @__PURE__ */ new Map();
179
+ const dialectsSeen = /* @__PURE__ */ new Set();
180
+ const meteredRows = [];
181
+ for (const [sourceRow, row] of events.entries()) {
182
+ const reading = readJournalRow(row);
183
+ if (reading.outcome === "unreadable") {
184
+ unreadableRows += 1;
185
+ continue;
186
+ }
187
+ dialectsSeen.add(reading.dialect);
188
+ if (reading.outcome === "ignored") {
189
+ ignoredByKind.set(reading.kind, (ignoredByKind.get(reading.kind) ?? 0) + 1);
190
+ continue;
191
+ }
192
+ const { kind, event: ev } = reading;
193
+ const id = typeof ev.id === "string" ? ev.id : "";
194
+ if (kind === "spawned") {
195
+ const parent = typeof ev.parent === "string" && ev.parent.length > 0 ? ev.parent : null;
196
+ const label = typeof ev.label === "string" ? ev.label : "";
197
+ const invalidFields = [];
198
+ if (id.length === 0) invalidFields.push("id");
199
+ const parentOmittedForFirstRoot = ev.parent === void 0 && rootId === null;
200
+ if (ev.parent !== null && !parentOmittedForFirstRoot && !(typeof ev.parent === "string" && ev.parent.length > 0)) invalidFields.push("parent");
201
+ if (label.length === 0) invalidFields.push("label");
202
+ if (ev.role !== void 0 && ev.role !== "supervisor" && ev.role !== "worker") invalidFields.push("role");
203
+ if (ev.profileDigest !== void 0 && !(typeof ev.profileDigest === "string" && ev.profileDigest.length > 0)) invalidFields.push("profileDigest");
204
+ if (ev.runtime !== void 0 && !(typeof ev.runtime === "string" && ev.runtime.length > 0)) invalidFields.push("runtime");
205
+ const role = ev.role === "supervisor" || ev.role === "worker" ? ev.role : null;
206
+ const valid = invalidFields.length === 0;
207
+ if (valid && parent === null && rootId === null) rootId = id;
208
+ spawns.push({
209
+ sourceRow,
210
+ id,
211
+ parent,
212
+ label,
213
+ role,
214
+ profileDigest: typeof ev.profileDigest === "string" && ev.profileDigest.length > 0 ? ev.profileDigest : null,
215
+ runtime: typeof ev.runtime === "string" && ev.runtime.length > 0 ? ev.runtime : null,
216
+ at: ms(ev.at),
217
+ valid,
218
+ invalidFields
219
+ });
220
+ } else if (kind === "settled") {
221
+ const verdict = readVerdict(ev.verdict);
222
+ closes.push({
223
+ id,
224
+ kind: "settled",
225
+ status: typeof ev.status === "string" ? ev.status : null,
226
+ verdict: verdict.label,
227
+ valid: verdict.valid,
228
+ score: verdict.score,
229
+ rawVerdict: verdict.raw,
230
+ reason: typeof ev.reason === "string" ? ev.reason : null,
231
+ infra: typeof ev.infra === "boolean" ? ev.infra : null,
232
+ at: ms(ev.at),
233
+ spend: readSpend(ev.spent),
234
+ hasSpend: asRecord(ev.spent).tokens !== void 0
235
+ });
236
+ } else if (kind === "cancelled") closes.push({
237
+ id,
238
+ kind: "cancelled",
239
+ status: "cancelled",
240
+ verdict: typeof ev.reason === "string" ? ev.reason : null,
241
+ valid: null,
242
+ score: null,
243
+ rawVerdict: typeof ev.reason === "string" ? ev.reason : null,
244
+ reason: typeof ev.reason === "string" ? ev.reason : null,
245
+ infra: null,
246
+ at: ms(ev.at),
247
+ spend: {
248
+ tokens: {
249
+ input: 0,
250
+ output: 0,
251
+ cacheRead: 0,
252
+ cacheWrite: 0,
253
+ hasCache: false,
254
+ breakdownKnown: true
255
+ },
256
+ tokensKnown: true,
257
+ usd: 0,
258
+ usdKnown: true
259
+ },
260
+ hasSpend: false
261
+ });
262
+ else if (kind === "metered") meteredRows.push({
263
+ id,
264
+ spend: readSpend(ev.spend),
265
+ at: ms(ev.at)
266
+ });
267
+ else throw new Error(`unhandled journal event kind ${JSON.stringify(kind)}`);
268
+ }
269
+ for (const row of meteredRows) {
270
+ if (rootId === null || row.id !== rootId) continue;
271
+ if (row.spend.tokensKnown) {
272
+ brainIn += row.spend.tokens.input;
273
+ brainOut += row.spend.tokens.output;
274
+ brainCacheRead += row.spend.tokens.cacheRead;
275
+ brainCacheWrite += row.spend.tokens.cacheWrite;
276
+ brainHasCache = brainHasCache || row.spend.tokens.hasCache;
277
+ brainCacheBreakdownKnown = brainCacheBreakdownKnown && row.spend.tokens.breakdownKnown;
278
+ brainTokensKnownCount += 1;
279
+ } else brainTokensUnknownCount += 1;
280
+ if (row.spend.usdKnown) {
281
+ brainUsd += row.spend.usd;
282
+ brainUsdKnownCount += 1;
283
+ } else brainUsdUnknownCount += 1;
284
+ meteredCount += 1;
285
+ }
286
+ const workerSpawns = spawns.filter((s) => s.valid && s.id !== rootId);
287
+ const workerIds = new Set(workerSpawns.map((s) => s.id));
288
+ const workerCloses = closes.filter((c) => workerIds.has(c.id));
289
+ const workerLogs = /* @__PURE__ */ new Map();
290
+ const workerLogRows = [];
291
+ for (const [sourceIndex, w] of (src.workers ?? []).entries()) {
292
+ const facts = {
293
+ sourceIndex,
294
+ workerId: w.workerId ?? null,
295
+ label: w.label,
296
+ inboxCaptured: w.inbox !== null,
297
+ eventsCaptured: w.events !== null,
298
+ inboxInvalidRows: 0,
299
+ eventsInvalidRows: 0,
300
+ started: null,
301
+ finished: false,
302
+ finishedAt: null,
303
+ passed: null,
304
+ score: null,
305
+ finishedPatchBytes: null,
306
+ evidenceBytes: 0,
307
+ steersQueued: null,
308
+ steersDelivered: null,
309
+ steersQueuedUnavailable: null,
310
+ steersDeliveredUnavailable: null,
311
+ questions: 0,
312
+ steerRequests: [],
313
+ steerAcknowledgements: []
314
+ };
315
+ const parsedInbox = parseJsonlWithDiagnostics(w.inbox);
316
+ const parsedEvents = parseJsonlWithDiagnostics(w.events);
317
+ facts.inboxInvalidRows = parsedInbox.invalidRows;
318
+ facts.eventsInvalidRows = parsedEvents.invalidRows;
319
+ for (const [row, req] of parsedInbox.rows.entries()) {
320
+ if (typeof req.message !== "string" || req.message.trim().length === 0) continue;
321
+ facts.steerRequests.push({
322
+ requestId: typeof req.id === "string" && req.id.length > 0 ? req.id : null,
323
+ row
324
+ });
325
+ }
326
+ for (const [row, ev] of parsedEvents.rows.entries()) {
327
+ const kind = ev.kind;
328
+ if (kind === "message") {
329
+ if (ev.direction === "up") {
330
+ facts.questions += 1;
331
+ continue;
332
+ }
333
+ facts.steerAcknowledgements.push({
334
+ requestId: typeof ev.requestId === "string" && ev.requestId.length > 0 ? ev.requestId : null,
335
+ delivered: typeof ev.delivered === "boolean" ? ev.delivered : null,
336
+ row
337
+ });
338
+ } else if (kind === "started") facts.started = ms(ev.at);
339
+ else if (kind === "finished") {
340
+ facts.finished = true;
341
+ facts.finishedAt = ms(ev.at);
342
+ facts.passed = typeof ev.passed === "boolean" ? ev.passed : null;
343
+ facts.score = typeof ev.score === "number" && Number.isFinite(ev.score) ? ev.score : null;
344
+ facts.finishedPatchBytes = typeof ev.patchBytes === "number" ? ev.patchBytes : null;
345
+ facts.evidenceBytes = typeof ev.evidence === "string" ? ev.evidence.length : 0;
346
+ }
347
+ }
348
+ const requestsById = /* @__PURE__ */ new Map();
349
+ for (const request of facts.steerRequests) {
350
+ if (request.requestId === null) continue;
351
+ requestsById.set(request.requestId, (requestsById.get(request.requestId) ?? 0) + 1);
352
+ }
353
+ const acknowledgementsById = /* @__PURE__ */ new Map();
354
+ for (const acknowledgement of facts.steerAcknowledgements) {
355
+ if (acknowledgement.requestId === null) continue;
356
+ const matches = acknowledgementsById.get(acknowledgement.requestId) ?? [];
357
+ matches.push(acknowledgement);
358
+ acknowledgementsById.set(acknowledgement.requestId, matches);
359
+ }
360
+ const queueProblems = [];
361
+ if (!facts.inboxCaptured) queueProblems.push("inbox absent");
362
+ if (!facts.eventsCaptured) queueProblems.push("events absent");
363
+ if (facts.inboxInvalidRows > 0) queueProblems.push("inbox contains malformed rows");
364
+ if (facts.eventsInvalidRows > 0) queueProblems.push("events contain malformed rows");
365
+ if (facts.steerRequests.some((request) => request.requestId === null)) queueProblems.push("queued request id missing");
366
+ if ([...requestsById.values()].some((count) => count > 1)) queueProblems.push("queued request id duplicated");
367
+ if (facts.steerAcknowledgements.some((acknowledgement) => acknowledgement.requestId === null)) queueProblems.push("acknowledgement request id missing");
368
+ if ([...acknowledgementsById.keys()].some((id) => !requestsById.has(id))) queueProblems.push("acknowledgement has no queued request");
369
+ if (queueProblems.length === 0) facts.steersQueued = requestsById.size;
370
+ else facts.steersQueuedUnavailable = [...new Set(queueProblems)].join("; ");
371
+ const deliveryProblems = [...queueProblems];
372
+ if ([...acknowledgementsById.values()].some((rows) => rows.length > 1)) deliveryProblems.push("acknowledgement request id duplicated");
373
+ if (facts.steerAcknowledgements.some((acknowledgement) => acknowledgement.delivered === null)) deliveryProblems.push("acknowledgement delivery status missing");
374
+ if (deliveryProblems.length === 0) facts.steersDelivered = [...requestsById.keys()].filter((id) => {
375
+ const acknowledgement = acknowledgementsById.get(id);
376
+ return acknowledgement?.length === 1 && acknowledgement[0]?.delivered === true;
377
+ }).length;
378
+ else facts.steersDeliveredUnavailable = [...new Set(deliveryProblems)].join("; ");
379
+ workerLogRows.push(facts);
380
+ workerLogs.set(workerSourceKey(w), facts);
381
+ }
382
+ const startedAt = ms(state?.startedAt) ?? spawns[0]?.at ?? null;
383
+ const rootClose = rootId === null ? null : closes.find((close) => close.id === rootId);
384
+ const completedAt = ms(state?.completedAt) ?? rootClose?.at ?? null;
385
+ let firstEventAt = null;
386
+ let lastEventAt = null;
387
+ const widenEventSpan = (at) => {
388
+ if (at === null) return;
389
+ if (firstEventAt === null || at < firstEventAt) firstEventAt = at;
390
+ if (lastEventAt === null || at > lastEventAt) lastEventAt = at;
391
+ };
392
+ for (const spawn of spawns) widenEventSpan(spawn.at);
393
+ for (const close of closes) widenEventSpan(close.at);
394
+ for (const metered of meteredRows) widenEventSpan(metered.at);
395
+ return {
396
+ rootId,
397
+ spawns,
398
+ closes,
399
+ workerSpawns,
400
+ workerCloses,
401
+ brain: {
402
+ tokensIn: brainIn,
403
+ tokensOut: brainOut,
404
+ cacheRead: brainCacheRead,
405
+ cacheWrite: brainCacheWrite,
406
+ hasCache: brainHasCache,
407
+ cacheBreakdownKnown: brainCacheBreakdownKnown,
408
+ tokensKnownCount: brainTokensKnownCount,
409
+ tokensUnknownCount: brainTokensUnknownCount,
410
+ usd: brainUsd,
411
+ usdKnownCount: brainUsdKnownCount,
412
+ usdUnknownCount: brainUsdUnknownCount,
413
+ meteredCount
414
+ },
415
+ workerLogs,
416
+ workerLogRows,
417
+ journalRows: events.length + parsedJournal.invalidRows,
418
+ journalInvalidRows: parsedJournal.invalidRows + unreadableRows,
419
+ journalMalformedJsonRows: parsedJournal.invalidRows,
420
+ journalIgnoredRowsByKind: Object.fromEntries(ignoredByKind),
421
+ journalMeteredRows: meteredRows.length,
422
+ journalDialect: summarizeDialect(dialectsSeen),
423
+ state,
424
+ startedAt,
425
+ completedAt,
426
+ firstEventAt,
427
+ lastEventAt
428
+ };
429
+ }
430
+ //#endregion
431
+ //#region src/supervisor-run/types.ts
432
+ function unavailable(reason) {
433
+ return { unavailable: reason };
434
+ }
435
+ function isUnavailable(v) {
436
+ return typeof v === "object" && v !== null && typeof v.unavailable === "string";
437
+ }
438
+ /** Render a measured scalar for the markdown/headline: `0` and `unavailable` stay distinct. */
439
+ function showMeasured(v) {
440
+ if (isUnavailable(v)) return `unavailable — ${v.unavailable}`;
441
+ if (v === null) return "null";
442
+ return String(v);
443
+ }
444
+ /** A source that carries every fact the analyzer can use. */
445
+ const NO_SOURCE_LIMITS = {
446
+ managerTokens: null,
447
+ workerTokens: null,
448
+ spendUsd: null,
449
+ workerVerdicts: null,
450
+ deliverables: null
451
+ };
452
+ const SUPERVISOR_RUN_SCHEMA = "tangle.supervisor-run@1";
453
+ const SUPERVISOR_RUN_ROLLUP_SCHEMA = "tangle.supervisor-run-rollup@1";
454
+ //#endregion
455
+ //#region src/supervisor-run/terminal-record.ts
456
+ /**
457
+ * The run's terminal record, read from the documents the store wrote when the
458
+ * run ended. Runtime's own record outranks every other source: `result.json` is
459
+ * the `SupervisedResult` that `supervise()` returned, verbatim, and its `kind`
460
+ * is the run's status. `failure.json` is the record Runtime writes when
461
+ * `supervise()` threw before a result landed. The control-plane-era loops
462
+ * documents (`state.json` `status`, `result.json` `sup_status`) stay readable
463
+ * as named legacy sources, so a report always says which record it read.
464
+ *
465
+ * Pure: takes already-parsed documents and returns `Measured` values. The
466
+ * analyzer and the rollout minter share it so a run never has two statuses.
467
+ */
468
+ /** The reason every terminal field reads `unavailable` when no store wrote one. */
469
+ const NO_TERMINAL_RECORD = "no terminal record: Runtime result.json kind, Runtime failure.json, or legacy state.json / result.json status";
470
+ /** The status reported for a run whose directory holds Runtime's failure record and no result. */
471
+ const RUNTIME_FAILED_STATUS = "failed";
472
+ function str(value) {
473
+ return typeof value === "string" && value.length > 0 ? value : null;
474
+ }
475
+ function errorRecord(doc, source, earlierAttempt) {
476
+ if (typeof doc.error !== "object" || doc.error === null) return null;
477
+ const error = asRecord(doc.error);
478
+ return {
479
+ source,
480
+ name: str(error.name),
481
+ message: str(error.message),
482
+ at: str(doc.at),
483
+ earlierAttempt
484
+ };
485
+ }
486
+ function readTerminalRecord(input) {
487
+ const { state, result } = input;
488
+ const resultKind = str(result?.kind);
489
+ const settled = resultKind !== null && result !== null;
490
+ const failureRecord = input.failure === null || input.failure === void 0 ? null : errorRecord(input.failure, "runtime-failure", settled);
491
+ if (settled) return {
492
+ supStatus: resultKind,
493
+ supStatusSource: "runtime-result",
494
+ supReason: str(result.reason),
495
+ failure: failureRecord ?? errorRecord(result, "runtime-result", false),
496
+ completed: resultKind === "winner"
497
+ };
498
+ if (failureRecord !== null) return {
499
+ supStatus: RUNTIME_FAILED_STATUS,
500
+ supStatusSource: "runtime-failure",
501
+ supReason: null,
502
+ failure: failureRecord,
503
+ completed: false
504
+ };
505
+ if (input.failure !== null && input.failure !== void 0) return {
506
+ supStatus: RUNTIME_FAILED_STATUS,
507
+ supStatusSource: "runtime-failure",
508
+ supReason: null,
509
+ failure: unavailable("Runtime failure.json carries no error record"),
510
+ completed: false
511
+ };
512
+ const legacyStateStatus = str(state?.status);
513
+ if (legacyStateStatus !== null) return {
514
+ supStatus: legacyStateStatus,
515
+ supStatusSource: "legacy-state",
516
+ supReason: null,
517
+ failure: unavailable("legacy state.json records no failure document"),
518
+ completed: legacyStateStatus === "completed"
519
+ };
520
+ const legacyResultStatus = str(result?.sup_status);
521
+ if (legacyResultStatus !== null) return {
522
+ supStatus: legacyResultStatus,
523
+ supStatusSource: "legacy-result",
524
+ supReason: null,
525
+ failure: unavailable("legacy result.json records no failure document"),
526
+ completed: legacyResultStatus === "completed"
527
+ };
528
+ return {
529
+ supStatus: unavailable(NO_TERMINAL_RECORD),
530
+ supStatusSource: unavailable(NO_TERMINAL_RECORD),
531
+ supReason: unavailable(NO_TERMINAL_RECORD),
532
+ failure: unavailable(NO_TERMINAL_RECORD),
533
+ completed: null
534
+ };
535
+ }
536
+ //#endregion
537
+ export { SUPERVISOR_RUN_ROLLUP_SCHEMA as a, showMeasured as c, parseJson as d, parseJsonl as f, NO_SOURCE_LIMITS as i, unavailable as l, workerSourceKey as m, RUNTIME_FAILED_STATUS as n, SUPERVISOR_RUN_SCHEMA as o, parseSupervisorTree as p, readTerminalRecord as r, isUnavailable as s, NO_TERMINAL_RECORD as t, asRecord as u };
538
+
539
+ //# sourceMappingURL=terminal-record-Ce9_UjRz.js.map