@caupulican/pi-adaptative 0.85.8 → 0.86.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/core/agent-paths.d.ts +6 -3
  3. package/dist/core/agent-paths.d.ts.map +1 -1
  4. package/dist/core/agent-paths.js +10 -3
  5. package/dist/core/agent-paths.js.map +1 -1
  6. package/dist/core/agent-session.d.ts +5 -2
  7. package/dist/core/agent-session.d.ts.map +1 -1
  8. package/dist/core/agent-session.js +7 -1
  9. package/dist/core/agent-session.js.map +1 -1
  10. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  11. package/dist/core/autonomy/bounded-completion.js +19 -8
  12. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  13. package/dist/core/autonomy/lane-tool-surface.d.ts +11 -5
  14. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  15. package/dist/core/autonomy/lane-tool-surface.js +34 -8
  16. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  17. package/dist/core/autonomy/subagent-prompt.d.ts +3 -3
  18. package/dist/core/autonomy/subagent-prompt.js +9 -9
  19. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  20. package/dist/core/background-lane-controller.d.ts +10 -8
  21. package/dist/core/background-lane-controller.d.ts.map +1 -1
  22. package/dist/core/background-lane-controller.js +23 -13
  23. package/dist/core/background-lane-controller.js.map +1 -1
  24. package/dist/core/bash-execution-controller.d.ts +4 -0
  25. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  26. package/dist/core/bash-execution-controller.js +11 -4
  27. package/dist/core/bash-execution-controller.js.map +1 -1
  28. package/dist/core/bash-executor.d.ts +2 -0
  29. package/dist/core/bash-executor.d.ts.map +1 -1
  30. package/dist/core/bash-executor.js +2 -1
  31. package/dist/core/bash-executor.js.map +1 -1
  32. package/dist/core/capability-contract.d.ts +1 -1
  33. package/dist/core/capability-contract.d.ts.map +1 -1
  34. package/dist/core/capability-contract.js +0 -1
  35. package/dist/core/capability-contract.js.map +1 -1
  36. package/dist/core/default-tool-surface.d.ts +1 -0
  37. package/dist/core/default-tool-surface.d.ts.map +1 -1
  38. package/dist/core/default-tool-surface.js +3 -2
  39. package/dist/core/default-tool-surface.js.map +1 -1
  40. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +27 -8
  41. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  42. package/dist/core/delegation/worker-agent-control-coordinator.js +191 -33
  43. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  44. package/dist/core/delegation/worker-agent-control.d.ts +45 -6
  45. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  46. package/dist/core/delegation/worker-agent-control.js +110 -13
  47. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  48. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  49. package/dist/core/delegation/worker-attempt-executor.js +177 -158
  50. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  51. package/dist/core/delegation/worker-authority-resolver.d.ts +23 -0
  52. package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -0
  53. package/dist/core/delegation/worker-authority-resolver.js +128 -0
  54. package/dist/core/delegation/worker-authority-resolver.js.map +1 -0
  55. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
  56. package/dist/core/delegation/worker-conversation-store.js +1 -1
  57. package/dist/core/delegation/worker-conversation-store.js.map +1 -1
  58. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -1
  59. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  60. package/dist/core/delegation/worker-delegation-controller.js +260 -87
  61. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  62. package/dist/core/delegation/worker-delegation-request.d.ts +25 -4
  63. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  64. package/dist/core/delegation/worker-delegation-request.js +90 -1
  65. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  66. package/dist/core/delegation/worker-execution-policy.d.ts +2 -0
  67. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  68. package/dist/core/delegation/worker-execution-policy.js +22 -12
  69. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  70. package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
  71. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  72. package/dist/core/delegation/worker-lifecycle.js +4 -2
  73. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  74. package/dist/core/delegation/worker-profile-resolver.d.ts +0 -2
  75. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  76. package/dist/core/delegation/worker-profile-resolver.js +8 -35
  77. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  78. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
  79. package/dist/core/delegation/worker-recovery-coordinator.js +1 -0
  80. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
  81. package/dist/core/delegation/worker-runner.d.ts +6 -1
  82. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  83. package/dist/core/delegation/worker-runner.js +20 -6
  84. package/dist/core/delegation/worker-runner.js.map +1 -1
  85. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +47 -0
  86. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -0
  87. package/dist/core/delegation/worker-tree-budget-coordinator.js +210 -0
  88. package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -0
  89. package/dist/core/memory/providers/file-store.d.ts +2 -0
  90. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  91. package/dist/core/memory/providers/file-store.js +22 -20
  92. package/dist/core/memory/providers/file-store.js.map +1 -1
  93. package/dist/core/models/runtime-process.d.ts.map +1 -1
  94. package/dist/core/models/runtime-process.js +5 -18
  95. package/dist/core/models/runtime-process.js.map +1 -1
  96. package/dist/core/orchestration/bounded-string-array.d.ts +11 -0
  97. package/dist/core/orchestration/bounded-string-array.d.ts.map +1 -0
  98. package/dist/core/orchestration/bounded-string-array.js +17 -0
  99. package/dist/core/orchestration/bounded-string-array.js.map +1 -0
  100. package/dist/core/orchestration/capability-gateway.d.ts +16 -0
  101. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  102. package/dist/core/orchestration/capability-gateway.js +38 -0
  103. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  104. package/dist/core/orchestration/contracts.d.ts +11 -3
  105. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  106. package/dist/core/orchestration/contracts.js +0 -1
  107. package/dist/core/orchestration/contracts.js.map +1 -1
  108. package/dist/core/orchestration/delegation-ledger.d.ts +1 -0
  109. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  110. package/dist/core/orchestration/delegation-ledger.js +3 -0
  111. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  112. package/dist/core/orchestration/event-store.d.ts +12 -10
  113. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  114. package/dist/core/orchestration/event-store.js +94 -104
  115. package/dist/core/orchestration/event-store.js.map +1 -1
  116. package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
  117. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  118. package/dist/core/orchestration/lane-tool-manifests.js +4 -1
  119. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  120. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  121. package/dist/core/orchestration/policy-compiler.js +8 -9
  122. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  123. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  124. package/dist/core/orchestration/profile-registry.js +4 -10
  125. package/dist/core/orchestration/profile-registry.js.map +1 -1
  126. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  127. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  128. package/dist/core/orchestration/task-runtime.js +58 -3
  129. package/dist/core/orchestration/task-runtime.js.map +1 -1
  130. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  131. package/dist/core/orchestration/worker-execution-contract.js +10 -17
  132. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  133. package/dist/core/risk-classifier.js +3 -3
  134. package/dist/core/risk-classifier.js.map +1 -1
  135. package/dist/core/runtime-builder.d.ts +4 -1
  136. package/dist/core/runtime-builder.d.ts.map +1 -1
  137. package/dist/core/runtime-builder.js +34 -15
  138. package/dist/core/runtime-builder.js.map +1 -1
  139. package/dist/core/secrets/bitwarden-credential-storage.d.ts +51 -0
  140. package/dist/core/secrets/bitwarden-credential-storage.d.ts.map +1 -0
  141. package/dist/core/secrets/bitwarden-credential-storage.js +345 -0
  142. package/dist/core/secrets/bitwarden-credential-storage.js.map +1 -0
  143. package/dist/core/secrets/credential-exposure-guard.d.ts +8 -4
  144. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  145. package/dist/core/secrets/credential-exposure-guard.js +30 -31
  146. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  147. package/dist/core/secrets/credential-manager.d.ts +109 -0
  148. package/dist/core/secrets/credential-manager.d.ts.map +1 -0
  149. package/dist/core/secrets/credential-manager.js +384 -0
  150. package/dist/core/secrets/credential-manager.js.map +1 -0
  151. package/dist/core/secrets/credential-project.d.ts +4 -0
  152. package/dist/core/secrets/credential-project.d.ts.map +1 -0
  153. package/dist/core/secrets/credential-project.js +145 -0
  154. package/dist/core/secrets/credential-project.js.map +1 -0
  155. package/dist/core/secrets/secret-dotenv.d.ts +1 -1
  156. package/dist/core/secrets/secret-dotenv.js +1 -1
  157. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  158. package/dist/core/settings-manager.d.ts +4 -2
  159. package/dist/core/settings-manager.d.ts.map +1 -1
  160. package/dist/core/settings-manager.js +9 -5
  161. package/dist/core/settings-manager.js.map +1 -1
  162. package/dist/core/slash-commands.d.ts.map +1 -1
  163. package/dist/core/slash-commands.js +1 -0
  164. package/dist/core/slash-commands.js.map +1 -1
  165. package/dist/core/system-prompt.js +1 -1
  166. package/dist/core/system-prompt.js.map +1 -1
  167. package/dist/core/tool-capability-policy.js +2 -2
  168. package/dist/core/tool-capability-policy.js.map +1 -1
  169. package/dist/core/tools/delegate.d.ts +29 -1
  170. package/dist/core/tools/delegate.d.ts.map +1 -1
  171. package/dist/core/tools/delegate.js +179 -28
  172. package/dist/core/tools/delegate.js.map +1 -1
  173. package/dist/core/tools/git-filter.d.ts +1 -0
  174. package/dist/core/tools/git-filter.d.ts.map +1 -1
  175. package/dist/core/tools/git-filter.js +1 -1
  176. package/dist/core/tools/git-filter.js.map +1 -1
  177. package/dist/core/tools/profile-writer.js +3 -3
  178. package/dist/core/tools/profile-writer.js.map +1 -1
  179. package/dist/core/tools/python.d.ts +2 -0
  180. package/dist/core/tools/python.d.ts.map +1 -1
  181. package/dist/core/tools/python.js +17 -12
  182. package/dist/core/tools/python.js.map +1 -1
  183. package/dist/core/tools/run-process.d.ts +2 -0
  184. package/dist/core/tools/run-process.d.ts.map +1 -1
  185. package/dist/core/tools/run-process.js +7 -3
  186. package/dist/core/tools/run-process.js.map +1 -1
  187. package/dist/core/tools/secret-store.d.ts +8 -18
  188. package/dist/core/tools/secret-store.d.ts.map +1 -1
  189. package/dist/core/tools/secret-store.js +83 -348
  190. package/dist/core/tools/secret-store.js.map +1 -1
  191. package/dist/index.d.ts +3 -1
  192. package/dist/index.d.ts.map +1 -1
  193. package/dist/index.js +3 -1
  194. package/dist/index.js.map +1 -1
  195. package/dist/migrations.d.ts.map +1 -1
  196. package/dist/migrations.js +38 -1
  197. package/dist/migrations.js.map +1 -1
  198. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  199. package/dist/modes/interactive/components/settings-selector.js +35 -14
  200. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  201. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  202. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  203. package/dist/modes/interactive/interactive-mode.js +26 -3
  204. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  205. package/dist/modes/interactive/secret-menu-controller.d.ts +21 -0
  206. package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -0
  207. package/dist/modes/interactive/secret-menu-controller.js +276 -0
  208. package/dist/modes/interactive/secret-menu-controller.js.map +1 -0
  209. package/dist/utils/tools-manager.d.ts +2 -1
  210. package/dist/utils/tools-manager.d.ts.map +1 -1
  211. package/dist/utils/tools-manager.js +43 -48
  212. package/dist/utils/tools-manager.js.map +1 -1
  213. package/dist/utils/zip-extractor.d.ts +8 -0
  214. package/dist/utils/zip-extractor.d.ts.map +1 -0
  215. package/dist/utils/zip-extractor.js +275 -0
  216. package/dist/utils/zip-extractor.js.map +1 -0
  217. package/docs/harness-architecture.md +34 -22
  218. package/docs/index.md +1 -1
  219. package/docs/resources.md +1 -1
  220. package/docs/settings.md +39 -103
  221. package/docs/usage.md +7 -5
  222. package/docs/worker-profiles.md +9 -7
  223. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  224. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  225. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  226. package/examples/extensions/sandbox/package-lock.json +2 -2
  227. package/examples/extensions/sandbox/package.json +1 -1
  228. package/examples/extensions/with-deps/package-lock.json +2 -2
  229. package/examples/extensions/with-deps/package.json +1 -1
  230. package/npm-shrinkwrap.json +12 -12
  231. package/package.json +4 -4
  232. package/dist/core/secrets/secret-vault-format.d.ts +0 -112
  233. package/dist/core/secrets/secret-vault-format.d.ts.map +0 -1
  234. package/dist/core/secrets/secret-vault-format.js +0 -396
  235. package/dist/core/secrets/secret-vault-format.js.map +0 -1
  236. package/dist/core/secrets/secret-vault.d.ts +0 -72
  237. package/dist/core/secrets/secret-vault.d.ts.map +0 -1
  238. package/dist/core/secrets/secret-vault.js +0 -663
  239. package/dist/core/secrets/secret-vault.js.map +0 -1
@@ -1,19 +1,43 @@
1
1
  import { Type } from "typebox";
2
+ import { HARNESS_CAPABILITIES, ORCHESTRATION_THINKING_LEVELS, WORKER_ROLES } from "../orchestration/contracts.js";
2
3
  import { emptyOrchestrationCall, renderOrchestrationToolResult, } from "./orchestration-panel.js";
3
4
  function createDelegateSchema() {
5
+ const authority = Type.Object({
6
+ role: Type.Optional(Type.Union(WORKER_ROLES.map((role) => Type.Literal(role)))),
7
+ model: Type.Optional(Type.Object({
8
+ provider: Type.String({ minLength: 1, maxLength: 128 }),
9
+ modelId: Type.String({ minLength: 1, maxLength: 512 }),
10
+ }, { additionalProperties: false })),
11
+ thinkingLevel: Type.Optional(Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level)))),
12
+ capabilities: Type.Optional(Type.Array(Type.Union(HARNESS_CAPABILITIES.map((capability) => Type.Literal(capability))), {
13
+ maxItems: 64,
14
+ })),
15
+ toolNames: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 512 }), { maxItems: 64 })),
16
+ readPaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),
17
+ writePaths: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 4_096 }), { maxItems: 64 })),
18
+ budget: Type.Optional(Type.Object({
19
+ maxTokens: Type.Optional(Type.Integer({ minimum: 0 })),
20
+ maxWallClockMs: Type.Optional(Type.Integer({ minimum: 0 })),
21
+ maxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
22
+ maxAttempts: Type.Optional(Type.Integer({ minimum: 0 })),
23
+ maxToolCalls: Type.Optional(Type.Integer({ minimum: 0 })),
24
+ requireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
25
+ }, { additionalProperties: false })),
26
+ }, { additionalProperties: false });
4
27
  return Type.Object({
5
28
  action: Type.Optional(Type.String({
6
29
  maxLength: 16,
7
- enum: ["start", "send", "follow_up", "interrupt", "resume", "cancel"],
8
- description: "Optional logical-agent action. Omit or use start to create a worker; send queues without waking; follow_up steers an active worker or wakes an idle one; interrupt is resumable; resume restores the exact admitted transcript/profile/model/resources under a fresh fence; cancel is terminal for the current task only.",
30
+ enum: ["start", "list", "transcript", "send", "follow_up", "wait", "interrupt", "resume", "cancel"],
31
+ description: "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.",
9
32
  })),
10
33
  profileId: Type.Optional(Type.String({
11
34
  maxLength: 512,
12
- description: "Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Regular sessions must omit this field and use the owner's configured default; only an active owner-authored orchestrator may select an allowlisted profile.",
35
+ description: "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.",
13
36
  })),
37
+ authority: Type.Optional(authority),
14
38
  instructions: Type.Optional(Type.String({
15
39
  maxLength: 16 * 1024,
16
- description: "The self-contained task for a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.",
40
+ description: "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.",
17
41
  })),
18
42
  agentId: Type.Optional(Type.String({
19
43
  maxLength: 512,
@@ -23,6 +47,12 @@ function createDelegateSchema() {
23
47
  maxLength: 4_096,
24
48
  description: "Bounded message for send or follow_up. Send only queues it; follow_up may wake idle work.",
25
49
  })),
50
+ threadId: Type.Optional(Type.String({ maxLength: 512, description: "Stable peer-message thread identity." })),
51
+ replyToMessageId: Type.Optional(Type.String({ maxLength: 512, description: "Message identity this peer response answers." })),
52
+ expectReply: Type.Optional(Type.Boolean({ description: "Mark this peer message as awaiting an explicit reply." })),
53
+ cursor: Type.Optional(Type.Integer({ minimum: 0, description: "Zero-based list or transcript page cursor." })),
54
+ maxMessages: Type.Optional(Type.Integer({ minimum: 1, maximum: 64, description: "Exact transcript messages to return per page." })),
55
+ timeoutMs: Type.Optional(Type.Integer({ minimum: 0, maximum: 300_000, description: "Event-driven wait timeout." })),
26
56
  }, { additionalProperties: false });
27
57
  }
28
58
  const delegateSchema = createDelegateSchema();
@@ -32,39 +62,43 @@ const MAX_DELEGATE_INSTRUCTIONS_CHARS = 16 * 1024;
32
62
  const MAX_DELEGATE_PROFILE_ID_CHARS = 512;
33
63
  const MAX_DELEGATE_AGENT_ID_CHARS = 512;
34
64
  const MAX_DELEGATE_MESSAGE_CHARS = 4_096;
65
+ const MAX_DELEGATE_CONTROL_ID_CHARS = 512;
35
66
  const MAX_PROFILE_GUIDELINE_CHARS = 4_096;
36
67
  const MAX_VISIBLE_ORCHESTRATION_PROFILES = 16;
37
68
  const MAX_PROFILE_GUIDELINE_FIELD_CHARS = 64;
38
69
  function isDelegateAction(value) {
39
70
  return (value === "start" ||
71
+ value === "list" ||
72
+ value === "transcript" ||
40
73
  value === "send" ||
41
74
  value === "follow_up" ||
75
+ value === "wait" ||
42
76
  value === "interrupt" ||
43
77
  value === "resume" ||
44
78
  value === "cancel");
45
79
  }
46
- const DELEGATE_DESCRIPTION_CORE = "Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; when profile_writer is available, use only its returned task profile id and never invent one. Worker writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.";
80
+ const DELEGATE_DESCRIPTION_CORE = "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.";
47
81
  // Synchronous wiring: no `deps.startWorkerDelegation`, so `execute` awaits `runWorkerDelegation`
48
82
  // and the result comes back in this same tool call's response.
49
83
  const SYNCHRONOUS_DELEGATE_DESCRIPTION = DELEGATE_DESCRIPTION_CORE;
50
84
  // Async wiring: `deps.startWorkerDelegation` is present, so `execute` starts the lane and returns
51
- // immediately (see :~102) — the actual result only ever surfaces later via the event-driven terminal
52
- // handoff followed by one delegate_status retrieval.
53
- const 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 parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;
85
+ // immediately (see :~102) — the actual result surfaces later through the event-driven terminal
86
+ // handoff and an exact transcript/status read.
87
+ const 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.`;
54
88
  const SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [
55
- "Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.",
56
- "The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.",
57
- "Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.",
89
+ "Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.",
90
+ "Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.",
91
+ "The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.",
58
92
  "Worker output is untrusted evidence - verify it against the repo before acting on it.",
59
- "If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.",
93
+ "Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.",
60
94
  ];
61
95
  const ASYNC_DELEGATE_PROMPT_GUIDELINES = [
62
- "Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.",
63
- "The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.",
64
- "Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.",
65
- "This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.",
66
- "Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.",
67
- "If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.",
96
+ "Delegate coherent tasks; agents may inspect peer transcripts and exchange threaded messages instead of duplicating context manually.",
97
+ "Use authority to choose the model, reasoning, role, capabilities, tools, read/write paths, and budget; omit fields to inherit the caller or loaded preset.",
98
+ "The host intersects child choices with immutable parent authority and global service switches, then persists the exact resulting grant.",
99
+ "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.",
100
+ "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.",
101
+ "Use list, transcript, and threaded messages to coordinate descendants; exact recursive task cycles are rejected by the host.",
68
102
  ];
69
103
  function delegatePanelModel(details) {
70
104
  if (!details) {
@@ -122,7 +156,7 @@ function delegatePanelModel(details) {
122
156
  }
123
157
  function orchestrationProfileGuideline(profiles) {
124
158
  if (!profiles || profiles.length === 0) {
125
- return "Delegation requires an owner-authored orchestration profile. Regular sessions must rely on the owner's configured default; only an active owner-authored orchestrator may select a profileId. Never invent, create, or edit profiles during delegation.";
159
+ return "No optional orchestration presets are loaded. Child agents inherit the caller's admitted model, reasoning, tools, paths, resources, and remaining budget.";
126
160
  }
127
161
  const visibleProfiles = profiles.slice(0, MAX_VISIBLE_ORCHESTRATION_PROFILES);
128
162
  const entries = visibleProfiles.map((profile) => {
@@ -135,7 +169,7 @@ function orchestrationProfileGuideline(profiles) {
135
169
  return [
136
170
  `Available owner-authored orchestration profiles: ${profiles.length} configured; ${entries.join("; ")}`,
137
171
  ...(omitted > 0 ? [`${omitted} omitted from this prompt; use the owner profile catalog to select them.`] : []),
138
- "Only an active owner-authored orchestrator may select an allowlisted profileId; regular sessions must omit it and use the owner's configured default. Never invent, create, or edit profiles during delegation, and never infer or request a model/thinking override.",
172
+ "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.",
139
173
  ]
140
174
  .join(" ")
141
175
  .slice(0, MAX_PROFILE_GUIDELINE_CHARS);
@@ -147,7 +181,7 @@ export function createDelegateToolDefinition(deps) {
147
181
  name: "delegate",
148
182
  label: "delegate",
149
183
  description: isAsyncWiring ? ASYNC_DELEGATE_DESCRIPTION : SYNCHRONOUS_DELEGATE_DESCRIPTION,
150
- promptSnippet: "Delegate a bounded task to an isolated, least-privilege worker lane.",
184
+ promptSnippet: "Create and coordinate an autonomous agent with inherited or explicitly selected authority.",
151
185
  promptGuidelines: [
152
186
  profileGuideline,
153
187
  ...(isAsyncWiring ? ASYNC_DELEGATE_PROMPT_GUIDELINES : SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES),
@@ -206,6 +240,29 @@ export function createDelegateToolDefinition(deps) {
206
240
  skipReason: "message_too_long",
207
241
  });
208
242
  }
243
+ for (const [label, value] of [
244
+ ["threadId", input.threadId],
245
+ ["replyToMessageId", input.replyToMessageId],
246
+ ]) {
247
+ if (value !== undefined && (value.length === 0 || value.length > MAX_DELEGATE_CONTROL_ID_CHARS)) {
248
+ return invalid(`delegate ${label} is invalid`, {
249
+ started: false,
250
+ action,
251
+ skipReason: "control_id_invalid",
252
+ });
253
+ }
254
+ }
255
+ if (input.cursor !== undefined && (!Number.isSafeInteger(input.cursor) || input.cursor < 0)) {
256
+ return invalid("delegate cursor is invalid", { started: false, action, skipReason: "cursor_invalid" });
257
+ }
258
+ if (input.maxMessages !== undefined &&
259
+ (!Number.isSafeInteger(input.maxMessages) || input.maxMessages < 1 || input.maxMessages > 64)) {
260
+ return invalid("delegate maxMessages is invalid", {
261
+ started: false,
262
+ action,
263
+ skipReason: "page_size_invalid",
264
+ });
265
+ }
209
266
  const requireAgentId = () => {
210
267
  const agentId = input.agentId?.trim();
211
268
  if (agentId)
@@ -213,6 +270,41 @@ export function createDelegateToolDefinition(deps) {
213
270
  return undefined;
214
271
  };
215
272
  try {
273
+ if (action === "list") {
274
+ if (!deps.workerAgentControl)
275
+ return invalid("delegate list is unavailable", {
276
+ started: false,
277
+ action,
278
+ skipReason: "worker_agent_control_unavailable",
279
+ });
280
+ const agents = deps.callerAgentId
281
+ ? deps.workerAgentControl.listWorkerAgents({ callerAgentId: deps.callerAgentId })
282
+ : deps.workerAgentControl.listWorkerAgents();
283
+ const cursor = input.cursor ?? 0;
284
+ if (cursor > agents.length)
285
+ return invalid("delegate list cursor exceeds the agent count", {
286
+ started: false,
287
+ action,
288
+ skipReason: "cursor_out_of_range",
289
+ });
290
+ const pageSize = input.maxMessages ?? 64;
291
+ const page = agents.slice(cursor, cursor + pageSize);
292
+ const nextCursor = cursor + page.length;
293
+ return {
294
+ content: [
295
+ {
296
+ type: "text",
297
+ text: JSON.stringify({
298
+ cursor,
299
+ totalAgents: agents.length,
300
+ agents: page,
301
+ ...(nextCursor < agents.length ? { nextCursor } : {}),
302
+ }),
303
+ },
304
+ ],
305
+ details: { started: true, action },
306
+ };
307
+ }
216
308
  if (action !== "start") {
217
309
  const agentId = requireAgentId();
218
310
  if (!agentId)
@@ -221,6 +313,42 @@ export function createDelegateToolDefinition(deps) {
221
313
  action,
222
314
  skipReason: "missing_agent_id",
223
315
  });
316
+ if (action === "transcript") {
317
+ if (!deps.workerAgentControl)
318
+ return invalid("delegate transcript is unavailable", {
319
+ started: false,
320
+ action,
321
+ agentId,
322
+ skipReason: "worker_agent_control_unavailable",
323
+ });
324
+ const page = deps.workerAgentControl.readWorkerAgentTranscript(agentId, {
325
+ ...(input.cursor !== undefined ? { cursor: input.cursor } : {}),
326
+ ...(input.maxMessages !== undefined ? { maxMessages: input.maxMessages } : {}),
327
+ ...(deps.callerAgentId ? { callerAgentId: deps.callerAgentId } : {}),
328
+ });
329
+ return {
330
+ content: [{ type: "text", text: JSON.stringify(page) }],
331
+ details: { started: true, action, agentId },
332
+ };
333
+ }
334
+ if (action === "wait") {
335
+ if (!deps.workerAgentControl)
336
+ return invalid("delegate wait is unavailable", {
337
+ started: false,
338
+ action,
339
+ agentId,
340
+ skipReason: "worker_agent_control_unavailable",
341
+ });
342
+ const waited = deps.callerAgentId
343
+ ? await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs, {
344
+ callerAgentId: deps.callerAgentId,
345
+ })
346
+ : await deps.workerAgentControl.waitForWorkerAgent(agentId, input.timeoutMs);
347
+ return {
348
+ content: [{ type: "text", text: `worker ${agentId} is ${waited.status}` }],
349
+ details: { started: true, action, agentId },
350
+ };
351
+ }
224
352
  if (action === "send" || action === "follow_up") {
225
353
  const message = input.message?.trim();
226
354
  if (!message)
@@ -230,6 +358,13 @@ export function createDelegateToolDefinition(deps) {
230
358
  agentId,
231
359
  skipReason: "missing_message",
232
360
  });
361
+ const messageOptions = {
362
+ ...(deps.callerAgentId ? { senderAgentId: deps.callerAgentId } : {}),
363
+ ...(input.threadId ? { threadId: input.threadId.trim() } : {}),
364
+ ...(input.replyToMessageId ? { replyToMessageId: input.replyToMessageId.trim() } : {}),
365
+ ...(input.expectReply === true ? { expectReply: true } : {}),
366
+ };
367
+ const hasMessageOptions = Object.keys(messageOptions).length > 0;
233
368
  if (action === "send") {
234
369
  if (!deps.workerAgentControl)
235
370
  return invalid("delegate send is unavailable", {
@@ -238,7 +373,9 @@ export function createDelegateToolDefinition(deps) {
238
373
  agentId,
239
374
  skipReason: "worker_agent_control_unavailable",
240
375
  });
241
- const outcome = deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);
376
+ const outcome = hasMessageOptions
377
+ ? deps.workerAgentControl.sendWorkerAgentMessage(agentId, message, messageOptions)
378
+ : deps.workerAgentControl.sendWorkerAgentMessage(agentId, message);
242
379
  return {
243
380
  content: [
244
381
  {
@@ -256,7 +393,9 @@ export function createDelegateToolDefinition(deps) {
256
393
  agentId,
257
394
  skipReason: "worker_agent_control_unavailable",
258
395
  });
259
- const outcome = deps.workerAgentControl.followUpWorkerAgent(agentId, message);
396
+ const outcome = hasMessageOptions
397
+ ? deps.workerAgentControl.followUpWorkerAgent(agentId, message, messageOptions)
398
+ : deps.workerAgentControl.followUpWorkerAgent(agentId, message);
260
399
  return {
261
400
  content: [
262
401
  {
@@ -282,7 +421,9 @@ export function createDelegateToolDefinition(deps) {
282
421
  agentId,
283
422
  skipReason: "worker_agent_control_unavailable",
284
423
  });
285
- const outcome = deps.workerAgentControl.interruptWorkerAgent(agentId);
424
+ const outcome = deps.callerAgentId
425
+ ? deps.workerAgentControl.interruptWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })
426
+ : deps.workerAgentControl.interruptWorkerAgent(agentId);
286
427
  return {
287
428
  content: [
288
429
  {
@@ -303,7 +444,9 @@ export function createDelegateToolDefinition(deps) {
303
444
  agentId,
304
445
  skipReason: "worker_agent_control_unavailable",
305
446
  });
306
- const outcome = deps.workerAgentControl.resumeWorkerAgent(agentId);
447
+ const outcome = deps.callerAgentId
448
+ ? deps.workerAgentControl.resumeWorkerAgent(agentId, { callerAgentId: deps.callerAgentId })
449
+ : deps.workerAgentControl.resumeWorkerAgent(agentId);
307
450
  return {
308
451
  content: [
309
452
  {
@@ -330,7 +473,11 @@ export function createDelegateToolDefinition(deps) {
330
473
  agentId,
331
474
  skipReason: "worker_agent_control_unavailable",
332
475
  });
333
- const cancelled = deps.workerAgentControl.cancelWorkerAgent(agentId);
476
+ const cancelled = deps.callerAgentId
477
+ ? deps.workerAgentControl.cancelWorkerAgent(agentId, undefined, {
478
+ callerAgentId: deps.callerAgentId,
479
+ })
480
+ : deps.workerAgentControl.cancelWorkerAgent(agentId);
334
481
  return {
335
482
  content: [
336
483
  {
@@ -358,7 +505,11 @@ export function createDelegateToolDefinition(deps) {
358
505
  skipReason: "missing_instructions",
359
506
  });
360
507
  const profileId = input.profileId?.trim();
361
- const request = { instructions, ...(profileId ? { profileId } : {}) };
508
+ const request = {
509
+ instructions,
510
+ ...(profileId ? { profileId } : {}),
511
+ ...(input.authority ? { authority: structuredClone(input.authority) } : {}),
512
+ };
362
513
  if (deps.startWorkerDelegation) {
363
514
  const started = deps.startWorkerDelegation(request);
364
515
  if (!started.started) {
@@ -375,7 +526,7 @@ export function createDelegateToolDefinition(deps) {
375
526
  content: [
376
527
  {
377
528
  type: "text",
378
- text: `delegate started (${started.record.status}) — stable agentId ${started.record.laneId}, task laneId ${started.record.laneId}; wait for its terminal handoff, then retrieve once with delegate_status`,
529
+ text: `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`,
379
530
  },
380
531
  ],
381
532
  details: {
@@ -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,EACN,sBAAsB,EAGtB,6BAA6B,GAC7B,MAAM,0BAA0B,CAAC;AAElC,SAAS,oBAAoB;IAC5B,OAAO,IAAI,CAAC,MAAM,CACjB;QACC,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,MAAM,CAAC;YACX,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC;YACrE,W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AAC;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 {\n\temptyOrchestrationCall,\n\ttype OrchestrationPanelModel,\n\ttype OrchestrationRowStatus,\n\trenderOrchestrationToolResult,\n} from \"./orchestration-panel.ts\";\n\nfunction createDelegateSchema() {\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\", \"send\", \"follow_up\", \"interrupt\", \"resume\", \"cancel\"],\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Optional logical-agent action. Omit or use start to create a worker; send queues without waking; follow_up steers an active worker or wakes an idle one; interrupt is resumable; resume restores the exact admitted transcript/profile/model/resources under a fresh fence; 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\"Owner-authored orchestration profile to use. The profile fixes role, model, thinking, tools, resources, budget, and concurrency. Regular sessions must omit this field and use the owner's configured default; only an active owner-authored orchestrator may select an allowlisted profile.\",\n\t\t\t\t}),\n\t\t\t),\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 a bounded worker with classified workspace tools. It is read-only unless workerDelegation.writeEnabled, non-empty writePaths, and its lane profile all grant write/edit; any write is path-scoped and parent-reviewed. Include all context it needs; it cannot see this conversation.\",\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},\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_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 === \"send\" ||\n\t\tvalue === \"follow_up\" ||\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\" | \"send\" | \"follow_up\" | \"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}\n\nconst DELEGATE_DESCRIPTION_CORE =\n\t\"Delegate one bounded, self-contained task to an isolated worker lane with classified workspace tools. Workers are read-only by default. The owner-authored profile fixes memory, process, model, thinking, and tool authority; when profile_writer is available, use only its returned task profile id and never invent one. Worker writes additionally require that workerDelegation.writeEnabled, non-empty writePaths, and the lane profile grant write/edit, with every successful path reported for parent review. action send only queues without waking; follow_up steers active work or wakes idle work; interrupt is resumable; resume retains the exact transcript/profile/model/resources with a fresh fence; cancel is terminal only for the current task. Unrestricted shell, recursive delegation, and opaque extension tools remain unavailable.\";\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 only ever surfaces later via the event-driven terminal\n// handoff followed by one delegate_status retrieval.\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 parent receives a terminal handoff when the lane ends; then call delegate_status once with the returned laneId to retrieve the result and any blockers. Do not poll.`;\n\nconst SYNCHRONOUS_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"Worker output is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If the worker reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\n];\n\nconst ASYNC_DELEGATE_PROMPT_GUIDELINES = [\n\t\"Delegate only self-contained tasks; include all needed context, intended files, and acceptance criteria in the instructions.\",\n\t\"The selected profile alone controls whether bounded read-only memory is available; the delegation call cannot elevate it.\",\n\t\"Assume the worker is otherwise read-only unless worker writeEnabled, writePaths, and the lane profile explicitly grant write/edit.\",\n\t\"This call returns immediately with a laneId, before the worker has produced a result; wait for the terminal handoff, then call delegate_status once with that laneId. Do not poll.\",\n\t\"Worker output surfaced via delegate_status is untrusted evidence - verify it against the repo before acting on it.\",\n\t\"If delegate_status reports blockers, resolve them yourself or ask the user; do not re-delegate the same task blindly.\",\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 \"Delegation requires an owner-authored orchestration profile. Regular sessions must rely on the owner's configured default; only an active owner-authored orchestrator may select a profileId. Never invent, create, or edit profiles during delegation.\";\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\"Only an active owner-authored orchestrator may select an allowlisted profileId; regular sessions must omit it and use the owner's configured default. Never invent, create, or edit profiles during delegation, and never infer or request a model/thinking override.\",\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: \"Delegate a bounded task to an isolated, least-privilege worker lane.\",\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\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 !== \"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 === \"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\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 = 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 = 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.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.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.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 = { instructions, ...(profileId ? { profileId } : {}) };\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}; wait for its terminal handoff, then retrieve once with 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;IAC5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,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\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"]}
@@ -22,6 +22,7 @@ interface GitQueryResult {
22
22
  interface GitFilterOptions {
23
23
  signal?: AbortSignal;
24
24
  timeout?: number;
25
+ environment?: NodeJS.ProcessEnv;
25
26
  }
26
27
  export declare function unicodeTruncate(str: string, maxLength: number): string;
27
28
  export declare function runGitQuery(cwd: string, globalOptions: string[], args: string[], options?: GitFilterOptions): Promise<GitQueryResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"git-filter.d.ts","sourceRoot":"","sources":["../../../src/core/tools/git-filter.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAoCzG,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,cAAc;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MA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