@tangle-network/agent-runtime 0.327.0 → 0.329.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 (54) hide show
  1. package/dist/{activation-DfhOPF9_.js → activation-BfHpXIo0.js} +2 -2
  2. package/dist/{activation-DfhOPF9_.js.map → activation-BfHpXIo0.js.map} +1 -1
  3. package/dist/{activation-D4kme3Oh.d.ts → activation-CQo8-ir9.d.ts} +2 -2
  4. package/dist/agent.d.ts +1 -1
  5. package/dist/agent.js +2 -2
  6. package/dist/{coordination-driver-Cd0KpYoT.js → coordination-driver-DsxFmzhm.js} +369 -25
  7. package/dist/coordination-driver-DsxFmzhm.js.map +1 -0
  8. package/dist/{delegate-C6qiH8ti.js → delegate-C-E2pUey.js} +2 -2
  9. package/dist/{delegate-C6qiH8ti.js.map → delegate-C-E2pUey.js.map} +1 -1
  10. package/dist/durable.d.ts +1 -1
  11. package/dist/durable.js +3 -3
  12. package/dist/{graph-7DxUifPo.js → graph-BamfOWzd.js} +13 -6
  13. package/dist/graph-BamfOWzd.js.map +1 -0
  14. package/dist/{improvement-cycle-sd7Y_buy.js → improvement-cycle-BWcUsIgg.js} +3 -3
  15. package/dist/{improvement-cycle-sd7Y_buy.js.map → improvement-cycle-BWcUsIgg.js.map} +1 -1
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +7 -7
  18. package/dist/intelligence.d.ts +2 -2
  19. package/dist/intelligence.js +3 -3
  20. package/dist/kernel.d.ts +2 -2
  21. package/dist/kernel.js +8 -8
  22. package/dist/{loop-runner-bin-DLiEuQAt.js → loop-runner-bin-CVZ5S19W.js} +3 -3
  23. package/dist/{loop-runner-bin-DLiEuQAt.js.map → loop-runner-bin-CVZ5S19W.js.map} +1 -1
  24. package/dist/{loop-runner-bin-DKkrGTge.d.ts → loop-runner-bin-U00bzVay.d.ts} +2 -2
  25. package/dist/loop-runner-bin.d.ts +1 -1
  26. package/dist/loop-runner-bin.js +1 -1
  27. package/dist/mcp/bin.js +3 -3
  28. package/dist/mcp/index.d.ts +2 -2
  29. package/dist/mcp/index.js +4 -4
  30. package/dist/{openai-tools-BTq7nLhg.d.ts → openai-tools-DnA8exP6.d.ts} +2 -2
  31. package/dist/profiles.d.ts +1 -1
  32. package/dist/{provision-supervisor-BCpumw87.js → provision-supervisor-mpEy_KWu.js} +3 -3
  33. package/dist/{provision-supervisor-BCpumw87.js.map → provision-supervisor-mpEy_KWu.js.map} +1 -1
  34. package/dist/{runtime-CfBB9gRz.js → runtime-VteVmwAw.js} +8 -8
  35. package/dist/{runtime-CfBB9gRz.js.map → runtime-VteVmwAw.js.map} +1 -1
  36. package/dist/{search-executor-BgMpZuhl.js → search-executor-eTeXrpkP.js} +2 -2
  37. package/dist/{search-executor-BgMpZuhl.js.map → search-executor-eTeXrpkP.js.map} +1 -1
  38. package/dist/{server-vyi-BhWC.js → server-BGQv06nN.js} +3 -3
  39. package/dist/{server-vyi-BhWC.js.map → server-BGQv06nN.js.map} +1 -1
  40. package/dist/{supervise-Bso1hco7.js → supervise-BIIbQhg7.js} +232 -32
  41. package/dist/supervise-BIIbQhg7.js.map +1 -0
  42. package/dist/{supervisor-hIpqcCJr.js → supervisor-U76PdEPD.js} +31 -6
  43. package/dist/supervisor-U76PdEPD.js.map +1 -0
  44. package/dist/testing.d.ts +1 -1
  45. package/dist/testing.js +12 -12
  46. package/dist/tui/index.d.ts +1 -1
  47. package/dist/tui/index.js +1 -1
  48. package/dist/{types-loG2Pvmj.d.ts → types-B6IAL5Q7.d.ts} +201 -8
  49. package/package.json +1 -1
  50. package/skills/agent-graphs/references/authoring.md +12 -1
  51. package/dist/coordination-driver-Cd0KpYoT.js.map +0 -1
  52. package/dist/graph-7DxUifPo.js.map +0 -1
  53. package/dist/supervise-Bso1hco7.js.map +0 -1
  54. package/dist/supervisor-hIpqcCJr.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { $i as InMemoryResultBlobStore, Bt as createRouterTranscript, Ct as checkVerdictOf, Dt as failedItems, En as runBrainLoop, Ft as createExecutorRegistry, J as scopeRetainedOwnerResourceReader, Qi as FileSpawnJournal, T as meterRuntimeOwnedProviderAttempt, Ta as resolveRedactor, Zi as FileResultBlobStore, Zt as createInbox, _a as assertValidBudget, at as runtimeGraphMetadataKey, c as runTree, ca as parseWorkerToolTraceArtifact, da as detachedFrozen, ea as InMemorySpawnJournal, i as bestDelivered, ji as settlementFailureCause, la as workerTraceAnalysisStore, ma as errMessage, mi as providerAttemptEvidence, nn as createPeerMailbox, o as pickBestDelivered, on as isLiveNodeStatus, s as runFinalizer, sn as isTerminalNodeStatus, tt as resolveSpawnResourcePaths, ua as contentAddress, v as withDriverExecutor, w as meterRuntimeOwnedAccounting, yt as CheckUnavailableError } from "./supervisor-hIpqcCJr.js";
1
+ import { $i as FileSpawnJournal, Dn as runBrainLoop, Ea as resolveRedactor, It as createExecutorRegistry, Mi as settlementFailureCause, Ot as failedItems, Qi as FileResultBlobStore, Qt as createInbox, T as meterRuntimeOwnedProviderAttempt, Vt as createRouterTranscript, Y as scopeRetainedOwnerResourceReader, bt as CheckUnavailableError, c as runTree, cn as isTerminalNodeStatus, da as contentAddress, ea as InMemoryResultBlobStore, fa as detachedFrozen, ha as errMessage, hi as providerAttemptEvidence, i as bestDelivered, la as parseWorkerToolTraceArtifact, nt as resolveSpawnResourcePaths, o as pickBestDelivered, ot as runtimeGraphMetadataKey, rn as createPeerMailbox, s as runFinalizer, sn as isLiveNodeStatus, ta as InMemorySpawnJournal, ua as workerTraceAnalysisStore, v as withDriverExecutor, va as assertValidBudget, w as meterRuntimeOwnedAccounting, wt as checkVerdictOf } from "./supervisor-U76PdEPD.js";
2
2
  import { f as RuntimeRunStateError, m as ValidationError } from "./errors-DodWX-cb.js";
3
3
  import { G as chargedTokens, gt as withBudgetResources, lt as unmeteredSpend, pt as addResourceSpend, tt as promptCacheTokenClasses } from "./sandbox-profile-compat-CVgQWb7T.js";
4
4
  import { a as readCommittedJsonLines, t as appendCommittedJsonLine } from "./jsonl-file-DBv31uPi.js";
@@ -253,6 +253,16 @@ function createWorkerOutputReader(blobs) {
253
253
  *
254
254
  * @experimental
255
255
  */
256
+ /**
257
+ * The substitution and the sentence a manager reads beside it. A manager that reports which model
258
+ * did the work must read `modelSubstitution.ran`, never the model it asked for.
259
+ */
260
+ function modelSubstitutionReport(substitution) {
261
+ return {
262
+ modelSubstitution: substitution,
263
+ modelWarning: `spawn authorization ran this worker on ${substitution.ran}, not the ${substitution.requested} you authored; attribute its work to ${substitution.ran}`
264
+ };
265
+ }
256
266
  /** Where a question this driver cannot answer goes next. `answer_question` accepts these and
257
267
  * nothing else, so the decision type states them and nothing else. */
258
268
  const questionEscalationTargets = ["parent", "user"];
@@ -521,7 +531,8 @@ const journalEventKinds = [
521
531
  "analyst-assignment",
522
532
  "acknowledgement",
523
533
  "tool-outcome",
524
- "lead-message"
534
+ "lead-message",
535
+ "map"
525
536
  ];
526
537
  /** The reserved coordination verb names — the complete set `createCoordinationTools` can emit
527
538
  * (the analyst pair is conditional but still reserved). A driver's extra WORK tools must not
@@ -564,7 +575,8 @@ const wakeEventKinds = [
564
575
  "settled",
565
576
  "finding",
566
577
  "tool-outcome",
567
- "lead-message"
578
+ "lead-message",
579
+ "map"
568
580
  ];
569
581
  const idArg = {
570
582
  type: "string",
@@ -884,6 +896,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
884
896
  const node = nodeForWorker(settled.handle.id);
885
897
  const assignmentId = settled.handle.assignmentId ?? node?.assignmentId;
886
898
  const identity = settled.handle.identity ?? node?.identity;
899
+ const modelSubstitution = settled.handle.modelSubstitution ?? node?.modelSubstitution;
887
900
  const materialization = settled.handle.materialization ?? node?.materialization;
888
901
  const executionBindings = settled.handle.executionBindings ?? node?.executionBindings;
889
902
  const settledAt = settled.settledAt ?? node?.settledAt;
@@ -895,6 +908,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
895
908
  id: settled.handle.id,
896
909
  ...assignmentId === void 0 ? {} : { assignmentId },
897
910
  ...identity === void 0 ? {} : { identity },
911
+ ...modelSubstitution === void 0 ? {} : modelSubstitutionReport(modelSubstitution),
898
912
  ...materialization === void 0 ? {} : { materialization },
899
913
  ...executionBindings === void 0 ? {} : { executionBindings },
900
914
  ...settledAt === void 0 ? {} : { settledAt },
@@ -1023,7 +1037,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
1023
1037
  checkReads.push(entry);
1024
1038
  return entry;
1025
1039
  };
1026
- const eventWorker = (event) => event.type === "settled" ? event.worker.id : event.type === "finding" ? event.finding.fromWorker : event.type === "question" ? event.question.from : void 0;
1040
+ const eventWorker = (event) => event.type === "settled" ? event.worker.id : event.type === "finding" ? event.finding.fromWorker : event.type === "question" ? event.question.from : event.type === "map" ? event.map.sourceWorker : void 0;
1027
1041
  const acknowledge = async (targets, by) => {
1028
1042
  const fresh = targets.filter((delivery) => !delivery.acknowledged);
1029
1043
  if (fresh.length === 0) return [];
@@ -1343,6 +1357,271 @@ function createCoordinationToolsForManager(opts, lifetime) {
1343
1357
  analyst: kind,
1344
1358
  sourceWorker
1345
1359
  }, { alreadySpent: true }) });
1360
+ const mapRoutes = opts.mapOnSettle ?? [];
1361
+ const mapMembers = /* @__PURE__ */ new Map();
1362
+ const textBytes = (value) => Buffer.byteLength(safeJsonText(value), "utf8");
1363
+ const publishMap = async (event, wake = false) => {
1364
+ const record = detachedFrozen({
1365
+ type: "map",
1366
+ map: event
1367
+ });
1368
+ if (wake) await bus.publish(record);
1369
+ else await bus.publish(record, { queue: false });
1370
+ };
1371
+ const workerSlotBound = () => {
1372
+ const capacity = opts.scope.workerCapacity;
1373
+ if (capacity === void 0 || capacity.freeSlots === null) return void 0;
1374
+ return capacity.working + capacity.freeSlots;
1375
+ };
1376
+ const mapSettlement = (settled, worker) => {
1377
+ if (settled.kind !== "done" || worker.status !== "done") return {
1378
+ outcome: "failed",
1379
+ reason: worker.status === "down" ? worker.reason : "down"
1380
+ };
1381
+ if (worker.valid === false) return {
1382
+ outcome: "failed",
1383
+ reason: "its deliverable check rejected the result"
1384
+ };
1385
+ if (settled.out === void 0) return {
1386
+ outcome: "empty",
1387
+ reason: "it settled with no result"
1388
+ };
1389
+ return {
1390
+ outcome: "delivered",
1391
+ result: settled.out
1392
+ };
1393
+ };
1394
+ const startMapSpawn = async (expansion, role, profile, task, index) => {
1395
+ const { route } = expansion;
1396
+ const name = typeof profile.name === "string" && profile.name.length > 0 ? profile.name : "worker";
1397
+ let response;
1398
+ try {
1399
+ response = await admitSpawn({
1400
+ profile,
1401
+ args: {
1402
+ label: index === void 0 ? name : `${name}#${index}`,
1403
+ ...role === "item" && route.itemBudget !== void 0 ? { budget: route.itemBudget } : {}
1404
+ },
1405
+ task,
1406
+ key: void 0,
1407
+ continuity: { continuity: "fresh" },
1408
+ successorOf: void 0,
1409
+ preflightProfile: () => opts.resolveSpawnProfile ? detachedFrozen(opts.resolveSpawnProfile(profile)) : profile,
1410
+ resourcesFromPath: [],
1411
+ defaultLabel: name,
1412
+ map: Object.freeze({
1413
+ edge: route.edge,
1414
+ role,
1415
+ ...index === void 0 ? {} : { index }
1416
+ })
1417
+ });
1418
+ } catch (error) {
1419
+ return { refused: errMessage(error) };
1420
+ }
1421
+ const started = response;
1422
+ if (typeof started.workerId === "string") {
1423
+ mapMembers.set(started.workerId, {
1424
+ expansion,
1425
+ role,
1426
+ ...index === void 0 ? {} : { index },
1427
+ bytes: textBytes(task)
1428
+ });
1429
+ return { workerId: started.workerId };
1430
+ }
1431
+ return { refused: typeof started.reason === "string" ? started.reason : "spawn refused" };
1432
+ };
1433
+ const mapItemProfile = async (route) => {
1434
+ if ("profile" in route.item) return { profile: route.item.profile };
1435
+ if (!opts.graphs) return { refused: "a graph item starts through run_graph, which this manager does not serve" };
1436
+ const prepared = await opts.graphs.prepare({ graph: route.item.graph });
1437
+ return prepared.ok ? { profile: detachedFrozen(prepared.profile) } : { refused: prepared.reason };
1438
+ };
1439
+ const startMapItem = async (expansion, index) => {
1440
+ const { route } = expansion;
1441
+ const resolved = await mapItemProfile(route);
1442
+ const started = "refused" in resolved ? resolved : await startMapSpawn(expansion, "item", resolved.profile, expansion.items[index], index);
1443
+ if ("workerId" in started) {
1444
+ expansion.inFlight += 1;
1445
+ return;
1446
+ }
1447
+ const reason = `item spawn refused: ${started.refused}`;
1448
+ expansion.settlements[index] = {
1449
+ outcome: "unpropagated",
1450
+ reason
1451
+ };
1452
+ if (route.onItemFailure === "all-or-refuse") expansion.stopped = true;
1453
+ await publishMap({
1454
+ edge: route.edge,
1455
+ phase: "item",
1456
+ outcome: "unpropagated",
1457
+ sourceWorker: expansion.sourceWorker,
1458
+ index,
1459
+ bytes: 0,
1460
+ reason
1461
+ });
1462
+ };
1463
+ const pumpMap = async (expansion) => {
1464
+ const { route, items } = expansion;
1465
+ while (!expansion.stopped && expansion.inFlight < route.concurrency && expansion.next < items.length) {
1466
+ const index = expansion.next;
1467
+ expansion.next += 1;
1468
+ await startMapItem(expansion, index);
1469
+ }
1470
+ if (expansion.inFlight === 0) await finishMap(expansion);
1471
+ };
1472
+ const finishMap = async (expansion, closed) => {
1473
+ if (expansion.finished) return;
1474
+ expansion.finished = true;
1475
+ const { route, items, sourceWorker } = expansion;
1476
+ for (let index = expansion.next; index < items.length; index += 1) {
1477
+ const reason = closed ?? "not started: all-or-refuse stopped this map after an item failed";
1478
+ expansion.settlements[index] = {
1479
+ outcome: "unpropagated",
1480
+ reason
1481
+ };
1482
+ await publishMap({
1483
+ edge: route.edge,
1484
+ phase: "item",
1485
+ outcome: "unpropagated",
1486
+ sourceWorker,
1487
+ index,
1488
+ bytes: 0,
1489
+ reason
1490
+ });
1491
+ }
1492
+ expansion.next = items.length;
1493
+ const results = [];
1494
+ const failures = [];
1495
+ items.forEach((item, index) => {
1496
+ const settlement = expansion.settlements[index];
1497
+ if (settlement?.outcome === "delivered") results.push({
1498
+ index,
1499
+ item,
1500
+ result: settlement.result
1501
+ });
1502
+ else failures.push({
1503
+ index,
1504
+ item,
1505
+ outcome: settlement?.outcome ?? "unpropagated",
1506
+ reason: settlement?.reason ?? "never settled"
1507
+ });
1508
+ });
1509
+ const refusal = closed ?? (route.onItemFailure === "all-or-refuse" && failures.length > 0 ? `all-or-refuse: ${failures.length} of ${items.length} items did not deliver (${failures.map((failure) => `#${failure.index} ${failure.outcome}: ${failure.reason}`).join("; ")}); the join did not run` : void 0);
1510
+ if (refusal !== void 0) {
1511
+ await publishMap({
1512
+ edge: route.edge,
1513
+ phase: "join",
1514
+ outcome: "unpropagated",
1515
+ sourceWorker,
1516
+ bytes: 0,
1517
+ reason: refusal
1518
+ }, closed === void 0);
1519
+ return;
1520
+ }
1521
+ const task = {
1522
+ map: route.edge,
1523
+ source: sourceWorker,
1524
+ items: items.length,
1525
+ results,
1526
+ failures
1527
+ };
1528
+ const started = await startMapSpawn(expansion, "join", route.join, task, void 0);
1529
+ if ("refused" in started) await publishMap({
1530
+ edge: route.edge,
1531
+ phase: "join",
1532
+ outcome: "unpropagated",
1533
+ sourceWorker,
1534
+ bytes: 0,
1535
+ reason: `join spawn refused: ${started.refused}`
1536
+ }, true);
1537
+ };
1538
+ const settleMapMember = async (settled, worker, advance) => {
1539
+ const member = mapMembers.get(worker.id);
1540
+ if (member === void 0) return;
1541
+ mapMembers.delete(worker.id);
1542
+ const { expansion, role, index, bytes } = member;
1543
+ const settlement = mapSettlement(settled, worker);
1544
+ await publishMap({
1545
+ edge: expansion.route.edge,
1546
+ phase: role,
1547
+ outcome: settlement.outcome,
1548
+ sourceWorker: expansion.sourceWorker,
1549
+ ...index === void 0 ? {} : { index },
1550
+ workerId: worker.id,
1551
+ bytes,
1552
+ ...settlement.reason === void 0 ? {} : { reason: settlement.reason }
1553
+ });
1554
+ if (role === "join" || index === void 0) return;
1555
+ expansion.inFlight -= 1;
1556
+ expansion.settlements[index] = settlement;
1557
+ if (settlement.outcome !== "delivered" && expansion.route.onItemFailure === "all-or-refuse") expansion.stopped = true;
1558
+ if (advance) await pumpMap(expansion);
1559
+ else if (expansion.inFlight === 0) await finishMap(expansion, "not started: the manager stopped before this map finished");
1560
+ };
1561
+ const expandMaps = async (settled, worker) => {
1562
+ if (settled.kind !== "done" || mapRoutes.length === 0) return;
1563
+ const name = profileNameByWorker.get(worker.id);
1564
+ for (const route of mapRoutes) {
1565
+ if (route.from !== name) continue;
1566
+ const refuse = (reason) => publishMap({
1567
+ edge: route.edge,
1568
+ phase: "expand",
1569
+ outcome: "unpropagated",
1570
+ sourceWorker: worker.id,
1571
+ bytes: 0,
1572
+ reason
1573
+ }, true);
1574
+ const selected = resolveJsonPointer(settled.out, route.pointer);
1575
+ if (!selected.found) {
1576
+ await refuse(`pointer ${JSON.stringify(route.pointer)} does not resolve in the source result: ${selected.reason}; no item ran`);
1577
+ continue;
1578
+ }
1579
+ const items = selected.value;
1580
+ if (!Array.isArray(items)) {
1581
+ await refuse(`pointer ${JSON.stringify(route.pointer)} resolves to ${items === null ? "null" : typeof items}, not an array; no item ran`);
1582
+ continue;
1583
+ }
1584
+ if (items.length > route.maxItems) {
1585
+ await refuse(`max-items-exceeded: the list holds ${items.length} items and this map admits at most ${route.maxItems}; no item ran`);
1586
+ continue;
1587
+ }
1588
+ const slots = workerSlotBound();
1589
+ if (slots !== void 0 && route.concurrency > slots) {
1590
+ await refuse(`concurrency-unsatisfiable: concurrency ${route.concurrency} exceeds this run's ${slots} worker slots, so the cap could never be honored; no item ran`);
1591
+ continue;
1592
+ }
1593
+ await publishMap({
1594
+ edge: route.edge,
1595
+ phase: "expand",
1596
+ outcome: items.length === 0 ? "empty" : "delivered",
1597
+ sourceWorker: worker.id,
1598
+ bytes: textBytes(items),
1599
+ items: items.length,
1600
+ ...items.length === 0 ? { reason: "the list is empty; the join runs with no results" } : {}
1601
+ });
1602
+ await pumpMap({
1603
+ route,
1604
+ sourceWorker: worker.id,
1605
+ items: detachedFrozen(items),
1606
+ settlements: [],
1607
+ next: 0,
1608
+ inFlight: 0,
1609
+ stopped: false,
1610
+ finished: false
1611
+ });
1612
+ }
1613
+ };
1614
+ const runMapStep = async (step, worker) => {
1615
+ try {
1616
+ await step();
1617
+ } catch (error) {
1618
+ console.error("Runtime map step failed", {
1619
+ managerId: opts.scope.view.root,
1620
+ worker: worker.id,
1621
+ error: errMessage(error)
1622
+ });
1623
+ }
1624
+ };
1346
1625
  let flushing = 0;
1347
1626
  const flushPendingSettlement = async () => {
1348
1627
  flushing += 1;
@@ -1355,7 +1634,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
1355
1634
  const flushPendingSettlementOnce = async () => {
1356
1635
  const pending = pendingSettlement;
1357
1636
  if (!pending) return false;
1358
- await bus.publish(pending.event);
1637
+ if (mapMembers.get(pending.worker.id)?.role === "item") await bus.publish(pending.event, { queue: false });
1638
+ else await bus.publish(pending.event);
1359
1639
  if (pending.analystRun) {
1360
1640
  analystRuns.delete(pending.worker.id);
1361
1641
  flushedAnalystRuns.add(pending.worker.id);
@@ -1370,6 +1650,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
1370
1650
  }
1371
1651
  commitSettled(pending.worker);
1372
1652
  pendingSettlement = void 0;
1653
+ const advance = pending.analyze && !finishingAnalysis;
1654
+ await runMapStep(() => settleMapMember(pending.settled, pending.worker, advance), pending.worker);
1373
1655
  if (pending.analyze && !finishingAnalysis && analysisRoutes.length) {
1374
1656
  const sourceNames = workerRouteNames(pending.worker.id);
1375
1657
  const applicable = analysisRoutes.filter((route) => route.at !== "manager-end" && (route.statuses ?? ["done"]).includes(pending.worker.status) && (route.over === void 0 || route.over.some((name) => sourceNames.has(name))));
@@ -1404,6 +1686,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
1404
1686
  }
1405
1687
  for (const route of agentRoutes) await spawnAnalystRun(route, pending.worker);
1406
1688
  }
1689
+ if (advance) await runMapStep(() => expandMaps(pending.settled, pending.worker), pending.worker);
1407
1690
  return true;
1408
1691
  };
1409
1692
  const drainSettlement = async (source = "next") => {
@@ -1638,6 +1921,10 @@ function createCoordinationToolsForManager(opts, lifetime) {
1638
1921
  type: "lead-message",
1639
1922
  ...ev.message
1640
1923
  };
1924
+ if (ev.type === "map") return {
1925
+ type: "map",
1926
+ ...ev.map
1927
+ };
1641
1928
  return {
1642
1929
  type: ev.type,
1643
1930
  ...ev.down
@@ -1927,6 +2214,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
1927
2214
  status: node.status,
1928
2215
  ...node.assignmentId === void 0 ? {} : { assignmentId: node.assignmentId },
1929
2216
  ...node.identity === void 0 ? {} : { identity: node.identity },
2217
+ ...node.modelSubstitution === void 0 ? {} : modelSubstitutionReport(node.modelSubstitution),
1930
2218
  ...node.materialization === void 0 ? {} : { materialization: node.materialization },
1931
2219
  ...node.executionBindings === void 0 ? {} : { executionBindings: node.executionBindings },
1932
2220
  spent: node.spent,
@@ -1945,7 +2233,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
1945
2233
  queued: bus.queued([
1946
2234
  "settled",
1947
2235
  "finding",
1948
- "lead-message"
2236
+ "lead-message",
2237
+ "map"
1949
2238
  ])
1950
2239
  };
1951
2240
  };
@@ -2099,14 +2388,19 @@ function createCoordinationToolsForManager(opts, lifetime) {
2099
2388
  const { running, unqueued, queued } = openWork();
2100
2389
  return running.length > 0 || unqueued.length > 0 || queued.length > 0 || bus.pending(wakeEventKinds) > 0 || openReceipts.size > 0 || leadPublishing > 0 || pendingSettlement !== void 0 || flushing > 0;
2101
2390
  };
2391
+ const liveWorkersProgressing = () => {
2392
+ const running = openWork().running;
2393
+ return running.length > 0 && running.every((node) => readProgress(node.id)?.stalled === false);
2394
+ };
2102
2395
  const awaitWake = async (input) => {
2103
2396
  const startedAt = Date.now();
2397
+ let quietHeartbeats = 0;
2104
2398
  await ready();
2105
2399
  await settledWithoutDrain();
2106
2400
  if (!hasOpenWork() || input.signal.aborted) return void 0;
2107
- const heartbeatAt = startedAt + Math.max(0, input.heartbeatMs);
2401
+ let heartbeatAt = startedAt + Math.max(0, input.heartbeatMs);
2108
2402
  const deadlineAt = input.deadlineAt ?? Number.POSITIVE_INFINITY;
2109
- const wakeAt = Math.min(heartbeatAt, deadlineAt);
2403
+ let wakeAt = Math.min(heartbeatAt, deadlineAt);
2110
2404
  let unsubscribe;
2111
2405
  let timer;
2112
2406
  let onAbort;
@@ -2117,9 +2411,14 @@ function createCoordinationToolsForManager(opts, lifetime) {
2117
2411
  if (wakeEventKinds.includes(record.event.type)) resolve();
2118
2412
  });
2119
2413
  });
2120
- const elapsed = new Promise((resolve) => {
2121
- timer = setTimeout(resolve, Math.max(0, wakeAt - Date.now()));
2122
- });
2414
+ let elapsed = Promise.resolve();
2415
+ const armTimer = () => {
2416
+ if (timer) clearTimeout(timer);
2417
+ elapsed = new Promise((resolve) => {
2418
+ timer = setTimeout(resolve, Math.max(0, wakeAt - Date.now()));
2419
+ });
2420
+ };
2421
+ armTimer();
2123
2422
  const aborted = new Promise((resolve) => {
2124
2423
  onAbort = () => resolve();
2125
2424
  input.signal.addEventListener("abort", onAbort, { once: true });
@@ -2128,18 +2427,28 @@ function createCoordinationToolsForManager(opts, lifetime) {
2128
2427
  outsideWake = true;
2129
2428
  });
2130
2429
  let cursorIdle = false;
2131
- while (bus.pending(wakeEventKinds) === 0 && !outsideWake && !input.signal.aborted && Date.now() < wakeAt) {
2132
- const drained = !cursorIdle && openWork().running.length > 0 ? ensureDrain() : new Promise(() => void 0);
2133
- if (await Promise.race([
2134
- drained.then((value) => value ? "drained" : "idle"),
2135
- queuedEvent.then(() => "queued"),
2136
- elapsed.then(() => "elapsed"),
2137
- aborted.then(() => "aborted"),
2138
- outside.then(() => "outside")
2139
- ]) === "idle") {
2140
- cursorIdle = true;
2141
- if (!hasOpenWork()) break;
2430
+ for (;;) {
2431
+ while (bus.pending(wakeEventKinds) === 0 && !outsideWake && !input.signal.aborted && Date.now() < wakeAt) {
2432
+ const drained = !cursorIdle && openWork().running.length > 0 ? ensureDrain() : new Promise(() => void 0);
2433
+ if (await Promise.race([
2434
+ drained.then((value) => value ? "drained" : "idle"),
2435
+ queuedEvent.then(() => "queued"),
2436
+ elapsed.then(() => "elapsed"),
2437
+ aborted.then(() => "aborted"),
2438
+ outside.then(() => "outside")
2439
+ ]) === "idle") {
2440
+ cursorIdle = true;
2441
+ if (!hasOpenWork()) break;
2442
+ }
2443
+ }
2444
+ if (input.quietWhileProgressing === true && input.heartbeatMs > 0 && bus.pending(wakeEventKinds) === 0 && !outsideWake && !input.signal.aborted && Date.now() >= heartbeatAt && Date.now() < deadlineAt && liveWorkersProgressing()) {
2445
+ quietHeartbeats += 1;
2446
+ heartbeatAt = Date.now() + input.heartbeatMs;
2447
+ wakeAt = Math.min(heartbeatAt, deadlineAt);
2448
+ armTimer();
2449
+ continue;
2142
2450
  }
2451
+ break;
2143
2452
  }
2144
2453
  if (input.signal.aborted) return void 0;
2145
2454
  if (flushing > 0 && inFlightDrain !== null) await inFlightDrain.catch(() => false);
@@ -2175,7 +2484,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
2175
2484
  events,
2176
2485
  live: liveSnapshot(),
2177
2486
  freeSlots: freeWorkerSlots(),
2178
- idleMs: Date.now() - startedAt
2487
+ idleMs: Date.now() - startedAt,
2488
+ ...quietHeartbeats === 0 ? {} : { quietHeartbeats }
2179
2489
  });
2180
2490
  };
2181
2491
  const admitSpawn = async (input) => {
@@ -2214,7 +2524,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
2214
2524
  continuity: continuity.continuity,
2215
2525
  ...continuity.continuity === "resume" ? { resume: continuity.resume } : {},
2216
2526
  ...successorOf !== void 0 ? { successorOf } : {},
2217
- ...peerMailUrl !== void 0 ? { peerMailUrl } : {}
2527
+ ...peerMailUrl !== void 0 ? { peerMailUrl } : {},
2528
+ ...input.map !== void 0 ? { map: input.map } : {}
2218
2529
  });
2219
2530
  const res = opts.scope.spawn(() => opts.makeWorkerAgent(profile, context), task, {
2220
2531
  budget,
@@ -2254,6 +2565,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
2254
2565
  workerId: res.handle.id,
2255
2566
  assignmentId: res.handle.assignmentId ?? assignmentId,
2256
2567
  ...res.handle.identity === void 0 ? {} : { identity: res.handle.identity },
2568
+ ...res.handle.modelSubstitution === void 0 ? {} : modelSubstitutionReport(res.handle.modelSubstitution),
2257
2569
  ...res.handle.materialization === void 0 ? {} : { materialization: res.handle.materialization },
2258
2570
  ...res.handle.executionBindings === void 0 ? {} : { executionBindings: res.handle.executionBindings },
2259
2571
  continuity: continuity.continuity,
@@ -3486,6 +3798,36 @@ function nextUnkeyedAssignmentOrdinal(scope) {
3486
3798
  if (!Number.isSafeInteger(next)) throw new Error("coordination: durable assignment ordinal space is exhausted");
3487
3799
  return next;
3488
3800
  }
3801
+ /** Resolve an RFC 6901 JSON pointer (`''` is the whole document). */
3802
+ function resolveJsonPointer(document, pointer) {
3803
+ if (pointer === "") return {
3804
+ found: true,
3805
+ value: document
3806
+ };
3807
+ if (!pointer.startsWith("/")) return {
3808
+ found: false,
3809
+ reason: "a JSON pointer is empty or starts with \"/\""
3810
+ };
3811
+ let value = document;
3812
+ for (const raw of pointer.slice(1).split("/")) {
3813
+ const token = raw.replaceAll("~1", "/").replaceAll("~0", "~");
3814
+ if (Array.isArray(value)) {
3815
+ if (!/^(0|[1-9]\d*)$/.test(token) || Number(token) >= value.length) return {
3816
+ found: false,
3817
+ reason: `no index ${JSON.stringify(token)} in an array of ${value.length}`
3818
+ };
3819
+ value = value[Number(token)];
3820
+ } else if (typeof value === "object" && value !== null && Object.hasOwn(value, token)) value = value[token];
3821
+ else return {
3822
+ found: false,
3823
+ reason: `no member ${JSON.stringify(token)}`
3824
+ };
3825
+ }
3826
+ return {
3827
+ found: true,
3828
+ value
3829
+ };
3830
+ }
3489
3831
  /** Stringify a findings payload for a routed delivery; never throws (a cyclic payload degrades to
3490
3832
  * its String form rather than killing the settle path). */
3491
3833
  function safeJsonText(value) {
@@ -4719,6 +5061,7 @@ function driverAgent(opts) {
4719
5061
  ...opts.deliverable ? { deliverable: opts.deliverable } : {},
4720
5062
  ...opts.analysts ? { analysts: opts.analysts } : {},
4721
5063
  ...opts.analyzeOnSettle ? { analyzeOnSettle: opts.analyzeOnSettle } : {},
5064
+ ...opts.mapOnSettle ? { mapOnSettle: opts.mapOnSettle } : {},
4722
5065
  ...opts.sourceEvidenceRefs ? { sourceEvidenceRefs: opts.sourceEvidenceRefs } : {},
4723
5066
  ...opts.peerAudit ? { peerAudit: opts.peerAudit } : {},
4724
5067
  ...opts.watchWorkers ? { watchWorkers: opts.watchWorkers } : {},
@@ -4967,6 +5310,7 @@ function driverAgent(opts) {
4967
5310
  wake = await coord.awaitWake({
4968
5311
  signal: scope.signal,
4969
5312
  heartbeatMs: wakePolicy.heartbeatMs,
5313
+ quietWhileProgressing: true,
4970
5314
  debounceMs: wakePolicy.debounceMs,
4971
5315
  ...warnAt === void 0 ? {} : { deadlineAt: warnAt },
4972
5316
  alsoWakeOn: inbox.pending() > 0 ? Promise.resolve() : inbox.nextDelivery()
@@ -5122,4 +5466,4 @@ function safeJson(v) {
5122
5466
  //#endregion
5123
5467
  export { ANALYST_DEFINITION_BOUNDS as A, createEventBus as B, createFileRunContext as C, foldCoordinationRecords as D, FileCoordinationLog as E, createCoordinationToolsForManager as F, watchTrace as H, downMessageRefusalReasons as I, normalizeAnalyzeOnSettle as L, canonicalFindingEvent as M, coordinationVerbNames as N, applyRunCancellation as O, createCoordinationTools as P, parseAuthoredAnalystDefinition as R, renderAnytimeTable as S, withRunContext as T, defaultToolDetectors as V, sampleFromSettled as _, DEFAULT_DEADLINE_WARNING_MS as a, bestSoFar as b, refreshedWake as c, allWorkersStalled as d, anyOf as f, progressStop as g, plateau as h, finalizeBestDelivered as i, analystToolGroupNames as j, watchRunCancellation as k, resolveWakePolicy as l, noProgressFor as m, createSteerAcknowledger as n, composeWakeInput as o, createProgressTracker as p, driverAgent as r, deadlineWarningAt as s, createCancelAcknowledger as t, allOf as u, anytimeReport as v, createInMemoryRunContext as w, plateauLength as x, areaUnderCurve as y, questionEscalationTargets as z };
5124
5468
 
5125
- //# sourceMappingURL=coordination-driver-Cd0KpYoT.js.map
5469
+ //# sourceMappingURL=coordination-driver-DsxFmzhm.js.map