@narumitw/pi-subagents 2.1.4 → 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 (312) hide show
  1. package/README.md +187 -1228
  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 -1614
  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 -139
  179. package/docs/pi-subagents-diagrams.md +0 -183
  180. package/src/adaptive-scheduler.ts +0 -224
  181. package/src/admission-policy.ts +0 -78
  182. package/src/agent-projection.ts +0 -53
  183. package/src/agents/built-ins.ts +0 -71
  184. package/src/agents/catalog.ts +0 -241
  185. package/src/agents/discovery.ts +0 -265
  186. package/src/agents/types.ts +0 -100
  187. package/src/agents.ts +0 -51
  188. package/src/auto-transport.ts +0 -121
  189. package/src/blocking-status.ts +0 -63
  190. package/src/cached-module-loader.ts +0 -18
  191. package/src/capabilities.ts +0 -145
  192. package/src/capability-grant.ts +0 -115
  193. package/src/capability-router.ts +0 -107
  194. package/src/child-peer-bridge.ts +0 -124
  195. package/src/child-peer-tools.ts +0 -132
  196. package/src/completion-delivery.ts +0 -409
  197. package/src/completion-render.ts +0 -190
  198. package/src/completion-requirement.ts +0 -479
  199. package/src/completion-routing.ts +0 -24
  200. package/src/config-registration.ts +0 -114
  201. package/src/config-status.ts +0 -217
  202. package/src/config-ui.ts +0 -983
  203. package/src/consult-policy.ts +0 -15
  204. package/src/consult-registration.ts +0 -125
  205. package/src/consult-render.ts +0 -194
  206. package/src/consult-resources.ts +0 -51
  207. package/src/consult-tool.ts +0 -95
  208. package/src/consult.ts +0 -566
  209. package/src/context.ts +0 -126
  210. package/src/create-stateful-transport.ts +0 -157
  211. package/src/cwd-policy.ts +0 -183
  212. package/src/delegation-contract.ts +0 -463
  213. package/src/execution/budget.ts +0 -56
  214. package/src/execution/runtime-policy.ts +0 -19
  215. package/src/execution-plan.ts +0 -322
  216. package/src/execution-ui.ts +0 -259
  217. package/src/execution.ts +0 -1679
  218. package/src/in-process-transport.ts +0 -941
  219. package/src/inspect-registration.ts +0 -64
  220. package/src/inspect-render.ts +0 -334
  221. package/src/inspect-tool.ts +0 -45
  222. package/src/inspect.ts +0 -769
  223. package/src/integration-controller.ts +0 -98
  224. package/src/limits.ts +0 -75
  225. package/src/orchestration-metrics.ts +0 -116
  226. package/src/outcome.ts +0 -61
  227. package/src/panel-child-group.ts +0 -35
  228. package/src/panel-contract.ts +0 -343
  229. package/src/panel-evidence.ts +0 -59
  230. package/src/panel-execution.ts +0 -769
  231. package/src/panel-failure.ts +0 -56
  232. package/src/panel-planning.ts +0 -175
  233. package/src/panel-presets.ts +0 -3
  234. package/src/panel-prompts.ts +0 -132
  235. package/src/panel-reconciliation.ts +0 -57
  236. package/src/panel-render.ts +0 -103
  237. package/src/parallel-limit-ui.ts +0 -113
  238. package/src/params.ts +0 -278
  239. package/src/peer-communication.ts +0 -352
  240. package/src/peer-transport.ts +0 -49
  241. package/src/persistence.ts +0 -522
  242. package/src/pi-args.ts +0 -43
  243. package/src/pi-invocation.ts +0 -168
  244. package/src/process-control.ts +0 -43
  245. package/src/prompt-resources.ts +0 -38
  246. package/src/prompt-source-safety.ts +0 -48
  247. package/src/protocol.ts +0 -76
  248. package/src/registry-types.ts +0 -204
  249. package/src/registry.ts +0 -1698
  250. package/src/render-common.ts +0 -252
  251. package/src/render.ts +0 -704
  252. package/src/result-contract.ts +0 -431
  253. package/src/retained-semantic-state.ts +0 -100
  254. package/src/rpc-timeout-finalization.ts +0 -207
  255. package/src/rpc-transport-metadata.ts +0 -65
  256. package/src/rpc-transport.ts +0 -1035
  257. package/src/rpc-turn-capture.ts +0 -217
  258. package/src/runner-outcome.ts +0 -31
  259. package/src/runner-result.ts +0 -55
  260. package/src/runner-types.ts +0 -102
  261. package/src/runner-usage.ts +0 -48
  262. package/src/runner.ts +0 -866
  263. package/src/safe-text.ts +0 -67
  264. package/src/semantic-snapshot.ts +0 -214
  265. package/src/session-guidance-contract.ts +0 -399
  266. package/src/settings/inspection.ts +0 -302
  267. package/src/settings/schema.ts +0 -195
  268. package/src/settings-reader.ts +0 -215
  269. package/src/settings.ts +0 -452
  270. package/src/spawn-idempotency.ts +0 -68
  271. package/src/stateful-agent-view.ts +0 -85
  272. package/src/stateful-config.ts +0 -13
  273. package/src/stateful-guidance.ts +0 -29
  274. package/src/stateful-lifecycle.ts +0 -74
  275. package/src/stateful-limit-ui.ts +0 -249
  276. package/src/stateful-limits.ts +0 -96
  277. package/src/stateful-prompt.ts +0 -49
  278. package/src/stateful-registration.ts +0 -1320
  279. package/src/stateful-render.ts +0 -318
  280. package/src/stateful-safety.ts +0 -47
  281. package/src/stateful-tool-params.ts +0 -215
  282. package/src/stateful.ts +0 -12
  283. package/src/subagent-details.ts +0 -43
  284. package/src/subagents-extension.ts +0 -372
  285. package/src/subprocess-transport.ts +0 -145
  286. package/src/supervision.ts +0 -104
  287. package/src/task-path.ts +0 -65
  288. package/src/timeout-checkpoint.ts +0 -305
  289. package/src/timeout-finalization.ts +0 -75
  290. package/src/tool-schema-compatibility.ts +0 -73
  291. package/src/transport-types.ts +0 -74
  292. package/src/transport-ui.ts +0 -135
  293. package/src/transport.ts +0 -43
  294. package/src/turn-budget.ts +0 -109
  295. package/src/usage-format.ts +0 -42
  296. package/src/usage-recording-config.ts +0 -13
  297. package/src/usage-recording-store.ts +0 -183
  298. package/src/usage-recording.ts +0 -478
  299. package/src/verification-harness.ts +0 -516
  300. package/src/verification-policy.ts +0 -67
  301. package/src/verification-receipt.ts +0 -275
  302. package/src/verified-execution-benchmark.ts +0 -86
  303. package/src/verified-execution-contract.ts +0 -191
  304. package/src/verified-execution-schema.ts +0 -32
  305. package/src/work-item-ledger.ts +0 -1404
  306. package/src/work-item-persistence.ts +0 -254
  307. package/src/workflow-completion-controller.ts +0 -397
  308. package/src/workflow-planning.ts +0 -172
  309. package/src/workflow-tree-identity.ts +0 -289
  310. package/src/workflow-ui.ts +0 -69
  311. package/src/workflow-verification.ts +0 -296
  312. package/src/workspace.ts +0 -174
@@ -1,1212 +0,0 @@
1
- // @generated by scripts/build-runtime.mjs; do not edit.
2
- // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
- import "./chunk-PGLSFLYW.ts";
4
- import {
5
- formatStatefulAgentLine
6
- } from "./chunk-2LMJU25E.ts";
7
- import "./chunk-TZ34IQ3M.ts";
8
- import "./chunk-ILEQ27AL.ts";
9
- import "./chunk-P7OH4XMF.ts";
10
- import "./chunk-N7BLVXKK.ts";
11
- import "./chunk-ONDTY4EL.ts";
12
- import "./chunk-TM2R67J3.ts";
13
- import {
14
- discoverAgents
15
- } from "./chunk-LASD73CM.ts";
16
- import "./chunk-RSUXZD6S.ts";
17
- import {
18
- applyStatefulLimitSetting,
19
- completionLabel,
20
- consultResourceLabel,
21
- consultationCwdLabel,
22
- currentWorkflow,
23
- delegationCwdLabel,
24
- formatDetachedLimitSummary,
25
- formatEmptyStatefulRuntime,
26
- formatManagerSummary,
27
- helpLines,
28
- showSubagentHelp,
29
- showSubagentStatus,
30
- showWorkflowPreview,
31
- statefulLimitInputScreen,
32
- statefulLimitListScreen,
33
- statusLines,
34
- workflowLabel
35
- } from "./chunk-PBZMBTNJ.ts";
36
- import "./chunk-KMGKCEO4.ts";
37
- import {
38
- sameToolSet,
39
- uniqueToolNames,
40
- updateAgentSettingsPatch,
41
- updateAgentToolsSetting,
42
- updateBlockingMaxParallelTasksSetting,
43
- updateCompletionDeliverySetting,
44
- updateConsultResourceSetting,
45
- updateCwdPolicySetting,
46
- updateDelegationWorkflowSetting,
47
- updateStatefulTransportSetting,
48
- updateUsageRecordingSetting
49
- } from "./chunk-D4CR7T73.ts";
50
- import {
51
- USAGE_RECORDING_RETENTION_DAYS
52
- } from "./chunk-N2T5IN4X.ts";
53
- import {
54
- hasOwn,
55
- inspectBlockingParallelLimitSettings,
56
- inspectCompletionDeliverySettings,
57
- inspectConsultResourceSettings,
58
- inspectCwdPolicySettings,
59
- inspectDelegationWorkflowSettings,
60
- inspectStatefulTransportSettings,
61
- inspectUsageRecordingSettings,
62
- readSubagentSettings
63
- } from "./chunk-TMZRHIIK.ts";
64
- import {
65
- isStatefulLimitField
66
- } from "./chunk-VDG7LTYE.ts";
67
- import "./chunk-4AQSF7AS.ts";
68
- import "./chunk-YU53SHA7.ts";
69
- import "./chunk-LEOYDZI3.ts";
70
- import "./chunk-IWC32VPY.ts";
71
- import "./chunk-BFK2Z4ZF.ts";
72
- import "./chunk-NLT67IZS.ts";
73
- import {
74
- safeTerminalLine
75
- } from "./chunk-SWGQLFSD.ts";
76
- import "./chunk-JSZIP73U.ts";
77
- import {
78
- MAX_BLOCKING_PARALLEL_CONCURRENCY,
79
- MAX_CONFIGURABLE_PARALLEL_TASKS,
80
- MAX_SUBAGENT_TIMEOUT_MS
81
- } from "./chunk-H3FP6DLR.ts";
82
- import "./chunk-RRR66UWR.ts";
83
-
84
- // src/execution-ui.ts
85
- function executionAgentPickerScreen(agents) {
86
- const configured = readSubagentSettings()?.agents ?? {};
87
- return {
88
- kind: "actions",
89
- title: "Model, Thinking, and Time Limit",
90
- lines: ["Choose a subagent. A specific request can override these starting values."],
91
- items: [
92
- ...agents.map((agent) => {
93
- const value = configured[agent.name];
94
- return {
95
- id: agent.name,
96
- label: safeTerminalLine(agent.name),
97
- description: safeTerminalLine(
98
- `${agent.source} \xB7 model ${value?.model ?? agent.model ?? "default"} \xB7 thinking ${value?.thinkingLevel ?? agent.thinkingLevel ?? "default"} \xB7 time limit ${value?.timeoutMs ?? agent.timeoutMs ?? "default"}`
99
- ),
100
- action: "pick-execution-agent"
101
- };
102
- }),
103
- { id: "back", label: "Back", action: "back" }
104
- ],
105
- hint: "back"
106
- };
107
- }
108
- function executionAgentScreen(agent) {
109
- if (!agent) {
110
- return {
111
- kind: "actions",
112
- title: "Model, Thinking, and Time Limit",
113
- lines: ["No subagent selected."],
114
- items: [{ id: "back", label: "Back", action: "back" }],
115
- hint: "back"
116
- };
117
- }
118
- const configured = readSubagentSettings()?.agents?.[agent.name];
119
- return {
120
- kind: "actions",
121
- title: `${safeTerminalLine(agent.name)} defaults`,
122
- lines: [
123
- `Model: ${safeTerminalLine(configured?.model ?? agent.model ?? "agent or Pi default")}`,
124
- `Thinking: ${configured?.thinkingLevel ?? agent.thinkingLevel ?? "agent or Pi default"}`,
125
- `Time limit: ${configured?.timeoutMs ?? agent.timeoutMs ?? "agent or Pi default"}`,
126
- "A specific subagent request can override these defaults."
127
- ],
128
- items: [
129
- { id: "thinking", label: "Thinking level", to: "execution-thinking" },
130
- { id: "model", label: "Model", to: "execution-model" },
131
- { id: "timeout", label: "Time limit", to: "execution-timeout" },
132
- {
133
- id: "reset",
134
- label: "Use agent or Pi defaults",
135
- description: "Remove custom model, thinking, and time limit without changing tools",
136
- action: "reset-agent-execution"
137
- },
138
- { id: "back", label: "Back", action: "back" }
139
- ],
140
- hint: "back"
141
- };
142
- }
143
- function executionThinkingScreen(agent) {
144
- const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : void 0;
145
- return {
146
- kind: "settings",
147
- title: agent ? `${safeTerminalLine(agent.name)} thinking` : "Agent thinking",
148
- items: agent ? [
149
- {
150
- id: "thinking",
151
- label: "Default thinking level",
152
- description: "A specific subagent request can override this value.",
153
- currentValue: configured?.thinkingLevel ?? agent.thinkingLevel ?? "Use agent or Pi default",
154
- values: [
155
- "Use agent or Pi default",
156
- "off",
157
- "minimal",
158
- "low",
159
- "medium",
160
- "high",
161
- "xhigh",
162
- "max"
163
- ],
164
- action: "set-agent-thinking"
165
- }
166
- ] : [],
167
- hint: "back"
168
- };
169
- }
170
- function executionModelScreen(agent, ctx) {
171
- const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : void 0;
172
- const models = ctx.modelRegistry.getAvailable().map((model) => `${model.provider}/${model.id}`).sort((left, right) => left.localeCompare(right)).slice(0, 100);
173
- return {
174
- kind: "actions",
175
- title: agent ? `${safeTerminalLine(agent.name)} model` : "Agent model",
176
- lines: [
177
- `Current: ${safeTerminalLine(configured?.model ?? agent?.model ?? "agent or Pi default")}`,
178
- "Choose an available model or enter a custom Pi model pattern."
179
- ],
180
- items: agent ? [
181
- {
182
- id: "model:__inherited__",
183
- label: "Use agent or Pi default",
184
- description: "Remove the custom model setting",
185
- action: "set-agent-model"
186
- },
187
- ...models.map((model) => ({
188
- id: `model:${model}`,
189
- label: safeTerminalLine(model),
190
- action: "set-agent-model"
191
- })),
192
- {
193
- id: "custom",
194
- label: "Custom model pattern",
195
- description: "Enter provider/model, a model pattern, or an optional :thinking suffix",
196
- to: "execution-model-input"
197
- },
198
- { id: "back", label: "Back", action: "back" }
199
- ] : [],
200
- hint: "back"
201
- };
202
- }
203
- function executionModelInputScreen(agent) {
204
- const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : void 0;
205
- return {
206
- kind: "input",
207
- title: agent ? `${safeTerminalLine(agent.name)} model` : "Agent model",
208
- lines: [
209
- `Current: ${safeTerminalLine(configured?.model ?? agent?.model ?? "agent or Pi default")}`,
210
- "Enter a Pi CLI model pattern, including an optional :thinking suffix.",
211
- "Use agent or Pi defaults to remove this custom value."
212
- ],
213
- placeholder: "provider/model or model pattern",
214
- action: "set-agent-model",
215
- hint: "back"
216
- };
217
- }
218
- function executionTimeoutInputScreen(agent) {
219
- const configured = agent ? readSubagentSettings()?.agents?.[agent.name] : void 0;
220
- return {
221
- kind: "input",
222
- title: agent ? `${safeTerminalLine(agent.name)} time limit` : "Agent time limit",
223
- lines: [
224
- `Current: ${configured?.timeoutMs ?? agent?.timeoutMs ?? "agent or Pi default"}`,
225
- `Allowed: 1-${MAX_SUBAGENT_TIMEOUT_MS} milliseconds.`,
226
- "Use agent or Pi defaults to remove this custom value."
227
- ],
228
- placeholder: "Time limit in milliseconds",
229
- action: "set-agent-timeout",
230
- hint: "back"
231
- };
232
- }
233
- function applyAgentThinking(agent, value, ctx) {
234
- if (!agent) return { kind: "rejected" };
235
- const thinkingLevel = value === "Use agent or Pi default" ? void 0 : value;
236
- if (thinkingLevel !== void 0 && !["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(thinkingLevel)) {
237
- return { kind: "rejected" };
238
- }
239
- return saveAgentPatch(agent.name, { thinkingLevel }, ctx, "thinking level");
240
- }
241
- function applyAgentModel(agent, value, ctx) {
242
- if (!agent) return { kind: "rejected" };
243
- if (value === void 0) return saveAgentPatch(agent.name, { model: void 0 }, ctx, "model");
244
- const model = value.trim();
245
- if (!model || Buffer.byteLength(model, "utf8") > 1024 || hasTerminalControl(model)) {
246
- ctx.ui.notify("Model must contain 1-1024 UTF-8 bytes on one line.", "warning");
247
- return { kind: "rejected" };
248
- }
249
- return saveAgentPatch(agent.name, { model }, ctx, "model");
250
- }
251
- function applyAgentTimeout(agent, value, ctx) {
252
- if (!agent) return { kind: "rejected" };
253
- const normalized = value?.trim() ?? "";
254
- if (!/^\d+$/u.test(normalized)) {
255
- ctx.ui.notify("Time limit must be a whole number of milliseconds.", "warning");
256
- return { kind: "rejected" };
257
- }
258
- const timeoutMs = Number(normalized);
259
- if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > MAX_SUBAGENT_TIMEOUT_MS) {
260
- ctx.ui.notify(`Time limit must be between 1 and ${MAX_SUBAGENT_TIMEOUT_MS}.`, "warning");
261
- return { kind: "rejected" };
262
- }
263
- return saveAgentPatch(agent.name, { timeoutMs }, ctx, "timeout");
264
- }
265
- function resetAgentExecution(agent, ctx) {
266
- if (!agent) return { kind: "rejected" };
267
- return saveAgentPatch(
268
- agent.name,
269
- { model: void 0, thinkingLevel: void 0, timeoutMs: void 0 },
270
- ctx,
271
- "execution defaults"
272
- );
273
- }
274
- function saveAgentPatch(name, patch, ctx, label) {
275
- try {
276
- updateAgentSettingsPatch({ [name]: patch });
277
- ctx.ui.notify(`${safeTerminalLine(name)} ${label} saved.`, "info");
278
- return { kind: "back" };
279
- } catch (error) {
280
- ctx.ui.notify(
281
- `${safeTerminalLine(name)} ${label} was not saved: ${formatError(error)}`,
282
- "error"
283
- );
284
- return { kind: "rejected" };
285
- }
286
- }
287
- function hasTerminalControl(value) {
288
- return [...value].some((character) => {
289
- const code = character.codePointAt(0) ?? 0;
290
- return code <= 31 || code >= 127 && code <= 159;
291
- });
292
- }
293
- function formatError(error) {
294
- return safeTerminalLine(error instanceof Error ? error.message : String(error));
295
- }
296
-
297
- // src/parallel-limit-ui.ts
298
- function blockingParallelLimitScreen(runtime) {
299
- const limit = inspectBlockingParallelLimitSettings();
300
- return {
301
- kind: "input",
302
- title: "Blocking Worker Limit",
303
- lines: [
304
- "This applies only to requests that make Pi wait for delegated work.",
305
- `Current: ${runtime.getMaxParallelTasks()} subagents per blocking request`,
306
- `Allowed: 1-${MAX_CONFIGURABLE_PARALLEL_TASKS}`,
307
- `Pi still starts at most ${MAX_BLOCKING_PARALLEL_CONCURRENCY} of them at once.`,
308
- safeTerminalText(limit.path)
309
- ],
310
- placeholder: "Enter a whole number",
311
- action: "set-parallel-limit",
312
- hint: "back"
313
- };
314
- }
315
- function applyBlockingParallelLimitSetting(value, ctx, runtime) {
316
- const normalized = value?.trim() ?? "";
317
- if (!/^\d+$/u.test(normalized)) {
318
- notifyValidationError(ctx);
319
- return { kind: "rejected" };
320
- }
321
- const next = Number(normalized);
322
- if (!Number.isSafeInteger(next) || next < 1 || next > MAX_CONFIGURABLE_PARALLEL_TASKS) {
323
- notifyValidationError(ctx);
324
- return { kind: "rejected" };
325
- }
326
- const configured = inspectBlockingParallelLimitSettings();
327
- if (configured.error) {
328
- ctx.ui.notify(
329
- `Subagent settings cannot be edited: ${safeTerminalText(configured.error)}`,
330
- "error"
331
- );
332
- return { kind: "rejected" };
333
- }
334
- const previousRuntime = runtime.getMaxParallelTasks();
335
- const runtimeChanged = next !== previousRuntime;
336
- const settingsChanged = next !== configured.value;
337
- if (!runtimeChanged && !settingsChanged) return { kind: "back" };
338
- if (runtimeChanged) {
339
- try {
340
- runtime.setMaxParallelTasks(next);
341
- } catch (error) {
342
- ctx.ui.notify(
343
- `Parallel-worker limit was not applied; user settings are unchanged: ${formatError2(error)}`,
344
- "error"
345
- );
346
- return { kind: "rejected" };
347
- }
348
- }
349
- if (settingsChanged) {
350
- try {
351
- updateBlockingMaxParallelTasksSetting(next);
352
- } catch (saveError) {
353
- if (runtimeChanged) {
354
- try {
355
- runtime.setMaxParallelTasks(previousRuntime);
356
- } catch (rollbackError) {
357
- ctx.ui.notify(
358
- `Subagent settings were not saved, and the runtime rollback failed: ${formatError2(new AggregateError([saveError, rollbackError]))}`,
359
- "error"
360
- );
361
- return { kind: "rejected" };
362
- }
363
- }
364
- ctx.ui.notify(
365
- "Subagent settings were not saved; the previous runtime limit was restored.",
366
- "error"
367
- );
368
- return { kind: "rejected" };
369
- }
370
- }
371
- ctx.ui.notify(
372
- `${settingsChanged ? "Saved and " : ""}applied: maximum ${next} subagents per blocking request.`,
373
- "info"
374
- );
375
- return { kind: "back" };
376
- }
377
- function notifyValidationError(ctx) {
378
- ctx.ui.notify(
379
- `Blocking worker limit must be a whole number from 1 to ${MAX_CONFIGURABLE_PARALLEL_TASKS}.`,
380
- "warning"
381
- );
382
- }
383
- function safeTerminalText(value) {
384
- return value.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?");
385
- }
386
- function formatError2(error) {
387
- return safeTerminalText(error instanceof Error ? error.message : String(error));
388
- }
389
-
390
- // src/transport-ui.ts
391
- var TRANSPORT_OPTIONS = [
392
- {
393
- value: "subprocess",
394
- label: "Fresh process",
395
- description: "Start a separate Pi process for every turn. Most compatible, but slower for follow-ups."
396
- },
397
- {
398
- value: "in-process",
399
- label: "Inside Pi",
400
- description: "Run built-in tools inside Pi for faster follow-ups. Shares Pi's memory and crash boundary."
401
- },
402
- {
403
- value: "rpc",
404
- label: "Persistent process (RPC)",
405
- description: "Keep one separate Pi process per background subagent so follow-ups preserve history."
406
- },
407
- {
408
- value: "auto",
409
- label: "Automatic \xB7 Recommended",
410
- description: "Let Pi choose a compatible method for each subagent and its tools."
411
- }
412
- ];
413
- function transportSettingsScreen(runtime) {
414
- const configured = inspectStatefulTransportSettings();
415
- const current = runtime.getRuntimeStatus();
416
- return {
417
- kind: "actions",
418
- title: configured.error ? "Background Agent Transport \xB7 Read only" : "Background Agent Transport",
419
- lines: [
420
- "Advanced: choose how Pi hosts background subagents.",
421
- `Current session: ${transportLabel(current.transport)}`,
422
- `Configured after reload: ${transportLabel(configured.value)} (${configured.source})`,
423
- "Separate processes do not restrict filesystem or network access.",
424
- "Persistent process (RPC) supports built-in Pi tools and does not load child extensions.",
425
- ...configured.error ? [
426
- `Settings cannot be edited: ${safeTerminalLine(configured.error)}`,
427
- `Repair ${safeTerminalLine(configured.path)} and retry.`
428
- ] : []
429
- ],
430
- items: [
431
- ...configured.error ? [] : TRANSPORT_OPTIONS.map((option) => ({
432
- id: option.value,
433
- label: option.label,
434
- description: option.description,
435
- action: "set-transport"
436
- })),
437
- { id: "back", label: "Back", action: "back" }
438
- ],
439
- hint: "back"
440
- };
441
- }
442
- async function applyTransportSetting(value, ctx, runtime, signal, isCurrent) {
443
- if (!isTransport(value)) return { kind: "rejected" };
444
- const before = inspectStatefulTransportSettings();
445
- if (before.error) return { kind: "rejected" };
446
- if (value === before.value) return { kind: "stay" };
447
- const status = runtime.getRuntimeStatus();
448
- if (status.retainedAgents > 0) {
449
- ctx.ui.notify(
450
- `Cannot change transport while ${status.retainedAgents} subagent${status.retainedAgents === 1 ? " is" : "s are"} saved for follow-up. Clear Current subagents first.`,
451
- "warning"
452
- );
453
- return { kind: "rejected" };
454
- }
455
- const option = TRANSPORT_OPTIONS.find((candidate) => candidate.value === value);
456
- const confirmed = await ctx.ui.confirm(
457
- `Use ${transportLabel(value)} after reload?`,
458
- `${option?.description ?? ""}
459
-
460
- This saves the setting but does not reload Pi automatically.`,
461
- { signal }
462
- );
463
- if (signal.aborted || !isCurrent()) return { kind: "close" };
464
- if (!confirmed) return { kind: "rejected" };
465
- const after = inspectStatefulTransportSettings();
466
- if (after.error || after.value !== before.value || after.source !== before.source) {
467
- ctx.ui.notify("Transport settings changed while confirming; review again.", "warning");
468
- return { kind: "rejected" };
469
- }
470
- if (runtime.getRuntimeStatus().retainedAgents > 0) {
471
- ctx.ui.notify(
472
- "New subagents were saved for follow-up while confirming. Clear them before changing transport.",
473
- "warning"
474
- );
475
- return { kind: "rejected" };
476
- }
477
- try {
478
- updateStatefulTransportSetting(value);
479
- ctx.ui.notify(`Saved ${transportLabel(value)}. Run /reload when ready.`, "info");
480
- return { kind: "stay" };
481
- } catch (error) {
482
- ctx.ui.notify(
483
- `Transport was not saved; the previous setting remains: ${safeTerminalLine(error instanceof Error ? error.message : String(error))}`,
484
- "error"
485
- );
486
- return { kind: "rejected" };
487
- }
488
- }
489
- function transportLabel(value) {
490
- return TRANSPORT_OPTIONS.find((option) => option.value === value)?.label ?? value;
491
- }
492
- function isTransport(value) {
493
- return ["subprocess", "in-process", "rpc", "auto"].includes(value);
494
- }
495
-
496
- // src/config-ui.ts
497
- var SUBCOMMANDS = [
498
- { value: "settings", label: "settings", description: "Open grouped subagent settings" },
499
- { value: "status", label: "status", description: "Show detailed subagent diagnostics" },
500
- { value: "help", label: "help", description: "Show subagent first steps and safety help" }
501
- ];
502
- var TOOL_VIEWPORT_SIZE = 10;
503
- function registerSubagentConfigLifecycle(pi) {
504
- const owner = { generation: 0, controller: new AbortController() };
505
- pi.on("session_start", () => {
506
- owner.generation += 1;
507
- owner.controller.abort(new DOMException("Subagent session replaced", "AbortError"));
508
- owner.controller = new AbortController();
509
- });
510
- pi.on("session_shutdown", () => {
511
- owner.generation += 1;
512
- owner.controller.abort(new DOMException("Subagent session shut down", "AbortError"));
513
- });
514
- return owner;
515
- }
516
- function registerSubagentConfigCommand(pi, runtime, owner = registerSubagentConfigLifecycle(pi)) {
517
- registerSubagentPrimaryCommand(pi, runtime, owner);
518
- }
519
- function registerSubagentPrimaryCommand(pi, runtime, owner) {
520
- pi.registerCommand("subagents", {
521
- description: "Manage subagents, settings, diagnostics, and help",
522
- getArgumentCompletions(prefix) {
523
- const normalized = prefix.trim().toLowerCase();
524
- const matches = SUBCOMMANDS.filter((item) => item.value.startsWith(normalized));
525
- return matches.length > 0 ? matches : null;
526
- },
527
- async handler(args, ctx) {
528
- const subcommand = args.trim().toLowerCase();
529
- if (!subcommand) {
530
- await showSubagentManager(pi, ctx, runtime, owner);
531
- return;
532
- }
533
- switch (subcommand) {
534
- case "settings":
535
- await showSubagentSettings(pi, ctx, runtime, owner);
536
- return;
537
- case "status":
538
- showSubagentStatus(ctx, runtime);
539
- return;
540
- case "help":
541
- showSubagentHelp(ctx, runtime);
542
- return;
543
- default:
544
- if (ctx.mode === "tui" || ctx.hasUI) {
545
- ctx.ui.notify(`Unknown /subagents subcommand: ${subcommand}`, "warning");
546
- }
547
- }
548
- }
549
- });
550
- }
551
- async function showSubagentManager(pi, ctx, runtime, owner, start = "main") {
552
- if (ctx.mode !== "tui") {
553
- showSubagentStatus(ctx, runtime);
554
- return;
555
- }
556
- const generation = owner.generation;
557
- const isCurrent = () => generation === owner.generation && !owner.controller.signal.aborted;
558
- const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
559
- if (!isCurrent()) return;
560
- let availableAgents = discoverAgents(ctx.cwd, "user", readSubagentSettings() ?? {}).agents;
561
- let toolDraft;
562
- let selectedExecutionAgent;
563
- let selectedStatefulLimit = "maxAgents";
564
- const menu = defineMenu({
565
- start,
566
- screens: {
567
- main: () => {
568
- const status = runtime.getRuntimeStatus();
569
- const workflow = inspectDelegationWorkflowSettings();
570
- return {
571
- kind: "actions",
572
- title: "Subagents",
573
- lines: formatManagerSummary(runtime, status, workflow).split("\n"),
574
- items: [
575
- {
576
- id: "workflow",
577
- label: "How subagents run",
578
- description: "Choose whether Pi stays available while subagents work",
579
- to: "workflow"
580
- },
581
- {
582
- id: "agents",
583
- label: "Current subagents",
584
- description: `${status.activeAgents} working \xB7 ${status.retainedAgents} saved for follow-up`,
585
- to: "agents"
586
- },
587
- {
588
- id: "settings",
589
- label: "Settings",
590
- description: "Folders, completion, privacy, agent defaults, and advanced options",
591
- to: "settings-hub"
592
- },
593
- {
594
- id: "status",
595
- label: "Diagnostics",
596
- description: "Detailed runtime values, setting sources, and file paths",
597
- to: "status"
598
- },
599
- {
600
- id: "help",
601
- label: "Help",
602
- description: "First steps, settings behavior, commands, and safety",
603
- to: "help"
604
- }
605
- ],
606
- hint: "close"
607
- };
608
- },
609
- workflow: () => {
610
- const snapshot = inspectDelegationWorkflowSettings();
611
- const active = currentWorkflow(runtime, runtime.getRuntimeStatus());
612
- return {
613
- kind: "actions",
614
- title: "How Subagents Run",
615
- lines: [
616
- `Current: ${workflowLabel(active)}`,
617
- "Choose a workflow based on the tools and blocking behavior you need.",
618
- "The blocking subagent tool is deprecated and remains available only for compatibility.",
619
- "subagent_consult and subagent_await remain supported blocking helpers.",
620
- "For results needed in the current answer, enable automatic continuation in Settings.",
621
- ...snapshot.value !== active ? [`Configured after reload: ${workflowLabel(snapshot.value)}`] : [],
622
- ...snapshot.error ? [
623
- `Settings cannot be edited: ${safeTerminalLine(snapshot.error)}`,
624
- `Repair ${safeTerminalLine(snapshot.path)} and retry.`
625
- ] : []
626
- ],
627
- items: snapshot.error ? [] : [
628
- {
629
- id: "all",
630
- label: workflowLabel("all"),
631
- description: "Background agents plus deprecated subagent and supported blocking helpers",
632
- action: "set-workflow"
633
- },
634
- {
635
- id: "async-only",
636
- label: workflowLabel("async-only"),
637
- description: "Subagents work in the background while you continue using Pi",
638
- action: "set-workflow"
639
- },
640
- {
641
- id: "blocking-only",
642
- label: workflowLabel("blocking-only"),
643
- description: "No background agents; deprecated subagent plus read-only consultation",
644
- action: "set-workflow"
645
- }
646
- ],
647
- hint: "back"
648
- };
649
- },
650
- agents: () => {
651
- const agents = runtime.listAgents();
652
- const status = runtime.getRuntimeStatus();
653
- return {
654
- kind: "actions",
655
- title: "Current Subagents",
656
- lines: agents.length ? [
657
- "Working subagents and subagents saved for follow-up in this session.",
658
- ...agents.map(formatStatefulAgentLine)
659
- ] : [formatEmptyStatefulRuntime(status)],
660
- items: [
661
- ...agents.length > 0 ? [
662
- {
663
- id: "clear",
664
- label: "Clear current subagents",
665
- description: "Stop running work and remove subagents saved for follow-up",
666
- action: "clear-agents"
667
- }
668
- ] : [],
669
- { id: "back", label: "Back", action: "back" }
670
- ],
671
- hint: "back"
672
- };
673
- },
674
- "settings-hub": () => ({
675
- kind: "actions",
676
- title: "Subagent Settings",
677
- lines: [
678
- "Changes are saved immediately.",
679
- "Transport and background-agent limits take effect after /reload."
680
- ],
681
- items: [
682
- {
683
- id: "access",
684
- label: "Folders and trusted resources",
685
- description: "Where subagents can start and what trusted consultations can load",
686
- to: "access-settings"
687
- },
688
- {
689
- id: "behavior",
690
- label: "Completion and privacy",
691
- description: "What Pi does when work finishes and optional local recording",
692
- to: "behavior-settings"
693
- },
694
- {
695
- id: "agents",
696
- label: "Agent defaults",
697
- description: "Tools, model, thinking effort, and time limit for each subagent",
698
- to: "agent-settings"
699
- },
700
- {
701
- id: "runtime",
702
- label: "Advanced runtime settings",
703
- description: "Transport and capacity controls that most users can leave unchanged",
704
- to: "runtime-settings"
705
- },
706
- { id: "back", label: "Back", action: "back" }
707
- ],
708
- hint: "back"
709
- }),
710
- "access-settings": () => subagentAccessSettingsScreen(runtime),
711
- "behavior-settings": () => subagentBehaviorSettingsScreen(runtime),
712
- "agent-settings": () => ({
713
- kind: "actions",
714
- title: "Agent Defaults",
715
- lines: ["Choose the starting settings for each subagent."],
716
- items: [
717
- {
718
- id: "agent-tools",
719
- label: "Tool permissions",
720
- description: "Choose which tools each subagent may use",
721
- action: "load-agent-picker"
722
- },
723
- {
724
- id: "execution",
725
- label: "Model, thinking, and time limit",
726
- description: "Choose how each subagent starts unless a request overrides it",
727
- to: "execution-agent-picker"
728
- },
729
- { id: "back", label: "Back", action: "back" }
730
- ],
731
- hint: "back"
732
- }),
733
- "runtime-settings": () => {
734
- const limit = inspectBlockingParallelLimitSettings();
735
- return {
736
- kind: "actions",
737
- title: "Advanced Runtime Settings",
738
- lines: ["Most users can leave these settings unchanged."],
739
- items: [
740
- {
741
- id: "transport",
742
- label: "Transport",
743
- description: `How Pi hosts background subagents \xB7 Current: ${transportLabel(runtime.getRuntimeStatus().transport)}`,
744
- to: "transport"
745
- },
746
- {
747
- id: "parallel-limit",
748
- label: "Blocking worker limit",
749
- description: `Maximum subagents per blocking request \xB7 Current: ${runtime.getMaxParallelTasks()}`,
750
- to: "parallel-limit",
751
- disabled: limit.error !== void 0,
752
- disabledReason: limit.error ? `Repair ${safeTerminalLine(limit.path)} before editing this setting` : void 0
753
- },
754
- {
755
- id: "stateful-limits",
756
- label: "Background agent limits",
757
- description: formatDetachedLimitSummary(runtime.getRuntimeStatus()),
758
- to: "stateful-limits"
759
- },
760
- { id: "back", label: "Back", action: "back" }
761
- ],
762
- hint: "back"
763
- };
764
- },
765
- transport: () => transportSettingsScreen(runtime),
766
- "execution-agent-picker": () => executionAgentPickerScreen(availableAgents),
767
- "execution-agent": () => executionAgentScreen(selectedExecutionAgent),
768
- "execution-thinking": () => executionThinkingScreen(selectedExecutionAgent),
769
- "execution-model": () => executionModelScreen(selectedExecutionAgent, ctx),
770
- "execution-model-input": () => executionModelInputScreen(selectedExecutionAgent),
771
- "execution-timeout": () => executionTimeoutInputScreen(selectedExecutionAgent),
772
- "parallel-limit": () => blockingParallelLimitScreen(runtime),
773
- "stateful-limits": () => statefulLimitListScreen(runtime),
774
- "stateful-limit-input": () => statefulLimitInputScreen(selectedStatefulLimit, runtime),
775
- status: () => ({
776
- kind: "detail",
777
- title: "Subagent Diagnostics",
778
- lines: statusLines(runtime),
779
- hint: "back"
780
- }),
781
- help: () => ({
782
- kind: "detail",
783
- title: "Subagents Help",
784
- lines: helpLines(runtime),
785
- hint: "back"
786
- }),
787
- "agent-picker": () => {
788
- const settings = readSubagentSettings() ?? {};
789
- const configured = settings.agents ?? {};
790
- return {
791
- kind: "actions",
792
- title: "Tool Permissions",
793
- lines: ["Choose a subagent to change which tools it may use."],
794
- items: availableAgents.map((agent) => {
795
- const override = configured[agent.name];
796
- const hasOverride = override ? hasOwn(override, "tools") : false;
797
- const summary = hasOverride ? override?.tools && override.tools.length > 0 ? override.tools.join(", ") : "none" : "defaults";
798
- return {
799
- id: agent.name,
800
- label: safeTerminalLine(agent.name),
801
- description: safeTerminalLine(`${agent.source} \xB7 tools: ${summary}`),
802
- action: "pick-agent"
803
- };
804
- }),
805
- hint: "back"
806
- };
807
- },
808
- "tool-draft": () => ({
809
- kind: "multiSelect",
810
- title: toolDraft ? `${safeTerminalLine(toolDraft.agentName)} tools` : "Agent tools",
811
- enableSearch: true,
812
- lines: toolDraft ? [
813
- `Source: ${safeTerminalLine(toolDraft.agentSource)}`,
814
- "Toggle a draft, then Save changes."
815
- ] : ["No agent selected."],
816
- viewportSize: TOOL_VIEWPORT_SIZE,
817
- items: toolDraft?.orderedTools.map((name) => {
818
- const available = toolDraft?.allTools.includes(name) ?? false;
819
- return {
820
- id: name,
821
- label: safeTerminalLine(name),
822
- description: available ? "Available tool" : "Configured tool is not currently loaded",
823
- searchText: available ? "available tool" : "configured unavailable preserved",
824
- selected: toolDraft?.selected.has(name) ?? false,
825
- disabled: !available,
826
- disabledReason: available ? void 0 : "Unavailable; preserved until explicitly changed in JSON"
827
- };
828
- }) ?? [],
829
- action: "toggle-tool",
830
- actions: [
831
- { id: "save", label: "Save changes", action: "save-tools" },
832
- { id: "discard", label: "Discard draft", action: "discard-tools" }
833
- ],
834
- hint: "back",
835
- doneLabel: "Close without saving"
836
- })
837
- },
838
- actions: {
839
- "set-workflow": async ({ itemId, signal }) => {
840
- if (!isWorkflow(itemId)) return { kind: "rejected" };
841
- const snapshot = inspectDelegationWorkflowSettings();
842
- if (snapshot.error) return { kind: "rejected" };
843
- const active = currentWorkflow(runtime, runtime.getRuntimeStatus());
844
- if (itemId === active && itemId === snapshot.value) {
845
- ctx.ui.notify(`Subagents already use ${workflowLabel(itemId)}.`, "info");
846
- return { kind: "stay" };
847
- }
848
- const requiresReload = itemId !== active;
849
- if (requiresReload && blockReloadWithRetainedAgents(ctx, runtime)) {
850
- return { kind: "rejected" };
851
- }
852
- if (!await showWorkflowPreview(ctx, active, itemId, requiresReload, signal)) {
853
- return signal.aborted || !isCurrent() ? { kind: "close" } : { kind: "rejected" };
854
- }
855
- if (signal.aborted || !isCurrent()) return { kind: "close" };
856
- if (requiresReload && blockReloadWithRetainedAgents(ctx, runtime)) {
857
- return { kind: "rejected" };
858
- }
859
- try {
860
- updateDelegationWorkflowSetting(itemId);
861
- } catch (error) {
862
- ctx.ui.notify(
863
- `How subagents run was not saved: ${formatError3(error)}. The current choice is unchanged.`,
864
- "error"
865
- );
866
- return { kind: "rejected" };
867
- }
868
- if (!requiresReload) {
869
- ctx.ui.notify(
870
- `Saved ${workflowLabel(itemId)}. The current tool surface already matches.`,
871
- "info"
872
- );
873
- return { kind: "stay" };
874
- }
875
- ctx.ui.notify(
876
- `Saved ${workflowLabel(itemId)}. Reloading subagent tools\u2026 If the tool surface does not refresh, run /reload.`,
877
- "info"
878
- );
879
- await ctx.reload();
880
- return { kind: "close" };
881
- },
882
- "clear-agents": async ({ signal }) => {
883
- const agents = runtime.listAgents();
884
- if (agents.length === 0) return { kind: "stay" };
885
- const confirmed = await ctx.ui.confirm(
886
- "Clear current subagents?",
887
- `Stop work and remove ${agents.length} subagent${agents.length === 1 ? "" : "s"} saved for follow-up?`,
888
- { signal }
889
- );
890
- if (signal.aborted || !isCurrent()) return { kind: "close" };
891
- if (!confirmed) return { kind: "rejected" };
892
- if (runtime.listAgents().map((agent) => agent.id).join("\0") !== agents.map((agent) => agent.id).join("\0")) {
893
- ctx.ui.notify(
894
- "Current subagents changed while confirming; review the list again.",
895
- "warning"
896
- );
897
- return { kind: "rejected" };
898
- }
899
- const cleared = await runtime.clearAgents();
900
- if (signal.aborted || !isCurrent()) return { kind: "close" };
901
- ctx.ui.notify(`Cleared ${cleared} current subagent${cleared === 1 ? "" : "s"}.`, "info");
902
- return { kind: "stay" };
903
- },
904
- "set-transport": async ({ itemId, signal }) => applyTransportSetting(itemId, ctx, runtime, signal, isCurrent),
905
- "pick-execution-agent": async ({ itemId }) => {
906
- selectedExecutionAgent = availableAgents.find((agent) => agent.name === itemId);
907
- return selectedExecutionAgent ? { kind: "to", screen: "execution-agent" } : { kind: "rejected" };
908
- },
909
- "set-agent-thinking": async ({ value }) => applyAgentThinking(selectedExecutionAgent, value, ctx),
910
- "set-agent-model": async ({ itemId, value }) => {
911
- const selected = value ?? (itemId.startsWith("model:") ? itemId.slice(6) : void 0);
912
- return applyAgentModel(
913
- selectedExecutionAgent,
914
- selected === "__inherited__" ? void 0 : selected,
915
- ctx
916
- );
917
- },
918
- "set-agent-timeout": async ({ value }) => applyAgentTimeout(selectedExecutionAgent, value, ctx),
919
- "reset-agent-execution": async () => resetAgentExecution(selectedExecutionAgent, ctx),
920
- "set-parallel-limit": async ({ value }) => applyBlockingParallelLimitSetting(value, ctx, runtime),
921
- "pick-stateful-limit": async ({ itemId }) => {
922
- if (!isStatefulLimitField(itemId)) return { kind: "rejected" };
923
- selectedStatefulLimit = itemId;
924
- return { kind: "to", screen: "stateful-limit-input" };
925
- },
926
- "set-stateful-limit": async ({ value, signal }) => applyStatefulLimitSetting(selectedStatefulLimit, value, ctx, runtime, {
927
- signal,
928
- isCurrent
929
- }),
930
- "set-completion": async ({ value }) => applyCompletionSetting(value, ctx, runtime),
931
- "set-consult-resources": async ({ value }) => applyConsultResourceSetting(value, ctx, runtime),
932
- "set-consultation-cwd": async ({ value }) => applyConsultationCwdSetting(value, ctx, runtime),
933
- "set-delegation-cwd": async ({ value }) => applyDelegationCwdSetting(value, ctx, runtime),
934
- "set-usage-recording": async ({ value, signal }) => applyUsageRecordingSetting(value, ctx, runtime, { signal, isCurrent }),
935
- "load-agent-picker": async () => {
936
- availableAgents = discoverAgents(ctx.cwd, "user", readSubagentSettings() ?? {}).agents;
937
- if (availableAgents.length === 0) {
938
- ctx.ui.notify("No agents found", "warning");
939
- return { kind: "rejected" };
940
- }
941
- return { kind: "to", screen: "agent-picker" };
942
- },
943
- "pick-agent": async ({ itemId }) => {
944
- const agent = availableAgents.find((candidate) => candidate.name === itemId);
945
- if (!agent) return { kind: "rejected" };
946
- const settings = readSubagentSettings() ?? {};
947
- const configured = settings.agents?.[agent.name];
948
- const configuredTools = configured && hasOwn(configured, "tools") ? configured.tools ?? [] : void 0;
949
- const defaults = discoverAgents(ctx.cwd, "user").agents.find(
950
- (candidate) => candidate.name === agent.name
951
- )?.tools;
952
- const allTools = uniqueToolNames(pi.getAllTools().map((tool) => tool.name)).sort(
953
- (a, b) => a.localeCompare(b)
954
- );
955
- const selected = uniqueToolNames(configuredTools ?? defaults ?? allTools);
956
- const selectedSet = new Set(selected);
957
- toolDraft = {
958
- agentName: agent.name,
959
- agentSource: agent.source,
960
- allTools,
961
- defaultTools: defaults,
962
- orderedTools: [...selected, ...allTools.filter((name) => !selectedSet.has(name))],
963
- selected: selectedSet
964
- };
965
- return { kind: "to", screen: "tool-draft" };
966
- },
967
- "toggle-tool": async ({ itemId, selected }) => {
968
- if (!toolDraft?.allTools.includes(itemId)) return { kind: "rejected" };
969
- if (selected) toolDraft.selected.add(itemId);
970
- else toolDraft.selected.delete(itemId);
971
- return { kind: "stay" };
972
- },
973
- "save-tools": async () => {
974
- if (!toolDraft) return { kind: "rejected" };
975
- const selected = toolDraft.orderedTools.filter((name) => toolDraft?.selected.has(name));
976
- const restoredDefaults = toolDraft.defaultTools === void 0 ? sameToolSet(selected, toolDraft.allTools) : sameToolSet(selected, toolDraft.defaultTools);
977
- try {
978
- updateAgentToolsSetting(toolDraft.agentName, restoredDefaults ? void 0 : selected);
979
- } catch (error) {
980
- ctx.ui.notify(`Agent tool settings were not saved: ${formatError3(error)}`, "error");
981
- return { kind: "rejected" };
982
- }
983
- ctx.ui.notify(
984
- restoredDefaults ? `${safeTerminalLine(toolDraft.agentName)}: defaults restored` : `${safeTerminalLine(toolDraft.agentName)}: ${selected.length} tool${selected.length === 1 ? "" : "s"} configured`,
985
- "info"
986
- );
987
- toolDraft = void 0;
988
- return { kind: "back" };
989
- },
990
- "discard-tools": async () => {
991
- toolDraft = void 0;
992
- return { kind: "back" };
993
- },
994
- back: async () => ({ kind: "back" })
995
- }
996
- });
997
- await runMenu(ctx, menu, {
998
- getState: () => void 0,
999
- signal: owner.controller.signal,
1000
- isCurrent
1001
- });
1002
- }
1003
- async function showSubagentSettings(pi, ctx, runtime, owner) {
1004
- const snapshot = inspectConsultResourceSettings();
1005
- if (ctx.mode !== "tui") {
1006
- if (ctx.hasUI) {
1007
- ctx.ui.notify(
1008
- `User settings apply to this and future sessions. Edit settings manually: ${safeTerminalLine(snapshot.path)}`,
1009
- "info"
1010
- );
1011
- }
1012
- return;
1013
- }
1014
- await showSubagentManager(pi, ctx, runtime, owner, "settings-hub");
1015
- }
1016
- function subagentAccessSettingsScreen(runtime) {
1017
- const consult = inspectConsultResourceSettings();
1018
- const cwdPolicy = inspectCwdPolicySettings();
1019
- const error = consult.error ?? cwdPolicy.error;
1020
- return {
1021
- kind: "settings",
1022
- title: error ? "Folders and Trusted Resources \xB7 Read only" : "Folders and Trusted Resources",
1023
- lines: [
1024
- "Choose where subagents may start and what read-only consultations may load.",
1025
- "These settings do not restrict files, shell commands, network access, or OS permissions.",
1026
- "Manage saved folder trust with Pi /trust, then restart Pi.",
1027
- safeTerminalLine(consult.path),
1028
- ...error ? [`Settings cannot be edited: ${safeTerminalLine(error)}`] : []
1029
- ],
1030
- items: error ? [] : [
1031
- {
1032
- id: "consultationCwd",
1033
- label: "Where read-only consultations can start",
1034
- description: "Use only this workspace, or allow other folders without loading untrusted project resources.",
1035
- currentValue: consultationCwdLabel(runtime.getConsultationCwdPolicy()),
1036
- values: ["Any folder \xB7 no project resources when untrusted", "This workspace only"],
1037
- action: "set-consultation-cwd"
1038
- },
1039
- {
1040
- id: "delegationCwd",
1041
- label: "Where subagents can start",
1042
- description: "Limit subagents to this workspace, saved-trusted folders, or any folder Pi can access.",
1043
- currentValue: delegationCwdLabel(runtime.getDelegationCwdPolicy()),
1044
- values: [
1045
- "This workspace or saved-trusted folders",
1046
- "This workspace only",
1047
- "Any folder Pi can access"
1048
- ],
1049
- action: "set-delegation-cwd"
1050
- },
1051
- {
1052
- id: "consultResources",
1053
- label: "Resources for trusted read-only consultations",
1054
- description: "Choose how much project context, skills, and prompt guidance a trusted consultation may load.",
1055
- currentValue: consultResourceLabel(runtime.getConsultResourcePolicy()),
1056
- values: ["Project context only", "No project resources", "All trusted resources"],
1057
- action: "set-consult-resources"
1058
- }
1059
- ]
1060
- };
1061
- }
1062
- function subagentBehaviorSettingsScreen(runtime) {
1063
- const completion = inspectCompletionDeliverySettings();
1064
- const usageRecording = inspectUsageRecordingSettings();
1065
- const error = completion.error ?? usageRecording.error;
1066
- return {
1067
- kind: "settings",
1068
- title: error ? "Completion and Privacy \xB7 Read only" : "Completion and Privacy",
1069
- lines: [
1070
- "These changes apply immediately and to future sessions.",
1071
- safeTerminalLine(completion.path),
1072
- ...error ? [`Settings cannot be edited: ${safeTerminalLine(error)}`] : []
1073
- ],
1074
- items: error ? [] : [
1075
- {
1076
- id: "completionDelivery",
1077
- label: "When background work finishes",
1078
- description: "Wait for your next message, or steer results into active work and continue automatically from idle.",
1079
- currentValue: completionLabel(runtime.getCompletionDelivery()),
1080
- values: ["Wait for my next message", "Continue automatically when work finishes"],
1081
- action: "set-completion"
1082
- },
1083
- {
1084
- id: "usageRecording",
1085
- label: "Local usage recording",
1086
- description: `Optionally keep content-free timing and lifecycle events on this device for ${USAGE_RECORDING_RETENTION_DAYS} days.`,
1087
- currentValue: runtime.getUsageRecordingEnabled?.() ? "On \xB7 local only" : "Off",
1088
- values: ["Off", "On \xB7 local only"],
1089
- action: "set-usage-recording"
1090
- }
1091
- ]
1092
- };
1093
- }
1094
- async function applyUsageRecordingSetting(value, ctx, runtime, options) {
1095
- if (options.signal.aborted || !options.isCurrent()) return { kind: "close" };
1096
- const previous = runtime.getUsageRecordingEnabled?.() ?? false;
1097
- const next = value === "On \xB7 local only";
1098
- if (next === previous) return { kind: "stay" };
1099
- if (!runtime.setUsageRecordingEnabled) {
1100
- ctx.ui.notify("Usage recording is unavailable in this session.", "error");
1101
- return { kind: "rejected" };
1102
- }
1103
- try {
1104
- updateUsageRecordingSetting(next);
1105
- } catch (error) {
1106
- ctx.ui.notify(`Subagent settings were not saved: ${formatError3(error)}`, "error");
1107
- return { kind: "rejected" };
1108
- }
1109
- try {
1110
- await runtime.setUsageRecordingEnabled(next);
1111
- if (options.signal.aborted || !options.isCurrent()) return { kind: "close" };
1112
- ctx.ui.notify(
1113
- next ? `Local content-free usage recording enabled. Records stay on this device for ${USAGE_RECORDING_RETENTION_DAYS} days.` : "Local usage recording disabled. Existing records expire under the retention policy.",
1114
- "info"
1115
- );
1116
- return { kind: "stay" };
1117
- } catch (error) {
1118
- if (options.signal.aborted || !options.isCurrent()) return { kind: "close" };
1119
- try {
1120
- updateUsageRecordingSetting(previous);
1121
- await runtime.setUsageRecordingEnabled(previous);
1122
- if (options.signal.aborted || !options.isCurrent()) return { kind: "close" };
1123
- } catch (rollbackError) {
1124
- if (options.signal.aborted || !options.isCurrent()) return { kind: "close" };
1125
- ctx.ui.notify(
1126
- `Usage recording could not be applied or rolled back: ${formatError3(new AggregateError([error, rollbackError]))}`,
1127
- "error"
1128
- );
1129
- return { kind: "rejected" };
1130
- }
1131
- ctx.ui.notify(`Subagent settings were not applied: ${formatError3(error)}`, "error");
1132
- return { kind: "rejected" };
1133
- }
1134
- }
1135
- function applyCompletionSetting(value, ctx, runtime) {
1136
- const previous = runtime.getCompletionDelivery();
1137
- const next = value === "Continue automatically when work finishes" ? "auto-resume" : "next-turn";
1138
- if (next === previous) return { kind: "stay" };
1139
- try {
1140
- updateCompletionDeliverySetting(next);
1141
- runtime.setCompletionDelivery(next);
1142
- ctx.ui.notify(`Saved and applied: ${completionLabel(next)}.`, "info");
1143
- return { kind: "stay" };
1144
- } catch (error) {
1145
- ctx.ui.notify(`Subagent settings were not saved: ${formatError3(error)}`, "error");
1146
- return { kind: "rejected" };
1147
- }
1148
- }
1149
- function applyConsultResourceSetting(value, ctx, runtime) {
1150
- const previous = runtime.getConsultResourcePolicy();
1151
- const next = value === "No project resources" ? "none" : value === "All trusted resources" ? "all" : "project-context";
1152
- if (next === previous) return { kind: "stay" };
1153
- try {
1154
- updateConsultResourceSetting(next);
1155
- runtime.setConsultResourcePolicy(next);
1156
- ctx.ui.notify(`Saved and applied: ${consultResourceLabel(next)}.`, "info");
1157
- return { kind: "stay" };
1158
- } catch (error) {
1159
- ctx.ui.notify(`Subagent settings were not saved: ${formatError3(error)}`, "error");
1160
- return { kind: "rejected" };
1161
- }
1162
- }
1163
- function applyConsultationCwdSetting(value, ctx, runtime) {
1164
- const previous = runtime.getConsultationCwdPolicy();
1165
- const next = value === "This workspace only" ? "current-workspace" : "anywhere";
1166
- if (next === previous) return { kind: "stay" };
1167
- try {
1168
- updateCwdPolicySetting("consultation", next);
1169
- runtime.setConsultationCwdPolicy(next);
1170
- ctx.ui.notify(`Saved and applied: ${consultationCwdLabel(next)}.`, "info");
1171
- return { kind: "stay" };
1172
- } catch (error) {
1173
- ctx.ui.notify(`Subagent settings were not saved: ${formatError3(error)}`, "error");
1174
- return { kind: "rejected" };
1175
- }
1176
- }
1177
- function applyDelegationCwdSetting(value, ctx, runtime) {
1178
- const previous = runtime.getDelegationCwdPolicy();
1179
- const next = value === "This workspace only" ? "current-workspace" : value === "Any folder Pi can access" ? "anywhere" : "trusted-targets";
1180
- if (next === previous) return { kind: "stay" };
1181
- try {
1182
- updateCwdPolicySetting("delegation", next);
1183
- runtime.setDelegationCwdPolicy(next);
1184
- ctx.ui.notify(`Saved and applied: ${delegationCwdLabel(next)}.`, "info");
1185
- return { kind: "stay" };
1186
- } catch (error) {
1187
- ctx.ui.notify(`Subagent settings were not saved: ${formatError3(error)}`, "error");
1188
- return { kind: "rejected" };
1189
- }
1190
- }
1191
- function blockReloadWithRetainedAgents(ctx, runtime) {
1192
- const status = runtime.getRuntimeStatus();
1193
- if (status.retainedAgents === 0) return false;
1194
- ctx.ui.notify(
1195
- `Cannot reload while ${status.retainedAgents} subagent${status.retainedAgents === 1 ? " is" : "s are"} saved for follow-up (${status.activeAgents} working). Open Current subagents and clear them after their work is safe to discard, then change how subagents run.`,
1196
- "warning"
1197
- );
1198
- return true;
1199
- }
1200
- function isWorkflow(value) {
1201
- return value === "all" || value === "async-only" || value === "blocking-only";
1202
- }
1203
- function formatError3(error) {
1204
- return safeTerminalLine(error instanceof Error ? error.message : String(error));
1205
- }
1206
- export {
1207
- registerSubagentConfigCommand,
1208
- registerSubagentConfigLifecycle,
1209
- showSubagentManager,
1210
- showSubagentSettings
1211
- };
1212
- //# sourceMappingURL=config-ui-ABHYNGQ7.ts.map