@caupulican/pi-adaptative 0.86.2 → 0.86.3
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 +8 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +1 -12
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +7 -0
- package/dist/core/tools/delegate.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.86.3] - 2026-08-06
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Enforced a maximum 1-level delegation nesting model (orchestrator + leaf workers): removed `delegate` and `workflow.delegate` from default worker authority, and rejected nested subagent `delegate` `action: "start"` calls with `subagent_delegation_disabled`.
|
|
8
|
+
|
|
1
9
|
## [0.86.2] - 2026-08-06
|
|
2
10
|
|
|
3
11
|
### Fixed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAU1D,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAU1D,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAe1E,MAAM,WAAW,8BAA8B;IAC9C,SAAS,CAAC,EAAE,gCAAgC,CAAC;IAC7C,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED,MAAM,MAAM,yBAAyB,GAClC;IACA,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,qBAAqB,CAAC;IAChC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA6BjC,8FAA8F;AAC9F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,8BAA8B,GAAG,yBAAyB,CA6EvG"}
|
|
@@ -5,17 +5,7 @@ import { ORCHESTRATION_SCHEMA_VERSION, } from "../orchestration/contracts.js";
|
|
|
5
5
|
import { CLASSIFIED_LANE_TOOL_NAMES } from "../orchestration/lane-tool-manifests.js";
|
|
6
6
|
import { resolvePinnedOrchestrationModel } from "../orchestration/model-binding.js";
|
|
7
7
|
import { getToolCapabilityPolicy } from "../tool-capability-policy.js";
|
|
8
|
-
const DEFAULT_TOOL_NAMES = [
|
|
9
|
-
"read",
|
|
10
|
-
"grep",
|
|
11
|
-
"find",
|
|
12
|
-
"ls",
|
|
13
|
-
"write",
|
|
14
|
-
"edit",
|
|
15
|
-
"memory",
|
|
16
|
-
STABLE_SHELL_TOOL_NAME,
|
|
17
|
-
"delegate",
|
|
18
|
-
];
|
|
8
|
+
const DEFAULT_TOOL_NAMES = ["read", "grep", "find", "ls", "write", "edit", "memory", STABLE_SHELL_TOOL_NAME];
|
|
19
9
|
const AVAILABLE_TOOL_NAMES = new Set([...CLASSIFIED_LANE_TOOL_NAMES, "delegate"]);
|
|
20
10
|
const DEFAULT_CAPABILITIES = [
|
|
21
11
|
"filesystem.read",
|
|
@@ -26,7 +16,6 @@ const DEFAULT_CAPABILITIES = [
|
|
|
26
16
|
"network.http",
|
|
27
17
|
"service.mcp",
|
|
28
18
|
"memory.query",
|
|
29
|
-
"workflow.delegate",
|
|
30
19
|
];
|
|
31
20
|
function selectModelBinding(authority, base, foregroundModel, modelRegistry) {
|
|
32
21
|
const provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAEN,4BAA4B,GAG5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,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AE,CAAC;QAC7F,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n\t\"workflow.delegate\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) return { ok: true, shipment: input.base };\n\tconst binding = selectModelBinding(input.authority, input.base, input.foregroundModel, input.modelRegistry);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst requestedToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (policy.capabilityCandidates.some((capability) => capabilities.has(capability))) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,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EAAE,CAAC;SACtD;QACD,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\nconst DEFAULT_TOOL_NAMES = [\"read\", \"grep\", \"find\", \"ls\", \"write\", \"edit\", \"memory\", STABLE_SHELL_TOOL_NAME] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) return { ok: true, shipment: input.base };\n\tconst binding = selectModelBinding(input.authority, input.base, input.foregroundModel, input.modelRegistry);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst requestedToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (policy.capabilityCandidates.some((capability) => capabilities.has(capability))) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../../src/core/t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AAuB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpF,qBAAqB,CAAC,EAAE,SAAS;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5F,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAgHD,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,wBAAwB,GAAG,cAAc,CA8b3F"}
|
|
@@ -497,6 +497,13 @@ export function createDelegateToolDefinition(deps) {
|
|
|
497
497
|
},
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
|
+
if (deps.callerAgentId) {
|
|
501
|
+
return invalid("Subagent worker delegation is disabled (1-level nesting maximum). Only the root orchestrator may spawn worker agents.", {
|
|
502
|
+
started: false,
|
|
503
|
+
action,
|
|
504
|
+
skipReason: "subagent_delegation_disabled",
|
|
505
|
+
});
|
|
506
|
+
}
|
|
500
507
|
const instructions = input.instructions?.trim();
|
|
501
508
|
if (!instructions)
|
|
502
509
|
return invalid("delegate start requires instructions", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAM5C,OAAO,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClH,OAAO,EACN,sBAAsB,EAGtB,6BAA6B,GAC7B,MAAM,0BAA0B,CAAC;AAElC,SAAS,oBAAoB;IAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAC5B;QACC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI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y/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { HARNESS_CAPABILITIES, ORCHESTRATION_THINKING_LEVELS, WORKER_ROLES } from \"../orchestration/contracts.ts\";\nimport {\n\temptyOrchestrationCall,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n\trenderOrchestrationToolResult,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\tconst authority = Type.Object(\n\t\t{\n\t\t\trole: Type.Optional(Type.Union(WORKER_ROLES.map((role) => Type.Literal(role)))),\n\t\t\tmodel: Type.Optional(\n\t\t\t\tType.Object(\n\t\t\t\t\t{\n\t\t\t\t\t\tprovider: Type.String({ minLength: 1, maxLength: 128 }),\n\t\t\t\t\t\tmodelId: Type.String({ minLength: 1, maxLength: 512 }),\n\t\t\t\t\t},\n\t\t\t\t\t{ additionalProperties: false },\n\t\t\t\t),\n\t\t\t),\n\t\t\tthinkingLevel: Type.Optional(Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level)))),\n\t\t\tcapabilities: Type.Optional(\n\t\t\t\tType.Array(Type.Union(HARNESS_CAPABILITIES.map((capability) => Type.Literal(capability))), {\n\t\t\t\t\tmaxItems: 64,\n\t\t\t\t}),\n\t\t\t),\n\t\t\ttoolNames: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 512 }), { maxItems: 64 })),\n\t\t\treadPaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),\n\t\t\twritePaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),\n\t\t\tbudget: Type.Optional(\n\t\t\t\tType.Object(\n\t\t\t\t\t{\n\t\t\t\t\t\tmaxTokens: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxWallClockMs: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\t\tmaxAttempts: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxToolCalls: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\t},\n\t\t\t\t\t{ additionalProperties: false },\n\t\t\t\t),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16,\n\t\t\t\t\tenum: [\"start\", \"list\", \"transcript\", \"send\", \"follow_up\", \"wait\", \"interrupt\", \"resume\", \"cancel\"],\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional orchestration-tree action. Omit or use start to create a child; list discovers peers; transcript pages exact peer history; send/follow_up support threaded agent messages; wait is event-driven; interrupt is resumable; resume restores the exact admitted state; cancel is terminal for the current task only.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional loaded profile to use as routing and execution defaults. It is a preset, not an authority allowlist; authority may replace its model, reasoning, tools, capabilities, paths, and budget before the host intersects inherited grants.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tauthority: Type.Optional(authority),\n\t\t\tinstructions: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16 * 1024,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"The self-contained task for an autonomous child. It inherits the caller's full admitted grant by default and may recursively delegate, inspect peer transcripts, and coordinate the tree.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tagentId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription: \"Stable logical worker id returned by start; never substitute a transient task lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 4_096,\n\t\t\t\t\tdescription: \"Bounded message for send or follow_up. Send only queues it; follow_up may wake idle work.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tthreadId: Type.Optional(Type.String({ maxLength: 512, description: \"Stable peer-message thread identity.\" })),\n\t\t\treplyToMessageId: Type.Optional(\n\t\t\t\tType.String({ maxLength: 512, description: \"Message identity this peer response answers.\" }),\n\t\t\t),\n\t\t\texpectReply: Type.Optional(\n\t\t\t\tType.Boolean({ description: \"Mark this peer message as awaiting an explicit reply.\" }),\n\t\t\t),\n\t\t\tcursor: Type.Optional(Type.Integer({ minimum: 0, description: \"Zero-based list or transcript page cursor.\" })),\n\t\t\tmaxMessages: Type.Optional(\n\t\t\t\tType.Integer({ minimum: 1, maximum: 64, description: \"Exact transcript messages to return per page.\" }),\n\t\t\t),\n\t\t\ttimeoutMs: Type.Optional(\n\t\t\t\tType.Integer({ minimum: 0, maximum: 300_000, description: \"Event-driven wait timeout.\" }),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\nconst MAX_DELEGATE_RESULT_CHARS = 16 * 1024;\nconst MAX_DELEGATE_ERROR_CHARS = 1_900;\nconst MAX_DELEGATE_INSTRUCTIONS_CHARS = 16 * 1024;\nconst MAX_DELEGATE_PROFILE_ID_CHARS = 512;\nconst MAX_DELEGATE_AGENT_ID_CHARS = 512;\nconst MAX_DELEGATE_MESSAGE_CHARS = 4_096;\nconst MAX_DELEGATE_CONTROL_ID_CHARS = 512;\nconst MAX_PROFILE_GUIDELINE_CHARS = 4_096;\nconst MAX_VISIBLE_ORCHESTRATION_PROFILES = 16;\nconst MAX_PROFILE_GUIDELINE_FIELD_CHARS = 64;\n\ntype DelegateAction = NonNullable<DelegateToolDetails[\"action\"]>;\n\nfunction isDelegateAction(value: string): value is DelegateAction {\n\treturn (\n\t\tvalue === \"start\" ||\n\t\tvalue === \"list\" ||\n\t\tvalue === \"transcript\" ||\n\t\tvalue === \"send\" ||\n\t\tvalue === \"follow_up\" ||\n\t\tvalue === \"wait\" ||\n\t\tvalue === \"interrupt\" ||\n\t\tvalue === \"resume\" ||\n\t\tvalue === \"cancel\"\n\t);\n}\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\taction?: \"start\" | \"list\" | \"transcript\" | \"send\" | \"follow_up\" | \"wait\" | \"interrupt\" | \"resume\" | \"cancel\";\n\tagentId?: string;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n\tqueued?: boolean;\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n\tworkerAgentControl?: WorkerAgentControlPort;\n\t/** Runtime-owned sender identity for peer messages emitted from a delegated agent. */\n\tcallerAgentId?: string;\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Create agents recursively and coordinate the complete session orchestration tree. A child inherits the caller's execution authority by default and may select a loaded profile as a preset; inherited authority can narrow but never escalate beyond the root grant. There is no depth or fan-out cap: the host scheduler manages concurrency, cumulative budgets, leases, cancellation, and exact-cycle detection. list discovers peers; transcript pages exact durable peer messages; send/follow_up carry thread and reply metadata; wait is event-driven. interrupt is resumable; resume retains the admitted transcript/model/resources under a fresh fence; cancel is terminal only for the current task.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result surfaces later through the event-driven terminal\n// handoff and an exact transcript/status read.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The owning parent receives a durable terminal handoff when the lane ends. Read exact child evidence with transcript; foreground surfaces may use delegate_status. Use wait only when coordination must block. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.\",\n\t\"Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.\",\n\t\"The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.\",\n\t\"Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.\",\n\t\"The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.\",\n\t\"This call returns immediately with a stable agentId, before the worker has produced a result; the owning parent receives a durable terminal handoff. Use event-driven wait only when coordination must block. Do not poll.\",\n\t\"Read exact child evidence with transcript; foreground surfaces may use delegate_status. Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nfunction orchestrationProfileGuideline(\n\tprofiles: readonly { profileId: string; role: string; description: string }[] | undefined,\n): string {\n\tif (!profiles || profiles.length === 0) {\n\t\treturn \"No optional orchestration presets are loaded. Child agents inherit the caller's admitted model, reasoning, tools, paths, resources, and remaining budget.\";\n\t}\n\tconst visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);\n\tconst entries = visibleProfiles.map((profile) => {\n\t\tconst profileId = profile.profileId.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst role = profile.role.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst description = profile.description.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\treturn `${profileId} (${role}: ${description})`;\n\t});\n\tconst omitted = profiles.length - visibleProfiles.length;\n\treturn [\n\t\t`Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join(\"; \")}`,\n\t\t...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),\n\t\t\"Any agent may select a loaded profileId as a routing preset. The host intersects it with inherited authority, so a preset can specialize or narrow a child but cannot elevate it beyond the root grant.\",\n\t]\n\t\t.join(\" \")\n\t\t.slice(0, MAX_PROFILE_GUIDELINE_CHARS);\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline = orchestrationProfileGuideline(deps.orchestrationProfiles);\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Create and coordinate an autonomous agent with inherited or explicitly selected authority.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as DelegateToolDetails | undefined;\n\t\t\treturn renderOrchestrationToolResult(theme, delegatePanelModel(details), {\n\t\t\t\tisPartial,\n\t\t\t\tcollapse: !expanded && details?.started === true,\n\t\t\t\texpanded,\n\t\t\t});\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst requestedAction = input.action ?? \"start\";\n\t\t\tconst invalid = (message: string, actionDetails: DelegateToolDetails) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: message }],\n\t\t\t\tdetails: actionDetails,\n\t\t\t});\n\t\t\tif (!isDelegateAction(requestedAction)) {\n\t\t\t\treturn invalid(`delegate action is invalid: ${requestedAction}`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\tskipReason: \"invalid_action\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst action = requestedAction;\n\t\t\tif (input.instructions !== undefined && input.instructions.length > MAX_DELEGATE_INSTRUCTIONS_CHARS) {\n\t\t\t\treturn invalid(`delegate instructions may not exceed ${MAX_DELEGATE_INSTRUCTIONS_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"instructions_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.profileId !== undefined && input.profileId.length > MAX_DELEGATE_PROFILE_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate profileId may not exceed ${MAX_DELEGATE_PROFILE_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"profile_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_DELEGATE_AGENT_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate agentId may not exceed ${MAX_DELEGATE_AGENT_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"agent_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.message !== undefined && input.message.length > MAX_DELEGATE_MESSAGE_CHARS) {\n\t\t\t\treturn invalid(`delegate message may not exceed ${MAX_DELEGATE_MESSAGE_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"message_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const [label, value] of [\n\t\t\t\t[\"threadId\", input.threadId],\n\t\t\t\t[\"replyToMessageId\", input.replyToMessageId],\n\t\t\t] as const) {\n\t\t\t\tif (value !== undefined && (value.length === 0 || value.length > MAX_DELEGATE_CONTROL_ID_CHARS)) {\n\t\t\t\t\treturn invalid(`delegate ${label} is invalid`, {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"control_id_invalid\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (input.cursor !== undefined && (!Number.isSafeInteger(input.cursor) || input.cursor < 0)) {\n\t\t\t\treturn invalid(\"delegate cursor is invalid\", { started: false, action, skipReason: \"cursor_invalid\" });\n\t\t\t}\n\t\t\tif (\n\t\t\t\tinput.maxMessages !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(input.maxMessages) || input.maxMessages < 1 || input.maxMessages > 64)\n\t\t\t) {\n\t\t\t\treturn invalid(\"delegate maxMessages is invalid\", {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"page_size_invalid\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst requireAgentId = (): string | undefined => {\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (agentId) return agentId;\n\t\t\t\treturn undefined;\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tif (action === \"list\") {\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate list is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst agents = deps.callerAgentId\n\t\t\t\t\t\t? deps.workerAgentControl.listWorkerAgents({ callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t: deps.workerAgentControl.listWorkerAgents();\n\t\t\t\t\tconst cursor = input.cursor ?? 0;\n\t\t\t\t\tif (cursor > agents.length)\n\t\t\t\t\t\treturn invalid(\"delegate list cursor exceeds the agent count\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"cursor_out_of_range\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst pageSize = input.maxMessages ?? 64;\n\t\t\t\t\tconst page = agents.slice(cursor, cursor + pageSize);\n\t\t\t\t\tconst nextCursor = cursor + page.length;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: JSON.stringify({\n\t\t\t\t\t\t\t\t\tcursor,\n\t\t\t\t\t\t\t\t\ttotalAgents: agents.length,\n\t\t\t\t\t\t\t\t\tagents: page,\n\t\t\t\t\t\t\t\t\t...(nextCursor < agents.length ? { nextCursor } : {}),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { started: true, action },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (action !== \"start\") {\n\t\t\t\t\tconst agentId = requireAgentId();\n\t\t\t\t\tif (!agentId)\n\t\t\t\t\t\treturn invalid(`delegate ${action} requires agentId`, {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"missing_agent_id\",\n\t\t\t\t\t\t});\n\t\t\t\t\tif (action === \"transcript\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate transcript is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst page = deps.workerAgentControl.readWorkerAgentTranscript(agentId, {\n\t\t\t\t\t\t\t...(input.cursor !== undefined ? { cursor: input.cursor } : {}),\n\t\t\t\t\t\t\t...(input.maxMessages !== undefined ? { maxMessages: input.maxMessages } : {}),\n\t\t\t\t\t\t\t...(deps.callerAgentId ? { callerAgentId: deps.callerAgentId } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: JSON.stringify(page) }],\n\t\t\t\t\t\t\tdetails: { started: true, action, agentId },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"wait\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate wait is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst waited = deps.callerAgentId\n\t\t\t\t\t\t\t? await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs, {\n\t\t\t\t\t\t\t\t\tcallerAgentId: deps.callerAgentId,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t: await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `worker ${agentId} is ${waited.status}` }],\n\t\t\t\t\t\t\tdetails: { started: true, action, agentId },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"send\" || action === \"follow_up\") {\n\t\t\t\t\t\tconst message = input.message?.trim();\n\t\t\t\t\t\tif (!message)\n\t\t\t\t\t\t\treturn invalid(`delegate ${action} requires message`, {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"missing_message\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst messageOptions = {\n\t\t\t\t\t\t\t...(deps.callerAgentId ? { senderAgentId: deps.callerAgentId } : {}),\n\t\t\t\t\t\t\t...(input.threadId ? { threadId: input.threadId.trim() } : {}),\n\t\t\t\t\t\t\t...(input.replyToMessageId ? { replyToMessageId: input.replyToMessageId.trim() } : {}),\n\t\t\t\t\t\t\t...(input.expectReply === true ? { expectReply: true } : {}),\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst hasMessageOptions = Object.keys(messageOptions).length > 0;\n\t\t\t\t\t\tif (action === \"send\") {\n\t\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\t\treturn invalid(\"delegate send is unavailable\", {\n\t\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst outcome = hasMessageOptions\n\t\t\t\t\t\t\t\t? deps.workerAgentControl.sendWorkerAgentMessage(agentId, message, messageOptions)\n\t\t\t\t\t\t\t\t: deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\t\ttext: `message queued for ${agentId}; it will not wake the worker`,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdetails: { started: true, action, agentId, queued: outcome.queued },\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate follow_up is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = hasMessageOptions\n\t\t\t\t\t\t\t? deps.workerAgentControl.followUpWorkerAgent(agentId, message, messageOptions)\n\t\t\t\t\t\t\t: deps.workerAgentControl.followUpWorkerAgent(agentId, message);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: `follow_up ${outcome.started ? \"started\" : \"queued\"} for ${agentId}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"interrupt\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate interrupt is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.callerAgentId\n\t\t\t\t\t\t\t? deps.workerAgentControl.interruptWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t\t: deps.workerAgentControl.interruptWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.interrupted\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} interrupted; resume preserves its admitted state`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not interrupted (${outcome.reason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: { started: outcome.interrupted, action, agentId, skipReason: outcome.reason },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"resume\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate resume is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.callerAgentId\n\t\t\t\t\t\t\t? deps.workerAgentControl.resumeWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t\t: deps.workerAgentControl.resumeWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.started\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} resumed with its admitted transcript and authority`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not resumed (${outcome.skipReason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate cancel is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst cancelled = deps.callerAgentId\n\t\t\t\t\t\t? deps.workerAgentControl.cancelWorkerAgent(agentId, undefined, {\n\t\t\t\t\t\t\t\tcallerAgentId: deps.callerAgentId,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: deps.workerAgentControl.cancelWorkerAgent(agentId);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: cancelled\n\t\t\t\t\t\t\t\t\t? `worker ${agentId} cancelled for its current task`\n\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not cancelled`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: Boolean(cancelled),\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tlaneId: cancelled?.laneId,\n\t\t\t\t\t\t\tstatus: cancelled?.status,\n\t\t\t\t\t\t\treasonCode: cancelled?.reasonCode,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst instructions = input.instructions?.trim();\n\t\t\t\tif (!instructions)\n\t\t\t\t\treturn invalid(\"delegate start requires instructions\", {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"missing_instructions\",\n\t\t\t\t\t});\n\t\t\t\tconst profileId = input.profileId?.trim();\n\t\t\t\tconst request = {\n\t\t\t\t\tinstructions,\n\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t...(input.authority ? { authority: structuredClone(input.authority) } : {}),\n\t\t\t\t};\n\t\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\t\tif (!started.started) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\tskipReason: started.skipReason,\n\t\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — stable agentId ${started.record.laneId}, task laneId ${started.record.laneId}; the owning parent will receive its terminal handoff, then read exact evidence with transcript or foreground delegate_status`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\t\t...((started.record.profileId ?? profileId)\n\t\t\t\t\t\t\t\t? { profileId: started.record.profileId ?? profileId }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\tagentId: started.record.laneId,\n\t\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\t\t...(started.record.label ? { label: started.record.label } : {}),\n\t\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\t\tif (!run.started) {\n\t\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\tskipReason: reason,\n\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst outcome = run.outcome;\n\t\t\t\tconst lines: string[] = [\n\t\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t\t];\n\t\t\t\tif (outcome) {\n\t\t\t\t\tlines.push(\n\t\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\t\toutcome.claim.summary.slice(0, 8_000),\n\t\t\t\t\t);\n\t\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\t\tlines.push(\n\t\t\t\t\t\t\t`Blockers: ${outcome.claim.blockers\n\t\t\t\t\t\t\t\t.slice(0, 16)\n\t\t\t\t\t\t\t\t.map((blocker) => blocker.slice(0, 512))\n\t\t\t\t\t\t\t\t.join(\"; \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const finding of outcome.claim.evidence?.findings.slice(0, 16) ?? []) {\n\t\t\t\t\t\tlines.push(`- Finding: ${finding.summary.slice(0, 512)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\").slice(0, MAX_DELEGATE_RESULT_CHARS) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: run.record?.profileId ?? profileId,\n\t\t\t\t\t\tagentId: run.record?.laneId,\n\t\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst reason = (error instanceof Error ? error.message : String(error)).slice(0, MAX_DELEGATE_ERROR_CHARS);\n\t\t\t\treturn invalid(`delegate ${action} failed: ${reason}`.slice(0, 2_048), {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\t...(input.agentId?.trim() ? { agentId: input.agentId.trim() } : {}),\n\t\t\t\t\tskipReason: \"worker_agent_control_error\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../../src/core/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAM5C,OAAO,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClH,OAAO,EACN,sBAAsB,EAGtB,6BAA6B,GAC7B,MAAM,0BAA0B,CAAC;AAElC,SAAS,oBAAoB;IAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAC5B;QACC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/E,KAAK,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,MAAM,CACV;YACC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;YACvD,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;SACtD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CACD;QACD,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3G,YAAY,EAAE,IAA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AC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;wBAC/C,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;qBAC/C;iBACD,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,MAAM,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;gBAC3G,OAAO,OAAO,CAAC,YAAY,MAAM,YAAY,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;oBACtE,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnE,UAAU,EAAE,4BAA4B;iBACxC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerAgentControlPort } from \"../delegation/worker-agent-control.ts\";\nimport type { WorkerDelegationRequest } from \"../delegation/worker-delegation-request.ts\";\nimport type { WorkerRunOutcome } from \"../delegation/worker-runner.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { HARNESS_CAPABILITIES, ORCHESTRATION_THINKING_LEVELS, WORKER_ROLES } from \"../orchestration/contracts.ts\";\nimport {\n\temptyOrchestrationCall,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n\trenderOrchestrationToolResult,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\n\tconst authority = Type.Object(\n\t\t{\n\t\t\trole: Type.Optional(Type.Union(WORKER_ROLES.map((role) => Type.Literal(role)))),\n\t\t\tmodel: Type.Optional(\n\t\t\t\tType.Object(\n\t\t\t\t\t{\n\t\t\t\t\t\tprovider: Type.String({ minLength: 1, maxLength: 128 }),\n\t\t\t\t\t\tmodelId: Type.String({ minLength: 1, maxLength: 512 }),\n\t\t\t\t\t},\n\t\t\t\t\t{ additionalProperties: false },\n\t\t\t\t),\n\t\t\t),\n\t\t\tthinkingLevel: Type.Optional(Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level)))),\n\t\t\tcapabilities: Type.Optional(\n\t\t\t\tType.Array(Type.Union(HARNESS_CAPABILITIES.map((capability) => Type.Literal(capability))), {\n\t\t\t\t\tmaxItems: 64,\n\t\t\t\t}),\n\t\t\t),\n\t\t\ttoolNames: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 512 }), { maxItems: 64 })),\n\t\t\treadPaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),\n\t\t\twritePaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),\n\t\t\tbudget: Type.Optional(\n\t\t\t\tType.Object(\n\t\t\t\t\t{\n\t\t\t\t\t\tmaxTokens: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxWallClockMs: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\t\tmaxAttempts: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\tmaxToolCalls: Type.Optional(Type.Integer({ minimum: 0 })),\n\t\t\t\t\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\t},\n\t\t\t\t\t{ additionalProperties: false },\n\t\t\t\t),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n\treturn Type.Object(\n\t\t{\n\t\t\taction: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16,\n\t\t\t\t\tenum: [\"start\", \"list\", \"transcript\", \"send\", \"follow_up\", \"wait\", \"interrupt\", \"resume\", \"cancel\"],\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional orchestration-tree action. Omit or use start to create a child; list discovers peers; transcript pages exact peer history; send/follow_up support threaded agent messages; wait is event-driven; interrupt is resumable; resume restores the exact admitted state; cancel is terminal for the current task only.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tprofileId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional loaded profile to use as routing and execution defaults. It is a preset, not an authority allowlist; authority may replace its model, reasoning, tools, capabilities, paths, and budget before the host intersects inherited grants.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tauthority: Type.Optional(authority),\n\t\t\tinstructions: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 16 * 1024,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"The self-contained task for an autonomous child. It inherits the caller's full admitted grant by default and may recursively delegate, inspect peer transcripts, and coordinate the tree.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tagentId: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 512,\n\t\t\t\t\tdescription: \"Stable logical worker id returned by start; never substitute a transient task lane.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tmessage: Type.Optional(\n\t\t\t\tType.String({\n\t\t\t\t\tmaxLength: 4_096,\n\t\t\t\t\tdescription: \"Bounded message for send or follow_up. Send only queues it; follow_up may wake idle work.\",\n\t\t\t\t}),\n\t\t\t),\n\t\t\tthreadId: Type.Optional(Type.String({ maxLength: 512, description: \"Stable peer-message thread identity.\" })),\n\t\t\treplyToMessageId: Type.Optional(\n\t\t\t\tType.String({ maxLength: 512, description: \"Message identity this peer response answers.\" }),\n\t\t\t),\n\t\t\texpectReply: Type.Optional(\n\t\t\t\tType.Boolean({ description: \"Mark this peer message as awaiting an explicit reply.\" }),\n\t\t\t),\n\t\t\tcursor: Type.Optional(Type.Integer({ minimum: 0, description: \"Zero-based list or transcript page cursor.\" })),\n\t\t\tmaxMessages: Type.Optional(\n\t\t\t\tType.Integer({ minimum: 1, maximum: 64, description: \"Exact transcript messages to return per page.\" }),\n\t\t\t),\n\t\t\ttimeoutMs: Type.Optional(\n\t\t\t\tType.Integer({ minimum: 0, maximum: 300_000, description: \"Event-driven wait timeout.\" }),\n\t\t\t),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nconst delegateSchema = createDelegateSchema();\nconst MAX_DELEGATE_RESULT_CHARS = 16 * 1024;\nconst MAX_DELEGATE_ERROR_CHARS = 1_900;\nconst MAX_DELEGATE_INSTRUCTIONS_CHARS = 16 * 1024;\nconst MAX_DELEGATE_PROFILE_ID_CHARS = 512;\nconst MAX_DELEGATE_AGENT_ID_CHARS = 512;\nconst MAX_DELEGATE_MESSAGE_CHARS = 4_096;\nconst MAX_DELEGATE_CONTROL_ID_CHARS = 512;\nconst MAX_PROFILE_GUIDELINE_CHARS = 4_096;\nconst MAX_VISIBLE_ORCHESTRATION_PROFILES = 16;\nconst MAX_PROFILE_GUIDELINE_FIELD_CHARS = 64;\n\ntype DelegateAction = NonNullable<DelegateToolDetails[\"action\"]>;\n\nfunction isDelegateAction(value: string): value is DelegateAction {\n\treturn (\n\t\tvalue === \"start\" ||\n\t\tvalue === \"list\" ||\n\t\tvalue === \"transcript\" ||\n\t\tvalue === \"send\" ||\n\t\tvalue === \"follow_up\" ||\n\t\tvalue === \"wait\" ||\n\t\tvalue === \"interrupt\" ||\n\t\tvalue === \"resume\" ||\n\t\tvalue === \"cancel\"\n\t);\n}\n\nexport type DelegateToolInput = Static<typeof delegateSchema>;\n\nexport interface DelegateRunOutcome {\n\tstarted: boolean;\n\tskipReason?: string;\n\trecord?: LaneRecord;\n\toutcome?: WorkerRunOutcome;\n}\n\nexport interface DelegateToolDetails {\n\tstarted: boolean;\n\taction?: \"start\" | \"list\" | \"transcript\" | \"send\" | \"follow_up\" | \"wait\" | \"interrupt\" | \"resume\" | \"cancel\";\n\tagentId?: string;\n\tskipReason?: string;\n\tprofileId?: string;\n\tlaneId?: string;\n\tlabel?: string;\n\tstatus?: LaneRecord[\"status\"];\n\treasonCode?: string;\n\taccepted?: boolean;\n\tcostUsd?: number;\n\tsummary?: string;\n\tblockers?: readonly string[];\n\tqueued?: boolean;\n}\n\nexport interface DelegateToolDependencies {\n\tstartWorkerDelegation?: (\n\t\targs: WorkerDelegationRequest,\n\t) => { started: false; skipReason: string } | { started: true; record: LaneRecord };\n\trunWorkerDelegation: (args: WorkerDelegationRequest) => Promise<DelegateRunOutcome>;\n\torchestrationProfiles?: readonly { profileId: string; role: string; description: string }[];\n\tworkerAgentControl?: WorkerAgentControlPort;\n\t/** Runtime-owned sender identity for peer messages emitted from a delegated agent. */\n\tcallerAgentId?: string;\n}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Create agents recursively and coordinate the complete session orchestration tree. A child inherits the caller's execution authority by default and may select a loaded profile as a preset; inherited authority can narrow but never escalate beyond the root grant. There is no depth or fan-out cap: the host scheduler manages concurrency, cumulative budgets, leases, cancellation, and exact-cycle detection. list discovers peers; transcript pages exact durable peer messages; send/follow_up carry thread and reply metadata; wait is event-driven. interrupt is resumable; resume retains the admitted transcript/model/resources under a fresh fence; cancel is terminal only for the current task.\";\n\n// Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`\n// and the result comes back in this same tool call's response.\nconst SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;\n\n// Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns\n// immediately (see :~102) — the actual result surfaces later through the event-driven terminal\n// handoff and an exact transcript/status read.\nconst ASYNC_DELEGATE_DESCRIPTION = `${DELEGATE_DESCRIPTION_CORE} This call returns immediately once the worker lane starts; it does not wait for the worker to finish. The owning parent receives a durable terminal handoff when the lane ends. Read exact child evidence with transcript; foreground surfaces may use delegate_status. Use wait only when coordination must block. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.\",\n\t\"Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.\",\n\t\"The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.\",\n\t\"Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.\",\n\t\"The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.\",\n\t\"This call returns immediately with a stable agentId, before the worker has produced a result; the owning parent receives a durable terminal handoff. Use event-driven wait only when coordination must block. Do not poll.\",\n\t\"Read exact child evidence with transcript; foreground surfaces may use delegate_status. Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.\",\n];\n\nfunction delegatePanelModel(details: DelegateToolDetails | undefined): OrchestrationPanelModel {\n\tif (!details) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch\",\n\t\t\tstatus: \"idle\",\n\t\t\temptyText: \"No structured worker details were retained.\",\n\t\t};\n\t}\n\tif (!details.started) {\n\t\treturn {\n\t\t\tlabel: \"workers\",\n\t\t\taction: \"dispatch skipped\",\n\t\t\tstatus: \"warning\",\n\t\t\temptyText: details.skipReason ?? \"The worker was not started.\",\n\t\t};\n\t}\n\tconst laneStatus = details.status ?? \"queued\";\n\tconst rowStatus: OrchestrationRowStatus = laneStatus;\n\tconst meta = [\n\t\tdetails.profileId ? `profile ${details.profileId}` : undefined,\n\t\tdetails.reasonCode,\n\t\tdetails.accepted === undefined ? undefined : details.accepted ? \"accepted\" : \"not accepted\",\n\t\tdetails.costUsd === undefined ? undefined : `$${details.costUsd.toFixed(4)}`,\n\t].filter((value): value is string => value !== undefined);\n\tconst detailsLines = [\n\t\tdetails.summary ? `untrusted claim: ${details.summary}` : undefined,\n\t\t...(details.blockers ?? []).map((blocker) => `blocker: ${blocker}`),\n\t].filter((value): value is string => value !== undefined);\n\tconst active = laneStatus === \"queued\" || laneStatus === \"running\";\n\treturn {\n\t\tlabel: \"workers\",\n\t\taction: active ? \"dispatched\" : \"completed\",\n\t\tstatus: active\n\t\t\t? \"running\"\n\t\t\t: laneStatus === \"succeeded\" && details.accepted !== false\n\t\t\t\t? \"success\"\n\t\t\t\t: laneStatus === \"failed\"\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"warning\",\n\t\tsummary: active ? [\"terminal handoff will wake this session\"] : undefined,\n\t\trows: [\n\t\t\t{\n\t\t\t\tstatus: rowStatus,\n\t\t\t\tlabel: details.label ?? details.laneId ?? \"worker lane\",\n\t\t\t\tmeta: [details.label ? details.laneId : undefined, ...meta].filter(\n\t\t\t\t\t(value): value is string => value !== undefined,\n\t\t\t\t),\n\t\t\t\tdetails: detailsLines,\n\t\t\t},\n\t\t],\n\t\tnotices:\n\t\t\tdetails.accepted === false\n\t\t\t\t? [{ status: \"warning\", text: \"Worker output was not accepted; inspect and verify before use.\" }]\n\t\t\t\t: undefined,\n\t};\n}\n\nfunction orchestrationProfileGuideline(\n\tprofiles: readonly { profileId: string; role: string; description: string }[] | undefined,\n): string {\n\tif (!profiles || profiles.length === 0) {\n\t\treturn \"No optional orchestration presets are loaded. Child agents inherit the caller's admitted model, reasoning, tools, paths, resources, and remaining budget.\";\n\t}\n\tconst visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);\n\tconst entries = visibleProfiles.map((profile) => {\n\t\tconst profileId = profile.profileId.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst role = profile.role.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\tconst description = profile.description.slice(0, MAX_PROFILE_GUIDELINE_FIELD_CHARS);\n\t\treturn `${profileId} (${role}: ${description})`;\n\t});\n\tconst omitted = profiles.length - visibleProfiles.length;\n\treturn [\n\t\t`Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join(\"; \")}`,\n\t\t...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),\n\t\t\"Any agent may select a loaded profileId as a routing preset. The host intersects it with inherited authority, so a preset can specialize or narrow a child but cannot elevate it beyond the root grant.\",\n\t]\n\t\t.join(\" \")\n\t\t.slice(0, MAX_PROFILE_GUIDELINE_CHARS);\n}\n\nexport function createDelegateToolDefinition(deps: DelegateToolDependencies): ToolDefinition {\n\tconst isAsyncWiring = deps.startWorkerDelegation !== undefined;\n\tconst profileGuideline = orchestrationProfileGuideline(deps.orchestrationProfiles);\n\treturn {\n\t\tname: \"delegate\",\n\t\tlabel: \"delegate\",\n\t\tdescription: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,\n\t\tpromptSnippet: \"Create and coordinate an autonomous agent with inherited or explicitly selected authority.\",\n\t\tpromptGuidelines: [\n\t\t\tprofileGuideline,\n\t\t\t...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),\n\t\t],\n\t\tparameters: delegateSchema,\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tconst details = result.details as DelegateToolDetails | undefined;\n\t\t\treturn renderOrchestrationToolResult(theme, delegatePanelModel(details), {\n\t\t\t\tisPartial,\n\t\t\t\tcollapse: !expanded && details?.started === true,\n\t\t\t\texpanded,\n\t\t\t});\n\t\t},\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tinput: DelegateToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: DelegateToolDetails;\n\t\t}> {\n\t\t\tconst requestedAction = input.action ?? \"start\";\n\t\t\tconst invalid = (message: string, actionDetails: DelegateToolDetails) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text: message }],\n\t\t\t\tdetails: actionDetails,\n\t\t\t});\n\t\t\tif (!isDelegateAction(requestedAction)) {\n\t\t\t\treturn invalid(`delegate action is invalid: ${requestedAction}`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\tskipReason: \"invalid_action\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst action = requestedAction;\n\t\t\tif (input.instructions !== undefined && input.instructions.length > MAX_DELEGATE_INSTRUCTIONS_CHARS) {\n\t\t\t\treturn invalid(`delegate instructions may not exceed ${MAX_DELEGATE_INSTRUCTIONS_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"instructions_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.profileId !== undefined && input.profileId.length > MAX_DELEGATE_PROFILE_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate profileId may not exceed ${MAX_DELEGATE_PROFILE_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"profile_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.agentId !== undefined && input.agentId.length > MAX_DELEGATE_AGENT_ID_CHARS) {\n\t\t\t\treturn invalid(`delegate agentId may not exceed ${MAX_DELEGATE_AGENT_ID_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"agent_id_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (input.message !== undefined && input.message.length > MAX_DELEGATE_MESSAGE_CHARS) {\n\t\t\t\treturn invalid(`delegate message may not exceed ${MAX_DELEGATE_MESSAGE_CHARS} characters`, {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"message_too_long\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const [label, value] of [\n\t\t\t\t[\"threadId\", input.threadId],\n\t\t\t\t[\"replyToMessageId\", input.replyToMessageId],\n\t\t\t] as const) {\n\t\t\t\tif (value !== undefined && (value.length === 0 || value.length > MAX_DELEGATE_CONTROL_ID_CHARS)) {\n\t\t\t\t\treturn invalid(`delegate ${label} is invalid`, {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"control_id_invalid\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (input.cursor !== undefined && (!Number.isSafeInteger(input.cursor) || input.cursor < 0)) {\n\t\t\t\treturn invalid(\"delegate cursor is invalid\", { started: false, action, skipReason: \"cursor_invalid\" });\n\t\t\t}\n\t\t\tif (\n\t\t\t\tinput.maxMessages !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(input.maxMessages) || input.maxMessages < 1 || input.maxMessages > 64)\n\t\t\t) {\n\t\t\t\treturn invalid(\"delegate maxMessages is invalid\", {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\tskipReason: \"page_size_invalid\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst requireAgentId = (): string | undefined => {\n\t\t\t\tconst agentId = input.agentId?.trim();\n\t\t\t\tif (agentId) return agentId;\n\t\t\t\treturn undefined;\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tif (action === \"list\") {\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate list is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst agents = deps.callerAgentId\n\t\t\t\t\t\t? deps.workerAgentControl.listWorkerAgents({ callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t: deps.workerAgentControl.listWorkerAgents();\n\t\t\t\t\tconst cursor = input.cursor ?? 0;\n\t\t\t\t\tif (cursor > agents.length)\n\t\t\t\t\t\treturn invalid(\"delegate list cursor exceeds the agent count\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"cursor_out_of_range\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst pageSize = input.maxMessages ?? 64;\n\t\t\t\t\tconst page = agents.slice(cursor, cursor + pageSize);\n\t\t\t\t\tconst nextCursor = cursor + page.length;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: JSON.stringify({\n\t\t\t\t\t\t\t\t\tcursor,\n\t\t\t\t\t\t\t\t\ttotalAgents: agents.length,\n\t\t\t\t\t\t\t\t\tagents: page,\n\t\t\t\t\t\t\t\t\t...(nextCursor < agents.length ? { nextCursor } : {}),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { started: true, action },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (action !== \"start\") {\n\t\t\t\t\tconst agentId = requireAgentId();\n\t\t\t\t\tif (!agentId)\n\t\t\t\t\t\treturn invalid(`delegate ${action} requires agentId`, {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"missing_agent_id\",\n\t\t\t\t\t\t});\n\t\t\t\t\tif (action === \"transcript\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate transcript is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst page = deps.workerAgentControl.readWorkerAgentTranscript(agentId, {\n\t\t\t\t\t\t\t...(input.cursor !== undefined ? { cursor: input.cursor } : {}),\n\t\t\t\t\t\t\t...(input.maxMessages !== undefined ? { maxMessages: input.maxMessages } : {}),\n\t\t\t\t\t\t\t...(deps.callerAgentId ? { callerAgentId: deps.callerAgentId } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: JSON.stringify(page) }],\n\t\t\t\t\t\t\tdetails: { started: true, action, agentId },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"wait\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate wait is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst waited = deps.callerAgentId\n\t\t\t\t\t\t\t? await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs, {\n\t\t\t\t\t\t\t\t\tcallerAgentId: deps.callerAgentId,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t: await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `worker ${agentId} is ${waited.status}` }],\n\t\t\t\t\t\t\tdetails: { started: true, action, agentId },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"send\" || action === \"follow_up\") {\n\t\t\t\t\t\tconst message = input.message?.trim();\n\t\t\t\t\t\tif (!message)\n\t\t\t\t\t\t\treturn invalid(`delegate ${action} requires message`, {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"missing_message\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst messageOptions = {\n\t\t\t\t\t\t\t...(deps.callerAgentId ? { senderAgentId: deps.callerAgentId } : {}),\n\t\t\t\t\t\t\t...(input.threadId ? { threadId: input.threadId.trim() } : {}),\n\t\t\t\t\t\t\t...(input.replyToMessageId ? { replyToMessageId: input.replyToMessageId.trim() } : {}),\n\t\t\t\t\t\t\t...(input.expectReply === true ? { expectReply: true } : {}),\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst hasMessageOptions = Object.keys(messageOptions).length > 0;\n\t\t\t\t\t\tif (action === \"send\") {\n\t\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\t\treturn invalid(\"delegate send is unavailable\", {\n\t\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst outcome = hasMessageOptions\n\t\t\t\t\t\t\t\t? deps.workerAgentControl.sendWorkerAgentMessage(agentId, message, messageOptions)\n\t\t\t\t\t\t\t\t: deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\t\ttext: `message queued for ${agentId}; it will not wake the worker`,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdetails: { started: true, action, agentId, queued: outcome.queued },\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate follow_up is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = hasMessageOptions\n\t\t\t\t\t\t\t? deps.workerAgentControl.followUpWorkerAgent(agentId, message, messageOptions)\n\t\t\t\t\t\t\t: deps.workerAgentControl.followUpWorkerAgent(agentId, message);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: `follow_up ${outcome.started ? \"started\" : \"queued\"} for ${agentId}`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"interrupt\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate interrupt is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.callerAgentId\n\t\t\t\t\t\t\t? deps.workerAgentControl.interruptWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t\t: deps.workerAgentControl.interruptWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.interrupted\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} interrupted; resume preserves its admitted state`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not interrupted (${outcome.reason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: { started: outcome.interrupted, action, agentId, skipReason: outcome.reason },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (action === \"resume\") {\n\t\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\t\treturn invalid(\"delegate resume is unavailable\", {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tconst outcome = deps.callerAgentId\n\t\t\t\t\t\t\t? deps.workerAgentControl.resumeWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })\n\t\t\t\t\t\t\t: deps.workerAgentControl.resumeWorkerAgent(agentId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\t\ttext: outcome.started\n\t\t\t\t\t\t\t\t\t\t? `worker ${agentId} resumed with its admitted transcript and authority`\n\t\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not resumed (${outcome.skipReason ?? \"unknown\"})`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: outcome.started,\n\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\t\tlaneId: outcome.record?.laneId,\n\t\t\t\t\t\t\t\tstatus: outcome.record?.status,\n\t\t\t\t\t\t\t\tskipReason: outcome.skipReason,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (!deps.workerAgentControl)\n\t\t\t\t\t\treturn invalid(\"delegate cancel is unavailable\", {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tskipReason: \"worker_agent_control_unavailable\",\n\t\t\t\t\t\t});\n\t\t\t\t\tconst cancelled = deps.callerAgentId\n\t\t\t\t\t\t? deps.workerAgentControl.cancelWorkerAgent(agentId, undefined, {\n\t\t\t\t\t\t\t\tcallerAgentId: deps.callerAgentId,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: deps.workerAgentControl.cancelWorkerAgent(agentId);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: cancelled\n\t\t\t\t\t\t\t\t\t? `worker ${agentId} cancelled for its current task`\n\t\t\t\t\t\t\t\t\t: `worker ${agentId} was not cancelled`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: Boolean(cancelled),\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tagentId,\n\t\t\t\t\t\t\tlaneId: cancelled?.laneId,\n\t\t\t\t\t\t\tstatus: cancelled?.status,\n\t\t\t\t\t\t\treasonCode: cancelled?.reasonCode,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (deps.callerAgentId) {\n\t\t\t\t\treturn invalid(\n\t\t\t\t\t\t\"Subagent worker delegation is disabled (1-level nesting maximum). Only the root orchestrator may spawn worker agents.\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\tskipReason: \"subagent_delegation_disabled\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst instructions = input.instructions?.trim();\n\t\t\t\tif (!instructions)\n\t\t\t\t\treturn invalid(\"delegate start requires instructions\", {\n\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tskipReason: \"missing_instructions\",\n\t\t\t\t\t});\n\t\t\t\tconst profileId = input.profileId?.trim();\n\t\t\t\tconst request = {\n\t\t\t\t\tinstructions,\n\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t...(input.authority ? { authority: structuredClone(input.authority) } : {}),\n\t\t\t\t};\n\t\t\t\tif (deps.startWorkerDelegation) {\n\t\t\t\t\tconst started = deps.startWorkerDelegation(request);\n\t\t\t\t\tif (!started.started) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${started.skipReason}` }],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\t\tskipReason: started.skipReason,\n\t\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\t\ttext: `delegate started (${started.record.status}) — stable agentId ${started.record.laneId}, task laneId ${started.record.laneId}; the owning parent will receive its terminal handoff, then read exact evidence with transcript or foreground delegate_status`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\t\t...((started.record.profileId ?? profileId)\n\t\t\t\t\t\t\t\t? { profileId: started.record.profileId ?? profileId }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\tagentId: started.record.laneId,\n\t\t\t\t\t\t\tlaneId: started.record.laneId,\n\t\t\t\t\t\t\t...(started.record.label ? { label: started.record.label } : {}),\n\t\t\t\t\t\t\tstatus: started.record.status,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst run = await deps.runWorkerDelegation(request);\n\t\t\t\tif (!run.started) {\n\t\t\t\t\tconst reason = run.skipReason ?? \"unknown\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `delegate skipped: ${reason}` }],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\tstarted: false,\n\t\t\t\t\t\t\tskipReason: reason,\n\t\t\t\t\t\t\t...(profileId ? { profileId } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst outcome = run.outcome;\n\t\t\t\tconst lines: string[] = [\n\t\t\t\t\t`delegate ${run.record?.status ?? \"unknown\"}${run.record?.reasonCode ? ` (${run.record.reasonCode})` : \"\"}`,\n\t\t\t\t];\n\t\t\t\tif (outcome) {\n\t\t\t\t\tlines.push(\n\t\t\t\t\t\t`accepted: ${outcome.accepted} [${outcome.acceptance.outcome}/${outcome.acceptance.reasonCode}]`,\n\t\t\t\t\t\t\"Worker output (UNTRUSTED - verify before acting on it):\",\n\t\t\t\t\t\toutcome.claim.summary.slice(0, 8_000),\n\t\t\t\t\t);\n\t\t\t\t\tif (outcome.claim.blockers && outcome.claim.blockers.length > 0) {\n\t\t\t\t\t\tlines.push(\n\t\t\t\t\t\t\t`Blockers: ${outcome.claim.blockers\n\t\t\t\t\t\t\t\t.slice(0, 16)\n\t\t\t\t\t\t\t\t.map((blocker) => blocker.slice(0, 512))\n\t\t\t\t\t\t\t\t.join(\"; \")}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tfor (const finding of outcome.claim.evidence?.findings.slice(0, 16) ?? []) {\n\t\t\t\t\t\tlines.push(`- Finding: ${finding.summary.slice(0, 512)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: lines.join(\"\\n\").slice(0, MAX_DELEGATE_RESULT_CHARS) }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstarted: true,\n\t\t\t\t\t\tprofileId: run.record?.profileId ?? profileId,\n\t\t\t\t\t\tagentId: run.record?.laneId,\n\t\t\t\t\t\tlaneId: run.record?.laneId,\n\t\t\t\t\t\tlabel: run.record?.label,\n\t\t\t\t\t\tstatus: run.record?.status,\n\t\t\t\t\t\treasonCode: run.record?.reasonCode,\n\t\t\t\t\t\taccepted: outcome?.accepted,\n\t\t\t\t\t\tcostUsd: outcome?.costUsd,\n\t\t\t\t\t\tsummary: outcome?.claim.summary.slice(0, 8_000),\n\t\t\t\t\t\tblockers: outcome?.claim.blockers?.slice(0, 16),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst reason = (error instanceof Error ? error.message : String(error)).slice(0, MAX_DELEGATE_ERROR_CHARS);\n\t\t\t\treturn invalid(`delegate ${action} failed: ${reason}`.slice(0, 2_048), {\n\t\t\t\t\tstarted: false,\n\t\t\t\t\taction,\n\t\t\t\t\t...(input.agentId?.trim() ? { agentId: input.agentId.trim() } : {}),\n\t\t\t\t\tskipReason: \"worker_agent_control_error\",\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-custom-provider",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-custom-provider",
|
|
9
|
-
"version": "0.86.
|
|
9
|
+
"version": "0.86.3",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-sandbox",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-sandbox",
|
|
9
|
-
"version": "0.86.
|
|
9
|
+
"version": "0.86.3",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sandbox-runtime": "^0.0.26"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "0.86.
|
|
9
|
+
"version": "0.86.3",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-adaptative",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@caupulican/pi-adaptative",
|
|
9
|
-
"version": "0.86.
|
|
9
|
+
"version": "0.86.3",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@caupulican/pi-agent-core": "^0.86.
|
|
13
|
-
"@caupulican/pi-ai": "^0.86.
|
|
14
|
-
"@caupulican/pi-tui": "^0.86.
|
|
12
|
+
"@caupulican/pi-agent-core": "^0.86.3",
|
|
13
|
+
"@caupulican/pi-ai": "^0.86.3",
|
|
14
|
+
"@caupulican/pi-tui": "^0.86.3",
|
|
15
15
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
16
16
|
"chalk": "5.6.2",
|
|
17
17
|
"cross-spawn": "7.0.6",
|
|
@@ -547,11 +547,11 @@
|
|
|
547
547
|
}
|
|
548
548
|
},
|
|
549
549
|
"node_modules/@caupulican/pi-agent-core": {
|
|
550
|
-
"version": "0.86.
|
|
551
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.86.
|
|
550
|
+
"version": "0.86.3",
|
|
551
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.86.3.tgz",
|
|
552
552
|
"license": "MIT",
|
|
553
553
|
"dependencies": {
|
|
554
|
-
"@caupulican/pi-ai": "^0.86.
|
|
554
|
+
"@caupulican/pi-ai": "^0.86.3",
|
|
555
555
|
"ignore": "7.0.5",
|
|
556
556
|
"typebox": "1.1.38",
|
|
557
557
|
"yaml": "2.9.0"
|
|
@@ -561,8 +561,8 @@
|
|
|
561
561
|
}
|
|
562
562
|
},
|
|
563
563
|
"node_modules/@caupulican/pi-ai": {
|
|
564
|
-
"version": "0.86.
|
|
565
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.86.
|
|
564
|
+
"version": "0.86.3",
|
|
565
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.86.3.tgz",
|
|
566
566
|
"license": "MIT",
|
|
567
567
|
"dependencies": {
|
|
568
568
|
"@anthropic-ai/sdk": "0.91.1",
|
|
@@ -616,8 +616,8 @@
|
|
|
616
616
|
}
|
|
617
617
|
},
|
|
618
618
|
"node_modules/@caupulican/pi-tui": {
|
|
619
|
-
"version": "0.86.
|
|
620
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.86.
|
|
619
|
+
"version": "0.86.3",
|
|
620
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.86.3.tgz",
|
|
621
621
|
"license": "MIT",
|
|
622
622
|
"dependencies": {
|
|
623
623
|
"get-east-asian-width": "1.6.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-adaptative",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.3",
|
|
4
4
|
"description": "Adaptive fork of Pi coding agent for self-evolving agent harness experiments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"postinstall": "node scripts/postinstall-python-runtime.mjs"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@caupulican/pi-agent-core": "^0.86.
|
|
88
|
-
"@caupulican/pi-ai": "^0.86.
|
|
89
|
-
"@caupulican/pi-tui": "^0.86.
|
|
87
|
+
"@caupulican/pi-agent-core": "^0.86.3",
|
|
88
|
+
"@caupulican/pi-ai": "^0.86.3",
|
|
89
|
+
"@caupulican/pi-tui": "^0.86.3",
|
|
90
90
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
91
91
|
"chalk": "5.6.2",
|
|
92
92
|
"cross-spawn": "7.0.6",
|