@tangle-network/agent-runtime 0.43.0 → 0.44.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/README.md +3 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/{chunk-C5HMTTNY.js → chunk-GFKVVRQ7.js} +8 -8
- package/dist/{chunk-MNCB4SJ5.js → chunk-KDMRUD2P.js} +2 -2
- package/dist/{chunk-EKBSQYZE.js → chunk-S7JXV32P.js} +159 -25
- package/dist/chunk-S7JXV32P.js.map +1 -0
- package/dist/{chunk-MJDGCRAT.js → chunk-SKUZZCHE.js} +2 -2
- package/dist/{dynamic-B_7GgCwu.d.ts → dynamic-wUgp6UKs.d.ts} +1 -1
- package/dist/improvement.js +3 -3
- package/dist/index.d.ts +6 -6
- package/dist/index.js +15 -15
- package/dist/{kb-gate-DTBum3vH.d.ts → kb-gate-D0ZIhFOU.d.ts} +1 -1
- package/dist/{loop-runner-bin-CVoCBmYk.d.ts → loop-runner-bin-BLMa8He3.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +4 -4
- package/dist/loop-runner-bin.js +4 -4
- package/dist/loops.d.ts +101 -79
- package/dist/loops.js +9 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +3 -3
- package/dist/{otel-export-BzvF1Ela.d.ts → otel-export-wFDmmurL.d.ts} +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/run-loop-C4L1Sted.d.ts +89 -0
- package/dist/{types-Bcp071Jg.d.ts → types-DbJzz2uf.d.ts} +1 -1
- package/dist/workflow.d.ts +550 -0
- package/dist/workflow.js +1779 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +29 -12
- package/dist/chunk-EKBSQYZE.js.map +0 -1
- /package/dist/{chunk-C5HMTTNY.js.map → chunk-GFKVVRQ7.js.map} +0 -0
- /package/dist/{chunk-MNCB4SJ5.js.map → chunk-KDMRUD2P.js.map} +0 -0
- /package/dist/{chunk-MJDGCRAT.js.map → chunk-SKUZZCHE.js.map} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @tangle-network/agent-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runs domain agents and closes the loop that makes them better — capturing every run as a trace and turning those traces into eval-gated improvements, automatically.
|
|
4
|
+
|
|
5
|
+
Two halves. **Execution:** the chat turn, the loop kernel (refine, fanout-vote, agent-authored dynamic topologies), delegated sub-agent loops (build, research, review, audit), and OpenTelemetry GenAI tracing of all of it. **Self-improvement:** the declarative `defineAgent` manifest that names an agent's mutable surfaces, an analyst loop that mines real traces into findings, surface adapters that apply them to prompts and knowledge, identity-gated prompt optimization, outcome measurement, and `createSandboxAct` so the agent is evaluated through its actual production profile. Domain behavior — models, tools, knowledge — lives in adapters; the scoring/judge/ship-gate engine in [`@tangle-network/agent-eval`](https://www.npmjs.com/package/@tangle-network/agent-eval); durable long-running execution in [`@tangle-network/sandbox`](https://www.npmjs.com/package/@tangle-network/sandbox).
|
|
4
6
|
|
|
5
7
|
```bash
|
|
6
8
|
pnpm add @tangle-network/agent-runtime @tangle-network/agent-eval @tangle-network/sandbox
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _tangle_network_agent_eval from '@tangle-network/agent-eval';
|
|
2
2
|
import { TraceAnalystKindSpec, AnalystFinding } from '@tangle-network/agent-eval';
|
|
3
|
-
import { R as RuntimeStreamEvent,
|
|
3
|
+
import { R as RuntimeStreamEvent, a as LoopSandboxClient, O as OutputAdapter, A as AgentRunSpec } from './types-DbJzz2uf.js';
|
|
4
4
|
import { A as AgentSurfaces } from './improvement-adapter-BC4HhuAR.js';
|
|
5
5
|
export { C as CreateSurfaceImprovementAdapterOpts, D as DraftPatchInput, a as DraftPatchOutput, R as ResolvedSurface, S as SurfaceImprovementEdit, b as SurfaceValidationIssue, c as createSurfaceImprovementAdapter, r as renderSurfaceIssues, d as resolveSubjectPath, v as validateSurfaces } from './improvement-adapter-BC4HhuAR.js';
|
|
6
6
|
import { K as KnowledgeAdapter, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
|
package/dist/agent.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createKbGate
|
|
3
|
+
} from "./chunk-FNMGYYSS.js";
|
|
4
|
+
import {
|
|
5
|
+
createDefaultCoderDelegate
|
|
6
|
+
} from "./chunk-SKUZZCHE.js";
|
|
1
7
|
import {
|
|
2
8
|
runAnalystLoop
|
|
3
9
|
} from "./chunk-XBUG326M.js";
|
|
4
10
|
import {
|
|
5
11
|
optimizePrompt
|
|
6
12
|
} from "./chunk-VOX6Z3II.js";
|
|
7
|
-
import {
|
|
8
|
-
createKbGate
|
|
9
|
-
} from "./chunk-FNMGYYSS.js";
|
|
10
|
-
import {
|
|
11
|
-
createDefaultCoderDelegate
|
|
12
|
-
} from "./chunk-MJDGCRAT.js";
|
|
13
13
|
import {
|
|
14
14
|
createDynamicDriver,
|
|
15
15
|
runLoop
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-S7JXV32P.js";
|
|
17
17
|
import {
|
|
18
18
|
ConfigError
|
|
19
19
|
} from "./chunk-SQSCRJ7U.js";
|
|
@@ -199,4 +199,4 @@ export {
|
|
|
199
199
|
runLoopRunnerCli,
|
|
200
200
|
parseLoopRunnerArgv
|
|
201
201
|
};
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
202
|
+
//# sourceMappingURL=chunk-GFKVVRQ7.js.map
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
import {
|
|
28
28
|
createFleetWorkspaceExecutor,
|
|
29
29
|
createSiblingSandboxExecutor
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-SKUZZCHE.js";
|
|
31
31
|
import {
|
|
32
32
|
runLocalHarness
|
|
33
33
|
} from "./chunk-GLR25NG7.js";
|
|
@@ -604,4 +604,4 @@ export {
|
|
|
604
604
|
createPropagatingTraceEmitter,
|
|
605
605
|
traceContextToEnv
|
|
606
606
|
};
|
|
607
|
-
//# sourceMappingURL=chunk-
|
|
607
|
+
//# sourceMappingURL=chunk-KDMRUD2P.js.map
|
|
@@ -104,6 +104,21 @@ function summarizeHistory(history, opts = {}) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// src/loops/drivers/planners.ts
|
|
108
|
+
var blind = ({ task, history }) => history.length === 0 ? { kind: "refine", task, rationale: "blind: single attempt" } : { kind: "stop", rationale: "blind: one attempt only" };
|
|
109
|
+
var PROMPT_PLANNERS = {
|
|
110
|
+
blind
|
|
111
|
+
};
|
|
112
|
+
function resolvePlanner(name) {
|
|
113
|
+
const planner = PROMPT_PLANNERS[name];
|
|
114
|
+
if (!planner) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`planners: unknown driver '${name}' (have: ${Object.keys(PROMPT_PLANNERS).join(", ")})`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return planner;
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
// src/loops/drivers/refine.ts
|
|
108
123
|
function createRefineDriver(options = {}) {
|
|
109
124
|
const maxIterations = options.maxIterations ?? 5;
|
|
@@ -149,16 +164,28 @@ function createSandboxPlanner(opts) {
|
|
|
149
164
|
const buildPrompt = opts.buildPrompt ?? defaultBuildPrompt;
|
|
150
165
|
const parseEnvelope = opts.parseEnvelope ?? defaultParseEnvelope;
|
|
151
166
|
return async (ctx) => {
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
167
|
+
const reused = opts.reuseBox ? await opts.reuseBox() : void 0;
|
|
168
|
+
const box = reused ?? await opts.client.create(buildSandboxOptions(opts.profile, opts.sandboxOverrides));
|
|
169
|
+
const plannerOwnsBox = reused === void 0;
|
|
170
|
+
try {
|
|
171
|
+
const prompt = await buildPrompt(ctx);
|
|
172
|
+
const events = [];
|
|
173
|
+
for await (const event of box.streamPrompt(prompt, { signal: opts.signal })) {
|
|
174
|
+
events.push(event);
|
|
175
|
+
}
|
|
176
|
+
const envelope = parseEnvelope(events);
|
|
177
|
+
if (!envelope) {
|
|
178
|
+
throw new PlannerError("sandbox planner emitted no parseable topology-move envelope");
|
|
179
|
+
}
|
|
180
|
+
return envelopeToMove(envelope, ctx, opts.decodeTask);
|
|
181
|
+
} finally {
|
|
182
|
+
if (plannerOwnsBox) {
|
|
183
|
+
try {
|
|
184
|
+
if (typeof box.delete === "function") await box.delete();
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
}
|
|
160
188
|
}
|
|
161
|
-
return envelopeToMove(envelope, ctx, opts.decodeTask);
|
|
162
189
|
};
|
|
163
190
|
}
|
|
164
191
|
function envelopeToMove(envelope, ctx, decodeTask) {
|
|
@@ -234,27 +261,28 @@ ${safeJson(summary)}`,
|
|
|
234
261
|
"Emit ONLY the JSON block."
|
|
235
262
|
].join("\n");
|
|
236
263
|
}
|
|
264
|
+
var TERMINAL_EVENT_TYPES = /* @__PURE__ */ new Set(["result", "final", "planner.move", "done"]);
|
|
237
265
|
function defaultParseEnvelope(events) {
|
|
266
|
+
const moveText = (data) => pickString(data.finalText) ?? pickString(data.text) ?? pickString(data.delta) ?? pickString(data.content) ?? pickString(data.message);
|
|
238
267
|
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
239
268
|
const event = events[i];
|
|
240
269
|
if (!event) continue;
|
|
241
|
-
const type = String(event.type ?? "");
|
|
242
270
|
const data = isRecord(event.data) ? event.data : void 0;
|
|
243
271
|
if (!data) continue;
|
|
244
|
-
if (type
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
272
|
+
if (!TERMINAL_EVENT_TYPES.has(String(event.type ?? ""))) continue;
|
|
273
|
+
const structured = coerceEnvelope(data.result ?? data.output ?? data.move ?? data);
|
|
274
|
+
if (structured) return structured;
|
|
275
|
+
const fromText = coerceEnvelope(extractFencedJson(moveText(data) ?? ""));
|
|
276
|
+
if (fromText) return fromText;
|
|
248
277
|
}
|
|
249
278
|
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
250
279
|
const event = events[i];
|
|
251
280
|
if (!event) continue;
|
|
252
281
|
const data = isRecord(event.data) ? event.data : void 0;
|
|
253
282
|
if (!data) continue;
|
|
254
|
-
const text =
|
|
283
|
+
const text = moveText(data);
|
|
255
284
|
if (!text) continue;
|
|
256
|
-
const
|
|
257
|
-
const coerced = coerceEnvelope(fenced);
|
|
285
|
+
const coerced = coerceEnvelope(extractFencedJson(text));
|
|
258
286
|
if (coerced) return coerced;
|
|
259
287
|
}
|
|
260
288
|
return void 0;
|
|
@@ -298,6 +326,89 @@ function reportLoopUsage(cost, result, source = "loop") {
|
|
|
298
326
|
cost.observeTokens({ input: result.tokenUsage.input, output: result.tokenUsage.output });
|
|
299
327
|
}
|
|
300
328
|
|
|
329
|
+
// src/loops/sandbox-acquire.ts
|
|
330
|
+
var RETRYABLE_HTTP = /* @__PURE__ */ new Set([502, 503, 504, 522, 524, 408, 425, 429]);
|
|
331
|
+
var TERMINAL_STATUS = /* @__PURE__ */ new Set(["failed", "expired", "stopped"]);
|
|
332
|
+
async function acquireSandbox(client, options, acquire = {}) {
|
|
333
|
+
if (!client || typeof client.create !== "function") {
|
|
334
|
+
throw new ValidationError("acquireSandbox: client.create is required");
|
|
335
|
+
}
|
|
336
|
+
const now = acquire.now ?? Date.now;
|
|
337
|
+
const sleep = acquire.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
338
|
+
const pollMs = acquire.pollIntervalMs ?? 3e3;
|
|
339
|
+
const deadline = now() + (acquire.readyTimeoutMs ?? 6e5);
|
|
340
|
+
const name = options.name ?? acquire.name ?? `loop-sbx-${randomSuffix()}`;
|
|
341
|
+
const createOpts = { ...options, name };
|
|
342
|
+
const c = client;
|
|
343
|
+
let lastErr;
|
|
344
|
+
let attempt = 0;
|
|
345
|
+
while (now() < deadline) {
|
|
346
|
+
throwIfAborted(acquire.signal);
|
|
347
|
+
try {
|
|
348
|
+
const box = await client.create(createOpts);
|
|
349
|
+
return await waitUntilReady(box, deadline, pollMs, acquire.signal, now, sleep);
|
|
350
|
+
} catch (err) {
|
|
351
|
+
throwIfAborted(acquire.signal);
|
|
352
|
+
if (!isRetryable(err)) throw err;
|
|
353
|
+
lastErr = err;
|
|
354
|
+
if (typeof c.list === "function") {
|
|
355
|
+
const found = (await c.list().catch(() => []))?.find((b) => b.name === name);
|
|
356
|
+
if (found) return await waitUntilReady(found, deadline, pollMs, acquire.signal, now, sleep);
|
|
357
|
+
}
|
|
358
|
+
attempt += 1;
|
|
359
|
+
await sleep(Math.min(pollMs * attempt, 15e3));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
throw new ValidationError(
|
|
363
|
+
`acquireSandbox: could not acquire a running sandbox "${name}" within budget`,
|
|
364
|
+
{ cause: lastErr instanceof Error ? lastErr : void 0 }
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
async function waitUntilReady(box, deadline, pollMs, signal, now, sleep) {
|
|
368
|
+
for (; ; ) {
|
|
369
|
+
throwIfAborted(signal);
|
|
370
|
+
const status = readStatus(box);
|
|
371
|
+
if (status === void 0 || status === "running") return box;
|
|
372
|
+
if (TERMINAL_STATUS.has(status)) {
|
|
373
|
+
throw new ValidationError(
|
|
374
|
+
`acquireSandbox: sandbox ${box.id ?? "(unknown)"} is ${status}${box.error ? `: ${box.error}` : ""}`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
if (now() >= deadline) {
|
|
378
|
+
throw new ValidationError(
|
|
379
|
+
`acquireSandbox: sandbox ${box.id ?? "(unknown)"} not running within budget (last status: ${status})`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
await sleep(pollMs);
|
|
383
|
+
if (typeof box.refresh === "function") await box.refresh();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function readStatus(box) {
|
|
387
|
+
const s = box.status;
|
|
388
|
+
return typeof s === "string" ? s : void 0;
|
|
389
|
+
}
|
|
390
|
+
function isRetryable(err) {
|
|
391
|
+
if (!err || typeof err !== "object") return false;
|
|
392
|
+
const e = err;
|
|
393
|
+
const status = e.status ?? e.statusCode;
|
|
394
|
+
if (typeof status === "number" && RETRYABLE_HTTP.has(status)) return true;
|
|
395
|
+
const name = e.name ?? "";
|
|
396
|
+
if (name === "TimeoutError" || name === "ServerError" || name === "NetworkError") return true;
|
|
397
|
+
return /\b(timed out|timeout|gateway|temporarily unavailable|ECONNRESET|ETIMEDOUT|EAI_AGAIN)\b/i.test(
|
|
398
|
+
e.message ?? ""
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
function throwIfAborted(signal) {
|
|
402
|
+
if (signal?.aborted) {
|
|
403
|
+
const err = new Error("aborted");
|
|
404
|
+
err.name = "AbortError";
|
|
405
|
+
throw err;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function randomSuffix(len = 10) {
|
|
409
|
+
return Math.random().toString(36).slice(2, 2 + len);
|
|
410
|
+
}
|
|
411
|
+
|
|
301
412
|
// src/loops/sandbox-events.ts
|
|
302
413
|
function extractLlmCallEvent(event, agentRunName) {
|
|
303
414
|
if (!event || typeof event !== "object") return void 0;
|
|
@@ -388,11 +499,16 @@ async function runLoop(options) {
|
|
|
388
499
|
throw new ValidationError("runLoop: ctx.sandboxClient.create is required");
|
|
389
500
|
}
|
|
390
501
|
const now = options.now ?? Date.now;
|
|
391
|
-
const runId = options.runId ?? `loop-${
|
|
502
|
+
const runId = options.runId ?? `loop-${randomSuffix2()}`;
|
|
392
503
|
const loopStart = now();
|
|
393
504
|
const driverName = options.driver.name ?? "driver";
|
|
394
505
|
const iterations = [];
|
|
395
506
|
let round = 0;
|
|
507
|
+
const ownedBoxes = [];
|
|
508
|
+
const collectBox = options.shareWorkerBox ? (box) => {
|
|
509
|
+
ownedBoxes.push(box);
|
|
510
|
+
options.shareWorkerBox?.(box);
|
|
511
|
+
} : void 0;
|
|
396
512
|
await emitTrace(options.ctx.traceEmitter, {
|
|
397
513
|
kind: "loop.started",
|
|
398
514
|
runId,
|
|
@@ -462,7 +578,8 @@ async function runLoop(options) {
|
|
|
462
578
|
runId,
|
|
463
579
|
now,
|
|
464
580
|
roundIndex,
|
|
465
|
-
parentIndex
|
|
581
|
+
parentIndex,
|
|
582
|
+
collectBox
|
|
466
583
|
});
|
|
467
584
|
if (controller.signal.aborted) throwAbort();
|
|
468
585
|
const decision2 = await options.driver.decide(iterations);
|
|
@@ -503,6 +620,8 @@ async function runLoop(options) {
|
|
|
503
620
|
return finalize({ options, decision, iterations, startMs: loopStart, now, runId });
|
|
504
621
|
} finally {
|
|
505
622
|
if (options.ctx.signal) options.ctx.signal.removeEventListener("abort", onOuterAbort);
|
|
623
|
+
for (const b of ownedBoxes) await destroySandboxSafe(b);
|
|
624
|
+
if (options.shareWorkerBox) options.shareWorkerBox(void 0);
|
|
506
625
|
}
|
|
507
626
|
}
|
|
508
627
|
async function runBatch(args) {
|
|
@@ -538,9 +657,10 @@ async function executeIteration(args) {
|
|
|
538
657
|
parentIndex: args.parentIndex
|
|
539
658
|
}
|
|
540
659
|
});
|
|
660
|
+
let box;
|
|
541
661
|
try {
|
|
542
|
-
|
|
543
|
-
const placement =
|
|
662
|
+
box = await createSandboxForSpec(args.ctx.sandboxClient, spec, args.signal);
|
|
663
|
+
const placement = describeSandboxPlacement(args.ctx.sandboxClient, box);
|
|
544
664
|
await emitTrace(args.ctx.traceEmitter, {
|
|
545
665
|
kind: "loop.iteration.dispatch",
|
|
546
666
|
runId: args.runId,
|
|
@@ -599,6 +719,15 @@ async function executeIteration(args) {
|
|
|
599
719
|
outputPreview: slot.output !== void 0 ? previewOutput(slot.output) : void 0
|
|
600
720
|
}
|
|
601
721
|
});
|
|
722
|
+
if (args.collectBox && box) args.collectBox(box);
|
|
723
|
+
else await destroySandboxSafe(box);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
async function destroySandboxSafe(box) {
|
|
727
|
+
if (!box || typeof box.delete !== "function") return;
|
|
728
|
+
try {
|
|
729
|
+
await box.delete();
|
|
730
|
+
} catch {
|
|
602
731
|
}
|
|
603
732
|
}
|
|
604
733
|
function branchPoint(iterations) {
|
|
@@ -624,7 +753,7 @@ function previewOutput(output) {
|
|
|
624
753
|
}
|
|
625
754
|
return s.length > 280 ? `${s.slice(0, 280)}\u2026` : s;
|
|
626
755
|
}
|
|
627
|
-
function
|
|
756
|
+
function describeSandboxPlacement(client, box) {
|
|
628
757
|
if (typeof client.describePlacement === "function") {
|
|
629
758
|
try {
|
|
630
759
|
const result = client.describePlacement(box);
|
|
@@ -658,7 +787,7 @@ async function createSandboxForSpec(client, spec, signal) {
|
|
|
658
787
|
}
|
|
659
788
|
};
|
|
660
789
|
if (signal.aborted) throwAbort();
|
|
661
|
-
return client
|
|
790
|
+
return acquireSandbox(client, opts, { signal });
|
|
662
791
|
}
|
|
663
792
|
function inferBackendType(profile) {
|
|
664
793
|
const explicit = profile.metadata?.backendType;
|
|
@@ -739,7 +868,7 @@ async function emitTrace(emitter, event) {
|
|
|
739
868
|
if (!emitter) return;
|
|
740
869
|
await emitter.emit(event);
|
|
741
870
|
}
|
|
742
|
-
function
|
|
871
|
+
function randomSuffix2(len = 8) {
|
|
743
872
|
return Math.random().toString(36).slice(2, 2 + len);
|
|
744
873
|
}
|
|
745
874
|
function throwAbort() {
|
|
@@ -799,15 +928,20 @@ function loopCampaignDispatch(opts) {
|
|
|
799
928
|
export {
|
|
800
929
|
createDynamicDriver,
|
|
801
930
|
summarizeHistory,
|
|
931
|
+
blind,
|
|
932
|
+
PROMPT_PLANNERS,
|
|
933
|
+
resolvePlanner,
|
|
802
934
|
createRefineDriver,
|
|
803
935
|
refineWinnerIndex,
|
|
804
936
|
createSandboxPlanner,
|
|
805
937
|
reportLoopUsage,
|
|
938
|
+
acquireSandbox,
|
|
806
939
|
extractLlmCallEvent,
|
|
807
940
|
mapSandboxEvent,
|
|
808
941
|
runLoop,
|
|
942
|
+
describeSandboxPlacement,
|
|
809
943
|
createSandboxForSpec,
|
|
810
944
|
loopDispatch,
|
|
811
945
|
loopCampaignDispatch
|
|
812
946
|
};
|
|
813
|
-
//# sourceMappingURL=chunk-
|
|
947
|
+
//# sourceMappingURL=chunk-S7JXV32P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loops/drivers/dynamic.ts","../src/loops/drivers/planners.ts","../src/loops/drivers/refine.ts","../src/loops/drivers/sandbox-planner.ts","../src/loops/report-usage.ts","../src/loops/sandbox-acquire.ts","../src/loops/sandbox-events.ts","../src/loops/run-loop.ts","../src/loops/loop-dispatch.ts"],"sourcesContent":["/**\n * @experimental\n *\n * Dynamic driver — the agent authors the loop topology at runtime.\n *\n * Where `refine` and `fanout-vote` encode a fixed shape as a pure function of\n * history, this driver delegates the per-round shape to an injected\n * `TopologyPlanner`. Each round the planner inspects the task + iteration\n * history and emits one `TopologyMove`:\n * - `refine` → one task next round (optionally rewritten from the prior attempt)\n * - `fanout` → N tasks next round (the kernel round-robins `agentRuns`, so a\n * 2-harness fanout dispatches branch 0 to harness A and branch 1 to harness B)\n * - `stop` → terminate; the kernel selects the winner across all iterations\n *\n * The planner is the brain; this driver is the structure. It maps moves onto\n * the kernel's `plan`/`decide` contract, enforces the iteration + fanout caps,\n * and fails loud on a malformed move. The planner is injected exactly like\n * `refine`'s `refineTask` and `fanout-vote`'s `selector` — so a test can drive\n * a deterministic policy through the real kernel, and production can wire it to\n * an LLM via `createSandboxPlanner`.\n *\n * Topology is orthogonal to harness: the planner never names a backend. Which\n * harness runs a branch is decided by the `AgentRunSpec` the kernel round-robins\n * to, so one dynamic driver works across claude-code, codex, opencode, pi —\n * including fanning a single round across several at once.\n */\n\nimport { PlannerError, ValidationError } from '../../errors'\nimport type { Driver, Iteration } from '../types'\n\n/** Terminal once `decide` returns `'done'` (a kernel terminal decision). */\nexport type DynamicDecision = 'continue' | 'done'\n\n/**\n * One topology decision for the next round. `fanout` carries explicit tasks\n * rather than a count so the planner can issue heterogeneous branches (a\n * different sub-task per harness); pass N copies of one task for a homogeneous\n * fanout that relies on `agentRuns` diversity instead.\n *\n * @experimental\n */\nexport type TopologyMove<Task> =\n | { kind: 'refine'; task: Task; rationale?: string; parentIndex?: number }\n | { kind: 'fanout'; tasks: Task[]; rationale?: string; parentIndex?: number }\n | { kind: 'stop'; rationale?: string }\n\n/** @experimental */\nexport interface PlannerContext<Task, Output> {\n /** The root task the loop was invoked with — stable across rounds. */\n task: Task\n /** Every iteration so far, in dispatch order, with outputs + verdicts. */\n history: ReadonlyArray<Iteration<Task, Output>>\n /** `history.length` — iterations already spent. */\n iterationsSpent: number\n /** Iterations left before the driver's `maxIterations` cap forces a stop. */\n iterationsRemaining: number\n}\n\n/**\n * Chooses the next topology move from the task + history. Sync or async; an\n * async planner is where an LLM call goes (see `createSandboxPlanner`).\n *\n * @experimental\n */\nexport type TopologyPlanner<Task, Output> = (\n ctx: PlannerContext<Task, Output>,\n) => TopologyMove<Task> | Promise<TopologyMove<Task>>\n\n/** @experimental */\nexport interface CreateDynamicDriverOptions<Task, Output> {\n /** The agent-authored topology policy. Invoked once per round in `plan`. */\n planner: TopologyPlanner<Task, Output>\n /**\n * Hard safety cap on total iterations. When reached, the driver stops before\n * consulting the planner. Default 8. Set the kernel's `runLoop`\n * `maxIterations >= ` this so the driver's cap governs and the loop closes on\n * a clean `'done'` rather than a truncated `'continue'`.\n */\n maxIterations?: number\n /** Max branches a single `fanout` move may dispatch. Default 4. */\n maxFanout?: number\n /** Stable identifier surfaced in trace events. Default `'dynamic'`. */\n name?: string\n}\n\n/** @experimental */\nexport function createDynamicDriver<Task, Output>(\n options: CreateDynamicDriverOptions<Task, Output>,\n): Driver<Task, Output, DynamicDecision> {\n if (typeof options.planner !== 'function') {\n throw new ValidationError('createDynamicDriver: planner must be a function')\n }\n const maxIterations = options.maxIterations ?? 8\n if (!Number.isFinite(maxIterations) || maxIterations <= 0) {\n throw new ValidationError('createDynamicDriver: maxIterations must be > 0')\n }\n const maxFanout = options.maxFanout ?? 4\n if (!Number.isFinite(maxFanout) || maxFanout < 1) {\n throw new ValidationError('createDynamicDriver: maxFanout must be >= 1')\n }\n\n // The kernel calls plan(), runs the batch, then calls decide() — strictly\n // sequential, one driver instance per loop. Caching the move the planner\n // chose this round lets decide() report terminality without re-invoking the\n // planner (which would double every LLM call).\n let pending: TopologyMove<Task> | undefined\n\n return {\n name: options.name ?? 'dynamic',\n async plan(task, history) {\n if (history.length >= maxIterations) {\n pending = { kind: 'stop', rationale: `maxIterations (${maxIterations}) reached` }\n return []\n }\n const move = await options.planner({\n task,\n history,\n iterationsSpent: history.length,\n iterationsRemaining: maxIterations - history.length,\n })\n pending = validateMove(move, maxFanout)\n switch (pending.kind) {\n case 'refine':\n return [pending.task]\n case 'fanout':\n return pending.tasks\n case 'stop':\n return []\n }\n },\n decide() {\n // pending is set by the plan() call that immediately precedes every\n // decide(). Only a `stop` move terminates; refine/fanout keep looping so\n // plan() — and thus the planner — runs again next round.\n return pending?.kind === 'stop' ? 'done' : 'continue'\n },\n describePlan() {\n // Surface the move the planner just chose (kind + rationale + an optional\n // DECLARED branch source) so the kernel's loop.plan trace carries the\n // agent's intent — including faithful edge lineage when the planner\n // branched off a specific (non-winner) iteration. `pending` is the move\n // set by the preceding plan().\n if (!pending) return undefined\n const out: { kind: string; rationale?: string; parentIndex?: number } = { kind: pending.kind }\n if (pending.rationale !== undefined) out.rationale = pending.rationale\n if (pending.kind !== 'stop' && pending.parentIndex !== undefined) {\n out.parentIndex = pending.parentIndex\n }\n return out\n },\n }\n}\n\nfunction validateMove<Task>(move: TopologyMove<Task>, maxFanout: number): TopologyMove<Task> {\n if (!move || typeof move !== 'object' || typeof (move as { kind?: unknown }).kind !== 'string') {\n throw new PlannerError(`dynamic planner returned a non-move value: ${describe(move)}`)\n }\n switch (move.kind) {\n case 'refine':\n return move\n case 'stop':\n return move\n case 'fanout': {\n if (!Array.isArray(move.tasks) || move.tasks.length === 0) {\n throw new PlannerError('dynamic planner fanout move must carry a non-empty tasks[]')\n }\n if (move.tasks.length <= maxFanout) return move\n // Clamp rather than reject — over-fanning is a budget concern, not a\n // structural error. The clamp is recorded in the rationale for traces.\n return {\n kind: 'fanout',\n tasks: move.tasks.slice(0, maxFanout),\n rationale: `${move.rationale ?? ''} [clamped ${move.tasks.length}→${maxFanout}]`.trim(),\n }\n }\n default:\n throw new PlannerError(\n `dynamic planner returned unknown move kind: ${describe((move as { kind: unknown }).kind)}`,\n )\n }\n}\n\nfunction describe(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Compact, planner-friendly view of iteration history — what an LLM planner\n * needs to choose the next move without the raw event streams. Output is\n * truncated so a long run's prompt stays bounded.\n *\n * @experimental\n */\nexport function summarizeHistory<Task, Output>(\n history: ReadonlyArray<Iteration<Task, Output>>,\n opts: { maxOutputChars?: number } = {},\n): Array<{\n index: number\n agentRunName: string\n valid?: boolean\n score?: number\n error?: string\n output?: string\n}> {\n const maxOutputChars = opts.maxOutputChars ?? 600\n return history.map((iter) => {\n const row: {\n index: number\n agentRunName: string\n valid?: boolean\n score?: number\n error?: string\n output?: string\n } = { index: iter.index, agentRunName: iter.agentRunName }\n if (iter.verdict) {\n row.valid = iter.verdict.valid\n if (typeof iter.verdict.score === 'number') row.score = iter.verdict.score\n }\n if (iter.error) row.error = iter.error.message\n if (iter.output !== undefined) {\n const serialized = describe(iter.output)\n row.output =\n serialized.length > maxOutputChars ? `${serialized.slice(0, maxOutputChars)}…` : serialized\n }\n return row\n })\n}\n","/**\n * @experimental\n *\n * Named driver policies — a registry, not a constructor zoo.\n *\n * A \"driver variant\" is just a `TopologyPlanner` chosen by name and run by the\n * one interpreter (`createDynamicDriver`). The agentic variants are sandboxed\n * agents (`createSandboxPlanner`) — an LLM/agent in a box that emits the next\n * move; this registry holds the *deterministic* ones a benchmark needs as\n * controls. Today that's `blind`: a single attempt, no steering — the baseline\n * you measure a real driver against.\n *\n * Adding a variant is a line here (or a sandboxed planner registered by name),\n * never a new `createXDriver` factory and never a spec schema.\n */\n\nimport type { TopologyMove, TopologyPlanner } from './dynamic'\n\n/** A driver policy over prompt-shaped (string) tasks. Output is consulted only\n * through the iteration's verdict, so it stays `unknown`. */\nexport type PromptPlanner = TopologyPlanner<string, unknown>\n\n/**\n * `blind` — one attempt, then stop. The no-driver control: a single worker run\n * with no steering, so a benchmark can isolate what a real driver adds.\n */\nexport const blind: PromptPlanner = ({ task, history }): TopologyMove<string> =>\n history.length === 0\n ? { kind: 'refine', task, rationale: 'blind: single attempt' }\n : { kind: 'stop', rationale: 'blind: one attempt only' }\n\n/** The registry. Pick a driver by name (e.g. `DRIVER=blind`); fail loud on an\n * unknown key. Sandboxed-agent planners can be registered here too. */\nexport const PROMPT_PLANNERS: Record<string, PromptPlanner> = {\n blind,\n}\n\n/** Resolve a planner by name; fail loud on an unknown variant. */\nexport function resolvePlanner(name: string): PromptPlanner {\n const planner = PROMPT_PLANNERS[name]\n if (!planner) {\n throw new Error(\n `planners: unknown driver '${name}' (have: ${Object.keys(PROMPT_PLANNERS).join(', ')})`,\n )\n }\n return planner\n}\n","/**\n * @experimental\n *\n * Refine driver — single task per iteration, validator-gated.\n *\n * `plan` returns `[task]` (possibly transformed via `refineTask`) until the\n * prior verdict is valid OR the local cap is hit, then `[]`.\n * `decide` returns `'stop'` once the latest verdict is valid OR the cap is\n * reached. The kernel's `maxIterations` is an orthogonal safety cap;\n * whichever is lower wins.\n */\n\nimport { ValidationError } from '../../errors'\nimport type { DefaultVerdict, Driver, Iteration } from '../types'\n\nexport type RefineDecision = 'continue' | 'stop'\n\n/** @experimental */\nexport interface CreateRefineDriverOptions<Task> {\n /** Hard cap on iterations. Default 5. */\n maxIterations?: number\n /**\n * Optional task transform applied each round based on the prior verdict.\n * When omitted, the same task is replayed and the agent is expected to\n * inspect the sandbox session state for prior attempts.\n */\n refineTask?: (task: Task, prior: DefaultVerdict) => Task\n /** Stable identifier surfaced in trace events. Default `'refine'`. */\n name?: string\n}\n\n/** @experimental */\nexport function createRefineDriver<Task, Output>(\n options: CreateRefineDriverOptions<Task> = {},\n): Driver<Task, Output, RefineDecision> {\n const maxIterations = options.maxIterations ?? 5\n if (!Number.isFinite(maxIterations) || maxIterations <= 0) {\n throw new ValidationError('createRefineDriver: maxIterations must be > 0')\n }\n const refineTask = options.refineTask\n return {\n name: options.name ?? 'refine',\n async plan(task, history) {\n if (history.length >= maxIterations) return []\n if (history.length === 0) return [task]\n const prior = history.at(-1)\n if (!prior) return [task]\n if (prior.verdict?.valid === true) return []\n // Worker error: replay the same task so the agent can self-correct.\n // The driver has no signal beyond `verdict`; only the validator\n // controls \"good enough\".\n if (!refineTask || !prior.verdict) return [prior.task]\n return [refineTask(prior.task, prior.verdict)]\n },\n decide(history) {\n const last = history.at(-1)\n if (!last) return 'continue'\n if (last.verdict?.valid === true) return 'stop'\n if (history.length >= maxIterations) return 'stop'\n return 'continue'\n },\n }\n}\n\n/**\n * Test helper: select the last-valid iteration (or the last attempt if\n * none passed). Mirrors the kernel's default selector ordering for refine\n * topologies — the most recent successful attempt wins.\n *\n * @experimental\n */\nexport function refineWinnerIndex<Task, Output>(\n iterations: ReadonlyArray<Iteration<Task, Output>>,\n): number | undefined {\n for (let i = iterations.length - 1; i >= 0; i -= 1) {\n if (iterations[i]?.verdict?.valid) return i\n }\n return iterations.length > 0 ? iterations.length - 1 : undefined\n}\n","/**\n * @experimental\n *\n * `createSandboxPlanner` — wire the dynamic driver's `TopologyPlanner` to a\n * real agent. Each round it spins a sandbox on `profile`, streams a prompt that\n * carries the history summary, and decodes the agent's chosen `TopologyMove`\n * from a JSON envelope it emits. This is the \"agent authors its own loop\n * topology\" path: the planner profile can be any harness (claude-code, codex,\n * opencode, pi) — its only job is to read what happened and emit the next move.\n *\n * The planner profile is deliberately distinct from the worker `agentRuns`: a\n * cheap fast model can steer topology while expensive workers do the labor, and\n * the planner never names which harness runs a branch — the kernel's\n * `agentRuns` round-robin decides that.\n *\n * Three execution modes, all the same code path:\n * - LLM call — a cheap-model `profile`; one prompt → one move.\n * - different sandbox (default) — a fresh planner-owned box per round.\n * - same sandbox — pass `reuseBox` to stream the move into the worker's\n * own box (a session against its live filesystem/state),\n * so the driver steers from what the worker actually did.\n *\n * Envelope contract the agent must emit (fenced ```json or a structured\n * `result`/`final` event payload):\n * { \"kind\": \"refine\" | \"fanout\" | \"stop\",\n * \"tasks\"?: [ <task>, ... ], // decoded via `decodeTask`\n * \"n\"?: number, // fanout shorthand: N copies of the root task\n * \"rationale\"?: string }\n *\n * A missing / unparseable / unknown-kind envelope throws `PlannerError` — the\n * loop never silently runs a topology the agent did not choose.\n */\n\nimport type {\n AgentProfile,\n CreateSandboxOptions,\n SandboxEvent,\n SandboxInstance,\n} from '@tangle-network/sandbox'\nimport { PlannerError, ValidationError } from '../../errors'\nimport type { AgentRunSpec, LoopSandboxClient } from '../types'\nimport type { PlannerContext, TopologyMove, TopologyPlanner } from './dynamic'\nimport { summarizeHistory } from './dynamic'\n\n/** Raw, pre-decode envelope an agent emits to choose the next move. */\nexport interface TopologyMoveEnvelope {\n kind: string\n tasks?: unknown[]\n n?: number\n rationale?: string\n}\n\n/** @experimental */\nexport interface CreateSandboxPlannerOptions<Task, Output> {\n /** Sandbox client — the planner calls `.create()` once per round. */\n client: LoopSandboxClient\n /** The planner agent. Steers topology; does not run the work. */\n profile: AgentProfile\n /**\n * Decode one raw task from the envelope's `tasks[]` into a domain `Task`.\n * Required because `Task` is opaque to this module — only the caller knows\n * its shape. Throw to reject a malformed task; the error surfaces as a\n * `PlannerError`.\n */\n decodeTask: (raw: unknown, ctx: PlannerContext<Task, Output>) => Task\n /** Override the default prompt (history summary + envelope contract). */\n buildPrompt?: (ctx: PlannerContext<Task, Output>) => string | Promise<string>\n /** Override envelope extraction from the event stream. */\n parseEnvelope?: (events: SandboxEvent[]) => TopologyMoveEnvelope | undefined\n /** Sandbox overrides for the planner sandbox (timeouts, env, etc.). */\n sandboxOverrides?: AgentRunSpec<Task>['sandboxOverrides']\n /** Cancellation for the planner's own LLM call. */\n signal?: AbortSignal\n /**\n * Same-sandbox mode. Return an existing box and the planner streams its move\n * INTO that box (a session against the worker's environment) instead of\n * spinning its own — so the driver can inspect the worker's real filesystem\n * and state, not just the history summary. The returned box's lifecycle is\n * the CALLER's: the planner neither creates nor deletes it. Return\n * `undefined` to fall back to the default (a fresh, planner-owned box =\n * different-sandbox mode). Omit entirely for the default.\n */\n reuseBox?: () => SandboxInstance | undefined | Promise<SandboxInstance | undefined>\n}\n\n/** @experimental */\nexport function createSandboxPlanner<Task, Output>(\n opts: CreateSandboxPlannerOptions<Task, Output>,\n): TopologyPlanner<Task, Output> {\n if (!opts.client || typeof opts.client.create !== 'function') {\n throw new ValidationError('createSandboxPlanner: client.create is required')\n }\n if (typeof opts.decodeTask !== 'function') {\n throw new ValidationError('createSandboxPlanner: decodeTask is required')\n }\n const buildPrompt = opts.buildPrompt ?? defaultBuildPrompt\n const parseEnvelope = opts.parseEnvelope ?? defaultParseEnvelope\n\n return async (ctx) => {\n // Same-sandbox mode: reuse the caller-owned box; else spin a planner-owned one.\n const reused = opts.reuseBox ? await opts.reuseBox() : undefined\n const box =\n reused ?? (await opts.client.create(buildSandboxOptions(opts.profile, opts.sandboxOverrides)))\n const plannerOwnsBox = reused === undefined\n try {\n const prompt = await buildPrompt(ctx)\n const events: SandboxEvent[] = []\n for await (const event of box.streamPrompt(prompt, { signal: opts.signal })) {\n events.push(event)\n }\n const envelope = parseEnvelope(events)\n if (!envelope) {\n throw new PlannerError('sandbox planner emitted no parseable topology-move envelope')\n }\n return envelopeToMove(envelope, ctx, opts.decodeTask)\n } finally {\n // Tear down only a box WE created (one per plan() round, so it doesn't\n // leak). A reused (same-sandbox) box belongs to the caller — never delete it.\n if (plannerOwnsBox) {\n try {\n if (typeof (box as { delete?: unknown }).delete === 'function') await box.delete()\n } catch {\n // ignore — platform reaps on expiry\n }\n }\n }\n }\n}\n\nfunction envelopeToMove<Task, Output>(\n envelope: TopologyMoveEnvelope,\n ctx: PlannerContext<Task, Output>,\n decodeTask: (raw: unknown, ctx: PlannerContext<Task, Output>) => Task,\n): TopologyMove<Task> {\n const kind = String(envelope.kind ?? '').toLowerCase()\n const rationale = typeof envelope.rationale === 'string' ? envelope.rationale : undefined\n if (kind === 'stop') {\n return { kind: 'stop', rationale }\n }\n if (kind === 'refine') {\n const raw = Array.isArray(envelope.tasks) ? envelope.tasks[0] : undefined\n // No new task → replay the root task; the worker self-corrects from its\n // own prior attempt in sandbox state, mirroring the refine driver default.\n const task = raw === undefined ? ctx.task : decodeTaskGuarded(decodeTask, raw, ctx)\n return { kind: 'refine', task, rationale }\n }\n if (kind === 'fanout') {\n const tasks = resolveFanoutTasks(envelope, ctx, decodeTask)\n return { kind: 'fanout', tasks, rationale }\n }\n throw new PlannerError(\n `sandbox planner emitted unknown move kind: ${JSON.stringify(envelope.kind)}`,\n )\n}\n\nfunction resolveFanoutTasks<Task, Output>(\n envelope: TopologyMoveEnvelope,\n ctx: PlannerContext<Task, Output>,\n decodeTask: (raw: unknown, ctx: PlannerContext<Task, Output>) => Task,\n): Task[] {\n if (Array.isArray(envelope.tasks) && envelope.tasks.length > 0) {\n return envelope.tasks.map((raw) => decodeTaskGuarded(decodeTask, raw, ctx))\n }\n // `n` shorthand: N copies of the root task, leaning on `agentRuns` diversity.\n if (typeof envelope.n === 'number' && Number.isFinite(envelope.n) && envelope.n >= 1) {\n return Array.from({ length: Math.floor(envelope.n) }, () => ctx.task)\n }\n throw new PlannerError('sandbox planner fanout envelope needs a non-empty tasks[] or n >= 1')\n}\n\nfunction decodeTaskGuarded<Task, Output>(\n decodeTask: (raw: unknown, ctx: PlannerContext<Task, Output>) => Task,\n raw: unknown,\n ctx: PlannerContext<Task, Output>,\n): Task {\n try {\n return decodeTask(raw, ctx)\n } catch (err) {\n throw new PlannerError(`sandbox planner decodeTask rejected ${JSON.stringify(raw)}`, {\n cause: err,\n })\n }\n}\n\nfunction buildSandboxOptions(\n profile: AgentProfile,\n overrides: AgentRunSpec<unknown>['sandboxOverrides'],\n): CreateSandboxOptions {\n const base = overrides ?? {}\n const overrideBackend = base.backend\n const explicitType = profile.metadata?.backendType\n type BackendType = NonNullable<CreateSandboxOptions['backend']>['type']\n return {\n ...base,\n backend: {\n type: (overrideBackend?.type ?? explicitType ?? 'opencode') as BackendType,\n profile,\n ...(overrideBackend?.model ? { model: overrideBackend.model } : {}),\n ...(overrideBackend?.server ? { server: overrideBackend.server } : {}),\n },\n }\n}\n\nfunction defaultBuildPrompt<Task, Output>(ctx: PlannerContext<Task, Output>): string {\n const summary = summarizeHistory(ctx.history)\n return [\n 'You are the loop planner. You do not do the work — you decide the topology of the next round.',\n '',\n `Root task:\\n${safeJson(ctx.task)}`,\n '',\n `Iterations spent: ${ctx.iterationsSpent}. Remaining before the hard cap: ${ctx.iterationsRemaining}.`,\n '',\n ctx.history.length === 0\n ? 'No attempts yet.'\n : `Attempts so far (index, agent, verdict, output):\\n${safeJson(summary)}`,\n '',\n 'Choose ONE move and emit it as a fenced JSON block:',\n ' - {\"kind\":\"refine\",\"tasks\":[<task>],\"rationale\":\"...\"} — one more attempt; omit tasks to replay the root task.',\n ' - {\"kind\":\"fanout\",\"tasks\":[<task>,<task>],\"rationale\":\"...\"} — N parallel branches (or \"n\": N for N copies of the root task).',\n ' - {\"kind\":\"stop\",\"rationale\":\"...\"} — a valid result exists or further attempts will not help.',\n '',\n 'Stop as soon as an attempt is valid. Prefer refine when an attempt is close; fan out when attempts disagree or the approach is uncertain.',\n 'Emit ONLY the JSON block.',\n ].join('\\n')\n}\n\nconst TERMINAL_EVENT_TYPES = new Set(['result', 'final', 'planner.move', 'done'])\n\n/**\n * Harness-agnostic move extraction. The move arrives one of two ways and we must\n * not assume which harness/SDK-version we're on (opencode emits `data.finalText`,\n * others `data.result`/`data.text`/…) — so we cover all text-bearing fields and\n * prefer (1) a STRUCTURED payload, then (2) a fenced move in a TERMINAL event's\n * final text, then (3) the latest schema-valid fenced/bare envelope anywhere.\n * Reverse iteration is load-bearing: the agent's real move is the LAST envelope\n * emitted; the JSON *examples* echoed from the prompt appear earlier, so latest-\n * first never mistakes an example for the answer.\n *\n * The reliable long-term path is a structured-output tool the planner CALLS (no\n * prose scraping at all); this text extractor is the resilient fallback for\n * harnesses without one.\n */\nfunction defaultParseEnvelope(events: SandboxEvent[]): TopologyMoveEnvelope | undefined {\n const moveText = (data: Record<string, unknown>): string | undefined =>\n pickString(data.finalText) ??\n pickString(data.text) ??\n pickString(data.delta) ??\n pickString(data.content) ??\n pickString(data.message)\n\n // 1) Terminal events, latest first: structured payload, else a fenced move in the final text.\n for (let i = events.length - 1; i >= 0; i -= 1) {\n const event = events[i]\n if (!event) continue\n const data = isRecord(event.data) ? event.data : undefined\n if (!data) continue\n if (!TERMINAL_EVENT_TYPES.has(String(event.type ?? ''))) continue\n const structured = coerceEnvelope(data.result ?? data.output ?? data.move ?? data)\n if (structured) return structured\n const fromText = coerceEnvelope(extractFencedJson(moveText(data) ?? ''))\n if (fromText) return fromText\n }\n // 2) Any text-bearing event, latest first: the last schema-valid fenced/bare envelope.\n for (let i = events.length - 1; i >= 0; i -= 1) {\n const event = events[i]\n if (!event) continue\n const data = isRecord(event.data) ? event.data : undefined\n if (!data) continue\n const text = moveText(data)\n if (!text) continue\n const coerced = coerceEnvelope(extractFencedJson(text))\n if (coerced) return coerced\n }\n return undefined\n}\n\nfunction coerceEnvelope(value: unknown): TopologyMoveEnvelope | undefined {\n if (!isRecord(value)) return undefined\n if (typeof value.kind !== 'string' || value.kind.length === 0) return undefined\n const out: TopologyMoveEnvelope = { kind: value.kind }\n if (Array.isArray(value.tasks)) out.tasks = value.tasks\n if (typeof value.n === 'number') out.n = value.n\n if (typeof value.rationale === 'string') out.rationale = value.rationale\n return out\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction pickString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction extractFencedJson(text: string): unknown | undefined {\n const match = text.match(/```(?:json)?\\s*([\\s\\S]*?)```/i)\n const body = (match?.[1] ?? text).trim()\n if (!body) return undefined\n try {\n return JSON.parse(body)\n } catch {\n return undefined\n }\n}\n\nfunction safeJson(value: unknown): string {\n try {\n return JSON.stringify(value, null, 2) ?? String(value)\n } catch {\n return String(value)\n }\n}\n","/**\n * Bridge a finished `runLoop` into an agent-eval campaign / profile-matrix\n * dispatch.\n *\n * `runProfileMatrix` (and `runCampaign`) run the backend-integrity guard over\n * the token usage a dispatch reports through `ctx.cost`. A dispatch that wraps\n * `runLoop` must forward the loop's cost AND token usage, or the guard reads\n * the run as a stub and throws. `reportLoopUsage` is that one line:\n *\n * const dispatch: ProfileDispatchFn<S, A> = async (profile, scenario, ctx) => {\n * const result = await runLoop({ ...optsFor(profile, scenario), ctx: loopCtx })\n * reportLoopUsage(ctx, result)\n * return result.winner?.output as A\n * }\n *\n * Typed structurally against the campaign `DispatchContext.cost` so this module\n * stays free of an agent-eval import — it works with any cost meter exposing\n * `observe` + `observeTokens`.\n */\n\nimport type { LoopResult } from './types'\n\n/** The slice of an agent-eval campaign `DispatchContext.cost` this needs. */\nexport interface UsageSink {\n observe(amountUsd: number, source: string): void\n observeTokens(usage: { input: number; output: number }): void\n}\n\n/**\n * Forward a `LoopResult`'s aggregated cost + token usage into a campaign cost\n * meter so the backend-integrity guard sees real LLM activity. `source`\n * defaults to `'loop'`.\n */\nexport function reportLoopUsage<Task, Output, Decision>(\n cost: UsageSink,\n result: Pick<LoopResult<Task, Output, Decision>, 'costUsd' | 'tokenUsage'>,\n source = 'loop',\n): void {\n cost.observe(result.costUsd, source)\n cost.observeTokens({ input: result.tokenUsage.input, output: result.tokenUsage.output })\n}\n","/**\n * @experimental\n *\n * `acquireSandbox` — cold-start-resilient sandbox acquisition. Eliminates the\n * \"create timed out at the proxy\" failure mode conceptually by DECOUPLING \"the\n * create HTTP call returned\" from \"the sandbox is ready\":\n *\n * - Create is initiated with a known `name`.\n * - Readiness is observed from the sandbox's own `status` (`refresh()` polls\n * true state), NOT from whether the create call returned in time.\n * - If the create call itself times out at a gateway (502/503/504/522/524 or\n * a transport timeout), provisioning is still running server-side — so we\n * find the named sandbox via `list()` and wait for it to reach `running`.\n *\n * Result: a scale-from-zero cold start (node boot + host-agent registration,\n * minutes) can no longer surface as a create failure behind a ~100s proxy\n * limit. The loop becomes indifferent to whether the host pool is warm or cold.\n *\n * Backward-compatible: an instance that reports no `status` (the minimal fakes\n * the loop tests use) is treated as ready — only an explicit `pending`/\n * `provisioning` status triggers waiting, and only a retryable THROW triggers\n * the find-by-name path. Real errors (auth, validation, budget) fail loud.\n */\n\nimport type { CreateSandboxOptions, SandboxInstance } from '@tangle-network/sandbox'\nimport { ValidationError } from '../errors'\nimport type { LoopSandboxClient } from './types'\n\n/** Gateway/transport statuses where the create call returned but provisioning continues. */\nconst RETRYABLE_HTTP = new Set([502, 503, 504, 522, 524, 408, 425, 429])\nconst TERMINAL_STATUS = new Set(['failed', 'expired', 'stopped'])\n\n/** @experimental */\nexport interface AcquireOptions {\n /**\n * Total budget for the sandbox to reach `running`, covering on-demand node\n * cold-start. Default 600_000ms — matches the orchestrator's pending-host\n * registration window so we never give up before the platform itself would.\n */\n readyTimeoutMs?: number\n /** Poll interval while waiting for `running` / for the named sandbox to appear. */\n pollIntervalMs?: number\n /** Cancellation (user abort). Distinct from create-call timeouts. */\n signal?: AbortSignal\n /** Stamp a name so a timed-out create is recoverable by lookup. Auto-generated if absent. */\n name?: string\n /** Clock override for deterministic tests. */\n now?: () => number\n /** Sleep override for deterministic tests. */\n sleep?: (ms: number) => Promise<void>\n}\n\n/** Minimal client surface acquire needs beyond `create` (the real SDK satisfies it). */\ninterface PollableClient extends LoopSandboxClient {\n list?: (options?: unknown) => Promise<SandboxInstance[]>\n get?: (id: string) => Promise<SandboxInstance | null>\n}\n\n/** @experimental */\nexport async function acquireSandbox(\n client: LoopSandboxClient,\n options: CreateSandboxOptions,\n acquire: AcquireOptions = {},\n): Promise<SandboxInstance> {\n if (!client || typeof client.create !== 'function') {\n throw new ValidationError('acquireSandbox: client.create is required')\n }\n const now = acquire.now ?? Date.now\n const sleep = acquire.sleep ?? ((ms: number) => new Promise((r) => setTimeout(r, ms)))\n const pollMs = acquire.pollIntervalMs ?? 3000\n const deadline = now() + (acquire.readyTimeoutMs ?? 600_000)\n const name = options.name ?? acquire.name ?? `loop-sbx-${randomSuffix()}`\n const createOpts: CreateSandboxOptions = { ...options, name }\n const c = client as PollableClient\n\n let lastErr: unknown\n let attempt = 0\n while (now() < deadline) {\n throwIfAborted(acquire.signal)\n try {\n const box = await client.create(createOpts)\n return await waitUntilReady(box, deadline, pollMs, acquire.signal, now, sleep)\n } catch (err) {\n throwIfAborted(acquire.signal)\n // Non-retryable (auth/validation/budget) fails loud immediately.\n if (!isRetryable(err)) throw err\n lastErr = err\n // Two recoveries for a gateway-timed-out create, in order:\n // (a) some orchestrators leave a pending sandbox behind — attach to it;\n // (b) others roll the create back — so retry create with backoff (a\n // retry lands once a warm host exists / the autoscaler caught up).\n if (typeof c.list === 'function') {\n const found = (await c.list().catch(() => []))?.find((b) => b.name === name)\n if (found) return await waitUntilReady(found, deadline, pollMs, acquire.signal, now, sleep)\n }\n attempt += 1\n await sleep(Math.min(pollMs * attempt, 15_000))\n }\n }\n throw new ValidationError(\n `acquireSandbox: could not acquire a running sandbox \"${name}\" within budget`,\n { cause: lastErr instanceof Error ? lastErr : undefined },\n )\n}\n\n/** Wait for `running`. No status (minimal fakes) = ready. Terminal status throws. */\nasync function waitUntilReady(\n box: SandboxInstance,\n deadline: number,\n pollMs: number,\n signal: AbortSignal | undefined,\n now: () => number,\n sleep: (ms: number) => Promise<void>,\n): Promise<SandboxInstance> {\n for (;;) {\n throwIfAborted(signal)\n const status = readStatus(box)\n if (status === undefined || status === 'running') return box\n if (TERMINAL_STATUS.has(status)) {\n throw new ValidationError(\n `acquireSandbox: sandbox ${box.id ?? '(unknown)'} is ${status}${box.error ? `: ${box.error}` : ''}`,\n )\n }\n if (now() >= deadline) {\n throw new ValidationError(\n `acquireSandbox: sandbox ${box.id ?? '(unknown)'} not running within budget (last status: ${status})`,\n )\n }\n await sleep(pollMs)\n if (typeof box.refresh === 'function') await box.refresh()\n }\n}\n\nfunction readStatus(box: SandboxInstance): string | undefined {\n const s = (box as { status?: unknown }).status\n return typeof s === 'string' ? s : undefined\n}\n\nfunction isRetryable(err: unknown): boolean {\n if (!err || typeof err !== 'object') return false\n const e = err as { status?: number; statusCode?: number; name?: string; message?: string }\n const status = e.status ?? e.statusCode\n if (typeof status === 'number' && RETRYABLE_HTTP.has(status)) return true\n const name = e.name ?? ''\n if (name === 'TimeoutError' || name === 'ServerError' || name === 'NetworkError') return true\n return /\\b(timed out|timeout|gateway|temporarily unavailable|ECONNRESET|ETIMEDOUT|EAI_AGAIN)\\b/i.test(\n e.message ?? '',\n )\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) {\n const err = new Error('aborted')\n err.name = 'AbortError'\n throw err\n }\n}\n\nfunction randomSuffix(len = 10): string {\n return Math.random()\n .toString(36)\n .slice(2, 2 + len)\n}\n","/**\n * Sandbox-event → runtime-event mapping.\n *\n * The sandbox SDK emits a polymorphic `SandboxEvent = { type, data, id? }`\n * whose `type` vocabulary is backend-determined (opencode, etc.) rather than\n * enumerated by the SDK. Two consumers project it:\n * - the loop kernel's cost ledger (`extractLlmCallEvent`) — sums usage off\n * every cost-bearing event, regardless of stream shape;\n * - the `AgentRuntime.act` streaming contract (`mapSandboxEvent`) — projects\n * incremental events to the `RuntimeStreamEvent` chat-UX vocabulary.\n *\n * Both live here so the empirically-observed `type` vocabulary has one home.\n */\n\nimport type { SandboxEvent } from '@tangle-network/sandbox'\nimport type { RuntimeStreamEvent } from '../types'\n\n/**\n * Extract a `RuntimeStreamEvent`-shaped `llm_call` from a sandbox event when\n * the event carries usage/cost data. Returns `undefined` for non-cost events\n * so the kernel can iterate the full stream without branching.\n *\n * Canonical cost-carrying types observed in the wild:\n * - `llm_call` — `data: { model, tokensIn, tokensOut, costUsd, ... }`\n * - `message.completed` / `result` — `data: { usage: { inputTokens,\n * outputTokens, totalCostUsd? } }`\n * - `cost.usage` / `usage` — same shape under a dedicated type\n *\n * Numeric coercion is strict: `Number.isFinite` gates every accumulator write\n * so a sentinel `NaN` from a misbehaving backend cannot poison the ledger.\n */\nexport function extractLlmCallEvent(\n event: SandboxEvent,\n agentRunName: string,\n): (RuntimeStreamEvent & { type: 'llm_call' }) | undefined {\n if (!event || typeof event !== 'object') return undefined\n const type = String(event.type ?? '')\n const data =\n event.data && typeof event.data === 'object'\n ? (event.data as Record<string, unknown>)\n : ({} as Record<string, unknown>)\n\n if (type === 'llm_call' || type === 'cost.usage' || type === 'usage') {\n return buildLlmCall(data, agentRunName)\n }\n if (type === 'message.completed' || type === 'result' || type === 'final') {\n const usage = data.usage as Record<string, unknown> | undefined\n if (!usage || typeof usage !== 'object') return undefined\n return buildLlmCall({ ...usage, model: data.model ?? usage.model }, agentRunName)\n }\n // sandbox 0.4.0 terminal event: `data = { tokenUsage: { inputTokens, outputTokens,\n // reasoningTokens, cacheReadInputTokens }, totalCostUsd }`. Usage lives under\n // `tokenUsage` (not `usage`) and the cost is top-level — neither matched the\n // branches above, so an in-process loopDispatch run reported {0,0} and the\n // backend-integrity guard misread a real run as a stub. Reasoning tokens are\n // billed output (reasoning models), so they fold into the output count.\n if (type === 'done') {\n const usage = data.tokenUsage as Record<string, unknown> | undefined\n if (!usage || typeof usage !== 'object') return undefined\n const out = pickFiniteNumber(usage, ['outputTokens', 'completion_tokens', 'tokensOut'])\n const reasoning = pickFiniteNumber(usage, ['reasoningTokens'])\n const mergedOut =\n out !== undefined || reasoning !== undefined ? (out ?? 0) + (reasoning ?? 0) : undefined\n return buildLlmCall(\n {\n inputTokens: usage.inputTokens,\n outputTokens: mergedOut,\n totalCostUsd: data.totalCostUsd,\n model: data.model ?? usage.model,\n },\n agentRunName,\n )\n }\n return undefined\n}\n\nfunction buildLlmCall(\n data: Record<string, unknown>,\n agentRunName: string,\n): (RuntimeStreamEvent & { type: 'llm_call' }) | undefined {\n const tokensIn = pickFiniteNumber(data, ['tokensIn', 'inputTokens', 'prompt_tokens'])\n const tokensOut = pickFiniteNumber(data, ['tokensOut', 'outputTokens', 'completion_tokens'])\n const costUsd = pickFiniteNumber(data, ['costUsd', 'totalCostUsd', 'cost_usd', 'cost'])\n if (tokensIn === undefined && tokensOut === undefined && costUsd === undefined) {\n return undefined\n }\n const model = typeof data.model === 'string' && data.model.length > 0 ? data.model : agentRunName\n const event: RuntimeStreamEvent & { type: 'llm_call' } = {\n type: 'llm_call',\n model,\n }\n if (tokensIn !== undefined) event.tokensIn = tokensIn\n if (tokensOut !== undefined) event.tokensOut = tokensOut\n if (costUsd !== undefined) event.costUsd = costUsd\n return event\n}\n\nfunction pickFiniteNumber(data: Record<string, unknown>, keys: string[]): number | undefined {\n for (const key of keys) {\n const value = data[key]\n if (typeof value === 'number' && Number.isFinite(value)) return value\n }\n return undefined\n}\n\n/**\n * Project one `SandboxEvent` onto the `RuntimeStreamEvent` chat-UX vocabulary,\n * for runtimes that bridge a sandbox `streamPrompt` into the\n * `AgentRuntime.act` streaming contract. Returns `undefined` for events that\n * have no faithful projection — the raw stream is preserved separately for the\n * `OutputAdapter`, so an unmapped event never loses data.\n *\n * Mapped (the task-optional incremental variants — no synthesized task\n * lifecycle, no guessed tool-part shapes):\n * - `message.part.updated` text part → `text_delta`\n * - `message.part.updated` reasoning/thinking part → `reasoning_delta`\n * - cost-bearing events → `llm_call` (shared with the ledger extractor)\n *\n * The opencode backend emits incremental text as\n * `{ type: 'message.part.updated', data: { part: { type, text }, delta } }`;\n * `delta` is the increment, `part.text` the running accumulation.\n */\nexport function mapSandboxEvent(\n event: SandboxEvent,\n opts: { agentRunName?: string } = {},\n): RuntimeStreamEvent | undefined {\n if (!event || typeof event !== 'object') return undefined\n const type = String(event.type ?? '')\n const data =\n event.data && typeof event.data === 'object'\n ? (event.data as Record<string, unknown>)\n : ({} as Record<string, unknown>)\n\n if (type === 'message.part.updated') {\n const part =\n data.part && typeof data.part === 'object' ? (data.part as Record<string, unknown>) : {}\n const partType = String(part.type ?? '')\n const delta = typeof data.delta === 'string' ? data.delta : undefined\n const text = delta ?? (typeof part.text === 'string' ? part.text : undefined)\n if (text === undefined) return undefined\n if (partType === 'text') return { type: 'text_delta', text }\n if (partType === 'reasoning' || partType === 'thinking')\n return { type: 'reasoning_delta', text }\n return undefined\n }\n\n return extractLlmCallEvent(event, opts.agentRunName ?? 'agent')\n}\n","/**\n * @experimental\n *\n * `runLoop` — the topology-agnostic kernel built atop the sandbox SDK.\n *\n * Each iteration:\n * 1. `driver.plan(task, history)` → N tasks (1 = refine, N = fanout, 0 = stop)\n * 2. For each task (parallel, bounded by `maxConcurrency`):\n * a. round-robin an `AgentRunSpec` from `agentRuns`\n * b. `sandboxClient.create({ backend: { profile }, ...overrides })`\n * c. emit `loop.iteration.dispatch` with the placement\n * (`{ sibling, sandboxId }` or `{ fleet, fleetId, machineId, sandboxId }`)\n * d. iterate `box.streamPrompt(taskToPrompt(task))` and collect events\n * 3. `output.parse(events)` → typed `Output`\n * 4. `validator?.validate(output)` → `DefaultVerdict`\n * 5. Append `Iteration` to history; emit `loop.iteration.ended`\n * 6. `driver.decide(history)` → if terminal, return result + winner\n *\n * The kernel owns: iteration accounting, per-iteration timing, error\n * capture, abort propagation, concurrency cap, cost aggregation, and trace\n * emission. The kernel does NOT own: what the agent runs (sandbox SDK +\n * profile), how outputs are decoded (output adapter), how outputs are\n * scored (validator), or topology (driver).\n */\n\nimport type {\n AgentProfile,\n CreateSandboxOptions,\n SandboxEvent,\n SandboxInstance,\n} from '@tangle-network/sandbox'\nimport { ValidationError } from '../errors'\nimport { acquireSandbox } from './sandbox-acquire'\nimport { extractLlmCallEvent } from './sandbox-events'\nimport type {\n AgentRunSpec,\n Driver,\n ExecCtx,\n Iteration,\n LoopResult,\n LoopSandboxClient,\n LoopSandboxPlacement,\n LoopTraceEmitter,\n LoopTraceEvent,\n LoopWinner,\n OutputAdapter,\n Validator,\n} from './types'\n\nconst DEFAULT_MAX_ITERATIONS = 10\nconst DEFAULT_MAX_CONCURRENCY = 4\n\n/** @experimental */\nexport interface RunLoopOptions<Task, Output, Decision> {\n driver: Driver<Task, Output, Decision>\n /**\n * Single agent spec — every iteration uses this profile. Mutually\n * exclusive with `agentRuns`.\n */\n agentRun?: AgentRunSpec<Task>\n /**\n * Multiple specs for heterogeneous fanout. The kernel round-robins\n * through them when the driver plans N tasks. Mutually exclusive with\n * `agentRun`.\n */\n agentRuns?: AgentRunSpec<Task>[]\n output: OutputAdapter<Output>\n validator?: Validator<Output>\n task: Task\n ctx: ExecCtx\n /** Default 10. Hard cap on total iterations across all `plan()` rounds. */\n maxIterations?: number\n /** Default 4. In-flight worker cap within a single `plan()` batch. */\n maxConcurrency?: number\n /**\n * Pre-allocated id for trace correlation. Default = `loop-${random}`.\n * Surfaces as `runId` on every emitted `LoopTraceEvent`.\n */\n runId?: string\n /**\n * Clock override; default `Date.now`. Deterministic tests pass a\n * monotonic counter to stabilize iteration timing fields.\n */\n now?: () => number\n /**\n * Override the default winner selector (highest-valid-score, ties broken\n * by earliest iteration).\n */\n selectWinner?: (iterations: Iteration<Task, Output>[]) => LoopWinner<Task, Output> | undefined\n /**\n * Same-sandbox driver mode. Pass a setter and the kernel keeps each worker box\n * alive across the `plan()` boundary and hands the latest one here, so a\n * same-sandbox planner (`createSandboxPlanner` with `reuseBox`) can stream its\n * move INTO the worker's live box — steering from the worker's real filesystem\n * and state, not just a history summary. The kernel owns teardown: every box\n * kept alive this way is destroyed at loop end (and the setter is called with\n * `undefined` then). Without it, worker boxes are torn down per-iteration\n * (default) and a same-sandbox planner has nothing to reuse. Intended for\n * single-worker (refine) loops; under fanout the most-recent box is shared.\n */\n shareWorkerBox?: (box: SandboxInstance | undefined) => void\n}\n\n/** @experimental */\nexport async function runLoop<Task, Output, Decision>(\n options: RunLoopOptions<Task, Output, Decision>,\n): Promise<LoopResult<Task, Output, Decision>> {\n const specs = resolveAgentRuns(options)\n const maxIterations = options.maxIterations ?? DEFAULT_MAX_ITERATIONS\n if (!Number.isFinite(maxIterations) || maxIterations <= 0) {\n throw new ValidationError('runLoop: maxIterations must be > 0')\n }\n const maxConcurrency = options.maxConcurrency ?? DEFAULT_MAX_CONCURRENCY\n if (!Number.isFinite(maxConcurrency) || maxConcurrency <= 0) {\n throw new ValidationError('runLoop: maxConcurrency must be > 0')\n }\n if (!options.ctx?.sandboxClient || typeof options.ctx.sandboxClient.create !== 'function') {\n throw new ValidationError('runLoop: ctx.sandboxClient.create is required')\n }\n const now = options.now ?? Date.now\n const runId = options.runId ?? `loop-${randomSuffix()}`\n const loopStart = now()\n const driverName = options.driver.name ?? 'driver'\n const iterations: Iteration<Task, Output>[] = []\n let round = 0\n // Same-sandbox mode: worker boxes are kept alive (not torn down per-iteration)\n // so the planner can stream into the latest; the kernel destroys them at loop end.\n const ownedBoxes: SandboxInstance[] = []\n const collectBox = options.shareWorkerBox\n ? (box: SandboxInstance) => {\n ownedBoxes.push(box)\n options.shareWorkerBox?.(box)\n }\n : undefined\n\n await emitTrace(options.ctx.traceEmitter, {\n kind: 'loop.started',\n runId,\n timestamp: now(),\n payload: {\n driver: driverName,\n agentRunNames: specs.map((spec) => spec.name ?? spec.profile.name ?? 'agent'),\n maxIterations,\n maxConcurrency,\n },\n })\n\n const controller = new AbortController()\n const onOuterAbort = () => controller.abort()\n if (options.ctx.signal) {\n if (options.ctx.signal.aborted) controller.abort()\n else options.ctx.signal.addEventListener('abort', onOuterAbort, { once: true })\n }\n\n try {\n while (iterations.length < maxIterations) {\n if (controller.signal.aborted) throwAbort()\n const planned = await options.driver.plan(options.task, iterations)\n const planDesc = options.driver.describePlan?.()\n const roundIndex = round\n const baseIndex = iterations.length\n const remaining = maxIterations - iterations.length\n const slice = planned.slice(0, remaining)\n // Edge lineage: a driver may DECLARE the branch source (planner-authored\n // topology); otherwise the kernel infers it — round 0 branches from root\n // (undefined), later rounds from the best-valid (else latest) iteration so\n // far. Either way it's emitted, not guessed by the viewer.\n const parentIndex =\n planDesc?.parentIndex ?? (roundIndex === 0 ? undefined : branchPoint(iterations))\n const childIndices = slice.map((_, i) => baseIndex + i)\n await emitTrace(options.ctx.traceEmitter, {\n kind: 'loop.plan',\n runId,\n timestamp: now(),\n payload: {\n roundIndex,\n plannedCount: planned.length,\n moveKind:\n planDesc?.kind ??\n (planned.length === 0 ? 'stop' : planned.length === 1 ? 'refine' : 'fanout'),\n rationale: planDesc?.rationale,\n parentIndex,\n childIndices,\n },\n })\n round += 1\n if (planned.length === 0) break\n\n // Reserve slots up front so concurrent workers may mutate by index.\n for (let i = 0; i < slice.length; i += 1) {\n const spec = specs[(baseIndex + i) % specs.length]!\n iterations.push({\n index: baseIndex + i,\n task: slice[i] as Task,\n agentRunName: spec.name ?? spec.profile.name ?? 'agent',\n events: [],\n startedAt: now(),\n endedAt: 0,\n costUsd: 0,\n tokenUsage: { input: 0, output: 0 },\n })\n }\n\n await runBatch({\n slice,\n baseIndex,\n iterations,\n specs,\n output: options.output,\n validator: options.validator,\n maxConcurrency,\n signal: controller.signal,\n ctx: options.ctx,\n runId,\n now,\n roundIndex,\n parentIndex,\n collectBox,\n })\n\n if (controller.signal.aborted) throwAbort()\n\n const decision = await options.driver.decide(iterations)\n await emitTrace(options.ctx.traceEmitter, {\n kind: 'loop.decision',\n runId,\n timestamp: now(),\n payload: { decision: serializeDecision(decision), historyLength: iterations.length },\n })\n if (isTerminalDecision(decision)) {\n return finalize({\n options,\n decision,\n iterations,\n startMs: loopStart,\n now,\n runId,\n })\n }\n }\n\n if (iterations.length >= maxIterations) {\n // Cap reached without a terminal decision — ask the driver one more time\n // for its final state, then close out.\n const decision = await options.driver.decide(iterations)\n await emitTrace(options.ctx.traceEmitter, {\n kind: 'loop.decision',\n runId,\n timestamp: now(),\n payload: { decision: serializeDecision(decision), historyLength: iterations.length },\n })\n return finalize({ options, decision, iterations, startMs: loopStart, now, runId })\n }\n // `plan()` returned `[]` before `decide()` reached a terminal state.\n const decision = await options.driver.decide(iterations)\n await emitTrace(options.ctx.traceEmitter, {\n kind: 'loop.decision',\n runId,\n timestamp: now(),\n payload: { decision: serializeDecision(decision), historyLength: iterations.length },\n })\n return finalize({ options, decision, iterations, startMs: loopStart, now, runId })\n } finally {\n if (options.ctx.signal) options.ctx.signal.removeEventListener('abort', onOuterAbort)\n // Same-sandbox mode kept worker boxes alive across plan() so the planner could\n // stream into them — the kernel owns their teardown, so destroy them all now.\n for (const b of ownedBoxes) await destroySandboxSafe(b)\n if (options.shareWorkerBox) options.shareWorkerBox(undefined)\n }\n}\n\ninterface RunBatchArgs<Task, Output> {\n slice: Task[]\n baseIndex: number\n iterations: Iteration<Task, Output>[]\n specs: AgentRunSpec<Task>[]\n output: OutputAdapter<Output>\n validator: Validator<Output> | undefined\n maxConcurrency: number\n signal: AbortSignal\n ctx: ExecCtx\n runId: string\n now: () => number\n /** Plan round these iterations belong to — stamped as `groupId`. */\n roundIndex: number\n /** Iteration this round branched from — stamped as `parentIndex`. */\n parentIndex?: number\n /**\n * Same-sandbox mode: when set, a finished iteration's box is handed here\n * (kept alive for the planner) instead of being torn down. `undefined` =\n * default per-iteration teardown.\n */\n collectBox?: (box: SandboxInstance) => void\n}\n\nasync function runBatch<Task, Output>(args: RunBatchArgs<Task, Output>) {\n const queue = args.slice.map((task, offset) => ({ task, index: args.baseIndex + offset }))\n const inflight = new Set<Promise<void>>()\n while (queue.length > 0 || inflight.size > 0) {\n while (inflight.size < args.maxConcurrency && queue.length > 0) {\n const item = queue.shift()!\n const p = executeIteration({ ...args, item }).finally(() => inflight.delete(p))\n inflight.add(p)\n }\n if (inflight.size === 0) break\n await Promise.race(inflight)\n }\n}\n\ninterface ExecuteIterationArgs<Task, Output> extends RunBatchArgs<Task, Output> {\n item: { task: Task; index: number }\n}\n\nasync function executeIteration<Task, Output>(args: ExecuteIterationArgs<Task, Output>) {\n const slot = args.iterations[args.item.index]\n if (!slot)\n throw new ValidationError(`runLoop: missing iteration slot at index ${args.item.index}`)\n const spec = args.specs[args.item.index % args.specs.length]\n if (!spec) throw new ValidationError('runLoop: no AgentRunSpec available for iteration')\n slot.startedAt = args.now()\n slot.agentRunName = spec.name ?? spec.profile.name ?? 'agent'\n\n await emitTrace(args.ctx.traceEmitter, {\n kind: 'loop.iteration.started',\n runId: args.runId,\n timestamp: args.now(),\n payload: {\n iterationIndex: args.item.index,\n agentRunName: slot.agentRunName,\n taskHash: hashJson(args.item.task),\n groupId: args.roundIndex,\n parentIndex: args.parentIndex,\n },\n })\n\n let box: SandboxInstance | undefined\n try {\n box = await createSandboxForSpec(args.ctx.sandboxClient, spec, args.signal)\n const placement = describeSandboxPlacement(args.ctx.sandboxClient, box)\n await emitTrace(args.ctx.traceEmitter, {\n kind: 'loop.iteration.dispatch',\n runId: args.runId,\n timestamp: args.now(),\n payload: {\n iterationIndex: args.item.index,\n agentRunName: slot.agentRunName,\n placement: placement.kind,\n sandboxId: placement.sandboxId,\n fleetId: placement.fleetId,\n machineId: placement.machineId,\n groupId: args.roundIndex,\n parentIndex: args.parentIndex,\n },\n })\n const message = spec.taskToPrompt(args.item.task)\n const events: SandboxEvent[] = []\n for await (const event of box.streamPrompt(message, { signal: args.signal })) {\n events.push(event)\n const llmCall = extractLlmCallEvent(event, slot.agentRunName)\n if (llmCall) {\n slot.costUsd += llmCall.costUsd ?? 0\n slot.tokenUsage.input += llmCall.tokensIn ?? 0\n slot.tokenUsage.output += llmCall.tokensOut ?? 0\n args.ctx.runHandle?.observe(llmCall)\n }\n }\n slot.events = events\n slot.output = args.output.parse(events)\n if (args.validator) {\n slot.verdict = await args.validator.validate(slot.output, {\n iteration: args.item.index,\n signal: args.signal,\n traceEmitter: args.ctx.traceEmitter,\n })\n }\n } catch (err) {\n slot.error = err instanceof Error ? err : new Error(String(err))\n } finally {\n slot.endedAt = args.now()\n await emitTrace(args.ctx.traceEmitter, {\n kind: 'loop.iteration.ended',\n runId: args.runId,\n timestamp: args.now(),\n payload: {\n iterationIndex: args.item.index,\n agentRunName: slot.agentRunName,\n outputHash: slot.output !== undefined ? hashJson(slot.output) : undefined,\n verdict: slot.verdict,\n error: slot.error?.message,\n costUsd: slot.costUsd,\n durationMs: slot.endedAt - slot.startedAt,\n tokenUsage:\n slot.tokenUsage.input || slot.tokenUsage.output ? { ...slot.tokenUsage } : undefined,\n groupId: args.roundIndex,\n parentIndex: args.parentIndex,\n outputPreview: slot.output !== undefined ? previewOutput(slot.output) : undefined,\n },\n })\n // The loop owns the per-shot box lifecycle. Default: tear it down now so\n // sandboxes don't leak. Same-sandbox mode: hand it to the kernel to keep\n // alive for the planner (it tears these down at loop end instead).\n if (args.collectBox && box) args.collectBox(box)\n else await destroySandboxSafe(box)\n }\n}\n\n/**\n * Best-effort sandbox teardown. A failed delete must never surface as a loop\n * error, and instances without a `delete` (the loop's test fakes) are skipped.\n */\nexport async function destroySandboxSafe(box: SandboxInstance | undefined): Promise<void> {\n if (!box || typeof (box as { delete?: unknown }).delete !== 'function') return\n try {\n await box.delete()\n } catch {\n // ignore — platform reaps on expiry\n }\n}\n\n/**\n * Branch point for a new round — the iteration a later round descends from.\n * Highest-valid-score iteration so far; ties + no-valid fall back to the latest\n * index. Inferred (not driver-declared), so refine renders as a chain and\n * fanout→refine chains off the fanout winner.\n */\nfunction branchPoint<Task, Output>(\n iterations: ReadonlyArray<Iteration<Task, Output>>,\n): number | undefined {\n if (iterations.length === 0) return undefined\n let best = iterations.length - 1\n let bestScore = -Infinity\n for (const iter of iterations) {\n if (iter.verdict?.valid !== true) continue\n const score = iter.verdict.score ?? 0\n if (score > bestScore) {\n bestScore = score\n best = iter.index\n }\n }\n return best\n}\n\n/** Bounded string preview of a parsed output for a viewer's drawer — never the\n * full payload. JSON when serializable, else `String()`, truncated to 280. */\nfunction previewOutput(output: unknown): string {\n let s: string\n try {\n s = typeof output === 'string' ? output : (JSON.stringify(output) ?? String(output))\n } catch {\n s = String(output)\n }\n return s.length > 280 ? `${s.slice(0, 280)}…` : s\n}\n\nexport function describeSandboxPlacement(\n client: LoopSandboxClient,\n box: SandboxInstance,\n): LoopSandboxPlacement {\n if (typeof client.describePlacement === 'function') {\n try {\n const result = client.describePlacement(box)\n if (\n result &&\n typeof result === 'object' &&\n (result.kind === 'sibling' || result.kind === 'fleet')\n ) {\n return {\n kind: result.kind,\n sandboxId: result.sandboxId ?? readSandboxId(box),\n fleetId: result.fleetId,\n machineId: result.machineId,\n }\n }\n } catch {\n // Adapter bug must not corrupt the iteration; fall through to default.\n }\n }\n return { kind: 'sibling', sandboxId: readSandboxId(box) }\n}\n\nfunction readSandboxId(box: SandboxInstance): string | undefined {\n const raw = (box as unknown as { id?: unknown }).id\n return typeof raw === 'string' && raw.length > 0 ? raw : undefined\n}\n\n/**\n * Instantiate a sandbox for an `AgentRunSpec`: sets `backend.profile` to the\n * spec's profile (inferring the backend type when the spec doesn't override\n * it) and merges `sandboxOverrides`. Shared by the loop kernel and the\n * `AgentRuntime.act` sandbox bridge so both boot the sandbox identically.\n */\nexport async function createSandboxForSpec<Task>(\n client: LoopSandboxClient,\n spec: AgentRunSpec<Task>,\n signal: AbortSignal,\n): Promise<SandboxInstance> {\n const overrides = spec.sandboxOverrides ?? {}\n const overrideBackend = overrides.backend\n const opts: CreateSandboxOptions = {\n ...overrides,\n backend: {\n type: overrideBackend?.type ?? inferBackendType(spec.profile),\n profile: spec.profile satisfies AgentProfile,\n ...(overrideBackend?.model ? { model: overrideBackend.model } : {}),\n ...(overrideBackend?.server ? { server: overrideBackend.server } : {}),\n },\n }\n // Cold-start-resilient acquire: a slow scale-from-zero create (node boot +\n // host-agent registration) can't surface as a failure — readiness is observed\n // from sandbox status, and a gateway-timed-out create is recovered by lookup.\n if (signal.aborted) throwAbort()\n return acquireSandbox(client, opts, { signal })\n}\n\nfunction inferBackendType(\n profile: AgentProfile,\n): CreateSandboxOptions['backend'] extends infer B\n ? B extends { type: infer T }\n ? T\n : never\n : never {\n // The sandbox SDK accepts profile-driven backend selection by name. When the\n // profile has no explicit hint we fall through to the SDK's default\n // ('opencode' on the platform side). Returning a literal here would lie\n // about provenance — let the SDK pick.\n type BackendType = NonNullable<CreateSandboxOptions['backend']>['type']\n const explicit = profile.metadata?.backendType\n if (typeof explicit === 'string') return explicit as BackendType\n return 'opencode' as BackendType\n}\n\ninterface FinalizeArgs<Task, Output, Decision> {\n options: RunLoopOptions<Task, Output, Decision>\n decision: Decision\n iterations: Iteration<Task, Output>[]\n startMs: number\n now: () => number\n runId: string\n}\n\nfunction finalize<Task, Output, Decision>(\n args: FinalizeArgs<Task, Output, Decision>,\n): LoopResult<Task, Output, Decision> {\n const winner = (args.options.selectWinner ?? defaultSelectWinner)(args.iterations)\n const costUsd = args.iterations.reduce((sum, iter) => sum + (iter.costUsd || 0), 0)\n const tokenUsage = args.iterations.reduce(\n (acc, iter) => {\n acc.input += iter.tokenUsage?.input ?? 0\n acc.output += iter.tokenUsage?.output ?? 0\n return acc\n },\n { input: 0, output: 0 },\n )\n const result: LoopResult<Task, Output, Decision> = {\n decision: args.decision,\n iterations: args.iterations,\n winner,\n durationMs: args.now() - args.startMs,\n costUsd,\n tokenUsage,\n }\n void emitTrace(args.options.ctx.traceEmitter, {\n kind: 'loop.ended',\n runId: args.runId,\n timestamp: args.now(),\n payload: {\n winnerIterationIndex: winner?.iterationIndex,\n totalCostUsd: costUsd,\n durationMs: result.durationMs,\n iterations: args.iterations.length,\n },\n })\n return result\n}\n\nfunction defaultSelectWinner<Task, Output>(\n iterations: Iteration<Task, Output>[],\n): LoopWinner<Task, Output> | undefined {\n const candidates = iterations.filter((iter) => iter.output !== undefined && !iter.error)\n if (candidates.length === 0) return undefined\n const valid = candidates.filter((iter) => iter.verdict?.valid === true)\n const pool = valid.length > 0 ? valid : candidates\n const sorted = [...pool].sort(\n (a, b) => (b.verdict?.score ?? 0) - (a.verdict?.score ?? 0) || a.index - b.index,\n )\n const top = sorted[0]\n if (!top || top.output === undefined) return undefined\n return {\n task: top.task,\n output: top.output,\n verdict: top.verdict,\n iterationIndex: top.index,\n agentRunName: top.agentRunName,\n }\n}\n\nfunction resolveAgentRuns<Task, Output, Decision>(\n options: RunLoopOptions<Task, Output, Decision>,\n): AgentRunSpec<Task>[] {\n if (options.agentRun && options.agentRuns) {\n throw new ValidationError('runLoop: pass exactly one of `agentRun` or `agentRuns`')\n }\n if (options.agentRun) return [options.agentRun]\n if (options.agentRuns && options.agentRuns.length > 0) return options.agentRuns\n throw new ValidationError('runLoop: `agentRun` or non-empty `agentRuns` is required')\n}\n\nfunction isTerminalDecision(decision: unknown): boolean {\n return (\n decision === 'stop' || decision === 'pick-winner' || decision === 'fail' || decision === 'done'\n )\n}\n\nfunction serializeDecision(decision: unknown): string {\n if (typeof decision === 'string') return decision\n if (decision === null || decision === undefined) return 'null'\n try {\n return JSON.stringify(decision)\n } catch {\n return String(decision)\n }\n}\n\nasync function emitTrace(\n emitter: LoopTraceEmitter | undefined,\n event: LoopTraceEvent,\n): Promise<void> {\n if (!emitter) return\n await emitter.emit(event)\n}\n\nfunction randomSuffix(len = 8): string {\n return Math.random()\n .toString(36)\n .slice(2, 2 + len)\n}\n\nfunction throwAbort(): never {\n const err = new Error('aborted')\n err.name = 'AbortError'\n throw err\n}\n\n/**\n * Stable hash for the trace payload. Not cryptographic — only used so\n * downstream eval pipelines can group iterations whose task / output is the\n * same. Bare structural hash; non-JSON values stringify via their `toString`.\n */\nfunction hashJson(value: unknown): string {\n let str: string\n try {\n str = JSON.stringify(value) ?? String(value)\n } catch {\n str = String(value)\n }\n // FNV-1a 32-bit — branch-free, dependency-free, good enough for grouping.\n let h = 0x811c9dc5\n for (let i = 0; i < str.length; i += 1) {\n h ^= str.charCodeAt(i)\n h = Math.imul(h, 0x01000193)\n }\n return (h >>> 0).toString(16).padStart(8, '0')\n}\n","/**\n * `loopDispatch` — turn `runLoop` into an agent-eval campaign dispatch.\n *\n * Without this adapter a consumer wiring `runLoop` into `runProfileMatrix` /\n * `runCampaign` has to, by hand, every time: (a) build an `ExecCtx` with a\n * sandbox client, (b) adapt the campaign `DispatchContext.trace` into a\n * `LoopTraceEmitter` (or lose all loop trace correlation), and (c) remember to\n * forward the loop's cost + tokens via `ctx.cost` (forgetting it yields a\n * `{0,0}` cell the backend-integrity guard reads as a stub). Three foot-guns,\n * the third silent. The fleet's products skipped (c) and fell back to a\n * `workerRecords[]` side-channel — the exact anti-pattern the substrate exists\n * to kill.\n *\n * `loopDispatch` collapses all three into one typed call:\n *\n * const dispatch = loopDispatch({\n * sandboxClient,\n * toLoopOptions: (scenario, profile) => ({ driver, agentRun, output, validator, task }),\n * })\n * await runProfileMatrix({ profiles, scenarios, dispatch, judges, commitSha })\n *\n * Usage is reported automatically; trace events are forwarded automatically;\n * the ctx is built automatically. The seam becomes impossible to mis-wire.\n *\n * Typed structurally against the campaign `DispatchContext` (imported type-only\n * from `@tangle-network/agent-eval/campaign`) — a downward dependency, never an\n * inversion.\n */\n\n// agent-eval's AgentProfile (the eval-harness unit of variation, `model: string`)\n// — NOT sandbox's AgentProfile. ProfileDispatchFn is keyed on the former.\nimport type { AgentProfile } from '@tangle-network/agent-eval'\nimport type {\n CampaignTraceWriter,\n DispatchContext,\n DispatchFn,\n ProfileDispatchFn,\n Scenario,\n} from '@tangle-network/agent-eval/campaign'\nimport { reportLoopUsage } from './report-usage'\nimport { type RunLoopOptions, runLoop } from './run-loop'\nimport type { LoopResult, LoopSandboxClient, LoopTraceEmitter } from './types'\n\n/** runLoop options minus the `ctx` (loopDispatch builds the ctx). */\nexport type LoopOptionsForDispatch<Task, Output, Decision> = Omit<\n RunLoopOptions<Task, Output, Decision>,\n 'ctx'\n>\n\nexport interface LoopDispatchOptions<\n Task,\n Output,\n Decision,\n TScenario extends Scenario,\n TArtifact,\n> {\n /** Sandbox client used for every cell's `runLoop`. Supplied once. */\n sandboxClient: LoopSandboxClient\n /** Build the per-cell runLoop options from the scenario (+ profile, when\n * used with `runProfileMatrix`). */\n toLoopOptions: (\n scenario: TScenario,\n profile: AgentProfile,\n ) => LoopOptionsForDispatch<Task, Output, Decision>\n /** Map the finished loop to the artifact the judges score. Default:\n * `result.winner?.output`. A loop with no winner yields `undefined` (judges\n * skip the cell) — but the loop's token usage is STILL reported, so the\n * integrity guard sees real activity. */\n toArtifact?: (result: LoopResult<Task, Output, Decision>) => TArtifact\n /** Forward `loop.*` trace events into the campaign's scoped trace so loop\n * spans correlate with the cell. Default true. */\n forwardTrace?: boolean\n /** Cost-meter source label for the loop's spend. Default `'loop'`. */\n costSource?: string\n}\n\n/** Bridge a campaign `DispatchContext.trace` to a `LoopTraceEmitter` so every\n * `loop.*` event lands as a span under the cell's scoped trace. */\nfunction campaignTraceToLoopEmitter(trace: CampaignTraceWriter): LoopTraceEmitter {\n return {\n emit(event) {\n trace\n .span(event.kind, { runId: event.runId, timestamp: event.timestamp, ...event.payload })\n .end()\n },\n }\n}\n\nasync function runLoopForCell<Task, Output, Decision, TScenario extends Scenario, TArtifact>(\n opts: LoopDispatchOptions<Task, Output, Decision, TScenario, TArtifact>,\n scenario: TScenario,\n profile: AgentProfile,\n ctx: DispatchContext,\n): Promise<TArtifact> {\n const loopOptions = opts.toLoopOptions(scenario, profile)\n const result = await runLoop<Task, Output, Decision>({\n ...loopOptions,\n ctx: {\n sandboxClient: opts.sandboxClient,\n signal: ctx.signal,\n traceEmitter: opts.forwardTrace === false ? undefined : campaignTraceToLoopEmitter(ctx.trace),\n },\n })\n reportLoopUsage(ctx.cost, result, opts.costSource ?? 'loop')\n const toArtifact =\n opts.toArtifact ?? ((r: LoopResult<Task, Output, Decision>) => r.winner?.output as TArtifact)\n return toArtifact(result)\n}\n\n/**\n * Adapter for `runProfileMatrix` (profile is an axis). Returns a\n * `ProfileDispatchFn` that runs `runLoop` per (profile, scenario) cell and\n * reports usage automatically.\n */\nexport function loopDispatch<Task, Output, Decision, TScenario extends Scenario, TArtifact>(\n opts: LoopDispatchOptions<Task, Output, Decision, TScenario, TArtifact>,\n): ProfileDispatchFn<TScenario, TArtifact> {\n return (profile, scenario, ctx) => runLoopForCell(opts, scenario, profile, ctx)\n}\n\n/**\n * Adapter for `runCampaign` (no profile axis). `toLoopOptions` receives only\n * the scenario; the `profile` passed to the shared core is a stable sentinel\n * so a single `runLoop` config is reused across cells.\n */\nexport function loopCampaignDispatch<Task, Output, Decision, TScenario extends Scenario, TArtifact>(\n opts: Omit<LoopDispatchOptions<Task, Output, Decision, TScenario, TArtifact>, 'toLoopOptions'> & {\n toLoopOptions: (scenario: TScenario) => LoopOptionsForDispatch<Task, Output, Decision>\n },\n): DispatchFn<TScenario, TArtifact> {\n const profileSentinel = { id: 'loop-campaign', model: 'n/a@loop-campaign' } as AgentProfile\n const profiled: LoopDispatchOptions<Task, Output, Decision, TScenario, TArtifact> = {\n ...opts,\n toLoopOptions: (scenario) => opts.toLoopOptions(scenario),\n }\n return (scenario, ctx) => runLoopForCell(profiled, scenario, profileSentinel, ctx)\n}\n"],"mappings":";;;;;;AAsFO,SAAS,oBACd,SACuC;AACvC,MAAI,OAAO,QAAQ,YAAY,YAAY;AACzC,UAAM,IAAI,gBAAgB,iDAAiD;AAAA,EAC7E;AACA,QAAM,gBAAgB,QAAQ,iBAAiB;AAC/C,MAAI,CAAC,OAAO,SAAS,aAAa,KAAK,iBAAiB,GAAG;AACzD,UAAM,IAAI,gBAAgB,gDAAgD;AAAA,EAC5E;AACA,QAAM,YAAY,QAAQ,aAAa;AACvC,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,YAAY,GAAG;AAChD,UAAM,IAAI,gBAAgB,6CAA6C;AAAA,EACzE;AAMA,MAAI;AAEJ,SAAO;AAAA,IACL,MAAM,QAAQ,QAAQ;AAAA,I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B;AACpB,QAAM,cAAc,KAAK,cAAc,UAAU,OAAO;AACxD,QAAM,SAAS,MAAM,QAAgC;AAAA,IACnD,GAAG;AAAA,IACH,KAAK;AAAA,MACH,eAAe,KAAK;AAAA,MACpB,QAAQ,IAAI;AAAA,MACZ,cAAc,KAAK,iBAAiB,QAAQ,SAAY,2BAA2B,IAAI,KAAK;AAAA,IAC9F;AAAA,EACF,CAAC;AACD,kBAAgB,IAAI,MAAM,QAAQ,KAAK,cAAc,MAAM;AAC3D,QAAM,aACJ,KAAK,eAAe,CAAC,MAA0C,EAAE,QAAQ;AAC3E,SAAO,WAAW,MAAM;AAC1B;AAOO,SAAS,aACd,MACyC;AACzC,SAAO,CAAC,SAAS,UAAU,QAAQ,eAAe,MAAM,UAAU,SAAS,GAAG;AAChF;AAOO,SAAS,qBACd,MAGkC;AAClC,QAAM,kBAAkB,EAAE,IAAI,iBAAiB,OAAO,oBAAoB;AAC1E,QAAM,WAA8E;AAAA,IAClF,GAAG;AAAA,IACH,eAAe,CAAC,aAAa,KAAK,cAAc,QAAQ;AAAA,EAC1D;AACA,SAAO,CAAC,UAAU,QAAQ,eAAe,UAAU,UAAU,iBAAiB,GAAG;AACnF;","names":["randomSuffix","decision"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runLoop
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S7JXV32P.js";
|
|
4
4
|
import {
|
|
5
5
|
coderProfile,
|
|
6
6
|
multiHarnessCoderFanout
|
|
@@ -210,4 +210,4 @@ export {
|
|
|
210
210
|
createFleetWorkspaceExecutor,
|
|
211
211
|
createDefaultCoderDelegate
|
|
212
212
|
};
|
|
213
|
-
//# sourceMappingURL=chunk-
|
|
213
|
+
//# sourceMappingURL=chunk-SKUZZCHE.js.map
|