@tangle-network/agent-app 0.60.214 → 0.60.216

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 (37) hide show
  1. package/dist/chunk-CD2LQXY6.js +306 -0
  2. package/dist/chunk-CD2LQXY6.js.map +1 -0
  3. package/dist/{chunk-KDPTXXOQ.js → chunk-J3N6RNMH.js} +456 -75
  4. package/dist/chunk-J3N6RNMH.js.map +1 -0
  5. package/dist/chunk-LRYY3OX7.js +105 -0
  6. package/dist/chunk-LRYY3OX7.js.map +1 -0
  7. package/dist/{chunk-LLO436QO.js → chunk-QM7RTTDY.js} +27 -86
  8. package/dist/chunk-QM7RTTDY.js.map +1 -0
  9. package/dist/{chunk-ZRLKB4KB.js → chunk-YWLZOPDS.js} +10 -11
  10. package/dist/{chunk-ZRLKB4KB.js.map → chunk-YWLZOPDS.js.map} +1 -1
  11. package/dist/launch-invariants/catalog.d.ts +16 -0
  12. package/dist/launch-invariants/cli.js +5 -2
  13. package/dist/launch-invariants/cli.js.map +1 -1
  14. package/dist/launch-invariants/index.d.ts +1 -1
  15. package/dist/launch-invariants/index.js +13 -5
  16. package/dist/launch-invariants/index.js.map +1 -1
  17. package/dist/launch-invariants/limit-alarms.d.ts +19 -1
  18. package/dist/launch-invariants/testing.d.ts +0 -3
  19. package/dist/launch-invariants/testing.js +5 -2
  20. package/dist/platform/delegated-keys.d.ts +3 -1
  21. package/dist/platform/index.js +10 -1
  22. package/dist/platform/index.js.map +1 -1
  23. package/dist/signoff/app-defaults.d.ts +65 -0
  24. package/dist/signoff/cli.js +71 -4
  25. package/dist/signoff/cli.js.map +1 -1
  26. package/dist/signoff/defaults-cli.d.ts +1 -0
  27. package/dist/signoff/index.js +2 -1
  28. package/dist/signoff/types.d.ts +6 -0
  29. package/dist/signoff/worker-defaults.d.ts +8 -0
  30. package/dist/turn-health/index.js +12 -291
  31. package/dist/turn-health/index.js.map +1 -1
  32. package/dist/turn-trace/index.js +20 -3
  33. package/dist/turn-trace/index.js.map +1 -1
  34. package/dist/turn-trace/otel.d.ts +11 -4
  35. package/package.json +1 -1
  36. package/dist/chunk-KDPTXXOQ.js.map +0 -1
  37. package/dist/chunk-LLO436QO.js.map +0 -1
@@ -0,0 +1,306 @@
1
+ import {
2
+ postSlackAlert
3
+ } from "./chunk-F2VX6TTJ.js";
4
+
5
+ // src/turn-health/classify.ts
6
+ var ARTIFACT_PART_KINDS = /* @__PURE__ */ new Set(["file", "image", "work-product", "plan", "interaction"]);
7
+ var KNOWN_NON_OUTPUT_PART_KINDS = /* @__PURE__ */ new Set([
8
+ "reasoning",
9
+ "step-start",
10
+ "step-finish",
11
+ "source",
12
+ "source-url",
13
+ "data"
14
+ ]);
15
+ var SAMPLE_CHARS = 120;
16
+ function asRecord(value) {
17
+ return typeof value === "object" && value !== null ? value : null;
18
+ }
19
+ function nonEmptyString(value) {
20
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
21
+ }
22
+ function isUnparseableJson(value) {
23
+ const trimmed = value.trim();
24
+ if (trimmed.length === 0) return false;
25
+ try {
26
+ JSON.parse(trimmed);
27
+ return false;
28
+ } catch {
29
+ return true;
30
+ }
31
+ }
32
+ var SETTLED_TOOL_STATUSES = /* @__PURE__ */ new Set(["completed", "complete", "success", "done"]);
33
+ var FAILED_TOOL_STATUSES = /* @__PURE__ */ new Set(["error", "failed"]);
34
+ function classifyTurnOutcome(input) {
35
+ const reasons = [];
36
+ if (input.failed) {
37
+ reasons.push({
38
+ kind: "turn_failed",
39
+ reason: nonEmptyString(input.failureReason) ?? "unspecified"
40
+ });
41
+ }
42
+ const parts = Array.isArray(input.parts) ? input.parts : [];
43
+ let hasVisibleText = nonEmptyString(input.finalText) !== null;
44
+ let artifactCount = 0;
45
+ let toolCalls = 0;
46
+ const opaqueTypes = [];
47
+ let interpretedParts = 0;
48
+ for (const raw of parts) {
49
+ const part = asRecord(raw);
50
+ if (!part) continue;
51
+ const type = typeof part.type === "string" ? part.type : "";
52
+ if (type === "text") {
53
+ interpretedParts += 1;
54
+ if (nonEmptyString(part.text) !== null) hasVisibleText = true;
55
+ continue;
56
+ }
57
+ if (ARTIFACT_PART_KINDS.has(type)) {
58
+ interpretedParts += 1;
59
+ artifactCount += 1;
60
+ continue;
61
+ }
62
+ if (KNOWN_NON_OUTPUT_PART_KINDS.has(type)) {
63
+ interpretedParts += 1;
64
+ continue;
65
+ }
66
+ if (type !== "tool") {
67
+ opaqueTypes.push(type || "(missing type)");
68
+ continue;
69
+ }
70
+ interpretedParts += 1;
71
+ toolCalls += 1;
72
+ const tool = nonEmptyString(part.tool) ?? "unknown";
73
+ const state = asRecord(part.state);
74
+ const status = typeof state?.status === "string" ? state.status : "unknown";
75
+ const toolInput = state?.input;
76
+ const inputRecord = asRecord(toolInput);
77
+ const rejection = nonEmptyString(inputRecord?.error) ?? nonEmptyString(state?.error);
78
+ if (rejection && SETTLED_TOOL_STATUSES.has(status)) {
79
+ reasons.push({
80
+ kind: "tool_call_rejected",
81
+ // The payload names the tool the model MEANT to call; the part's own
82
+ // `tool` is the harness's placeholder for a rejected call.
83
+ tool: nonEmptyString(inputRecord?.tool) ?? tool,
84
+ error: rejection.slice(0, 200)
85
+ });
86
+ continue;
87
+ }
88
+ if (typeof toolInput === "string" && isUnparseableJson(toolInput)) {
89
+ reasons.push({
90
+ kind: "malformed_tool_call",
91
+ tool,
92
+ inputLength: toolInput.length,
93
+ sample: toolInput.slice(0, SAMPLE_CHARS)
94
+ });
95
+ continue;
96
+ }
97
+ if (!SETTLED_TOOL_STATUSES.has(status) && !FAILED_TOOL_STATUSES.has(status)) {
98
+ reasons.push({ kind: "tool_call_no_effect", tool, status });
99
+ }
100
+ }
101
+ const partsReadable = opaqueTypes.length === 0;
102
+ const uniqueOpaque = [...new Set(opaqueTypes)];
103
+ const unreadable = opaqueTypes.length > 0 && interpretedParts === 0 && !hasVisibleText;
104
+ if (unreadable) {
105
+ reasons.push({ kind: "unreadable_turn", partTypes: uniqueOpaque });
106
+ return {
107
+ healthy: false,
108
+ severity: "warning",
109
+ reasons,
110
+ toolCalls,
111
+ unreadable: true,
112
+ partsReadable: false,
113
+ opaquePartTypes: uniqueOpaque,
114
+ // Structurally 0 here — `unreadable` is only reached when
115
+ // `interpretedParts === 0`. Carried rather than hardcoded so the field
116
+ // has one source on every return path.
117
+ interpretedParts
118
+ };
119
+ }
120
+ if (input.gated) {
121
+ reasons.push({ kind: "answered_without_model" });
122
+ } else if (!input.failed && !hasVisibleText && artifactCount === 0) {
123
+ reasons.push({
124
+ kind: "empty_completion",
125
+ outputTokens: input.outputTokens ?? null,
126
+ partCount: parts.length,
127
+ ...input.durationMs !== void 0 ? { durationMs: input.durationMs } : {}
128
+ });
129
+ }
130
+ return {
131
+ healthy: reasons.length === 0,
132
+ severity: severityOf(reasons),
133
+ reasons,
134
+ toolCalls,
135
+ unreadable: false,
136
+ partsReadable,
137
+ opaquePartTypes: uniqueOpaque,
138
+ interpretedParts
139
+ };
140
+ }
141
+ function severityOf(reasons) {
142
+ if (reasons.length === 0) return null;
143
+ const critical = reasons.some(
144
+ (r) => r.kind === "empty_completion" || r.kind === "turn_failed" || r.kind === "tool_call_rejected"
145
+ );
146
+ return critical ? "critical" : "warning";
147
+ }
148
+ function describeReason(reason) {
149
+ switch (reason.kind) {
150
+ case "empty_completion":
151
+ return `completed with NO output (${reason.partCount} parts, outputTokens=${reason.outputTokens ?? "unknown"})`;
152
+ case "malformed_tool_call":
153
+ return `tool \`${reason.tool}\` arguments did not parse (${reason.inputLength} chars): ${reason.sample}`;
154
+ case "tool_call_no_effect":
155
+ return `tool \`${reason.tool}\` left no effect (status=${reason.status})`;
156
+ case "turn_failed":
157
+ return `turn failed: ${reason.reason}`;
158
+ case "tool_call_rejected":
159
+ return `tool \`${reason.tool}\` was REJECTED but settled as completed: ${reason.error}`;
160
+ case "answered_without_model":
161
+ return "answered by a pre-producer gate \u2014 the model never ran";
162
+ case "unreadable_turn":
163
+ return `turn could not be read: every part had an uninterpretable type (${reason.partTypes.join(
164
+ ", "
165
+ )})`;
166
+ }
167
+ }
168
+
169
+ // src/turn-health/sink.ts
170
+ function turnAlert(input) {
171
+ const kinds = [...new Set(input.reasons.map((r) => r.kind))].sort();
172
+ return {
173
+ product: input.product,
174
+ severity: input.severity,
175
+ // Keyed by product + reason kinds ONLY. A blank-completion storm across
176
+ // 200 turns is one incident, not 200 pages.
177
+ key: `turn:${input.product}:${kinds.join("+")}`,
178
+ title: `${input.product}: turn completed but delivered nothing (${kinds.join(", ")})`,
179
+ details: input.reasons.map(describeReason),
180
+ data: {
181
+ kinds,
182
+ ...input.threadId ? { threadId: input.threadId } : {},
183
+ ...input.turnId ? { turnId: input.turnId } : {},
184
+ ...input.model ? { model: input.model } : {}
185
+ },
186
+ at: input.at ?? Date.now()
187
+ };
188
+ }
189
+ function createWebhookAlertSink(options) {
190
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
191
+ return {
192
+ async deliver(alert) {
193
+ const icon = alert.severity === "critical" ? ":rotating_light:" : ":warning:";
194
+ const lines = [
195
+ `${icon} *${alert.title}*`,
196
+ ...alert.details.map((d) => `\u2022 ${d}`),
197
+ `_${new Date(alert.at).toISOString()}_`
198
+ ];
199
+ const response = await fetchImpl(options.webhookUrl, {
200
+ method: "POST",
201
+ headers: { "Content-Type": "application/json" },
202
+ body: JSON.stringify({ text: lines.join("\n") })
203
+ });
204
+ if (!response.ok) {
205
+ throw new Error(`alert webhook responded ${response.status}`);
206
+ }
207
+ }
208
+ };
209
+ }
210
+ function createSlackBotAlertSink(options) {
211
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
212
+ return {
213
+ async deliver(alert) {
214
+ const icon = alert.severity === "critical" ? ":rotating_light:" : ":warning:";
215
+ const lines = [
216
+ `${icon} *${alert.title}*`,
217
+ ...alert.details.map((d) => `\u2022 ${d}`),
218
+ `_${new Date(alert.at).toISOString()}_`
219
+ ];
220
+ const outcome = await postSlackAlert({
221
+ token: options.botToken,
222
+ channel: options.channel,
223
+ text: lines.join("\n"),
224
+ attempts: 1,
225
+ // Preserve the public minimal-fetch seam without owning a second Slack
226
+ // request builder or response parser. Real callers use native fetch.
227
+ fetchImpl: options.fetchImpl ? (async (url, init) => {
228
+ const response = await fetchImpl(String(url), {
229
+ method: init?.method ?? "POST",
230
+ headers: Object.fromEntries(new Headers(init?.headers)),
231
+ body: String(init?.body ?? "")
232
+ });
233
+ return new Response(await response.text?.() ?? "", { status: response.status });
234
+ }) : void 0
235
+ });
236
+ if (!outcome.delivered) throw new Error(`Slack alert failed (${outcome.reason}): ${outcome.detail}`);
237
+ }
238
+ };
239
+ }
240
+ function createConsoleAlertSink(log = console.error) {
241
+ return {
242
+ async deliver(alert) {
243
+ log(
244
+ `[turn-health] ${alert.severity.toUpperCase()} ${alert.title} :: ${alert.details.join(" | ")}`
245
+ );
246
+ }
247
+ };
248
+ }
249
+ function createMultiAlertSink(sinks) {
250
+ return {
251
+ async deliver(alert) {
252
+ const settled = await Promise.allSettled(sinks.map((s) => s.deliver(alert)));
253
+ const failures = settled.filter((r) => r.status === "rejected");
254
+ if (failures.length === sinks.length && sinks.length > 0) {
255
+ throw new Error("every alert sink failed");
256
+ }
257
+ }
258
+ };
259
+ }
260
+ function createMemoryThrottleStore() {
261
+ const seen = /* @__PURE__ */ new Map();
262
+ return {
263
+ async lastSentAt(key) {
264
+ return seen.get(key) ?? null;
265
+ },
266
+ async markSent(key, at) {
267
+ seen.set(key, at);
268
+ }
269
+ };
270
+ }
271
+ function createThrottledAlertSink(inner, options) {
272
+ const store = options.store ?? createMemoryThrottleStore();
273
+ return {
274
+ async deliver(alert) {
275
+ const last = await store.lastSentAt(alert.key);
276
+ if (last !== null && alert.at - last < options.windowMs) return;
277
+ await inner.deliver(alert);
278
+ await store.markSent(alert.key, alert.at);
279
+ }
280
+ };
281
+ }
282
+ function createGuardedAlertSink(inner, onError = (e) => console.error("[turn-health] alert delivery failed", e)) {
283
+ return {
284
+ async deliver(alert) {
285
+ try {
286
+ await inner.deliver(alert);
287
+ } catch (error) {
288
+ onError(error);
289
+ }
290
+ }
291
+ };
292
+ }
293
+
294
+ export {
295
+ classifyTurnOutcome,
296
+ describeReason,
297
+ turnAlert,
298
+ createWebhookAlertSink,
299
+ createSlackBotAlertSink,
300
+ createConsoleAlertSink,
301
+ createMultiAlertSink,
302
+ createMemoryThrottleStore,
303
+ createThrottledAlertSink,
304
+ createGuardedAlertSink
305
+ };
306
+ //# sourceMappingURL=chunk-CD2LQXY6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turn-health/classify.ts","../src/turn-health/sink.ts"],"sourcesContent":["/**\n * The classifier for turns that FAIL BY RETURNING SUCCESS.\n *\n * Every failure this module names shipped to a customer with HTTP 200, no\n * thrown error, and no log line anyone read. Three were measured in production\n * in a single week:\n *\n * - a turn settled `{\"outcome\":{\"type\":\"completed\"},\"finalText\":\"\",\n * \"tokenUsage\":{\"outputTokens\":0}}` — the customer saw a blank bubble;\n * - six `submit_proposal` tool calls collapsed into ONE whose arguments were\n * a 1,652-character non-JSON string, so zero proposals persisted and\n * nothing errored (agent-runtime #626);\n * - a thread took 255 user messages over 17 days and produced 2 replies,\n * both of them error text.\n *\n * A conventional health check cannot see any of these, because it probes\n * DEPENDENCIES (is the sandbox reachable, is the router up) and every one of\n * these failures happens with all dependencies green. This classifier probes\n * the OUTCOME instead.\n *\n * It is deliberately pure and structural: it reads a settled turn's own\n * projection, so the SAME function judges a live turn through the\n * `/chat-routes` lifecycle seam and a historical row read back out of the\n * store during a sweep. One definition of \"silently broken\", two call sites.\n */\n\n/** How loudly a reason should be routed. `critical` means a customer got\n * nothing usable; `warning` means the turn degraded but still produced\n * something a human could read. */\nexport type TurnHealthSeverity = 'critical' | 'warning'\n\n/** One specific way a turn returned success while failing.\n *\n * Each variant carries the evidence that identified it, so an alert can name\n * the offending value instead of asserting a verdict the reader has to take\n * on faith. */\nexport type TurnHealthReason =\n /** Settled without error and produced nothing a user can read: no text, and\n * no artifact part (file/image/work-product/plan/interaction). This is the\n * verbatim blank-completion capture. */\n | {\n kind: 'empty_completion'\n outputTokens: number | null\n partCount: number\n durationMs?: number\n }\n /** A tool call whose arguments never parsed. The engine surfaces unparseable\n * arguments as a RAW STRING rather than throwing, so the call is neither\n * dropped nor errored — it silently does nothing. Detecting a string-typed\n * tool input that fails `JSON.parse` is the exact fingerprint of the\n * index-less parallel-tool-call collapse. */\n | {\n kind: 'malformed_tool_call'\n tool: string\n inputLength: number\n /** Leading characters of the offending input, for the alert body. */\n sample: string\n }\n /** A tool call that never reached a terminal state carrying output. The call\n * was issued and then simply produced no effect. */\n | {\n kind: 'tool_call_no_effect'\n tool: string\n status: string\n }\n /** The turn failed outright. Not silent by itself — but it becomes silent\n * the moment nothing is watching, which is how 16 days of\n * `TANGLE_HUB_URL is required` reached customers unnoticed. */\n | { kind: 'turn_failed'; reason: string }\n /** A tool call the harness REJECTED, settled as `completed`.\n *\n * Found live in legal-agent production, and missed by every other rule here:\n * the model called `submit_proposal`, the harness answered \"Model tried to\n * call unavailable tool 'submit_proposal'\", and the part persisted as\n * `{\"tool\":\"invalid\",\"state\":{\"status\":\"completed\",\"input\":{\"error\":\"…\"}}}`.\n *\n * Status is `completed`, the arguments parse cleanly, and the turn has text —\n * so the blank-completion, malformed-argument and no-effect rules all pass it.\n * Six deliverables were requested and silently discarded while the product\n * reported success six times.\n *\n * Detected structurally, on the presence of an `error` in the settled state\n * rather than on any harness's name for a rejected call — `invalid` is one\n * harness's convention and must not be baked into the shell. */\n | {\n kind: 'tool_call_rejected'\n /** The tool the model was trying to reach, when the payload names it. */\n tool: string\n error: string\n }\n /** The turn was answered without the model ever running — a pre-producer gate\n * short-circuited and returned the product's own response.\n *\n * Reported as a `warning`, never `critical`: gating an unready turn is a\n * legitimate design (an intake flow SHOULD answer before spending a model\n * call). What is pathological is the RATE, which only the caller's own\n * threshold can judge — so this variant exists to be COUNTED, and alerting\n * on it is opt-in. It is the per-turn evidence behind a dead tool surface:\n * a gate that answers every turn means the agent never runs at all. */\n | { kind: 'answered_without_model' }\n /** The detector could not read this turn.\n *\n * Every part carried a type outside the vocabulary this classifier\n * understands — which is what field-level encryption at rest looks like from\n * the outside (tax-agent persists `{\"type\":\"__encrypted_parts__\"}`, its own\n * convention, and 32 of its 129 assistant rows are exactly that).\n *\n * This exists because the alternative is the bug this whole module hunts.\n * An unreadable row has no text, no artifact and no tool part, so every\n * other rule here would happily conclude \"nothing wrong\" — a detector\n * reporting health from data it cannot see. Blindness is a finding, not a\n * pass, so it gets its own reason and its own counter. */\n | { kind: 'unreadable_turn'; partTypes: string[] }\n\n/** A settled turn, in the narrowest shape both call sites can supply.\n *\n * Structural on purpose: the lifecycle seam supplies `finalText`/`usage`, a\n * store sweep supplies `content`/`parts` read back from a row, and neither\n * has to import the other's types. */\nexport interface TurnOutcomeInput {\n /** The turn's final assistant text. */\n finalText?: string | null\n /** The persisted assistant parts. Untyped by design — a sweep reads these\n * out of a JSON column and must not be forced to validate them first. */\n parts?: readonly unknown[] | null\n /** Output tokens, when the caller has usage. `null`/absent is unknown, which\n * is NOT the same as zero and is never treated as evidence. */\n outputTokens?: number | null\n /** Set when the turn surfaced a terminal error event. */\n failed?: boolean\n failureReason?: string | null\n durationMs?: number\n /** Set when a pre-producer gate answered this turn and the model never ran.\n * Supplied by `/chat-routes`' lifecycle seam, which stamps `gated` on the\n * completion it now fires for a `contextGate` short-circuit. */\n gated?: boolean\n}\n\n/** The verdict for one turn. `healthy` is exactly `reasons.length === 0`, kept\n * as a field so callers read intent rather than an array length. */\nexport interface TurnHealthVerdict {\n healthy: boolean\n severity: TurnHealthSeverity | null\n reasons: TurnHealthReason[]\n /** How many tool parts this turn carried.\n *\n * Zero is NOT a per-turn defect — plenty of good turns answer from context\n * without touching a tool, and paging on each one would be pure noise. It is\n * reported so a WINDOW can be judged: a product whose deliverable is tool\n * output and which produced zero tool calls across every turn in the\n * lookback has a dead tool surface, and that is the shape no per-turn rule\n * can see.\n *\n * Only meaningful alongside {@link interpretedParts} > 0. Zero tool calls\n * read off a row that persisted NO parts is not an observation about the\n * tool surface — it is the absence of one. */\n toolCalls: number\n /** True when nothing about this turn could be judged — no interpretable part\n * AND no visible text. Callers MUST exclude these from any healthy/unhealthy\n * ratio, because counting an unreadable turn as healthy is how a detector\n * reports green on data it never read. */\n unreadable: boolean\n /** False when this turn carried parts that could not be interpreted.\n *\n * Separate from {@link unreadable} because the two blindnesses have\n * different consequences, and production has a row that is one but not the\n * other: tax-agent persists CIPHERTEXT as `content` alongside an encrypted\n * `parts` blob, so the turn plainly delivered something (there is text) while\n * its tool calls are completely invisible.\n *\n * Any conclusion ABOUT TOOLS — above all the dead-tool-surface verdict — may\n * only be drawn over turns where this is true. Reading \"no tool parts\" off an\n * encrypted blob and declaring the tool surface dead would be the same\n * crime as declaring it healthy: a finding asserted from data never read. */\n partsReadable: boolean\n /** The part types that could not be interpreted. Empty when\n * {@link partsReadable}. Named in the alert so a reader can see EXACTLY what\n * the detector was blind to instead of taking \"unreadable\" on faith. */\n opaquePartTypes: string[]\n /** How many parts this module actually READ (text, artifact, tool, or a known\n * non-output kind).\n *\n * The third blindness, and the one that shipped a false page. `partsReadable`\n * only says nothing was *uninterpretable*; a row that persisted NO parts at\n * all satisfies that vacuously. Production: 97 of tax-agent's 156 assistant\n * rows predate parts persistence entirely and store `[]`, and reading \"zero\n * tool calls\" off them raised a critical `dead_tool_surface` against a\n * product whose own `turn_events` table holds 243 `tool_call` frames.\n *\n * So a tool verdict requires BOTH `partsReadable` AND this being > 0 —\n * evidence that was read, not merely evidence that failed to be unreadable. */\n interpretedParts: number\n}\n\n/** Part kinds that count as something a user actually receives.\n *\n * A tool part is deliberately NOT here. A turn that ran six tools and said\n * nothing, with no artifact to show for it, is the malformed-tool-call\n * disaster — counting a tool chip as output would suppress the very alert\n * this module exists to raise. */\nconst ARTIFACT_PART_KINDS = new Set(['file', 'image', 'work-product', 'plan', 'interaction'])\n\n/** Part types that carry no user-visible output but ARE understood.\n *\n * The distinction matters: a turn made of nothing but `reasoning` parts\n * thought hard and said nothing, which is a real empty completion. A turn made\n * of types this module has never heard of is a turn it cannot read. Only the\n * second is blindness — so these are enumerated rather than lumped in with the\n * unknown.\n *\n * Grounded in what the fleet actually persists, not guessed: a scan of every\n * assistant part in the gtm / legal / tax production tables returns exactly\n * `tool` (138), `text` (69), `reasoning` (26), `step-start` (3),\n * `step-finish` (3) and tax's opaque `__encrypted_parts__` (32). */\nconst KNOWN_NON_OUTPUT_PART_KINDS = new Set([\n 'reasoning',\n 'step-start',\n 'step-finish',\n 'source',\n 'source-url',\n 'data',\n])\n\nconst SAMPLE_CHARS = 120\n\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : null\n}\n\nfunction nonEmptyString(value: unknown): string | null {\n return typeof value === 'string' && value.trim().length > 0 ? value : null\n}\n\n/** True when a string is not parseable JSON.\n *\n * Only meaningful for tool INPUT, where the engine's contract is that a\n * well-formed call carries an object (or a string that parses into one). A\n * string that fails to parse means the arguments were concatenated or\n * truncated upstream. */\nfunction isUnparseableJson(value: string): boolean {\n const trimmed = value.trim()\n if (trimmed.length === 0) return false\n try {\n JSON.parse(trimmed)\n return false\n } catch {\n return true\n }\n}\n\n/** Tool statuses that mean the call actually landed.\n *\n * Anything else — `pending`, `running`, an unknown string — left no persisted\n * effect by the time the turn settled. */\nconst SETTLED_TOOL_STATUSES = new Set(['completed', 'complete', 'success', 'done'])\n\n/** Tool statuses that ended the call by reporting its failure. The model and\n * the person saw the error, so the call is neither silently rejected nor left\n * without effect: on gtm-agent, 2,527 errored calls (HTTP statuses, missing\n * files, timeouts) in one day's 500 turns were all reported as REJECTED. */\nconst FAILED_TOOL_STATUSES = new Set(['error', 'failed'])\n\n/**\n * Judge one settled turn.\n *\n * Never throws: a malformed `parts` blob is a thing this function REPORTS on,\n * so it must not be a thing it dies on. Telemetry that can crash the turn it\n * measures is worse than no telemetry.\n */\nexport function classifyTurnOutcome(input: TurnOutcomeInput): TurnHealthVerdict {\n const reasons: TurnHealthReason[] = []\n\n if (input.failed) {\n reasons.push({\n kind: 'turn_failed',\n reason: nonEmptyString(input.failureReason) ?? 'unspecified',\n })\n }\n\n const parts = Array.isArray(input.parts) ? input.parts : []\n\n let hasVisibleText = nonEmptyString(input.finalText) !== null\n let artifactCount = 0\n let toolCalls = 0\n // Part types this module could not interpret. Tracked so blindness can be\n // reported as blindness instead of silently reading as health.\n const opaqueTypes: string[] = []\n let interpretedParts = 0\n\n for (const raw of parts) {\n const part = asRecord(raw)\n if (!part) continue\n const type = typeof part.type === 'string' ? part.type : ''\n\n if (type === 'text') {\n interpretedParts += 1\n if (nonEmptyString(part.text) !== null) hasVisibleText = true\n continue\n }\n if (ARTIFACT_PART_KINDS.has(type)) {\n interpretedParts += 1\n artifactCount += 1\n continue\n }\n if (KNOWN_NON_OUTPUT_PART_KINDS.has(type)) {\n interpretedParts += 1\n continue\n }\n if (type !== 'tool') {\n opaqueTypes.push(type || '(missing type)')\n continue\n }\n interpretedParts += 1\n toolCalls += 1\n\n const tool = nonEmptyString(part.tool) ?? 'unknown'\n const state = asRecord(part.state)\n const status = typeof state?.status === 'string' ? state.status : 'unknown'\n\n // The #626 fingerprint: arguments surfaced as a raw string because they\n // failed to parse upstream. Checked before the status gate — a malformed\n // call can still be marked completed, which is precisely why it is silent.\n // A rejected call settles as `completed` and carries its rejection in the\n // state. Checked BEFORE the status gate for the same reason as the\n // malformed case: the status is exactly what makes it silent.\n const toolInput = state?.input\n const inputRecord = asRecord(toolInput)\n const rejection =\n nonEmptyString(inputRecord?.error) ?? nonEmptyString((state as Record<string, unknown>)?.error)\n if (rejection && SETTLED_TOOL_STATUSES.has(status)) {\n reasons.push({\n kind: 'tool_call_rejected',\n // The payload names the tool the model MEANT to call; the part's own\n // `tool` is the harness's placeholder for a rejected call.\n tool: nonEmptyString(inputRecord?.tool) ?? tool,\n error: rejection.slice(0, 200),\n })\n continue\n }\n if (typeof toolInput === 'string' && isUnparseableJson(toolInput)) {\n reasons.push({\n kind: 'malformed_tool_call',\n tool,\n inputLength: toolInput.length,\n sample: toolInput.slice(0, SAMPLE_CHARS),\n })\n continue\n }\n\n if (!SETTLED_TOOL_STATUSES.has(status) && !FAILED_TOOL_STATUSES.has(status)) {\n reasons.push({ kind: 'tool_call_no_effect', tool, status })\n }\n }\n\n // A turn whose parts were ALL uninterpretable cannot be judged. Reported as\n // blindness and returned early, because every rule below would otherwise read\n // \"no text, no artifact\" off data that was simply encrypted and call it a\n // blank completion — a false page that would train readers to ignore this\n // module, which is the same ending as no detector at all.\n const partsReadable = opaqueTypes.length === 0\n const uniqueOpaque = [...new Set(opaqueTypes)]\n const unreadable = opaqueTypes.length > 0 && interpretedParts === 0 && !hasVisibleText\n if (unreadable) {\n reasons.push({ kind: 'unreadable_turn', partTypes: uniqueOpaque })\n return {\n healthy: false,\n severity: 'warning',\n reasons,\n toolCalls,\n unreadable: true,\n partsReadable: false,\n opaquePartTypes: uniqueOpaque,\n // Structurally 0 here — `unreadable` is only reached when\n // `interpretedParts === 0`. Carried rather than hardcoded so the field\n // has one source on every return path.\n interpretedParts,\n }\n }\n\n // A gate answered before the producer ran. Recorded rather than judged: see\n // `answered_without_model`. It also SUPPRESSES the empty-completion rule\n // below — the model producing no text is the expected outcome when the model\n // never ran, and firing `empty_completion` here would page on every healthy\n // intake turn.\n if (input.gated) {\n reasons.push({ kind: 'answered_without_model' })\n } else if (!input.failed && !hasVisibleText && artifactCount === 0) {\n // `outputTokens` is corroborating evidence, never the trigger: a turn can\n // spend tokens on reasoning and still deliver nothing, and a turn with\n // unknown usage can still be perfectly fine.\n reasons.push({\n kind: 'empty_completion',\n outputTokens: input.outputTokens ?? null,\n partCount: parts.length,\n ...(input.durationMs !== undefined ? { durationMs: input.durationMs } : {}),\n })\n }\n\n return {\n healthy: reasons.length === 0,\n severity: severityOf(reasons),\n reasons,\n toolCalls,\n unreadable: false,\n partsReadable,\n opaquePartTypes: uniqueOpaque,\n interpretedParts,\n }\n}\n\n/** `critical` when the customer got nothing usable out of the turn. A\n * malformed tool call alongside readable text is a `warning` — degraded, but\n * a human still received an answer. */\nfunction severityOf(reasons: TurnHealthReason[]): TurnHealthSeverity | null {\n if (reasons.length === 0) return null\n // A rejected tool call is critical even alongside readable prose: the\n // customer got words where they should have got a filed deliverable.\n const critical = reasons.some(\n (r) =>\n r.kind === 'empty_completion' ||\n r.kind === 'turn_failed' ||\n r.kind === 'tool_call_rejected',\n )\n return critical ? 'critical' : 'warning'\n}\n\n/** One-line human summary of a reason, for an alert body. */\nexport function describeReason(reason: TurnHealthReason): string {\n switch (reason.kind) {\n case 'empty_completion':\n return `completed with NO output (${reason.partCount} parts, outputTokens=${\n reason.outputTokens ?? 'unknown'\n })`\n case 'malformed_tool_call':\n return `tool \\`${reason.tool}\\` arguments did not parse (${reason.inputLength} chars): ${reason.sample}`\n case 'tool_call_no_effect':\n return `tool \\`${reason.tool}\\` left no effect (status=${reason.status})`\n case 'turn_failed':\n return `turn failed: ${reason.reason}`\n case 'tool_call_rejected':\n return `tool \\`${reason.tool}\\` was REJECTED but settled as completed: ${reason.error}`\n case 'answered_without_model':\n return 'answered by a pre-producer gate — the model never ran'\n case 'unreadable_turn':\n return `turn could not be read: every part had an uninterpretable type (${reason.partTypes.join(\n ', ',\n )})`\n }\n}\n","/**\n * Where a silent-failure verdict GOES.\n *\n * The detection half is worthless without this half. Every failure this module\n * finds was already visible in the database the whole time — 255 unanswered\n * messages sat in a table for 17 days. What was missing was not the data, it\n * was delivery to a human who had not thought to look.\n *\n * So the sink is a seam, not a channel: the product supplies the transport,\n * and agent-app ships the two shapes the fleet already has credentials for\n * (an ops webhook, and stderr). No new channel is invented here.\n */\n\nimport { postSlackAlert } from '../alerting/slack.js'\nimport { describeReason, type TurnHealthReason, type TurnHealthSeverity } from './classify.js'\n\n/** One deliverable alert. */\nexport interface TurnHealthAlert {\n /** Which product raised it (`projectId`). Alerts from four products land in\n * one channel, so this is what makes the message actionable. */\n product: string\n severity: TurnHealthSeverity\n /** Stable grouping key. Throttling is keyed on this, so it must NOT contain\n * a turn id or a timestamp or every alert is unique and nothing dedupes. */\n key: string\n title: string\n /** Human-readable lines. */\n details: string[]\n /** Structured payload for a machine consumer. */\n data?: Record<string, unknown>\n at: number\n}\n\n/** Deliver an alert. Implementations MUST NOT throw — see\n * {@link createGuardedAlertSink}. */\nexport interface AlertSink {\n deliver(alert: TurnHealthAlert): Promise<void>\n}\n\n/** Build the alert for a set of reasons found on one turn. */\nexport function turnAlert(input: {\n product: string\n severity: TurnHealthSeverity\n reasons: TurnHealthReason[]\n threadId?: string\n turnId?: string\n model?: string\n at?: number\n}): TurnHealthAlert {\n const kinds = [...new Set(input.reasons.map((r) => r.kind))].sort()\n return {\n product: input.product,\n severity: input.severity,\n // Keyed by product + reason kinds ONLY. A blank-completion storm across\n // 200 turns is one incident, not 200 pages.\n key: `turn:${input.product}:${kinds.join('+')}`,\n title: `${input.product}: turn completed but delivered nothing (${kinds.join(', ')})`,\n details: input.reasons.map(describeReason),\n data: {\n kinds,\n ...(input.threadId ? { threadId: input.threadId } : {}),\n ...(input.turnId ? { turnId: input.turnId } : {}),\n ...(input.model ? { model: input.model } : {}),\n },\n at: input.at ?? Date.now(),\n }\n}\n\n// ── transports ────────────────────────────────────────────────────────────\n\n/** Minimal structural fetch, so this module has no lib-dom dependency and can\n * be driven by a fake in tests. */\nexport type FetchLike = (\n url: string,\n init: { method: string; headers: Record<string, string>; body: string },\n) => Promise<{ ok: boolean; status: number; text?(): Promise<string> }>\n\n/**\n * POST to an incoming webhook in the Slack message format.\n *\n * Chosen because the org already runs one (`SLACK_OPS_WEBHOOK_URL`) and\n * gtm-agent's outbound webhook code already speaks this exact shape — the\n * instruction was to route somewhere humans already look, not to stand up a\n * new channel. Discord and most log drains accept the same `{text}` body.\n */\nexport function createWebhookAlertSink(options: {\n webhookUrl: string\n fetchImpl?: FetchLike\n}): AlertSink {\n const fetchImpl = options.fetchImpl ?? (globalThis.fetch as unknown as FetchLike)\n return {\n async deliver(alert) {\n const icon = alert.severity === 'critical' ? ':rotating_light:' : ':warning:'\n const lines = [\n `${icon} *${alert.title}*`,\n ...alert.details.map((d) => `• ${d}`),\n `_${new Date(alert.at).toISOString()}_`,\n ]\n const response = await fetchImpl(options.webhookUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ text: lines.join('\\n') }),\n })\n if (!response.ok) {\n // A dropped alert is a silent failure of the silent-failure detector.\n // It must be loud in the one place that is still working: the log.\n throw new Error(`alert webhook responded ${response.status}`)\n }\n },\n }\n}\n\n/**\n * POST to Slack `chat.postMessage` with a bot token.\n *\n * This is the transport the org actually has. A survey of the four product\n * repos found NO ops alert path of any kind — no incoming webhook, no pager, no\n * notifier — which is the mechanical reason a 17-day outage never reached a\n * human. What does exist is a Slack bot token in the shared secrets store, and\n * `@tangle-network/agent-integrations` already speaks this exact API, so this\n * routes alerts through the channel the org runs rather than standing up a new\n * one.\n *\n * Slack answers `200 OK` with `{\"ok\": false, \"error\": \"...\"}` for an invalid\n * token or channel, so the body is checked and not just the status — a\n * transport that reports success on a rejected post would make the alerter\n * itself a silent failure.\n */\nexport function createSlackBotAlertSink(options: {\n botToken: string\n channel: string\n fetchImpl?: FetchLike\n}): AlertSink {\n const fetchImpl = options.fetchImpl ?? (globalThis.fetch as unknown as FetchLike)\n return {\n async deliver(alert) {\n const icon = alert.severity === 'critical' ? ':rotating_light:' : ':warning:'\n const lines = [\n `${icon} *${alert.title}*`,\n ...alert.details.map((d) => `• ${d}`),\n `_${new Date(alert.at).toISOString()}_`,\n ]\n const outcome = await postSlackAlert({\n token: options.botToken, channel: options.channel, text: lines.join('\\n'), attempts: 1,\n // Preserve the public minimal-fetch seam without owning a second Slack\n // request builder or response parser. Real callers use native fetch.\n fetchImpl: options.fetchImpl ? (async (url, init) => {\n const response = await fetchImpl(String(url), {\n method: init?.method ?? 'POST',\n headers: Object.fromEntries(new Headers(init?.headers)),\n body: String(init?.body ?? ''),\n })\n return new Response(await response.text?.() ?? '', { status: response.status })\n }) : undefined,\n })\n if (!outcome.delivered) throw new Error(`Slack alert failed (${outcome.reason}): ${outcome.detail}`)\n },\n }\n}\n\n/** stderr sink. The zero-config fallback so a product that has not yet been\n * given a webhook still emits something a log search can find. */\nexport function createConsoleAlertSink(log: (message: string) => void = console.error): AlertSink {\n return {\n async deliver(alert) {\n log(\n `[turn-health] ${alert.severity.toUpperCase()} ${alert.title} :: ${alert.details.join(' | ')}`,\n )\n },\n }\n}\n\n/** Fan out to several sinks. One failing transport must not stop the others. */\nexport function createMultiAlertSink(sinks: readonly AlertSink[]): AlertSink {\n return {\n async deliver(alert) {\n const settled = await Promise.allSettled(sinks.map((s) => s.deliver(alert)))\n const failures = settled.filter((r) => r.status === 'rejected')\n if (failures.length === sinks.length && sinks.length > 0) {\n throw new Error('every alert sink failed')\n }\n },\n }\n}\n\n// ── throttling ────────────────────────────────────────────────────────────\n\n/** Records the last time a key was alerted on. A product backs this with KV,\n * D1, or a Durable Object; the in-memory default is correct for a sweep that\n * runs as a single cron invocation. */\nexport interface AlertThrottleStore {\n lastSentAt(key: string): Promise<number | null>\n markSent(key: string, at: number): Promise<void>\n}\n\n/** Process-local throttle store. */\nexport function createMemoryThrottleStore(): AlertThrottleStore {\n const seen = new Map<string, number>()\n return {\n async lastSentAt(key) {\n return seen.get(key) ?? null\n },\n async markSent(key, at) {\n seen.set(key, at)\n },\n }\n}\n\n/**\n * Collapse repeats of the same `key` inside `windowMs`.\n *\n * Deliberately re-alerts once per window rather than going silent after the\n * first: an incident that is still burning must keep saying so. Going quiet\n * after one message is how a 17-day outage stays invisible after someone\n * dismisses the first notification.\n */\nexport function createThrottledAlertSink(\n inner: AlertSink,\n options: { windowMs: number; store?: AlertThrottleStore },\n): AlertSink {\n const store = options.store ?? createMemoryThrottleStore()\n return {\n async deliver(alert) {\n const last = await store.lastSentAt(alert.key)\n if (last !== null && alert.at - last < options.windowMs) return\n await inner.deliver(alert)\n await store.markSent(alert.key, alert.at)\n },\n }\n}\n\n/**\n * Swallow transport errors so telemetry can never fail the turn it measures.\n *\n * Use this at the LIVE lifecycle call site only. A sweep should let the error\n * surface, because a sweep that cannot deliver has done nothing at all and its\n * cron run should go red.\n */\nexport function createGuardedAlertSink(\n inner: AlertSink,\n onError: (error: unknown) => void = (e) => console.error('[turn-health] alert delivery failed', e),\n): AlertSink {\n return {\n async deliver(alert) {\n try {\n await inner.deliver(alert)\n } catch (error) {\n onError(error)\n }\n },\n }\n}\n"],"mappings":";;;;;AAwMA,IAAM,sBAAsB,oBAAI,IAAI,CAAC,QAAQ,SAAS,gBAAgB,QAAQ,aAAa,CAAC;AAc5F,IAAM,8BAA8B,oBAAI,IAAI;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,eAAe;AAErB,SAAS,SAAS,OAAgD;AAChE,SAAO,OAAO,UAAU,YAAY,UAAU,OAAQ,QAAoC;AAC5F;AAEA,SAAS,eAAe,OAA+B;AACrD,SAAO,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,SAAS,IAAI,QAAQ;AACxE;AAQA,SAAS,kBAAkB,OAAwB;AACjD,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI;AACF,SAAK,MAAM,OAAO;AAClB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMA,IAAM,wBAAwB,oBAAI,IAAI,CAAC,aAAa,YAAY,WAAW,MAAM,CAAC;AAMlF,IAAM,uBAAuB,oBAAI,IAAI,CAAC,SAAS,QAAQ,CAAC;AASjD,SAAS,oBAAoB,OAA4C;AAC9E,QAAM,UAA8B,CAAC;AAErC,MAAI,MAAM,QAAQ;AAChB,YAAQ,KAAK;AAAA,MACX,MAAM;AAAA,MACN,QAAQ,eAAe,MAAM,aAAa,KAAK;AAAA,IACjD,CA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