@tangle-network/agent-runtime 0.46.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/agent.d.ts +1 -1
  2. package/dist/agent.js +1 -1
  3. package/dist/analyst-loop.d.ts +1 -1
  4. package/dist/{chunk-GN75RGM6.js → chunk-656G2XCL.js} +3 -3
  5. package/dist/{chunk-65FQLI4V.js → chunk-IW2LMLK6.js} +1714 -42
  6. package/dist/chunk-IW2LMLK6.js.map +1 -0
  7. package/dist/{chunk-I42NHLKX.js → chunk-LX66I3SC.js} +11 -6
  8. package/dist/chunk-LX66I3SC.js.map +1 -0
  9. package/dist/{chunk-KPN7OQ64.js → chunk-TJS7S3HJ.js} +2 -2
  10. package/dist/{chunk-KPN7OQ64.js.map → chunk-TJS7S3HJ.js.map} +1 -1
  11. package/dist/{coder-DCWFQpmJ.d.ts → coder-CVZNGbyg.d.ts} +1 -1
  12. package/dist/{driver-C-mtBo7h.d.ts → driver-DYU2sgHr.d.ts} +1 -1
  13. package/dist/index.d.ts +7 -7
  14. package/dist/index.js +3 -3
  15. package/dist/{kb-gate-2Gwpz_27.d.ts → kb-gate-51BlLlVM.d.ts} +8 -2
  16. package/dist/{loop-runner-bin-D-K6bRp3.d.ts → loop-runner-bin-DEm4roYF.d.ts} +4 -4
  17. package/dist/loop-runner-bin.d.ts +5 -5
  18. package/dist/loop-runner-bin.js +3 -3
  19. package/dist/loops.d.ts +5 -5
  20. package/dist/loops.js +55 -1
  21. package/dist/mcp/bin.js +3 -3
  22. package/dist/mcp/index.d.ts +71 -70
  23. package/dist/mcp/index.js +199 -27
  24. package/dist/mcp/index.js.map +1 -1
  25. package/dist/{otel-export-nurzFwuJ.d.ts → otel-export-EzfsVUhh.d.ts} +1 -1
  26. package/dist/profiles.d.ts +2 -2
  27. package/dist/{run-loop-CU2Y00Si.d.ts → run-loop-DvD4aGiE.d.ts} +1 -1
  28. package/dist/runtime.d.ts +915 -71
  29. package/dist/runtime.js +55 -1
  30. package/dist/{types-BfoeiQRZ.d.ts → types-BpDfCPUp.d.ts} +5 -5
  31. package/dist/{types-DnYoHvvZ.d.ts → types-nBMuollC.d.ts} +17 -0
  32. package/dist/workflow.d.ts +2 -2
  33. package/dist/workflow.js +1 -1
  34. package/package.json +25 -14
  35. package/skills/loop-writer/SKILL.md +163 -0
  36. package/dist/chunk-65FQLI4V.js.map +0 -1
  37. package/dist/chunk-I42NHLKX.js.map +0 -1
  38. /package/dist/{chunk-GN75RGM6.js.map → chunk-656G2XCL.js.map} +0 -0
package/dist/mcp/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  removeWorktree,
15
15
  traceContextToEnv,
16
16
  validateDelegateUiAuditArgs
17
- } from "../chunk-KPN7OQ64.js";
17
+ } from "../chunk-TJS7S3HJ.js";
18
18
  import "../chunk-WIR4HOOJ.js";
19
19
  import {
20
20
  mcpToolsForRuntimeMcp,
@@ -58,7 +58,7 @@ import {
58
58
  createDefaultCoderDelegate,
59
59
  createFleetWorkspaceExecutor,
60
60
  createSiblingSandboxExecutor
61
- } from "../chunk-I42NHLKX.js";
61
+ } from "../chunk-LX66I3SC.js";
62
62
  import "../chunk-KADIJAD4.js";
63
63
  import {
64
64
  runLocalHarness
@@ -70,7 +70,7 @@ import {
70
70
  } from "../chunk-7JITYN6T.js";
71
71
  import {
72
72
  assertTraceDerivedFindings
73
- } from "../chunk-65FQLI4V.js";
73
+ } from "../chunk-IW2LMLK6.js";
74
74
  import "../chunk-GSUO5QS6.js";
75
75
  import "../chunk-DGUM43GV.js";
76
76
 
@@ -246,7 +246,30 @@ var idArg = { type: "string", description: "The workerId returned by spawn_worke
246
246
  function createCoordinationTools(opts) {
247
247
  let stopped = false;
248
248
  let reason;
249
+ let questionSeq = 0;
249
250
  const ledger = [];
251
+ const questions = [];
252
+ const questionPolicy = opts.questionPolicy ?? "auto";
253
+ const str = (v, field) => {
254
+ if (typeof v !== "string" || v.length === 0)
255
+ throw new Error(`coordination tools: "${field}" must be a non-empty string`);
256
+ return v;
257
+ };
258
+ const obj = (raw) => {
259
+ if (!raw || typeof raw !== "object")
260
+ throw new Error("coordination tools: arguments must be an object");
261
+ return raw;
262
+ };
263
+ const level = (v) => {
264
+ if (v === "worker" || v === "driver" || v === "loop") return v;
265
+ throw new Error('coordination tools: "level" must be worker, driver, or loop');
266
+ };
267
+ const urgency = (v) => {
268
+ if (v === "continue-without" || v === "blocks-step" || v === "blocks-run") return v;
269
+ throw new Error(
270
+ 'coordination tools: "urgency" must be continue-without, blocks-step, or blocks-run'
271
+ );
272
+ };
250
273
  const recordSettled = (s) => {
251
274
  const w = s.kind === "done" ? {
252
275
  id: s.handle.id,
@@ -258,24 +281,68 @@ function createCoordinationTools(opts) {
258
281
  ledger.push(w);
259
282
  return w;
260
283
  };
261
- const str = (v, field) => {
262
- if (typeof v !== "string" || v.length === 0)
263
- throw new Error(`operator toolbox: "${field}" must be a non-empty string`);
264
- return v;
284
+ const nextQuestionId = (from) => `${from}:q${questionSeq++}`;
285
+ const normalizeQuestion = (q, fallbackFrom) => {
286
+ const from = str(q.from ?? fallbackFrom, "from");
287
+ return {
288
+ id: typeof q.id === "string" && q.id.length > 0 ? q.id : nextQuestionId(from),
289
+ from,
290
+ level: level(q.level),
291
+ question: str(q.question, "question"),
292
+ reason: str(q.reason, "reason"),
293
+ ...q.options ? { options: q.options } : {},
294
+ urgency: urgency(q.urgency)
295
+ };
265
296
  };
266
- const obj = (raw) => {
267
- if (!raw || typeof raw !== "object")
268
- throw new Error("operator toolbox: arguments must be an object");
269
- return raw;
297
+ const addQuestion = (raw, fallbackFrom, decision) => {
298
+ const q = normalizeQuestion(raw, fallbackFrom);
299
+ const existing = questions.find((x) => x.id === q.id);
300
+ if (existing) return { question: existing, added: false };
301
+ const effectiveDecision = decision ?? (questionPolicy === "bubble" ? {
302
+ kind: "escalate",
303
+ to: "parent",
304
+ reason: "question policy bubbled to parent"
305
+ } : void 0);
306
+ const status = effectiveDecision?.kind === "answer" ? "answered" : effectiveDecision?.kind === "defer" ? "deferred" : effectiveDecision?.kind === "escalate" ? "escalated" : "open";
307
+ const record = {
308
+ ...q,
309
+ status,
310
+ openedAt: Date.now(),
311
+ ...effectiveDecision ? { decision: effectiveDecision } : {}
312
+ };
313
+ questions.push(record);
314
+ return { question: record, added: true };
315
+ };
316
+ const emitNewQuestion = async (record) => {
317
+ if (record.added) await opts.onEvent?.({ type: "question", question: record.question });
318
+ return record.question;
319
+ };
320
+ const decideQuestion = (questionId, decision) => {
321
+ const idx = questions.findIndex((q) => q.id === questionId);
322
+ if (idx < 0) throw new Error(`unknown questionId ${JSON.stringify(questionId)}`);
323
+ const prior = questions[idx];
324
+ const status = decision.kind === "answer" ? "answered" : decision.kind === "defer" ? "deferred" : "escalated";
325
+ const next = { ...prior, status, decision };
326
+ questions[idx] = next;
327
+ return next;
328
+ };
329
+ const blockingQuestionsForStop = () => {
330
+ if (questionPolicy === "auto" || questionPolicy === "bubble") return [];
331
+ return questions.filter((q) => {
332
+ const blocking = q.urgency === "blocks-step" || q.urgency === "blocks-run";
333
+ if (!blocking) return false;
334
+ if (questionPolicy === "mustDecide") return q.status === "open";
335
+ return q.status !== "answered" && q.status !== "deferred";
336
+ });
270
337
  };
271
338
  const tools = [
272
339
  {
273
340
  name: "spawn_worker",
274
- description: 'Start a worker the operator will drive. `profile` is the worker (or another DRIVER \u2014 drivers-of-drivers are allowed); `task` is what it should do. Reserves the worker\u2019s budget from the conserved pool and FAILS CLOSED when the pool is dry \u2014 so spawning "at will" is bounded by the budget. Returns { workerId } or { error: "budget-exhausted" | "depth-exceeded" }.',
341
+ description: "Start a worker the driver will drive. `profile` is the worker or another driver; `task` is what it should do. Reserves budget from the conserved pool and fails closed.",
275
342
  inputSchema: {
276
343
  type: "object",
277
344
  properties: {
278
- profile: { description: "The worker/driver profile to run (passed to makeWorkerAgent)." },
345
+ profile: { description: "The worker/driver profile to run." },
279
346
  task: { description: "The task the worker should perform." },
280
347
  label: { type: "string", description: "Optional trace label." }
281
348
  },
@@ -293,7 +360,7 @@ function createCoordinationTools(opts) {
293
360
  },
294
361
  {
295
362
  name: "observe_worker",
296
- description: "Inspect a worker you are driving: its live status + conserved spend, and \u2014 once it has settled \u2014 its output artifact (rehydrated from the result blob). Use this to review work before deciding your next move. (In-flight token-level trace is surfaced via the analyst, not here.)",
363
+ description: "Inspect a worker status, spend, and settled output artifact when available.",
297
364
  inputSchema: { type: "object", properties: { workerId: idArg }, required: ["workerId"] },
298
365
  handler: async (raw) => {
299
366
  const id = str(obj(raw).workerId, "workerId");
@@ -310,7 +377,7 @@ function createCoordinationTools(opts) {
310
377
  },
311
378
  {
312
379
  name: "steer_worker",
313
- description: "Steer a RUNNING worker out-of-band \u2014 deliver your next instruction / a course-correction / an interrupt to its inbox. Returns { delivered } \u2014 false if the worker has finished or its harness cannot be steered mid-flight (then spawn a fresh one or wait and re-observe).",
380
+ description: "Deliver an out-of-band instruction to a running worker inbox.",
314
381
  inputSchema: {
315
382
  type: "object",
316
383
  properties: {
@@ -329,23 +396,124 @@ function createCoordinationTools(opts) {
329
396
  },
330
397
  {
331
398
  name: "await_next",
332
- description: 'Wait for the next worker you spawned to FINISH, then read its deployable verdict. This is how you advance: spawn one or more workers, then call await_next to block until the next one settles. Returns { settled: workerId, status: "done"|"down", score, valid } for a finished worker, or { idle: true } when no worker is still running (then spawn more or stop). Workers run concurrently \u2014 spawn a batch, then await_next repeatedly to collect them.',
399
+ description: "Wait for the next spawned worker to settle. Returns { idle: true } when none are live.",
333
400
  inputSchema: { type: "object", properties: {} },
334
401
  handler: async () => {
335
402
  const s = await opts.scope.next();
336
403
  if (!s) return { idle: true };
337
404
  const w = recordSettled(s);
338
- return w.status === "done" ? { settled: w.id, status: "done", score: w.score, valid: w.valid } : { settled: w.id, status: "down", reason: w.reason };
405
+ return w.status === "done" ? {
406
+ settled: w.id,
407
+ status: "done",
408
+ score: w.score,
409
+ valid: w.valid,
410
+ outRef: w.outRef
411
+ } : { settled: w.id, status: "down", reason: w.reason };
412
+ }
413
+ },
414
+ {
415
+ name: "list_questions",
416
+ description: "List questions raised by workers, drivers, or analysts. Blocking stop behavior follows questionPolicy.",
417
+ inputSchema: { type: "object", properties: {} },
418
+ handler: () => Promise.resolve({ questions })
419
+ },
420
+ {
421
+ name: "answer_question",
422
+ description: "Record an answer, deferral, or escalation for a loop question.",
423
+ inputSchema: {
424
+ type: "object",
425
+ properties: {
426
+ questionId: { type: "string" },
427
+ answer: { type: "string" },
428
+ by: { type: "string", description: 'Node id or "user".' },
429
+ deferReason: { type: "string" },
430
+ escalateTo: { type: "string", enum: ["parent", "user"] },
431
+ escalateReason: { type: "string" }
432
+ },
433
+ required: ["questionId"]
434
+ },
435
+ handler: (raw) => {
436
+ const a = obj(raw);
437
+ const questionId = str(a.questionId, "questionId");
438
+ if (typeof a.answer === "string" && a.answer.length > 0) {
439
+ return Promise.resolve({
440
+ question: decideQuestion(questionId, {
441
+ kind: "answer",
442
+ answer: a.answer,
443
+ by: typeof a.by === "string" && a.by.length > 0 ? a.by : "user"
444
+ })
445
+ });
446
+ }
447
+ if (typeof a.deferReason === "string" && a.deferReason.length > 0) {
448
+ return Promise.resolve({
449
+ question: decideQuestion(questionId, {
450
+ kind: "defer",
451
+ reason: a.deferReason
452
+ })
453
+ });
454
+ }
455
+ if (a.escalateTo === "parent" || a.escalateTo === "user") {
456
+ const escalateReason = typeof a.escalateReason === "string" && a.escalateReason.length > 0 ? a.escalateReason : "driver escalated";
457
+ return Promise.resolve({
458
+ question: decideQuestion(questionId, {
459
+ kind: "escalate",
460
+ to: a.escalateTo,
461
+ reason: escalateReason
462
+ })
463
+ });
464
+ }
465
+ throw new Error("answer_question: provide answer, deferReason, or escalateTo");
466
+ }
467
+ },
468
+ {
469
+ name: "ask_parent",
470
+ description: "Raise a question to the parent driver/Pi/user when this driver cannot decide.",
471
+ inputSchema: {
472
+ type: "object",
473
+ properties: {
474
+ from: { type: "string" },
475
+ level: { type: "string", enum: ["worker", "driver", "loop"] },
476
+ question: { type: "string" },
477
+ reason: { type: "string" },
478
+ urgency: { type: "string", enum: ["continue-without", "blocks-step", "blocks-run"] }
479
+ },
480
+ required: ["from", "level", "question", "reason", "urgency"]
481
+ },
482
+ handler: async (raw) => {
483
+ const a = obj(raw);
484
+ const from = str(a.from, "from");
485
+ const q = await emitNewQuestion(
486
+ addQuestion(
487
+ {
488
+ from,
489
+ level: level(a.level),
490
+ question: str(a.question, "question"),
491
+ reason: str(a.reason, "reason"),
492
+ urgency: urgency(a.urgency)
493
+ },
494
+ from,
495
+ { kind: "escalate", to: "parent", reason: "asked parent" }
496
+ )
497
+ );
498
+ return { question: q };
339
499
  }
340
500
  },
341
501
  {
342
502
  name: "stop",
343
- description: "Declare the run complete \u2014 every required change is made and verified. The terminal move.",
503
+ description: "Declare the run complete.",
344
504
  inputSchema: {
345
505
  type: "object",
346
506
  properties: { reason: { type: "string", description: "Why you are stopping." } }
347
507
  },
348
508
  handler: (raw) => {
509
+ const blocking = blockingQuestionsForStop();
510
+ if (blocking.length) {
511
+ return Promise.resolve({
512
+ stopped: false,
513
+ error: "unresolved-blocking-questions",
514
+ questions: blocking
515
+ });
516
+ }
349
517
  stopped = true;
350
518
  const r = obj(raw).reason;
351
519
  reason = typeof r === "string" ? r : void 0;
@@ -353,22 +521,20 @@ function createCoordinationTools(opts) {
353
521
  }
354
522
  }
355
523
  ];
356
- if (opts.analystKinds) {
524
+ if (opts.analysts) {
357
525
  tools.push({
358
526
  name: "list_analysts",
359
- description: "List the trace-analyst lenses available to run over a worker \u2014 id, what each looks for, and its area.",
527
+ description: "List trace-analyst lenses available to run over a settled worker.",
360
528
  inputSchema: { type: "object", properties: {} },
361
- handler: () => Promise.resolve({ analysts: opts.analystKinds })
529
+ handler: () => Promise.resolve({ analysts: opts.analysts?.kinds })
362
530
  });
363
- }
364
- if (opts.runAnalyst) {
365
531
  tools.push({
366
532
  name: "run_analyst",
367
- description: "Apply an analyst LENS to a worker you are driving \u2014 run `kind` over the worker\u2019s trace and return its findings (trace-derived, never score-derived). Use `list_analysts` for the menu; run several lenses to triangulate. The worker must have settled (its trace is read from its output).",
533
+ description: "Apply an analyst lens to a settled worker trace.",
368
534
  inputSchema: {
369
535
  type: "object",
370
536
  properties: {
371
- kind: { type: "string", description: "The analyst kind id (see list_analysts)." },
537
+ kind: { type: "string", description: "The analyst kind id." },
372
538
  workerId: idArg
373
539
  },
374
540
  required: ["kind", "workerId"]
@@ -381,11 +547,17 @@ function createCoordinationTools(opts) {
381
547
  if (!node.outRef)
382
548
  return { error: `worker ${JSON.stringify(id)} has not settled \u2014 no trace to analyze yet` };
383
549
  const trace = await opts.blobs.get(node.outRef);
384
- return { findings: await opts.runAnalyst?.(str(a.kind, "kind"), trace) };
550
+ return { findings: await opts.analysts?.run(str(a.kind, "kind"), trace) };
385
551
  }
386
552
  });
387
553
  }
388
- return { tools, isStopped: () => stopped, stopReason: () => reason, settled: () => ledger };
554
+ return {
555
+ tools,
556
+ isStopped: () => stopped,
557
+ stopReason: () => reason,
558
+ settled: () => ledger,
559
+ questions: () => questions
560
+ };
389
561
  }
390
562
  export {
391
563
  DELEGATE_CODE_DESCRIPTION,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/tools/checks.ts","../../src/mcp/tools/coordination.ts"],"sourcesContent":["/**\n * @experimental\n *\n * The trace-analyst KIND directory — the operator's lenses, as composable DATA.\n *\n * An analyst is not one question. A kind is ONE lens (completeness, correctness, policy, efficiency,\n * tool-use, …); each emits `AnalystFinding`s tagged by its `area`. The driver `list_analysts` to see\n * the menu, `run_analyst(kind, worker)` to apply a lens, and `define_analyst` to author a new one —\n * so at test time you compose the exact lenses a domain needs (maximum specificity), not one generic\n * reviewer. The kinds are data, the runner is generic, and the finding shape + firewall are reused\n * from agent-eval / the keystone — never re-derived.\n *\n * A kind here is a lightweight lens (`Check`); it is a deliberate SUBSET of agent-eval's full\n * `TraceAnalystKindSpec`, so a kind that needs the heavy agentic actor (sub-agent recursion, tools,\n * goldens) upgrades to `createTraceAnalystKind` without changing this directory's surface.\n */\n\nimport {\n type AnalystFinding,\n type AnalystSeverity,\n type EvidenceRef,\n makeFinding,\n} from '@tangle-network/agent-eval'\nimport { assertTraceDerivedFindings } from '../../runtime'\n\n// agent-eval's root entry exports the lift (`makeFinding`) + the `AnalystFinding`/`EvidenceRef` shapes\n// but NOT the raw-row validator / schema prompt (kind-factory-internal). We inline a minimal,\n// equivalent pair so a lens emits the SAME finding shape without reaching into an unstable internal.\nconst ANALYST_SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'] as const\n\nconst FINDING_SCHEMA_PROMPT = [\n 'Each finding is a JSON object with these fields:',\n '- severity: one of \"critical\" | \"high\" | \"medium\" | \"low\" | \"info\"',\n '- claim: one-sentence statement',\n '- evidence_uri: REQUIRED, never blank — exactly one of \"span://<trace>/<span>\", \"artifact://<path>\",',\n ' or \"metric://<name>\"; ALWAYS cite a real id from the trace. No citable id ⇒ omit the finding.',\n '- evidence_excerpt?: a short quote from the cited evidence',\n '- confidence: number 0..1',\n '- rationale?: one sentence of reasoning',\n '- recommended_action?: a concrete imperative (\"Add ...\", \"Replace ...\", \"Stop ...\")',\n 'Emit an empty array when there is nothing to report. Never fabricate evidence.',\n].join('\\n')\n\ninterface RawRow {\n severity: AnalystSeverity\n claim: string\n evidence_uri: string\n confidence: number\n evidence_excerpt?: string\n rationale?: string\n recommended_action?: string\n subject?: string\n}\n\n/** Validate one raw finding row (the lightweight equivalent of agent-eval's `parseRawFinding`):\n * require a claim + a real trace evidence_uri; drop anything else. Returns null to discard. */\nfunction validateRawFinding(row: unknown): RawRow | null {\n if (!row || typeof row !== 'object') return null\n const r = row as Record<string, unknown>\n if (typeof r.claim !== 'string' || r.claim.length === 0) return null\n if (typeof r.evidence_uri !== 'string' || !/^(span|artifact|metric):\\/\\//.test(r.evidence_uri))\n return null\n const sev = (ANALYST_SEVERITIES as readonly string[]).includes(r.severity as string)\n ? (r.severity as AnalystSeverity)\n : 'medium'\n return {\n severity: sev,\n claim: r.claim,\n evidence_uri: r.evidence_uri,\n confidence: typeof r.confidence === 'number' ? r.confidence : 0.5,\n ...(typeof r.evidence_excerpt === 'string' ? { evidence_excerpt: r.evidence_excerpt } : {}),\n ...(typeof r.rationale === 'string' ? { rationale: r.rationale } : {}),\n ...(typeof r.recommended_action === 'string'\n ? { recommended_action: r.recommended_action }\n : {}),\n ...(typeof r.subject === 'string' ? { subject: r.subject } : {}),\n }\n}\n\n/** One lens — a composable analyst kind. Identity fields mirror `TraceAnalystKindSpec` so a kind is\n * upgradeable to the full agentic factory; `lookFor` is the lens question the actor applies. */\nexport interface Check {\n readonly id: string\n readonly description: string\n /** Coarse classification stamped on every finding this kind emits (the renderer groups by it). */\n readonly area: string\n readonly version: string\n /** The lens — what this analyst looks for in the trace. */\n readonly lookFor: string\n}\n\n/** The built-in lens directory. Domain-blind (about any agent trace); compose at test time. */\nexport const defaultChecks: Record<string, Check> = {\n completeness: {\n id: 'completeness',\n description: 'Required work the trace does not yet show done or verified.',\n area: 'failure-mode',\n version: '1',\n lookFor:\n 'every change the task requires that the trace does NOT yet show completed AND verified by a ' +\n 'tool result. One finding per missing/unverified requirement.',\n },\n correctness: {\n id: 'correctness',\n description: 'Tool calls that produced wrong, erroring, or contradicted results.',\n area: 'correctness',\n version: '1',\n lookFor:\n 'tool calls whose RESULT shows an error, a wrong value, or contradicts what the task required ' +\n '(e.g. set the wrong field, value did not take, an error was ignored).',\n },\n policy: {\n id: 'policy',\n description: 'Actions that violate a stated policy, constraint, or allow-list.',\n area: 'safety',\n version: '1',\n lookFor:\n 'actions in the trace that violate a policy/constraint stated in the task or system prompt ' +\n '(forbidden tool, missing approval, out-of-scope mutation, skipped precondition).',\n },\n efficiency: {\n id: 'efficiency',\n description: 'Wasted, redundant, or looping work.',\n area: 'cost',\n version: '1',\n lookFor:\n 'redundant or wasted actions — repeated identical calls, a stalled line retried the same way, ' +\n 'work that produced no progress toward the goal.',\n },\n 'tool-use': {\n id: 'tool-use',\n description: 'Malformed or misused tool calls.',\n area: 'tool-use',\n version: '1',\n lookFor:\n 'tool calls with malformed/invalid arguments, the wrong tool for the intent, or a tool used ' +\n 'against its contract — judged from the call + its result.',\n },\n}\n\n/** Lift validated raw rows into `AnalystFinding`s (agent-eval `makeFinding` stamps `finding_id`/\n * `produced_at`), then enforce the trace-derived firewall (selector ≠ judge). Pure — no LLM. */\nexport function liftFindings(kind: Check, rows: unknown[], producedAt: string): AnalystFinding[] {\n const findings: AnalystFinding[] = []\n for (const row of rows) {\n const raw = validateRawFinding(row)\n if (!raw) continue\n findings.push(\n makeFinding({\n analyst_id: kind.id,\n area: kind.area,\n severity: raw.severity,\n claim: raw.claim,\n confidence: raw.confidence,\n produced_at: producedAt,\n evidence_refs: evidenceRefs(raw.evidence_uri, raw.evidence_excerpt),\n ...(raw.rationale ? { rationale: raw.rationale } : {}),\n ...(raw.recommended_action ? { recommended_action: raw.recommended_action } : {}),\n ...(raw.subject ? { subject: raw.subject } : {}),\n metadata: { kind_version: kind.version },\n }),\n )\n }\n assertTraceDerivedFindings(findings) // throws if a finding cites judge/verdict/score evidence\n return findings\n}\n\n/** Map a raw `evidence_uri` (span:// | artifact:// | metric://<name>) to a typed `EvidenceRef`. A\n * metric ref carries the bare NAME (the firewall checks the metric name for judge/verdict/score —\n * so a finding that cites a judge metric is rejected as not trace-derived). */\nfunction evidenceRefs(uri: string, excerpt?: string): EvidenceRef[] {\n const scheme = uri.split('://', 1)[0]\n if (scheme === 'metric')\n return [\n { kind: 'metric', uri: uri.replace(/^metric:\\/\\//, ''), ...(excerpt ? { excerpt } : {}) },\n ]\n const kind: EvidenceRef['kind'] = scheme === 'span' ? 'span' : 'artifact'\n return [{ kind, uri, ...(excerpt ? { excerpt } : {}) }]\n}\n\n/** Render a worker's trace (tool calls + results) into the text an analyst lens reads. Generic over\n * the trace shape: a `{ messages }` conversation, a bare message array, else stringified. */\nexport function renderTrace(trace: unknown): string {\n const messages = Array.isArray(trace)\n ? trace\n : trace &&\n typeof trace === 'object' &&\n Array.isArray((trace as { messages?: unknown[] }).messages)\n ? (trace as { messages: unknown[] }).messages\n : undefined\n if (!messages) return JSON.stringify(trace ?? {}).slice(0, 8000)\n return messages\n .map((m) => {\n const r = m as {\n role?: string\n content?: unknown\n tool_calls?: Array<{ function?: { name?: string; arguments?: string } }>\n }\n if (r.role === 'tool') return `RESULT ${String(r.content).slice(0, 300)}`\n const calls = r.tool_calls\n ?.map((c) => `${c.function?.name}(${c.function?.arguments})`)\n .join(', ')\n return calls ? `CALL ${calls}` : `SAY ${String(r.content ?? '').slice(0, 200)}`\n })\n .join('\\n')\n .slice(0, 8000)\n}\n\nexport interface CheckRunnerOptions {\n routerBaseUrl: string\n routerKey: string\n model: string\n /** Test/override seam — replace the LLM call. Default: a router chat completion. */\n chat?: (system: string, user: string) => Promise<string>\n}\n\n/** Run ONE lens over a trace → findings. Generic over any kind: prompt = the lens + the agent-eval\n * finding schema; the model's JSON array is parsed (`parseRawFinding`), lifted, and firewalled. */\nexport async function runCheck(\n kind: Check,\n trace: unknown,\n opts: CheckRunnerOptions,\n producedAt: string,\n): Promise<AnalystFinding[]> {\n const sys =\n `You are a trace analyst applying ONE lens: look for ${kind.lookFor}\\n\\n` +\n `${FINDING_SCHEMA_PROMPT}\\n\\nReturn ONLY a fenced \\`\\`\\`json array of finding objects (possibly empty).`\n const user = `WORKER TRACE:\\n${renderTrace(trace)}\\n\\nApply your lens and emit the findings array.`\n const chat = opts.chat ?? defaultChat(opts)\n const content = await chat(sys, user)\n const match = content.match(/```(?:json)?\\s*([\\s\\S]*?)```/)\n let rows: unknown[] = []\n try {\n const parsed = JSON.parse((match?.[1] ?? content).trim())\n rows = Array.isArray(parsed)\n ? parsed\n : Array.isArray((parsed as { findings?: unknown[] })?.findings)\n ? (parsed as { findings: unknown[] }).findings\n : []\n } catch {\n rows = []\n }\n return liftFindings(kind, rows, producedAt)\n}\n\nfunction defaultChat(opts: CheckRunnerOptions): (system: string, user: string) => Promise<string> {\n return async (system, user) => {\n const res = await fetch(`${opts.routerBaseUrl.replace(/\\/$/, '')}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${opts.routerKey}` },\n body: JSON.stringify({\n model: opts.model,\n messages: [\n { role: 'system', content: system },\n { role: 'user', content: user },\n ],\n temperature: 0.3,\n }),\n })\n if (!res.ok) throw new Error(`analyst router ${res.status}`)\n const data = (await res.json()) as { choices?: Array<{ message?: { content?: string } }> }\n return data.choices?.[0]?.message?.content ?? ''\n }\n}\n\n/** Build a `run_analyst` runner over a kind directory — the seam the operator toolbox is wired with.\n * Returns the findings, or a typed error for an unknown kind. `producedAt` is passed in (the runtime\n * forbids `Date.now` in replay-safe paths; the caller stamps it). */\nexport function makeCheckRunner(\n kinds: Record<string, Check>,\n opts: CheckRunnerOptions,\n): (\n kindId: string,\n trace: unknown,\n producedAt: string,\n) => Promise<AnalystFinding[] | { error: string }> {\n return async (kindId, trace, producedAt) => {\n const kind = kinds[kindId]\n if (!kind)\n return {\n error: `unknown analyst kind ${JSON.stringify(kindId)} (have: ${Object.keys(kinds).join(', ')})`,\n }\n return runCheck(kind, trace, opts, producedAt)\n }\n}\n","/**\n * @experimental\n *\n * COORDINATION TOOLS — the verbs a parent agent uses to coordinate the child agents it spawns,\n * exposed as MCP tools backed by a live keystone `Scope`. This is `Scope`-as-MCP.\n *\n * NOT a transport. The cross-org message bus (`docs/agent-bus-protocol.md`) and the SDK's\n * `dispatchPrompt`/`SessionMessage` are the *transports* the `steer` verb rides; THIS file is the\n * verb set (the API). One verb, several bindings: in-process `Scope.send` is a direct call; across\n * sandboxes it rides SDK session-messaging; across orgs it rides the agent-bus protocol.\n *\n * spawn_worker → scope.spawn (budget-bounded, fail-closed — equal-k holds even for an LLM driver)\n * await_next → scope.next (THE wake event: block until the next spawned child settles)\n * observe_worker→ scope.view + the result blob (a child's status, spend, and settled output)\n * steer_worker → scope.send (deliver a next-instruction / interrupt to a RUNNING child)\n * list_analysts → the check menu (the trace lenses the agent can apply — see checks.ts)\n * run_analyst → apply a CHECK (run a kind over a child's trace → trace-derived findings)\n * stop → declare the run complete (the terminal move)\n *\n * The check verbs are present only when the check seam (`analystKinds` + `runAnalyst`) is wired —\n * an agent that does not review traces (a pure dispatcher) omits them. A trace check is a SEPARATE\n * lens (selector ≠ judge: it reads the trace, never the score); authoring a NEW check at runtime is\n * the next addition.\n *\n * A worker the driver spawns may itself carry the driver profile — `spawn_worker` does not care what\n * the profile is, so drivers-of-drivers fall out for free (each sub-driver gets its own sub-scope,\n * bounded by `maxDepth` + the conserved pool).\n */\n\nimport type {\n Budget,\n ResultBlobStore,\n Scope,\n Settled,\n Agent as SuperviseAgent,\n} from '../../runtime'\nimport type { McpToolDescriptor } from '../server'\n\n/** A worker the driver has drained via `await_next` — the operator's running ledger of settled\n * workers + their DEPLOYABLE verdict (the driver IS the selector, so it legitimately reads the\n * verdict; the analyst, which reads only the trace, is the separate selector≠judge lens). The\n * driver picks its deliverable from this ledger at `stop`. */\nexport interface SettledWorker {\n readonly id: string\n readonly status: 'done' | 'down'\n /** Deployable score in [0,1] from the worker's verdict (done only). */\n readonly score?: number\n /** Whether the deployable verdict passed (done only). */\n readonly valid?: boolean\n /** Result-blob pointer for the worker's output/trace (done only). */\n readonly outRef?: string\n /** Failure reason (down only). */\n readonly reason?: string\n}\n\n/** How a `spawn_worker` profile becomes a spawnable leaf `Agent`. The caller wires this (e.g. the\n * surface registry turns a profile into a shot executor) so the toolbox stays domain-blind. */\nexport type MakeWorkerAgent = (profile: unknown) => SuperviseAgent<unknown, unknown>\n\nexport interface CoordinationToolsOptions {\n /** The DRIVER's live scope — spawn/observe/steer all act on this. */\n readonly scope: Scope<unknown>\n /** Result blobs, so `observe_worker` can rehydrate a settled worker's output. */\n readonly blobs: ResultBlobStore\n /** Turn a spawn_worker `profile` into a leaf agent (registry-resolved on spawn). */\n readonly makeWorkerAgent: MakeWorkerAgent\n /** Per-worker conserved budget the driver reserves on each spawn. */\n readonly perWorker: Budget\n /** The analyst lens menu (for `list_analysts`) — id + one-line + area. Injected so the toolbox\n * stays domain-blind; wire it from `analyst-kinds.ts`'s directory. Omit to disable analyst tools. */\n readonly analystKinds?: ReadonlyArray<{ id: string; description: string; area: string }>\n /** Run a lens over a worker's trace → findings (or a typed error). Wire it from\n * `makeCheckRunner(...)`. `run_analyst` fetches the worker's settled output and passes it here. */\n readonly runAnalyst?: (kindId: string, trace: unknown) => Promise<unknown>\n}\n\nexport interface CoordinationTools {\n /** MCP tools — register on an `McpServer`, or call the handlers directly in-process. */\n readonly tools: McpToolDescriptor[]\n /** True once the driver called `stop` — the operator loop reads this to terminate. */\n isStopped(): boolean\n /** The reason passed to `stop`, if any. */\n stopReason(): string | undefined\n /** The workers drained so far via `await_next` (the driver's selection ledger). */\n settled(): ReadonlyArray<SettledWorker>\n}\n\nconst idArg = { type: 'string', description: 'The workerId returned by spawn_worker.' } as const\n\n/** Build the operator toolbox over a live scope. The tools are the driver's verbs; their handlers\n * are thin wrappers over the keystone (spawn/view/send), so the budget/journal/abort discipline of\n * the Supervisor applies to a sandbox driver exactly as to the in-process one. */\nexport function createCoordinationTools(opts: CoordinationToolsOptions): CoordinationTools {\n let stopped = false\n let reason: string | undefined\n const ledger: SettledWorker[] = []\n\n const recordSettled = (s: Settled<unknown>): SettledWorker => {\n const w: SettledWorker =\n s.kind === 'done'\n ? {\n id: s.handle.id,\n status: 'done',\n score: s.verdict?.score ?? 0,\n valid: s.verdict?.valid ?? false,\n outRef: s.outRef,\n }\n : { id: s.handle.id, status: 'down', reason: s.reason }\n ledger.push(w)\n return w\n }\n\n const str = (v: unknown, field: string): string => {\n if (typeof v !== 'string' || v.length === 0)\n throw new Error(`operator toolbox: \"${field}\" must be a non-empty string`)\n return v\n }\n const obj = (raw: unknown): Record<string, unknown> => {\n if (!raw || typeof raw !== 'object')\n throw new Error('operator toolbox: arguments must be an object')\n return raw as Record<string, unknown>\n }\n\n const tools: McpToolDescriptor[] = [\n {\n name: 'spawn_worker',\n description:\n 'Start a worker the operator will drive. `profile` is the worker (or another DRIVER — ' +\n 'drivers-of-drivers are allowed); `task` is what it should do. Reserves the worker’s budget ' +\n 'from the conserved pool and FAILS CLOSED when the pool is dry — so spawning \"at will\" is ' +\n 'bounded by the budget. Returns { workerId } or { error: \"budget-exhausted\" | \"depth-exceeded\" }.',\n inputSchema: {\n type: 'object',\n properties: {\n profile: { description: 'The worker/driver profile to run (passed to makeWorkerAgent).' },\n task: { description: 'The task the worker should perform.' },\n label: { type: 'string', description: 'Optional trace label.' },\n },\n required: ['profile', 'task'],\n },\n handler: (raw) => {\n const a = obj(raw)\n const agent = opts.makeWorkerAgent(a.profile)\n const res = opts.scope.spawn(agent, a.task, {\n budget: opts.perWorker,\n label: typeof a.label === 'string' ? a.label : 'worker',\n })\n return Promise.resolve(res.ok ? { workerId: res.handle.id } : { error: res.reason })\n },\n },\n {\n name: 'observe_worker',\n description:\n 'Inspect a worker you are driving: its live status + conserved spend, and — once it has ' +\n 'settled — its output artifact (rehydrated from the result blob). Use this to review work ' +\n 'before deciding your next move. (In-flight token-level trace is surfaced via the analyst, ' +\n 'not here.)',\n inputSchema: { type: 'object', properties: { workerId: idArg }, required: ['workerId'] },\n handler: async (raw) => {\n const id = str(obj(raw).workerId, 'workerId')\n const node = opts.scope.view.nodes.find((n) => n.id === id)\n if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` }\n const output = node.outRef ? await opts.blobs.get(node.outRef) : undefined\n return {\n status: node.status,\n spent: node.spent,\n outRef: node.outRef ?? null,\n output: output ?? null,\n }\n },\n },\n {\n name: 'steer_worker',\n description:\n 'Steer a RUNNING worker out-of-band — deliver your next instruction / a course-correction / ' +\n 'an interrupt to its inbox. Returns { delivered } — false if the worker has finished or its ' +\n 'harness cannot be steered mid-flight (then spawn a fresh one or wait and re-observe).',\n inputSchema: {\n type: 'object',\n properties: {\n workerId: idArg,\n instruction: { type: 'string', description: 'What the worker should do next.' },\n },\n required: ['workerId', 'instruction'],\n },\n handler: (raw) => {\n const a = obj(raw)\n const delivered = opts.scope.send(str(a.workerId, 'workerId'), {\n steer: str(a.instruction, 'instruction'),\n })\n return Promise.resolve({ delivered })\n },\n },\n {\n name: 'await_next',\n description:\n 'Wait for the next worker you spawned to FINISH, then read its deployable verdict. This is ' +\n 'how you advance: spawn one or more workers, then call await_next to block until the next ' +\n 'one settles. Returns { settled: workerId, status: \"done\"|\"down\", score, valid } for a ' +\n 'finished worker, or { idle: true } when no worker is still running (then spawn more or stop). ' +\n 'Workers run concurrently — spawn a batch, then await_next repeatedly to collect them.',\n inputSchema: { type: 'object', properties: {} },\n handler: async () => {\n const s = await opts.scope.next()\n if (!s) return { idle: true }\n const w = recordSettled(s)\n return w.status === 'done'\n ? { settled: w.id, status: 'done', score: w.score, valid: w.valid }\n : { settled: w.id, status: 'down', reason: w.reason }\n },\n },\n {\n name: 'stop',\n description:\n 'Declare the run complete — every required change is made and verified. The terminal move.',\n inputSchema: {\n type: 'object',\n properties: { reason: { type: 'string', description: 'Why you are stopping.' } },\n },\n handler: (raw) => {\n stopped = true\n const r = obj(raw).reason\n reason = typeof r === 'string' ? r : undefined\n return Promise.resolve({ stopped: true })\n },\n },\n ]\n\n // list_analysts / run_analyst — present only when the analyst seam is wired. The driver picks a\n // kind from the menu and applies it to a worker it is driving; findings are trace-derived (the\n // firewall lives in the runner). (define_analyst — authoring a NEW kind at runtime — is deferred.)\n if (opts.analystKinds) {\n tools.push({\n name: 'list_analysts',\n description:\n 'List the trace-analyst lenses available to run over a worker — id, what each looks for, and its area.',\n inputSchema: { type: 'object', properties: {} },\n handler: () => Promise.resolve({ analysts: opts.analystKinds }),\n })\n }\n if (opts.runAnalyst) {\n tools.push({\n name: 'run_analyst',\n description:\n 'Apply an analyst LENS to a worker you are driving — run `kind` over the worker’s trace and ' +\n 'return its findings (trace-derived, never score-derived). Use `list_analysts` for the menu; ' +\n 'run several lenses to triangulate. The worker must have settled (its trace is read from its output).',\n inputSchema: {\n type: 'object',\n properties: {\n kind: { type: 'string', description: 'The analyst kind id (see list_analysts).' },\n workerId: idArg,\n },\n required: ['kind', 'workerId'],\n },\n handler: async (raw) => {\n const a = obj(raw)\n const id = str(a.workerId, 'workerId')\n const node = opts.scope.view.nodes.find((n) => n.id === id)\n if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` }\n if (!node.outRef)\n return { error: `worker ${JSON.stringify(id)} has not settled — no trace to analyze yet` }\n const trace = await opts.blobs.get(node.outRef)\n return { findings: await opts.runAnalyst?.(str(a.kind, 'kind'), trace) }\n },\n })\n }\n\n return { tools, isStopped: () => stopped, stopReason: () => reason, settled: () => ledger }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA;AAAA,EAIE;AAAA,OACK;AAMP,IAAM,qBAAqB,CAAC,YAAY,QAAQ,UAAU,OAAO,MAAM;AAEvE,IAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,IAAI;AAeX,SAAS,mBAAmB,KAA6B;AACvD,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;AAC5C,QAAM,IAAI;AACV,MAAI,OAAO,EAAE,UAAU,YAAY,EAAE,MAAM,WAAW,EAAG,QAAO;AAChE,MAAI,OAAO,EAAE,iBAAiB,YAAY,CAAC,+BAA+B,KAAK,EAAE,YAAY;AAC3F,WAAO;AACT,QAAM,MAAO,mBAAyC,SAAS,EAAE,QAAkB,IAC9E,EAAE,WACH;AACJ,SAAO;AAAA,IACL,UAAU;AAAA,IACV,OAAO,EAAE;AAAA,IACT,cAAc,EAAE;AAAA,IAChB,YAAY,OAAO,EAAE,eAAe,WAAW,EAAE,aAAa;AAAA,IAC9D,GAA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cp/tools/coordination.ts"],"sourcesContent":["/**\n * @experimental\n *\n * The trace-analyst KIND directory — the operator's lenses, as composable DATA.\n *\n * An analyst is not one question. A kind is ONE lens (completeness, correctness, policy, efficiency,\n * tool-use, …); each emits `AnalystFinding`s tagged by its `area`. The driver `list_analysts` to see\n * the menu, `run_analyst(kind, worker)` to apply a lens, and `define_analyst` to author a new one —\n * so at test time you compose the exact lenses a domain needs (maximum specificity), not one generic\n * reviewer. The kinds are data, the runner is generic, and the finding shape + firewall are reused\n * from agent-eval / the keystone — never re-derived.\n *\n * A kind here is a lightweight lens (`Check`); it is a deliberate SUBSET of agent-eval's full\n * `TraceAnalystKindSpec`, so a kind that needs the heavy agentic actor (sub-agent recursion, tools,\n * goldens) upgrades to `createTraceAnalystKind` without changing this directory's surface.\n */\n\nimport {\n type AnalystFinding,\n type AnalystSeverity,\n type EvidenceRef,\n makeFinding,\n} from '@tangle-network/agent-eval'\nimport { assertTraceDerivedFindings } from '../../runtime'\n\n// agent-eval's root entry exports the lift (`makeFinding`) + the `AnalystFinding`/`EvidenceRef` shapes\n// but NOT the raw-row validator / schema prompt (kind-factory-internal). We inline a minimal,\n// equivalent pair so a lens emits the SAME finding shape without reaching into an unstable internal.\nconst ANALYST_SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'] as const\n\nconst FINDING_SCHEMA_PROMPT = [\n 'Each finding is a JSON object with these fields:',\n '- severity: one of \"critical\" | \"high\" | \"medium\" | \"low\" | \"info\"',\n '- claim: one-sentence statement',\n '- evidence_uri: REQUIRED, never blank — exactly one of \"span://<trace>/<span>\", \"artifact://<path>\",',\n ' or \"metric://<name>\"; ALWAYS cite a real id from the trace. No citable id ⇒ omit the finding.',\n '- evidence_excerpt?: a short quote from the cited evidence',\n '- confidence: number 0..1',\n '- rationale?: one sentence of reasoning',\n '- recommended_action?: a concrete imperative (\"Add ...\", \"Replace ...\", \"Stop ...\")',\n 'Emit an empty array when there is nothing to report. Never fabricate evidence.',\n].join('\\n')\n\ninterface RawRow {\n severity: AnalystSeverity\n claim: string\n evidence_uri: string\n confidence: number\n evidence_excerpt?: string\n rationale?: string\n recommended_action?: string\n subject?: string\n}\n\n/** Validate one raw finding row (the lightweight equivalent of agent-eval's `parseRawFinding`):\n * require a claim + a real trace evidence_uri; drop anything else. Returns null to discard. */\nfunction validateRawFinding(row: unknown): RawRow | null {\n if (!row || typeof row !== 'object') return null\n const r = row as Record<string, unknown>\n if (typeof r.claim !== 'string' || r.claim.length === 0) return null\n if (typeof r.evidence_uri !== 'string' || !/^(span|artifact|metric):\\/\\//.test(r.evidence_uri))\n return null\n const sev = (ANALYST_SEVERITIES as readonly string[]).includes(r.severity as string)\n ? (r.severity as AnalystSeverity)\n : 'medium'\n return {\n severity: sev,\n claim: r.claim,\n evidence_uri: r.evidence_uri,\n confidence: typeof r.confidence === 'number' ? r.confidence : 0.5,\n ...(typeof r.evidence_excerpt === 'string' ? { evidence_excerpt: r.evidence_excerpt } : {}),\n ...(typeof r.rationale === 'string' ? { rationale: r.rationale } : {}),\n ...(typeof r.recommended_action === 'string'\n ? { recommended_action: r.recommended_action }\n : {}),\n ...(typeof r.subject === 'string' ? { subject: r.subject } : {}),\n }\n}\n\n/** One lens — a composable analyst kind. Identity fields mirror `TraceAnalystKindSpec` so a kind is\n * upgradeable to the full agentic factory; `lookFor` is the lens question the actor applies. */\nexport interface Check {\n readonly id: string\n readonly description: string\n /** Coarse classification stamped on every finding this kind emits (the renderer groups by it). */\n readonly area: string\n readonly version: string\n /** The lens — what this analyst looks for in the trace. */\n readonly lookFor: string\n}\n\n/** The built-in lens directory. Domain-blind (about any agent trace); compose at test time. */\nexport const defaultChecks: Record<string, Check> = {\n completeness: {\n id: 'completeness',\n description: 'Required work the trace does not yet show done or verified.',\n area: 'failure-mode',\n version: '1',\n lookFor:\n 'every change the task requires that the trace does NOT yet show completed AND verified by a ' +\n 'tool result. One finding per missing/unverified requirement.',\n },\n correctness: {\n id: 'correctness',\n description: 'Tool calls that produced wrong, erroring, or contradicted results.',\n area: 'correctness',\n version: '1',\n lookFor:\n 'tool calls whose RESULT shows an error, a wrong value, or contradicts what the task required ' +\n '(e.g. set the wrong field, value did not take, an error was ignored).',\n },\n policy: {\n id: 'policy',\n description: 'Actions that violate a stated policy, constraint, or allow-list.',\n area: 'safety',\n version: '1',\n lookFor:\n 'actions in the trace that violate a policy/constraint stated in the task or system prompt ' +\n '(forbidden tool, missing approval, out-of-scope mutation, skipped precondition).',\n },\n efficiency: {\n id: 'efficiency',\n description: 'Wasted, redundant, or looping work.',\n area: 'cost',\n version: '1',\n lookFor:\n 'redundant or wasted actions — repeated identical calls, a stalled line retried the same way, ' +\n 'work that produced no progress toward the goal.',\n },\n 'tool-use': {\n id: 'tool-use',\n description: 'Malformed or misused tool calls.',\n area: 'tool-use',\n version: '1',\n lookFor:\n 'tool calls with malformed/invalid arguments, the wrong tool for the intent, or a tool used ' +\n 'against its contract — judged from the call + its result.',\n },\n}\n\n/** Lift validated raw rows into `AnalystFinding`s (agent-eval `makeFinding` stamps `finding_id`/\n * `produced_at`), then enforce the trace-derived firewall (selector ≠ judge). Pure — no LLM. */\nexport function liftFindings(kind: Check, rows: unknown[], producedAt: string): AnalystFinding[] {\n const findings: AnalystFinding[] = []\n for (const row of rows) {\n const raw = validateRawFinding(row)\n if (!raw) continue\n findings.push(\n makeFinding({\n analyst_id: kind.id,\n area: kind.area,\n severity: raw.severity,\n claim: raw.claim,\n confidence: raw.confidence,\n produced_at: producedAt,\n evidence_refs: evidenceRefs(raw.evidence_uri, raw.evidence_excerpt),\n ...(raw.rationale ? { rationale: raw.rationale } : {}),\n ...(raw.recommended_action ? { recommended_action: raw.recommended_action } : {}),\n ...(raw.subject ? { subject: raw.subject } : {}),\n metadata: { kind_version: kind.version },\n }),\n )\n }\n assertTraceDerivedFindings(findings) // throws if a finding cites judge/verdict/score evidence\n return findings\n}\n\n/** Map a raw `evidence_uri` (span:// | artifact:// | metric://<name>) to a typed `EvidenceRef`. A\n * metric ref carries the bare NAME (the firewall checks the metric name for judge/verdict/score —\n * so a finding that cites a judge metric is rejected as not trace-derived). */\nfunction evidenceRefs(uri: string, excerpt?: string): EvidenceRef[] {\n const scheme = uri.split('://', 1)[0]\n if (scheme === 'metric')\n return [\n { kind: 'metric', uri: uri.replace(/^metric:\\/\\//, ''), ...(excerpt ? { excerpt } : {}) },\n ]\n const kind: EvidenceRef['kind'] = scheme === 'span' ? 'span' : 'artifact'\n return [{ kind, uri, ...(excerpt ? { excerpt } : {}) }]\n}\n\n/** Render a worker's trace (tool calls + results) into the text an analyst lens reads. Generic over\n * the trace shape: a `{ messages }` conversation, a bare message array, else stringified. */\nexport function renderTrace(trace: unknown): string {\n const messages = Array.isArray(trace)\n ? trace\n : trace &&\n typeof trace === 'object' &&\n Array.isArray((trace as { messages?: unknown[] }).messages)\n ? (trace as { messages: unknown[] }).messages\n : undefined\n if (!messages) return JSON.stringify(trace ?? {}).slice(0, 8000)\n return messages\n .map((m) => {\n const r = m as {\n role?: string\n content?: unknown\n tool_calls?: Array<{ function?: { name?: string; arguments?: string } }>\n }\n if (r.role === 'tool') return `RESULT ${String(r.content).slice(0, 300)}`\n const calls = r.tool_calls\n ?.map((c) => `${c.function?.name}(${c.function?.arguments})`)\n .join(', ')\n return calls ? `CALL ${calls}` : `SAY ${String(r.content ?? '').slice(0, 200)}`\n })\n .join('\\n')\n .slice(0, 8000)\n}\n\nexport interface CheckRunnerOptions {\n routerBaseUrl: string\n routerKey: string\n model: string\n /** Test/override seam — replace the LLM call. Default: a router chat completion. */\n chat?: (system: string, user: string) => Promise<string>\n}\n\n/** Run ONE lens over a trace → findings. Generic over any kind: prompt = the lens + the agent-eval\n * finding schema; the model's JSON array is parsed (`parseRawFinding`), lifted, and firewalled. */\nexport async function runCheck(\n kind: Check,\n trace: unknown,\n opts: CheckRunnerOptions,\n producedAt: string,\n): Promise<AnalystFinding[]> {\n const sys =\n `You are a trace analyst applying ONE lens: look for ${kind.lookFor}\\n\\n` +\n `${FINDING_SCHEMA_PROMPT}\\n\\nReturn ONLY a fenced \\`\\`\\`json array of finding objects (possibly empty).`\n const user = `WORKER TRACE:\\n${renderTrace(trace)}\\n\\nApply your lens and emit the findings array.`\n const chat = opts.chat ?? defaultChat(opts)\n const content = await chat(sys, user)\n const match = content.match(/```(?:json)?\\s*([\\s\\S]*?)```/)\n let rows: unknown[] = []\n try {\n const parsed = JSON.parse((match?.[1] ?? content).trim())\n rows = Array.isArray(parsed)\n ? parsed\n : Array.isArray((parsed as { findings?: unknown[] })?.findings)\n ? (parsed as { findings: unknown[] }).findings\n : []\n } catch {\n rows = []\n }\n return liftFindings(kind, rows, producedAt)\n}\n\nfunction defaultChat(opts: CheckRunnerOptions): (system: string, user: string) => Promise<string> {\n return async (system, user) => {\n const res = await fetch(`${opts.routerBaseUrl.replace(/\\/$/, '')}/chat/completions`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${opts.routerKey}` },\n body: JSON.stringify({\n model: opts.model,\n messages: [\n { role: 'system', content: system },\n { role: 'user', content: user },\n ],\n temperature: 0.3,\n }),\n })\n if (!res.ok) throw new Error(`analyst router ${res.status}`)\n const data = (await res.json()) as { choices?: Array<{ message?: { content?: string } }> }\n return data.choices?.[0]?.message?.content ?? ''\n }\n}\n\n/**\n * Build a `run_analyst` runner over a kind directory.\n * Returns findings, or a typed error for an unknown kind. `producedAt` is\n * passed in because replay-safe paths must not read `Date.now`.\n */\nexport function makeCheckRunner(\n kinds: Record<string, Check>,\n opts: CheckRunnerOptions,\n): (\n kindId: string,\n trace: unknown,\n producedAt: string,\n) => Promise<AnalystFinding[] | { error: string }> {\n return async (kindId, trace, producedAt) => {\n const kind = kinds[kindId]\n if (!kind)\n return {\n error: `unknown analyst kind ${JSON.stringify(kindId)} (have: ${Object.keys(kinds).join(', ')})`,\n }\n return runCheck(kind, trace, opts, producedAt)\n }\n}\n","/**\n * @experimental\n *\n * MCP binding for a live `Scope`. A sandbox driver gets the same small verbs\n * the in-process driver has: spawn, observe, await, steer, ask/answer, analyze,\n * and stop. Settled outputs remain Scope artifacts; product code can project\n * them into any UI/report envelope it needs.\n */\n\nimport type {\n Budget,\n ResultBlobStore,\n Scope,\n Settled,\n Agent as SuperviseAgent,\n} from '../../runtime'\nimport type { McpToolDescriptor } from '../server'\n\n/** A worker the driver has drained via `await_next`. */\nexport interface SettledWorker {\n readonly id: string\n readonly status: 'done' | 'down'\n readonly score?: number\n readonly valid?: boolean\n readonly outRef?: string\n readonly reason?: string\n}\n\nexport type QuestionLevel = 'worker' | 'driver' | 'loop'\nexport type QuestionUrgency = 'continue-without' | 'blocks-step' | 'blocks-run'\n\nexport interface QuestionOption {\n readonly label: string\n readonly tradeoff: string\n}\n\nexport interface Question {\n readonly id: string\n readonly from: string\n readonly level: QuestionLevel\n readonly question: string\n readonly reason: string\n readonly urgency: QuestionUrgency\n readonly options?: ReadonlyArray<QuestionOption>\n}\n\nexport type QuestionDecision =\n | { readonly kind: 'answer'; readonly answer: string; readonly by: string }\n | { readonly kind: 'defer'; readonly reason: string }\n | { readonly kind: 'escalate'; readonly to: 'parent' | 'user' | string; readonly reason: string }\n\nexport interface QuestionRecord extends Question {\n readonly status: 'open' | 'answered' | 'deferred' | 'escalated'\n readonly decision?: QuestionDecision\n readonly openedAt: number\n}\n\ntype QuestionInput = Omit<Question, 'id'> & { readonly id?: string }\nexport type QuestionPolicy = 'auto' | 'mustDecide' | 'bubble' | 'failClosed'\n\nexport interface AnalystRegistry {\n readonly kinds: ReadonlyArray<{ id: string; description: string; area: string }>\n readonly run: (kindId: string, trace: unknown) => Promise<unknown>\n}\n\nexport type CoordinationEvent = { readonly type: 'question'; readonly question: QuestionRecord }\n\nexport type MakeWorkerAgent = (profile: unknown) => SuperviseAgent<unknown, unknown>\n\nexport interface CoordinationToolsOptions {\n readonly scope: Scope<unknown>\n readonly blobs: ResultBlobStore\n readonly makeWorkerAgent: MakeWorkerAgent\n readonly perWorker: Budget\n readonly analysts?: AnalystRegistry\n readonly onEvent?: (event: CoordinationEvent) => void | Promise<void>\n readonly questionPolicy?: QuestionPolicy\n}\n\nexport interface CoordinationTools {\n readonly tools: McpToolDescriptor[]\n isStopped(): boolean\n stopReason(): string | undefined\n settled(): ReadonlyArray<SettledWorker>\n questions(): ReadonlyArray<QuestionRecord>\n}\n\nconst idArg = { type: 'string', description: 'The workerId returned by spawn_worker.' } as const\n\n/** Build the driver's MCP tools over a live scope. */\nexport function createCoordinationTools(opts: CoordinationToolsOptions): CoordinationTools {\n let stopped = false\n let reason: string | undefined\n let questionSeq = 0\n const ledger: SettledWorker[] = []\n const questions: QuestionRecord[] = []\n const questionPolicy = opts.questionPolicy ?? 'auto'\n\n const str = (v: unknown, field: string): string => {\n if (typeof v !== 'string' || v.length === 0)\n throw new Error(`coordination tools: \"${field}\" must be a non-empty string`)\n return v\n }\n const obj = (raw: unknown): Record<string, unknown> => {\n if (!raw || typeof raw !== 'object')\n throw new Error('coordination tools: arguments must be an object')\n return raw as Record<string, unknown>\n }\n const level = (v: unknown): Question['level'] => {\n if (v === 'worker' || v === 'driver' || v === 'loop') return v\n throw new Error('coordination tools: \"level\" must be worker, driver, or loop')\n }\n const urgency = (v: unknown): Question['urgency'] => {\n if (v === 'continue-without' || v === 'blocks-step' || v === 'blocks-run') return v\n throw new Error(\n 'coordination tools: \"urgency\" must be continue-without, blocks-step, or blocks-run',\n )\n }\n\n const recordSettled = (s: Settled<unknown>): SettledWorker => {\n const w: SettledWorker =\n s.kind === 'done'\n ? {\n id: s.handle.id,\n status: 'done',\n score: s.verdict?.score ?? 0,\n valid: s.verdict?.valid ?? false,\n outRef: s.outRef,\n }\n : { id: s.handle.id, status: 'down', reason: s.reason }\n ledger.push(w)\n return w\n }\n\n const nextQuestionId = (from: string): string => `${from}:q${questionSeq++}`\n const normalizeQuestion = (q: QuestionInput, fallbackFrom: string): Question => {\n const from = str(q.from ?? fallbackFrom, 'from')\n return {\n id: typeof q.id === 'string' && q.id.length > 0 ? q.id : nextQuestionId(from),\n from,\n level: level(q.level),\n question: str(q.question, 'question'),\n reason: str(q.reason, 'reason'),\n ...(q.options ? { options: q.options } : {}),\n urgency: urgency(q.urgency),\n }\n }\n const addQuestion = (\n raw: QuestionInput,\n fallbackFrom: string,\n decision?: QuestionDecision,\n ): { question: QuestionRecord; added: boolean } => {\n const q = normalizeQuestion(raw, fallbackFrom)\n const existing = questions.find((x) => x.id === q.id)\n if (existing) return { question: existing, added: false }\n const effectiveDecision =\n decision ??\n (questionPolicy === 'bubble'\n ? ({\n kind: 'escalate',\n to: 'parent',\n reason: 'question policy bubbled to parent',\n } as const)\n : undefined)\n const status: QuestionRecord['status'] =\n effectiveDecision?.kind === 'answer'\n ? 'answered'\n : effectiveDecision?.kind === 'defer'\n ? 'deferred'\n : effectiveDecision?.kind === 'escalate'\n ? 'escalated'\n : 'open'\n const record: QuestionRecord = {\n ...q,\n status,\n openedAt: Date.now(),\n ...(effectiveDecision ? { decision: effectiveDecision } : {}),\n }\n questions.push(record)\n return { question: record, added: true }\n }\n const emitNewQuestion = async (record: {\n question: QuestionRecord\n added: boolean\n }): Promise<QuestionRecord> => {\n if (record.added) await opts.onEvent?.({ type: 'question', question: record.question })\n return record.question\n }\n const decideQuestion = (questionId: string, decision: QuestionDecision): QuestionRecord => {\n const idx = questions.findIndex((q) => q.id === questionId)\n if (idx < 0) throw new Error(`unknown questionId ${JSON.stringify(questionId)}`)\n const prior = questions[idx] as QuestionRecord\n const status: QuestionRecord['status'] =\n decision.kind === 'answer' ? 'answered' : decision.kind === 'defer' ? 'deferred' : 'escalated'\n const next: QuestionRecord = { ...prior, status, decision }\n questions[idx] = next\n return next\n }\n const blockingQuestionsForStop = (): QuestionRecord[] => {\n if (questionPolicy === 'auto' || questionPolicy === 'bubble') return []\n return questions.filter((q) => {\n const blocking = q.urgency === 'blocks-step' || q.urgency === 'blocks-run'\n if (!blocking) return false\n if (questionPolicy === 'mustDecide') return q.status === 'open'\n return q.status !== 'answered' && q.status !== 'deferred'\n })\n }\n\n const tools: McpToolDescriptor[] = [\n {\n name: 'spawn_worker',\n description:\n 'Start a worker the driver will drive. `profile` is the worker or another driver; ' +\n '`task` is what it should do. Reserves budget from the conserved pool and fails closed.',\n inputSchema: {\n type: 'object',\n properties: {\n profile: { description: 'The worker/driver profile to run.' },\n task: { description: 'The task the worker should perform.' },\n label: { type: 'string', description: 'Optional trace label.' },\n },\n required: ['profile', 'task'],\n },\n handler: (raw) => {\n const a = obj(raw)\n const agent = opts.makeWorkerAgent(a.profile)\n const res = opts.scope.spawn(agent, a.task, {\n budget: opts.perWorker,\n label: typeof a.label === 'string' ? a.label : 'worker',\n })\n return Promise.resolve(res.ok ? { workerId: res.handle.id } : { error: res.reason })\n },\n },\n {\n name: 'observe_worker',\n description: 'Inspect a worker status, spend, and settled output artifact when available.',\n inputSchema: { type: 'object', properties: { workerId: idArg }, required: ['workerId'] },\n handler: async (raw) => {\n const id = str(obj(raw).workerId, 'workerId')\n const node = opts.scope.view.nodes.find((n) => n.id === id)\n if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` }\n const output = node.outRef ? await opts.blobs.get(node.outRef) : undefined\n return {\n status: node.status,\n spent: node.spent,\n outRef: node.outRef ?? null,\n output: output ?? null,\n }\n },\n },\n {\n name: 'steer_worker',\n description: 'Deliver an out-of-band instruction to a running worker inbox.',\n inputSchema: {\n type: 'object',\n properties: {\n workerId: idArg,\n instruction: { type: 'string', description: 'What the worker should do next.' },\n },\n required: ['workerId', 'instruction'],\n },\n handler: (raw) => {\n const a = obj(raw)\n const delivered = opts.scope.send(str(a.workerId, 'workerId'), {\n steer: str(a.instruction, 'instruction'),\n })\n return Promise.resolve({ delivered })\n },\n },\n {\n name: 'await_next',\n description:\n 'Wait for the next spawned worker to settle. Returns { idle: true } when none are live.',\n inputSchema: { type: 'object', properties: {} },\n handler: async () => {\n const s = await opts.scope.next()\n if (!s) return { idle: true }\n const w = recordSettled(s)\n return w.status === 'done'\n ? {\n settled: w.id,\n status: 'done',\n score: w.score,\n valid: w.valid,\n outRef: w.outRef,\n }\n : { settled: w.id, status: 'down', reason: w.reason }\n },\n },\n {\n name: 'list_questions',\n description:\n 'List questions raised by workers, drivers, or analysts. Blocking stop behavior follows questionPolicy.',\n inputSchema: { type: 'object', properties: {} },\n handler: () => Promise.resolve({ questions }),\n },\n {\n name: 'answer_question',\n description: 'Record an answer, deferral, or escalation for a loop question.',\n inputSchema: {\n type: 'object',\n properties: {\n questionId: { type: 'string' },\n answer: { type: 'string' },\n by: { type: 'string', description: 'Node id or \"user\".' },\n deferReason: { type: 'string' },\n escalateTo: { type: 'string', enum: ['parent', 'user'] },\n escalateReason: { type: 'string' },\n },\n required: ['questionId'],\n },\n handler: (raw) => {\n const a = obj(raw)\n const questionId = str(a.questionId, 'questionId')\n if (typeof a.answer === 'string' && a.answer.length > 0) {\n return Promise.resolve({\n question: decideQuestion(questionId, {\n kind: 'answer',\n answer: a.answer,\n by: typeof a.by === 'string' && a.by.length > 0 ? a.by : 'user',\n }),\n })\n }\n if (typeof a.deferReason === 'string' && a.deferReason.length > 0) {\n return Promise.resolve({\n question: decideQuestion(questionId, {\n kind: 'defer',\n reason: a.deferReason,\n }),\n })\n }\n if (a.escalateTo === 'parent' || a.escalateTo === 'user') {\n const escalateReason =\n typeof a.escalateReason === 'string' && a.escalateReason.length > 0\n ? a.escalateReason\n : 'driver escalated'\n return Promise.resolve({\n question: decideQuestion(questionId, {\n kind: 'escalate',\n to: a.escalateTo,\n reason: escalateReason,\n }),\n })\n }\n throw new Error('answer_question: provide answer, deferReason, or escalateTo')\n },\n },\n {\n name: 'ask_parent',\n description: 'Raise a question to the parent driver/Pi/user when this driver cannot decide.',\n inputSchema: {\n type: 'object',\n properties: {\n from: { type: 'string' },\n level: { type: 'string', enum: ['worker', 'driver', 'loop'] },\n question: { type: 'string' },\n reason: { type: 'string' },\n urgency: { type: 'string', enum: ['continue-without', 'blocks-step', 'blocks-run'] },\n },\n required: ['from', 'level', 'question', 'reason', 'urgency'],\n },\n handler: async (raw) => {\n const a = obj(raw)\n const from = str(a.from, 'from')\n const q = await emitNewQuestion(\n addQuestion(\n {\n from,\n level: level(a.level),\n question: str(a.question, 'question'),\n reason: str(a.reason, 'reason'),\n urgency: urgency(a.urgency),\n },\n from,\n { kind: 'escalate', to: 'parent', reason: 'asked parent' },\n ),\n )\n return { question: q }\n },\n },\n {\n name: 'stop',\n description: 'Declare the run complete.',\n inputSchema: {\n type: 'object',\n properties: { reason: { type: 'string', description: 'Why you are stopping.' } },\n },\n handler: (raw) => {\n const blocking = blockingQuestionsForStop()\n if (blocking.length) {\n return Promise.resolve({\n stopped: false,\n error: 'unresolved-blocking-questions',\n questions: blocking,\n })\n }\n stopped = true\n const r = obj(raw).reason\n reason = typeof r === 'string' ? r : undefined\n return Promise.resolve({ stopped: true })\n },\n },\n ]\n\n if (opts.analysts) {\n tools.push({\n name: 'list_analysts',\n description: 'List trace-analyst lenses available to run over a settled worker.',\n inputSchema: { type: 'object', properties: {} },\n handler: () => Promise.resolve({ analysts: opts.analysts?.kinds }),\n })\n tools.push({\n name: 'run_analyst',\n description: 'Apply an analyst lens to a settled worker trace.',\n inputSchema: {\n type: 'object',\n properties: {\n kind: { type: 'string', description: 'The analyst kind id.' },\n workerId: idArg,\n },\n required: ['kind', 'workerId'],\n },\n handler: async (raw) => {\n const a = obj(raw)\n const id = str(a.workerId, 'workerId')\n const node = opts.scope.view.nodes.find((n) => n.id === id)\n if (!node) return { error: `unknown workerId ${JSON.stringify(id)}` }\n if (!node.outRef)\n return { error: `worker ${JSON.stringify(id)} has not settled — no trace to analyze yet` }\n const trace = await opts.blobs.get(node.outRef)\n return { findings: await opts.analysts?.run(str(a.kind, 'kind'), trace) }\n },\n })\n }\n\n return {\n tools,\n isStopped: () => stopped,\n stopReason: () => reason,\n settled: () => ledger,\n questions: () => questions,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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Z;AAAA,QACA,UAAU,CAAC,QAAQ,UAAU;AAAA,MAC/B;AAAA,MACA,SAAS,OAAO,QAAQ;AACtB,cAAM,IAAI,IAAI,GAAG;AACjB,cAAM,KAAK,IAAI,EAAE,UAAU,UAAU;AACrC,cAAM,OAAO,KAAK,MAAM,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE;AAC1D,YAAI,CAAC,KAAM,QAAO,EAAE,OAAO,oBAAoB,KAAK,UAAU,EAAE,CAAC,GAAG;AACpE,YAAI,CAAC,KAAK;AACR,iBAAO,EAAE,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC,kDAA6C;AAC3F,cAAM,QAAQ,MAAM,KAAK,MAAM,IAAI,KAAK,MAAM;AAC9C,eAAO,EAAE,UAAU,MAAM,KAAK,UAAU,IAAI,IAAI,EAAE,MAAM,MAAM,GAAG,KAAK,EAAE;AAAA,MAC1E;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,IACA,WAAW,MAAM;AAAA,IACjB,YAAY,MAAM;AAAA,IAClB,SAAS,MAAM;AAAA,IACf,WAAW,MAAM;AAAA,EACnB;AACF;","names":[]}
@@ -1,4 +1,4 @@
1
- import { d as OpenAIChatTool } from './types-DnYoHvvZ.js';
1
+ import { d as OpenAIChatTool } from './types-nBMuollC.js';
2
2
 
3
3
  /**
4
4
  * @experimental
@@ -1,5 +1,5 @@
1
- export { C as CoderOutput, b as CoderProfileOptions, a as CoderTask, M as MultiHarnessCoderFanoutOptions, c as coderProfile, d as createCoderValidator, m as multiHarnessCoderFanout } from './coder-DCWFQpmJ.js';
2
- import { S as SandboxClient, O as OutputAdapter, V as Validator, A as AgentRunSpec } from './types-DnYoHvvZ.js';
1
+ export { C as CoderOutput, b as CoderProfileOptions, a as CoderTask, M as MultiHarnessCoderFanoutOptions, c as coderProfile, d as createCoderValidator, m as multiHarnessCoderFanout } from './coder-CVZNGbyg.js';
2
+ import { S as SandboxClient, O as OutputAdapter, V as Validator, A as AgentRunSpec } from './types-nBMuollC.js';
3
3
  import { a as UiLens, U as UiFinding } from './substrate-CUgk7F7s.js';
4
4
  export { b as UI_FINDING_SEVERITIES, c as UI_LENSES, d as UiFindingScreenshot, e as UiFindingSeverity } from './substrate-CUgk7F7s.js';
5
5
  import { SandboxEvent, AgentProfile } from '@tangle-network/sandbox';
@@ -1,5 +1,5 @@
1
1
  import { SandboxInstance } from '@tangle-network/sandbox';
2
- import { D as Driver, A as AgentRunSpec, O as OutputAdapter, V as Validator, E as ExecCtx, I as Iteration, L as LoopWinner, a as LoopLineageOptions, S as SandboxClient, b as LoopResult } from './types-DnYoHvvZ.js';
2
+ import { D as Driver, A as AgentRunSpec, O as OutputAdapter, V as Validator, E as ExecCtx, I as Iteration, L as LoopWinner, a as LoopLineageOptions, S as SandboxClient, b as LoopResult } from './types-nBMuollC.js';
3
3
 
4
4
  /**
5
5
  * @experimental