@tangle-network/agent-runtime 0.217.1 → 0.218.1

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 (47) hide show
  1. package/dist/{activation-CmjhbLOU.js → activation-DI04_3R-.js} +2 -2
  2. package/dist/{activation-CmjhbLOU.js.map → activation-DI04_3R-.js.map} +1 -1
  3. package/dist/agent.d.ts +1 -1
  4. package/dist/agent.js +2 -2
  5. package/dist/{coordination-driver-TV8PUtix.js → coordination-driver-rlM6lqtZ.js} +2 -2
  6. package/dist/{coordination-driver-TV8PUtix.js.map → coordination-driver-rlM6lqtZ.js.map} +1 -1
  7. package/dist/{delegate-DY7LDk6i.js → delegate-CVlTAKGU.js} +2 -2
  8. package/dist/{delegate-DY7LDk6i.js.map → delegate-CVlTAKGU.js.map} +1 -1
  9. package/dist/durable.d.ts +1 -1
  10. package/dist/durable.js +2 -2
  11. package/dist/{graph-Dq8M69Wl.js → graph-i9EWCOK7.js} +3 -3
  12. package/dist/{graph-Dq8M69Wl.js.map → graph-i9EWCOK7.js.map} +1 -1
  13. package/dist/{improvement-cycle-CtzDO04H.js → improvement-cycle-DqfEWpFs.js} +3 -3
  14. package/dist/{improvement-cycle-CtzDO04H.js.map → improvement-cycle-DqfEWpFs.js.map} +1 -1
  15. package/dist/{index-XlvRo6ys.d.ts → index-DgDpB-HB.d.ts} +6 -3
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +7 -7
  18. package/dist/intelligence.js +3 -3
  19. package/dist/kernel.d.ts +1 -1
  20. package/dist/kernel.js +8 -8
  21. package/dist/{loop-runner-bin-C8fsTTl4.js → loop-runner-bin-BiZuxoZW.js} +3 -3
  22. package/dist/{loop-runner-bin-C8fsTTl4.js.map → loop-runner-bin-BiZuxoZW.js.map} +1 -1
  23. package/dist/{loop-runner-bin-C4hZxGiX.d.ts → loop-runner-bin-CDs3H8Ej.d.ts} +2 -2
  24. package/dist/loop-runner-bin.d.ts +1 -1
  25. package/dist/loop-runner-bin.js +1 -1
  26. package/dist/mcp/bin.js +3 -3
  27. package/dist/mcp/index.d.ts +1 -1
  28. package/dist/mcp/index.js +4 -4
  29. package/dist/{provision-supervisor-iQXK22cP.js → provision-supervisor-SvnQnnII.js} +3 -3
  30. package/dist/{provision-supervisor-iQXK22cP.js.map → provision-supervisor-SvnQnnII.js.map} +1 -1
  31. package/dist/{runtime-yar7Fays.js → runtime-DGdRJN30.js} +8 -8
  32. package/dist/{runtime-yar7Fays.js.map → runtime-DGdRJN30.js.map} +1 -1
  33. package/dist/{server-BU0NZQ9c.js → server-BNE25y3V.js} +3 -3
  34. package/dist/{server-BU0NZQ9c.js.map → server-BNE25y3V.js.map} +1 -1
  35. package/dist/{structural-rollout-CtZzP2lH.js → structural-rollout-Bb0d3o-X.js} +2 -2
  36. package/dist/{structural-rollout-CtZzP2lH.js.map → structural-rollout-Bb0d3o-X.js.map} +1 -1
  37. package/dist/{supervise-BvVk6npK.js → supervise-DV0dlkir.js} +124 -8
  38. package/dist/supervise-DV0dlkir.js.map +1 -0
  39. package/dist/{redact-BaQMqbqi.js → supervisor-DELeLQRJ.js} +125 -93
  40. package/dist/supervisor-DELeLQRJ.js.map +1 -0
  41. package/dist/testing.d.ts +1 -1
  42. package/dist/testing.js +12 -12
  43. package/dist/tui/index.d.ts +1 -1
  44. package/dist/tui/index.js +1 -1
  45. package/package.json +3 -3
  46. package/dist/redact-BaQMqbqi.js.map +0 -1
  47. package/dist/supervise-BvVk6npK.js.map +0 -1
@@ -1,11 +1,11 @@
1
- import { $ as captureReusableExecutorConfig, $r as inheritRuntimeOwnedExecutorAttestation, $t as bridgeRuntimeAttachmentsKey, A as consumeScopeRetainedOwnerResult, Ar as assertProfileMaterialization, Bn as registerRetainedExecutorPreparation, Br as renderUnsupported, Ct as contentAddress, Dt as WORKER_TRACE_PROPAGATION, Et as spendFromUsageEvents, Fn as resourceTelemetry, Fr as promptControlProfileMaterialization, Hn as RunCancellationReason, Hr as unsupportedProfileDimensions, In as withBudgetResources, Ir as promptModelProfileMaterialization, It as createInbox, Jt as bridgeModelRouteRefusal, M as scopeRetainedOwnerContext, Mn as unmeteredSpend, Mr as defineProfileMaterializationContract, N as scopeRetainedOwnerPriorSpend, Nn as zeroSpend, Nr as fullProfileMaterialization, P as scopeRetainedOwnerResult, Pn as addResourceSpend, Pr as profileMaterializationAxes$1, Q as bindReusableExecutorExecutionId, S as scopeOwnerExecutorNodeContext, Vn as retainedExecutorSeamKey, Wr as worktreeCliProfileMaterialization, X as DEFAULT_SUCCESSFUL_SHUTDOWN_MS, Xr as attestRuntimeOwnedScopeOwner, Z as teardownExecutor, _ as deriveNodeExecutionIdentity, a as createSupervisor, ai as runtimeOwnedDriveHarnessProviderEvidence, ar as createOtelExporter, b as recordScopeOwnerMaterialization, bn as addSpend, ci as runtimeOwnedExecutorProviderEvidence, cr as generateSpanId, d as driverChild, dn as routerBrain, en as bridgeStopSignalKey, f as driverExecutorFactory, fr as toOtelAttributes, gi as detachedSnapshot, h as beginScopeOwnerAttempt, i as createRootHandle, ii as recordRuntimeOwnedDriveHarnessProviderEvidence, it as snapshotExecutorConfig, j as prepareScopeRetainedOwnerTask, jr as controlProfileMaterialization, l as runFinalizer, li as runtimeOwnedPendingExecutorMaterialization, nt as createExecutor, o as bestDelivered, oi as runtimeOwnedExecutorExecutionBinding, p as isDriverSpec, qt as bridgeAdmissionRefusal, ri as providerAttemptEvidence, si as runtimeOwnedExecutorMaterialization, u as runTree, ui as runtimeOwnedScopeOwnerRuntime, v as meterRuntimeOwnedAccounting, vn as resolveAgentEnvironmentProvider, wt as assertValidBudget, x as restoreScopeOwnerAcceptedExecution, y as meterRuntimeOwnedProviderAttempt } from "./redact-BaQMqbqi.js";
1
+ import { $ as createExecutor, A as scopeRetainedOwnerPriorSpend, An as withTimeout, Bn as RunCancellationReason, Ct as spendFromUsageEvents, D as consumeScopeRetainedOwnerResult, Fr as profileMaterializationAxes$1, Gr as worktreeCliProfileMaterialization, Gt as bridgeModelRouteRefusal, Ir as promptControlProfileMaterialization, J as teardownExecutor, Lr as promptModelProfileMaterialization, Mn as addResourceSpend, Mr as controlProfileMaterialization, Nn as resourceTelemetry, Nr as defineProfileMaterializationContract, Nt as createInbox, O as prepareScopeRetainedOwnerTask, Pn as withBudgetResources, Pr as fullProfileMaterialization, Rn as registerRetainedExecutorPreparation, Ur as unsupportedProfileDimensions, Vr as renderUnsupported, Wt as bridgeAdmissionRefusal, X as captureReusableExecutorConfig, Xt as bridgeRuntimeAttachmentsKey, Y as bindReusableExecutorExecutionId, Zr as attestRuntimeOwnedScopeOwner, Zt as bridgeStopSignalKey, _ as recordScopeOwnerMaterialization, _i as detachedSnapshot, _n as addSpend, ai as recordRuntimeOwnedDriveHarnessProviderEvidence, bt as contentAddress, c as driverChild, ci as runtimeOwnedExecutorMaterialization, cn as routerBrain, di as runtimeOwnedScopeOwnerRuntime, ei as inheritRuntimeOwnedExecutorAttestation, f as beginScopeOwnerAttempt, g as meterRuntimeOwnedProviderAttempt, h as meterRuntimeOwnedAccounting, hn as resolveAgentEnvironmentProvider, ii as providerAttemptEvidence, j as scopeRetainedOwnerResult, jn as zeroSpend, jr as assertProfileMaterialization, k as scopeRetainedOwnerContext, kn as unmeteredSpend, l as driverExecutorFactory, li as runtimeOwnedExecutorProviderEvidence, lr as generateSpanId, m as deriveNodeExecutionIdentity, n as createSupervisor, o as runFinalizer, oi as runtimeOwnedDriveHarnessProviderEvidence, or as createOtelExporter, pr as toOtelAttributes, q as DEFAULT_SUCCESSFUL_SHUTDOWN_MS, r as bestDelivered, s as runTree, si as runtimeOwnedExecutorExecutionBinding, t as createRootHandle, tt as snapshotExecutorConfig, u as isDriverSpec, ui as runtimeOwnedPendingExecutorMaterialization, v as restoreScopeOwnerAcceptedExecution, wt as WORKER_TRACE_PROPAGATION, xt as assertValidBudget, y as scopeOwnerExecutorNodeContext, zn as retainedExecutorSeamKey } from "./supervisor-DELeLQRJ.js";
2
2
  import { f as RuntimeRunStateError, i as ConfigError, m as ValidationError, r as BackendTransportError, t as AgentEvalError } from "./errors-DodWX-cb.js";
3
3
  import { a as concreteProfileModel, c as profileModelExecutionSettings, d as agentHarness, f as harnessRunsAgent, n as assertModelAllowed, o as enforceTokenLimits, r as assertProfileModelsAllowed, s as profileBridgeWireModel, t as assertExecutableAgentProfile } from "./model-policy-DKDyr-fc.js";
4
4
  import { t as composeRuntimeHooks } from "./runtime-hooks-tXpAarhW.js";
5
5
  import { k as writeRunCancellation, o as readRunCancelRequest, s as readRunCancellation } from "./run-layout-hZREkcfu.js";
6
- import { C as createCoordinationTools, F as watchRunCancellation, M as createInMemoryRunContext, P as applyRunCancellation, S as coordinationVerbNames, c as createProgressTracker, d as progressStop, j as createFileRunContext, r as driverAgent } from "./coordination-driver-TV8PUtix.js";
6
+ import { C as createCoordinationTools, F as watchRunCancellation, M as createInMemoryRunContext, P as applyRunCancellation, S as coordinationVerbNames, c as createProgressTracker, d as progressStop, j as createFileRunContext, r as driverAgent, y as DEFAULT_AWAIT_EVENT_TIMEOUT_MS } from "./coordination-driver-rlM6lqtZ.js";
7
7
  import { t as createStdioToolServer } from "./tool-server-BJbCPhoW.js";
8
- import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, validateAgentProfileSecurity } from "@tangle-network/agent-interface";
8
+ import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalCandidateJson, validateAgentProfileSecurity } from "@tangle-network/agent-interface";
9
9
  import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
10
10
  import { resolve } from "node:path";
11
11
  import { isMaterializerHarness } from "@tangle-network/agent-profile-materialize";
@@ -577,7 +577,7 @@ function coordinationHttpHandler(input) {
577
577
  requests = 0;
578
578
  controlRequests = 0;
579
579
  }
580
- controlAdmission = active >= limits.maxConcurrentRequests || requests >= limits.requestsPerMinute;
580
+ controlAdmission = active + input.backgroundActions() >= limits.maxConcurrentRequests || requests >= limits.requestsPerMinute;
581
581
  if (controlAdmission) {
582
582
  if (controlActive >= 2 || controlRequests >= 60) {
583
583
  reject(429);
@@ -656,6 +656,106 @@ function coordinationHttpHandler(input) {
656
656
  };
657
657
  }
658
658
  //#endregion
659
+ //#region src/runtime/supervise/single-flight-tools.ts
660
+ /**
661
+ * Serve method-supplied supervisor tools on the coordination MCP as single-flight, fenced calls.
662
+ *
663
+ * A method tool can run for hours: a literature graph spawns and joins its own children inside one
664
+ * call. The coordination transport answers 504 at `requestTimeoutMs`, so an unwrapped long call
665
+ * reaches the caller as a hard tool error while its handler keeps running. A caller that retries
666
+ * starts a second full run. Run mech-interp-foundations-glm2-20260911d spawned the same enumerate
667
+ * and extract children twice this way.
668
+ *
669
+ * Two rules close that failure:
670
+ * - Identity. A call joins an existing invocation when its tool name and its RFC 8785 canonical
671
+ * arguments match, and that invocation has not yet returned its outcome to a caller. The handler
672
+ * is not invoked again. Key order does not matter: the observed retry reordered every key.
673
+ * - Fence. A call waits at most `fenceMs` for the outcome. If the handler is still running, the call
674
+ * returns a non-error pending result. A later identical call keeps waiting, then returns the value
675
+ * or throws the handler's error once the handler settles.
676
+ *
677
+ * An invocation's identity ends when a call returns its outcome. The next identical call is a fresh
678
+ * run, because equal arguments do not make a call a replay. Code mode's `execute` and Knowledge's
679
+ * `knowledge_search` read live state, so their callers repeat identical arguments to get a current
680
+ * answer. A handler that finishes within the fence therefore behaves exactly as it did unwrapped.
681
+ * No escape hatch is needed: the only calls this absorbs are ones whose caller could not have seen
682
+ * the outcome.
683
+ */
684
+ function singleFlightTools(tools, options) {
685
+ const { fenceMs } = options;
686
+ if (!Number.isSafeInteger(fenceMs) || fenceMs <= 0) throw new ValidationError("singleFlightTools: fenceMs must be a positive safe integer");
687
+ const now = options.now ?? Date.now;
688
+ const invocations = /* @__PURE__ */ new Map();
689
+ const start = (tool, raw) => {
690
+ const invocation = {
691
+ startedAt: now(),
692
+ settled: (async () => tool.handler(raw))().then((value) => {
693
+ invocation.outcome = {
694
+ ok: true,
695
+ value
696
+ };
697
+ return invocation.outcome;
698
+ }, (error) => {
699
+ invocation.outcome = {
700
+ ok: false,
701
+ error
702
+ };
703
+ return invocation.outcome;
704
+ }),
705
+ outcome: void 0,
706
+ waiting: 0
707
+ };
708
+ return invocation;
709
+ };
710
+ const wrap = (tool) => Object.freeze({
711
+ ...tool,
712
+ handler: async (raw) => {
713
+ const key = invocationKey(tool.name, raw);
714
+ let invocation = invocations.get(key);
715
+ if (invocation === void 0) {
716
+ invocation = start(tool, raw);
717
+ invocations.set(key, invocation);
718
+ }
719
+ if (invocation.outcome === void 0) {
720
+ invocation.waiting++;
721
+ try {
722
+ await withTimeout(invocation.settled, fenceMs);
723
+ } finally {
724
+ invocation.waiting--;
725
+ }
726
+ }
727
+ const outcome = invocation.outcome;
728
+ if (outcome === void 0) return pendingToolCall(tool.name, now() - invocation.startedAt);
729
+ if (invocations.get(key) === invocation) invocations.delete(key);
730
+ if (outcome.ok) return outcome.value;
731
+ throw outcome.error;
732
+ }
733
+ });
734
+ return {
735
+ tools: Object.freeze(tools.map(wrap)),
736
+ background() {
737
+ let count = 0;
738
+ for (const invocation of invocations.values()) if (invocation.outcome === void 0 && invocation.waiting === 0) count++;
739
+ return count;
740
+ }
741
+ };
742
+ }
743
+ function invocationKey(name, raw) {
744
+ try {
745
+ return canonicalCandidateJson([name, raw]);
746
+ } catch (error) {
747
+ throw new ValidationError(`${name}: arguments must be finite JSON so a repeated call can join its earlier run`, { cause: error });
748
+ }
749
+ }
750
+ function pendingToolCall(tool, elapsedMs) {
751
+ return {
752
+ pending: true,
753
+ tool,
754
+ elapsedMs,
755
+ instruction: `${tool} is still running; nothing failed. Call ${tool} again with the same arguments to keep waiting. That call joins this run and returns its result, or its error, once it finishes. Different arguments start a separate run.`
756
+ };
757
+ }
758
+ //#endregion
659
759
  //#region src/runtime/supervise/coordination-mcp.ts
660
760
  /**
661
761
  *
@@ -700,10 +800,25 @@ function assertCoordinationTransport(options) {
700
800
  }
701
801
  coordinationHttpLimits(options);
702
802
  }
803
+ /**
804
+ * The longest one coordination call holds its HTTP response before it answers with a re-pollable
805
+ * pending result instead: `await_event` by default, and every method-supplied node tool always.
806
+ *
807
+ * It is half of `requestTimeoutMs`, so the answer leaves before the transport's own 504 at
808
+ * `requestTimeoutMs`, with the other half left for body transfer, admission, and serialization.
809
+ * Deriving it here means a configured request timeout moves both fences with it. It is capped at
810
+ * {@link DEFAULT_AWAIT_EVENT_TIMEOUT_MS} so a long request timeout does not lengthen each wait; at
811
+ * the default 30 s request timeout both values are 15 s.
812
+ */
813
+ function coordinationResponseFenceMs(requestTimeoutMs) {
814
+ return Math.max(1, Math.min(DEFAULT_AWAIT_EVENT_TIMEOUT_MS, Math.floor(requestTimeoutMs / 2)));
815
+ }
703
816
  /** Stand up the existing coordination tools with bounded HTTP access over one live scope. */
704
817
  async function serveCoordinationMcp(opts) {
705
818
  const host = opts.host ?? "127.0.0.1";
706
819
  assertCoordinationTransport(opts);
820
+ const requestTimeoutMs = coordinationHttpLimits(opts).requestTimeoutMs;
821
+ const responseFenceMs = coordinationResponseFenceMs(requestTimeoutMs);
707
822
  if (opts.peerMail && (!isLoopbackHost(host) || opts.publicUrl)) throw new ConfigError("remote peer mail requires a separate reachable capability transport; coordination authentication does not authorize the peer listener");
708
823
  const identity = Object.freeze({ ...opts.identity ?? {
709
824
  runId: opts.scope.view?.root ?? "",
@@ -773,7 +888,7 @@ async function serveCoordinationMcp(opts) {
773
888
  ...opts.deliverable ? { deliverable: opts.deliverable } : {},
774
889
  ...opts.onStop ? { onStop: opts.onStop } : {},
775
890
  ...opts.maxLiveWorkers !== void 0 ? { maxLiveWorkers: opts.maxLiveWorkers } : {},
776
- awaitTimeoutMs: opts.awaitTimeoutMs ?? 15e3,
891
+ awaitTimeoutMs: opts.awaitTimeoutMs ?? responseFenceMs,
777
892
  ...opts.analysts ? { analysts: opts.analysts } : {},
778
893
  ...opts.analyzeOnSettle ? { analyzeOnSettle: opts.analyzeOnSettle } : {},
779
894
  ...opts.watchWorkers ? { watchWorkers: opts.watchWorkers } : {},
@@ -797,7 +912,8 @@ async function serveCoordinationMcp(opts) {
797
912
  if (reservedNames.has(tool.name)) throw new ValidationError(`serveCoordinationMcp: node tool ${JSON.stringify(tool.name)} shadows a coordination verb or another node tool`);
798
913
  reservedNames.add(tool.name);
799
914
  }
800
- const availableTools = [...coord.tools, ...opts.nodeTools ?? []];
915
+ const nodeTools = singleFlightTools(opts.nodeTools ?? [], { fenceMs: responseFenceMs });
916
+ const availableTools = [...coord.tools, ...nodeTools.tools];
801
917
  const availableByName = new Map(availableTools.map((tool) => [tool.name, tool]));
802
918
  if (!Array.isArray(opts.toolNames)) throw new ValidationError("serveCoordinationMcp: toolNames must name every granted tool explicitly");
803
919
  const selectedNames = opts.toolNames;
@@ -818,6 +934,7 @@ async function serveCoordinationMcp(opts) {
818
934
  identity,
819
935
  toolNames: new Set(servedTools.map((tool) => tool.name)),
820
936
  handle: (message) => mcp.handle(message),
937
+ backgroundActions: nodeTools.background,
821
938
  authorize: (req) => {
822
939
  if (!paths.has(req.url ?? "")) return 404;
823
940
  if (!audiences.has(req.headers.host ?? "")) return 403;
@@ -828,7 +945,6 @@ async function serveCoordinationMcp(opts) {
828
945
  if (!validCredential(supplied)) return 401;
829
946
  }
830
947
  }));
831
- const requestTimeoutMs = coordinationHttpLimits(opts).requestTimeoutMs;
832
948
  server.requestTimeout = requestTimeoutMs;
833
949
  server.headersTimeout = requestTimeoutMs;
834
950
  const port = await new Promise((resolve, reject) => {
@@ -3539,4 +3655,4 @@ function rootProviderModelEvidenceFromExecution(evidence) {
3539
3655
  //#endregion
3540
3656
  export { serveCoordinationMcp as _, isPreSpawnExecutorFailure as a, mapExecutorResult as b, withWorkerSpawnRetry as c, resolveSupervisorProfile as d, supervisorAgent as f, defaultUnmetContractSteer as g, classifyDriverFailure as h, workerFromBackend as i, assertCoordinationBinding as l, DriverAttemptsExhaustedError as m, supervise as n, resolveWorkerSpawnRetry as o, supervisorAgentWithTestBrain as p, superviseWithTestBrain as r, retryPreSpawnRefusals as s, DEFAULT_AUTHORED_PROFILE_SECURITY_POLICY as t, coordinationProfileToolPrefix as u, createSupervisorSpanRecorder as v, gateOnDeliverable as y };
3541
3657
 
3542
- //# sourceMappingURL=supervise-BvVk6npK.js.map
3658
+ //# sourceMappingURL=supervise-DV0dlkir.js.map