@tangle-network/agent-runtime 0.300.0 → 0.306.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.
- package/dist/{activation-DqWmWTyB.js → activation-C5wesfzd.js} +3 -3
- package/dist/{activation-DqWmWTyB.js.map → activation-C5wesfzd.js.map} +1 -1
- package/dist/{activation-Bhp8dYV5.d.ts → activation-wZ-8vOjV.d.ts} +88 -13
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/{bundle-C9v5TH_H.js → bundle-C8EO05u3.js} +2 -2
- package/dist/{bundle-C9v5TH_H.js.map → bundle-C8EO05u3.js.map} +1 -1
- package/dist/candidate-execution/index.d.ts +3 -26
- package/dist/candidate-execution/index.js +6 -6
- package/dist/{coordination-driver-DzTvehd6.js → coordination-driver-yj9HPXef.js} +322 -223
- package/dist/coordination-driver-yj9HPXef.js.map +1 -0
- package/dist/{delegate-vJ2g76r6.js → delegate-KtrL9HWq.js} +5 -5
- package/dist/delegate-KtrL9HWq.js.map +1 -0
- package/dist/durable.d.ts +3 -15
- package/dist/durable.js +158 -124
- package/dist/durable.js.map +1 -1
- package/dist/{graph-BDQh3qry.js → graph-DcdyHbgf.js} +5 -6
- package/dist/graph-DcdyHbgf.js.map +1 -0
- package/dist/{improvement-cycle-D6cPLi6k.js → improvement-cycle-DsN-TVXR.js} +1129 -10
- package/dist/improvement-cycle-DsN-TVXR.js.map +1 -0
- package/dist/{index-sC6sl88d.d.ts → index-DflDZq_I.d.ts} +188 -748
- package/dist/index.d.ts +378 -12
- package/dist/index.js +223 -320
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +5 -5
- package/dist/intelligence.js +7 -8
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +4 -4
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-DZglq4Cf.d.ts → loop-runner-bin-DZfRUVWy.d.ts} +3 -3
- package/dist/{loop-runner-bin-DQIHnCL0.js → loop-runner-bin-rVrSX5l1.js} +3 -3
- package/dist/{loop-runner-bin-DQIHnCL0.js.map → loop-runner-bin-rVrSX5l1.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +6 -35
- package/dist/mcp/index.js +311 -364
- package/dist/mcp/index.js.map +1 -1
- package/dist/model-policy-DydyWTQg.js.map +1 -1
- package/dist/{openai-tools-DvR82zEo.d.ts → openai-tools-YO30D2s3.d.ts} +2 -2
- package/dist/{prepare-CGVNMb1o.js → prepare--nWcazPr.js} +7 -13
- package/dist/prepare--nWcazPr.js.map +1 -0
- package/dist/{profile-BetOB4_Q.js → profile-h04LDjV6.js} +2 -2
- package/dist/{profile-BetOB4_Q.js.map → profile-h04LDjV6.js.map} +1 -1
- package/dist/profiles.d.ts +2 -94
- package/dist/profiles.js +2 -451
- package/dist/profiles.js.map +1 -1
- package/dist/{protected-model-port-CAa0t1MT.d.ts → protected-model-port-C9QtEf3y.d.ts} +2 -2
- package/dist/{protected-model-port-CuVHkhti.js → protected-model-port-wwalbyXM.js} +4 -4
- package/dist/{protected-model-port-CuVHkhti.js.map → protected-model-port-wwalbyXM.js.map} +1 -1
- package/dist/{provision-supervisor-IXBlLHE0.js → provision-supervisor-WxFEFQeJ.js} +14 -24
- package/dist/provision-supervisor-WxFEFQeJ.js.map +1 -0
- package/dist/{runtime-DpEt5v42.js → runtime-B9eBIyws.js} +86 -496
- package/dist/runtime-B9eBIyws.js.map +1 -0
- package/dist/{search-method-DvU-fc-f.js → search-executor-2tWr38Qw.js} +239 -1132
- package/dist/search-executor-2tWr38Qw.js.map +1 -0
- package/dist/{server-CIE8s4AN.js → server-CpKcrOPj.js} +5 -12
- package/dist/server-CpKcrOPj.js.map +1 -0
- package/dist/{stream-agent-turn-I3bb0eqF.d.ts → stream-agent-turn-B1giFgOg.d.ts} +4 -2
- package/dist/{substrate-UjsxukjZ.d.ts → substrate-L_sC7jCD.d.ts} +2 -2
- package/dist/{supervise-C5mktzrh.js → supervise-DllOHM4M.js} +206 -80
- package/dist/supervise-DllOHM4M.js.map +1 -0
- package/dist/{supervisor-CQSu5XGl.js → supervisor-gCfG6K1-.js} +1130 -1667
- package/dist/supervisor-gCfG6K1-.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +14 -14
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{types-C73caP0U.d.ts → types-DeuEkBhI.d.ts} +167 -261
- package/dist/{workspace-archive-pz8YJ1fr.d.ts → workspace-streams-CpSmt3zx.d.ts} +67 -3
- package/dist/{workspace-streams-D5gHJdTb.js → workspace-streams-ILw0eWZ0.js} +694 -2
- package/dist/workspace-streams-ILw0eWZ0.js.map +1 -0
- package/package.json +8 -8
- package/skills/generate-eval/SKILL.md +1 -1
- package/skills/profile-authoring/SKILL.md +5 -5
- package/skills/supervise/SKILL.md +2 -2
- package/dist/coordination-driver-DzTvehd6.js.map +0 -1
- package/dist/delegate-vJ2g76r6.js.map +0 -1
- package/dist/graph-BDQh3qry.js.map +0 -1
- package/dist/improvement-cycle-D6cPLi6k.js.map +0 -1
- package/dist/prepare-CGVNMb1o.js.map +0 -1
- package/dist/provision-supervisor-IXBlLHE0.js.map +0 -1
- package/dist/runtime-DpEt5v42.js.map +0 -1
- package/dist/search-method-DvU-fc-f.js.map +0 -1
- package/dist/server-CIE8s4AN.js.map +0 -1
- package/dist/supervise-C5mktzrh.js.map +0 -1
- package/dist/supervisor-CQSu5XGl.js.map +0 -1
- package/dist/workspace-streams-D5gHJdTb.js.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as scopeRetainedOwnerPriorSpend, $n as bridgeStopSignalKey, A as isDriverSpec, Ai as runtimeOwnedExecutorExecutionBinding, B as recordScopeOwnerMaterialization, Bi as detachedSnapshot, Ci as inheritRuntimeOwnedExecutorAttestation, Ct as snapshotExecutorConfig, Di as providerAttemptEvidence, Dt as createRouterTranscript, Fn as prepareJsonlAppend, G as beginScopeRetainedOwnerDrive, H as restoreScopeOwnerAcceptedExecution, I as deriveNodeExecutionIdentity, In as readCommittedJsonLines, It as createActivityLog, J as consumeScopeRetainedOwnerResult, Jn as meterUsageEvent, K as bindScopeRetainedOwnerEnvironmentId, Kn as assertValidBudget, L as meterRuntimeOwnedAccounting, Mi as runtimeOwnedExecutorProviderEvidence, Mr as createOtelExporter, N as assertRecursiveReservationPolicy, Ni as runtimeOwnedPendingExecutorMaterialization, O as driverChild, Oi as recordRuntimeOwnedDriveHarnessProviderEvidence, P as beginScopeOwnerAttempt, Pi as runtimeOwnedScopeOwnerRuntime, Pn as isNoEntError, Pr as generateSpanId, Q as scopeRetainedOwnerContext, Qn as bridgeRuntimeAttachmentsKey, R as meterRuntimeOwnedProviderAttempt, Rr as toOtelAttributes, Rt as createInbox, S as createContinuationKeeper, Tn as retainedExecutorSeamKey, U as scopeOwnerExecutorNodeContext, Un as executorFailure, V as recordScopeOwnerPause, Vn as parseWorkerToolTraceArtifact, X as prepareScopeRetainedOwnerTask, Xt as bridgeModelRouteRefusal, Y as noteScopeRetainedOwnerCoordination, Yn as newUsageTotals, Yt as bridgeAdmissionRefusal, Z as reconcileScopeRetainedOwnerEnvironment, Zn as spendFromUsageTotals, _ as CheckUnavailableError, _r as readHarnessTranscript, _t as bindReusableExecutorExecutionId, ai as controlProfileMaterialization, b as bestComposite, bi as attestRuntimeOwnedScopeOwner, br as contentAddress, c as runTree, ci as profileMaterializationAxes$1, er as errMessage, et as scopeRetainedOwnerResourceReader, f as runDriverWithRetry, fn as routerBrain, fr as linkAbort, gi as unsupportedProfileDimensions, gr as persistHarnessTranscript, h as CONTINUATIONS_DIR, i as bestDelivered, ii as assertProfileMaterialization, ji as runtimeOwnedExecutorMaterialization, k as driverExecutorFactory, ki as runtimeOwnedDriveHarnessProviderEvidence, kt as WORKER_TRACE_PROPAGATION, li as promptControlProfileMaterialization, mi as renderUnsupported, n as createRootHandle, nt as scopeRetainedOwnerResult, oi as defineProfileMaterializationContract, p as summarizeDriverAttempts, pr as runAbortable, q as bindScopeRetainedOwnerProvider, qt as isLiveNodeStatus, r as createSupervisor, rt as scopeRetainedOwnerTurnEnded, s as runFinalizer, si as fullProfileMaterialization, tt as scopeRetainedOwnerRestorePoint, u as HarnessTurnFailedError, ui as promptModelProfileMaterialization, ur as RunCancellationReason, v as admitContinuationPolicy, vi as worktreeCliProfileMaterialization, vn as resolveAgentEnvironmentProvider, vt as captureReusableExecutorConfig, wn as registerRetainedExecutorPreparation, x as checkVerdictOf, xt as createExecutor, z as recordScopeOwnerDriverAttempt } from "./supervisor-gCfG6K1-.js";
|
|
2
2
|
import { f as RuntimeRunStateError, i as ConfigError, m as ValidationError } from "./errors-DodWX-cb.js";
|
|
3
|
+
import { G as errorMessage, St as teardownSurfaces, Y as isAsyncIterable$1, at as unmeteredSpend, dt as resourceTelemetry, ft as withBudgetResources, ht as DEFAULT_SUCCESSFUL_SHUTDOWN_MS, lt as addResourceSpend, ot as withTimeout, st as zeroSpend, tt as sleep, xt as teardownExecutor, z as addSpend } from "./workspace-streams-ILw0eWZ0.js";
|
|
3
4
|
import { _ as agentHarness, a as concreteProfileModel, c as profileModelExecutionSettings, n as assertModelAllowed, o as enforceTokenLimits, r as assertProfileModelsAllowed, s as profileBridgeWireModel, t as assertExecutableAgentProfile, v as harnessRunsAgent } from "./model-policy-DydyWTQg.js";
|
|
4
5
|
import { n as assertNoSymlinkDescendant } from "./durable-file-DWQA4ooo.js";
|
|
5
6
|
import { t as composeRuntimeHooks } from "./runtime-hooks-tXpAarhW.js";
|
|
6
|
-
import {
|
|
7
|
+
import { C as createInMemoryRunContext, D as applyRunCancellation, M as coordinationVerbNames, O as watchRunCancellation, P as createCoordinationToolsForManager, S as createFileRunContext, c as resolveWakePolicy, f as createProgressTracker, h as progressStop, m as plateau, n as createSteerAcknowledger, o as composeWakeInput, r as driverAgent, s as deadlineWarningAt, t as createCancelAcknowledger, w as withRunContext } from "./coordination-driver-yj9HPXef.js";
|
|
7
8
|
import { r as createStdioToolServer, t as PROTOCOL_VERSION } from "./tool-server-Dqer2M4_.js";
|
|
8
9
|
import { k as writeRunCancellation, o as readRunCancelRequest, s as readRunCancellation } from "./run-layout-DSCWdbX2.js";
|
|
9
10
|
import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalCandidateJson, validateAgentProfileSecurity } from "@tangle-network/agent-interface";
|
|
@@ -16,6 +17,13 @@ import { isMaterializerHarness } from "@tangle-network/agent-profile-materialize
|
|
|
16
17
|
import { ATTR } from "@tangle-network/agent-trace-contract";
|
|
17
18
|
import { createServer } from "node:http";
|
|
18
19
|
import { withProfileKb } from "@tangle-network/agent-interface/profile-kb";
|
|
20
|
+
//#region src/mcp/tools/coordination-request-context.ts
|
|
21
|
+
/** The tool-call timeout Runtime asks harnesses to give its coordination server. The Tangle
|
|
22
|
+
* profile materializer writes it as `MCP_TOOL_TIMEOUT` (Claude Code) and `tool_timeout_sec`
|
|
23
|
+
* (Codex) when an attachment declares `metadata.toolTimeoutMs`, so a fenced coordination call
|
|
24
|
+
* that holds its response for its whole fence is never cut off at the 60 s harness default. */
|
|
25
|
+
const COORDINATION_CLIENT_TOOL_TIMEOUT_MS = 3e5;
|
|
26
|
+
//#endregion
|
|
19
27
|
//#region src/runtime/supervise/completion-gate.ts
|
|
20
28
|
/**
|
|
21
29
|
*
|
|
@@ -85,7 +93,7 @@ function gateOnDeliverable(inner, deliverable) {
|
|
|
85
93
|
...inner.harnessTranscriptSettled ? { harnessTranscriptSettled: () => inner.harnessTranscriptSettled?.() ?? Promise.resolve() } : {},
|
|
86
94
|
execute(task, signal) {
|
|
87
95
|
const r = inner.execute(task, signal);
|
|
88
|
-
if (isAsyncIterable$
|
|
96
|
+
if (isAsyncIterable$1(r)) return (async function* () {
|
|
89
97
|
try {
|
|
90
98
|
for await (const ev of r) yield ev;
|
|
91
99
|
} finally {
|
|
@@ -148,7 +156,7 @@ function mapExecutorResult(inner, map) {
|
|
|
148
156
|
...inner.harnessTranscriptSettled ? { harnessTranscriptSettled: () => inner.harnessTranscriptSettled?.() ?? Promise.resolve() } : {},
|
|
149
157
|
execute(task, signal) {
|
|
150
158
|
const execution = inner.execute(task, signal);
|
|
151
|
-
if (isAsyncIterable$
|
|
159
|
+
if (isAsyncIterable$1(execution)) return (async function* () {
|
|
152
160
|
for await (const event of execution) yield event;
|
|
153
161
|
await settle(inner.resultArtifact(), task);
|
|
154
162
|
})();
|
|
@@ -162,9 +170,6 @@ function mapExecutorResult(inner, map) {
|
|
|
162
170
|
}
|
|
163
171
|
});
|
|
164
172
|
}
|
|
165
|
-
function isAsyncIterable$2(v) {
|
|
166
|
-
return v != null && typeof v[Symbol.asyncIterator] === "function";
|
|
167
|
-
}
|
|
168
173
|
//#endregion
|
|
169
174
|
//#region src/runtime/supervise/coordination-http.ts
|
|
170
175
|
function coordinationHttpLimits(options) {
|
|
@@ -287,12 +292,10 @@ function coordinationHttpHandler(input) {
|
|
|
287
292
|
active++;
|
|
288
293
|
}
|
|
289
294
|
admitted = true;
|
|
290
|
-
const declaredTimeoutMs = declaredToolTimeoutMs(req.headers[MCP_TOOL_TIMEOUT_HEADER]);
|
|
291
|
-
const declaredFenceMs = declaredTimeoutMs === void 0 ? void 0 : declaredAwaitFenceMs(declaredTimeoutMs);
|
|
292
295
|
timer = setTimeout(() => {
|
|
293
296
|
timedOut = true;
|
|
294
297
|
reject(executing ? 504 : 408);
|
|
295
|
-
},
|
|
298
|
+
}, limits.requestTimeoutMs);
|
|
296
299
|
timer.unref();
|
|
297
300
|
let size = 0;
|
|
298
301
|
const chunks = [];
|
|
@@ -342,7 +345,7 @@ function coordinationHttpHandler(input) {
|
|
|
342
345
|
reject(authorization);
|
|
343
346
|
return;
|
|
344
347
|
}
|
|
345
|
-
const response = await
|
|
348
|
+
const response = await input.handle(message);
|
|
346
349
|
if (!finished) respond(response === null ? 202 : 200, response ?? void 0);
|
|
347
350
|
await audit(timedOut ? "completed-after-deadline" : "completed", timedOut ? 504 : response === null ? 202 : 200, action);
|
|
348
351
|
} catch {
|
|
@@ -459,25 +462,23 @@ async function preflightPublicCoordination(input) {
|
|
|
459
462
|
*
|
|
460
463
|
* Two rules close that failure:
|
|
461
464
|
* - Identity. A call joins an existing invocation when its tool name and its RFC 8785 canonical
|
|
462
|
-
* arguments match, and that invocation has not yet
|
|
463
|
-
*
|
|
464
|
-
* - Fence. A call waits at most `fenceMs` for the outcome. If the handler is still running, the
|
|
465
|
-
* returns a
|
|
466
|
-
*
|
|
465
|
+
* arguments match, and that invocation has not yet settled. The handler is not invoked again.
|
|
466
|
+
* Key order does not matter: the observed retry reordered every key.
|
|
467
|
+
* - Fence. A call waits at most `fenceMs` for the outcome. If the handler is still running, the
|
|
468
|
+
* call returns a receipt. The handler keeps running, and its outcome is published to the
|
|
469
|
+
* manager's inbox, where its next wake delivers it. Nothing has to call again to collect it.
|
|
467
470
|
*
|
|
468
|
-
* An invocation's identity ends when
|
|
469
|
-
*
|
|
471
|
+
* An invocation's identity ends when its handler settles. The next identical call is a fresh run,
|
|
472
|
+
* because equal arguments do not make a call a replay: code mode's `execute` and Knowledge's
|
|
470
473
|
* `knowledge_search` read live state, so their callers repeat identical arguments to get a current
|
|
471
474
|
* answer. A handler that finishes within the fence therefore behaves exactly as it did unwrapped.
|
|
472
|
-
* No escape hatch is needed: the only calls this absorbs are ones whose caller could not have seen
|
|
473
|
-
* the outcome.
|
|
474
475
|
*/
|
|
475
476
|
function singleFlightTools(tools, options) {
|
|
476
|
-
const { fenceMs } = options;
|
|
477
|
+
const { fenceMs, receipts } = options;
|
|
477
478
|
if (!Number.isSafeInteger(fenceMs) || fenceMs <= 0) throw new ValidationError("singleFlightTools: fenceMs must be a positive safe integer");
|
|
478
479
|
const now = options.now ?? Date.now;
|
|
479
480
|
const invocations = /* @__PURE__ */ new Map();
|
|
480
|
-
const start = (tool, raw) => {
|
|
481
|
+
const start = (tool, raw, key) => {
|
|
481
482
|
const invocation = {
|
|
482
483
|
startedAt: now(),
|
|
483
484
|
settled: (async () => tool.handler(raw))().then((value) => {
|
|
@@ -494,8 +495,19 @@ function singleFlightTools(tools, options) {
|
|
|
494
495
|
return invocation.outcome;
|
|
495
496
|
}),
|
|
496
497
|
outcome: void 0,
|
|
497
|
-
waiting: 0
|
|
498
|
+
waiting: 0,
|
|
499
|
+
receipt: void 0
|
|
498
500
|
};
|
|
501
|
+
invocation.settled.then(async (outcome) => {
|
|
502
|
+
if (invocations.get(key) === invocation) invocations.delete(key);
|
|
503
|
+
if (invocation.receipt !== void 0) await receipts.settleToolReceipt(invocation.receipt, outcome).catch((error) => {
|
|
504
|
+
console.error("Runtime could not publish a receipted tool outcome", {
|
|
505
|
+
tool: tool.name,
|
|
506
|
+
receipt: invocation.receipt,
|
|
507
|
+
error: error instanceof Error ? error.message : String(error)
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
});
|
|
499
511
|
return invocation;
|
|
500
512
|
};
|
|
501
513
|
const wrap = (tool) => Object.freeze({
|
|
@@ -504,7 +516,7 @@ function singleFlightTools(tools, options) {
|
|
|
504
516
|
const key = invocationKey(tool.name, raw);
|
|
505
517
|
let invocation = invocations.get(key);
|
|
506
518
|
if (invocation === void 0) {
|
|
507
|
-
invocation = start(tool, raw);
|
|
519
|
+
invocation = start(tool, raw, key);
|
|
508
520
|
invocations.set(key, invocation);
|
|
509
521
|
}
|
|
510
522
|
if (invocation.outcome === void 0) {
|
|
@@ -516,8 +528,10 @@ function singleFlightTools(tools, options) {
|
|
|
516
528
|
}
|
|
517
529
|
}
|
|
518
530
|
const outcome = invocation.outcome;
|
|
519
|
-
if (outcome === void 0)
|
|
520
|
-
|
|
531
|
+
if (outcome === void 0) {
|
|
532
|
+
invocation.receipt ??= receipts.openToolReceipt(tool.name);
|
|
533
|
+
return toolCallReceipt(tool.name, invocation.receipt, now() - invocation.startedAt);
|
|
534
|
+
}
|
|
521
535
|
if (outcome.ok) return outcome.value;
|
|
522
536
|
throw outcome.error;
|
|
523
537
|
}
|
|
@@ -538,19 +552,20 @@ function invocationKey(name, raw) {
|
|
|
538
552
|
throw new ValidationError(`${name}: arguments must be finite JSON so a repeated call can join its earlier run`, { cause: error });
|
|
539
553
|
}
|
|
540
554
|
}
|
|
541
|
-
function
|
|
555
|
+
function toolCallReceipt(tool, receipt, elapsedMs) {
|
|
542
556
|
return {
|
|
543
|
-
|
|
557
|
+
running: true,
|
|
558
|
+
receipt,
|
|
544
559
|
tool,
|
|
545
560
|
elapsedMs,
|
|
546
|
-
instruction: `${tool} is still running; nothing failed.
|
|
561
|
+
instruction: `${tool} is still running; nothing failed. Do not call it again: its result arrives with receipt ${receipt} when you are next woken. Continue other work, or end your turn to wait.`
|
|
547
562
|
};
|
|
548
563
|
}
|
|
549
564
|
//#endregion
|
|
550
565
|
//#region src/runtime/supervise/coordination-mcp.ts
|
|
551
566
|
/**
|
|
552
567
|
*
|
|
553
|
-
* Serve the coordination verbs (spawn_worker /
|
|
568
|
+
* Serve the coordination verbs (spawn_worker / observe_agent / steer_agent / submit_result / stop)
|
|
554
569
|
* as a real HTTP MCP server over a LIVE `Scope`. This is the keystone that lets a coding-harness
|
|
555
570
|
* agent (opencode via the cli-bridge, claude-code, codex) BE the supervisor: it mounts this MCP
|
|
556
571
|
* (`mcp.mcpServers.coordination`) and calls `spawn_worker` as a native tool, which lands on
|
|
@@ -597,20 +612,20 @@ function assertCoordinationTransport(options) {
|
|
|
597
612
|
* exactly when a deliverable is injected.
|
|
598
613
|
*/
|
|
599
614
|
const DELIVERABLE_VERB = "submit_result";
|
|
615
|
+
/** The longest any coordination call holds its response, whatever the request timeout: under the
|
|
616
|
+
* 60 s MCP tool-call timeout Claude Code and Codex apply by default. */
|
|
617
|
+
const RESPONSE_FENCE_CAP_MS = 45e3;
|
|
600
618
|
/**
|
|
601
|
-
* The longest
|
|
602
|
-
*
|
|
603
|
-
*
|
|
619
|
+
* The longest a fenced coordination call (`submit_result` and every method-supplied node tool)
|
|
620
|
+
* holds its HTTP response before it answers with a receipt instead. The call keeps running, and
|
|
621
|
+
* its outcome reaches the manager in its next wake.
|
|
604
622
|
*
|
|
605
623
|
* It is half of `requestTimeoutMs`, so the answer leaves before the transport's own 504 at
|
|
606
|
-
* `requestTimeoutMs`, with the other half left for body transfer, admission, and serialization
|
|
607
|
-
*
|
|
608
|
-
* {@link DEFAULT_AWAIT_EVENT_TIMEOUT_MS} so a long request timeout does not lengthen each wait; at
|
|
609
|
-
* the default 90 s request timeout both values are 45 s, under the 60 s MCP tool-call timeout that
|
|
610
|
-
* Claude Code and Codex apply by default.
|
|
624
|
+
* `requestTimeoutMs`, with the other half left for body transfer, admission, and serialization,
|
|
625
|
+
* and at most {@link RESPONSE_FENCE_CAP_MS}.
|
|
611
626
|
*/
|
|
612
627
|
function coordinationResponseFenceMs(requestTimeoutMs) {
|
|
613
|
-
return Math.max(1, Math.min(
|
|
628
|
+
return Math.max(1, Math.min(RESPONSE_FENCE_CAP_MS, Math.floor(requestTimeoutMs / 2)));
|
|
614
629
|
}
|
|
615
630
|
/** Stand up the existing coordination tools with bounded HTTP access over one live scope. */
|
|
616
631
|
async function serveCoordinationMcp(opts) {
|
|
@@ -698,7 +713,6 @@ async function serveCoordinationMcpForManager(opts, lifetime) {
|
|
|
698
713
|
...opts.deliverable ? { deliverable: opts.deliverable } : {},
|
|
699
714
|
...opts.readContinuation ? { readContinuation: opts.readContinuation } : {},
|
|
700
715
|
...opts.onStop ? { onStop: opts.onStop } : {},
|
|
701
|
-
awaitTimeoutMs: opts.awaitTimeoutMs ?? responseFenceMs,
|
|
702
716
|
...opts.analysts ? { analysts: opts.analysts } : {},
|
|
703
717
|
...opts.analyzeOnSettle ? { analyzeOnSettle: opts.analyzeOnSettle } : {},
|
|
704
718
|
...opts.sourceEvidenceRefs ? { sourceEvidenceRefs: opts.sourceEvidenceRefs } : {},
|
|
@@ -727,8 +741,14 @@ async function serveCoordinationMcpForManager(opts, lifetime) {
|
|
|
727
741
|
if (reservedNames.has(tool.name)) throw new ValidationError(`serveCoordinationMcp: node tool ${JSON.stringify(tool.name)} shadows a coordination verb or another node tool`);
|
|
728
742
|
reservedNames.add(tool.name);
|
|
729
743
|
}
|
|
730
|
-
const nodeTools = singleFlightTools(opts.nodeTools ?? [], {
|
|
731
|
-
|
|
744
|
+
const nodeTools = singleFlightTools(opts.nodeTools ?? [], {
|
|
745
|
+
fenceMs: responseFenceMs,
|
|
746
|
+
receipts: coord
|
|
747
|
+
});
|
|
748
|
+
const fencedVerbs = singleFlightTools(coord.tools.filter((tool) => tool.name === DELIVERABLE_VERB), {
|
|
749
|
+
fenceMs: responseFenceMs,
|
|
750
|
+
receipts: coord
|
|
751
|
+
});
|
|
732
752
|
if (opts.deliverable && fencedVerbs.tools.length !== 1) throw new ValidationError(`serveCoordinationMcp: a deliverable is injected but the coordination verbs lack ${DELIVERABLE_VERB}, so its check would run unfenced`);
|
|
733
753
|
const fencedByName = new Map(fencedVerbs.tools.map((tool) => [tool.name, tool]));
|
|
734
754
|
const availableTools = [...coord.tools.map((tool) => fencedByName.get(tool.name) ?? tool), ...nodeTools.tools];
|
|
@@ -747,7 +767,7 @@ async function serveCoordinationMcpForManager(opts, lifetime) {
|
|
|
747
767
|
serverVersion: "1",
|
|
748
768
|
tools: servedTools
|
|
749
769
|
});
|
|
750
|
-
opts.onCoordinationTools?.([...mcp.tools.values()]);
|
|
770
|
+
opts.onCoordinationTools?.([...mcp.tools.values()], coord);
|
|
751
771
|
const server = createServer(coordinationHttpHandler({
|
|
752
772
|
options: opts,
|
|
753
773
|
identity,
|
|
@@ -1032,14 +1052,13 @@ function createSupervisorSpanRecorder(opts) {
|
|
|
1032
1052
|
if (!childId) return;
|
|
1033
1053
|
const label = str(p.label) ?? "node";
|
|
1034
1054
|
const runtime = str(p.runtime);
|
|
1035
|
-
const isWait = runtime === "wait";
|
|
1036
1055
|
const attrs = {
|
|
1037
1056
|
...base,
|
|
1038
|
-
[ATTR.spanKind]:
|
|
1057
|
+
[ATTR.spanKind]: "AGENT",
|
|
1039
1058
|
"agent.name": label,
|
|
1040
1059
|
"tangle.supervise.node.id": childId,
|
|
1041
1060
|
"tangle.supervise.node.label": label,
|
|
1042
|
-
"tangle.supervise.node.kind":
|
|
1061
|
+
"tangle.supervise.node.kind": "agent",
|
|
1043
1062
|
"tangle.supervise.tree.root": event.runId
|
|
1044
1063
|
};
|
|
1045
1064
|
if (event.parentId) attrs["tangle.supervise.node.parent_id"] = event.parentId;
|
|
@@ -1296,6 +1315,7 @@ function composeReentryTask(input) {
|
|
|
1296
1315
|
const changes = stateLines(state, false, input.tools);
|
|
1297
1316
|
return [reentry.steer, ...changes.length > 0 ? ["", ...changes] : []].join("\n");
|
|
1298
1317
|
}
|
|
1318
|
+
if (reentry.reason === "wake" && continuity.session === "continued") return reentry.input;
|
|
1299
1319
|
return [
|
|
1300
1320
|
`You are re-entering a run that is already in progress (driver attempt ${input.attempt}). This is the same run and the same objective, not a new one.`,
|
|
1301
1321
|
whyLine(reentry),
|
|
@@ -1317,6 +1337,12 @@ function composeReentryTask(input) {
|
|
|
1317
1337
|
"",
|
|
1318
1338
|
reentry.steer
|
|
1319
1339
|
] : [],
|
|
1340
|
+
...reentry.reason === "wake" ? [
|
|
1341
|
+
"",
|
|
1342
|
+
"## What woke you",
|
|
1343
|
+
"",
|
|
1344
|
+
reentry.input
|
|
1345
|
+
] : [],
|
|
1320
1346
|
"",
|
|
1321
1347
|
"## Run state, from the coordinator",
|
|
1322
1348
|
"",
|
|
@@ -1326,7 +1352,6 @@ function composeReentryTask(input) {
|
|
|
1326
1352
|
"",
|
|
1327
1353
|
"Continue the run from this state.",
|
|
1328
1354
|
...continuity.workspace === "kept" || continuity.workspace === "restored" ? ["Read the files you already wrote before you repeat any step of the task. A step whose file is there is done, and its content stands."] : [],
|
|
1329
|
-
...input.tools?.includes("await_event") === true ? ["Receive the waiting events with await_event before starting new work."] : [],
|
|
1330
1355
|
...input.tools?.includes("observe_agent") === true ? ["Read the output of every settled worker with observe_agent before you spawn anything new."] : [],
|
|
1331
1356
|
"Do not spawn a replacement for a worker that is running or has settled.",
|
|
1332
1357
|
"Your coordination tools are served by the same coordinator as before, and the state above comes from it."
|
|
@@ -1340,6 +1365,7 @@ function composeReentryTask(input) {
|
|
|
1340
1365
|
*/
|
|
1341
1366
|
function whyLine(reentry) {
|
|
1342
1367
|
if (reentry.reason === "unmet-contract") return `Your previous turn ended with the completion check unmet (continuation ${reentry.continuation}).`;
|
|
1368
|
+
if (reentry.reason === "wake") return "Your previous turn ended while your workers ran, and Runtime woke you with what happened.";
|
|
1343
1369
|
return reentry.reason === "upstream-unavailable" ? "Your previous turn was interrupted before it finished; the run itself is intact." : `Your previous turn ended before it finished (retry ${reentry.retry}); the run itself is intact.`;
|
|
1344
1370
|
}
|
|
1345
1371
|
function environmentLine(continuity) {
|
|
@@ -1357,7 +1383,7 @@ function stateLines(state, full, tools) {
|
|
|
1357
1383
|
else if (full) lines.push("Workers settled: none.");
|
|
1358
1384
|
if (state.waiting.length > 0) lines.push(`Events waiting for you: ${state.waiting.length} (${state.waiting.map((event) => event.worker === void 0 ? event.type : `${event.type} from ${event.worker}`).join("; ")}).`);
|
|
1359
1385
|
else if (full) lines.push("Events waiting for you: none.");
|
|
1360
|
-
if (state.unacknowledged.length > 0) lines.push(`Events delivered to a turn that
|
|
1386
|
+
if (state.unacknowledged.length > 0) lines.push(`Events delivered to a turn that has not finished, so treat them as unread: ${state.unacknowledged.map((event) => `#${event.seq} ${event.type}${event.worker === void 0 ? "" : ` from ${event.worker}`}`).join("; ")}.`);
|
|
1361
1387
|
if (state.lastRejection !== void 0) lines.push(`Your last submit_result was refused: ${state.lastRejection.reason}`);
|
|
1362
1388
|
return lines;
|
|
1363
1389
|
}
|
|
@@ -1528,9 +1554,6 @@ async function readRootStream(runDir) {
|
|
|
1528
1554
|
}
|
|
1529
1555
|
return records;
|
|
1530
1556
|
}
|
|
1531
|
-
function errorMessage(error) {
|
|
1532
|
-
return error instanceof Error ? error.message : String(error);
|
|
1533
|
-
}
|
|
1534
1557
|
//#endregion
|
|
1535
1558
|
//#region src/runtime/supervise/run-traces.ts
|
|
1536
1559
|
/**
|
|
@@ -1769,6 +1792,7 @@ function declaredRuntimeToolNames(profile) {
|
|
|
1769
1792
|
/** Describe Runtime declarations that cannot resolve without a product tool provider. */
|
|
1770
1793
|
function runtimeToolDeclarationError(profile, hasProductToolResolver, mountedStaticToolNames = []) {
|
|
1771
1794
|
const mountedStaticToolNameSet = new Set(mountedStaticToolNames);
|
|
1795
|
+
if (declaredRuntimeToolNames(profile).includes("await_event")) return `the profile declares ${JSON.stringify(`${coordinationProfileToolPrefix}await_event`)}, which no longer exists: a manager ends its turn to wait, and Runtime wakes it with what happened. Remove the grant`;
|
|
1772
1796
|
const unresolved = declaredRuntimeToolNames(profile).filter((name) => !coordinationVerbNameSet$1.has(name) && !hasProductToolResolver && !mountedStaticToolNameSet.has(name));
|
|
1773
1797
|
if (unresolved.length === 0) return void 0;
|
|
1774
1798
|
return `the profile declares ${unresolved.map((name) => JSON.stringify(`${coordinationProfileToolPrefix}${name}`)).join(", ")}, but this run has no resolveSupervisorTools provider or router-mounted static tool for those tools`;
|
|
@@ -1860,6 +1884,7 @@ function assertCoordinationBinding(binding) {
|
|
|
1860
1884
|
}
|
|
1861
1885
|
function createVerbSlot() {
|
|
1862
1886
|
let bound;
|
|
1887
|
+
let waits;
|
|
1863
1888
|
const verb = (name) => async (args) => {
|
|
1864
1889
|
if (bound === void 0) throw new ValidationError(`supervisorAgent: coordination verb "${name}" was called before this manager's coordination tools were bound`);
|
|
1865
1890
|
const tool = bound.find((descriptor) => descriptor.name === name);
|
|
@@ -1869,7 +1894,12 @@ function createVerbSlot() {
|
|
|
1869
1894
|
return {
|
|
1870
1895
|
verbs: Object.freeze({
|
|
1871
1896
|
spawnAgent: verb("spawn_worker"),
|
|
1872
|
-
|
|
1897
|
+
awaitSettlement: async (args) => {
|
|
1898
|
+
if (waits === void 0) throw new ValidationError("supervisorAgent: coordination verb \"awaitSettlement\" was called before this manager's coordination tools were bound");
|
|
1899
|
+
const ids = args?.workerIds;
|
|
1900
|
+
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new ValidationError("awaitSettlement: workerIds must be an array of worker ids");
|
|
1901
|
+
return { settled: await waits.awaitSettlement(ids) };
|
|
1902
|
+
},
|
|
1873
1903
|
steerAgent: verb("steer_agent"),
|
|
1874
1904
|
observeAgent: verb("observe_agent"),
|
|
1875
1905
|
listQuestions: verb("list_questions"),
|
|
@@ -1886,8 +1916,9 @@ function createVerbSlot() {
|
|
|
1886
1916
|
inputSchema
|
|
1887
1917
|
})));
|
|
1888
1918
|
},
|
|
1889
|
-
bind(tools) {
|
|
1919
|
+
bind(tools, coordination) {
|
|
1890
1920
|
bound = tools;
|
|
1921
|
+
waits = coordination;
|
|
1891
1922
|
}
|
|
1892
1923
|
};
|
|
1893
1924
|
}
|
|
@@ -1978,7 +2009,7 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
1978
2009
|
...deps.escalateQuestion ? { escalateQuestion: deps.escalateQuestion } : {},
|
|
1979
2010
|
...deps.watchWorkers ? { watchWorkers: deps.watchWorkers } : {},
|
|
1980
2011
|
...deps.stallAfterMs !== void 0 ? { stallAfterMs: deps.stallAfterMs } : {},
|
|
1981
|
-
...deps.
|
|
2012
|
+
...deps.wake !== void 0 ? { wake: deps.wake } : {},
|
|
1982
2013
|
...deps.continuityByProfile ? { continuityByProfile: deps.continuityByProfile } : {},
|
|
1983
2014
|
...deps.preflightSpawn ? { preflightSpawn: deps.preflightSpawn } : {},
|
|
1984
2015
|
...deps.resolveSpawnProfile ? { resolveSpawnProfile: deps.resolveSpawnProfile } : {},
|
|
@@ -1994,7 +2025,7 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
1994
2025
|
...deps.replaySettlements ? { replaySettlements: true } : {},
|
|
1995
2026
|
...priorCoordination ? { priorCoordination } : {},
|
|
1996
2027
|
...deps.finalizer ? { finalizer: deps.finalizer } : {},
|
|
1997
|
-
...slot ? { onCoordinationTools: (tools) => slot.bind(tools) } : {},
|
|
2028
|
+
...slot ? { onCoordinationTools: (tools, coordination) => slot.bind(tools, coordination) } : {},
|
|
1998
2029
|
...deps.controlDir === void 0 ? {} : { controlDir: deps.controlDir },
|
|
1999
2030
|
...deps.steerDir === void 0 ? {} : { steerDir: deps.steerDir },
|
|
2000
2031
|
...deps.controlScope === void 0 ? {} : { controlScope: deps.controlScope },
|
|
@@ -2024,13 +2055,25 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2024
2055
|
const rawDeliverReady = driveHarness.deliverReady;
|
|
2025
2056
|
if (rawDeliverReady !== void 0 && typeof rawDeliverReady !== "function") throw new ValidationError("supervisorAgent: driveHarness.deliverReady must be a function when provided");
|
|
2026
2057
|
const deliverReady = rawDeliverReady?.bind(driveHarness);
|
|
2058
|
+
const wakePolicy = resolveWakePolicy(deps.wake);
|
|
2059
|
+
let managerInbox;
|
|
2060
|
+
let waitingOn;
|
|
2061
|
+
let liveCoordinator;
|
|
2027
2062
|
const externalAgent = {
|
|
2028
2063
|
name,
|
|
2029
|
-
|
|
2030
|
-
return
|
|
2031
|
-
}
|
|
2064
|
+
deliver(message) {
|
|
2065
|
+
return managerInbox?.(message) ?? false;
|
|
2066
|
+
},
|
|
2067
|
+
resultAccepted: () => Boolean(liveCoordinator?.submittedResult()),
|
|
2032
2068
|
traceSource: () => driveHarness.traceSource?.(),
|
|
2033
|
-
progress: () =>
|
|
2069
|
+
progress: () => {
|
|
2070
|
+
const harnessProgress = driveHarness.progress?.();
|
|
2071
|
+
if (waitingOn === void 0) return harnessProgress;
|
|
2072
|
+
return {
|
|
2073
|
+
...harnessProgress,
|
|
2074
|
+
note: `waiting for ${waitingOn} worker${waitingOn === 1 ? "" : "s"}; Runtime wakes it when one reports`
|
|
2075
|
+
};
|
|
2076
|
+
},
|
|
2034
2077
|
...driveHarness.harnessTranscript ? { harnessTranscript: () => driveHarness.harnessTranscript?.() } : {},
|
|
2035
2078
|
...driveHarness.harnessTranscriptSettled ? { harnessTranscriptSettled: () => driveHarness.harnessTranscriptSettled?.() ?? Promise.resolve() } : {},
|
|
2036
2079
|
async act(task, scope) {
|
|
@@ -2102,12 +2145,17 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2102
2145
|
...priorCoordination?.analystDefinitions?.length ? { priorAnalystDefinitions: priorCoordination.analystDefinitions } : {},
|
|
2103
2146
|
...nodeTools?.length ? { nodeTools } : {},
|
|
2104
2147
|
toolNames: runtimeToolNames,
|
|
2105
|
-
onCoordinationTools: (tools) => slot.bind(tools)
|
|
2148
|
+
onCoordinationTools: (tools, coordination) => slot.bind(tools, coordination)
|
|
2106
2149
|
}, coordinationLifetime.signal).catch((error) => {
|
|
2107
2150
|
coordinationLifetime.abort(error);
|
|
2108
2151
|
throw error;
|
|
2109
2152
|
});
|
|
2110
2153
|
ledger = mcp;
|
|
2154
|
+
liveCoordinator = mcp;
|
|
2155
|
+
managerInbox = (message) => {
|
|
2156
|
+
if (deliver !== void 0 && harnessInvocationActive && (deliverReady === void 0 || deliverReady()) && deliver(message)) return true;
|
|
2157
|
+
return controls.receiveLeadMessage(message);
|
|
2158
|
+
};
|
|
2111
2159
|
const coordinationTools = slot.descriptors();
|
|
2112
2160
|
const providerProfile = detachedSnapshot(providerVisibleProfile(stableProfile), "supervisorAgent provider-visible profile");
|
|
2113
2161
|
let controlObserver;
|
|
@@ -2120,8 +2168,8 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2120
2168
|
signal: coordinationLifetime.signal,
|
|
2121
2169
|
controlScope: deps.controlScope ?? "run",
|
|
2122
2170
|
...deps.controlScope === "subtree" ? {} : {
|
|
2123
|
-
deliverRoot: (message) =>
|
|
2124
|
-
deliverRootReady: () =>
|
|
2171
|
+
deliverRoot: (message) => managerInbox?.(message) ?? false,
|
|
2172
|
+
deliverRootReady: () => true
|
|
2125
2173
|
},
|
|
2126
2174
|
onError: (error) => {
|
|
2127
2175
|
coordinationLifetime.abort(error);
|
|
@@ -2234,6 +2282,8 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2234
2282
|
if (last?.unavailable !== void 0) throw new CheckUnavailableError(`the completion check could not run: ${last.unavailable}`);
|
|
2235
2283
|
};
|
|
2236
2284
|
const loopRecords = [];
|
|
2285
|
+
let deadlineWarned = false;
|
|
2286
|
+
const managerStartedAt = Date.now();
|
|
2237
2287
|
let environmentReplacements = 0;
|
|
2238
2288
|
let workspaceRestores = 0;
|
|
2239
2289
|
const describe = deps.deliverable?.describe;
|
|
@@ -2296,7 +2346,7 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2296
2346
|
if (completed) await controls.endDriverAttempt("completed");
|
|
2297
2347
|
else await controls.endDriverAttempt("failed").catch(() => void 0);
|
|
2298
2348
|
}
|
|
2299
|
-
if (contractDeclared && !mcp.submittedResult()) {
|
|
2349
|
+
if (contractDeclared && !mcp.submittedResult() && !controls.hasOpenWork()) {
|
|
2300
2350
|
await mcp.drainResolved();
|
|
2301
2351
|
candidate = await finalize();
|
|
2302
2352
|
if (candidate === void 0 && !mcp.isStopped()) await readCheckAtTurnEnd(attempt);
|
|
@@ -2305,6 +2355,35 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2305
2355
|
progress: readProgress,
|
|
2306
2356
|
budget: () => scope.budget,
|
|
2307
2357
|
signal: scope.signal,
|
|
2358
|
+
wait: {
|
|
2359
|
+
open: () => !mcp.submittedResult() && !mcp.isStopped() && progressStopReason === void 0 && controls.hasOpenWork(),
|
|
2360
|
+
wake: async (nextAttempt) => {
|
|
2361
|
+
const deadlineMs = scope.budget.deadlineMs;
|
|
2362
|
+
const warnAt = deadlineWarningAt(deadlineMs, wakePolicy, deadlineWarned, managerStartedAt);
|
|
2363
|
+
waitingOn = scope.view.nodes.filter((node) => node.id !== scope.view.root && isLiveNodeStatus(node.status)).length;
|
|
2364
|
+
try {
|
|
2365
|
+
const wake = await controls.awaitWake({
|
|
2366
|
+
attempt: nextAttempt,
|
|
2367
|
+
signal: AbortSignal.any([scope.signal, stopController.signal]),
|
|
2368
|
+
heartbeatMs: wakePolicy.heartbeatMs,
|
|
2369
|
+
debounceMs: wakePolicy.debounceMs,
|
|
2370
|
+
...warnAt === void 0 ? {} : { deadlineAt: warnAt }
|
|
2371
|
+
});
|
|
2372
|
+
if (wake === void 0 || stopController.signal.aborted) return void 0;
|
|
2373
|
+
if (wake.reason === "deadline") deadlineWarned = true;
|
|
2374
|
+
return {
|
|
2375
|
+
input: composeWakeInput(wake, {
|
|
2376
|
+
tools: runtimeToolNames,
|
|
2377
|
+
deadlineMs,
|
|
2378
|
+
now: Date.now()
|
|
2379
|
+
}),
|
|
2380
|
+
idleMs: wake.idleMs
|
|
2381
|
+
};
|
|
2382
|
+
} finally {
|
|
2383
|
+
waitingOn = void 0;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
},
|
|
2308
2387
|
...deps.driverRetry ? { policy: deps.driverRetry } : {},
|
|
2309
2388
|
...continuation !== void 0 && keeper !== void 0 && continuationDeadlineMs ? { continuation: {
|
|
2310
2389
|
maxBarren: continuation.maxBarren,
|
|
@@ -2372,6 +2451,7 @@ function buildSupervisorAgent(profile, deps, testBrain) {
|
|
|
2372
2451
|
});
|
|
2373
2452
|
throw error;
|
|
2374
2453
|
} finally {
|
|
2454
|
+
managerInbox = void 0;
|
|
2375
2455
|
coordinationLifetime.abort(/* @__PURE__ */ new Error("supervisor manager stopped"));
|
|
2376
2456
|
try {
|
|
2377
2457
|
await controlObserver?.close();
|
|
@@ -2670,9 +2750,6 @@ function interactiveOf(inner) {
|
|
|
2670
2750
|
if (inner.interactive === void 0) throw new ValidationError("retryPreSpawnRefusals: inner executor exposes no interactive session");
|
|
2671
2751
|
return inner.interactive();
|
|
2672
2752
|
}
|
|
2673
|
-
function isAsyncIterable$1(value) {
|
|
2674
|
-
return value !== null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
2675
|
-
}
|
|
2676
2753
|
/** The wait stays REF'd: a worker waiting out a saturated executor is live work, and an unref'd
|
|
2677
2754
|
* timer lets the process exit mid-backoff when nothing else is pending. */
|
|
2678
2755
|
function defaultSleep(ms, signal) {
|
|
@@ -3116,6 +3193,15 @@ async function providerAcceptsCoordinationAttachments(backend) {
|
|
|
3116
3193
|
const attachments = create.runtimeAttachments;
|
|
3117
3194
|
return Boolean(attachments && typeof attachments === "object" && "mcp" in attachments && attachments.mcp === true);
|
|
3118
3195
|
}
|
|
3196
|
+
/**
|
|
3197
|
+
* A manager waits between turns, and a wake can come much later than five minutes after its last
|
|
3198
|
+
* turn. Claude Code 2.1.289 writes its prompt cache with a five-minute lifetime unless this variable
|
|
3199
|
+
* is set; a wake after the cache expired re-writes the manager's whole context, about 140K tokens
|
|
3200
|
+
* per turn on a Discovery root measured 2026-10-05. That root ran on a subscription and already
|
|
3201
|
+
* wrote one-hour entries; the variable makes the hour hold for every claude-code manager, whatever
|
|
3202
|
+
* its credential. A value the caller set wins.
|
|
3203
|
+
*/
|
|
3204
|
+
const CLAUDE_CODE_ONE_HOUR_CACHE = "ENABLE_PROMPT_CACHING_1H";
|
|
3119
3205
|
/** Run a harness-brained manager through the same executor factory as its children. The manager's
|
|
3120
3206
|
* full profile is preserved, the live coordination server is added under one reserved alias, and
|
|
3121
3207
|
* every streamed turn is charged to the manager's scope before it may continue. */
|
|
@@ -3126,18 +3212,46 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3126
3212
|
const baseFactory = createExecutor(boundBackend);
|
|
3127
3213
|
const ownerRuntime = boundBackend.backend === "provider" ? boundBackend.runtime ?? resolveAgentEnvironmentProvider(boundBackend.provider, boundBackend.registry).name : "cli";
|
|
3128
3214
|
let activeExecutor;
|
|
3215
|
+
const driveActivity = createActivityLog();
|
|
3216
|
+
let driveTurns = 0;
|
|
3217
|
+
const noteDriveProgress = (event) => {
|
|
3218
|
+
const at = Date.now();
|
|
3219
|
+
if (event.kind === "tool_call") driveActivity.push({
|
|
3220
|
+
at,
|
|
3221
|
+
kind: "tool",
|
|
3222
|
+
label: event.toolName
|
|
3223
|
+
});
|
|
3224
|
+
else if (event.kind === "tool_result") driveActivity.push({
|
|
3225
|
+
at,
|
|
3226
|
+
kind: "tool",
|
|
3227
|
+
label: event.toolName,
|
|
3228
|
+
status: "ok"
|
|
3229
|
+
});
|
|
3230
|
+
else if (event.kind === "text_delta" || event.kind === "reasoning_delta") {
|
|
3231
|
+
const last = driveActivity.last();
|
|
3232
|
+
if (last === void 0 || last.kind !== "turn" || at - last.at > 3e4) driveActivity.push({
|
|
3233
|
+
at,
|
|
3234
|
+
kind: "turn",
|
|
3235
|
+
label: "model output"
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
};
|
|
3129
3239
|
let managerTranscript;
|
|
3130
3240
|
let managerArtifact;
|
|
3131
3241
|
const drive = async ({ profile, authoredProfile, task, scope, coordinationMcpUrl, coordinationMcpHeaders, stopSignal, coordinationTools, reentry }) => {
|
|
3132
3242
|
managerArtifact = void 0;
|
|
3133
3243
|
const retainedOwner = boundBackend.backend === "provider" ? scopeRetainedOwnerContext(scope) : void 0;
|
|
3134
3244
|
if (retainedOwner && boundBackend.backend === "provider") {
|
|
3135
|
-
bindScopeRetainedOwnerProvider(scope, resolveAgentEnvironmentProvider(boundBackend.provider, boundBackend.registry)
|
|
3245
|
+
bindScopeRetainedOwnerProvider(scope, resolveAgentEnvironmentProvider(boundBackend.provider, boundBackend.registry), boundBackend.workspaceRetention === void 0 ? void 0 : {
|
|
3246
|
+
port: boundBackend.workspaceRetention,
|
|
3247
|
+
profile
|
|
3248
|
+
});
|
|
3136
3249
|
bindScopeRetainedOwnerEnvironmentId(scope, () => {
|
|
3137
3250
|
if (activeExecutor === void 0) return void 0;
|
|
3138
3251
|
const execution = runtimeOwnedExecutorMaterialization(activeExecutor)?.execution;
|
|
3139
3252
|
return execution?.kind === "environment" ? execution.id : void 0;
|
|
3140
3253
|
});
|
|
3254
|
+
await scopeRetainedOwnerTurnEnded(scope);
|
|
3141
3255
|
}
|
|
3142
3256
|
let driveTask = task;
|
|
3143
3257
|
if (reentry !== void 0) {
|
|
@@ -3156,7 +3270,7 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3156
3270
|
return;
|
|
3157
3271
|
}
|
|
3158
3272
|
const initialBudget = scope.budget;
|
|
3159
|
-
if (!(scope.view.inFlight > 0
|
|
3273
|
+
if (!(scope.view.inFlight > 0) && (initialBudget.tokensLeft <= 0 || initialBudget.iterationsLeft <= 0 || initialBudget.usdCapped && initialBudget.usdLeft <= 0 || Object.values(initialBudget.resources ?? {}).some((resource) => !resource.known || resource.remaining <= 0) || initialBudget.deadlineMs > 0 && now() >= initialBudget.deadlineMs)) throw new ValidationError("driveHarnessFromBackend: supervisor budget exhausted");
|
|
3160
3274
|
const canonicalDriverProfile = agentProfileSchema.parse(authoredProfile);
|
|
3161
3275
|
assertNoReservedCoordinationMcpAlias(canonicalDriverProfile, "driveHarnessFromBackend");
|
|
3162
3276
|
const stableCoordinationTools = detachedSnapshot(coordinationTools, "driveHarnessFromBackend coordination tools");
|
|
@@ -3188,6 +3302,7 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3188
3302
|
defaults: {
|
|
3189
3303
|
...boundBackend.defaults ?? {},
|
|
3190
3304
|
env: {
|
|
3305
|
+
...providerDriverProfile.harness === "claude-code" ? { [CLAUDE_CODE_ONE_HOUR_CACHE]: "1" } : {},
|
|
3191
3306
|
...boundBackend.defaults?.env ?? {},
|
|
3192
3307
|
[credentialName]: authorization.slice(7)
|
|
3193
3308
|
},
|
|
@@ -3304,6 +3419,7 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3304
3419
|
runtime: executor.runtime
|
|
3305
3420
|
});
|
|
3306
3421
|
if (retainedOwner) committedOwnerSpend = addSpend(committedOwnerSpend, charge);
|
|
3422
|
+
if (effectiveStopSignal?.aborted === true) return;
|
|
3307
3423
|
const budget = scope.budget;
|
|
3308
3424
|
if (budget.tokensLeft <= 0 || budget.usdCapped && budget.usdLeft <= 0 || Object.values(budget.resources ?? {}).some((resource) => !resource.known || resource.remaining <= 0) || budget.deadlineMs > 0 && now() >= budget.deadlineMs) throw new ValidationError("driveHarnessFromBackend: supervisor budget exhausted");
|
|
3309
3425
|
};
|
|
@@ -3362,6 +3478,7 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3362
3478
|
await retainedOwner.onResult(result);
|
|
3363
3479
|
terminalAccountingCaptured = true;
|
|
3364
3480
|
};
|
|
3481
|
+
const endDrive = retainedOwner ? beginScopeRetainedOwnerDrive(scope) : () => {};
|
|
3365
3482
|
try {
|
|
3366
3483
|
const declaration = runtimeOwnedExecutorMaterialization(executor);
|
|
3367
3484
|
const executionBinding = runtimeOwnedExecutorExecutionBinding(executor);
|
|
@@ -3383,9 +3500,12 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3383
3500
|
for await (const event of run) if (event.kind === "iteration") {
|
|
3384
3501
|
await meterPending();
|
|
3385
3502
|
turns += 1;
|
|
3503
|
+
driveTurns += 1;
|
|
3386
3504
|
if (turnStop !== void 0 && turns >= turnCap && !turnStop.signal.aborted) turnStop.abort(`supervise: maxTurns ${turnCap} reached`);
|
|
3387
|
-
} else if (event.kind === "progress")
|
|
3388
|
-
|
|
3505
|
+
} else if (event.kind === "progress") {
|
|
3506
|
+
rootStream?.append(event.progress);
|
|
3507
|
+
noteDriveProgress(event.progress);
|
|
3508
|
+
} else pendingUsage.push(event);
|
|
3389
3509
|
await meterPending();
|
|
3390
3510
|
const artifact = executor.resultArtifact();
|
|
3391
3511
|
terminalArtifact = artifact;
|
|
@@ -3501,6 +3621,7 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3501
3621
|
const capture = executor.harnessTranscript?.();
|
|
3502
3622
|
if (capture !== void 0 && (capture.status !== "unavailable" || managerTranscript?.status === "unavailable" || managerTranscript === void 0)) managerTranscript = capture;
|
|
3503
3623
|
if (activeExecutor === executor) activeExecutor = void 0;
|
|
3624
|
+
endDrive();
|
|
3504
3625
|
}
|
|
3505
3626
|
if (failed) throw failure;
|
|
3506
3627
|
if (turnFailure !== void 0) throw turnFailure;
|
|
@@ -3514,7 +3635,16 @@ function driveHarnessFromBackend(backend, executionId, now = Date.now, maxTurns,
|
|
|
3514
3635
|
};
|
|
3515
3636
|
drive.deliverReady = () => activeExecutor !== void 0;
|
|
3516
3637
|
drive.traceSource = () => activeExecutor?.traceSource?.();
|
|
3517
|
-
drive.progress = () =>
|
|
3638
|
+
drive.progress = () => {
|
|
3639
|
+
const fromExecutor = activeExecutor?.progress?.();
|
|
3640
|
+
const own = driveActivity.read();
|
|
3641
|
+
const recentActivity = [...fromExecutor?.recentActivity ?? [], ...own].sort((a, b) => a.at - b.at).slice(-12);
|
|
3642
|
+
return {
|
|
3643
|
+
...fromExecutor,
|
|
3644
|
+
turns: Math.max(fromExecutor?.turns ?? 0, driveTurns),
|
|
3645
|
+
...recentActivity.length > 0 ? { recentActivity } : {}
|
|
3646
|
+
};
|
|
3647
|
+
};
|
|
3518
3648
|
if (boundBackend.backend === "provider") {
|
|
3519
3649
|
drive.harnessTranscript = () => managerTranscript ?? activeExecutor?.harnessTranscript?.();
|
|
3520
3650
|
drive.harnessTranscriptSettled = () => activeExecutor?.harnessTranscriptSettled?.() ?? Promise.resolve();
|
|
@@ -3662,7 +3792,6 @@ const superviseOptionKeySet = /* @__PURE__ */ new Set([
|
|
|
3662
3792
|
"peerMail",
|
|
3663
3793
|
"perWorker",
|
|
3664
3794
|
"reservationPolicy",
|
|
3665
|
-
"probes",
|
|
3666
3795
|
"profileGuidance",
|
|
3667
3796
|
"profileSecurity",
|
|
3668
3797
|
"registry",
|
|
@@ -3679,7 +3808,7 @@ const superviseOptionKeySet = /* @__PURE__ */ new Set([
|
|
|
3679
3808
|
"runId",
|
|
3680
3809
|
"signal",
|
|
3681
3810
|
"stallAfterMs",
|
|
3682
|
-
"
|
|
3811
|
+
"wake",
|
|
3683
3812
|
"steerDir",
|
|
3684
3813
|
"stopRule",
|
|
3685
3814
|
"watchWorkers",
|
|
@@ -3769,7 +3898,7 @@ function rootSpawnResourceRoot(backend) {
|
|
|
3769
3898
|
}
|
|
3770
3899
|
function captureSuperviseOptions(opts) {
|
|
3771
3900
|
assertSuperviseOptionKeys(opts, "supervise");
|
|
3772
|
-
const { backend, coordination, driverBackend, deliverable, resolveDeliverable, router, compaction, watchWorkers, analysts, makeWorkerAgent, makeLeafAgent, recoverExecutor, resume, resolveSpawnProfile, blobs, journal, runContext,
|
|
3901
|
+
const { backend, coordination, driverBackend, deliverable, resolveDeliverable, router, compaction, watchWorkers, analysts, makeWorkerAgent, makeLeafAgent, recoverExecutor, resume, resolveSpawnProfile, blobs, journal, runContext, registry, hooks, otel, authorizeSpawn, authorizeMessage, driveHarness, resolveDriveHarness, resolveSupervisorTools, escalateQuestion, onCoordinationEvent, executeExtraTool, stopRule, onProgressStop, onDriverAttempt, continuation, workerRetry, onWorkerRetry, finalizer, now, signal, rootHandle, workerSlots, ...decisionData } = opts;
|
|
3773
3902
|
assertNoUncapturedExecutableOption(decisionData);
|
|
3774
3903
|
const capturedData = detachedSnapshot(decisionData, "supervise options");
|
|
3775
3904
|
const capturedCoordination = coordination === void 0 ? void 0 : (() => {
|
|
@@ -3845,7 +3974,6 @@ function captureSuperviseOptions(opts) {
|
|
|
3845
3974
|
...resume === void 0 ? {} : { resume },
|
|
3846
3975
|
...runContext === void 0 ? {} : { runContext },
|
|
3847
3976
|
...workerSlots === void 0 ? {} : { workerSlots },
|
|
3848
|
-
...probes === void 0 ? {} : { probes },
|
|
3849
3977
|
...authorizeSpawn === void 0 ? {} : { authorizeSpawn },
|
|
3850
3978
|
...authorizeMessage === void 0 ? {} : { authorizeMessage },
|
|
3851
3979
|
...driveHarness === void 0 ? {} : { driveHarness },
|
|
@@ -4128,7 +4256,6 @@ function superviseInternal(profile, task, opts, testBrain) {
|
|
|
4128
4256
|
const deliverable = resolveNamed("deliverable", "deliverables", options.deliverable, options.registry?.deliverables);
|
|
4129
4257
|
const finalizer = resolveNamed("finalizer", "finalizers", options.finalizer, options.registry?.finalizers);
|
|
4130
4258
|
const analysts = resolveNamed("analysts", "analysts", options.analysts, options.registry?.analysts);
|
|
4131
|
-
const probes = resolveNamed("probes", "probes", options.probes, options.registry?.probes);
|
|
4132
4259
|
const profileTable = snapshotProfileTable(options.registry?.profiles, options.allowedModels, options.makeWorkerAgent === void 0 && options.authorizeSpawn === void 0 ? (entry, context) => {
|
|
4133
4260
|
const security = validateAgentProfileSecurity(entry, options.profileSecurity ?? DEFAULT_AUTHORED_PROFILE_SECURITY_POLICY);
|
|
4134
4261
|
if (!security.ok) throw new ValidationError(`${context}: ${security.issues.filter((issue) => issue.level === "error").map((issue) => `${issue.code}${issue.path ? ` at ${issue.path}` : ""}`).join(", ")}`);
|
|
@@ -4324,7 +4451,7 @@ function superviseInternal(profile, task, opts, testBrain) {
|
|
|
4324
4451
|
...!analystLineage && spawnContext.analyst === void 0 && !spawnContext.assignmentId.startsWith("analyst:") && options.analyzeOnSettle ? { analyzeOnSettle: options.analyzeOnSettle } : {},
|
|
4325
4452
|
...options.watchWorkers ? { watchWorkers: options.watchWorkers } : {},
|
|
4326
4453
|
...options.stallAfterMs !== void 0 ? { stallAfterMs: options.stallAfterMs } : {},
|
|
4327
|
-
...options.
|
|
4454
|
+
...options.wake !== void 0 ? { wake: options.wake } : {},
|
|
4328
4455
|
...options.continuityByProfile ? { continuityByProfile: options.continuityByProfile } : {},
|
|
4329
4456
|
...spawnPreflight ? { preflightSpawn: spawnPreflight } : {},
|
|
4330
4457
|
...options.resolveSpawnProfile ? { resolveSpawnProfile: options.resolveSpawnProfile } : {},
|
|
@@ -4447,7 +4574,7 @@ function superviseInternal(profile, task, opts, testBrain) {
|
|
|
4447
4574
|
...options.analyzeOnSettle ? { analyzeOnSettle: options.analyzeOnSettle } : {},
|
|
4448
4575
|
...options.watchWorkers ? { watchWorkers: options.watchWorkers } : {},
|
|
4449
4576
|
...options.stallAfterMs !== void 0 ? { stallAfterMs: options.stallAfterMs } : {},
|
|
4450
|
-
...options.
|
|
4577
|
+
...options.wake !== void 0 ? { wake: options.wake } : {},
|
|
4451
4578
|
...options.continuityByProfile ? { continuityByProfile: options.continuityByProfile } : {},
|
|
4452
4579
|
...options.stopRule ? { stopRule: stopRuleOf(options.stopRule) } : {},
|
|
4453
4580
|
...options.onProgressStop ? { onProgressStop: options.onProgressStop } : {},
|
|
@@ -4509,7 +4636,6 @@ function superviseInternal(profile, task, opts, testBrain) {
|
|
|
4509
4636
|
ownerWorkspaceRetention: managerBackend?.backend === "provider" && managerBackend.workspaceRetention !== void 0,
|
|
4510
4637
|
...options.workerSlots !== void 0 ? { workerSlots: options.workerSlots } : {},
|
|
4511
4638
|
...options.reservationPolicy ? { reservationPolicy: options.reservationPolicy } : {},
|
|
4512
|
-
...probes ? { probes } : {},
|
|
4513
4639
|
...ctx.resume === true || options.runDir === void 0 && options.resume === true ? { resume: true } : {},
|
|
4514
4640
|
...options.now ? { now: options.now } : {},
|
|
4515
4641
|
signal: options.signal ? AbortSignal.any([options.signal, durableCancellation.signal]) : durableCancellation.signal,
|
|
@@ -4588,4 +4714,4 @@ function rootProviderModelEvidenceFromExecution(evidence) {
|
|
|
4588
4714
|
//#endregion
|
|
4589
4715
|
export { gateOnDeliverable as C, serveCoordinationMcp as S, readRootStream as _, superviseWithTestBrain as a, composeReentryTask as b, resolveWorkerSpawnRetry as c, assertCoordinationBinding as d, coordinationProfileToolPrefix as f, ROOT_STREAM_FILE as g, supervisorAgentWithTestBrain as h, superviseRootProfile as i, retryPreSpawnRefusals as l, supervisorAgent as m, profileGuidanceComposer as n, workerFromBackend as o, resolveSupervisorProfile as p, supervise as r, isPreSpawnExecutorFailure as s, DEFAULT_AUTHORED_PROFILE_SECURITY_POLICY as t, withWorkerSpawnRetry as u, readRootStreamReceipt as v, mapExecutorResult as w, createSupervisorSpanRecorder as x, UNPROVEN_CONTINUITY as y };
|
|
4590
4716
|
|
|
4591
|
-
//# sourceMappingURL=supervise-
|
|
4717
|
+
//# sourceMappingURL=supervise-DllOHM4M.js.map
|