@narumitw/pi-subagents 2.1.3 → 3.0.0

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 (314) hide show
  1. package/README.md +181 -1250
  2. package/dist/child-communication-bridge.ts +136 -0
  3. package/dist/child-communication-bridge.ts.map +7 -0
  4. package/dist/chunks/chunk-UKTWUQRM.js +667 -0
  5. package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
  6. package/dist/index.ts +1448 -1598
  7. package/dist/index.ts.map +4 -4
  8. package/docs/design-principles.md +31 -0
  9. package/docs/ipc-transport-idea.md +103 -0
  10. package/docs/tools.md +109 -0
  11. package/package.json +11 -19
  12. package/src/broker-credentials.ts +71 -0
  13. package/src/child-communication-bridge.ts +153 -0
  14. package/src/child-communication-tools.ts +147 -0
  15. package/src/completion-renderer.ts +60 -0
  16. package/src/index.ts +1 -1
  17. package/src/message-broker.ts +628 -0
  18. package/src/model-output.ts +42 -0
  19. package/src/process.ts +688 -0
  20. package/src/runtime.ts +538 -0
  21. package/src/subagents.ts +33 -34
  22. package/src/tools.ts +416 -0
  23. package/src/types.ts +85 -0
  24. package/src/widget.ts +130 -0
  25. package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
  26. package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
  27. package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
  28. package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
  29. package/dist/chunks/child-peer-bridge.ts +0 -108
  30. package/dist/chunks/child-peer-bridge.ts.map +0 -7
  31. package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
  32. package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
  33. package/dist/chunks/chunk-47SK2QYC.ts +0 -56
  34. package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
  35. package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
  36. package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
  37. package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
  38. package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
  39. package/dist/chunks/chunk-6H6TBBED.ts +0 -108
  40. package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
  41. package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
  42. package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
  43. package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
  44. package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
  45. package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
  46. package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
  47. package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
  48. package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
  49. package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
  50. package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
  51. package/dist/chunks/chunk-D4CR7T73.ts +0 -353
  52. package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
  53. package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
  54. package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
  55. package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
  56. package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
  57. package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
  58. package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
  59. package/dist/chunks/chunk-HA36LPCO.ts +0 -130
  60. package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
  61. package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
  62. package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
  63. package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
  64. package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
  65. package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
  66. package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
  67. package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
  68. package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
  69. package/dist/chunks/chunk-IWC32VPY.ts +0 -172
  70. package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
  71. package/dist/chunks/chunk-JSZIP73U.ts +0 -362
  72. package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
  73. package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
  74. package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
  75. package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
  76. package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
  77. package/dist/chunks/chunk-LASD73CM.ts +0 -339
  78. package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
  79. package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
  80. package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
  81. package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
  82. package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
  83. package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
  84. package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
  85. package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
  86. package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
  87. package/dist/chunks/chunk-NLT67IZS.ts +0 -322
  88. package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
  89. package/dist/chunks/chunk-NTRPLF46.ts +0 -63
  90. package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
  91. package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
  92. package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
  93. package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
  94. package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
  95. package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
  96. package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
  97. package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
  98. package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
  99. package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
  100. package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
  101. package/dist/chunks/chunk-RRR66UWR.ts +0 -28
  102. package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
  103. package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
  104. package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
  105. package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
  106. package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
  107. package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
  108. package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
  109. package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
  110. package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
  111. package/dist/chunks/chunk-TM2R67J3.ts +0 -52
  112. package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
  113. package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
  114. package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
  115. package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
  116. package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
  117. package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
  118. package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
  119. package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
  120. package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
  121. package/dist/chunks/chunk-X4NMONPE.ts +0 -73
  122. package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
  123. package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
  124. package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
  125. package/dist/chunks/chunk-YU53SHA7.ts +0 -328
  126. package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
  127. package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
  128. package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
  129. package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
  130. package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
  131. package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
  132. package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
  133. package/dist/chunks/consult-LJU3IQY5.ts +0 -519
  134. package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
  135. package/dist/chunks/context-QDKLVQXE.ts +0 -11
  136. package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
  137. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
  138. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
  139. package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
  140. package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
  141. package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
  142. package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
  143. package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
  144. package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
  145. package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
  146. package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
  147. package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
  148. package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
  149. package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
  150. package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
  151. package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
  152. package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
  153. package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
  154. package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
  155. package/dist/chunks/registry-BT54L6CY.ts +0 -1445
  156. package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
  157. package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
  158. package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
  159. package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
  160. package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
  161. package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
  162. package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
  163. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
  164. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
  165. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
  166. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
  167. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
  168. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
  169. package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
  170. package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
  171. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
  172. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
  173. package/dist/chunks/workspace-WDKLN72J.ts +0 -11
  174. package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
  175. package/docs/async-runtime-protocol.md +0 -84
  176. package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
  177. package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
  178. package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -153
  179. package/docs/pi-subagents-diagrams.md +0 -183
  180. package/src/adaptive-scheduler.ts +0 -224
  181. package/src/admission-benchmark.ts +0 -95
  182. package/src/admission-policy.ts +0 -78
  183. package/src/agent-projection.ts +0 -53
  184. package/src/agents/built-ins.ts +0 -71
  185. package/src/agents/catalog.ts +0 -241
  186. package/src/agents/discovery.ts +0 -265
  187. package/src/agents/types.ts +0 -100
  188. package/src/agents.ts +0 -51
  189. package/src/async-subagent-benchmark.ts +0 -532
  190. package/src/auto-transport.ts +0 -121
  191. package/src/blocking-status.ts +0 -63
  192. package/src/cached-module-loader.ts +0 -18
  193. package/src/capabilities.ts +0 -145
  194. package/src/capability-grant.ts +0 -115
  195. package/src/capability-router.ts +0 -107
  196. package/src/child-peer-bridge.ts +0 -124
  197. package/src/child-peer-tools.ts +0 -132
  198. package/src/completion-delivery.ts +0 -409
  199. package/src/completion-render.ts +0 -190
  200. package/src/completion-requirement.ts +0 -479
  201. package/src/completion-routing.ts +0 -24
  202. package/src/config-registration.ts +0 -114
  203. package/src/config-status.ts +0 -217
  204. package/src/config-ui.ts +0 -983
  205. package/src/consult-policy.ts +0 -15
  206. package/src/consult-registration.ts +0 -125
  207. package/src/consult-render.ts +0 -194
  208. package/src/consult-resources.ts +0 -51
  209. package/src/consult-tool.ts +0 -95
  210. package/src/consult.ts +0 -566
  211. package/src/context.ts +0 -126
  212. package/src/create-stateful-transport.ts +0 -157
  213. package/src/cwd-policy.ts +0 -183
  214. package/src/delegation-contract.ts +0 -463
  215. package/src/execution/budget.ts +0 -56
  216. package/src/execution/runtime-policy.ts +0 -19
  217. package/src/execution-plan.ts +0 -322
  218. package/src/execution-ui.ts +0 -259
  219. package/src/execution.ts +0 -1679
  220. package/src/in-process-transport.ts +0 -941
  221. package/src/inspect-registration.ts +0 -64
  222. package/src/inspect-render.ts +0 -334
  223. package/src/inspect-tool.ts +0 -45
  224. package/src/inspect.ts +0 -769
  225. package/src/integration-controller.ts +0 -98
  226. package/src/limits.ts +0 -75
  227. package/src/orchestration-metrics.ts +0 -116
  228. package/src/outcome.ts +0 -61
  229. package/src/panel-child-group.ts +0 -35
  230. package/src/panel-contract.ts +0 -343
  231. package/src/panel-evidence.ts +0 -59
  232. package/src/panel-execution.ts +0 -769
  233. package/src/panel-failure.ts +0 -56
  234. package/src/panel-planning.ts +0 -175
  235. package/src/panel-presets.ts +0 -3
  236. package/src/panel-prompts.ts +0 -132
  237. package/src/panel-reconciliation.ts +0 -57
  238. package/src/panel-render.ts +0 -103
  239. package/src/parallel-limit-ui.ts +0 -113
  240. package/src/params.ts +0 -278
  241. package/src/peer-communication.ts +0 -352
  242. package/src/peer-transport.ts +0 -49
  243. package/src/persistence.ts +0 -522
  244. package/src/pi-args.ts +0 -43
  245. package/src/pi-invocation.ts +0 -168
  246. package/src/process-control.ts +0 -43
  247. package/src/prompt-resources.ts +0 -38
  248. package/src/prompt-source-safety.ts +0 -48
  249. package/src/protocol.ts +0 -76
  250. package/src/registry-types.ts +0 -204
  251. package/src/registry.ts +0 -1698
  252. package/src/render-common.ts +0 -252
  253. package/src/render.ts +0 -704
  254. package/src/result-contract.ts +0 -431
  255. package/src/retained-semantic-state.ts +0 -100
  256. package/src/rpc-timeout-finalization.ts +0 -207
  257. package/src/rpc-transport-metadata.ts +0 -65
  258. package/src/rpc-transport.ts +0 -1035
  259. package/src/rpc-turn-capture.ts +0 -217
  260. package/src/runner-outcome.ts +0 -31
  261. package/src/runner-result.ts +0 -55
  262. package/src/runner-types.ts +0 -102
  263. package/src/runner-usage.ts +0 -48
  264. package/src/runner.ts +0 -866
  265. package/src/safe-text.ts +0 -67
  266. package/src/semantic-snapshot.ts +0 -214
  267. package/src/session-guidance-contract.ts +0 -399
  268. package/src/settings/inspection.ts +0 -302
  269. package/src/settings/schema.ts +0 -195
  270. package/src/settings-reader.ts +0 -215
  271. package/src/settings.ts +0 -452
  272. package/src/spawn-idempotency.ts +0 -68
  273. package/src/stateful-agent-view.ts +0 -85
  274. package/src/stateful-config.ts +0 -13
  275. package/src/stateful-guidance.ts +0 -29
  276. package/src/stateful-lifecycle.ts +0 -74
  277. package/src/stateful-limit-ui.ts +0 -249
  278. package/src/stateful-limits.ts +0 -96
  279. package/src/stateful-prompt.ts +0 -49
  280. package/src/stateful-registration.ts +0 -1320
  281. package/src/stateful-render.ts +0 -318
  282. package/src/stateful-safety.ts +0 -47
  283. package/src/stateful-tool-params.ts +0 -215
  284. package/src/stateful.ts +0 -12
  285. package/src/subagent-details.ts +0 -43
  286. package/src/subagents-extension.ts +0 -355
  287. package/src/subprocess-transport.ts +0 -145
  288. package/src/supervision.ts +0 -104
  289. package/src/task-path.ts +0 -65
  290. package/src/timeout-checkpoint.ts +0 -305
  291. package/src/timeout-finalization.ts +0 -75
  292. package/src/tool-schema-compatibility.ts +0 -73
  293. package/src/transport-types.ts +0 -74
  294. package/src/transport-ui.ts +0 -135
  295. package/src/transport.ts +0 -43
  296. package/src/turn-budget.ts +0 -109
  297. package/src/usage-format.ts +0 -42
  298. package/src/usage-recording-config.ts +0 -13
  299. package/src/usage-recording-store.ts +0 -183
  300. package/src/usage-recording.ts +0 -478
  301. package/src/verification-harness.ts +0 -516
  302. package/src/verification-policy.ts +0 -67
  303. package/src/verification-receipt.ts +0 -275
  304. package/src/verified-execution-benchmark.ts +0 -86
  305. package/src/verified-execution-contract.ts +0 -191
  306. package/src/verified-execution-schema.ts +0 -32
  307. package/src/work-item-ledger.ts +0 -1404
  308. package/src/work-item-persistence.ts +0 -254
  309. package/src/workflow-completion-controller.ts +0 -397
  310. package/src/workflow-planning.ts +0 -172
  311. package/src/workflow-tree-identity.ts +0 -289
  312. package/src/workflow-ui.ts +0 -69
  313. package/src/workflow-verification.ts +0 -296
  314. package/src/workspace.ts +0 -174
@@ -1,71 +0,0 @@
1
- /**
2
- * Built-in agent definitions and prompt construction.
3
- */
4
-
5
- import { type AgentCapabilityManifest, CAPABILITY_MANIFEST_VERSION } from "../capabilities.js";
6
- import type { AgentConfig } from "./types.js";
7
-
8
- export const BUILT_IN_AGENTS: AgentConfig[] = [
9
- {
10
- name: "explorer",
11
- description:
12
- "Read-only codebase exploration for specific questions; returns concise findings with paths and evidence.",
13
- tools: ["read", "grep", "find", "ls"],
14
- capabilityManifest: builtInManifest(["repository-search", "code-evidence"], "read", [
15
- "evidence-gathering",
16
- ]),
17
- thinkingLevel: "low",
18
- source: "built-in",
19
- filePath: "built-in:explorer",
20
- systemPrompt: [
21
- "You are an explorer subagent. Explore the codebase for specific, well-scoped questions and report grounded findings.",
22
- "Do not edit files, run shell commands, or use any tool outside the read-only inspection set.",
23
- "Do not install dependencies, run formatters, start servers, run tests, or execute long-running commands.",
24
- "Return concise bullets with exact file paths, symbols, and open questions.",
25
- ].join("\n"),
26
- },
27
- {
28
- name: "worker",
29
- description: "Bounded implementation and command-execution worker with clear ownership.",
30
- capabilityManifest: builtInManifest(
31
- ["implementation", "command-execution", "repository-modification"],
32
- "write",
33
- ),
34
- source: "built-in",
35
- filePath: "built-in:worker",
36
- systemPrompt: workerSystemPrompt(),
37
- },
38
- ];
39
-
40
- export function getBuiltInAgent(name: string): AgentConfig | undefined {
41
- const agent = BUILT_IN_AGENTS.find((candidate) => candidate.name === name);
42
- return agent ? structuredClone(agent) : undefined;
43
- }
44
-
45
- function builtInManifest(
46
- capabilities: string[],
47
- filesystem: "read" | "write",
48
- verificationRoles: string[] = [],
49
- ): AgentCapabilityManifest {
50
- return {
51
- version: CAPABILITY_MANIFEST_VERSION,
52
- capabilities,
53
- modalities: ["text"],
54
- resultFormats: ["text", "structured-v1", "structured-v2"],
55
- authority: { filesystem },
56
- verificationRoles,
57
- contextStrengths: ["repository"],
58
- costHint: filesystem === "read" ? "low" : "medium",
59
- latencyHint: filesystem === "read" ? "low" : "medium",
60
- limitations: [],
61
- };
62
- }
63
-
64
- function workerSystemPrompt(): string {
65
- return [
66
- "You are a focused worker subagent running in an isolated Pi child context.",
67
- "Complete only the bounded delegated implementation slice and respect its assigned file or responsibility ownership.",
68
- "Keep scope tight, avoid unrelated changes, and do not overwrite concurrent work outside your ownership.",
69
- "The main agent owns integration and final verification; report changed files, commands run, and remaining risks for that handoff.",
70
- ].join("\n");
71
- }
@@ -1,241 +0,0 @@
1
- /**
2
- * Bounded, sanitized model-facing agent catalog formatting.
3
- */
4
-
5
- import { BUILT_IN_AGENTS } from "./built-ins.js";
6
- import {
7
- type AgentDiscoveryOptions,
8
- type AgentDiscoveryResult,
9
- discoverAgents,
10
- } from "./discovery.js";
11
- import { type AgentConfig, resolveAgentToolNames, type SubagentSettings } from "./types.js";
12
-
13
- export function formatAgentList(
14
- agents: AgentConfig[],
15
- maxItems: number,
16
- ): { text: string; remaining: number } {
17
- if (agents.length === 0) return { text: "none", remaining: 0 };
18
- const listed = agents.slice(0, maxItems);
19
- const remaining = agents.length - listed.length;
20
- return {
21
- text: listed.map((a) => `${a.name} (${a.source}): ${a.description}`).join("; "),
22
- remaining,
23
- };
24
- }
25
-
26
- export interface AgentCatalog {
27
- /** The effective catalog for the default invocation scope. */
28
- user: AgentDiscoveryResult;
29
- /** The project-scope catalog; custom project definitions are loaded only after project trust. */
30
- project?: AgentDiscoveryResult;
31
- }
32
-
33
- export interface AgentCatalogFormatOptions {
34
- maxItems?: number;
35
- maxDescriptionLength?: number;
36
- maxCharacters?: number;
37
- }
38
-
39
- export interface AgentCatalogFormatResult {
40
- text: string;
41
- omitted: number;
42
- }
43
-
44
- export const DEFAULT_AGENT_CATALOG_MAX_ITEMS = 32;
45
- export const DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH = 240;
46
- export const DEFAULT_AGENT_CATALOG_MAX_CHARACTERS = 6_000;
47
- export const DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE = 128;
48
- export const DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES = 64 * 1024;
49
- export const DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE = 2 * 1024 * 1024;
50
-
51
- const BUILT_IN_AGENT_ORDER = new Map(BUILT_IN_AGENTS.map((agent, index) => [agent.name, index]));
52
-
53
- function compareCatalogAgents(left: AgentConfig, right: AgentConfig): number {
54
- const leftBuiltInOrder = BUILT_IN_AGENT_ORDER.get(left.name);
55
- const rightBuiltInOrder = BUILT_IN_AGENT_ORDER.get(right.name);
56
- if (leftBuiltInOrder !== undefined || rightBuiltInOrder !== undefined) {
57
- if (leftBuiltInOrder === undefined) return 1;
58
- if (rightBuiltInOrder === undefined) return -1;
59
- return leftBuiltInOrder - rightBuiltInOrder;
60
- }
61
- return left.name.localeCompare(right.name);
62
- }
63
-
64
- function normalizeCatalogDescription(description: string, maxLength: number): string {
65
- const normalized = description.replace(/\s+/gu, " ").trim();
66
- if (normalized.length <= maxLength) return normalized;
67
- const suffix = "…";
68
- return `${normalized.slice(0, Math.max(0, maxLength - suffix.length)).trimEnd()}${suffix}`;
69
- }
70
-
71
- type CatalogScope = "user" | "project" | "project-fallback";
72
-
73
- function formatDeclaredItems(items: readonly string[] | undefined): string {
74
- if (items === undefined) return "undeclared";
75
- return items.length > 0 ? items.join(", ") : "none";
76
- }
77
-
78
- function catalogAgentContractMetadata(agent: AgentConfig): string {
79
- const manifest = agent.capabilityManifest;
80
- return [
81
- `capabilities: ${formatDeclaredItems(manifest?.capabilities)}`,
82
- `tools: ${formatDeclaredItems(resolveAgentToolNames(agent.tools))}`,
83
- `filesystem: ${manifest?.authority?.filesystem ?? "undeclared"}`,
84
- `result formats: ${formatDeclaredItems(manifest?.resultFormats)}`,
85
- ].join("; ");
86
- }
87
-
88
- function catalogAgentLine(
89
- agent: AgentConfig,
90
- scope: CatalogScope,
91
- userNames: ReadonlySet<string>,
92
- maxDescriptionLength: number,
93
- ): string {
94
- const scopeLabel =
95
- scope === "user"
96
- ? 'agentScope: "user"'
97
- : scope === "project"
98
- ? 'requires agentScope: "project" or "both"'
99
- : 'requires agentScope: "project" ("both" selects the user definition)';
100
- const collision =
101
- scope !== "user" && userNames.has(agent.name)
102
- ? scope === "project"
103
- ? "; overrides the default user definition for project/both"
104
- : "; scope-specific fallback for the default user override"
105
- : "";
106
- return `- ${agent.name} [source: ${agent.source}; ${scopeLabel}${collision}] [${catalogAgentContractMetadata(agent)}] — ${normalizeCatalogDescription(agent.description, maxDescriptionLength)}`;
107
- }
108
-
109
- /**
110
- * Format the effective agent variants that the parent model can invoke.
111
- *
112
- * User-authored descriptions are prompt text, so this formatter deliberately normalizes and bounds
113
- * them. Project definitions are supplied separately by the caller so an untrusted project is never
114
- * read merely to build model-facing metadata.
115
- */
116
- export function formatAgentCatalog(
117
- catalog: AgentCatalog,
118
- options: AgentCatalogFormatOptions = {},
119
- ): AgentCatalogFormatResult {
120
- const maxItems = Math.max(0, options.maxItems ?? DEFAULT_AGENT_CATALOG_MAX_ITEMS);
121
- const maxDescriptionLength = Math.max(
122
- 1,
123
- options.maxDescriptionLength ?? DEFAULT_AGENT_CATALOG_MAX_DESCRIPTION_LENGTH,
124
- );
125
- const maxCharacters = Math.max(1, options.maxCharacters ?? DEFAULT_AGENT_CATALOG_MAX_CHARACTERS);
126
- const userDiscoveryIncomplete =
127
- (catalog.user.omittedAgentDefinitions ?? 0) > 0 ||
128
- catalog.user.metadataDiscoveryIncomplete === true;
129
- const projectDiscoveryIncomplete =
130
- (catalog.project?.omittedAgentDefinitions ?? 0) > 0 ||
131
- catalog.project?.metadataDiscoveryIncomplete === true;
132
- const discoveredUserAgents = [...catalog.user.agents].sort(compareCatalogAgents);
133
- const discoveredProjectScopeAgents = [...(catalog.project?.agents ?? [])].sort(
134
- compareCatalogAgents,
135
- );
136
- const userAgents = userDiscoveryIncomplete ? [] : discoveredUserAgents;
137
- const projectScopeAgents = projectDiscoveryIncomplete ? [] : discoveredProjectScopeAgents;
138
- const projectAgents = projectScopeAgents.filter((agent) => agent.source === "project");
139
- const discoveredUserByName = new Map(discoveredUserAgents.map((agent) => [agent.name, agent]));
140
- const userByName = new Map(userAgents.map((agent) => [agent.name, agent]));
141
- const userNames = new Set(userByName.keys());
142
- const potentialProjectFallbackAgents = discoveredProjectScopeAgents.filter(
143
- (agent) =>
144
- agent.source === "built-in" && discoveredUserByName.get(agent.name)?.source === "user",
145
- );
146
- const projectFallbackAgents =
147
- userDiscoveryIncomplete || projectDiscoveryIncomplete ? [] : potentialProjectFallbackAgents;
148
- const allEntries = [
149
- ...userAgents.map((agent) => ({ agent, scope: "user" as const })),
150
- ...projectAgents.map((agent) => ({ agent, scope: "project" as const })),
151
- ...projectFallbackAgents.map((agent) => ({ agent, scope: "project-fallback" as const })),
152
- ];
153
- const boundedEntries = allEntries.slice(0, maxItems);
154
- const suppressedMetadataEntries =
155
- (userDiscoveryIncomplete ? discoveredUserAgents.length : 0) +
156
- (projectDiscoveryIncomplete
157
- ? discoveredProjectScopeAgents.filter((agent) => agent.source === "project").length +
158
- potentialProjectFallbackAgents.length
159
- : 0);
160
- const discoveryOmissions =
161
- (catalog.user.omittedAgentDefinitions ?? 0) +
162
- (catalog.project?.omittedAgentDefinitions ?? 0) +
163
- suppressedMetadataEntries;
164
- const discoveryIncomplete =
165
- catalog.user.metadataDiscoveryIncomplete === true ||
166
- catalog.project?.metadataDiscoveryIncomplete === true;
167
-
168
- const render = (entries: typeof allEntries, omitted: number): string => {
169
- const lines = [
170
- "Available agent definitions (metadata only; runtime validation and trust remain authoritative).",
171
- "Use capability and tool identifiers exactly as shown when authoring enforced contracts.",
172
- "Enforced contract readPaths, writePaths, network, and secrets guarantees are unsupported.",
173
- ];
174
- const userLines = entries
175
- .filter((entry) => entry.scope === "user")
176
- .map((entry) => catalogAgentLine(entry.agent, entry.scope, userNames, maxDescriptionLength));
177
- if (userLines.length > 0) {
178
- lines.push('Default scope (agentScope: "user"):');
179
- lines.push(...userLines);
180
- }
181
- const projectLines = entries
182
- .filter((entry) => entry.scope !== "user")
183
- .map((entry) => catalogAgentLine(entry.agent, entry.scope, userNames, maxDescriptionLength));
184
- if (projectLines.length > 0) {
185
- lines.push("Trusted project/scope variants (use the required agentScope shown):");
186
- lines.push(...projectLines);
187
- }
188
- const collisionNames = entries
189
- .filter((entry) => entry.scope !== "user" && userNames.has(entry.agent.name))
190
- .map((entry) => entry.agent.name);
191
- if (collisionNames.length > 0 && projectLines.length > 0) {
192
- const precedence = entries
193
- .filter((entry) => entry.scope !== "user" && userNames.has(entry.agent.name))
194
- .map((entry) =>
195
- entry.scope === "project"
196
- ? `${entry.agent.name}: user with "user", project with "project"/"both"`
197
- : `${entry.agent.name}: user with "user"/"both", built-in with "project"`,
198
- );
199
- lines.push(`Same-name precedence: ${precedence.join("; ")}.`);
200
- }
201
- if (omitted > 0) {
202
- lines.push(
203
- `[${omitted} additional agent definition${omitted === 1 ? "" : "s"} omitted due to metadata bounds or incomplete discovery.]`,
204
- );
205
- }
206
- if (discoveryIncomplete) {
207
- lines.push("[Agent metadata discovery was incomplete; some definitions may be unavailable.]");
208
- }
209
- return lines.join("\n");
210
- };
211
-
212
- let listedCount = boundedEntries.length;
213
- let text = render(
214
- boundedEntries.slice(0, listedCount),
215
- allEntries.length - listedCount + discoveryOmissions,
216
- );
217
- while (text.length > maxCharacters && listedCount > 0) {
218
- listedCount -= 1;
219
- text = render(
220
- boundedEntries.slice(0, listedCount),
221
- allEntries.length - listedCount + discoveryOmissions,
222
- );
223
- }
224
- return { text, omitted: allEntries.length - listedCount + discoveryOmissions };
225
- }
226
-
227
- export function discoverAgentCatalog(
228
- cwd: string,
229
- projectTrusted: boolean,
230
- config?: SubagentSettings,
231
- ): AgentCatalog {
232
- const options: AgentDiscoveryOptions = {
233
- maxFiles: DEFAULT_AGENT_CATALOG_MAX_FILES_PER_SCOPE,
234
- maxFileBytes: DEFAULT_AGENT_CATALOG_MAX_FILE_BYTES,
235
- maxTotalBytes: DEFAULT_AGENT_CATALOG_MAX_TOTAL_BYTES_PER_SCOPE,
236
- };
237
- return {
238
- user: discoverAgents(cwd, "user", config, options),
239
- project: projectTrusted ? discoverAgents(cwd, "project", config, options) : undefined,
240
- };
241
- }
@@ -1,265 +0,0 @@
1
- /**
2
- * Filesystem and frontmatter discovery for user and trusted project agents.
3
- */
4
-
5
- import * as fs from "node:fs";
6
- import * as path from "node:path";
7
- import { CONFIG_DIR_NAME, getAgentDir, parseFrontmatter } from "@earendil-works/pi-coding-agent";
8
- import { normalizeCapabilityManifest } from "../capabilities.js";
9
- import { BUILT_IN_AGENTS } from "./built-ins.js";
10
- import type { AgentConfig, AgentScope, SubagentSettings } from "./types.js";
11
- import { isThinkingLevel } from "./types.js";
12
-
13
- export interface AgentDiscoveryResult {
14
- agents: AgentConfig[];
15
- projectAgentsDir: string | null;
16
- omittedAgentDefinitions?: number;
17
- metadataDiscoveryIncomplete?: boolean;
18
- }
19
-
20
- export interface AgentDiscoveryOptions {
21
- maxFiles?: number;
22
- maxFileBytes?: number;
23
- maxTotalBytes?: number;
24
- }
25
-
26
- interface LoadedAgents {
27
- agents: AgentConfig[];
28
- omittedAgentDefinitions: number;
29
- metadataDiscoveryIncomplete: boolean;
30
- }
31
-
32
- function readFileBoundedSync(
33
- filePath: string,
34
- maxBytes: number | undefined,
35
- ): { content?: string; bytes: number; limited: boolean } {
36
- if (maxBytes === undefined) {
37
- try {
38
- const content = fs.readFileSync(filePath, "utf-8");
39
- return { content, bytes: Buffer.byteLength(content), limited: false };
40
- } catch {
41
- return { bytes: 0, limited: false };
42
- }
43
- }
44
-
45
- const readLimit = Math.max(0, maxBytes);
46
- let fd: number | undefined;
47
- try {
48
- fd = fs.openSync(filePath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
49
- if (!fs.fstatSync(fd).isFile()) return { bytes: 0, limited: false };
50
- const buffer = Buffer.allocUnsafe(readLimit + 1);
51
- let offset = 0;
52
- while (offset < buffer.length) {
53
- const bytesRead = fs.readSync(fd, buffer, offset, buffer.length - offset, null);
54
- if (bytesRead === 0) break;
55
- offset += bytesRead;
56
- }
57
- if (offset > readLimit) return { bytes: offset, limited: true };
58
- return { content: buffer.subarray(0, offset).toString("utf-8"), bytes: offset, limited: false };
59
- } catch {
60
- return { bytes: 0, limited: false };
61
- } finally {
62
- if (fd !== undefined) fs.closeSync(fd);
63
- }
64
- }
65
-
66
- function loadAgentsFromDir(
67
- dir: string,
68
- source: "user" | "project",
69
- options: AgentDiscoveryOptions = {},
70
- ): LoadedAgents {
71
- const agents: AgentConfig[] = [];
72
- let omittedAgentDefinitions = 0;
73
-
74
- let entries: fs.Dirent[];
75
- try {
76
- entries = fs.readdirSync(dir, { withFileTypes: true });
77
- } catch (error) {
78
- return {
79
- agents,
80
- omittedAgentDefinitions,
81
- metadataDiscoveryIncomplete: (error as NodeJS.ErrnoException).code !== "ENOENT",
82
- };
83
- }
84
-
85
- const agentEntries = entries
86
- .filter((entry) => entry.name.endsWith(".md"))
87
- .filter((entry) => entry.isFile() || entry.isSymbolicLink());
88
- let totalBytes = 0;
89
-
90
- for (const [index, entry] of agentEntries.entries()) {
91
- if (options.maxFiles !== undefined && index >= options.maxFiles) {
92
- omittedAgentDefinitions += agentEntries.length - index;
93
- break;
94
- }
95
- const filePath = path.join(dir, entry.name);
96
- const remainingBytes =
97
- options.maxTotalBytes === undefined ? undefined : options.maxTotalBytes - totalBytes;
98
- if (remainingBytes !== undefined && remainingBytes <= 0) {
99
- omittedAgentDefinitions++;
100
- continue;
101
- }
102
- const maxBytes =
103
- options.maxFileBytes === undefined
104
- ? remainingBytes
105
- : remainingBytes === undefined
106
- ? options.maxFileBytes
107
- : Math.min(options.maxFileBytes, remainingBytes);
108
- const loaded = readFileBoundedSync(filePath, maxBytes);
109
- totalBytes += Math.min(loaded.bytes, maxBytes ?? loaded.bytes);
110
- if (loaded.limited || loaded.content === undefined) {
111
- if (loaded.limited) omittedAgentDefinitions++;
112
- continue;
113
- }
114
-
115
- const { frontmatter, body } = parseFrontmatter<Record<string, unknown>>(loaded.content);
116
-
117
- if (typeof frontmatter.name !== "string" || typeof frontmatter.description !== "string") {
118
- continue;
119
- }
120
-
121
- const hasTools = hasOwn(frontmatter, "tools");
122
- const rawTools = frontmatter.tools;
123
- let tools: string[] | undefined;
124
- if (hasTools) {
125
- if (rawTools === null) {
126
- tools = [];
127
- } else if (Array.isArray(rawTools)) {
128
- if (!rawTools.every((tool): tool is string => typeof tool === "string")) continue;
129
- tools = rawTools.map((tool) => tool.trim()).filter(Boolean);
130
- } else if (typeof rawTools === "string") {
131
- tools = rawTools
132
- .split(",")
133
- .map((tool) => tool.trim())
134
- .filter(Boolean);
135
- } else {
136
- continue;
137
- }
138
- }
139
-
140
- agents.push({
141
- name: frontmatter.name,
142
- description: frontmatter.description,
143
- ...(hasTools ? { tools: tools ?? [] } : {}),
144
- model: typeof frontmatter.model === "string" ? frontmatter.model : undefined,
145
- thinkingLevel: isThinkingLevel(frontmatter.thinkingLevel)
146
- ? frontmatter.thinkingLevel
147
- : undefined,
148
- capabilityManifest: normalizeCapabilityManifest(frontmatter.capabilityManifest),
149
- systemPrompt: body,
150
- source,
151
- filePath,
152
- });
153
- }
154
-
155
- return { agents, omittedAgentDefinitions, metadataDiscoveryIncomplete: false };
156
- }
157
-
158
- function isDirectory(p: string): boolean {
159
- try {
160
- return fs.statSync(p).isDirectory();
161
- } catch {
162
- return false;
163
- }
164
- }
165
-
166
- function findNearestProjectAgentsDir(cwd: string): string | null {
167
- let currentDir = cwd;
168
- while (true) {
169
- const candidate = path.join(currentDir, CONFIG_DIR_NAME, "agents");
170
- if (isDirectory(candidate)) return candidate;
171
-
172
- const parentDir = path.dirname(currentDir);
173
- if (parentDir === currentDir) return null;
174
- currentDir = parentDir;
175
- }
176
- }
177
-
178
- function hasOwn(obj: object, key: PropertyKey): boolean {
179
- return Object.hasOwn(obj, key);
180
- }
181
-
182
- function applyAgentOverride(
183
- agent: AgentConfig,
184
- override: NonNullable<SubagentSettings["agents"]>[string],
185
- ): AgentConfig {
186
- const nextAgent: AgentConfig = { ...agent };
187
- if (hasOwn(override, "tools")) nextAgent.tools = override.tools;
188
- if (hasOwn(override, "model")) {
189
- nextAgent.model = override.model === null ? undefined : override.model;
190
- }
191
- if (hasOwn(override, "thinkingLevel")) {
192
- nextAgent.thinkingLevel = override.thinkingLevel === null ? undefined : override.thinkingLevel;
193
- }
194
- if (hasOwn(override, "timeoutMs")) {
195
- nextAgent.timeoutMs = override.timeoutMs === null ? undefined : override.timeoutMs;
196
- }
197
- return nextAgent;
198
- }
199
-
200
- export function discoverAgents(
201
- cwd: string,
202
- scope: AgentScope,
203
- config?: SubagentSettings,
204
- options: AgentDiscoveryOptions = {},
205
- ): AgentDiscoveryResult {
206
- const userDir = path.join(getAgentDir(), "agents");
207
- const projectAgentsDir = findNearestProjectAgentsDir(cwd);
208
-
209
- const userLoaded =
210
- scope === "project"
211
- ? { agents: [], omittedAgentDefinitions: 0, metadataDiscoveryIncomplete: false }
212
- : loadAgentsFromDir(userDir, "user", options);
213
- const projectLoaded =
214
- scope === "user" || !projectAgentsDir
215
- ? { agents: [], omittedAgentDefinitions: 0, metadataDiscoveryIncomplete: false }
216
- : loadAgentsFromDir(projectAgentsDir, "project", options);
217
- const userAgents = userLoaded.agents;
218
- const projectAgents = projectLoaded.agents;
219
-
220
- const agentMap = new Map<string, AgentConfig>();
221
-
222
- // Lowest priority: built-ins are always available, then user agents, then
223
- // trusted project agents if requested. This mirrors the subagent boundary
224
- // pattern in ./src: stable built-ins plus overridable local definitions.
225
- for (const agent of BUILT_IN_AGENTS) agentMap.set(agent.name, agent);
226
-
227
- if (scope === "both") {
228
- for (const agent of userAgents) agentMap.set(agent.name, agent);
229
- for (const agent of projectAgents) agentMap.set(agent.name, agent);
230
- } else if (scope === "user") {
231
- for (const agent of userAgents) agentMap.set(agent.name, agent);
232
- } else {
233
- for (const agent of projectAgents) agentMap.set(agent.name, agent);
234
- }
235
-
236
- // Apply user-configured overrides (from /subagents → Agent tool settings) on top of
237
- // the final resolved agent map, regardless of agent source.
238
- const configuredAgents = config?.agents ?? {};
239
- for (const [name, override] of Object.entries(configuredAgents)) {
240
- const agent = agentMap.get(name);
241
- if (!agent) continue;
242
- agentMap.set(name, applyAgentOverride(agent, override));
243
- }
244
- const legacyScoutOverride = configuredAgents.scout;
245
- const explorerAgent = agentMap.get("explorer");
246
- if (
247
- legacyScoutOverride &&
248
- explorerAgent &&
249
- !hasOwn(configuredAgents, "explorer") &&
250
- !agentMap.has("scout")
251
- ) {
252
- agentMap.set("explorer", applyAgentOverride(explorerAgent, legacyScoutOverride));
253
- }
254
-
255
- const omittedAgentDefinitions =
256
- userLoaded.omittedAgentDefinitions + projectLoaded.omittedAgentDefinitions;
257
- const metadataDiscoveryIncomplete =
258
- userLoaded.metadataDiscoveryIncomplete || projectLoaded.metadataDiscoveryIncomplete;
259
- return {
260
- agents: Array.from(agentMap.values()),
261
- projectAgentsDir,
262
- ...(omittedAgentDefinitions > 0 ? { omittedAgentDefinitions } : {}),
263
- ...(metadataDiscoveryIncomplete ? { metadataDiscoveryIncomplete } : {}),
264
- };
265
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * Foundational agent and settings types with dependency-light validation helpers.
3
- */
4
-
5
- import type { AgentCapabilityManifest } from "../capabilities.js";
6
- import type { SubagentUsageRecordingSettings } from "../usage-recording-config.js";
7
-
8
- export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
9
-
10
- export type SubagentThinkingLevel = (typeof THINKING_LEVELS)[number];
11
-
12
- export function isThinkingLevel(value: unknown): value is SubagentThinkingLevel {
13
- return typeof value === "string" && THINKING_LEVELS.includes(value as SubagentThinkingLevel);
14
- }
15
-
16
- export type AgentScope = "user" | "project" | "both";
17
-
18
- export type AgentSource = "built-in" | "user" | "project";
19
-
20
- export const DEFAULT_PI_TOOL_NAMES = ["read", "bash", "edit", "write"] as const;
21
-
22
- export function resolveAgentToolNames(tools: readonly string[] | undefined): string[] {
23
- return [...new Set(tools ?? DEFAULT_PI_TOOL_NAMES)];
24
- }
25
-
26
- export interface AgentConfig {
27
- name: string;
28
- description: string;
29
- tools?: string[];
30
- model?: string;
31
- thinkingLevel?: SubagentThinkingLevel;
32
- timeoutMs?: number;
33
- capabilityManifest?: AgentCapabilityManifest;
34
- systemPrompt: string;
35
- source: AgentSource;
36
- filePath: string;
37
- }
38
-
39
- export interface SubagentAgentConfig {
40
- tools?: string[];
41
- model?: string | null;
42
- thinkingLevel?: SubagentThinkingLevel | null;
43
- timeoutMs?: number | null;
44
- }
45
-
46
- export type SubagentTransportKind = "subprocess" | "in-process" | "rpc" | "auto";
47
-
48
- export type CompletionDelivery = "next-turn" | "auto-resume";
49
-
50
- export const CONSULT_RESOURCE_POLICIES = ["project-context", "none", "all"] as const;
51
-
52
- export type ConsultResourcePolicy = (typeof CONSULT_RESOURCE_POLICIES)[number];
53
-
54
- export interface SubagentConsultSettings {
55
- resources?: ConsultResourcePolicy;
56
- }
57
-
58
- export const CONSULTATION_CWD_POLICIES = ["anywhere", "current-workspace"] as const;
59
- export type ConsultationCwdPolicy = (typeof CONSULTATION_CWD_POLICIES)[number];
60
-
61
- export const DELEGATION_CWD_POLICIES = [
62
- "trusted-targets",
63
- "current-workspace",
64
- "anywhere",
65
- ] as const;
66
- export type DelegationCwdPolicy = (typeof DELEGATION_CWD_POLICIES)[number];
67
-
68
- export interface SubagentCwdPolicySettings {
69
- consultation?: ConsultationCwdPolicy;
70
- delegation?: DelegationCwdPolicy;
71
- }
72
-
73
- export interface SubagentBlockingSettings {
74
- enabled?: boolean;
75
- maxParallelTasks?: number;
76
- }
77
-
78
- export interface SubagentRuntimeSettings {
79
- enabled?: boolean;
80
- transport?: SubagentTransportKind;
81
- completionDelivery?: CompletionDelivery;
82
- maxAgents?: number;
83
- maxActiveTurns?: number;
84
- maxDepth?: number;
85
- maxChildrenPerAgent?: number;
86
- maxMailboxMessages?: number;
87
- maxMailboxMessageBytes?: number;
88
- idleTtlMs?: number;
89
- retentionDays?: number;
90
- maxStoredAgents?: number;
91
- }
92
-
93
- export interface SubagentSettings {
94
- agents?: Record<string, SubagentAgentConfig>;
95
- blocking?: SubagentBlockingSettings;
96
- stateful?: SubagentRuntimeSettings;
97
- consult?: SubagentConsultSettings;
98
- cwdPolicy?: SubagentCwdPolicySettings;
99
- usageRecording?: SubagentUsageRecordingSettings;
100
- }