@tangle-network/agent-runtime 0.59.0 → 0.61.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.
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -2
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-IN7WHMGZ.js → chunk-5V343QPB.js} +47 -7
- package/dist/chunk-5V343QPB.js.map +1 -0
- package/dist/chunk-7IXF3VUJ.js +59 -0
- package/dist/chunk-7IXF3VUJ.js.map +1 -0
- package/dist/{chunk-ZWGEA722.js → chunk-AU5MCNHO.js} +2 -2
- package/dist/chunk-IBRJTG7O.js +475 -0
- package/dist/chunk-IBRJTG7O.js.map +1 -0
- package/dist/{chunk-MMDIORZY.js → chunk-Q5R33I7Y.js} +4 -23
- package/dist/chunk-Q5R33I7Y.js.map +1 -0
- package/dist/{chunk-45D64J7B.js → chunk-VCOT7XEQ.js} +190 -99
- package/dist/chunk-VCOT7XEQ.js.map +1 -0
- package/dist/coder-DD5J5Onk.d.ts +52 -0
- package/dist/coordination-k29badiX.d.ts +381 -0
- package/dist/{delegates-C94qchkz.d.ts → delegates-CWMv_rKL.d.ts} +649 -21
- package/dist/index.d.ts +9 -6
- package/dist/index.js +9 -9
- package/dist/intelligence.d.ts +1 -1
- package/dist/{loop-runner-bin-Noz7P-mS.d.ts → loop-runner-bin-Bqt0hiNY.d.ts} +46 -12
- package/dist/loop-runner-bin.d.ts +7 -4
- package/dist/loop-runner-bin.js +4 -4
- package/dist/loops.d.ts +7 -6
- package/dist/loops.js +17 -6
- package/dist/mcp/bin.js +10 -10
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +12 -12
- package/dist/mcp/index.js +7 -7
- package/dist/{openai-tools-d4GKwgya.d.ts → openai-tools-CA2N3-Ak.d.ts} +1 -1
- package/dist/profiles.d.ts +7 -9
- package/dist/profiles.js +5 -7
- package/dist/profiles.js.map +1 -1
- package/dist/{run-loop-CcqfR_gy.d.ts → run-loop-D3PwlG7J.d.ts} +1 -1
- package/dist/runtime.d.ts +30 -1046
- package/dist/runtime.js +17 -6
- package/dist/{types-CUzjRFZ3.d.ts → types-Crxftafi.d.ts} +2 -2
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +1 -2
- package/dist/workflow.js.map +1 -1
- package/dist/worktree-fanout-CBULEoVe.d.ts +1098 -0
- package/package.json +2 -2
- package/dist/chunk-45D64J7B.js.map +0 -1
- package/dist/chunk-4FEUFYOY.js +0 -282
- package/dist/chunk-4FEUFYOY.js.map +0 -1
- package/dist/chunk-7QYOXFCD.js +0 -293
- package/dist/chunk-7QYOXFCD.js.map +0 -1
- package/dist/chunk-IN7WHMGZ.js.map +0 -1
- package/dist/chunk-MMDIORZY.js.map +0 -1
- package/dist/coder-CybltHEm.d.ts +0 -163
- package/dist/coordination-Biw19JzN.d.ts +0 -944
- /package/dist/{chunk-ZWGEA722.js.map → chunk-AU5MCNHO.js.map} +0 -0
|
@@ -1,9 +1,489 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { DefaultVerdict, AgentEvalError } from '@tangle-network/agent-eval';
|
|
2
|
+
import { AgentProfile, BackendType, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
|
|
3
|
+
import { R as RuntimeHooks } from './runtime-hooks-C7JwKb9E.js';
|
|
4
|
+
import { f as LoopTokenUsage, g as LoopTraceEmitter, d as LoopTraceEvent, S as SandboxClient, A as AgentRunSpec } from './types-Crxftafi.js';
|
|
5
|
+
import { C as CoderTask } from './coder-DD5J5Onk.js';
|
|
5
6
|
import { a as UiLens, U as UiFinding } from './substrate-CUgk7F7s.js';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @experimental
|
|
10
|
+
*
|
|
11
|
+
* Recursive execution atom — the FROZEN type surface (the keystone contract).
|
|
12
|
+
*
|
|
13
|
+
* One self-similar `Agent` atom runs inside a budget-conserving reactive `Scope`,
|
|
14
|
+
* orchestrated by a `Supervisor` over an event-sourced `SpawnJournal`. A leaf is an
|
|
15
|
+
* `Agent` that never calls `scope.spawn`; a driver is an `Agent` that spawns and runs
|
|
16
|
+
* a policy over its children's streaming results.
|
|
17
|
+
*
|
|
18
|
+
* Two invariants the surface exists to make enforceable:
|
|
19
|
+
* - Budget is an atomically-reserved CONSERVED pool, so `Σk(treatment) ≡ Σk(blind)` by
|
|
20
|
+
* construction (reserve-on-spawn, refund-unspent-on-settle, fail-closed admission).
|
|
21
|
+
* - The journal records a content-addressed `outRef` per child result, so replay
|
|
22
|
+
* rehydrates the exact `Settled` the driver branched on (the replay invariant below).
|
|
23
|
+
*
|
|
24
|
+
* The leaf RUNTIME is one OPEN `Executor` interface, not a closed `inline|sandbox|cli`
|
|
25
|
+
* union the call site switches on. The built-ins (router/inline, sandbox, cli) are the
|
|
26
|
+
* initial IMPLEMENTATIONS; any user agent is first-class the moment it implements the
|
|
27
|
+
* interface. The interface IS the extension point — no per-vendor adapters live here.
|
|
28
|
+
*
|
|
29
|
+
* Layering: substrate types (`DefaultVerdict`) come from `@tangle-network/agent-eval`;
|
|
30
|
+
* runtime-shaped types (everything else) live here. Pure types/interfaces only — this
|
|
31
|
+
* module typechecks standalone and is imported by every keystone impl.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One self-similar atom. A leaf is an `Agent` that never calls `scope.spawn`; a driver
|
|
36
|
+
* is an `Agent` whose `act` spawns children and reacts to them via `scope.next()`. An
|
|
37
|
+
* analyst is an `Agent` whose task is "read these traces → findings" — `where` it runs
|
|
38
|
+
* is its executor, not a separate type.
|
|
39
|
+
*
|
|
40
|
+
* `act` MUST be replay-safe: it may read `verdict`, `spent`, and `out` (rehydrated by
|
|
41
|
+
* `outRef`) off each `Settled`; it MUST NOT read `Date.now`, `Math.random`, or any
|
|
42
|
+
* unordered collection. `scope.next()` delivers strictly in recorded `seq` order.
|
|
43
|
+
*/
|
|
44
|
+
interface Agent<Task, Out> {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
act(task: Task, scope: Scope<Out>): Promise<Out>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The leaf runtime — ONE open interface, not a closed union. `execute` returns a
|
|
50
|
+
* `Promise<ExecutorResult>` for one-shot executors OR an `AsyncIterable<UsageEvent>` for
|
|
51
|
+
* streaming ones; a streaming executor reports incremental normalized usage as it runs
|
|
52
|
+
* (the budget pool reconciles against it) and exposes its terminal artifact via
|
|
53
|
+
* `resultArtifact()`. Both shapes normalize usage to `UsageEvent` so the conserved pool
|
|
54
|
+
* meters every runtime identically.
|
|
55
|
+
*
|
|
56
|
+
* Built-in implementations (in `runtime.ts`, NOT variants here): router/inline (a direct
|
|
57
|
+
* Router/HTTP inference call, no box), sandbox (COMPOSES `runLoop` as a leaf, forwarding
|
|
58
|
+
* PR #150's optional `lineage` passthrough — does NOT reinvent checkpoint/fork), cli
|
|
59
|
+
* (Halo/RLM subprocess; `budgetExempt`, excluded from equal-k by construction). A user's
|
|
60
|
+
* own agent (mastra/agno/raw HTTP/anything) is first-class by implementing this interface.
|
|
61
|
+
*/
|
|
62
|
+
interface Executor<Out> {
|
|
63
|
+
/** Stable runtime tag for traces + the equal-k exemption check. */
|
|
64
|
+
readonly runtime: Runtime;
|
|
65
|
+
/**
|
|
66
|
+
* When true, this executor's spend is NOT metered against the conserved pool and its
|
|
67
|
+
* iterations are excluded from the equal-k assertion (a `cli` subprocess without
|
|
68
|
+
* token accounting). Fail-loud everywhere else: a metered executor MUST report usage.
|
|
69
|
+
*/
|
|
70
|
+
readonly budgetExempt?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* One-shot → resolves a `ExecutorResult`; streaming → yields incremental `UsageEvent`s and
|
|
73
|
+
* the terminal artifact is read from `resultArtifact()` after the stream drains.
|
|
74
|
+
* `signal` is the spawn-scoped abort (chains the acquire lifecycle for sandbox).
|
|
75
|
+
*/
|
|
76
|
+
execute(task: unknown, signal: AbortSignal): Promise<ExecutorResult<Out>> | AsyncIterable<UsageEvent>;
|
|
77
|
+
/**
|
|
78
|
+
* Optional inbox: receive an out-of-band message from the driver mid-run (the `send`/`steer_worker`
|
|
79
|
+
* verb). A streaming executor drains pending messages between turns and folds them into the next
|
|
80
|
+
* step (a steer / interrupt / resume). A one-shot executor that can't be steered mid-flight omits
|
|
81
|
+
* this; `Scope.send` then returns `false` for it. Never throws — a malformed message is the
|
|
82
|
+
* executor's to ignore.
|
|
83
|
+
*/
|
|
84
|
+
deliver?(msg: unknown): void;
|
|
85
|
+
/**
|
|
86
|
+
* Tear the executor's resources down. `grace` mirrors the OTP shutdown spec
|
|
87
|
+
* (`'brutalKill'` = immediate, a number = ms grace, `'infinity'` = await clean exit).
|
|
88
|
+
*/
|
|
89
|
+
teardown(grace: number | 'brutalKill' | 'infinity'): Promise<{
|
|
90
|
+
destroyed: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* The replay source (B1): the content-addressed `outRef` + the materialized output the
|
|
94
|
+
* driver branched on, its verdict, and the conserved spend. Read once, after settle.
|
|
95
|
+
*/
|
|
96
|
+
resultArtifact(): {
|
|
97
|
+
outRef: string;
|
|
98
|
+
out: Out;
|
|
99
|
+
verdict?: DefaultVerdict;
|
|
100
|
+
spent: Spend;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* A driver-executor's OWN-inference subtree total (rolled up from its nested tree's `metered`
|
|
104
|
+
* events) — the parent scope journals it as a `metered` event for this node on settle, on BOTH
|
|
105
|
+
* the done AND the down/crash paths, so a crashed sub-driver's partial inference still re-homes
|
|
106
|
+
* (the pool already debited it via `observe`; the journal must match). NOT reconciled, so it never
|
|
107
|
+
* trips the reservation clamp. Read on settle, valid after `execute` resolves OR throws. Leaf
|
|
108
|
+
* executors omit it (returns `undefined`).
|
|
109
|
+
*/
|
|
110
|
+
metered?(): Spend | undefined;
|
|
111
|
+
}
|
|
112
|
+
/** Terminal artifact of a one-shot `Executor.execute`. */
|
|
113
|
+
interface ExecutorResult<Out> {
|
|
114
|
+
outRef: string;
|
|
115
|
+
out: Out;
|
|
116
|
+
verdict?: DefaultVerdict;
|
|
117
|
+
spent: Spend;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Normalized usage event — the single channel every executor reports through, so the
|
|
121
|
+
* conserved pool meters all runtimes identically. `tokens` carries `LoopTokenUsage`'s
|
|
122
|
+
* `{ input, output }`; `usd` is a SEPARATE channel (never folded into tokens).
|
|
123
|
+
*/
|
|
124
|
+
type UsageEvent = {
|
|
125
|
+
kind: 'tokens';
|
|
126
|
+
input: number;
|
|
127
|
+
output: number;
|
|
128
|
+
} | {
|
|
129
|
+
kind: 'cost';
|
|
130
|
+
usd: number;
|
|
131
|
+
} | {
|
|
132
|
+
kind: 'iteration';
|
|
133
|
+
};
|
|
134
|
+
/** The runtime tag of a `Executor` impl. Open by intent — `string` so a BYO executor
|
|
135
|
+
* names its own runtime; the built-ins use these literals. */
|
|
136
|
+
type Runtime = 'router' | 'inline' | 'sandbox' | 'cli' | (string & {});
|
|
137
|
+
/**
|
|
138
|
+
* `AgentProfile` does NOT carry a `harness`/backend field — `harness` lives on the
|
|
139
|
+
* sandbox SDK's `BackendConfig`, not the portable profile. So an agent is mapped to its
|
|
140
|
+
* executor through this MINIMAL wrapper, never by fabricating a field onto `AgentProfile`.
|
|
141
|
+
*
|
|
142
|
+
* Resolution (in `runtime.ts`):
|
|
143
|
+
* - `executor` present → BYO: use it verbatim (a user's own `Executor`).
|
|
144
|
+
* - `harness === null` → router/inline: a direct Router call, no box.
|
|
145
|
+
* - `harness` is a `BackendType` → sandbox: compose `runLoop` against `profile` on that backend.
|
|
146
|
+
* Fail loud on an unresolvable spec (no executor and an unknown harness).
|
|
147
|
+
*/
|
|
148
|
+
interface AgentSpec {
|
|
149
|
+
readonly profile: AgentProfile;
|
|
150
|
+
/** `null` selects router/inline; a `BackendType` selects the sandboxed harness. */
|
|
151
|
+
readonly harness: BackendType | null;
|
|
152
|
+
/** Bring-your-own executor: when set, overrides harness-based resolution entirely. */
|
|
153
|
+
readonly executor?: Executor<unknown>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Builds a fresh `Executor` for one spawn from the resolved spec. Per-spawn (not
|
|
157
|
+
* shared) so each child owns its own box/abort/teardown lifecycle. A BYO factory lets a
|
|
158
|
+
* user supply construction args without pre-instantiating.
|
|
159
|
+
*/
|
|
160
|
+
type ExecutorFactory<Out> = (spec: AgentSpec, ctx: ExecutorContext) => Executor<Out>;
|
|
161
|
+
/** Construction context handed to a `ExecutorFactory` — the seams a built-in needs
|
|
162
|
+
* (sandbox client for the sandbox executor, router config for router/inline) without
|
|
163
|
+
* the factory reaching into module globals. */
|
|
164
|
+
interface ExecutorContext {
|
|
165
|
+
readonly signal: AbortSignal;
|
|
166
|
+
/** Opaque seams the registry threads through; a built-in narrows what it needs. */
|
|
167
|
+
readonly seams: Readonly<Record<string, unknown>>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The OPEN resolver: maps an `AgentSpec` to a `ExecutorFactory`. The default
|
|
171
|
+
* registry resolves the three built-ins AND accepts a BYO `executor`/factory; callers
|
|
172
|
+
* register more runtimes by name. NOT a closed switch — registration is the extension
|
|
173
|
+
* point, mirroring the open `Executor` interface.
|
|
174
|
+
*/
|
|
175
|
+
interface ExecutorRegistry {
|
|
176
|
+
/** Register a factory for a named runtime. Throws on a duplicate name (fail loud). */
|
|
177
|
+
register<Out>(runtime: Runtime, factory: ExecutorFactory<Out>): void;
|
|
178
|
+
/**
|
|
179
|
+
* Resolve a spec to a factory. Precedence: a BYO `spec.executor` → a trivial factory
|
|
180
|
+
* returning it; else `harness === null` → the `'router'` factory; else a registered
|
|
181
|
+
* factory for the harness-derived runtime. Returns a typed outcome — the caller
|
|
182
|
+
* inspects `succeeded` before `value` (no silent fallback).
|
|
183
|
+
*/
|
|
184
|
+
resolve<Out>(spec: AgentSpec): {
|
|
185
|
+
succeeded: true;
|
|
186
|
+
value: ExecutorFactory<Out>;
|
|
187
|
+
} | {
|
|
188
|
+
succeeded: false;
|
|
189
|
+
error: string;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** A budget envelope on a spawn or the root. All ceilings; the pool reserves against them. */
|
|
193
|
+
interface Budget {
|
|
194
|
+
readonly maxIterations: number;
|
|
195
|
+
readonly maxTokens: number;
|
|
196
|
+
readonly maxUsd?: number;
|
|
197
|
+
readonly deadlineMs?: number;
|
|
198
|
+
}
|
|
199
|
+
/** Conserved spend, reconciled from the normalized `UsageEvent` stream. Tokens and usd
|
|
200
|
+
* are separate channels (never folded). */
|
|
201
|
+
interface Spend {
|
|
202
|
+
iterations: number;
|
|
203
|
+
tokens: LoopTokenUsage;
|
|
204
|
+
usd: number;
|
|
205
|
+
ms: number;
|
|
206
|
+
}
|
|
207
|
+
/** OTP child-spec restart class. */
|
|
208
|
+
type Restart = 'temporary' | 'transient' | 'permanent';
|
|
209
|
+
/** `'acquiring'` is first-class (M1): a node spends real time + reaps an orphan box
|
|
210
|
+
* during sandbox acquire BEFORE it is `running`, so abort must be defined over it. */
|
|
211
|
+
type NodeStatus = 'pending' | 'acquiring' | 'running' | 'done' | 'failed' | 'cancelled';
|
|
212
|
+
/** Deterministic node id — `${parent}:s${seq}` from the cursor order, never wall-clock. */
|
|
213
|
+
type NodeId = string;
|
|
214
|
+
interface SpawnOpts {
|
|
215
|
+
readonly budget: Budget;
|
|
216
|
+
readonly label: string;
|
|
217
|
+
readonly restart?: Restart;
|
|
218
|
+
/** Teardown grace handed to the executor when this node is reaped. */
|
|
219
|
+
readonly shutdown?: number | 'brutalKill' | 'infinity';
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* A live child handle. `abort()` is defined over the ACQUIRE lifecycle: it chains into
|
|
223
|
+
* the `acquireSandbox` signal and reaps a find-by-name orphan box, so a node aborted
|
|
224
|
+
* mid-acquire never leaks (M1).
|
|
225
|
+
*/
|
|
226
|
+
interface Handle<Out> {
|
|
227
|
+
readonly id: NodeId;
|
|
228
|
+
readonly label: string;
|
|
229
|
+
readonly status: NodeStatus;
|
|
230
|
+
abort(reason?: string): void;
|
|
231
|
+
/** Phantom: binds the handle to the child's output type so `spawn<C>` returns a
|
|
232
|
+
* `Handle<C>` distinct from a `Handle<other>`. Type-only — never present at runtime. */
|
|
233
|
+
readonly __out?: Out;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* A settled child, delivered by `scope.next()`. `seq` is the monotonic cursor order
|
|
237
|
+
* `next()` yielded this settlement (B2) — NOT wall-clock — and replay delivers strictly
|
|
238
|
+
* in `seq` order. `outRef` rehydrates `out` from the `ResultBlobStore` on replay.
|
|
239
|
+
*/
|
|
240
|
+
type Settled<Out> = {
|
|
241
|
+
kind: 'done';
|
|
242
|
+
handle: Handle<Out>;
|
|
243
|
+
out: Out;
|
|
244
|
+
outRef: string;
|
|
245
|
+
verdict?: DefaultVerdict;
|
|
246
|
+
spent: Spend;
|
|
247
|
+
seq: number;
|
|
248
|
+
} | {
|
|
249
|
+
kind: 'down';
|
|
250
|
+
handle: Handle<Out>;
|
|
251
|
+
reason: string;
|
|
252
|
+
/** True = infrastructure failure (excluded from merge `n` / equal-k), not a bad result. */
|
|
253
|
+
infra: boolean;
|
|
254
|
+
restartCount: number;
|
|
255
|
+
seq: number;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* The budget-conserving reactive scope an `Agent.act` runs inside. `spawn` reserves
|
|
259
|
+
* budget atomically from the shared pool and fails closed when the pool cannot cover it.
|
|
260
|
+
* `next()` waits for one settlement from this scope's live set; `view` reads live state,
|
|
261
|
+
* not the replay log.
|
|
262
|
+
*/
|
|
263
|
+
interface Scope<Out> {
|
|
264
|
+
/**
|
|
265
|
+
* Spawn a child. Reserves `opts.budget` from the conserved pool atomically; refunds the
|
|
266
|
+
* unspent remainder on settle. Returns a typed outcome — fail-closed on an exhausted
|
|
267
|
+
* pool or an exceeded depth ceiling (the caller inspects `ok` before `handle`).
|
|
268
|
+
*/
|
|
269
|
+
spawn<C extends Out>(agent: Agent<unknown, C>, task: unknown, opts: SpawnOpts): {
|
|
270
|
+
ok: true;
|
|
271
|
+
handle: Handle<C>;
|
|
272
|
+
} | {
|
|
273
|
+
ok: false;
|
|
274
|
+
reason: 'budget-exhausted' | 'depth-exceeded';
|
|
275
|
+
};
|
|
276
|
+
/** ray.wait n=1 over this scope's in-memory live set; resolves as each child settles;
|
|
277
|
+
* `null` when the live set is empty. */
|
|
278
|
+
next(): Promise<Settled<Out> | null>;
|
|
279
|
+
/**
|
|
280
|
+
* Steer a RUNNING child out-of-band — deliver a message to its executor's inbox (the driver's
|
|
281
|
+
* `send` verb: next-instruction, interrupt, or resume). Returns `true` if the message was
|
|
282
|
+
* delivered to a live child whose executor accepts delivery, `false` otherwise (unknown id,
|
|
283
|
+
* already settled, or an executor with no inbox). The executor drains its inbox between turns;
|
|
284
|
+
* a leaf that does not implement `deliver` simply cannot be steered mid-flight. In-process this
|
|
285
|
+
* is a direct call; the sandbox/Agent-Bus transports surface the SAME verb as an MCP tool.
|
|
286
|
+
*/
|
|
287
|
+
send(nodeId: NodeId, msg: unknown): boolean;
|
|
288
|
+
/** This scope's abort signal — aborted when the run is cancelled, a breaker trips, the pool
|
|
289
|
+
* is exhausted, or a parent scope cascades. A long-running driver `act` over this scope reads
|
|
290
|
+
* it to break promptly (the conserved pool + driver-stop are the other bounds). A nested
|
|
291
|
+
* scope carries its own signal, chained off its driver child's abort. */
|
|
292
|
+
readonly signal: AbortSignal;
|
|
293
|
+
/**
|
|
294
|
+
* Meter the driver's OWN compute against the conserved pool — its inference turns, which are
|
|
295
|
+
* real tokens/usd but not a spawned child (no reserve/reconcile). A direct `free → committed`
|
|
296
|
+
* debit, so equal-k counts the driver's tokens AND the in-loop budget guard (`budget.tokensLeft`)
|
|
297
|
+
* halts a driver that thinks the pool dry. `detail` rides an `agent.turn` trace event for live
|
|
298
|
+
* observability (turn index, tool calls, cumulative spend). It also journals a `metered` event —
|
|
299
|
+
* the durable twin of the pool debit (as `settled` is the twin of `reconcile`) — so every
|
|
300
|
+
* journal-based cost reader (`spentFromJournal`, `trajectoryReport`) sums driver inference
|
|
301
|
+
* automatically. A leaf never calls this; a driver meters each chat turn and awaits it (the
|
|
302
|
+
* metered event is cost-critical, so it lands before the join-barrier roll-up).
|
|
303
|
+
*/
|
|
304
|
+
meter(spend: Spend, detail?: Record<string, unknown>): Promise<void>;
|
|
305
|
+
/** The live tree — reads the in-memory nursery, not the journal. */
|
|
306
|
+
readonly view: TreeView;
|
|
307
|
+
/** Conserved-pool readouts (post-reservation). */
|
|
308
|
+
readonly budget: Readonly<{
|
|
309
|
+
tokensLeft: number;
|
|
310
|
+
usdLeft: number;
|
|
311
|
+
usdCapped: boolean;
|
|
312
|
+
deadlineMs: number;
|
|
313
|
+
reservedTokens: number;
|
|
314
|
+
}>;
|
|
315
|
+
}
|
|
316
|
+
interface NodeSnapshot {
|
|
317
|
+
readonly id: NodeId;
|
|
318
|
+
readonly parent?: NodeId;
|
|
319
|
+
readonly label: string;
|
|
320
|
+
readonly status: NodeStatus;
|
|
321
|
+
readonly runtime: Runtime;
|
|
322
|
+
readonly budget: Budget;
|
|
323
|
+
/** Conserved spend so far for this node. */
|
|
324
|
+
readonly spent: Spend;
|
|
325
|
+
/** `outRef` once the node is `done` (the replay/result pointer). */
|
|
326
|
+
readonly outRef?: string;
|
|
327
|
+
}
|
|
328
|
+
/** The live tree — what `scope.view` / `RootHandle.view()` materialize for a viewer. */
|
|
329
|
+
interface TreeView {
|
|
330
|
+
readonly root: NodeId;
|
|
331
|
+
readonly nodes: ReadonlyArray<NodeSnapshot>;
|
|
332
|
+
/** Count of nodes in `running` or `acquiring` — the "what's in flow?" answer. */
|
|
333
|
+
readonly inFlight: number;
|
|
334
|
+
}
|
|
335
|
+
/** Journaled spawn-tree events (B1/B2). `seq` is the cursor order; `at` is an ISO
|
|
336
|
+
* timestamp for human inspection only (NOT a replay input). */
|
|
337
|
+
type SpawnEvent = {
|
|
338
|
+
kind: 'spawned';
|
|
339
|
+
id: NodeId;
|
|
340
|
+
parent?: NodeId;
|
|
341
|
+
label: string;
|
|
342
|
+
budget: Budget;
|
|
343
|
+
runtime: Runtime;
|
|
344
|
+
seq: number;
|
|
345
|
+
at: string;
|
|
346
|
+
} | {
|
|
347
|
+
kind: 'settled';
|
|
348
|
+
id: NodeId;
|
|
349
|
+
status: 'done' | 'down';
|
|
350
|
+
/** Content-addressed result pointer; rehydrates `out` from `ResultBlobStore`. */
|
|
351
|
+
outRef?: string;
|
|
352
|
+
verdict?: DefaultVerdict;
|
|
353
|
+
spent: Spend;
|
|
354
|
+
infra?: boolean;
|
|
355
|
+
seq: number;
|
|
356
|
+
at: string;
|
|
357
|
+
} | {
|
|
358
|
+
kind: 'cancelled';
|
|
359
|
+
id: NodeId;
|
|
360
|
+
reason: string;
|
|
361
|
+
seq: number;
|
|
362
|
+
at: string;
|
|
363
|
+
} | {
|
|
364
|
+
/** A driver's OWN inference spend, journaled separately from spawned-child work — the journal
|
|
365
|
+
* TWIN of `BudgetPool.observe`, exactly as `settled` is the twin of `reconcile`. So every
|
|
366
|
+
* journal-based cost reader sums it automatically — the journal is the single cost ledger.
|
|
367
|
+
* It carries spend only and is NOT a settlement: replay + `materializeTreeView` skip it for
|
|
368
|
+
* structure, and its `seq` lives outside the cursor-uniqueness namespace. A
|
|
369
|
+
* driver re-homes its nested subtree's metered total up to its parent (like settled spend),
|
|
370
|
+
* so summing any sub-tree root yields that sub-tree's true driver-inference cost. */
|
|
371
|
+
kind: 'metered';
|
|
372
|
+
id: NodeId;
|
|
373
|
+
spend: Spend;
|
|
374
|
+
seq: number;
|
|
375
|
+
at: string;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* The spawn-tree event source (mirrors `ConversationJournal`'s begin/append/load shape).
|
|
379
|
+
* `loadTree` replays the full ordered event list for resume/replay; `appendEvent` is
|
|
380
|
+
* called only AFTER the event is observed-committed (never speculative).
|
|
381
|
+
*/
|
|
382
|
+
interface SpawnJournal {
|
|
383
|
+
loadTree(root: NodeId): Promise<SpawnEvent[] | undefined>;
|
|
384
|
+
beginTree(root: NodeId, at: string): Promise<void>;
|
|
385
|
+
appendEvent(root: NodeId, ev: SpawnEvent): Promise<void>;
|
|
386
|
+
}
|
|
387
|
+
/** Content-addressed result blobs (the `outRef` → artifact map) backing the replay
|
|
388
|
+
* invariant. Split from the journal so the journal stays small (decisions) and the
|
|
389
|
+
* payloads (evidence) live where a viewer/replayer rehydrates them. */
|
|
390
|
+
interface ResultBlobStore {
|
|
391
|
+
put(outRef: string, artifact: unknown): Promise<void>;
|
|
392
|
+
get(outRef: string): Promise<unknown | undefined>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Owns the conserved pool, the spawn log, the abort cascade, the OTP intensity breaker,
|
|
396
|
+
* and the root handle. `run` executes the root `Agent` to completion; `attach` wires a
|
|
397
|
+
* live `RootHandle` (the Q2 substrate the chat/pi-viz client later consumes).
|
|
398
|
+
*/
|
|
399
|
+
interface Supervisor<Task, Out> {
|
|
400
|
+
run(root: Agent<Task, Out>, task: Task, opts: SupervisorOpts): Promise<SupervisedResult<Out>>;
|
|
401
|
+
attach(h: RootHandle<Out>): void;
|
|
402
|
+
}
|
|
403
|
+
interface SupervisorOpts {
|
|
404
|
+
/** The root conserved-pool ceiling (tokens + usd + iterations + deadline). */
|
|
405
|
+
readonly budget: Budget;
|
|
406
|
+
/** Trace-correlation root + the journal/blob root key. */
|
|
407
|
+
readonly runId: NodeId;
|
|
408
|
+
/** Event source — defaults to the in-memory journal in the impl; pass JSONL/FS for durability. */
|
|
409
|
+
readonly journal: SpawnJournal;
|
|
410
|
+
/** Result payload store backing `outRef` rehydration. */
|
|
411
|
+
readonly blobs: ResultBlobStore;
|
|
412
|
+
/** Executor resolution — the open registry mapping `AgentSpec` → `Executor`. */
|
|
413
|
+
readonly executors: ExecutorRegistry;
|
|
414
|
+
/** Runtime recursion-depth ceiling (paired with the conserved pool per R3). */
|
|
415
|
+
readonly maxDepth?: number;
|
|
416
|
+
/**
|
|
417
|
+
* OTP intensity breaker: more than `maxRestarts` child restarts within `withinMs`
|
|
418
|
+
* trips the supervisor to `no-winner` rather than restarting forever.
|
|
419
|
+
*/
|
|
420
|
+
readonly maxRestarts?: number;
|
|
421
|
+
readonly withinMs?: number;
|
|
422
|
+
readonly now?: () => number;
|
|
423
|
+
readonly signal?: AbortSignal;
|
|
424
|
+
/** Lifecycle stream sink, threaded into the root `Scope` so every `spawn`/settle emits on the
|
|
425
|
+
* same `agent.spawn`/`agent.child` stream `runLoop` feeds — one observable recursive tree. */
|
|
426
|
+
readonly hooks?: RuntimeHooks;
|
|
427
|
+
}
|
|
428
|
+
/** Typed terminal result (M2) — a no-winner is NEVER coerced to a best-effort output. */
|
|
429
|
+
type SupervisedResult<Out> = {
|
|
430
|
+
kind: 'winner';
|
|
431
|
+
out: Out;
|
|
432
|
+
outRef: string;
|
|
433
|
+
verdict?: DefaultVerdict;
|
|
434
|
+
tree: TreeView;
|
|
435
|
+
spentTotal: Spend;
|
|
436
|
+
/** Where `spentTotal` went: `driverInference` = the drivers' own chat turns (metered via
|
|
437
|
+
* `Scope.meter`); `childWork` = every spawned child's reconciled spend (the journal sum).
|
|
438
|
+
* `driverInference + childWork === spentTotal`. Present whenever any driver metered. */
|
|
439
|
+
spentBreakdown?: {
|
|
440
|
+
driverInference: Spend;
|
|
441
|
+
childWork: Spend;
|
|
442
|
+
};
|
|
443
|
+
} | {
|
|
444
|
+
kind: 'no-winner';
|
|
445
|
+
reason: 'all-children-down' | 'budget-exhausted' | 'aborted';
|
|
446
|
+
tree: TreeView;
|
|
447
|
+
downCount: number;
|
|
448
|
+
};
|
|
449
|
+
/** Live root handle — the substrate a chat/pi-viz client attaches to (Q2). `signal`
|
|
450
|
+
* delivers an out-of-band message to the running root; `view()` materializes the tree. */
|
|
451
|
+
interface RootHandle<Out> {
|
|
452
|
+
view(): TreeView;
|
|
453
|
+
signal(msg: RootSignal): void;
|
|
454
|
+
abort(reason?: string): void;
|
|
455
|
+
/** Phantom: binds the handle to the supervised run's output type. Type-only — never
|
|
456
|
+
* present at runtime; lets `attach(h: RootHandle<Out>)` stay output-typed. */
|
|
457
|
+
readonly __out?: Out;
|
|
458
|
+
}
|
|
459
|
+
/** Out-of-band message to a running root. Open by intent — a client extends it. */
|
|
460
|
+
type RootSignal = {
|
|
461
|
+
kind: 'pause';
|
|
462
|
+
} | {
|
|
463
|
+
kind: 'resume';
|
|
464
|
+
} | {
|
|
465
|
+
kind: 'cancel';
|
|
466
|
+
reason?: string;
|
|
467
|
+
} | {
|
|
468
|
+
kind: 'ask';
|
|
469
|
+
question: string;
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* The progressive-widening gate (MCTS-PW). Decides whether a settled child is
|
|
473
|
+
* `promising` enough to spawn another under the remaining pool. DEFAULTS TO FLAT
|
|
474
|
+
* (`shouldWiden` always false) so a gate run never widens and the selector≠judge
|
|
475
|
+
* firewall conflict (R2) stays dormant. When widening IS enabled, `promising` MUST be
|
|
476
|
+
* derived from TRACE findings (`analyses`), never raw `verdict` — or the gate carries
|
|
477
|
+
* an explicit, argued `judgeExempt: true` (the documented escape hatch, off by default).
|
|
478
|
+
*/
|
|
479
|
+
interface WidenGate<Out> {
|
|
480
|
+
/** Default impl returns false for every settlement (flat — never widens). */
|
|
481
|
+
shouldWiden(settled: Settled<Out>, budget: Scope<Out>['budget']): boolean;
|
|
482
|
+
/** When true, widening may read `verdict` directly (collides with the steer firewall —
|
|
483
|
+
* must be explicitly argued per cell, never defaulted on). */
|
|
484
|
+
readonly judgeExempt?: boolean;
|
|
485
|
+
}
|
|
486
|
+
|
|
7
487
|
/**
|
|
8
488
|
* @experimental
|
|
9
489
|
*
|
|
@@ -106,6 +586,49 @@ declare function createDelegationTraceCollector(onSpans: (spans: DelegationTrace
|
|
|
106
586
|
*/
|
|
107
587
|
declare function composeLoopTraceEmitters(...emitters: ReadonlyArray<LoopTraceEmitter | undefined>): LoopTraceEmitter | undefined;
|
|
108
588
|
|
|
589
|
+
/**
|
|
590
|
+
* @experimental
|
|
591
|
+
*
|
|
592
|
+
* Sandbox-session coder decode layer. The sandbox-session delegate (`./delegates`) and the
|
|
593
|
+
* cross-restart resume driver (`./bin`) run the in-box harness over a `SandboxClient` and need to
|
|
594
|
+
* (a) build an `AgentRunSpec` from the authored coder profile, (b) decode the harness event stream
|
|
595
|
+
* into a structured `CoderOutput`, and (c) gate it with the shared mechanical checks. This is the
|
|
596
|
+
* MCP server's built-in `delegate_code` path — it is the live default delegate, NOT dormant — and is
|
|
597
|
+
* kept separate from the generic recursive path: `worktreeFanout` instead settles the raw
|
|
598
|
+
* `WorktreePatchArtifact` and gates via `patchDelivered`. Only the OPTIONAL cross-restart resume
|
|
599
|
+
* (the `driveTurn` tick) is opt-in (`MCP_ENABLE_DETACHED_RESUME`); the held-stream delegate is
|
|
600
|
+
* always live. Prefer `worktreeFanout` / `worktreeLoopRunner` for NEW local-repo coding.
|
|
601
|
+
*
|
|
602
|
+
* The decode tolerates two `result`-event shapes:
|
|
603
|
+
* 1. the in-process executor's raw worktree-harness result (`{ branch, patch, stats, checks }`),
|
|
604
|
+
* projected onto `CoderOutput`; and
|
|
605
|
+
* 2. an LLM-emitted JSON block (`{ branch, patch, testResult, typecheckResult, diffStats }`),
|
|
606
|
+
* lifted onto `data.result` or scanned out of the assistant transcript (any harness shape).
|
|
607
|
+
*/
|
|
608
|
+
|
|
609
|
+
/** @experimental The structured coder result the sandbox-session path decodes + gates. */
|
|
610
|
+
interface CoderOutput {
|
|
611
|
+
/** Branch the agent wrote the patch on. */
|
|
612
|
+
branch: string;
|
|
613
|
+
/** Unified diff (`git diff <base>..HEAD`). */
|
|
614
|
+
patch: string;
|
|
615
|
+
testResult: {
|
|
616
|
+
passed: boolean;
|
|
617
|
+
output: string;
|
|
618
|
+
};
|
|
619
|
+
typecheckResult: {
|
|
620
|
+
passed: boolean;
|
|
621
|
+
output: string;
|
|
622
|
+
};
|
|
623
|
+
diffStats: {
|
|
624
|
+
filesChanged: number;
|
|
625
|
+
insertions: number;
|
|
626
|
+
deletions: number;
|
|
627
|
+
};
|
|
628
|
+
/** Optional reviewer commentary surfaced by the agent. */
|
|
629
|
+
reviewerNotes?: string;
|
|
630
|
+
}
|
|
631
|
+
|
|
109
632
|
/**
|
|
110
633
|
* @experimental
|
|
111
634
|
*
|
|
@@ -1043,6 +1566,86 @@ declare class DelegationTaskQueue {
|
|
|
1043
1566
|
*/
|
|
1044
1567
|
declare function hashIdempotencyInput(value: unknown): string;
|
|
1045
1568
|
|
|
1569
|
+
/**
|
|
1570
|
+
* @experimental
|
|
1571
|
+
*
|
|
1572
|
+
* Git worktree helpers for the in-process delegation executor. Each
|
|
1573
|
+
* delegation runs in its own worktree so multiple parallel harness
|
|
1574
|
+
* subprocesses (claude / codex / opencode in a 3-way fanout) don't clobber
|
|
1575
|
+
* each other's edits on the shared workspace.
|
|
1576
|
+
*
|
|
1577
|
+
* Worktrees live under `<repoRoot>/.agent-worktrees/<runId>/`. After the
|
|
1578
|
+
* harness exits + the diff is captured, the worktree is removed.
|
|
1579
|
+
*
|
|
1580
|
+
* All operations spawn `git` via `child_process.spawn` synchronously
|
|
1581
|
+
* (via a `runGit` helper). Stays narrow on purpose: no commits, no rebases.
|
|
1582
|
+
* Diff capture stages all changes (`git add -A`) into the ephemeral worktree's
|
|
1583
|
+
* index so created (untracked) files appear in the `--cached` diff.
|
|
1584
|
+
*/
|
|
1585
|
+
/** @experimental */
|
|
1586
|
+
interface WorktreeHandle {
|
|
1587
|
+
/** Absolute path to the worktree directory. */
|
|
1588
|
+
path: string;
|
|
1589
|
+
/** SHA the worktree was created at. */
|
|
1590
|
+
baseSha: string;
|
|
1591
|
+
/** Branch name created for this worktree (typically `delegate/<runId>`). */
|
|
1592
|
+
branch: string;
|
|
1593
|
+
}
|
|
1594
|
+
/** @experimental */
|
|
1595
|
+
interface CreateWorktreeOptions {
|
|
1596
|
+
/** Absolute path to the main git checkout. */
|
|
1597
|
+
repoRoot: string;
|
|
1598
|
+
/** Unique id for the worktree path + branch. Use the delegation run id. */
|
|
1599
|
+
runId: string;
|
|
1600
|
+
/** Parent directory the worktree lives under. Defaults to `.agent-worktrees`. */
|
|
1601
|
+
variantsDir?: string;
|
|
1602
|
+
/** Override the base ref (default `HEAD`). */
|
|
1603
|
+
baseRef?: string;
|
|
1604
|
+
/** Test seam — inject a custom git runner. */
|
|
1605
|
+
runGit?: GitRunner;
|
|
1606
|
+
}
|
|
1607
|
+
/** @experimental */
|
|
1608
|
+
interface DiffOptions {
|
|
1609
|
+
/** Worktree to diff. */
|
|
1610
|
+
worktree: WorktreeHandle;
|
|
1611
|
+
/** What to compare against. Default `worktree.baseSha`. */
|
|
1612
|
+
baseRef?: string;
|
|
1613
|
+
/** Test seam. */
|
|
1614
|
+
runGit?: GitRunner;
|
|
1615
|
+
}
|
|
1616
|
+
/** @experimental */
|
|
1617
|
+
interface DiffResult {
|
|
1618
|
+
patch: string;
|
|
1619
|
+
stats: {
|
|
1620
|
+
filesChanged: number;
|
|
1621
|
+
insertions: number;
|
|
1622
|
+
deletions: number;
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
/** @experimental */
|
|
1626
|
+
interface RemoveWorktreeOptions {
|
|
1627
|
+
worktree: WorktreeHandle;
|
|
1628
|
+
repoRoot: string;
|
|
1629
|
+
/** Force removal even if dirty (default true; the loser of a fanout has uncommitted changes). */
|
|
1630
|
+
force?: boolean;
|
|
1631
|
+
/** Test seam. */
|
|
1632
|
+
runGit?: GitRunner;
|
|
1633
|
+
}
|
|
1634
|
+
/** Pluggable git runner (sync) — replaceable in tests. */
|
|
1635
|
+
type GitRunner = (args: ReadonlyArray<string>, opts: {
|
|
1636
|
+
cwd: string;
|
|
1637
|
+
}) => {
|
|
1638
|
+
stdout: string;
|
|
1639
|
+
stderr: string;
|
|
1640
|
+
exitCode: number;
|
|
1641
|
+
};
|
|
1642
|
+
/** @experimental */
|
|
1643
|
+
declare function createWorktree(options: CreateWorktreeOptions): Promise<WorktreeHandle>;
|
|
1644
|
+
/** @experimental */
|
|
1645
|
+
declare function captureWorktreeDiff(options: DiffOptions): Promise<DiffResult>;
|
|
1646
|
+
/** @experimental */
|
|
1647
|
+
declare function removeWorktree(options: RemoveWorktreeOptions): Promise<void>;
|
|
1648
|
+
|
|
1046
1649
|
/**
|
|
1047
1650
|
* @experimental
|
|
1048
1651
|
*
|
|
@@ -1341,6 +1944,28 @@ interface FleetWorkspaceExecutorOptions {
|
|
|
1341
1944
|
*/
|
|
1342
1945
|
declare function createFleetWorkspaceExecutor(options: FleetWorkspaceExecutorOptions): DelegationExecutor;
|
|
1343
1946
|
|
|
1947
|
+
/**
|
|
1948
|
+
* @experimental
|
|
1949
|
+
*
|
|
1950
|
+
* Delegate factories — the layer between MCP tool handlers and the
|
|
1951
|
+
* underlying `runLoop` runners.
|
|
1952
|
+
*
|
|
1953
|
+
* The MCP server is profile-agnostic: it owns the task queue + feedback
|
|
1954
|
+
* store + transport. Each `*Delegate` is the closure that the queue
|
|
1955
|
+
* invokes when a task runs. Consumers can override either delegate to
|
|
1956
|
+
* inject custom drivers, mocks, fleet-aware dispatchers, etc.
|
|
1957
|
+
*
|
|
1958
|
+
* The `detachedSessionDelegate` here is the built-in SANDBOX-SESSION coder path — the live default
|
|
1959
|
+
* `delegate_code` delegate: workers run the in-box harness over a `SandboxClient`. By default it
|
|
1960
|
+
* holds the stream; single-variant turns can OPTIONALLY dispatch DETACHED (`driveTurn` ticks) so a
|
|
1961
|
+
* durable queue resumes them across an MCP restart — that resume tick is the only part gated behind
|
|
1962
|
+
* `MCP_ENABLE_DETACHED_RESUME` (default off) in `bin.ts`, a capability the recursive
|
|
1963
|
+
* `Scope`/worktree-CLI leaf has no durable equivalent for yet. For NEW local-repo coding use
|
|
1964
|
+
* `worktreeFanout` / `worktreeLoopRunner`. The default researcher delegate is **not** wired in this
|
|
1965
|
+
* file — `agent-knowledge` cannot be imported from `agent-runtime` without inducing a cycle.
|
|
1966
|
+
* Consumers pass `researcherDelegate` explicitly.
|
|
1967
|
+
*/
|
|
1968
|
+
|
|
1344
1969
|
/** @experimental */
|
|
1345
1970
|
interface DelegateRunCtx {
|
|
1346
1971
|
signal: AbortSignal;
|
|
@@ -1362,7 +1987,8 @@ interface DelegateRunCtx {
|
|
|
1362
1987
|
*/
|
|
1363
1988
|
traceEmitter?: LoopTraceEmitter;
|
|
1364
1989
|
}
|
|
1365
|
-
/** @experimental
|
|
1990
|
+
/** @experimental The server's coder-profile delegate slot — the closure the queue invokes for a
|
|
1991
|
+
* `delegate_code` task. `detachedSessionDelegate` is the built-in implementation. */
|
|
1366
1992
|
type CoderDelegate = (args: DelegateCodeArgs, ctx: DelegateRunCtx) => Promise<CoderOutput>;
|
|
1367
1993
|
/** @experimental */
|
|
1368
1994
|
type ResearcherDelegate = (args: DelegateResearchArgs, ctx: DelegateRunCtx) => Promise<ResearchOutputShape>;
|
|
@@ -1399,13 +2025,15 @@ type CoderReviewer = (output: CoderOutput, task: CoderTask, ctx: {
|
|
|
1399
2025
|
signal: AbortSignal;
|
|
1400
2026
|
}) => Promise<CoderReview> | CoderReview;
|
|
1401
2027
|
/**
|
|
1402
|
-
* @experimental Winner-selection strategy among validated (+ reviewed)
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
2028
|
+
* @experimental Winner-selection strategy among validated (+ reviewed) candidates on the
|
|
2029
|
+
* sandbox-session path. The base strategies (`highest-score` / `smallest-diff` /
|
|
2030
|
+
* `first-approved`) delegate to the shared `selectValidWinner`; `highest-readiness` is the
|
|
2031
|
+
* reviewer-only strategy this path keeps that the generic selector does not express. Default
|
|
2032
|
+
* `highest-score`.
|
|
1405
2033
|
*/
|
|
1406
|
-
type
|
|
2034
|
+
type DetachedWinnerSelection = 'highest-score' | 'smallest-diff' | 'highest-readiness' | 'first-approved';
|
|
1407
2035
|
/** @experimental */
|
|
1408
|
-
interface
|
|
2036
|
+
interface DetachedSessionDelegateOptions {
|
|
1409
2037
|
/**
|
|
1410
2038
|
* Execution placement. Pass a {@link DelegationExecutor} (sibling or fleet)
|
|
1411
2039
|
* to control where worker iterations land. `sandboxClient` is a
|
|
@@ -1442,7 +2070,7 @@ interface CreateDefaultCoderDelegateOptions {
|
|
|
1442
2070
|
*/
|
|
1443
2071
|
reviewer?: CoderReviewer;
|
|
1444
2072
|
/** Winner-selection strategy among eligible candidates. Default `highest-score`. */
|
|
1445
|
-
winnerSelection?:
|
|
2073
|
+
winnerSelection?: DetachedWinnerSelection;
|
|
1446
2074
|
/**
|
|
1447
2075
|
* Loop trace emitter forwarded into every delegated `runLoop`. Wire
|
|
1448
2076
|
* `createPropagatingTraceEmitter(readTraceContextFromEnv())` here (the bin
|
|
@@ -1461,23 +2089,23 @@ interface CreateDefaultCoderDelegateOptions {
|
|
|
1461
2089
|
detachedWallCapMs?: number;
|
|
1462
2090
|
}
|
|
1463
2091
|
/**
|
|
1464
|
-
* Build
|
|
1465
|
-
* sandbox client + coder profile
|
|
1466
|
-
*
|
|
2092
|
+
* Build the sandbox-session coder delegate. It drives `runLoop` against the project's
|
|
2093
|
+
* sandbox client + coder profile; when `args.variants > 1` it switches to the multi-harness fanout
|
|
2094
|
+
* topology.
|
|
1467
2095
|
*
|
|
1468
2096
|
* This is the SANDBOX-SESSION coder path: workers run the in-box harness via the
|
|
1469
2097
|
* `SandboxClient`'s `streamPrompt`, and single-variant turns can dispatch DETACHED
|
|
1470
2098
|
* (driveTurn ticks) so a durable queue resumes them across an MCP restart — a substrate
|
|
1471
2099
|
* the recursive worktree-CLI leaf does not yet have a journal-replay equivalent for.
|
|
1472
2100
|
*
|
|
1473
|
-
* For NEW local-repo coding
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
2101
|
+
* For NEW local-repo coding use `worktreeFanout` / `worktreeLoopRunner` (author an `AgentProfile`
|
|
2102
|
+
* per harness → `createWorktreeCliExecutor` leaves → `gateOnDeliverable`). This delegate stays as the
|
|
2103
|
+
* MCP server's built-in `delegate_code` path; it runs held-stream by default and only its OPTIONAL
|
|
2104
|
+
* cross-restart resume (the `driveTurn` tick) is opt-in behind `MCP_ENABLE_DETACHED_RESUME`.
|
|
1477
2105
|
*
|
|
1478
2106
|
* @experimental
|
|
1479
2107
|
*/
|
|
1480
|
-
declare function
|
|
2108
|
+
declare function detachedSessionDelegate(options: DetachedSessionDelegateOptions): CoderDelegate;
|
|
1481
2109
|
/**
|
|
1482
2110
|
* Canonical `DelegateCodeArgs` → `CoderTask` mapping — the single source for
|
|
1483
2111
|
* the delegate's live dispatch AND the resume driver's settle/message
|
|
@@ -1508,11 +2136,11 @@ interface SettleDetachedCoderTurnOptions {
|
|
|
1508
2136
|
* SCOPE NOTE (detached/resume): the detached `driveTurn`-tick + cross-restart resume path is
|
|
1509
2137
|
* bound to the `runLoop` + sandbox-session substrate. The recursive `Scope`/worktree-CLI leaf has
|
|
1510
2138
|
* journal→replay but no driveTurn-over-a-detached-sandbox-session equivalent yet, so resume is NOT
|
|
1511
|
-
* advertised on the generic `
|
|
2139
|
+
* advertised on the generic `worktreeFanout` path. This helper (with `coderTaskFromArgs` and
|
|
1512
2140
|
* `createDriveTurnResumeDriver`) stays as the resume seam `bin.ts` wires for in-flight records.
|
|
1513
2141
|
*
|
|
1514
2142
|
* @experimental
|
|
1515
2143
|
*/
|
|
1516
2144
|
declare function settleDetachedCoderTurn(turn: DetachedTurn, options: SettleDetachedCoderTurnOptions): Promise<CoderOutput>;
|
|
1517
2145
|
|
|
1518
|
-
export { type
|
|
2146
|
+
export { type DelegationRecord as $, type Agent as A, type Budget as B, type CoderReviewer as C, type DelegateCodeArgs as D, type ExecutorRegistry as E, type FleetHandle as F, type GitRunner as G, type CappedDelegationTrace as H, type CoderReview as I, type CreateWorktreeOptions as J, DELEGATION_TRACE_MAX_BYTES as K, DELEGATION_TRACE_MAX_SPANS as L, type DelegateCodeConfig as M, type NodeId as N, type DelegateResearchConfig as O, type DelegateRunCtx as P, type DelegateUiAuditConfig as Q, type ResearcherDelegate as R, type Scope as S, type TraceContext as T, type UiAuditorDelegate as U, type DelegateUiAuditRoute as V, type DelegationError as W, type DelegationHistoryEntry as X, DelegationPersistenceError as Y, type DelegationProfile as Z, type DelegationProgress as _, type DetachedWinnerSelection as a, type OtelExportConfig as a$, type DelegationResultPayload as a0, type DelegationResumeContext as a1, type DelegationResumeDriver as a2, type DelegationResumeTick as a3, type DelegationRunContext as a4, DelegationStateCorruptError as a5, type DelegationStatus as a6, type DelegationStore as a7, type DelegationTaskQueueOptions as a8, type DelegationTraceCaps as a9, capDelegationTrace as aA, captureWorktreeDiff as aB, coderTaskFromArgs as aC, composeLoopTraceEmitters as aD, createDelegationTraceCollector as aE, createDriveTurnResumeDriver as aF, createFleetWorkspaceExecutor as aG, createPropagatingTraceEmitter as aH, createSiblingSandboxExecutor as aI, createWorktree as aJ, detachedSessionDelegate as aK, detachedTurnEvents as aL, formatDetachedSessionRef as aM, hashIdempotencyInput as aN, parseDetachedSessionRef as aO, readTraceContextFromEnv as aP, removeWorktree as aQ, runDetachedTurn as aR, settleDetachedCoderTurn as aS, traceContextToEnv as aT, type EvalRunEvent as aU, type EvalRunGeneration as aV, type EvalRunsExportConfig as aW, type EvalRunsExportResult as aX, INTELLIGENCE_WIRE_VERSION as aY, type LoopSpanNode as aZ, type OtelAttribute as a_, type DelegationTraceCollector as aa, type DelegationTraceSpan as ab, type DetachedSessionDelegateOptions as ac, type DetachedSessionRefParts as ad, type DetachedTurn as ae, type DiffOptions as af, type DiffResult as ag, type DriveTurnCapableBox as ah, type DriveTurnResumeDriverOptions as ai, type DriveTurnTick as aj, type FeedbackRating as ak, type FeedbackRefersTo as al, FileDelegationStore as am, type FileDelegationStoreOptions as an, type FleetWorkspaceExecutorOptions as ao, InMemoryDelegationStore as ap, type RemoveWorktreeOptions as aq, type ResearchOutputShape as ar, type RunDetachedTurnOptions as as, type SettleDetachedCoderTurnOptions as at, type SiblingSandboxExecutorOptions as au, type SubmitInput as av, type SubmitOutput as aw, type UiAuditorDelegationOutput as ax, type WorktreeHandle as ay, buildDelegationTraceSpans as az, type CoderOutput as b, type OtelExporter as b0, type OtelSpan as b1, buildLoopOtelSpans as b2, buildLoopSpanNodes as b3, createOtelExporter as b4, exportEvalRuns as b5, loopEventToOtelSpan as b6, type SpawnEvent as b7, type TreeView as b8, type ExecutorFactory as b9, type UsageEvent as ba, type Supervisor as bb, type ExecutorContext as bc, type ExecutorResult as bd, type Handle as be, type NodeSnapshot as bf, type NodeStatus as bg, type Restart as bh, type RootSignal as bi, type Runtime as bj, type SpawnOpts as bk, type SupervisorOpts as bl, type WidenGate as bm, type DelegateFeedbackArgs as c, type DelegationFeedbackSnapshot as d, DelegationTaskQueue as e, type CoderDelegate as f, type ResultBlobStore as g, type AgentSpec as h, type SpawnJournal as i, type RootHandle as j, type SupervisedResult as k, type Settled as l, type Spend as m, type Executor as n, type DelegationExecutor as o, type DelegateCodeResult as p, type DelegateFeedbackResult as q, type ResearchSource as r, type DelegateResearchArgs as s, type DelegateResearchResult as t, type DelegateUiAuditArgs as u, type DelegateUiAuditResult as v, type DelegationHistoryResult as w, type DelegationHistoryArgs as x, type DelegationStatusResult as y, type DelegationStatusArgs as z };
|