@tangle-network/agent-runtime 9.0.10 → 9.0.11
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/CHANGELOG.md +12 -0
- package/dist/{activation-BuKAzxZB.js → activation-B_10QJ3D.js} +2 -2
- package/dist/{activation-BuKAzxZB.js.map → activation-B_10QJ3D.js.map} +1 -1
- package/dist/{activation-CVVpVGyG.d.ts → activation-emYXDX7T.d.ts} +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/{coordination-manager-B-Ugh18D.js → coordination-manager-BUct8qFe.js} +2 -2
- package/dist/{coordination-manager-B-Ugh18D.js.map → coordination-manager-BUct8qFe.js.map} +1 -1
- package/dist/{delegate-Dizy-1ZC.js → delegate-DHtsLCyr.js} +2 -2
- package/dist/{delegate-Dizy-1ZC.js.map → delegate-DHtsLCyr.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +4 -4
- package/dist/{graph-Bf3axJxp.js → graph-D6KJ6wxN.js} +35 -12
- package/dist/graph-D6KJ6wxN.js.map +1 -0
- package/dist/{improve-JThdxpGB.js → improve-CUqmH45C.js} +5 -5
- package/dist/{improve-JThdxpGB.js.map → improve-CUqmH45C.js.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +3 -3
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +10 -10
- package/dist/{loop-runner-D8FP4oEN.js → loop-runner-CCeBurqG.js} +2 -2
- package/dist/{loop-runner-D8FP4oEN.js.map → loop-runner-CCeBurqG.js.map} +1 -1
- package/dist/{loop-runner-40_tD2d4.d.ts → loop-runner-Q9nlHcEH.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +2 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +4 -4
- package/dist/profiles.d.ts +1 -1
- package/dist/{provision-supervisor-BDAXc65B.js → provision-supervisor-CNTBbuDV.js} +3 -3
- package/dist/{provision-supervisor-BDAXc65B.js.map → provision-supervisor-CNTBbuDV.js.map} +1 -1
- package/dist/{run-state-9FP-wBWK.js → run-state-C0nr4O7P.js} +2 -2
- package/dist/{run-state-9FP-wBWK.js.map → run-state-C0nr4O7P.js.map} +1 -1
- package/dist/{runtime-Czu2SSMy.js → runtime-C5yB7Vkk.js} +10 -10
- package/dist/{runtime-Czu2SSMy.js.map → runtime-C5yB7Vkk.js.map} +1 -1
- package/dist/{search-executor-Dl_WUQeH.js → search-executor-BgEY5MKQ.js} +2 -2
- package/dist/{search-executor-Dl_WUQeH.js.map → search-executor-BgEY5MKQ.js.map} +1 -1
- package/dist/{server-Dbge7VDj.js → server-X67SS4r8.js} +2 -2
- package/dist/{server-Dbge7VDj.js.map → server-X67SS4r8.js.map} +1 -1
- package/dist/{structural-rollout-DUMYWwZ3.js → structural-rollout-BSzN8a0T.js} +2 -2
- package/dist/{structural-rollout-DUMYWwZ3.js.map → structural-rollout-BSzN8a0T.js.map} +1 -1
- package/dist/{supervise-BpcWjDMr.js → supervise-RJG2ruTF.js} +180 -203
- package/dist/supervise-RJG2ruTF.js.map +1 -0
- package/dist/{supervisor-CdrDXnOJ.js → supervisor-DbtgkJyr.js} +16 -5
- package/dist/supervisor-DbtgkJyr.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +11 -11
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{types-DRijOelA.d.ts → types-DMqr8Tmx.d.ts} +17 -3
- package/package.json +1 -1
- package/dist/graph-Bf3axJxp.js.map +0 -1
- package/dist/supervise-BpcWjDMr.js.map +0 -1
- package/dist/supervisor-CdrDXnOJ.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { f as RuntimeRunStateError, i as ConfigError, m as ValidationError } from "./errors-DG8yufqX.js";
|
|
2
|
-
import { c as createSteerAcknowledger, d as coordinationVerbNames, f as createFileRunContext, l as budgetOverspendText, m as withRunContext, n as createCoordinationToolsForManager, p as createInMemoryRunContext, s as createCancelAcknowledger, t as createCoordinationTools, u as normalizeAnalyzeOnSettle } from "./coordination-manager-
|
|
3
|
-
import { B as toolResultText, C as captureReusableExecutorConfig, Ct as bridgeModelRouteRefusal, Gt as promptControlProfileMaterialization, H as routerBrain, Ht as defineProfileMaterializationContract, I as codeModeArguments, Kt as promptModelProfileMaterialization, L as codeModeModelOutput, Mt as bridgeStopSignalKey, R as createCodeModeTools, S as bindReusableExecutorExecutionId, St as bridgeAdmissionRefusal, T as snapshotExecutorConfig, Ut as fullProfileMaterialization, V as createRouterTranscript, Vt as controlProfileMaterialization, W as resolveAgentEnvironmentProvider, Wt as profileMaterializationAxes$1, X as INBOX_RECEIPT_KEY, Xt as unsupportedProfileDimensions, Yt as sandboxProfileMaterialization, Z as createInbox, Zt as worktreeCliProfileMaterialization, _ as isDriverSpec, _t as CheckUnavailableError, a as assertRunParking, ct as DriverAttemptsExhaustedError, d as bestDelivered, dt as classifyDriverFailure, f as runFinalizer, ft as summarizeDriverAttempts, g as driverExecutorFactory, gt as preflightPublicCoordination, h as driverChild, ht as upstreamUnavailableSignal, i as RunParkedError, it as isPeerMailEnvelope, jt as bridgeRuntimeAttachmentsKey, l as sleepScopeWait, lt as HarnessTurnFailedError, m as createRootHandle, mt as undispatchedCredentialExit, n as createSupervisor, o as bindScopeParkingDrain, p as runTree, pt as transientFailureKind, qt as renderUnsupported, s as isRunParked, tt as PEER_MAIL_WIRE_KEY, u as withRunParking, ut as abandonablePending, vt as gateFactoryOnDeliverable, w as createExecutor, zt as assertProfileMaterialization } from "./supervisor-
|
|
2
|
+
import { c as createSteerAcknowledger, d as coordinationVerbNames, f as createFileRunContext, l as budgetOverspendText, m as withRunContext, n as createCoordinationToolsForManager, p as createInMemoryRunContext, s as createCancelAcknowledger, t as createCoordinationTools, u as normalizeAnalyzeOnSettle } from "./coordination-manager-BUct8qFe.js";
|
|
3
|
+
import { B as toolResultText, C as captureReusableExecutorConfig, Ct as bridgeModelRouteRefusal, Gt as promptControlProfileMaterialization, H as routerBrain, Ht as defineProfileMaterializationContract, I as codeModeArguments, Kt as promptModelProfileMaterialization, L as codeModeModelOutput, Mt as bridgeStopSignalKey, R as createCodeModeTools, S as bindReusableExecutorExecutionId, St as bridgeAdmissionRefusal, T as snapshotExecutorConfig, Ut as fullProfileMaterialization, V as createRouterTranscript, Vt as controlProfileMaterialization, W as resolveAgentEnvironmentProvider, Wt as profileMaterializationAxes$1, X as INBOX_RECEIPT_KEY, Xt as unsupportedProfileDimensions, Yt as sandboxProfileMaterialization, Z as createInbox, Zt as worktreeCliProfileMaterialization, _ as isDriverSpec, _t as CheckUnavailableError, a as assertRunParking, ct as DriverAttemptsExhaustedError, d as bestDelivered, dt as classifyDriverFailure, f as runFinalizer, ft as summarizeDriverAttempts, g as driverExecutorFactory, gt as preflightPublicCoordination, h as driverChild, ht as upstreamUnavailableSignal, i as RunParkedError, it as isPeerMailEnvelope, jt as bridgeRuntimeAttachmentsKey, l as sleepScopeWait, lt as HarnessTurnFailedError, m as createRootHandle, mt as undispatchedCredentialExit, n as createSupervisor, o as bindScopeParkingDrain, p as runTree, pt as transientFailureKind, qt as renderUnsupported, s as isRunParked, tt as PEER_MAIL_WIRE_KEY, u as withRunParking, ut as abandonablePending, vt as gateFactoryOnDeliverable, w as createExecutor, zt as assertProfileMaterialization } from "./supervisor-DbtgkJyr.js";
|
|
4
4
|
import { _ as workerAssignmentNamespace, c as writeRunCancellation, d as coordinationEventId, f as externalExecutionId, g as supervisionRunNamespace, h as rootCoordinationOwner, i as readRunCancellation, l as canonicalExecution, m as freezeDetachedProfile, p as freezeDetached, r as readRunCancelRequest, s as watchRunCancellation, t as applyRunCancellation, u as childCoordinationOwner } from "./run-cancellation-Cy9ie5cQ.js";
|
|
5
5
|
import { a as errMessage, c as errorStack, i as causeChain, l as errorText, n as detachedSnapshot, o as errorHttpStatus, u as defaultRedactor } from "./snapshot-BKI_w3JD.js";
|
|
6
6
|
import { t as composeRuntimeHooks } from "./runtime-hooks-CsW2pfFk.js";
|
|
@@ -85,6 +85,7 @@ const superviseOptionKeySet = /* @__PURE__ */ new Set([
|
|
|
85
85
|
"resolveDriveHarness",
|
|
86
86
|
"resolveSpawnProfile",
|
|
87
87
|
"resolveSupervisorTools",
|
|
88
|
+
"servesToolNames",
|
|
88
89
|
"rootDriverFromBackend",
|
|
89
90
|
"rootHandle",
|
|
90
91
|
"router",
|
|
@@ -3295,6 +3296,172 @@ var DriverBrainTurns = class {
|
|
|
3295
3296
|
for (const lease of this.leases.splice(0)) lease.release();
|
|
3296
3297
|
}
|
|
3297
3298
|
};
|
|
3299
|
+
// src/runtime/supervise/single-flight-tools.ts
|
|
3300
|
+
/**
|
|
3301
|
+
* Serve method-supplied supervisor tools on the coordination MCP as single-flight, fenced calls.
|
|
3302
|
+
*
|
|
3303
|
+
* A method tool can run for hours: a literature graph spawns and joins its own children inside one
|
|
3304
|
+
* call. The coordination transport answers 504 at `requestTimeoutMs`, so an unwrapped long call
|
|
3305
|
+
* reaches the caller as a hard tool error while its handler keeps running. A caller that retries
|
|
3306
|
+
* starts a second full run. Run mech-interp-foundations-glm2-20260911d spawned the same enumerate
|
|
3307
|
+
* and extract children twice this way.
|
|
3308
|
+
*
|
|
3309
|
+
* Two rules close that failure:
|
|
3310
|
+
* - Identity. A call joins an existing invocation when its tool name and its RFC 8785 canonical
|
|
3311
|
+
* arguments match, and that invocation has not yet settled. The handler is not invoked again.
|
|
3312
|
+
* Key order does not matter: the observed retry reordered every key.
|
|
3313
|
+
* - Fence. A call waits at most `fenceMs` for the outcome. If the handler is still running, the
|
|
3314
|
+
* call returns a receipt. The handler keeps running, and its outcome is published to the
|
|
3315
|
+
* manager's inbox, where its next wake delivers it. Nothing has to call again to collect it.
|
|
3316
|
+
*
|
|
3317
|
+
* An invocation's identity ends when its handler settles. The next identical call is a fresh run,
|
|
3318
|
+
* because equal arguments do not make a call a replay: code mode's `execute` and Knowledge's
|
|
3319
|
+
* `knowledge_search` read live state, so their callers repeat identical arguments to get a current
|
|
3320
|
+
* answer. A handler that finishes within the fence therefore behaves exactly as it did unwrapped.
|
|
3321
|
+
*/
|
|
3322
|
+
function singleFlightTools(tools, options) {
|
|
3323
|
+
const { fenceMs, receipts } = options;
|
|
3324
|
+
if (!Number.isSafeInteger(fenceMs) || fenceMs <= 0) throw new ValidationError("singleFlightTools: fenceMs must be a positive safe integer");
|
|
3325
|
+
const now = options.now ?? Date.now;
|
|
3326
|
+
const invocations = /* @__PURE__ */ new Map();
|
|
3327
|
+
const start = (tool, raw, key) => {
|
|
3328
|
+
const invocation = {
|
|
3329
|
+
startedAt: now(),
|
|
3330
|
+
settled: (async () => tool.handler(raw))().then((value) => {
|
|
3331
|
+
invocation.outcome = {
|
|
3332
|
+
ok: true,
|
|
3333
|
+
value
|
|
3334
|
+
};
|
|
3335
|
+
return invocation.outcome;
|
|
3336
|
+
}, (error) => {
|
|
3337
|
+
invocation.outcome = {
|
|
3338
|
+
ok: false,
|
|
3339
|
+
error
|
|
3340
|
+
};
|
|
3341
|
+
return invocation.outcome;
|
|
3342
|
+
}),
|
|
3343
|
+
outcome: void 0,
|
|
3344
|
+
waiting: 0,
|
|
3345
|
+
receipt: void 0
|
|
3346
|
+
};
|
|
3347
|
+
invocation.settled.then(async (outcome) => {
|
|
3348
|
+
if (invocations.get(key) === invocation) invocations.delete(key);
|
|
3349
|
+
if (invocation.receipt !== void 0) await receipts.settleToolReceipt(invocation.receipt, outcome).catch((error) => {
|
|
3350
|
+
console.error("Runtime could not publish a receipted tool outcome", {
|
|
3351
|
+
tool: tool.name,
|
|
3352
|
+
receipt: invocation.receipt,
|
|
3353
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3354
|
+
});
|
|
3355
|
+
});
|
|
3356
|
+
});
|
|
3357
|
+
return invocation;
|
|
3358
|
+
};
|
|
3359
|
+
const wrap = (tool) => Object.freeze({
|
|
3360
|
+
...tool,
|
|
3361
|
+
handler: async (raw) => {
|
|
3362
|
+
const key = invocationKey(tool.name, raw);
|
|
3363
|
+
let invocation = invocations.get(key);
|
|
3364
|
+
if (invocation === void 0) {
|
|
3365
|
+
invocation = start(tool, raw, key);
|
|
3366
|
+
invocations.set(key, invocation);
|
|
3367
|
+
}
|
|
3368
|
+
if (invocation.outcome === void 0) {
|
|
3369
|
+
invocation.waiting++;
|
|
3370
|
+
try {
|
|
3371
|
+
await withTimeout(invocation.settled, fenceMs);
|
|
3372
|
+
} finally {
|
|
3373
|
+
invocation.waiting--;
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
const outcome = invocation.outcome;
|
|
3377
|
+
if (outcome === void 0) {
|
|
3378
|
+
invocation.receipt ??= receipts.openToolReceipt(tool.name);
|
|
3379
|
+
return toolCallReceipt(tool.name, invocation.receipt, now() - invocation.startedAt);
|
|
3380
|
+
}
|
|
3381
|
+
if (outcome.ok) return outcome.value;
|
|
3382
|
+
throw outcome.error;
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
return {
|
|
3386
|
+
tools: Object.freeze(tools.map(wrap)),
|
|
3387
|
+
background() {
|
|
3388
|
+
let count = 0;
|
|
3389
|
+
for (const invocation of invocations.values()) if (invocation.outcome === void 0 && invocation.waiting === 0) count++;
|
|
3390
|
+
return count;
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
}
|
|
3394
|
+
function invocationKey(name, raw) {
|
|
3395
|
+
try {
|
|
3396
|
+
return canonicalCandidateJson([name, raw]);
|
|
3397
|
+
} catch (error) {
|
|
3398
|
+
throw new ValidationError(`${name}: arguments must be finite JSON so a repeated call can join its earlier run`, { cause: error });
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
function toolCallReceipt(tool, receipt, elapsedMs) {
|
|
3402
|
+
return {
|
|
3403
|
+
running: true,
|
|
3404
|
+
receipt,
|
|
3405
|
+
tool,
|
|
3406
|
+
elapsedMs,
|
|
3407
|
+
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.`
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
// src/runtime/supervise/coordination-mcp-tools.ts
|
|
3411
|
+
/** `submit_result` runs an injected deliverable's check inside its request (src/mcp/tools/coordination.ts
|
|
3412
|
+
* builds it exactly then) and `spawn_worker` reads by-path resources out of the manager's workspace
|
|
3413
|
+
* first, so either can outlast one request and both are served like `nodeTools`. */
|
|
3414
|
+
const DELIVERABLE_VERB = "submit_result";
|
|
3415
|
+
const FENCED_VERBS = /* @__PURE__ */ new Set([DELIVERABLE_VERB, "spawn_worker"]);
|
|
3416
|
+
/** The options the coordination tools are built from; `resolveProbeTool` binds `report_blocked` to
|
|
3417
|
+
* what this manager was granted. */
|
|
3418
|
+
function coordinationToolOptions(opts, ownerReader, resolveProbeTool) {
|
|
3419
|
+
const { identity, nodeTools, toolNames, onCoordinationTools, peerMail, preflightSpawn, ...rest } = opts;
|
|
3420
|
+
return {
|
|
3421
|
+
...rest,
|
|
3422
|
+
resolveProbeTool,
|
|
3423
|
+
...preflightSpawn ? { preflightSpawn } : {},
|
|
3424
|
+
...ownerReader ? { spawnResourceReader: ownerReader } : {},
|
|
3425
|
+
...peerMail ? { peerMail: typeof peerMail === "object" ? { ...peerMail } : {} } : {}
|
|
3426
|
+
};
|
|
3427
|
+
}
|
|
3428
|
+
/** Refuse absent names before a root turn or a child admission with a declared vocabulary. */
|
|
3429
|
+
function unservedToolsRefusal(requested, served) {
|
|
3430
|
+
const missing = requested.filter((name) => !served.includes(name));
|
|
3431
|
+
if (missing.length === 0) return void 0;
|
|
3432
|
+
return `requested tools ${missing.map((n) => JSON.stringify(n)).join(", ")} are unavailable; served: ${served.join(", ")}`;
|
|
3433
|
+
}
|
|
3434
|
+
/**
|
|
3435
|
+
* The granted tools in the order `opts.toolNames` names them, and the count of calls still running
|
|
3436
|
+
* behind a fence. An unknown, duplicated or shadowing name fails before the listener opens.
|
|
3437
|
+
*/
|
|
3438
|
+
function bindServedTools(opts, coord, fenceMs) {
|
|
3439
|
+
const reservedNames = new Set(coord.tools.map((tool) => tool.name));
|
|
3440
|
+
for (const tool of opts.nodeTools ?? []) {
|
|
3441
|
+
if (reservedNames.has(tool.name)) throw new ValidationError(`serveCoordinationMcp: node tool ${JSON.stringify(tool.name)} shadows a coordination verb or another node tool`);
|
|
3442
|
+
reservedNames.add(tool.name);
|
|
3443
|
+
}
|
|
3444
|
+
const nodeTools = singleFlightTools(opts.nodeTools ?? [], {
|
|
3445
|
+
fenceMs,
|
|
3446
|
+
receipts: coord
|
|
3447
|
+
});
|
|
3448
|
+
const fencedVerbs = singleFlightTools(coord.tools.filter((tool) => FENCED_VERBS.has(tool.name)), {
|
|
3449
|
+
fenceMs,
|
|
3450
|
+
receipts: coord
|
|
3451
|
+
});
|
|
3452
|
+
if (opts.deliverable && !fencedVerbs.tools.some((tool) => tool.name === DELIVERABLE_VERB)) throw new ValidationError(`serveCoordinationMcp: a deliverable is injected but the coordination verbs lack ${DELIVERABLE_VERB}, so its check would run unfenced`);
|
|
3453
|
+
const fencedByName = new Map(fencedVerbs.tools.map((tool) => [tool.name, tool]));
|
|
3454
|
+
const availableByName = new Map([...coord.tools.map((tool) => fencedByName.get(tool.name) ?? tool), ...nodeTools.tools].map((tool) => [tool.name, tool]));
|
|
3455
|
+
if (!Array.isArray(opts.toolNames)) throw new ValidationError("serveCoordinationMcp: toolNames must name every granted tool explicitly");
|
|
3456
|
+
const selectedNames = opts.toolNames;
|
|
3457
|
+
if (new Set(selectedNames).size !== selectedNames.length) throw new ValidationError("serveCoordinationMcp: toolNames contains a duplicate name");
|
|
3458
|
+
const refusal = unservedToolsRefusal(selectedNames, [...availableByName.keys()]);
|
|
3459
|
+
if (refusal !== void 0) throw new ValidationError(`serveCoordinationMcp: ${refusal}`);
|
|
3460
|
+
return {
|
|
3461
|
+
servedTools: selectedNames.map((name) => availableByName.get(name)),
|
|
3462
|
+
background: () => nodeTools.background() + fencedVerbs.background()
|
|
3463
|
+
};
|
|
3464
|
+
}
|
|
3298
3465
|
// src/runtime/supervise/driver-tool-surface.ts
|
|
3299
3466
|
/** Mount this manager's coordination tools over `scope` and select exactly the granted tools. */
|
|
3300
3467
|
async function openDriverToolSurface(opts, scope) {
|
|
@@ -3338,17 +3505,18 @@ async function openDriverToolSurface(opts, scope) {
|
|
|
3338
3505
|
const availableTools = [...coord.tools, ...opts.nodeTools ?? []];
|
|
3339
3506
|
const availableByName = new Map(availableTools.map((tool) => [tool.name, tool]));
|
|
3340
3507
|
const extraByName = new Map((opts.extraTools ?? []).map((tool) => [tool.name, tool]));
|
|
3508
|
+
const served = [...availableByName.keys(), ...extraByName.keys()];
|
|
3509
|
+
const refusal = unservedToolsRefusal(opts.toolNames, served);
|
|
3510
|
+
if (refusal !== void 0) throw new ValidationError(`driverAgent: ${refusal}`);
|
|
3341
3511
|
const selectedTools = opts.toolNames.map((name) => {
|
|
3342
3512
|
const descriptor = availableByName.get(name);
|
|
3343
3513
|
if (descriptor !== void 0) return {
|
|
3344
3514
|
kind: "descriptor",
|
|
3345
3515
|
descriptor
|
|
3346
3516
|
};
|
|
3347
|
-
const extra = extraByName.get(name);
|
|
3348
|
-
if (extra === void 0) throw new ValidationError(`driverAgent: requested tool ${JSON.stringify(name)} is unavailable`);
|
|
3349
3517
|
return {
|
|
3350
3518
|
kind: "extra",
|
|
3351
|
-
extra
|
|
3519
|
+
extra: extraByName.get(name)
|
|
3352
3520
|
};
|
|
3353
3521
|
});
|
|
3354
3522
|
const modelTools = selectedTools.flatMap((selected) => selected.kind === "descriptor" ? [selected.descriptor] : []);
|
|
@@ -4164,198 +4332,6 @@ function createCoordinationListener(ctx, bound) {
|
|
|
4164
4332
|
return mainHandler(req, res);
|
|
4165
4333
|
});
|
|
4166
4334
|
}
|
|
4167
|
-
// src/runtime/supervise/single-flight-tools.ts
|
|
4168
|
-
/**
|
|
4169
|
-
* Serve method-supplied supervisor tools on the coordination MCP as single-flight, fenced calls.
|
|
4170
|
-
*
|
|
4171
|
-
* A method tool can run for hours: a literature graph spawns and joins its own children inside one
|
|
4172
|
-
* call. The coordination transport answers 504 at `requestTimeoutMs`, so an unwrapped long call
|
|
4173
|
-
* reaches the caller as a hard tool error while its handler keeps running. A caller that retries
|
|
4174
|
-
* starts a second full run. Run mech-interp-foundations-glm2-20260911d spawned the same enumerate
|
|
4175
|
-
* and extract children twice this way.
|
|
4176
|
-
*
|
|
4177
|
-
* Two rules close that failure:
|
|
4178
|
-
* - Identity. A call joins an existing invocation when its tool name and its RFC 8785 canonical
|
|
4179
|
-
* arguments match, and that invocation has not yet settled. The handler is not invoked again.
|
|
4180
|
-
* Key order does not matter: the observed retry reordered every key.
|
|
4181
|
-
* - Fence. A call waits at most `fenceMs` for the outcome. If the handler is still running, the
|
|
4182
|
-
* call returns a receipt. The handler keeps running, and its outcome is published to the
|
|
4183
|
-
* manager's inbox, where its next wake delivers it. Nothing has to call again to collect it.
|
|
4184
|
-
*
|
|
4185
|
-
* An invocation's identity ends when its handler settles. The next identical call is a fresh run,
|
|
4186
|
-
* because equal arguments do not make a call a replay: code mode's `execute` and Knowledge's
|
|
4187
|
-
* `knowledge_search` read live state, so their callers repeat identical arguments to get a current
|
|
4188
|
-
* answer. A handler that finishes within the fence therefore behaves exactly as it did unwrapped.
|
|
4189
|
-
*/
|
|
4190
|
-
function singleFlightTools(tools, options) {
|
|
4191
|
-
const { fenceMs, receipts } = options;
|
|
4192
|
-
if (!Number.isSafeInteger(fenceMs) || fenceMs <= 0) throw new ValidationError("singleFlightTools: fenceMs must be a positive safe integer");
|
|
4193
|
-
const now = options.now ?? Date.now;
|
|
4194
|
-
const invocations = /* @__PURE__ */ new Map();
|
|
4195
|
-
const start = (tool, raw, key) => {
|
|
4196
|
-
const invocation = {
|
|
4197
|
-
startedAt: now(),
|
|
4198
|
-
settled: (async () => tool.handler(raw))().then((value) => {
|
|
4199
|
-
invocation.outcome = {
|
|
4200
|
-
ok: true,
|
|
4201
|
-
value
|
|
4202
|
-
};
|
|
4203
|
-
return invocation.outcome;
|
|
4204
|
-
}, (error) => {
|
|
4205
|
-
invocation.outcome = {
|
|
4206
|
-
ok: false,
|
|
4207
|
-
error
|
|
4208
|
-
};
|
|
4209
|
-
return invocation.outcome;
|
|
4210
|
-
}),
|
|
4211
|
-
outcome: void 0,
|
|
4212
|
-
waiting: 0,
|
|
4213
|
-
receipt: void 0
|
|
4214
|
-
};
|
|
4215
|
-
invocation.settled.then(async (outcome) => {
|
|
4216
|
-
if (invocations.get(key) === invocation) invocations.delete(key);
|
|
4217
|
-
if (invocation.receipt !== void 0) await receipts.settleToolReceipt(invocation.receipt, outcome).catch((error) => {
|
|
4218
|
-
console.error("Runtime could not publish a receipted tool outcome", {
|
|
4219
|
-
tool: tool.name,
|
|
4220
|
-
receipt: invocation.receipt,
|
|
4221
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4222
|
-
});
|
|
4223
|
-
});
|
|
4224
|
-
});
|
|
4225
|
-
return invocation;
|
|
4226
|
-
};
|
|
4227
|
-
const wrap = (tool) => Object.freeze({
|
|
4228
|
-
...tool,
|
|
4229
|
-
handler: async (raw) => {
|
|
4230
|
-
const key = invocationKey(tool.name, raw);
|
|
4231
|
-
let invocation = invocations.get(key);
|
|
4232
|
-
if (invocation === void 0) {
|
|
4233
|
-
invocation = start(tool, raw, key);
|
|
4234
|
-
invocations.set(key, invocation);
|
|
4235
|
-
}
|
|
4236
|
-
if (invocation.outcome === void 0) {
|
|
4237
|
-
invocation.waiting++;
|
|
4238
|
-
try {
|
|
4239
|
-
await withTimeout(invocation.settled, fenceMs);
|
|
4240
|
-
} finally {
|
|
4241
|
-
invocation.waiting--;
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
const outcome = invocation.outcome;
|
|
4245
|
-
if (outcome === void 0) {
|
|
4246
|
-
invocation.receipt ??= receipts.openToolReceipt(tool.name);
|
|
4247
|
-
return toolCallReceipt(tool.name, invocation.receipt, now() - invocation.startedAt);
|
|
4248
|
-
}
|
|
4249
|
-
if (outcome.ok) return outcome.value;
|
|
4250
|
-
throw outcome.error;
|
|
4251
|
-
}
|
|
4252
|
-
});
|
|
4253
|
-
return {
|
|
4254
|
-
tools: Object.freeze(tools.map(wrap)),
|
|
4255
|
-
background() {
|
|
4256
|
-
let count = 0;
|
|
4257
|
-
for (const invocation of invocations.values()) if (invocation.outcome === void 0 && invocation.waiting === 0) count++;
|
|
4258
|
-
return count;
|
|
4259
|
-
}
|
|
4260
|
-
};
|
|
4261
|
-
}
|
|
4262
|
-
function invocationKey(name, raw) {
|
|
4263
|
-
try {
|
|
4264
|
-
return canonicalCandidateJson([name, raw]);
|
|
4265
|
-
} catch (error) {
|
|
4266
|
-
throw new ValidationError(`${name}: arguments must be finite JSON so a repeated call can join its earlier run`, { cause: error });
|
|
4267
|
-
}
|
|
4268
|
-
}
|
|
4269
|
-
function toolCallReceipt(tool, receipt, elapsedMs) {
|
|
4270
|
-
return {
|
|
4271
|
-
running: true,
|
|
4272
|
-
receipt,
|
|
4273
|
-
tool,
|
|
4274
|
-
elapsedMs,
|
|
4275
|
-
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.`
|
|
4276
|
-
};
|
|
4277
|
-
}
|
|
4278
|
-
// src/runtime/supervise/coordination-mcp-tools.ts
|
|
4279
|
-
/**
|
|
4280
|
-
* Which tools one coordination server serves: the options its coordination tools are built from,
|
|
4281
|
-
* and the granted subset of coordination verbs and node tools, fenced and single-flight.
|
|
4282
|
-
*/
|
|
4283
|
-
/** `submit_result` runs an injected deliverable's check inside its request (src/mcp/tools/coordination.ts
|
|
4284
|
-
* builds it exactly then) and `spawn_worker` reads by-path resources out of the manager's workspace
|
|
4285
|
-
* first, so either can outlast one request and both are served like `nodeTools`. */
|
|
4286
|
-
const DELIVERABLE_VERB = "submit_result";
|
|
4287
|
-
const FENCED_VERBS = /* @__PURE__ */ new Set([DELIVERABLE_VERB, "spawn_worker"]);
|
|
4288
|
-
/** The options the coordination tools are built from; `resolveProbeTool` binds `report_blocked` to
|
|
4289
|
-
* what this manager was granted. */
|
|
4290
|
-
function coordinationToolOptions(opts, ownerReader, resolveProbeTool) {
|
|
4291
|
-
return {
|
|
4292
|
-
resolveProbeTool,
|
|
4293
|
-
scope: opts.scope,
|
|
4294
|
-
blobs: opts.blobs,
|
|
4295
|
-
makeWorkerAgent: opts.makeWorkerAgent,
|
|
4296
|
-
...opts.graphs ? { graphs: opts.graphs } : {},
|
|
4297
|
-
...opts.authorizeDownMessage ? { authorizeDownMessage: opts.authorizeDownMessage } : {},
|
|
4298
|
-
perWorker: opts.perWorker,
|
|
4299
|
-
...opts.deliverable ? { deliverable: opts.deliverable } : {},
|
|
4300
|
-
...opts.readContinuation ? { readContinuation: opts.readContinuation } : {},
|
|
4301
|
-
...opts.onStop ? { onStop: opts.onStop } : {},
|
|
4302
|
-
...opts.analysts ? { analysts: opts.analysts } : {},
|
|
4303
|
-
...opts.analyzeOnSettle ? { analyzeOnSettle: opts.analyzeOnSettle } : {},
|
|
4304
|
-
...opts.mapOnSettle ? { mapOnSettle: opts.mapOnSettle } : {},
|
|
4305
|
-
...opts.sourceEvidenceRefs ? { sourceEvidenceRefs: opts.sourceEvidenceRefs } : {},
|
|
4306
|
-
...opts.peerAudit ? { peerAudit: opts.peerAudit } : {},
|
|
4307
|
-
...opts.watchWorkers ? { watchWorkers: opts.watchWorkers } : {},
|
|
4308
|
-
...opts.stallAfterMs !== void 0 ? { stallAfterMs: opts.stallAfterMs } : {},
|
|
4309
|
-
...opts.continuityByProfile ? { continuityByProfile: opts.continuityByProfile } : {},
|
|
4310
|
-
...opts.onEvent ? { onEvent: opts.onEvent } : {},
|
|
4311
|
-
...opts.replaySettlements ? { replaySettlements: true } : {},
|
|
4312
|
-
...opts.questionPolicy ? { questionPolicy: opts.questionPolicy } : {},
|
|
4313
|
-
...opts.escalateQuestion ? { escalateQuestion: opts.escalateQuestion } : {},
|
|
4314
|
-
...opts.onChildQuestionInbox ? { onChildQuestionInbox: opts.onChildQuestionInbox } : {},
|
|
4315
|
-
...opts.priorEscalations?.length ? { priorEscalations: opts.priorEscalations } : {},
|
|
4316
|
-
...opts.priorQuestions?.length ? { priorQuestions: opts.priorQuestions } : {},
|
|
4317
|
-
...opts.priorJournal?.length ? { priorJournal: opts.priorJournal } : {},
|
|
4318
|
-
...opts.priorAnalystDefinitions?.length ? { priorAnalystDefinitions: opts.priorAnalystDefinitions } : {},
|
|
4319
|
-
...opts.preflightSpawn ? { preflightSpawn: opts.preflightSpawn } : {},
|
|
4320
|
-
...opts.resolveSpawnProfile ? { resolveSpawnProfile: opts.resolveSpawnProfile } : {},
|
|
4321
|
-
...opts.composeSpawnProfile ? { composeSpawnProfile: opts.composeSpawnProfile } : {},
|
|
4322
|
-
...opts.profiles ? { profiles: opts.profiles } : {},
|
|
4323
|
-
...opts.spawnResourceRoot ? { spawnResourceRoot: opts.spawnResourceRoot } : {},
|
|
4324
|
-
...ownerReader ? { spawnResourceReader: ownerReader } : {},
|
|
4325
|
-
...opts.peerMail ? { peerMail: typeof opts.peerMail === "object" && opts.peerMail.limits ? { limits: opts.peerMail.limits } : {} } : {}
|
|
4326
|
-
};
|
|
4327
|
-
}
|
|
4328
|
-
/**
|
|
4329
|
-
* The granted tools in the order `opts.toolNames` names them, and the count of calls still running
|
|
4330
|
-
* behind a fence. An unknown, duplicated or shadowing name fails before the listener opens.
|
|
4331
|
-
*/
|
|
4332
|
-
function bindServedTools(opts, coord, fenceMs) {
|
|
4333
|
-
const reservedNames = new Set(coord.tools.map((tool) => tool.name));
|
|
4334
|
-
for (const tool of opts.nodeTools ?? []) {
|
|
4335
|
-
if (reservedNames.has(tool.name)) throw new ValidationError(`serveCoordinationMcp: node tool ${JSON.stringify(tool.name)} shadows a coordination verb or another node tool`);
|
|
4336
|
-
reservedNames.add(tool.name);
|
|
4337
|
-
}
|
|
4338
|
-
const nodeTools = singleFlightTools(opts.nodeTools ?? [], {
|
|
4339
|
-
fenceMs,
|
|
4340
|
-
receipts: coord
|
|
4341
|
-
});
|
|
4342
|
-
const fencedVerbs = singleFlightTools(coord.tools.filter((tool) => FENCED_VERBS.has(tool.name)), {
|
|
4343
|
-
fenceMs,
|
|
4344
|
-
receipts: coord
|
|
4345
|
-
});
|
|
4346
|
-
if (opts.deliverable && !fencedVerbs.tools.some((tool) => tool.name === DELIVERABLE_VERB)) throw new ValidationError(`serveCoordinationMcp: a deliverable is injected but the coordination verbs lack ${DELIVERABLE_VERB}, so its check would run unfenced`);
|
|
4347
|
-
const fencedByName = new Map(fencedVerbs.tools.map((tool) => [tool.name, tool]));
|
|
4348
|
-
const availableByName = new Map([...coord.tools.map((tool) => fencedByName.get(tool.name) ?? tool), ...nodeTools.tools].map((tool) => [tool.name, tool]));
|
|
4349
|
-
if (!Array.isArray(opts.toolNames)) throw new ValidationError("serveCoordinationMcp: toolNames must name every granted tool explicitly");
|
|
4350
|
-
const selectedNames = opts.toolNames;
|
|
4351
|
-
if (new Set(selectedNames).size !== selectedNames.length) throw new ValidationError("serveCoordinationMcp: toolNames contains a duplicate name");
|
|
4352
|
-
const missing = selectedNames.filter((name) => !availableByName.has(name));
|
|
4353
|
-
if (missing.length > 0) throw new ValidationError(`serveCoordinationMcp: requested tools ${missing.map((n) => JSON.stringify(n)).join(", ")} are unavailable; served: ${[...availableByName.keys()].join(", ")}`);
|
|
4354
|
-
return {
|
|
4355
|
-
servedTools: selectedNames.map((name) => availableByName.get(name)),
|
|
4356
|
-
background: () => nodeTools.background() + fencedVerbs.background()
|
|
4357
|
-
};
|
|
4358
|
-
}
|
|
4359
4335
|
// src/runtime/supervise/coordination-mcp.ts
|
|
4360
4336
|
/** Serve Runtime coordination as bounded HTTP MCP over one live scope. @experimental */
|
|
4361
4337
|
/** Recognizable loopback spellings; other hostnames require authenticated remote transport. */
|
|
@@ -8727,13 +8703,14 @@ function modelSettingsSpawnPreflight(runtimeOwnsManager, path) {
|
|
|
8727
8703
|
};
|
|
8728
8704
|
}
|
|
8729
8705
|
/** Refuse a Runtime-managed child whose declared tools cannot exist on its execution path. */
|
|
8730
|
-
function profileToolSpawnPreflight(runtimeOwnsManager, canResolveProductTools) {
|
|
8706
|
+
function profileToolSpawnPreflight(runtimeOwnsManager, canResolveProductTools, servesToolNames) {
|
|
8731
8707
|
return async (profile) => {
|
|
8732
8708
|
if (!runtimeOwnsManager) return void 0;
|
|
8733
|
-
const
|
|
8734
|
-
|
|
8709
|
+
const served = servesToolNames && [...coordinationVerbNames, ...servesToolNames];
|
|
8710
|
+
const detail = runtimeToolDeclarationError(profile, canResolveProductTools) ?? (served && unservedToolsRefusal(declaredRuntimeToolNames(profile), served));
|
|
8711
|
+
return detail === void 0 ? void 0 : {
|
|
8735
8712
|
cause: "unmountable-tool",
|
|
8736
|
-
detail
|
|
8713
|
+
detail
|
|
8737
8714
|
};
|
|
8738
8715
|
};
|
|
8739
8716
|
}
|
|
@@ -9056,7 +9033,7 @@ function managerDriverPlan(options, canonicalProfile, externalRoot) {
|
|
|
9056
9033
|
const custom = manager ? external && hasCustomDriveHarness : options.makeLeafAgent !== void 0;
|
|
9057
9034
|
const backend = manager ? external ? managerBackend : void 0 : options.backend;
|
|
9058
9035
|
return modelSettingsSpawnPreflight(options.makeWorkerAgent === void 0 && !custom, backend?.backend === "provider" ? "provider" : "router")?.(profile, context);
|
|
9059
|
-
}, profileToolSpawnPreflight(options.makeWorkerAgent === void 0, options.resolveSupervisorTools !== void 0), coordinationChannelSpawnPreflight(options.makeWorkerAgent === void 0, hasCustomDriveHarness, managerBackend, options.coordination), options.backend?.backend === "bridge" ? bridgeSpawnPreflight(options.backend) : void 0, options.backend?.backend === "provider" && typeof options.backend.provider === "object" ? providerSpawnPreflight(options.backend.provider) : void 0, resourceSpawnPreflight(options.backend));
|
|
9036
|
+
}, profileToolSpawnPreflight(options.makeWorkerAgent === void 0, options.resolveSupervisorTools !== void 0, options.servesToolNames), coordinationChannelSpawnPreflight(options.makeWorkerAgent === void 0, hasCustomDriveHarness, managerBackend, options.coordination), options.backend?.backend === "bridge" ? bridgeSpawnPreflight(options.backend) : void 0, options.backend?.backend === "provider" && typeof options.backend.provider === "object" ? providerSpawnPreflight(options.backend.provider) : void 0, resourceSpawnPreflight(options.backend));
|
|
9060
9037
|
const checkNames = options.checkNodes?.names;
|
|
9061
9038
|
const spawnPreflight = agentPreflight && checkNames ? (profile, context) => checkNames.includes(profile.name ?? "") && !profile.harness && !profile.model ? Promise.resolve(void 0) : agentPreflight(profile, context) : agentPreflight;
|
|
9062
9039
|
const driverMaterialization = hasCustomDriveHarness ? options.driveHarnessMaterialization ?? fullProfileMaterialization : managerBackend && automaticDriver ? backendProfileMaterialization(managerBackend) : void 0;
|
|
@@ -9425,4 +9402,4 @@ function superviseWithContext(profile, task, opts, brain) {
|
|
|
9425
9402
|
}
|
|
9426
9403
|
export { createPromptRegistry as A, noProgressFor as B, journaledGateDecider as C, graphRootProfile as D, defaultEdgeTraversalCap as E, kernelPromptRegistry as F, plateauLength as G, anytimeReport as H, naiveContinuationPrompt as I, renderAnytimeTable as K, promptHandle as L, dumbContinuationFailPrompt as M, dumbContinuationPassPrompt as N, validateGraphTopology as O, formatPromptHandle as P, allWorkersStalled as R, flowRootProfile as S, validateFlowGraph as T, areaUnderCurve as U, plateau as V, bestSoFar as W, driverAgent as _, superviseRootProfile as a, GraphRouteError as b, supervisorAgentWithTestBrain as c, rootStreamToolSpans as d, runToolSpans as f, coordinationControlToolNames as g, serveCoordinationMcp as h, profileGuidanceComposer as i, delegatesWorkerBriefPrompt as j, analyzesFindingsReportPrompt as k, ASSISTANT_REASONING_SPAN as l, composeReentryTask as m, superviseFleetCapabilities as n, workerFromBackend as o, UNPROVEN_CONTINUITY as p, createSupervisorSpanRecorder as q, superviseWithTestBrain as r, supervisorAgent as s, supervise as t, ASSISTANT_TEXT_SPAN as u, runBrainLoop as v, routeFlowOf as w, createFlowRun as x, createGraphOverlay as y, anyOf as z };
|
|
9427
9404
|
|
|
9428
|
-
//# sourceMappingURL=supervise-
|
|
9405
|
+
//# sourceMappingURL=supervise-RJG2ruTF.js.map
|