@tangle-network/agent-runtime 0.104.0 → 0.106.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +176 -42
  2. package/dist/activation-CRjVfOiy.js +203 -0
  3. package/dist/activation-CRjVfOiy.js.map +1 -0
  4. package/dist/activation-DyWB0K6E.d.ts +98 -0
  5. package/dist/agent.d.ts +216 -234
  6. package/dist/agent.js +615 -547
  7. package/dist/agent.js.map +1 -1
  8. package/dist/analyst-loop-DGdtVENg.js +517 -0
  9. package/dist/analyst-loop-DGdtVENg.js.map +1 -0
  10. package/dist/analyst-loop.d.ts +10 -43
  11. package/dist/analyst-loop.js +2 -11
  12. package/dist/backends-Dy8NujB4.js +713 -0
  13. package/dist/backends-Dy8NujB4.js.map +1 -0
  14. package/dist/candidate-execution/index.d.ts +4 -192
  15. package/dist/candidate-execution/index.js +5 -66
  16. package/dist/candidate-execution-DqMbv1rU.js +488 -0
  17. package/dist/candidate-execution-DqMbv1rU.js.map +1 -0
  18. package/dist/coder-yhVWbdWc.js +40 -0
  19. package/dist/coder-yhVWbdWc.js.map +1 -0
  20. package/dist/conversation-XucG_K3l.js +1265 -0
  21. package/dist/conversation-XucG_K3l.js.map +1 -0
  22. package/dist/conversation.d.ts +2 -804
  23. package/dist/conversation.js +2 -55
  24. package/dist/environment-provider-CfLUmKmf.js +1168 -0
  25. package/dist/environment-provider-CfLUmKmf.js.map +1 -0
  26. package/dist/environment-provider-IUGU3epE.d.ts +964 -0
  27. package/dist/environment-provider.d.ts +2 -78
  28. package/dist/environment-provider.js +2 -18
  29. package/dist/errors-DEAvWQPy.js +111 -0
  30. package/dist/errors-DEAvWQPy.js.map +1 -0
  31. package/dist/improvement-adapter-Cr5TBSji.d.ts +166 -0
  32. package/dist/improvement-cycle-C095kS_g.js +2624 -0
  33. package/dist/improvement-cycle-C095kS_g.js.map +1 -0
  34. package/dist/index-BGdxAwfO.d.ts +838 -0
  35. package/dist/index-C-FYUuFG.d.ts +193 -0
  36. package/dist/index-CbNM40xG.d.ts +140 -0
  37. package/dist/index-DruSKs3Z.d.ts +7224 -0
  38. package/dist/index-Efjb3nrQ.d.ts +671 -0
  39. package/dist/index.d.ts +14 -1134
  40. package/dist/index.js +2134 -1972
  41. package/dist/index.js.map +1 -1
  42. package/dist/intelligence.d.ts +776 -888
  43. package/dist/intelligence.js +1466 -1410
  44. package/dist/intelligence.js.map +1 -1
  45. package/dist/{kb-gate-CwHO0vz6.d.ts → kb-gate-C8z2juK8.d.ts} +33 -31
  46. package/dist/kb-gate-DpaSwXVx.js +80 -0
  47. package/dist/kb-gate-DpaSwXVx.js.map +1 -0
  48. package/dist/knowledge-Ku-mPP4f.js +433 -0
  49. package/dist/knowledge-Ku-mPP4f.js.map +1 -0
  50. package/dist/knowledge.d.ts +2 -150
  51. package/dist/knowledge.js +2 -40
  52. package/dist/local-harness-Dh8PJ0ot.d.ts +455 -0
  53. package/dist/loop-runner-bin-BXsFEUcf.d.ts +162 -0
  54. package/dist/loop-runner-bin-BwjQ1NfH.js +268 -0
  55. package/dist/loop-runner-bin-BwjQ1NfH.js.map +1 -0
  56. package/dist/loop-runner-bin.d.ts +2 -17
  57. package/dist/loop-runner-bin.js +2 -24
  58. package/dist/loops.d.ts +5 -4164
  59. package/dist/loops.js +8 -419
  60. package/dist/mcp/bin.d.ts +1 -1
  61. package/dist/mcp/bin.js +116 -146
  62. package/dist/mcp/bin.js.map +1 -1
  63. package/dist/mcp/index.d.ts +295 -437
  64. package/dist/mcp/index.js +1242 -1177
  65. package/dist/mcp/index.js.map +1 -1
  66. package/dist/mcp/memory-bin.d.ts +1 -1
  67. package/dist/mcp/memory-bin.js +37 -16
  68. package/dist/mcp/memory-bin.js.map +1 -1
  69. package/dist/memory-server-DL6cE2Ag.js +234 -0
  70. package/dist/memory-server-DL6cE2Ag.js.map +1 -0
  71. package/dist/model-resolution-Btd9iIKV.js +98 -0
  72. package/dist/model-resolution-Btd9iIKV.js.map +1 -0
  73. package/dist/openai-tools-B68JaOCx.d.ts +24 -0
  74. package/dist/openai-tools-CKLy1C7M.js +44 -0
  75. package/dist/openai-tools-CKLy1C7M.js.map +1 -0
  76. package/dist/otel-export-D34IQW1C.js +843 -0
  77. package/dist/otel-export-D34IQW1C.js.map +1 -0
  78. package/dist/platform.d.ts +188 -185
  79. package/dist/platform.js +185 -218
  80. package/dist/platform.js.map +1 -1
  81. package/dist/prepare-B53sPV7M.js +4292 -0
  82. package/dist/prepare-B53sPV7M.js.map +1 -0
  83. package/dist/primeintellect/index.d.ts +150 -147
  84. package/dist/primeintellect/index.js +626 -1004
  85. package/dist/primeintellect/index.js.map +1 -1
  86. package/dist/profiles.d.ts +296 -490
  87. package/dist/profiles.js +722 -749
  88. package/dist/profiles.js.map +1 -1
  89. package/dist/protected-model-port-BLPH5VVv.js +722 -0
  90. package/dist/protected-model-port-BLPH5VVv.js.map +1 -0
  91. package/dist/protected-model-port-BP6Z4eau.d.ts +283 -0
  92. package/dist/protected-redaction--F3v1oo8.js +200 -0
  93. package/dist/protected-redaction--F3v1oo8.js.map +1 -0
  94. package/dist/redact-D-u-rrcn.js +82 -0
  95. package/dist/redact-D-u-rrcn.js.map +1 -0
  96. package/dist/redact-kbIOjfjM.d.ts +452 -0
  97. package/dist/researcher-CoVqNhfI.js +433 -0
  98. package/dist/researcher-CoVqNhfI.js.map +1 -0
  99. package/dist/runtime-BG0BziaP.js +5408 -0
  100. package/dist/runtime-BG0BziaP.js.map +1 -0
  101. package/dist/sandbox-events-DeI5xX8P.js +316 -0
  102. package/dist/sandbox-events-DeI5xX8P.js.map +1 -0
  103. package/dist/spawn-journal-CwPvKUTa.js +456 -0
  104. package/dist/spawn-journal-CwPvKUTa.js.map +1 -0
  105. package/dist/structural-rollout-IXUEplky.js +1445 -0
  106. package/dist/structural-rollout-IXUEplky.js.map +1 -0
  107. package/dist/substrate-B0TYNrXn.js +27 -0
  108. package/dist/substrate-B0TYNrXn.js.map +1 -0
  109. package/dist/{substrate-Dyiqmd3o.d.ts → substrate-BcnuSHXm.d.ts} +57 -54
  110. package/dist/supervise-BiRutHS9.js +7321 -0
  111. package/dist/supervise-BiRutHS9.js.map +1 -0
  112. package/dist/supervisor-DTKhF-RV.js +3826 -0
  113. package/dist/supervisor-DTKhF-RV.js.map +1 -0
  114. package/dist/testing.d.ts +4 -3
  115. package/dist/testing.js +2478 -2637
  116. package/dist/testing.js.map +1 -1
  117. package/dist/tool-server-RcWgLIsL.js +141 -0
  118. package/dist/tool-server-RcWgLIsL.js.map +1 -0
  119. package/dist/trace-propagation-CJJC7SVB.js +57 -0
  120. package/dist/trace-propagation-CJJC7SVB.js.map +1 -0
  121. package/dist/types-BaIpb0XT.d.ts +492 -0
  122. package/dist/types-BevOjfTY.d.ts +765 -0
  123. package/dist/types-C9j4qg6l.d.ts +500 -0
  124. package/dist/types-Cja5OTGh.d.ts +190 -0
  125. package/dist/util-MVgdwuIS.js +145 -0
  126. package/dist/util-MVgdwuIS.js.map +1 -0
  127. package/dist/workspace-archive-BosQiotA.js +575 -0
  128. package/dist/workspace-archive-BosQiotA.js.map +1 -0
  129. package/package.json +43 -55
  130. package/skills/build-with-agent-runtime/SKILL.md +16 -9
  131. package/skills/loop-writer/SKILL.md +1 -1
  132. package/dist/activation-Cm-9MMX1.d.ts +0 -69
  133. package/dist/analyst-loop.js.map +0 -1
  134. package/dist/backends-BO4Jqoe2.d.ts +0 -134
  135. package/dist/candidate-execution/index.js.map +0 -1
  136. package/dist/chunk-2KGAN2HM.js +0 -1256
  137. package/dist/chunk-2KGAN2HM.js.map +0 -1
  138. package/dist/chunk-2QJSNOGK.js +0 -48
  139. package/dist/chunk-2QJSNOGK.js.map +0 -1
  140. package/dist/chunk-2UABGGUB.js +0 -474
  141. package/dist/chunk-2UABGGUB.js.map +0 -1
  142. package/dist/chunk-2VZYRB55.js +0 -834
  143. package/dist/chunk-2VZYRB55.js.map +0 -1
  144. package/dist/chunk-2X65HYMI.js +0 -3526
  145. package/dist/chunk-2X65HYMI.js.map +0 -1
  146. package/dist/chunk-3MDZX7YU.js +0 -125
  147. package/dist/chunk-3MDZX7YU.js.map +0 -1
  148. package/dist/chunk-3PPVCS75.js +0 -199
  149. package/dist/chunk-3PPVCS75.js.map +0 -1
  150. package/dist/chunk-5HNDYWUT.js +0 -6424
  151. package/dist/chunk-5HNDYWUT.js.map +0 -1
  152. package/dist/chunk-5IBQAPVB.js +0 -29
  153. package/dist/chunk-5IBQAPVB.js.map +0 -1
  154. package/dist/chunk-5QOB7H74.js +0 -387
  155. package/dist/chunk-5QOB7H74.js.map +0 -1
  156. package/dist/chunk-ATDFUJYI.js +0 -4728
  157. package/dist/chunk-ATDFUJYI.js.map +0 -1
  158. package/dist/chunk-B7K7V22Y.js +0 -699
  159. package/dist/chunk-B7K7V22Y.js.map +0 -1
  160. package/dist/chunk-DPEUKJRO.js +0 -27
  161. package/dist/chunk-DPEUKJRO.js.map +0 -1
  162. package/dist/chunk-FD2MBMOH.js +0 -494
  163. package/dist/chunk-FD2MBMOH.js.map +0 -1
  164. package/dist/chunk-FJI3EXU3.js +0 -2402
  165. package/dist/chunk-FJI3EXU3.js.map +0 -1
  166. package/dist/chunk-HAO4CXHP.js +0 -200
  167. package/dist/chunk-HAO4CXHP.js.map +0 -1
  168. package/dist/chunk-ISPWRSEC.js +0 -408
  169. package/dist/chunk-ISPWRSEC.js.map +0 -1
  170. package/dist/chunk-KRBFHMV6.js +0 -1228
  171. package/dist/chunk-KRBFHMV6.js.map +0 -1
  172. package/dist/chunk-L5DST3QC.js +0 -351
  173. package/dist/chunk-L5DST3QC.js.map +0 -1
  174. package/dist/chunk-M22PL4GH.js +0 -171
  175. package/dist/chunk-M22PL4GH.js.map +0 -1
  176. package/dist/chunk-NURIQBJQ.js +0 -72
  177. package/dist/chunk-NURIQBJQ.js.map +0 -1
  178. package/dist/chunk-PZZKQVQV.js +0 -52
  179. package/dist/chunk-PZZKQVQV.js.map +0 -1
  180. package/dist/chunk-Q2JSAVQ3.js +0 -671
  181. package/dist/chunk-Q2JSAVQ3.js.map +0 -1
  182. package/dist/chunk-SBTWKPVR.js +0 -5576
  183. package/dist/chunk-SBTWKPVR.js.map +0 -1
  184. package/dist/chunk-SGKPNBXE.js +0 -60
  185. package/dist/chunk-SGKPNBXE.js.map +0 -1
  186. package/dist/chunk-SNSMRT6H.js +0 -680
  187. package/dist/chunk-SNSMRT6H.js.map +0 -1
  188. package/dist/chunk-STJEHM5F.js +0 -1338
  189. package/dist/chunk-STJEHM5F.js.map +0 -1
  190. package/dist/chunk-UPWGXKXB.js +0 -254
  191. package/dist/chunk-UPWGXKXB.js.map +0 -1
  192. package/dist/chunk-YEJR7IXO.js +0 -68
  193. package/dist/chunk-YEJR7IXO.js.map +0 -1
  194. package/dist/chunk-ZXICDSAK.js +0 -907
  195. package/dist/chunk-ZXICDSAK.js.map +0 -1
  196. package/dist/completion-gate-Bv47cOnn.d.ts +0 -256
  197. package/dist/conversation.js.map +0 -1
  198. package/dist/coordination-CxtzMxSM.d.ts +0 -2570
  199. package/dist/environment-provider.js.map +0 -1
  200. package/dist/improve--2A0gK1-.d.ts +0 -440
  201. package/dist/improvement-adapter-HAZz-7vK.d.ts +0 -203
  202. package/dist/knowledge.js.map +0 -1
  203. package/dist/local-harness-CtK9dSny.d.ts +0 -175
  204. package/dist/loop-runner-bin-DUOGtvOl.d.ts +0 -207
  205. package/dist/loop-runner-bin.js.map +0 -1
  206. package/dist/loops.js.map +0 -1
  207. package/dist/openai-tools-fnj6SRVg.d.ts +0 -46
  208. package/dist/protected-model-port-DzkUY3HQ.d.ts +0 -271
  209. package/dist/sanitize-DEbPNtyI.d.ts +0 -328
  210. package/dist/structural-rollout-C4mabf87.d.ts +0 -446
  211. package/dist/supervise-7q9F5brx.d.ts +0 -379
  212. package/dist/types-BCoemcXU.d.ts +0 -802
  213. package/dist/types-BwoZWq-i.d.ts +0 -510
  214. package/dist/types-Cbp72qyu.d.ts +0 -491
  215. package/dist/types-CmYCMbFT.d.ts +0 -203
  216. package/dist/types-CvNwMzQt.d.ts +0 -957
  217. package/dist/worktree-fanout-WsOzt8qu.d.ts +0 -999
@@ -0,0 +1,765 @@
1
+ import { u as AgentTaskSpec, x as RuntimeStreamEvent } from "./types-C9j4qg6l.js";
2
+ import { DefaultVerdict } from "@tangle-network/agent-eval";
3
+ import { AgentProfile as AgentProfile$1 } from "@tangle-network/agent-interface";
4
+ import { CreateSandboxOptions, SandboxEvent, SandboxInstance } from "@tangle-network/sandbox";
5
+ //#region src/runtime-hooks.d.ts
6
+ /**
7
+ *
8
+ * Runtime hook contracts. Hooks are execution-scoped observers, not part of an
9
+ * `AgentProfile`: profiles stay portable agent recipes; hooks attach to the
10
+ * loop or product harness that is running the profile.
11
+ *
12
+ * @experimental
13
+ */
14
+ type RuntimeHookPhase = 'before' | 'after' | 'error' | 'event';
15
+ type RuntimeHookTarget = 'agent.run' | 'agent.turn' | 'agent.tool_call' | 'agent.spawn' | 'agent.child' | 'agent.plan' | 'agent.decision' | (string & {});
16
+ type RuntimeDecisionKind = 'continue' | 'verify' | 'ask' | 'retry' | 'stop' | 'memory-write' | 'memory-read' | 'tool-select' | 'skill-select' | 'workflow-select' | 'surface-promote' | (string & {});
17
+ interface RuntimeHookEvent<Payload = unknown> {
18
+ id: string;
19
+ runId: string;
20
+ scenarioId?: string;
21
+ target: RuntimeHookTarget;
22
+ phase: RuntimeHookPhase;
23
+ timestamp: number;
24
+ stepIndex?: number;
25
+ parentId?: string;
26
+ payload?: Payload;
27
+ metadata?: Record<string, unknown>;
28
+ }
29
+ interface RuntimeHookContext {
30
+ signal?: AbortSignal;
31
+ }
32
+ interface RuntimeDecisionEvidenceRef {
33
+ source: string;
34
+ id: string;
35
+ detail?: string;
36
+ metadata?: Record<string, unknown>;
37
+ }
38
+ interface RuntimeDecisionPoint {
39
+ id: string;
40
+ runId: string;
41
+ scenarioId?: string;
42
+ stepIndex: number;
43
+ kind: RuntimeDecisionKind;
44
+ candidateActions: string[];
45
+ context?: string;
46
+ evidence: RuntimeDecisionEvidenceRef[];
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ interface RuntimeHookErrorContext {
50
+ hook: 'onEvent' | 'onDecisionPoint';
51
+ eventId?: string;
52
+ target?: RuntimeHookTarget;
53
+ phase?: RuntimeHookPhase;
54
+ decisionId?: string;
55
+ decisionKind?: RuntimeDecisionKind;
56
+ }
57
+ /**
58
+ * The observation seam attached to a running loop (never to the portable genome).
59
+ * Implement the optional hooks to receive lifecycle events, semantic decision points,
60
+ * and hook errors. Author with {@link defineRuntimeHooks} for inference, and attach N
61
+ * observers at once with {@link composeRuntimeHooks} — there is ONE event stream, not a
62
+ * callback-prop zoo.
63
+ */
64
+ interface RuntimeHooks {
65
+ /**
66
+ * General before/after/event hook. Use this for telemetry, memory capture,
67
+ * policy wrapping, child lifecycle observers, or product-specific extension
68
+ * points.
69
+ */
70
+ onEvent?: (event: RuntimeHookEvent, context: RuntimeHookContext) => void | Promise<void>;
71
+ /**
72
+ * Semantic decision hook. Belief-state evaluation consumes this, but runtime
73
+ * code should keep emitting ordinary lifecycle events as the base layer.
74
+ */
75
+ onDecisionPoint?: (point: RuntimeDecisionPoint, context: RuntimeHookContext) => void | Promise<void>;
76
+ onHookError?: (error: Error, context: RuntimeHookErrorContext) => void | Promise<void>;
77
+ }
78
+ /** Identity helper that types a {@link RuntimeHooks} literal so the fields are inferred. */
79
+ declare function defineRuntimeHooks(hooks: RuntimeHooks): RuntimeHooks;
80
+ /**
81
+ * Merge several {@link RuntimeHooks} into one. Falsy entries are dropped (so you can
82
+ * pass `flag && hooks`), and every observer's `onEvent`/`onDecisionPoint` fires for each
83
+ * event. Use this to attach N observers to a loop instead of a second event bus.
84
+ */
85
+ declare function composeRuntimeHooks(...entries: Array<RuntimeHooks | undefined | null | false>): RuntimeHooks;
86
+ /** Fire `hooks.onEvent`, swallowing sync throws and surfacing async failures to `onError`. */
87
+ declare function notifyRuntimeHookEvent(hooks: RuntimeHooks | undefined, event: RuntimeHookEvent, context?: RuntimeHookContext): void;
88
+ /** Fire `hooks.onDecisionPoint`, swallowing sync throws and surfacing async failures to `onError`. */
89
+ declare function notifyRuntimeDecisionPoint(hooks: RuntimeHooks | undefined, point: RuntimeDecisionPoint, context?: RuntimeHookContext): void;
90
+ //#endregion
91
+ //#region src/runtime-run.d.ts
92
+ /** @stable */
93
+ type RuntimeRunStatus = 'running' | 'completed' | 'failed' | 'cancelled';
94
+ /** @stable */
95
+ interface RuntimeRunCost {
96
+ /** Cumulative input tokens across every observed `llm_call` event. */
97
+ tokensIn: number;
98
+ /** Cumulative output tokens across every observed `llm_call` event. */
99
+ tokensOut: number;
100
+ /** Sum of `costUsd` from every observed `llm_call` event. */
101
+ costUsd: number;
102
+ /** Wall time from `startRuntimeRun()` to `complete()` (or `now()` if not yet completed). */
103
+ wallMs: number;
104
+ /** Count of `llm_call` events observed during the run. */
105
+ llmCalls: number;
106
+ }
107
+ /** @stable */
108
+ interface RuntimeRunCompleteInput {
109
+ status: Exclude<RuntimeRunStatus, 'running'>;
110
+ resultSummary?: string;
111
+ /** Optional explicit cost override; if omitted, the accumulated ledger is used. */
112
+ cost?: Partial<RuntimeRunCost>;
113
+ /** Stable error message when `status === 'failed'`. */
114
+ error?: string;
115
+ /** Additional adapter-specific fields merged into the persisted row. */
116
+ metadata?: Record<string, unknown>;
117
+ }
118
+ /** @stable */
119
+ interface RuntimeRunRow {
120
+ /** Stable runtime-side identifier. Adapters may translate to their own primary key. */
121
+ id: string;
122
+ workspaceId: string;
123
+ sessionId?: string;
124
+ agentId?: string;
125
+ domain?: string;
126
+ taskId: string;
127
+ scenarioId?: string;
128
+ status: RuntimeRunStatus;
129
+ resultSummary?: string;
130
+ error?: string;
131
+ cost: RuntimeRunCost;
132
+ startedAt: string;
133
+ completedAt?: string;
134
+ metadata?: Record<string, unknown>;
135
+ }
136
+ /** @stable */
137
+ interface RuntimeRunPersistenceAdapter {
138
+ /**
139
+ * Called once when `handle.persist()` runs. Implementations write `row` to
140
+ * their durable store (D1, postgres, KV) and return whatever the consumer
141
+ * wants the caller to see (often the storage-side row id). Errors thrown
142
+ * here propagate out of `persist()` so the caller can decide whether to
143
+ * retry or log-and-continue.
144
+ */
145
+ upsert(row: RuntimeRunRow): Promise<void> | void;
146
+ }
147
+ /** @stable */
148
+ interface RuntimeRunOptions {
149
+ workspaceId: string;
150
+ sessionId?: string;
151
+ agentId?: string;
152
+ taskSpec: AgentTaskSpec;
153
+ scenarioId?: string;
154
+ /** Optional persistence adapter; if omitted, `persist()` is a no-op. */
155
+ adapter?: RuntimeRunPersistenceAdapter;
156
+ /** Override the row id; default = `${taskSpec.id}:${random suffix}`. */
157
+ id?: string;
158
+ /** Override the clock; default = `Date.now()`. Useful for deterministic tests. */
159
+ now?: () => number;
160
+ }
161
+ /** @stable */
162
+ interface RuntimeRunHandle {
163
+ /** Stable id assigned at start. */
164
+ readonly id: string;
165
+ readonly workspaceId: string;
166
+ readonly sessionId: string | undefined;
167
+ readonly taskSpec: AgentTaskSpec;
168
+ readonly status: RuntimeRunStatus;
169
+ /**
170
+ * Observe a single `RuntimeStreamEvent`. The handle ignores non-cost events
171
+ * (text deltas, tool calls) silently so consumers can pipe the whole stream
172
+ * through `handle.observe`. `llm_call` events update the ledger.
173
+ */
174
+ observe(event: RuntimeStreamEvent): void;
175
+ /** Snapshot of the current cost ledger. Safe to call at any time. */
176
+ cost(): RuntimeRunCost;
177
+ /**
178
+ * Transition to a terminal state. Idempotent for the same status; throws
179
+ * `RuntimeRunStateError` for a different terminal status (state machines
180
+ * don't time-travel).
181
+ */
182
+ complete(input: RuntimeRunCompleteInput): void;
183
+ /** Build the current row without writing it. Useful for tests + dry runs. */
184
+ toRow(metadata?: Record<string, unknown>): RuntimeRunRow;
185
+ /**
186
+ * Persist the current row via the configured adapter. Must be called after
187
+ * `complete()`. Idempotent for the same terminal state (the adapter sees
188
+ * the same row on retry).
189
+ */
190
+ persist(metadata?: Record<string, unknown>): Promise<void>;
191
+ }
192
+ /**
193
+ *
194
+ * Construct a runtime-run handle. The returned handle is mutable across its
195
+ * lifetime; consumers should not share it across requests.
196
+ *
197
+ * @stable
198
+ */
199
+ declare function startRuntimeRun(options: RuntimeRunOptions): RuntimeRunHandle;
200
+ //#endregion
201
+ //#region src/runtime/types.d.ts
202
+ /** @experimental */
203
+ interface ValidationCtx {
204
+ /** Iteration index this output came from (0-based). */
205
+ iteration: number;
206
+ /**
207
+ * Live sandbox for this iteration. Validators that need execution-grounded
208
+ * evidence can inspect files or run commands here instead of forcing callers
209
+ * to bypass the loop kernel with raw Sandbox SDK orchestration.
210
+ */
211
+ box?: SandboxInstance;
212
+ /** Cooperative cancellation channel. */
213
+ signal: AbortSignal;
214
+ /**
215
+ * Optional trace emitter. When set, validator implementations that make
216
+ * LLM calls (e.g. an LLM-judge reviewer) emit spans into it.
217
+ * The kernel passes `ctx.traceEmitter` from `ExecCtx` when available.
218
+ */
219
+ traceEmitter?: LoopTraceEmitter;
220
+ }
221
+ /** @experimental */
222
+ interface Validator<Output, Verdict = DefaultVerdict> {
223
+ validate(output: Output, ctx: ValidationCtx): Promise<Verdict>;
224
+ }
225
+ /**
226
+ * Sandbox-SDK-shaped agent specification.
227
+ *
228
+ * The kernel uses `profile` to instantiate a sandbox per iteration, formats
229
+ * `task` into a prompt via `taskToPrompt`, and merges `sandboxOverrides` into
230
+ * the `CreateSandboxOptions` it passes to `client.create`. Heterogeneous
231
+ * fanout supplies multiple `AgentRunSpec`s and the kernel round-robins
232
+ * through them when the driver plans N tasks.
233
+ *
234
+ * @experimental
235
+ */
236
+ interface AgentRunSpec<Task> {
237
+ /** Sandbox SDK profile — what kind of agent runs the task. */
238
+ profile: AgentProfile$1;
239
+ /** Task → prompt formatter. Pure and deterministic. */
240
+ taskToPrompt: (task: Task) => string;
241
+ /**
242
+ * Optional pre-prompt sandbox provisioner. Runs after the sandbox is acquired
243
+ * and before the first prompt is streamed into that box. Use this for
244
+ * domain-agnostic setup such as repo snapshots, benchmark fixtures, policy
245
+ * files, or seed datasets. The hook is part of the runtime surface so loop
246
+ * consumers do not hand-roll Sandbox SDK orchestration just to prepare a
247
+ * workspace before the agent sees it.
248
+ *
249
+ * `ctx.recordMount` records what was placed into the box so the run carries a
250
+ * provenance manifest (`LoopResult.provenance.mounts`). It is optional and
251
+ * provenance-only — the kernel never reads box contents and attaches no
252
+ * meaning to the entries; not calling it simply leaves the manifest empty.
253
+ */
254
+ prepareBox?: (box: SandboxInstance, ctx: {
255
+ signal: AbortSignal;
256
+ recordMount: MountRecorder;
257
+ }) => Promise<void> | void;
258
+ /**
259
+ * Per-spec stable name. Surfaced in trace events and the default winner
260
+ * selector tiebreak. Falls back to `profile.name ?? 'agent'`.
261
+ */
262
+ name?: string;
263
+ /**
264
+ * Optional sandbox-SDK `CreateSandboxOptions` overrides merged on top of
265
+ * the kernel's defaults. `backend.profile` is set to `profile` by the
266
+ * kernel and cannot be overridden here — use `profile` itself for that.
267
+ */
268
+ sandboxOverrides?: Partial<Omit<CreateSandboxOptions, 'backend'>> & {
269
+ backend?: Omit<NonNullable<CreateSandboxOptions['backend']>, 'profile'>;
270
+ };
271
+ }
272
+ /**
273
+ * Stream of `SandboxEvent`s → typed `Output`.
274
+ *
275
+ * Adapters are pure functions over the already-collected event array; they
276
+ * do not receive the live AsyncIterable so they can be replayed against
277
+ * persisted streams during tests / replays.
278
+ *
279
+ * @experimental
280
+ */
281
+ interface OutputAdapter<Output> {
282
+ parse(events: SandboxEvent[]): Output;
283
+ }
284
+ /** LLM token usage. Structurally maps into agent-eval's paid-call receipt so a
285
+ * campaign dispatch settles real usage instead of appearing as a stub. */
286
+ interface LoopTokenUsage {
287
+ input: number;
288
+ output: number;
289
+ }
290
+ /**
291
+ * One mounted resource recorded during box preparation — a pure provenance
292
+ * record of what the caller placed into a box before the agent saw it. The
293
+ * kernel never reads box contents itself (it does not know what was mounted);
294
+ * the caller, which owns the bytes inside `prepareBox`, supplies each entry via
295
+ * `recordMount`. Carries no domain semantics — just where the resource landed,
296
+ * its content fingerprint, its size, and where it came from — so a run is
297
+ * auditable after the fact ("what exactly was this agent given?").
298
+ *
299
+ * @experimental
300
+ */
301
+ interface MountManifestEntry {
302
+ /** Destination path inside the box where the resource was placed. */
303
+ path: string;
304
+ /** Hex SHA-256 of the mounted bytes. The caller computes it from the bytes
305
+ * it wrote — the kernel does not hash box contents. */
306
+ sha256: string;
307
+ /** Size of the mounted resource in bytes. */
308
+ bytes: number;
309
+ /** Free-form origin of the resource (e.g. a repo ref, a corpus id, a local
310
+ * path, a URL). Provenance only — the kernel attaches no meaning to it. */
311
+ source: string;
312
+ }
313
+ /**
314
+ * A record of one candidate-selection decision: which iteration the selector
315
+ * picked (or rejected) and why. Pure audit trail of the SELECTOR role — it
316
+ * carries the selector's identity, the candidate's score, and an optional
317
+ * human-readable reason, with no domain semantics. The kernel emits one receipt
318
+ * per scored candidate at finalize so a run answers "why did THIS one win?".
319
+ *
320
+ * @experimental
321
+ */
322
+ interface SelectionReceipt {
323
+ /** Iteration index this receipt is about. */
324
+ candidateIndex: number;
325
+ /** True for the iteration the selector chose as winner; false otherwise. */
326
+ selected: boolean;
327
+ /** The candidate's verdict score, when it has one. */
328
+ score?: number;
329
+ /** Why this candidate was (or was not) selected, when the selector states it. */
330
+ reason?: string;
331
+ /** Identity of the selector that produced this receipt — `'caller'` (an
332
+ * explicit `selectWinner`), `'driver'` (a driver-authored winner), or
333
+ * `'default'` (the kernel's best-valid-score argmax). */
334
+ selector: 'caller' | 'driver' | 'default';
335
+ }
336
+ /**
337
+ * Domain-free run provenance: a manifest of what was mounted into the run's
338
+ * boxes and the receipts for how the winner was selected. Surfaced on
339
+ * `LoopResult` purely for run auditability — nothing in the kernel branches on
340
+ * it. Empty arrays when the caller recorded no mounts and there was no
341
+ * candidate to select.
342
+ *
343
+ * @experimental
344
+ */
345
+ interface RunProvenance {
346
+ /** Every resource recorded via `prepareBox`'s `recordMount`, in record order. */
347
+ mounts: MountManifestEntry[];
348
+ /** One receipt per scored candidate at finalize, in iteration order. */
349
+ selectionReceipts: SelectionReceipt[];
350
+ }
351
+ /**
352
+ * Records a mounted resource into the run's provenance manifest. Passed to
353
+ * `prepareBox` so the caller — which owns the bytes it writes into the box —
354
+ * declares what it mounted without the kernel having to inspect box contents.
355
+ *
356
+ * @experimental
357
+ */
358
+ type MountRecorder = (entry: MountManifestEntry) => void;
359
+ /** @experimental */
360
+ interface Iteration<Task, Output> {
361
+ /** 0-based iteration index assigned by the kernel. */
362
+ index: number;
363
+ task: Task;
364
+ /** Stable name of the `AgentRunSpec` that produced this iteration. */
365
+ agentRunName: string;
366
+ output?: Output;
367
+ verdict?: DefaultVerdict;
368
+ error?: Error;
369
+ /** Raw sandbox event stream collected for this iteration. */
370
+ events: SandboxEvent[];
371
+ startedAt: number;
372
+ endedAt: number;
373
+ costUsd: number;
374
+ /** Summed LLM token usage across every `llm_call` event in this iteration. */
375
+ tokenUsage: LoopTokenUsage;
376
+ }
377
+ /** @experimental */
378
+ interface Driver<Task, Output, Decision> {
379
+ /**
380
+ * Stable identifier surfaced in trace events. Default `'driver'`.
381
+ */
382
+ readonly name?: string;
383
+ /**
384
+ * Tasks to issue this iteration. `[task]` → refine; N copies → fanout;
385
+ * `[]` → no more work this round (kernel proceeds to `decide`).
386
+ */
387
+ plan(task: Task, history: ReadonlyArray<Iteration<Task, Output>>): Promise<Task[]>;
388
+ /**
389
+ * Inspect history and return the next state. The kernel terminates the
390
+ * loop when `decide` returns a value listed in `isTerminalDecision`
391
+ * (`'stop' | 'pick-winner' | 'fail' | 'done'`), when `maxIterations`
392
+ * is hit, or when the abort signal fires.
393
+ */
394
+ decide(history: ReadonlyArray<Iteration<Task, Output>>): Decision | Promise<Decision>;
395
+ /**
396
+ * Optional: describe the move `plan()` just produced, for trace emission.
397
+ * The kernel calls this immediately after `plan()` and emits the result in
398
+ * the `loop.plan` event so a topology viewer can render the agent's chosen
399
+ * move + rationale (not just the inferred fan-width). Drivers whose topology
400
+ * is a pure function of count (refine/fanout-vote) omit it — the kernel
401
+ * infers `moveKind` from the planned-task count. A driver that authors its
402
+ * own topology returns its chosen move's kind + rationale here.
403
+ */
404
+ describePlan?(): LoopPlanDescription | undefined;
405
+ /**
406
+ * Optional: the driver AUTHORS the winner instead of the kernel's argmax. The
407
+ * kernel consults this at finalize ONLY when the caller did not pass an explicit
408
+ * `selectWinner` to runAgentRounds. Return the driver-declared winner (e.g. from a
409
+ * `select` topology move) or `undefined` to fall through to the default
410
+ * (best-valid-score, earliest index). This is the SELECTOR role made
411
+ * agent-authorable — the planner runs the selection, not the kernel.
412
+ * @experimental
413
+ */
414
+ selectWinner?(history: ReadonlyArray<Iteration<Task, Output>>): LoopWinner<Task, Output> | undefined;
415
+ }
416
+ /** @experimental Driver-supplied description of the just-planned move. */
417
+ interface LoopPlanDescription {
418
+ /** Topology move this round — e.g. `'refine' | 'fanout' | 'verify' | 'stop'`. */
419
+ kind: string;
420
+ /** Why the driver chose this move (the agent's rationale), when available. */
421
+ rationale?: string;
422
+ /**
423
+ * Iteration index this round branches FROM, when the driver declares it.
424
+ * Overrides the kernel's inferred branch point — lets a planner that
425
+ * branches off a specific (non-winner) iteration emit faithful edge lineage.
426
+ * Omit to keep the inferred (best-valid / latest) branch point.
427
+ */
428
+ parentIndex?: number;
429
+ }
430
+ /** @experimental */
431
+ interface LoopWinner<Task, Output> {
432
+ task: Task;
433
+ output: Output;
434
+ verdict?: DefaultVerdict;
435
+ iterationIndex: number;
436
+ agentRunName: string;
437
+ }
438
+ /** @experimental */
439
+ interface LoopResult<Task, Output, Decision> {
440
+ decision: Decision;
441
+ iterations: Iteration<Task, Output>[];
442
+ winner?: LoopWinner<Task, Output>;
443
+ durationMs: number;
444
+ /** Sum of every iteration's `costUsd`. */
445
+ costUsd: number;
446
+ /** Sum of every iteration's token usage. `loopDispatch` commits it through
447
+ * the campaign's paid-call receipt. */
448
+ tokenUsage: LoopTokenUsage;
449
+ /** Domain-free run provenance for auditability: the mount manifest recorded
450
+ * during `prepareBox` and the selection receipts for how the winner was
451
+ * chosen. Always present; empty arrays when nothing was recorded. */
452
+ provenance: RunProvenance;
453
+ }
454
+ /**
455
+ * Minimal sandbox client surface the kernel calls. Satisfied structurally by
456
+ * `new Sandbox({ apiKey, baseUrl })` — declared as a structural type so
457
+ * tests can pass a stub without instantiating the SDK.
458
+ *
459
+ * `describePlacement` is optional. When present, the kernel calls it after
460
+ * each `create()` so the `loop.iteration.dispatch` trace event carries fleet
461
+ * coordinates (fleetId + machineId) instead of just the sibling sandboxId.
462
+ * Fleet-aware adapters set this; the raw `Sandbox` SDK class does not, and
463
+ * the kernel falls back to `{ placement: 'sibling', sandboxId: box.id }`.
464
+ *
465
+ * @experimental
466
+ */
467
+ interface SandboxClient {
468
+ create(options?: CreateSandboxOptions): Promise<SandboxInstance>;
469
+ describePlacement?(box: SandboxInstance): LoopSandboxPlacement;
470
+ /**
471
+ * Optional CRIU capability probe. When present and it resolves
472
+ * `{ available: true }`, the loop's `lineage.fork` seam may checkpoint+fork a
473
+ * parent box so a fanout's branches inherit a shared context prefix; absent or
474
+ * `false`, the fanout degrades to independent fresh boxes. The kernel reads
475
+ * this ONLY through the capability probe — it never branches on backend kind.
476
+ * The raw `Sandbox` SDK class satisfies it; the loop's test fakes omit it
477
+ * (⇒ `canFork = false`).
478
+ * @experimental
479
+ */
480
+ criuStatus?(): Promise<{
481
+ available: boolean;
482
+ criuVersion?: string;
483
+ reason?: string;
484
+ }>;
485
+ }
486
+ /**
487
+ * Opt-in box-lineage controls for `runAgentRounds`. Default OFF — with both flags
488
+ * unset the kernel's per-iteration behavior is byte-identical to acquiring a
489
+ * fresh box, streaming once, and tearing it down. The independence of N fresh
490
+ * boxes (e.g. `random@k`) is a compute-control invariant; these flags must
491
+ * never apply to it. Enable them ONLY on a steered loop (refine / planner-driven
492
+ * fanout) where reusing the parent's context is intended.
493
+ *
494
+ * Live-box footprint: the lineage keeps every box it starts or forks alive
495
+ * across rounds so a later round can descend from it, and tears them down at
496
+ * loop end. When the driver's branch point is kernel-inferred (no
497
+ * `describePlan` — refine, fanout-vote), the kernel prunes boxes no future
498
+ * round can reach after each round, so the live set tracks the active frontier.
499
+ * When the driver authors its own branch point (`describePlan().parentIndex`),
500
+ * it may descend from any prior
501
+ * iteration, so no box is pruned and the live-box count rises to the total
502
+ * iterations across all rounds. Size `forkFanout` runs accordingly (CRIU forks
503
+ * are copy-on-write, but each is still a live box until loop end).
504
+ *
505
+ * @experimental
506
+ */
507
+ interface LoopLineageOptions {
508
+ /**
509
+ * When true, a refine round (1 planned task) descending from a prior round
510
+ * CONTINUES the parent iteration's session on the SAME box
511
+ * (`streamPrompt({ sessionId })`) instead of acquiring a fresh box and
512
+ * re-injecting prior context as prompt text. Round 0 (no parent) always
513
+ * starts fresh. Usable on any single-task path, not just the refine driver.
514
+ *
515
+ * Requires a platform that honors a client-supplied `sessionId`. The lineage
516
+ * mints the id and `continue` asserts the session is still live
517
+ * (`box.session(id).status()`), failing loud if the platform dropped it — so a
518
+ * non-honoring platform errors instead of silently running contextless turns.
519
+ * Verify continuity against the live platform before enabling: the assertion
520
+ * proves the session EXISTS server-side, not that prior turns replay into it.
521
+ */
522
+ sessionContinuity?: boolean;
523
+ /**
524
+ * When true AND the platform reports CRIU fork support, a fanout round (N
525
+ * planned tasks) descending from a prior round FORKS the parent iteration's
526
+ * checkpoint so all N branches inherit a shared context prefix. Without fork
527
+ * support it degrades to N independent fresh boxes (same result, no prefix).
528
+ * Round 0 always starts fresh. NEVER set this for a `random@k` control arm —
529
+ * forking would couple the independent samples.
530
+ *
531
+ * A real fork inherits the parent's IMAGE/PROFILE: per-branch `AgentRunSpec`
532
+ * profiles are honored only on the degraded fresh-box path, so a
533
+ * heterogeneous-profile fanout silently homogenizes to the parent's profile
534
+ * when fork is available. Use this for same-profile branching; for
535
+ * different-per-branch profiles use the unforked fanout path.
536
+ */
537
+ forkFanout?: boolean;
538
+ /**
539
+ * Per-turn sandbox streaming mode. Default `'sse'` (live `streamPrompt` —
540
+ * low-latency, full per-token trace; best for interactive chat). `'poll'`
541
+ * fire-and-detaches via `dispatchPrompt` and awaits the terminal result by
542
+ * status-polling, so a long, quiet in-box turn (clone + build + test) never
543
+ * holds a live stream a proxy idle-timeout can drop mid-execution. Lower trace
544
+ * fidelity (one terminal event), so it is opt-in — intended for BATCH eval
545
+ * runs, which don't need live streaming and were losing long turns to the
546
+ * idle-drop. Applies to the default fresh-box path too, not only when
547
+ * `sessionContinuity`/`forkFanout` are on.
548
+ */
549
+ streaming?: 'sse' | 'poll';
550
+ }
551
+ /** @experimental */
552
+ interface LoopSandboxPlacement {
553
+ kind: 'sibling' | 'fleet';
554
+ sandboxId?: string;
555
+ fleetId?: string;
556
+ machineId?: string;
557
+ }
558
+ /** @experimental */
559
+ interface LoopTraceEmitter {
560
+ emit(event: LoopTraceEvent): void | Promise<void>;
561
+ }
562
+ /** @experimental */
563
+ type LoopTraceEvent = {
564
+ kind: 'loop.started';
565
+ runId: string;
566
+ timestamp: number;
567
+ payload: LoopStartedPayload;
568
+ } | {
569
+ kind: 'loop.plan';
570
+ runId: string;
571
+ timestamp: number;
572
+ payload: LoopPlanPayload;
573
+ } | {
574
+ kind: 'loop.iteration.started';
575
+ runId: string;
576
+ timestamp: number;
577
+ payload: LoopIterationStartedPayload;
578
+ } | {
579
+ kind: 'loop.iteration.dispatch';
580
+ runId: string;
581
+ timestamp: number;
582
+ payload: LoopIterationDispatchPayload;
583
+ } | {
584
+ kind: 'loop.iteration.ended';
585
+ runId: string;
586
+ timestamp: number;
587
+ payload: LoopIterationEndedPayload;
588
+ } | {
589
+ kind: 'loop.decision';
590
+ runId: string;
591
+ timestamp: number;
592
+ payload: LoopDecisionPayload;
593
+ } | {
594
+ kind: 'loop.ended';
595
+ runId: string;
596
+ timestamp: number;
597
+ payload: LoopEndedPayload;
598
+ } | {
599
+ kind: 'loop.teardown.failed';
600
+ runId: string;
601
+ timestamp: number;
602
+ payload: LoopTeardownFailedPayload;
603
+ };
604
+ /** @experimental */
605
+ interface LoopStartedPayload {
606
+ driver: string;
607
+ agentRunNames: string[];
608
+ maxIterations: number;
609
+ maxConcurrency: number;
610
+ }
611
+ /**
612
+ * Emitted once per `plan()` round, immediately after the driver plans. Carries
613
+ * the topology move so a viewer renders WHAT the agent decided + WHY, not just
614
+ * the inferred fan-width. `moveKind` is the driver's `describePlan().kind` when
615
+ * provided, else inferred from `plannedCount` (0→stop, 1→refine, N→fanout).
616
+ *
617
+ * @experimental
618
+ */
619
+ interface LoopPlanPayload {
620
+ /** 0-based plan round (one per `plan()` call). */
621
+ roundIndex: number;
622
+ /** Tasks the driver issued this round. */
623
+ plannedCount: number;
624
+ /** Topology move — `'refine' | 'fanout' | 'verify' | 'stop'` etc. */
625
+ moveKind: string;
626
+ /** Driver rationale for the move, when available. */
627
+ rationale?: string;
628
+ /**
629
+ * Iteration index this round branched FROM (the edge source). `undefined`
630
+ * for round 0 (root). Kernel-inferred branch point — the best-valid (else
631
+ * latest) iteration so far — unless a driver later declares it explicitly.
632
+ */
633
+ parentIndex?: number;
634
+ /** Iteration indices this round dispatched (the edge targets). */
635
+ childIndices: number[];
636
+ }
637
+ /** @experimental */
638
+ interface LoopIterationStartedPayload {
639
+ iterationIndex: number;
640
+ agentRunName: string;
641
+ taskHash: string;
642
+ /** Plan round (== `LoopPlanPayload.roundIndex`) this iteration belongs to. */
643
+ groupId?: number;
644
+ /** Iteration this one was planned from; `undefined` ⇒ root. */
645
+ parentIndex?: number;
646
+ }
647
+ /**
648
+ * Where the iteration's worker was placed. `sibling` = a fresh sandbox the
649
+ * kernel created via `sandboxClient.create`. `fleet` = an existing machine in
650
+ * a shared-workspace fleet — workers see the caller's filesystem and any diff
651
+ * they write lands on it directly.
652
+ *
653
+ * @experimental
654
+ */
655
+ interface LoopIterationDispatchPayload {
656
+ iterationIndex: number;
657
+ agentRunName: string;
658
+ placement: 'sibling' | 'fleet';
659
+ /** Set on every placement. Lets analyst loops correlate per-iteration logs. */
660
+ sandboxId?: string;
661
+ /** Set only when `placement === 'fleet'`. */
662
+ fleetId?: string;
663
+ /** Set only when `placement === 'fleet'`. */
664
+ machineId?: string;
665
+ /** Plan round this iteration belongs to. */
666
+ groupId?: number;
667
+ /** Iteration this one was planned from; `undefined` ⇒ root. */
668
+ parentIndex?: number;
669
+ }
670
+ /** @experimental */
671
+ interface LoopIterationEndedPayload {
672
+ iterationIndex: number;
673
+ agentRunName: string;
674
+ outputHash?: string;
675
+ verdict?: DefaultVerdict;
676
+ error?: string;
677
+ costUsd: number;
678
+ durationMs: number;
679
+ /** Summed LLM token usage for this iteration — maps to gen_ai.usage.* on the
680
+ * branch span. Omitted when no `llm_call` events carried token counts. */
681
+ tokenUsage?: LoopTokenUsage;
682
+ /** Plan round this iteration belongs to. */
683
+ groupId?: number;
684
+ /** Iteration this one was planned from; `undefined` ⇒ root. */
685
+ parentIndex?: number;
686
+ /** Truncated string preview of the parsed output — for a viewer's drawer.
687
+ * Bounded to ~280 chars; never the full payload. */
688
+ outputPreview?: string;
689
+ }
690
+ /** @experimental */
691
+ interface LoopDecisionPayload {
692
+ decision: string;
693
+ historyLength: number;
694
+ }
695
+ /** @experimental */
696
+ interface LoopEndedPayload {
697
+ winnerIterationIndex?: number;
698
+ totalCostUsd: number;
699
+ durationMs: number;
700
+ iterations: number;
701
+ }
702
+ /** Emitted when a box's `delete()` throws or times out during teardown — the
703
+ * loop swallows the failure (platform reaps on expiry) but surfaces it here so
704
+ * a real leak (e.g. mid-loop auth expiry) is observable. @experimental */
705
+ interface LoopTeardownFailedPayload {
706
+ sandboxId?: string;
707
+ /** `'timeout'` or the delete error message. */
708
+ reason: string;
709
+ }
710
+ /**
711
+ * Execution context for `runAgentRounds`: the sandbox client the kernel creates boxes through, plus optional runtime hooks.
712
+ *
713
+ * @experimental
714
+ */
715
+ interface ExecCtx {
716
+ /** Sandbox SDK client — the kernel calls `.create()` per iteration. */
717
+ sandboxClient: SandboxClient;
718
+ /** Optional runtime hooks. Execution-scoped; never part of `AgentProfile`. */
719
+ hooks?: RuntimeHooks;
720
+ /** Optional trace emitter. When set, the kernel emits `loop.*` events. */
721
+ traceEmitter?: LoopTraceEmitter;
722
+ /**
723
+ * Optional per-event tee. When set, the kernel forwards EVERY raw event from
724
+ * each iteration's `streamPrompt` stream as it arrives, so a host can stream
725
+ * the agent's live output (tokens, tool calls) token-by-token. The observer
726
+ * receives a defensive copy of each event — mutating it cannot affect the
727
+ * run's own cost accounting or output parsing. Called synchronously in the hot
728
+ * stream loop and never awaited, so a slow or never-settling observer cannot
729
+ * stall the stream; keep it cheap. An async observer is fire-and-forget: its
730
+ * promise is not awaited, so events carry no ordering or backpressure
731
+ * guarantees (the next event may be observed before a prior async observer
732
+ * settles) — use it for side-effect telemetry, not sequential processing.
733
+ * Both a synchronous throw and a rejected returned promise are caught +
734
+ * ignored so the observer can never break the run — but prefer not to depend
735
+ * on that.
736
+ *
737
+ * @experimental
738
+ */
739
+ onSandboxEvent?: (event: SandboxEvent, meta: {
740
+ iterationIndex: number;
741
+ agentRunName: string;
742
+ }) => void | PromiseLike<void>;
743
+ /**
744
+ * Optional production-run handle. When set, every synthesized `llm_call`
745
+ * the kernel infers from a sandbox event stream is forwarded via
746
+ * `runHandle.observe` so per-run cost aggregates pick up loop spend.
747
+ */
748
+ runHandle?: RuntimeRunHandle;
749
+ /** Cooperative cancellation signal. */
750
+ signal?: AbortSignal;
751
+ /**
752
+ * Trace id for OTEL correlation. When set alongside `traceEmitter`, the
753
+ * exporter uses this as the parent trace for all emitted spans. Typically
754
+ * inherited from TRACE_ID env var in MCP subprocess mode.
755
+ */
756
+ traceId?: string;
757
+ /**
758
+ * Parent span id for OTEL correlation. Loop events become children of
759
+ * this span. Typically inherited from PARENT_SPAN_ID env var.
760
+ */
761
+ parentSpanId?: string;
762
+ }
763
+ //#endregion
764
+ export { RuntimeRunCompleteInput as A, RuntimeDecisionPoint as B, MountRecorder as C, SelectionReceipt as D, SandboxClient as E, RuntimeRunRow as F, RuntimeHookTarget as G, RuntimeHookErrorContext as H, RuntimeRunStatus as I, defineRuntimeHooks as J, RuntimeHooks as K, startRuntimeRun as L, RuntimeRunHandle as M, RuntimeRunOptions as N, ValidationCtx as O, RuntimeRunPersistenceAdapter as P, RuntimeDecisionEvidenceRef as R, MountManifestEntry as S, RunProvenance as T, RuntimeHookEvent as U, RuntimeHookContext as V, RuntimeHookPhase as W, notifyRuntimeHookEvent as X, notifyRuntimeDecisionPoint as Y, LoopTeardownFailedPayload as _, Iteration as a, LoopTraceEvent as b, LoopIterationDispatchPayload as c, LoopLineageOptions as d, LoopPlanDescription as f, LoopStartedPayload as g, LoopSandboxPlacement as h, ExecCtx as i, RuntimeRunCost as j, Validator as k, LoopIterationEndedPayload as l, LoopResult as m, DefaultVerdict as n, LoopDecisionPayload as o, LoopPlanPayload as p, composeRuntimeHooks as q, Driver as r, LoopEndedPayload as s, AgentRunSpec as t, LoopIterationStartedPayload as u, LoopTokenUsage as v, OutputAdapter as w, LoopWinner as x, LoopTraceEmitter as y, RuntimeDecisionKind as z };
765
+ //# sourceMappingURL=types-BevOjfTY.d.ts.map