@tangle-network/agent-runtime 0.142.3 → 0.153.1

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 (117) hide show
  1. package/README.md +32 -0
  2. package/dist/{activation-o7JKmtxi.js → activation-DKxQsHiO.js} +3 -3
  3. package/dist/{activation-o7JKmtxi.js.map → activation-DKxQsHiO.js.map} +1 -1
  4. package/dist/agent.d.ts +2 -2
  5. package/dist/agent.js +3 -3
  6. package/dist/{analyst-loop-GcX0BY75.js → analyst-loop-B2kTHKNh.js} +2 -2
  7. package/dist/{analyst-loop-GcX0BY75.js.map → analyst-loop-B2kTHKNh.js.map} +1 -1
  8. package/dist/analyst-loop.d.ts +1 -1
  9. package/dist/analyst-loop.js +1 -1
  10. package/dist/{authoring-Bm1WlGPv.js → authoring-Tk2xFys0.js} +2 -2
  11. package/dist/{authoring-Bm1WlGPv.js.map → authoring-Tk2xFys0.js.map} +1 -1
  12. package/dist/candidate-execution/index.js +4 -4
  13. package/dist/{candidate-execution-CD5PoNmC.js → candidate-execution-CB9RJbbJ.js} +4 -4
  14. package/dist/{candidate-execution-CD5PoNmC.js.map → candidate-execution-CB9RJbbJ.js.map} +1 -1
  15. package/dist/{conversation-DXKJHyqB.js → conversation-D64WyWrK.js} +4 -4
  16. package/dist/{conversation-DXKJHyqB.js.map → conversation-D64WyWrK.js.map} +1 -1
  17. package/dist/conversation.d.ts +1 -1
  18. package/dist/conversation.js +1 -1
  19. package/dist/durable.d.ts +102 -4
  20. package/dist/durable.js +259 -10
  21. package/dist/durable.js.map +1 -1
  22. package/dist/{environment-provider-BicwCDK5.d.ts → environment-provider-DJG0yIYl.d.ts} +3 -3
  23. package/dist/{environment-provider-DCEACNt9.js → environment-provider-D_MXw3jK.js} +88 -9
  24. package/dist/environment-provider-D_MXw3jK.js.map +1 -0
  25. package/dist/environment-provider.d.ts +1 -1
  26. package/dist/environment-provider.js +1 -1
  27. package/dist/executable-spec-BUcUcEPk.js +73 -0
  28. package/dist/executable-spec-BUcUcEPk.js.map +1 -0
  29. package/dist/{graph-DhrLuLOS.js → graph-M0Qr4863.js} +4 -4
  30. package/dist/{graph-DhrLuLOS.js.map → graph-M0Qr4863.js.map} +1 -1
  31. package/dist/{improvement-cycle-lcwlR6E2.js → improvement-cycle-CDxlGQGE.js} +7 -7
  32. package/dist/{improvement-cycle-lcwlR6E2.js.map → improvement-cycle-CDxlGQGE.js.map} +1 -1
  33. package/dist/{index-Bx3-tqG-.d.ts → index-BihHgUAI.d.ts} +4 -4
  34. package/dist/{index-D_aH0F4C.d.ts → index-Dlz7ejRx.d.ts} +342 -521
  35. package/dist/{index-CV1xRWy2.d.ts → index-LQfgFJoX.d.ts} +3 -3
  36. package/dist/index.d.ts +9 -9
  37. package/dist/index.js +13 -13
  38. package/dist/intelligence.d.ts +5 -5
  39. package/dist/intelligence.js +6 -6
  40. package/dist/kernel.d.ts +7 -7
  41. package/dist/kernel.js +13 -13
  42. package/dist/{knowledge-C9LlSJAR.js → knowledge-DM-i40b9.js} +10 -7
  43. package/dist/{knowledge-C9LlSJAR.js.map → knowledge-DM-i40b9.js.map} +1 -1
  44. package/dist/knowledge.d.ts +1 -1
  45. package/dist/knowledge.js +1 -1
  46. package/dist/{loop-runner-bin-CctBy5-X.d.ts → loop-runner-bin-D-BW51yr.d.ts} +3 -3
  47. package/dist/{loop-runner-bin-DFo6Ss-1.js → loop-runner-bin-pD5WJuqJ.js} +4 -4
  48. package/dist/{loop-runner-bin-DFo6Ss-1.js.map → loop-runner-bin-pD5WJuqJ.js.map} +1 -1
  49. package/dist/loop-runner-bin.d.ts +1 -1
  50. package/dist/loop-runner-bin.js +1 -1
  51. package/dist/{materialization-CrdcfWXp.js → materialization-Bo6j3Hg9.js} +261 -24
  52. package/dist/materialization-Bo6j3Hg9.js.map +1 -0
  53. package/dist/mcp/bin.js +3 -3
  54. package/dist/mcp/index.d.ts +5 -5
  55. package/dist/mcp/index.js +6 -6
  56. package/dist/{model-policy-DgRJIJse.js → model-policy-Sw4ywhtL.js} +68 -6
  57. package/dist/model-policy-Sw4ywhtL.js.map +1 -0
  58. package/dist/{openai-tools-CSm460sC.js → openai-tools-CWBywy-e.js} +2 -2
  59. package/dist/{openai-tools-CSm460sC.js.map → openai-tools-CWBywy-e.js.map} +1 -1
  60. package/dist/{openai-tools-t5-6h5bj.d.ts → openai-tools-z-whdYNC.d.ts} +2 -2
  61. package/dist/{prepare-D3n7cA39.js → prepare-C3eFd3UA.js} +2 -2
  62. package/dist/{prepare-D3n7cA39.js.map → prepare-C3eFd3UA.js.map} +1 -1
  63. package/dist/primeintellect/index.d.ts +1 -1
  64. package/dist/profiles.d.ts +1 -1
  65. package/dist/profiles.js +1 -1
  66. package/dist/{protected-model-port-bq6bD9YX.js → protected-model-port-Dn2b6peS.js} +2 -2
  67. package/dist/{protected-model-port-bq6bD9YX.js.map → protected-model-port-Dn2b6peS.js.map} +1 -1
  68. package/dist/{redact-B0gDSTZO.d.ts → redact-NAptmqKw.d.ts} +3 -3
  69. package/dist/{researcher-CiSY6Wzb.js → researcher-BMFFPwKb.js} +2 -2
  70. package/dist/{researcher-CiSY6Wzb.js.map → researcher-BMFFPwKb.js.map} +1 -1
  71. package/dist/{run-layout-Be_Z0dF8.js → run-layout-C2jgwsCq.js} +111 -6
  72. package/dist/run-layout-C2jgwsCq.js.map +1 -0
  73. package/dist/{runtime-htqI3fKL.d.ts → runtime-B-5dp5Iz.d.ts} +223 -11
  74. package/dist/{runtime-DQs5xHdt.js → runtime-RY_rvv7t.js} +93 -84
  75. package/dist/runtime-RY_rvv7t.js.map +1 -0
  76. package/dist/{sandbox-events-BK-g19wx.js → sandbox-events-DMijDq2p.js} +53 -49
  77. package/dist/sandbox-events-DMijDq2p.js.map +1 -0
  78. package/dist/{spawn-journal-D2HKUImC.js → spawn-journal-CLguaA2A.js} +8 -43
  79. package/dist/spawn-journal-CLguaA2A.js.map +1 -0
  80. package/dist/{stream-agent-turn-Dfy12OjG.d.ts → stream-agent-turn-BGyszuPH.d.ts} +6 -3
  81. package/dist/{stream-agent-turn-BMHUIuQS.js → stream-agent-turn-D6HoaRPV.js} +140 -23
  82. package/dist/stream-agent-turn-D6HoaRPV.js.map +1 -0
  83. package/dist/{structural-rollout-CzZKDkmA.js → structural-rollout-P1YxFRfl.js} +11 -8
  84. package/dist/structural-rollout-P1YxFRfl.js.map +1 -0
  85. package/dist/{supervise-BEs5MB91.js → supervise-BezbzKiJ.js} +1550 -1186
  86. package/dist/supervise-BezbzKiJ.js.map +1 -0
  87. package/dist/{supervisor-B_0ISTFG.js → supervisor-DBVlPONC.js} +697 -230
  88. package/dist/supervisor-DBVlPONC.js.map +1 -0
  89. package/dist/testing.d.ts +2 -2
  90. package/dist/testing.js +12 -12
  91. package/dist/{top-app-BMOSKK06.js → top-app-tKo9OrON.js} +189 -86
  92. package/dist/top-app-tKo9OrON.js.map +1 -0
  93. package/dist/tui/bin.js +1 -1
  94. package/dist/tui/index.d.ts +32 -4
  95. package/dist/tui/index.js +1 -1
  96. package/dist/{types-_7w24mMg.d.ts → types-BPQhQRrC.d.ts} +508 -11
  97. package/dist/{types-DZrBoBpN.d.ts → types-DeX8ibLc.d.ts} +4 -1
  98. package/dist/{util-C1bv6yog.js → util-Bncw0o_F.js} +41 -2
  99. package/dist/util-Bncw0o_F.js.map +1 -0
  100. package/dist/{workspace-archive-C52LjkeN.js → workspace-archive-Dm73lTfB.js} +2 -2
  101. package/dist/{workspace-archive-C52LjkeN.js.map → workspace-archive-Dm73lTfB.js.map} +1 -1
  102. package/package.json +6 -6
  103. package/dist/environment-provider-DCEACNt9.js.map +0 -1
  104. package/dist/materialization-CrdcfWXp.js.map +0 -1
  105. package/dist/model-policy-DgRJIJse.js.map +0 -1
  106. package/dist/retained-run-binding-Dp2e8xne.js +0 -268
  107. package/dist/retained-run-binding-Dp2e8xne.js.map +0 -1
  108. package/dist/run-layout-Be_Z0dF8.js.map +0 -1
  109. package/dist/runtime-DQs5xHdt.js.map +0 -1
  110. package/dist/sandbox-events-BK-g19wx.js.map +0 -1
  111. package/dist/spawn-journal-D2HKUImC.js.map +0 -1
  112. package/dist/stream-agent-turn-BMHUIuQS.js.map +0 -1
  113. package/dist/structural-rollout-CzZKDkmA.js.map +0 -1
  114. package/dist/supervise-BEs5MB91.js.map +0 -1
  115. package/dist/supervisor-B_0ISTFG.js.map +0 -1
  116. package/dist/top-app-BMOSKK06.js.map +0 -1
  117. package/dist/util-C1bv6yog.js.map +0 -1
@@ -28,7 +28,15 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeF
28
28
  * {@link WorkerCancelRequest}
29
29
  * cancellations/<opId>.json the acknowledgement for one cancel operation — a
30
30
  * {@link WorkerCancellation} written ONLY by the runtime
31
- * acknowledger (the coordination driver's turn loop)
31
+ * acknowledger in the OWNING manager's turn loop: exact node
32
+ * ids route to the manager that parents them (any depth);
33
+ * label/profile-name references to the root manager alone
34
+ * cancellations/run.request.json the run-scoped cancel request — one {@link RunCancelRequest},
35
+ * the whole RUN rather than one worker
36
+ * cancellations/run.json the acknowledgement for the run-scoped request — a
37
+ * {@link RunCancellation} written ONLY by the runtime (the root
38
+ * manager issues the abort; the `supervise()` settle path records
39
+ * what the run actually did)
32
40
  *
33
41
  * Reads are tolerant by contract: a partial trailing line (a writer mid-append) or a corrupt line
34
42
  * never poisons the rest of the file — later valid lines still matter.
@@ -217,9 +225,10 @@ function writeWorkerCancellation(eventDir, record) {
217
225
  * durable state.
218
226
  *
219
227
  * The write half of the acknowledged-cancellation contract (`writeWorkerSteer` is the steer
220
- * analog): append the request to the run's cancellation inbox, where the runtime's acknowledger
221
- * (the coordination driver's turn loop) applies it aborting exactly that worker's subtree and
222
- * recording what it proved. This function never applies the cancellation itself; writing a
228
+ * analog): append the request to the run's cancellation inbox, where the OWNING manager's
229
+ * acknowledger (its turn loop the root for label/profile references, the parent manager for an
230
+ * exact node id at any depth) applies it aborting exactly that worker's subtree and recording
231
+ * what it proved. This function never applies the cancellation itself; writing a
223
232
  * request file is not an acknowledgement.
224
233
  *
225
234
  * Idempotency is a lookup: when an acknowledgement for `operationId` already exists, it is
@@ -266,6 +275,102 @@ function cancelWorker(eventDir, worker, operationId, options = {}) {
266
275
  terminated: []
267
276
  };
268
277
  }
278
+ /** The run-scoped cancel request file of one run — one {@link RunCancelRequest}. */
279
+ function runCancelRequestFile(eventDir) {
280
+ return join(workerCancellationsDir(eventDir), "run.request.json");
281
+ }
282
+ /** The run-scoped acknowledgement file of one run — one {@link RunCancellation}. */
283
+ function runCancellationFile(eventDir) {
284
+ return join(workerCancellationsDir(eventDir), "run.json");
285
+ }
286
+ /** Read the run-scoped cancel request, or `undefined` when none was written. */
287
+ function readRunCancelRequest(eventDir) {
288
+ const file = runCancelRequestFile(eventDir);
289
+ if (!existsSync(file)) return void 0;
290
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
291
+ if (!isRunCancelRequest(parsed)) throw new Error(`run cancel request '${file}' is not a complete RunCancelRequest`);
292
+ return parsed;
293
+ }
294
+ /**
295
+ * Read the acknowledgement for the run-scoped cancel operation. `undefined` when the runtime has
296
+ * not answered. A record holding a DIFFERENT `operationId` belongs to another operation on the
297
+ * same run — fail loud rather than answer for it.
298
+ */
299
+ function readRunCancellation(eventDir, operationId) {
300
+ const file = runCancellationFile(eventDir);
301
+ if (!existsSync(file)) return void 0;
302
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
303
+ if (parsed.operationId !== operationId) throw new Error(`run cancel acknowledgement '${file}' holds operation '${parsed.operationId}', not '${operationId}' — one run carries one run-scoped cancel operation`);
304
+ return parsed;
305
+ }
306
+ /**
307
+ * Durably write the run-scoped acknowledgement. Write-then-rename, so a concurrent reader sees the
308
+ * prior complete record or the new complete record, never a partial file.
309
+ *
310
+ * @internal The runtime is the only intended writer; clients read via {@link readRunCancellation}
311
+ * or {@link cancelRun}.
312
+ */
313
+ function writeRunCancellation(eventDir, record) {
314
+ mkdirSync(workerCancellationsDir(eventDir), { recursive: true });
315
+ const file = runCancellationFile(eventDir);
316
+ const tmp = `${file}.${randomUUID()}.tmp`;
317
+ writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\n`, "utf8");
318
+ renameSync(tmp, file);
319
+ }
320
+ /**
321
+ * Request the cancellation of the WHOLE run, idempotently, and return the operation's current
322
+ * durable state.
323
+ *
324
+ * The run-scoped twin of {@link cancelWorker}: write the request into the run's cancellation
325
+ * directory, where the run's own root manager applies it — aborting the root through the one
326
+ * cascade controller the run already has, so every live worker comes down with it. This function
327
+ * never applies the cancellation itself; writing a request file is not an acknowledgement.
328
+ *
329
+ * Idempotency is a lookup: when an acknowledgement for `operationId` already exists it is returned
330
+ * AS-IS and nothing is written. A request the runtime has not answered yet returns
331
+ * `effect: 'unknown'` (never a success); call again with the same `operationId` — or
332
+ * {@link readRunCancellation} — to read the acknowledged result after a reconnect.
333
+ *
334
+ * A run carries ONE run-scoped operation: a second request under a different `operationId` throws
335
+ * rather than silently replacing the pending one, because both would claim the same single abort.
336
+ */
337
+ function cancelRun(eventDir, operationId, options = {}) {
338
+ const opId = operationId.trim();
339
+ if (!opId) throw new Error("cancelRun: operationId is empty");
340
+ const acknowledged = readRunCancellation(eventDir, opId);
341
+ if (acknowledged) return acknowledged;
342
+ const pending = readRunCancelRequest(eventDir);
343
+ if (pending !== void 0 && pending.operationId !== opId) throw new Error(`cancelRun: run cancel '${pending.operationId}' is already pending for this run; read it with readRunCancellation instead of issuing '${opId}'`);
344
+ const source = options.source ?? "human";
345
+ const request = pending ?? {
346
+ operationId: opId,
347
+ at: (/* @__PURE__ */ new Date()).toISOString(),
348
+ source,
349
+ ...options.reason === void 0 ? {} : { reason: options.reason }
350
+ };
351
+ if (pending === void 0) {
352
+ mkdirSync(workerCancellationsDir(eventDir), { recursive: true });
353
+ writeFileSync(runCancelRequestFile(eventDir), `${JSON.stringify(request, null, 2)}\n`, "utf8");
354
+ appendWorkerControlEvent(eventDir, "run", {
355
+ kind: "run-cancel-request",
356
+ operationId: opId,
357
+ source,
358
+ queued: true,
359
+ ...options.reason === void 0 ? {} : { reason: options.reason }
360
+ });
361
+ }
362
+ return {
363
+ operationId: opId,
364
+ effect: "unknown",
365
+ requestedAt: request.at,
366
+ observedAt: request.at,
367
+ ...request.reason === void 0 ? {} : { reason: request.reason },
368
+ detail: "request queued; no runtime acknowledger has answered yet"
369
+ };
370
+ }
371
+ function isRunCancelRequest(value) {
372
+ return typeof value.operationId === "string" && value.operationId.length > 0 && typeof value.at === "string" && typeof value.source === "string" && (value.reason === void 0 || typeof value.reason === "string");
373
+ }
269
374
  function isWorkerCancelRequest(value) {
270
375
  return typeof value.operationId === "string" && value.operationId.length > 0 && typeof value.at === "string" && typeof value.source === "string" && typeof value.worker === "string" && value.worker.length > 0 && (value.reason === void 0 || typeof value.reason === "string");
271
376
  }
@@ -283,6 +388,6 @@ function isWorkerSteerRequest(value) {
283
388
  return typeof value.id === "string" && typeof value.at === "string" && typeof value.source === "string" && typeof value.worker === "string" && typeof value.message === "string" && value.message.trim().length > 0;
284
389
  }
285
390
  //#endregion
286
- export { writeWorkerCancellation as _, readWorkerCancellation as a, supervisorRunDir as c, workerCancelRequestsFile as d, workerCancellationFile as f, workerInboxFileFromEventDir as g, workerInboxFile as h, readWorkerCancelRequests as i, supervisorRunsRoot as l, workerControlLogFile as m, legacySupervisorRunDir as n, readWorkerSteerRequests as o, workerCancellationsDir as p, legacySupervisorRunsRoot as r, safeWorkerFile as s, cancelWorker as t, supervisorWorkersDir as u, writeWorkerSteer as v };
391
+ export { writeWorkerCancellation as C, writeRunCancellation as S, workerCancellationFile as _, readRunCancelRequest as a, workerInboxFile as b, readWorkerCancellation as c, runCancellationFile as d, safeWorkerFile as f, workerCancelRequestsFile as g, supervisorWorkersDir as h, legacySupervisorRunsRoot as i, readWorkerSteerRequests as l, supervisorRunsRoot as m, cancelWorker as n, readRunCancellation as o, supervisorRunDir as p, legacySupervisorRunDir as r, readWorkerCancelRequests as s, cancelRun as t, runCancelRequestFile as u, workerCancellationsDir as v, writeWorkerSteer as w, workerInboxFileFromEventDir as x, workerControlLogFile as y };
287
392
 
288
- //# sourceMappingURL=run-layout-Be_Z0dF8.js.map
393
+ //# sourceMappingURL=run-layout-C2jgwsCq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-layout-C2jgwsCq.js","names":[],"sources":["../src/runtime/supervise/run-layout.ts"],"sourcesContent":["/**\n * The on-disk supervisor-run layout: `<root>/.agent/supervisor/<id>`.\n *\n * This is the durable, cross-process face of a supervisor run — the counterpart to the in-process\n * `Inbox` seam in `./inbox`. A run persists its state under one directory so that any OTHER process\n * can find it after the fact: `@tangle-network/traces` reads exactly this layout via\n * `traces analyze --supervisor-run-dir`, a restarted host can rehydrate a run it no longer holds\n * handles to, and a human can steer a live worker by appending one NDJSON line. Until now the\n * layout was defined only in the unpublished `loops` repo (`src/supervisor-control.ts`) — a\n * published reader depending on an unpublished writer's convention — so the contract is promoted\n * here, names preserved.\n *\n * `.agent` is the one dot-dir for ALL agent-owned state (skills already write\n * `.agent/hypotheses/`, `.agent/skill-runs.jsonl`); supervisor runs live beside them rather than\n * under a product-branded dir. Runs written by older writers used `.loops/supervisor/<id>` —\n * readers that must see those keep a legacy fallback; this writer never creates `.loops` again.\n *\n * Layout, relative to `supervisorRunDir(root, id)`:\n *\n * workers/<label>.inbox.ndjson down-leg steer/answer requests for one worker (durable inbox);\n * each line is a {@link WorkerSteerRequest}\n * workers/<label>.ndjson best-effort per-worker control-event log (delivery bookkeeping)\n * cancellations/requests.ndjson worker-scoped cancel requests (durable inbox); each line is a\n * {@link WorkerCancelRequest}\n * cancellations/<opId>.json the acknowledgement for one cancel operation — a\n * {@link WorkerCancellation} written ONLY by the runtime\n * acknowledger in the OWNING manager's turn loop: exact node\n * ids route to the manager that parents them (any depth);\n * label/profile-name references to the root manager alone\n * cancellations/run.request.json the run-scoped cancel request — one {@link RunCancelRequest},\n * the whole RUN rather than one worker\n * cancellations/run.json the acknowledgement for the run-scoped request — a\n * {@link RunCancellation} written ONLY by the runtime (the root\n * manager issues the abort; the `supervise()` settle path records\n * what the run actually did)\n *\n * Reads are tolerant by contract: a partial trailing line (a writer mid-append) or a corrupt line\n * never poisons the rest of the file — later valid lines still matter.\n *\n * Promoted from `loops/src/supervisor-control.ts`. The one deliberate difference: the loops version\n * resolved a worker id to its label through the run journal before writing a steer; that resolution\n * stays with the caller (it is journal-format-specific), so `writeWorkerSteer` here takes the worker\n * LABEL directly.\n *\n * @experimental\n */\n\nimport { randomUUID } from 'node:crypto'\nimport {\n appendFileSync,\n existsSync,\n mkdirSync,\n readFileSync,\n renameSync,\n writeFileSync,\n} from 'node:fs'\nimport { join, resolve } from 'node:path'\nimport type { RetainedRunEffect } from '../retained-run-types'\n\n/** One durable down-leg request appended to a worker's inbox file. */\nexport interface WorkerSteerRequest {\n readonly id: string\n /** ISO timestamp of the append. */\n readonly at: string\n /** Who asked — 'human', a brain label, a tool name. Provenance, not authorization. */\n readonly source: string\n /** The worker LABEL the request targets (already resolved by the caller). */\n readonly worker: string\n readonly message: string\n}\n\n/** One durable worker-scoped cancel request appended to the run's cancellation inbox. */\nexport interface WorkerCancelRequest {\n /** Caller-minted stable operation identifier — the idempotency key of the whole operation. */\n readonly operationId: string\n /** ISO timestamp of the append. */\n readonly at: string\n /** Who asked — 'human', a brain label, a tool name. Provenance, not authorization. */\n readonly source: string\n /** The worker the request targets: a workerId (node id — routed to the owning manager at any\n * depth), or a profile name or spawn label (resolved by the root manager against its direct\n * children only). */\n readonly worker: string\n readonly reason?: string\n}\n\n/**\n * The durable acknowledgement state for one worker-scoped cancel operation, keyed by\n * `operationId`. The runtime acknowledger is the ONLY writer; `cancelWorker` only reads it.\n *\n * `effect` reuses the retained-run vocabulary ({@link RetainedRunEffect}) so the runtime has one\n * spelling of the four cancellation states:\n * - `'unknown'` — not yet resolved by the runtime (also what `cancelWorker` returns for\n * a request no acknowledger has answered), or — terminally, with the\n * run-over detail — an abort was issued but the run ended before the\n * termination could be observed. Never a success.\n * - `'cancel_requested'` — the runtime issued the worker's abort; termination not yet proven.\n * - `'cancelled'` — the worker reached a terminal `down` state on the settle path.\n * - `'not_live'` — the worker was not live to cancel (already settled, it settled\n * `done` despite the abort, or the run ended before the request was\n * ever applied). Never a success of THIS operation.\n *\n * Expiry is run end: the owning manager's final pass closes every still-open request it owns\n * (`not_live` never applied, `unknown` issued-but-unproven), so a pending request cannot outlive\n * its run and abort a future spawn that happens to reuse a label.\n */\nexport interface WorkerCancellation {\n readonly operationId: string\n /** The worker reference exactly as requested. */\n readonly worker: string\n readonly effect: RetainedRunEffect\n /** ISO timestamp of the original request. */\n readonly requestedAt: string\n /** ISO timestamp of the runtime's most recent observation of this operation. */\n readonly observedAt: string\n /** The node id the acknowledger resolved `worker` to, once resolved. */\n readonly workerId?: string\n /** The caller's reason, carried verbatim from the request. */\n readonly reason?: string\n /** The runtime's explanation of how it arrived at `effect`. */\n readonly detail?: string\n /**\n * Every node id this operation PROVED terminated: the requested worker plus each descendant of\n * its subtree observed to reach a terminal `down`/`cancelled` journal record at or after the\n * abort was ISSUED — the acknowledger's own `observedAt` on the `cancel_requested` record\n * (runtime clock), never the client's `requestedAt` (a cancelled lead cascades to its subtree\n * by design — the scope signal chain — so the acknowledgement names the set, not one id).\n * Proven at acknowledgement time; post-abort causation is approximate: a descendant that died\n * of its own cause after the abort is indistinguishable from the cascade and may be included,\n * a late teardown journal joins the set on a later pass while the manager still runs, and one\n * still absent at run end is absent from the set. Grows monotonically; empty until termination\n * is proven.\n */\n readonly terminated: ReadonlyArray<string>\n}\n\n/** One durable run-scoped cancel request: cancel the WHOLE run, not one worker. */\nexport interface RunCancelRequest {\n /** Caller-minted stable operation identifier — the idempotency key of the whole operation. */\n readonly operationId: string\n /** ISO timestamp of the write. */\n readonly at: string\n /** Who asked — 'human', a brain label, a tool name. Provenance, not authorization. */\n readonly source: string\n readonly reason?: string\n}\n\n/**\n * The durable acknowledgement state for the run-scoped cancel operation, keyed by `operationId`.\n * The runtime is the ONLY writer; {@link cancelRun} only reads it.\n *\n * `effect` is the same {@link RetainedRunEffect} vocabulary the worker-scoped and retained-run\n * paths use, so the runtime has one spelling of the four cancellation states:\n * - `'unknown'` — no runtime has answered yet. Never a success.\n * - `'cancel_requested'` — the root manager issued the run's cascading abort; the run's terminal\n * state is not yet observed.\n * - `'cancelled'` — the run reached its terminal state ABORTED after that request.\n * - `'not_live'` — the run was not live to cancel: it settled on its own despite the\n * request, or it ended before the request was applied.\n */\nexport interface RunCancellation {\n readonly operationId: string\n readonly effect: RetainedRunEffect\n /** ISO timestamp of the original request. */\n readonly requestedAt: string\n /** ISO timestamp of the runtime's most recent observation of this operation. */\n readonly observedAt: string\n /** The caller's reason, carried verbatim from the request. */\n readonly reason?: string\n /** The runtime's explanation of how it arrived at `effect`. */\n readonly detail?: string\n}\n\n/** The root every supervisor run of one workspace lives under. */\nexport function supervisorRunsRoot(rootDir: string): string {\n return join(resolve(rootDir), '.agent', 'supervisor')\n}\n\n/** The run directory every artifact of one supervisor run lives under. */\nexport function supervisorRunDir(rootDir: string, id: string): string {\n return join(supervisorRunsRoot(rootDir), id)\n}\n\n/**\n * Where a pre-rename writer put the same run (`<root>/.loops/supervisor/<id>`). Readers that must\n * see historical runs check {@link supervisorRunDir} first and fall back to this; nothing writes\n * here anymore.\n */\nexport function legacySupervisorRunDir(rootDir: string, id: string): string {\n return join(legacySupervisorRunsRoot(rootDir), id)\n}\n\n/**\n * The pre-rename runs root (`<root>/.loops/supervisor`). Only readers that ENUMERATE historical\n * runs need this — the per-id form is {@link legacySupervisorRunDir}. Nothing writes here.\n */\nexport function legacySupervisorRunsRoot(rootDir: string): string {\n return join(resolve(rootDir), '.loops', 'supervisor')\n}\n\n/** A worker label reduced to a safe filename stem. Empty labels get a stable fallback. */\nexport function safeWorkerFile(label: string): string {\n const safe = label.replace(/[^A-Za-z0-9._-]/g, '_')\n return safe.length > 0 ? safe : 'worker'\n}\n\n/** The directory holding every per-worker file of one run (inboxes and control-event logs). */\nexport function supervisorWorkersDir(eventDir: string): string {\n return join(eventDir, 'workers')\n}\n\n/** The durable inbox file for one worker of one run. */\nexport function workerInboxFile(rootDir: string, supervisorId: string, worker: string): string {\n return workerInboxFileFromEventDir(supervisorRunDir(rootDir, supervisorId), worker)\n}\n\n/** Same, addressed from an already-known run directory (the reader's usual entry point). */\nexport function workerInboxFileFromEventDir(eventDir: string, worker: string): string {\n return join(supervisorWorkersDir(eventDir), `${safeWorkerFile(worker)}.inbox.ndjson`)\n}\n\n/**\n * The best-effort control-event log for one worker (`workers/<label>.ndjson`) — delivery\n * bookkeeping for steers, plus whatever lifecycle events a writer chooses to append. Distinct from\n * the inbox: the inbox is the durable down-leg queue, this is the record of what happened to it.\n */\nexport function workerControlLogFile(eventDir: string, worker: string): string {\n return join(supervisorWorkersDir(eventDir), `${safeWorkerFile(worker)}.ndjson`)\n}\n\n/**\n * Durably append one steer request to a worker's inbox and log the delivery attempt.\n *\n * The inbox append is the durable act; the control-event log is best-effort bookkeeping and may\n * silently fail without voiding the steer.\n */\nexport function writeWorkerSteer(\n rootDir: string,\n supervisorId: string,\n worker: string,\n message: string,\n source = 'human',\n): { worker: string; file: string; request: WorkerSteerRequest } {\n const trimmed = message.trim()\n if (!trimmed) throw new Error('steer message is empty')\n const dir = supervisorRunDir(rootDir, supervisorId)\n mkdirSync(supervisorWorkersDir(dir), { recursive: true })\n const request: WorkerSteerRequest = {\n id: randomUUID(),\n at: new Date().toISOString(),\n source,\n worker,\n message: trimmed,\n }\n const file = workerInboxFile(rootDir, supervisorId, worker)\n appendFileSync(file, `${JSON.stringify(request)}\\n`, 'utf8')\n appendWorkerControlEvent(dir, worker, {\n kind: 'message',\n direction: 'down',\n source,\n requestId: request.id,\n message: trimmed,\n queued: true,\n delivered: false,\n })\n return { worker, file, request }\n}\n\n/** Read every valid steer request in a worker's inbox. Corrupt or partial lines are skipped. */\nexport function readWorkerSteerRequests(eventDir: string, worker: string): WorkerSteerRequest[] {\n const file = workerInboxFileFromEventDir(eventDir, worker)\n if (!existsSync(file)) return []\n const out: WorkerSteerRequest[] = []\n let raw = ''\n try {\n raw = readFileSync(file, 'utf8')\n } catch {\n return out\n }\n for (const line of raw.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed) continue\n try {\n const parsed = JSON.parse(trimmed) as Partial<WorkerSteerRequest>\n if (isWorkerSteerRequest(parsed)) out.push(parsed)\n } catch {\n // Ignore partial or corrupt input lines; later valid lines still matter.\n }\n }\n return out\n}\n\n/** The directory holding every cancellation artifact of one run (request inbox + acknowledgements). */\nexport function workerCancellationsDir(eventDir: string): string {\n return join(eventDir, 'cancellations')\n}\n\n/** The durable cancel-request inbox of one run — one NDJSON line per {@link WorkerCancelRequest}. */\nexport function workerCancelRequestsFile(eventDir: string): string {\n return join(workerCancellationsDir(eventDir), 'requests.ndjson')\n}\n\n/**\n * The acknowledgement file for one cancel operation. The filename is a sanitized stem of the\n * `operationId`; the record inside carries the exact id, and readers verify it so two distinct\n * ids that sanitize to one stem fail loud instead of answering for each other.\n */\nexport function workerCancellationFile(eventDir: string, operationId: string): string {\n return join(workerCancellationsDir(eventDir), `${safeOperationFile(operationId)}.json`)\n}\n\nfunction safeOperationFile(operationId: string): string {\n const safe = operationId.replace(/[^A-Za-z0-9._-]/g, '_')\n if (safe.length === 0) throw new Error('cancel operationId is empty')\n return safe\n}\n\n/** Read every valid cancel request in the run's cancellation inbox. Corrupt lines are skipped. */\nexport function readWorkerCancelRequests(eventDir: string): WorkerCancelRequest[] {\n const file = workerCancelRequestsFile(eventDir)\n if (!existsSync(file)) return []\n const out: WorkerCancelRequest[] = []\n let raw = ''\n try {\n raw = readFileSync(file, 'utf8')\n } catch {\n return out\n }\n for (const line of raw.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed) continue\n try {\n const parsed = JSON.parse(trimmed) as Partial<WorkerCancelRequest>\n if (isWorkerCancelRequest(parsed)) out.push(parsed)\n } catch {\n // Ignore partial or corrupt input lines; later valid lines still matter.\n }\n }\n return out\n}\n\n/**\n * Read the acknowledgement for one cancel operation. `undefined` when the runtime has not\n * answered. A record whose stored `operationId` differs from the requested one is a filename\n * collision between two sanitized ids — fail loud rather than return another operation's answer.\n */\nexport function readWorkerCancellation(\n eventDir: string,\n operationId: string,\n): WorkerCancellation | undefined {\n const file = workerCancellationFile(eventDir, operationId)\n if (!existsSync(file)) return undefined\n const parsed = JSON.parse(readFileSync(file, 'utf8')) as WorkerCancellation\n if (parsed.operationId !== operationId) {\n throw new Error(\n `cancel acknowledgement collision: '${file}' holds operation '${parsed.operationId}', ` +\n `not '${operationId}' — use operation ids that stay distinct after filename sanitization`,\n )\n }\n return parsed\n}\n\n/**\n * Durably write one acknowledgement record. Write-then-rename, so a concurrent reader sees the\n * prior complete record or the new complete record, never a partial file.\n *\n * @internal The runtime acknowledger is the only intended writer; clients read via\n * {@link readWorkerCancellation} or {@link cancelWorker}.\n */\nexport function writeWorkerCancellation(eventDir: string, record: WorkerCancellation): void {\n const dir = workerCancellationsDir(eventDir)\n mkdirSync(dir, { recursive: true })\n const file = workerCancellationFile(eventDir, record.operationId)\n const tmp = `${file}.${randomUUID()}.tmp`\n writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\\n`, 'utf8')\n renameSync(tmp, file)\n}\n\n/**\n * Request the cancellation of ONE worker, idempotently, and return the operation's current\n * durable state.\n *\n * The write half of the acknowledged-cancellation contract (`writeWorkerSteer` is the steer\n * analog): append the request to the run's cancellation inbox, where the OWNING manager's\n * acknowledger (its turn loop — the root for label/profile references, the parent manager for an\n * exact node id at any depth) applies it — aborting exactly that worker's subtree and recording\n * what it proved. This function never applies the cancellation itself; writing a\n * request file is not an acknowledgement.\n *\n * Idempotency is a lookup: when an acknowledgement for `operationId` already exists, it is\n * returned AS-IS and nothing is appended — repeating one operation can never apply twice. A\n * request the runtime has not answered yet returns `effect: 'unknown'` (never a success); call\n * again with the same `operationId` — or `readWorkerCancellation` — to read the acknowledged\n * result after a reconnect.\n */\nexport function cancelWorker(\n eventDir: string,\n worker: string,\n operationId: string,\n options: { readonly reason?: string; readonly source?: string } = {},\n): WorkerCancellation {\n const ref = worker.trim()\n if (!ref) throw new Error('cancelWorker: worker reference is empty')\n const opId = operationId.trim()\n if (!opId) throw new Error('cancelWorker: operationId is empty')\n const acknowledged = readWorkerCancellation(eventDir, opId)\n if (acknowledged) return acknowledged\n const source = options.source ?? 'human'\n const pending = readWorkerCancelRequests(eventDir).find((r) => r.operationId === opId)\n const request: WorkerCancelRequest = pending ?? {\n operationId: opId,\n at: new Date().toISOString(),\n source,\n worker: ref,\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n }\n if (!pending) {\n mkdirSync(workerCancellationsDir(eventDir), { recursive: true })\n appendFileSync(workerCancelRequestsFile(eventDir), `${JSON.stringify(request)}\\n`, 'utf8')\n appendWorkerControlEvent(eventDir, ref, {\n kind: 'cancel-request',\n operationId: opId,\n source,\n queued: true,\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n })\n }\n return {\n operationId: opId,\n worker: request.worker,\n effect: 'unknown',\n requestedAt: request.at,\n observedAt: request.at,\n ...(request.reason === undefined ? {} : { reason: request.reason }),\n detail: 'request queued; no runtime acknowledger has answered yet',\n terminated: [],\n }\n}\n\n/** The run-scoped cancel request file of one run — one {@link RunCancelRequest}. */\nexport function runCancelRequestFile(eventDir: string): string {\n return join(workerCancellationsDir(eventDir), 'run.request.json')\n}\n\n/** The run-scoped acknowledgement file of one run — one {@link RunCancellation}. */\nexport function runCancellationFile(eventDir: string): string {\n return join(workerCancellationsDir(eventDir), 'run.json')\n}\n\n/** Read the run-scoped cancel request, or `undefined` when none was written. */\nexport function readRunCancelRequest(eventDir: string): RunCancelRequest | undefined {\n const file = runCancelRequestFile(eventDir)\n if (!existsSync(file)) return undefined\n const parsed = JSON.parse(readFileSync(file, 'utf8')) as Partial<RunCancelRequest>\n if (!isRunCancelRequest(parsed)) {\n throw new Error(`run cancel request '${file}' is not a complete RunCancelRequest`)\n }\n return parsed\n}\n\n/**\n * Read the acknowledgement for the run-scoped cancel operation. `undefined` when the runtime has\n * not answered. A record holding a DIFFERENT `operationId` belongs to another operation on the\n * same run — fail loud rather than answer for it.\n */\nexport function readRunCancellation(\n eventDir: string,\n operationId: string,\n): RunCancellation | undefined {\n const file = runCancellationFile(eventDir)\n if (!existsSync(file)) return undefined\n const parsed = JSON.parse(readFileSync(file, 'utf8')) as RunCancellation\n if (parsed.operationId !== operationId) {\n throw new Error(\n `run cancel acknowledgement '${file}' holds operation '${parsed.operationId}', not ` +\n `'${operationId}' — one run carries one run-scoped cancel operation`,\n )\n }\n return parsed\n}\n\n/**\n * Durably write the run-scoped acknowledgement. Write-then-rename, so a concurrent reader sees the\n * prior complete record or the new complete record, never a partial file.\n *\n * @internal The runtime is the only intended writer; clients read via {@link readRunCancellation}\n * or {@link cancelRun}.\n */\nexport function writeRunCancellation(eventDir: string, record: RunCancellation): void {\n const dir = workerCancellationsDir(eventDir)\n mkdirSync(dir, { recursive: true })\n const file = runCancellationFile(eventDir)\n const tmp = `${file}.${randomUUID()}.tmp`\n writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\\n`, 'utf8')\n renameSync(tmp, file)\n}\n\n/**\n * Request the cancellation of the WHOLE run, idempotently, and return the operation's current\n * durable state.\n *\n * The run-scoped twin of {@link cancelWorker}: write the request into the run's cancellation\n * directory, where the run's own root manager applies it — aborting the root through the one\n * cascade controller the run already has, so every live worker comes down with it. This function\n * never applies the cancellation itself; writing a request file is not an acknowledgement.\n *\n * Idempotency is a lookup: when an acknowledgement for `operationId` already exists it is returned\n * AS-IS and nothing is written. A request the runtime has not answered yet returns\n * `effect: 'unknown'` (never a success); call again with the same `operationId` — or\n * {@link readRunCancellation} — to read the acknowledged result after a reconnect.\n *\n * A run carries ONE run-scoped operation: a second request under a different `operationId` throws\n * rather than silently replacing the pending one, because both would claim the same single abort.\n */\nexport function cancelRun(\n eventDir: string,\n operationId: string,\n options: { readonly reason?: string; readonly source?: string } = {},\n): RunCancellation {\n const opId = operationId.trim()\n if (!opId) throw new Error('cancelRun: operationId is empty')\n const acknowledged = readRunCancellation(eventDir, opId)\n if (acknowledged) return acknowledged\n const pending = readRunCancelRequest(eventDir)\n if (pending !== undefined && pending.operationId !== opId) {\n throw new Error(\n `cancelRun: run cancel '${pending.operationId}' is already pending for this run; ` +\n `read it with readRunCancellation instead of issuing '${opId}'`,\n )\n }\n const source = options.source ?? 'human'\n const request: RunCancelRequest = pending ?? {\n operationId: opId,\n at: new Date().toISOString(),\n source,\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n }\n if (pending === undefined) {\n mkdirSync(workerCancellationsDir(eventDir), { recursive: true })\n writeFileSync(runCancelRequestFile(eventDir), `${JSON.stringify(request, null, 2)}\\n`, 'utf8')\n appendWorkerControlEvent(eventDir, 'run', {\n kind: 'run-cancel-request',\n operationId: opId,\n source,\n queued: true,\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n })\n }\n return {\n operationId: opId,\n effect: 'unknown',\n requestedAt: request.at,\n observedAt: request.at,\n ...(request.reason === undefined ? {} : { reason: request.reason }),\n detail: 'request queued; no runtime acknowledger has answered yet',\n }\n}\n\nfunction isRunCancelRequest(value: Partial<RunCancelRequest>): value is RunCancelRequest {\n return (\n typeof value.operationId === 'string' &&\n value.operationId.length > 0 &&\n typeof value.at === 'string' &&\n typeof value.source === 'string' &&\n (value.reason === undefined || typeof value.reason === 'string')\n )\n}\n\nfunction isWorkerCancelRequest(value: Partial<WorkerCancelRequest>): value is WorkerCancelRequest {\n return (\n typeof value.operationId === 'string' &&\n value.operationId.length > 0 &&\n typeof value.at === 'string' &&\n typeof value.source === 'string' &&\n typeof value.worker === 'string' &&\n value.worker.length > 0 &&\n (value.reason === undefined || typeof value.reason === 'string')\n )\n}\n\nfunction appendWorkerControlEvent(\n eventDir: string,\n label: string,\n event: Record<string, unknown>,\n): void {\n try {\n mkdirSync(supervisorWorkersDir(eventDir), { recursive: true })\n appendFileSync(\n workerControlLogFile(eventDir, label),\n `${JSON.stringify({ at: new Date().toISOString(), label, ...event })}\\n`,\n 'utf8',\n )\n } catch {\n // Control logging is best-effort; the inbox write above is the durable part.\n }\n}\n\nfunction isWorkerSteerRequest(value: Partial<WorkerSteerRequest>): value is WorkerSteerRequest {\n return (\n typeof value.id === 'string' &&\n typeof value.at === 'string' &&\n typeof value.source === 'string' &&\n typeof value.worker === 'string' &&\n typeof value.message === 'string' &&\n value.message.trim().length > 0\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8KA,SAAgB,mBAAmB,SAAyB;CAC1D,OAAO,KAAK,QAAQ,OAAO,GAAG,UAAU,YAAY;AACtD;;AAGA,SAAgB,iBAAiB,SAAiB,IAAoB;CACpE,OAAO,KAAK,mBAAmB,OAAO,GAAG,EAAE;AAC7C;;;;;;AAOA,SAAgB,uBAAuB,SAAiB,IAAoB;CAC1E,OAAO,KAAK,yBAAyB,OAAO,GAAG,EAAE;AACnD;;;;;AAMA,SAAgB,yBAAyB,SAAyB;CAChE,OAAO,KAAK,QAAQ,OAAO,GAAG,UAAU,YAAY;AACtD;;AAGA,SAAgB,eAAe,OAAuB;CACpD,MAAM,OAAO,MAAM,QAAQ,oBAAoB,GAAG;CAClD,OAAO,KAAK,SAAS,IAAI,OAAO;AAClC;;AAGA,SAAgB,qBAAqB,UAA0B;CAC7D,OAAO,KAAK,UAAU,SAAS;AACjC;;AAGA,SAAgB,gBAAgB,SAAiB,cAAsB,QAAwB;CAC7F,OAAO,4BAA4B,iBAAiB,SAAS,YAAY,GAAG,MAAM;AACpF;;AAGA,SAAgB,4BAA4B,UAAkB,QAAwB;CACpF,OAAO,KAAK,qBAAqB,QAAQ,GAAG,GAAG,eAAe,MAAM,EAAE,cAAc;AACtF;;;;;;AAOA,SAAgB,qBAAqB,UAAkB,QAAwB;CAC7E,OAAO,KAAK,qBAAqB,QAAQ,GAAG,GAAG,eAAe,MAAM,EAAE,QAAQ;AAChF;;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AAO,MAAM,WAAW;AAE3D;AAEA,SAAS,yBACP,UACA,OACA,OACM;CACN,IAAI;EACF,UAAU,qBAAqB,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;EAC7D,eACE,qBAAqB,UAAU,KAAK,GACpC,GAAG,KAAK,UAAU;GAAE,qBAAI,IAAI,KAAK,EAAA,CAAE,YAAY;GAAG;GAAO,GAAG;EAAM,CAAC,EAAE,KACrE,MACF;CACF,QAAQ,CAER;AACF;AAEA,SAAS,qBAAqB,OAAiE;CAC7F,OACE,OAAO,MAAM,OAAO,YACpB,OAAO,MAAM,OAAO,YACpB,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,YAAY,YACzB,MAAM,QAAQ,KAAK,CAAC,CAAC,SAAS;AAElC"}
@@ -1,9 +1,10 @@
1
- import { E as SandboxClient, i as ExecCtx, k as Validator } from "./types-DZrBoBpN.js";
2
- import { I as Scope, Q as UsageEvent, U as Spend, d as ExecutorFactory, gn as ExecutorProgress, ln as TraceSource, m as ExecutorRegistry } from "./types-_7w24mMg.js";
3
- import { i as AgentEnvironmentProvider, o as AgentEnvironmentProviderRegistry, w as ProviderExecutorOptions } from "./environment-provider-BicwCDK5.js";
4
- import { AgentProfile, AgentProfileMcpServer, HarnessType, ReasoningEffort } from "@tangle-network/agent-interface";
1
+ import { E as SandboxClient, at as RuntimeStreamEvent, i as ExecCtx, k as Validator } from "./types-DeX8ibLc.js";
2
+ import { B as Scope, Cn as ExecutorProgress, _ as ExecutorRegistry, a as DefaultVerdict, g as ExecutorProgressEvent, gn as TraceSource, l as ExecutorCancellation, p as ExecutorFactory, q as Spend, rt as UsageEvent, u as ExecutorCancellationRequest, y as ExecutorToolCall } from "./types-BPQhQRrC.js";
3
+ import { i as AgentEnvironmentProvider, o as AgentEnvironmentProviderRegistry, w as ProviderExecutorOptions } from "./environment-provider-DJG0yIYl.js";
4
+ import { AgentProfile, AgentProfileMcpServer, HarnessType, ReasoningEffort, StreamEvent } from "@tangle-network/agent-interface";
5
5
  import { WorkspacePlanReceipt } from "@tangle-network/agent-profile-materialize";
6
6
  import { ChildProcess } from "node:child_process";
7
+ import { AgentRunOutcome } from "@tangle-network/sandbox/runtime";
7
8
  import { BackendType, SandboxEvent } from "@tangle-network/sandbox";
8
9
  //#region src/mcp/protocol.d.ts
9
10
  /**
@@ -320,6 +321,13 @@ interface RouterConfig extends RouterTransportConfig {
320
321
  * lives here rather than on one call site.
321
322
  */
322
323
  maxTokens?: number;
324
+ /**
325
+ * Optional ceiling on TOTAL completion tokens — visible answer plus hidden reasoning —
326
+ * forwarded as `max_completion_tokens`. Distinct from `maxTokens`: a reasoning model can spend
327
+ * an entire `max_tokens` budget on hidden thinking, so only this field bounds what the provider
328
+ * bills for one completion.
329
+ */
330
+ maxCompletionTokens?: number;
323
331
  /**
324
332
  * Take the tool-calling completion over SSE instead of one buffered POST. Off by default —
325
333
  * `routerChatWithTools` never streams, and every existing caller keeps the buffered transport
@@ -770,6 +778,212 @@ interface ResolvedMcpServerLaunch {
770
778
  */
771
779
  declare function resolveMcpServerLaunch(server: AgentProfileMcpServer, keys: KeyProvider | undefined, label: string): Promise<ResolvedMcpServerLaunch>;
772
780
  //#endregion
781
+ //#region src/runtime/sandbox-events.d.ts
782
+ /** The provider/model the platform reports it actually bound to a turn, when it reports one.
783
+ * `source` is the platform's own account of where that choice came from — `environment` means
784
+ * the platform chose, not the request. */
785
+ interface SandboxServedBackend {
786
+ readonly provider?: string;
787
+ readonly model?: string;
788
+ readonly source?: string;
789
+ }
790
+ /**
791
+ * Read the served execution identity off one Sandbox event.
792
+ *
793
+ * The platform reports `effectiveBackend` on `execution.started` and again on the terminal
794
+ * event (`@tangle-network/sandbox`, `EffectiveBackend`). Absence returns `undefined`
795
+ * and must stay unknown — a request is not a receipt, so nothing here may be inferred from
796
+ * what was asked for.
797
+ */
798
+ declare function sandboxEventServedBackend(event: SandboxEvent): SandboxServedBackend | undefined;
799
+ /**
800
+ * Fail the execution when the platform reports serving a model other than the exact one asked for.
801
+ *
802
+ * Measured motive (agent-runtime#892, live infrastructure 2026-08-17): 6 of 6 boxes whose profile
803
+ * declared `zai-coding-plan/glm-5.2` reported
804
+ * `{"provider":"openai-compat","model":"deepseek/deepseek-v4-flash","source":"environment"}`,
805
+ * while the materialization receipt recorded the declared model as `status: "known"`. Sending
806
+ * `backend.model` makes that substitution unlikely; only reading the report back makes it
807
+ * detectable. A run that cannot say which model produced its evidence must not settle as one
808
+ * that can.
809
+ *
810
+ * Silent when the platform reports no served model: unobserved stays unobserved.
811
+ */
812
+ declare function assertSandboxServedModel(event: SandboxEvent, expected: {
813
+ readonly provider?: string;
814
+ readonly model?: string;
815
+ } | undefined): void;
816
+ /**
817
+ * Extract a `RuntimeStreamEvent`-shaped `llm_call` from a sandbox event when
818
+ * the event carries usage/cost data. Returns `undefined` for non-cost events
819
+ * so the kernel can iterate the full stream without branching.
820
+ *
821
+ * Pure by contract: it never throws on a failed run. The terminal truth
822
+ * boundary is the public Sandbox outcome tracker, applied after the complete
823
+ * stream. Post-hoc readers — {@link sumSandboxUsage}, the
824
+ * analyst trace store, the chat projection — must stay able to read a failed
825
+ * turn's events, which is when reading them matters most.
826
+ *
827
+ * Canonical cost-carrying types observed in the wild:
828
+ * - `llm_call` — `data: { model, tokensIn, tokensOut, costUsd, ... }`
829
+ * - `message.completed` / `result` — `data: { usage: { inputTokens,
830
+ * outputTokens, totalCostUsd? } }`
831
+ * - `cost.usage` / `usage` — same shape under a dedicated type
832
+ *
833
+ * Numeric coercion is strict: `Number.isFinite` gates every accumulator write
834
+ * so a sentinel `NaN` from a misbehaving backend cannot poison the ledger.
835
+ */
836
+ declare function extractLlmCallEvent(event: SandboxEvent, agentRunName: string): (RuntimeStreamEvent & {
837
+ type: 'llm_call';
838
+ }) | undefined;
839
+ /**
840
+ * Sum the token usage + USD cost of a sandbox turn's events — the one honest way to meter an
841
+ * `openSandboxRun` cell. Folds `extractLlmCallEvent` over the stream (which reads usage off EVERY backend
842
+ * event shape), so a `runProfileMatrix` dispatch can report it to `ctx.cost`:
843
+ *
844
+ * receipt: (turn) => {
845
+ * const u = sumSandboxUsage(turn.events)
846
+ * return { model, inputTokens: u.input, outputTokens: u.output,
847
+ * ...(u.tokensKnown === false ? { usageUnknown: true } : {}),
848
+ * ...(u.usdKnown !== false && u.costUsd > 0 ? { actualCostUsd: u.costUsd } : {}),
849
+ * ...(u.usdKnown === false ? { costUnknown: true } : {}),
850
+ * ...(u.estimatedCostUsd !== undefined ? { estimatedCostUsd: u.estimatedCostUsd } : {}) }
851
+ * }
852
+ *
853
+ * Without this a cell reads `{tokens:0, cost:0}` and the backend-integrity guard correctly aborts the
854
+ * matrix as a stub. `agentRunName` is the fallback model label for cost-only events (default `'agent'`).
855
+ */
856
+ declare function sumSandboxUsage(events: readonly SandboxEvent[], agentRunName?: string): {
857
+ input: number;
858
+ output: number;
859
+ costUsd: number;
860
+ tokensKnown?: false;
861
+ usdKnown?: false;
862
+ estimatedCostUsd?: number;
863
+ };
864
+ /**
865
+ * Cross-event state for {@link mapSandboxToolEvent}. Sandbox backends emit a
866
+ * tool invocation as MANY `message.part.updated` frames on the same call id
867
+ * (pending → running → completed), so faithful projection needs per-call
868
+ * status memory: one `tool_call` on first sighting, at most one `tool_result`
869
+ * on the terminal transition, nothing on intermediate re-frames. Create one
870
+ * state per turn via {@link createSandboxToolPartState}.
871
+ *
872
+ * @experimental
873
+ */
874
+ interface SandboxToolPartState {
875
+ /** Last seen status per tool call id. A terminal status is sticky — later
876
+ * frames on a settled call project to nothing. */
877
+ statusByCall: Map<string, string>;
878
+ /** Sequence for synthesized call ids when an event carries none. */
879
+ seq: number;
880
+ }
881
+ /**
882
+ * Fresh per-turn {@link SandboxToolPartState} for {@link mapSandboxToolEvent} — an
883
+ * empty call-status map so each turn projects tool frames independently.
884
+ *
885
+ * @experimental
886
+ */
887
+ declare function createSandboxToolPartState(): SandboxToolPartState;
888
+ /**
889
+ * Project one `SandboxEvent` onto the `tool_call` / `tool_result` variants of
890
+ * `RuntimeStreamEvent` — the tool-part projection `mapSandboxEvent`
891
+ * deliberately does NOT perform. Opt-in and additive: `mapSandboxEvent`'s
892
+ * default vocabulary (text/reasoning deltas + `llm_call`) is unchanged;
893
+ * consumers that need the tool surface (chat UIs rendering tool activity)
894
+ * compose this projector alongside it — `streamAgentTurn` does exactly that
895
+ * under its `preserveToolParts` option.
896
+ *
897
+ * Handled shapes (observed on the opencode / claude-code sandbox backends):
898
+ * - `message.part.updated` with `part.type === 'tool'` — stateful: a
899
+ * `tool_call` on the call id's first frame (args from `state.input` or
900
+ * `state.metadata.input`), a `tool_result` when the status transitions to
901
+ * `completed` (result from `state.output` / `metadata.output`) or to a
902
+ * terminal failure (result is `{ error, status, output? }` — the error
903
+ * surfaced in-band, never dropped).
904
+ * - bare `tool*` event types (`tool.call`, `tool_result`, …) — stateless:
905
+ * `*result*` types project to `tool_result`, the rest to `tool_call`.
906
+ *
907
+ * Returns `[]` for every non-tool event.
908
+ *
909
+ * @experimental
910
+ */
911
+ declare function mapSandboxToolEvent(event: SandboxEvent, state: SandboxToolPartState): (RuntimeStreamEvent & {
912
+ type: 'tool_call' | 'tool_result';
913
+ })[];
914
+ /**
915
+ * Project one `SandboxEvent` onto the `RuntimeStreamEvent` chat-UX vocabulary,
916
+ * for runtimes that bridge a sandbox `streamPrompt` into the
917
+ * `AgentRuntime.act` streaming contract. Returns `undefined` for events that
918
+ * have no faithful projection — the raw stream is preserved separately for the
919
+ * `OutputAdapter`, so an unmapped event never loses data.
920
+ *
921
+ * Mapped (the task-optional incremental variants — no synthesized task
922
+ * lifecycle, no guessed tool-part shapes):
923
+ * - `message.part.updated` text part → `text_delta`
924
+ * - `message.part.updated` reasoning/thinking part → `reasoning_delta`
925
+ * - cost-bearing events → `llm_call` (shared with the ledger extractor)
926
+ *
927
+ * Tool parts are deliberately NOT mapped here (unchanged default) — compose
928
+ * {@link mapSandboxToolEvent} alongside when a consumer needs them.
929
+ *
930
+ * The opencode backend emits incremental text as
931
+ * `{ type: 'message.part.updated', data: { part: { type, text }, delta } }`;
932
+ * `delta` is the increment, `part.text` the running accumulation.
933
+ */
934
+ declare function mapSandboxEvent(event: SandboxEvent, opts?: {
935
+ agentRunName?: string;
936
+ }): RuntimeStreamEvent | undefined;
937
+ /**
938
+ * Project one `SandboxEvent` onto Runtime's executor progress vocabulary: incremental text and
939
+ * reasoning, tool calls and results, and an interaction request. It composes the existing
940
+ * projections ({@link mapSandboxEvent}, {@link mapSandboxToolEvent}, and the canonical Agent
941
+ * Interface decode) so every sandbox-shaped executor publishes live output through one reader.
942
+ * Usage-bearing events project to nothing here — accounting stays on the `tokens`/`cost`
943
+ * channels.
944
+ *
945
+ * Pass one {@link SandboxToolPartState} per turn so a multi-frame tool call yields one call and
946
+ * at most one result.
947
+ *
948
+ * @experimental
949
+ */
950
+ declare function sandboxProgressEvents(event: SandboxEvent, state: SandboxToolPartState): ExecutorProgressEvent[];
951
+ //#endregion
952
+ //#region src/runtime/sandbox-executor-output.d.ts
953
+ /**
954
+ * What a settled turn produced, as an explicit marker.
955
+ *
956
+ * `text` carries the byte length of the answer, `empty` says a text-bearing terminal event was
957
+ * observed and carried nothing, and `absent` says no text-bearing event was observed at all.
958
+ * The three are distinct on purpose: an empty settle blob used to be indistinguishable from lost
959
+ * output, so a reader could not tell a box that produced nothing from one whose answer never
960
+ * arrived.
961
+ */
962
+ type SandboxOutputMarker = {
963
+ readonly kind: 'text';
964
+ readonly bytes: number;
965
+ } | {
966
+ readonly kind: 'empty';
967
+ } | {
968
+ readonly kind: 'absent';
969
+ };
970
+ /** Parsed output of one Sandbox executor turn. */
971
+ interface SandboxLeafOut {
972
+ events: SandboxEvent[];
973
+ /** The observed answer. `undefined` when no text-bearing event was observed — never `''`. */
974
+ content: string | undefined;
975
+ /** Explicit account of what the turn produced. */
976
+ output: SandboxOutputMarker;
977
+ /**
978
+ * Provider and model the platform reported serving this turn, when it reported one. Absent means
979
+ * the platform said nothing; it is never filled from the request, because a request is not a
980
+ * receipt.
981
+ */
982
+ servedBackend?: SandboxServedBackend;
983
+ toolCalls?: ExecutorToolCall[];
984
+ outcome?: AgentRunOutcome;
985
+ }
986
+ //#endregion
773
987
  //#region src/runtime/supervise/inbox.d.ts
774
988
  /** A message from the run's AUTHORITY — the parent driver. These two kinds carry instruction. */
775
989
  interface AuthorityInboxMessage {
@@ -829,10 +1043,13 @@ interface SteerableSandboxSession {
829
1043
  /** Drive the worker to settlement. `signal` is the spawn-scoped abort handed to `execute`. */
830
1044
  stream(task: unknown, signal: AbortSignal): AsyncIterable<UsageEvent>;
831
1045
  progress(): ExecutorProgress;
1046
+ /** Ask the box to stop the running execution on this exact session and report what it answered. */
1047
+ cancel(request: ExecutorCancellationRequest): Promise<ExecutorCancellation>;
832
1048
  traceSource(): TraceSource;
833
1049
  artifact(): {
834
1050
  outRef: string;
835
1051
  out: unknown;
1052
+ verdict?: DefaultVerdict;
836
1053
  spent: Spend;
837
1054
  } | undefined;
838
1055
  teardown(): Promise<void>;
@@ -1109,11 +1326,6 @@ interface RouterToolsSeam {
1109
1326
  durationMs?: number;
1110
1327
  }) => void;
1111
1328
  }
1112
- /** Parsed output of the sandbox leaf: the iteration's raw event stream. What a
1113
- * `SandboxSeam.validator` receives as its `output` argument. */
1114
- interface SandboxLeafOut {
1115
- events: SandboxEvent[];
1116
- }
1117
1329
  /**
1118
1330
  * The leaf `createWorktreeCliExecutor` as a backend-as-data factory: a supervisor-authored
1119
1331
  * `AgentProfile` driving claude / codex / opencode on its own worktree. `budgetExempt` like
@@ -1161,5 +1373,5 @@ declare function createExecutor(config: ExecutorConfig): ExecutorFactory<unknown
1161
1373
  */
1162
1374
  declare function createExecutorRegistry(): ExecutorRegistry;
1163
1375
  //#endregion
1164
- export { WorktreeHandle as $, resolveSecretEnv as A, JsonRpcResponse as At, LOCAL_HARNESSES as B, PeerInboxMessage as C, PeerMailboxOptions as Ct, envKeyProvider as D, peerMailTools as Dt, ResolvedMcpServerLaunch as E, isPeerMailEnvelope as Et, WorktreeProfileMaterializationReceipt as F, localHarnessExecutable as G, LocalHarnessResult as H, CodexExecutionEvidence as I, CreateWorktreeOptions as J, parseCodexTokenUsage as K, CodexExecutionPolicy as L, WorktreeCheckRunner as M, McpTransport as Mt, WorktreeCommandResult as N, mcpSecretEnvMetadataKey as O, peerMailVerbNames as Ot, WorktreeHarnessResult as P, RemoveWorktreeOptions as Q, CodexTokenUsage as R, InboxMessage as S, PeerMailbox as St, KeyProvider as T, createPeerMailbox as Tt, RunLocalHarnessOptions as U, LocalHarness as V, harnessSupportsReasoningEffort as W, DiffResult as X, DiffOptions as Y, GitRunner as Z, SteerableSandboxArgs as _, PeerMailLimits as _t, CliWorktreeSeam as a, ToolLoopCallContext as at, AuthorityInboxMessage as b, PeerMailRefusal as bt, RouterSeam as c, ToolLoopCompactionOptions as ct, SandboxSeam as d, AUTHORITY_MARKERS as dt, captureWorktreeDiff as et, cliWorktreeExecutor as f, DEFAULT_PEER_MAIL_LIMITS as ft, SandboxSteeringOptions as g, PeerMailKind as gt, DEFAULT_SANDBOX_STEERING_MAX_TURNS as h, PeerMailEvent as ht, CliWorktreeBridgeSeam as i, ToolSpec as it, secretEnvOfMcpServer as j, McpToolDescriptor as jt, resolveMcpServerLaunch as k, JsonRpcMessage as kt, RouterToolsSeam as l, ToolLoopMessageRecord as lt, createExecutorRegistry as m, PeerMailEnvelope as mt, BridgeSeam as n, removeWorktree as nt, ExecutorConfig as o, ToolLoopChat as ot, createExecutor as p, PEER_MAIL_WIRE_KEY as pt, runLocalHarness as q, CliSeam as r, RouterTransportConfig as rt, ProviderSeam as s, ToolLoopCompaction as st, BridgeModelCredential as t, createWorktree as tt, SandboxLeafOut as u, ToolLoopToolCall as ut, SteerableSandboxSession as v, PeerMailOutcome as vt, createInbox as w, claimsAuthority as wt, Inbox as x, PeerMailSendInput as xt, createSteerableSandboxSession as y, PeerMailReadout as yt, DEFAULT_LOCAL_HARNESS as z };
1165
- //# sourceMappingURL=runtime-htqI3fKL.d.ts.map
1376
+ export { LocalHarnessResult as $, extractLlmCallEvent as A, PeerMailReadout as At, resolveMcpServerLaunch as B, JsonRpcMessage as Bt, createInbox as C, DEFAULT_PEER_MAIL_LIMITS as Ct, SandboxToolPartState as D, PeerMailKind as Dt, SandboxServedBackend as E, PeerMailEvent as Et, sumSandboxUsage as F, claimsAuthority as Ft, WorktreeHarnessResult as G, secretEnvOfMcpServer as H, McpToolDescriptor as Ht, KeyProvider as I, createPeerMailbox as It, CodexExecutionPolicy as J, WorktreeProfileMaterializationReceipt as K, ResolvedMcpServerLaunch as L, isPeerMailEnvelope as Lt, mapSandboxToolEvent as M, PeerMailSendInput as Mt, sandboxEventServedBackend as N, PeerMailbox as Nt, assertSandboxServedModel as O, PeerMailLimits as Ot, sandboxProgressEvents as P, PeerMailboxOptions as Pt, LocalHarness as Q, envKeyProvider as R, peerMailTools as Rt, PeerInboxMessage as S, AUTHORITY_MARKERS as St, SandboxOutputMarker as T, PeerMailEnvelope as Tt, WorktreeCheckRunner as U, McpTransport as Ut, resolveSecretEnv as V, JsonRpcResponse as Vt, WorktreeCommandResult as W, DEFAULT_LOCAL_HARNESS as X, CodexTokenUsage as Y, LOCAL_HARNESSES as Z, SteerableSandboxSession as _, ToolLoopChat as _t, CliWorktreeSeam as a, CreateWorktreeOptions as at, Inbox as b, ToolLoopMessageRecord as bt, RouterSeam as c, GitRunner as ct, cliWorktreeExecutor as d, captureWorktreeDiff as dt, RunLocalHarnessOptions as et, createExecutor as f, createWorktree as ft, SteerableSandboxArgs as g, ToolLoopCallContext as gt, SandboxSteeringOptions as h, ToolSpec as ht, CliWorktreeBridgeSeam as i, runLocalHarness as it, mapSandboxEvent as j, PeerMailRefusal as jt, createSandboxToolPartState as k, PeerMailOutcome as kt, RouterToolsSeam as l, RemoveWorktreeOptions as lt, DEFAULT_SANDBOX_STEERING_MAX_TURNS as m, RouterTransportConfig as mt, BridgeSeam as n, localHarnessExecutable as nt, ExecutorConfig as o, DiffOptions as ot, createExecutorRegistry as p, removeWorktree as pt, CodexExecutionEvidence as q, CliSeam as r, parseCodexTokenUsage as rt, ProviderSeam as s, DiffResult as st, BridgeModelCredential as t, harnessSupportsReasoningEffort as tt, SandboxSeam as u, WorktreeHandle as ut, createSteerableSandboxSession as v, ToolLoopCompaction as vt, SandboxLeafOut as w, PEER_MAIL_WIRE_KEY as wt, InboxMessage as x, ToolLoopToolCall as xt, AuthorityInboxMessage as y, ToolLoopCompactionOptions as yt, mcpSecretEnvMetadataKey as z, peerMailVerbNames as zt };
1377
+ //# sourceMappingURL=runtime-B-5dp5Iz.d.ts.map