@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,60 +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 {
4
- DEFAULT_MAX_OUTPUT_BYTES,
5
- TRUNCATION_MARKER,
6
- redactPrivateText,
7
- truncateUtf8
8
- } from "./chunk-H3FP6DLR.ts";
9
-
10
- // src/safe-text.ts
11
- import * as os from "node:os";
12
- import * as path from "node:path";
13
- import { DEFAULT_MAX_LINES, getAgentDir } from "@earendil-works/pi-coding-agent";
14
- var DEFAULT_MAX_OUTPUT_LINES = DEFAULT_MAX_LINES;
15
- function safeTerminalText(value) {
16
- return value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/gu, "?").replace(/\r/gu, "");
17
- }
18
- function safeTerminalLine(value, maxBytes = 2 * 1024) {
19
- const singleLine = safeTerminalText(redactPrivateText(value)).replace(/\s+/gu, " ").trim();
20
- return truncateUtf8(singleLine, maxBytes).text.replace(/\s+/gu, " ").trim();
21
- }
22
- function boundText(value, maxBytes = DEFAULT_MAX_OUTPUT_BYTES, maxLines = DEFAULT_MAX_OUTPUT_LINES) {
23
- const safe = safeTerminalText(value);
24
- const lines = safe.split("\n");
25
- const lineBounded = lines.length > maxLines ? `${lines.slice(0, Math.max(0, maxLines - 1)).join("\n")}${TRUNCATION_MARKER}` : safe;
26
- const bounded = truncateUtf8(lineBounded, maxBytes);
27
- return { text: bounded.text, truncated: lines.length > maxLines || bounded.truncated };
28
- }
29
- function boundedPrivateText(value, maxBytes) {
30
- return boundText(redactPrivateText(value), maxBytes).text;
31
- }
32
- function safeDisplayPath(value, workspace) {
33
- if (value.startsWith("built-in:")) return safeTerminalLine(value);
34
- const resolved = path.resolve(value);
35
- const agentDir = path.resolve(getAgentDir());
36
- const relativeAgent = path.relative(agentDir, resolved);
37
- if (relativeAgent === "" || !relativeAgent.startsWith("..") && !path.isAbsolute(relativeAgent)) {
38
- return relativeAgent ? `~/${safeTerminalLine(relativeAgent)}` : "~";
39
- }
40
- const resolvedWorkspace = path.resolve(workspace);
41
- const relativeWorkspace = path.relative(resolvedWorkspace, resolved);
42
- if (relativeWorkspace === "" || !relativeWorkspace.startsWith("..") && !path.isAbsolute(relativeWorkspace)) {
43
- return relativeWorkspace ? safeTerminalLine(relativeWorkspace) : ".";
44
- }
45
- const home = path.resolve(os.homedir());
46
- const relativeHome = path.relative(home, resolved);
47
- if (relativeHome === "" || !relativeHome.startsWith("..") && !path.isAbsolute(relativeHome)) {
48
- return relativeHome ? `~/${safeTerminalLine(relativeHome)}` : "~";
49
- }
50
- return safeTerminalLine(resolved);
51
- }
52
-
53
- export {
54
- safeTerminalText,
55
- safeTerminalLine,
56
- boundText,
57
- boundedPrivateText,
58
- safeDisplayPath
59
- };
60
- //# sourceMappingURL=chunk-SWGQLFSD.ts.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/safe-text.ts"],
4
- "sourcesContent": ["import * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { DEFAULT_MAX_LINES, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport { redactPrivateText } from \"./context.js\";\nimport { DEFAULT_MAX_OUTPUT_BYTES, TRUNCATION_MARKER, truncateUtf8 } from \"./limits.js\";\n\nexport const DEFAULT_MAX_OUTPUT_LINES = DEFAULT_MAX_LINES;\n\nexport function safeTerminalText(value: string): string {\n\treturn (\n\t\tvalue\n\t\t\t// biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls while preserving newlines.\n\t\t\t.replace(/[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f-\\u009f]/gu, \"?\")\n\t\t\t.replace(/\\r/gu, \"\")\n\t);\n}\n\nexport function safeTerminalLine(value: string, maxBytes = 2 * 1024): string {\n\tconst singleLine = safeTerminalText(redactPrivateText(value)).replace(/\\s+/gu, \" \").trim();\n\treturn truncateUtf8(singleLine, maxBytes).text.replace(/\\s+/gu, \" \").trim();\n}\n\nexport function boundText(\n\tvalue: string,\n\tmaxBytes = DEFAULT_MAX_OUTPUT_BYTES,\n\tmaxLines = DEFAULT_MAX_OUTPUT_LINES,\n): { text: string; truncated: boolean } {\n\tconst safe = safeTerminalText(value);\n\tconst lines = safe.split(\"\\n\");\n\tconst lineBounded =\n\t\tlines.length > maxLines\n\t\t\t? `${lines.slice(0, Math.max(0, maxLines - 1)).join(\"\\n\")}${TRUNCATION_MARKER}`\n\t\t\t: safe;\n\tconst bounded = truncateUtf8(lineBounded, maxBytes);\n\treturn { text: bounded.text, truncated: lines.length > maxLines || bounded.truncated };\n}\n\nexport function boundedPrivateText(value: string, maxBytes: number): string {\n\treturn boundText(redactPrivateText(value), maxBytes).text;\n}\n\nexport function safeDisplayPath(value: string, workspace: string): string {\n\tif (value.startsWith(\"built-in:\")) return safeTerminalLine(value);\n\tconst resolved = path.resolve(value);\n\tconst agentDir = path.resolve(getAgentDir());\n\tconst relativeAgent = path.relative(agentDir, resolved);\n\tif (\n\t\trelativeAgent === \"\" ||\n\t\t(!relativeAgent.startsWith(\"..\") && !path.isAbsolute(relativeAgent))\n\t) {\n\t\treturn relativeAgent ? `~/${safeTerminalLine(relativeAgent)}` : \"~\";\n\t}\n\tconst resolvedWorkspace = path.resolve(workspace);\n\tconst relativeWorkspace = path.relative(resolvedWorkspace, resolved);\n\tif (\n\t\trelativeWorkspace === \"\" ||\n\t\t(!relativeWorkspace.startsWith(\"..\") && !path.isAbsolute(relativeWorkspace))\n\t) {\n\t\treturn relativeWorkspace ? safeTerminalLine(relativeWorkspace) : \".\";\n\t}\n\tconst home = path.resolve(os.homedir());\n\tconst relativeHome = path.relative(home, resolved);\n\tif (relativeHome === \"\" || (!relativeHome.startsWith(\"..\") && !path.isAbsolute(relativeHome))) {\n\t\treturn relativeHome ? `~/${safeTerminalLine(relativeHome)}` : \"~\";\n\t}\n\treturn safeTerminalLine(resolved);\n}\n"],
5
- "mappings": ";;;;;;;;;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,mBAAmB,mBAAmB;AAIxC,IAAM,2BAA2B;AAEjC,SAAS,iBAAiB,OAAuB;AACvD,SACC,MAEE,QAAQ,2DAA2D,GAAG,EACtE,QAAQ,QAAQ,EAAE;AAEtB;AAEO,SAAS,iBAAiB,OAAe,WAAW,IAAI,MAAc;AAC5E,QAAM,aAAa,iBAAiB,kBAAkB,KAAK,CAAC,EAAE,QAAQ,SAAS,GAAG,EAAE,KAAK;AACzF,SAAO,aAAa,YAAY,QAAQ,EAAE,KAAK,QAAQ,SAAS,GAAG,EAAE,KAAK;AAC3E;AAEO,SAAS,UACf,OACA,WAAW,0BACX,WAAW,0BAC4B;AACvC,QAAM,OAAO,iBAAiB,KAAK;AACnC,QAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAM,cACL,MAAM,SAAS,WACZ,GAAG,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,WAAW,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,iBAAiB,KAC3E;AACJ,QAAM,UAAU,aAAa,aAAa,QAAQ;AAClD,SAAO,EAAE,MAAM,QAAQ,MAAM,WAAW,MAAM,SAAS,YAAY,QAAQ,UAAU;AACtF;AAEO,SAAS,mBAAmB,OAAe,UAA0B;AAC3E,SAAO,UAAU,kBAAkB,KAAK,GAAG,QAAQ,EAAE;AACtD;AAEO,SAAS,gBAAgB,OAAe,WAA2B;AACzE,MAAI,MAAM,WAAW,WAAW,EAAG,QAAO,iBAAiB,KAAK;AAChE,QAAM,WAAgB,aAAQ,KAAK;AACnC,QAAM,WAAgB,aAAQ,YAAY,CAAC;AAC3C,QAAM,gBAAqB,cAAS,UAAU,QAAQ;AACtD,MACC,kBAAkB,MACjB,CAAC,cAAc,WAAW,IAAI,KAAK,CAAM,gBAAW,aAAa,GACjE;AACD,WAAO,gBAAgB,KAAK,iBAAiB,aAAa,CAAC,KAAK;AAAA,EACjE;AACA,QAAM,oBAAyB,aAAQ,SAAS;AAChD,QAAM,oBAAyB,cAAS,mBAAmB,QAAQ;AACnE,MACC,sBAAsB,MACrB,CAAC,kBAAkB,WAAW,IAAI,KAAK,CAAM,gBAAW,iBAAiB,GACzE;AACD,WAAO,oBAAoB,iBAAiB,iBAAiB,IAAI;AAAA,EAClE;AACA,QAAM,OAAY,aAAW,WAAQ,CAAC;AACtC,QAAM,eAAoB,cAAS,MAAM,QAAQ;AACjD,MAAI,iBAAiB,MAAO,CAAC,aAAa,WAAW,IAAI,KAAK,CAAM,gBAAW,YAAY,GAAI;AAC9F,WAAO,eAAe,KAAK,iBAAiB,YAAY,CAAC,KAAK;AAAA,EAC/D;AACA,SAAO,iBAAiB,QAAQ;AACjC;",
6
- "names": []
7
- }
@@ -1,52 +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 {
4
- discoverAgents
5
- } from "./chunk-LASD73CM.ts";
6
- import {
7
- readSubagentSettings
8
- } from "./chunk-TMZRHIIK.ts";
9
- import {
10
- safeTerminalLine
11
- } from "./chunk-SWGQLFSD.ts";
12
-
13
- // src/stateful-safety.ts
14
- import { realpathSync } from "node:fs";
15
- import * as path from "node:path";
16
- function isWriteCapable(tools) {
17
- if (!tools) return true;
18
- return tools.some((tool) => ["bash", "write", "edit"].includes(tool));
19
- }
20
- async function confirmProjectAgent(name, scope, confirm, ctx, cwd, settings) {
21
- if (scope !== "project" && scope !== "both") return;
22
- if (!isSameCwd(cwd, ctx.cwd)) {
23
- throw new Error("Project-local subagent definitions cannot run with an overridden cwd");
24
- }
25
- if (!ctx.isProjectTrusted()) {
26
- throw new Error("Project-local subagent definitions require a trusted project");
27
- }
28
- const discovery = discoverAgents(cwd, scope, settings ?? readSubagentSettings());
29
- const agent = discovery.agents.find((candidate) => candidate.name === name);
30
- if (agent?.source !== "project") return;
31
- if (confirm && ctx.hasUI) {
32
- const approved = await ctx.ui.confirm(
33
- "Run project-local agent?",
34
- `Agent: ${safeTerminalLine(name, 256)}
35
- Source: ${safeTerminalLine(agent.filePath)}`
36
- );
37
- if (!approved) throw new Error("Project-local subagent was not approved");
38
- }
39
- }
40
- function isSameCwd(left, right) {
41
- try {
42
- return realpathSync(left) === realpathSync(right);
43
- } catch {
44
- return path.resolve(left) === path.resolve(right);
45
- }
46
- }
47
-
48
- export {
49
- isWriteCapable,
50
- confirmProjectAgent
51
- };
52
- //# sourceMappingURL=chunk-TM2R67J3.ts.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/stateful-safety.ts"],
4
- "sourcesContent": ["import { realpathSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { discoverAgents } from \"./agents/discovery.js\";\nimport type { AgentScope, SubagentSettings } from \"./agents/types.js\";\nimport { safeTerminalLine } from \"./safe-text.js\";\nimport { readSubagentSettings } from \"./settings-reader.js\";\n\nexport function isWriteCapable(tools: string[] | undefined): boolean {\n\tif (!tools) return true;\n\treturn tools.some((tool) => [\"bash\", \"write\", \"edit\"].includes(tool));\n}\n\nexport async function confirmProjectAgent(\n\tname: string,\n\tscope: AgentScope,\n\tconfirm: boolean,\n\tctx: ExtensionContext,\n\tcwd: string,\n\tsettings?: SubagentSettings,\n): Promise<void> {\n\tif (scope !== \"project\" && scope !== \"both\") return;\n\tif (!isSameCwd(cwd, ctx.cwd)) {\n\t\tthrow new Error(\"Project-local subagent definitions cannot run with an overridden cwd\");\n\t}\n\tif (!ctx.isProjectTrusted()) {\n\t\tthrow new Error(\"Project-local subagent definitions require a trusted project\");\n\t}\n\tconst discovery = discoverAgents(cwd, scope, settings ?? readSubagentSettings());\n\tconst agent = discovery.agents.find((candidate) => candidate.name === name);\n\tif (agent?.source !== \"project\") return;\n\tif (confirm && ctx.hasUI) {\n\t\tconst approved = await ctx.ui.confirm(\n\t\t\t\"Run project-local agent?\",\n\t\t\t`Agent: ${safeTerminalLine(name, 256)}\\nSource: ${safeTerminalLine(agent.filePath)}`,\n\t\t);\n\t\tif (!approved) throw new Error(\"Project-local subagent was not approved\");\n\t}\n}\n\nfunction isSameCwd(left: string, right: string): boolean {\n\ttry {\n\t\treturn realpathSync(left) === realpathSync(right);\n\t} catch {\n\t\treturn path.resolve(left) === path.resolve(right);\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;AAAA,SAAS,oBAAoB;AAC7B,YAAY,UAAU;AAOf,SAAS,eAAe,OAAsC;AACpE,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,MAAM,KAAK,CAAC,SAAS,CAAC,QAAQ,SAAS,MAAM,EAAE,SAAS,IAAI,CAAC;AACrE;AAEA,eAAsB,oBACrB,MACA,OACA,SACA,KACA,KACA,UACgB;AAChB,MAAI,UAAU,aAAa,UAAU,OAAQ;AAC7C,MAAI,CAAC,UAAU,KAAK,IAAI,GAAG,GAAG;AAC7B,UAAM,IAAI,MAAM,sEAAsE;AAAA,EACvF;AACA,MAAI,CAAC,IAAI,iBAAiB,GAAG;AAC5B,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAC/E;AACA,QAAM,YAAY,eAAe,KAAK,OAAO,YAAY,qBAAqB,CAAC;AAC/E,QAAM,QAAQ,UAAU,OAAO,KAAK,CAAC,cAAc,UAAU,SAAS,IAAI;AAC1E,MAAI,OAAO,WAAW,UAAW;AACjC,MAAI,WAAW,IAAI,OAAO;AACzB,UAAM,WAAW,MAAM,IAAI,GAAG;AAAA,MAC7B;AAAA,MACA,UAAU,iBAAiB,MAAM,GAAG,CAAC;AAAA,UAAa,iBAAiB,MAAM,QAAQ,CAAC;AAAA,IACnF;AACA,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM,yCAAyC;AAAA,EACzE;AACD;AAEA,SAAS,UAAU,MAAc,OAAwB;AACxD,MAAI;AACH,WAAO,aAAa,IAAI,MAAM,aAAa,KAAK;AAAA,EACjD,QAAQ;AACP,WAAY,aAAQ,IAAI,MAAW,aAAQ,KAAK;AAAA,EACjD;AACD;",
6
- "names": []
7
- }
@@ -1,497 +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 {
4
- STATEFUL_LIMIT_FIELDS,
5
- isValidStatefulLimit,
6
- resolveStatefulLimits
7
- } from "./chunk-VDG7LTYE.ts";
8
- import {
9
- CONSULTATION_CWD_POLICIES,
10
- CONSULT_RESOURCE_POLICIES,
11
- DELEGATION_CWD_POLICIES,
12
- isThinkingLevel
13
- } from "./chunk-4AQSF7AS.ts";
14
- import {
15
- DEFAULT_MAX_PARALLEL_TASKS,
16
- MAX_CONFIGURABLE_PARALLEL_TASKS,
17
- MAX_SUBAGENT_TIMEOUT_MS
18
- } from "./chunk-H3FP6DLR.ts";
19
-
20
- // src/settings/schema.ts
21
- function hasOwn(obj, key) {
22
- return Object.hasOwn(obj, key);
23
- }
24
- function isPlainObject(value) {
25
- return typeof value === "object" && value !== null && !Array.isArray(value);
26
- }
27
- function isStringArray(value) {
28
- return Array.isArray(value) && value.every((item) => typeof item === "string");
29
- }
30
- function isPositiveNumber(value) {
31
- return typeof value === "number" && Number.isFinite(value) && value >= 1;
32
- }
33
- function isPositiveInteger(value) {
34
- return isPositiveNumber(value) && Number.isSafeInteger(value);
35
- }
36
- function normalizeAgentSettings(value) {
37
- if (!isPlainObject(value)) return void 0;
38
- const config = {};
39
- let hasKnownField = false;
40
- if (hasOwn(value, "tools")) {
41
- if (!isStringArray(value.tools)) return void 0;
42
- config.tools = value.tools;
43
- hasKnownField = true;
44
- }
45
- if (hasOwn(value, "model")) {
46
- if (value.model !== null && typeof value.model !== "string") return void 0;
47
- config.model = value.model;
48
- hasKnownField = true;
49
- }
50
- if (hasOwn(value, "thinkingLevel")) {
51
- if (value.thinkingLevel !== null && !isThinkingLevel(value.thinkingLevel)) return void 0;
52
- config.thinkingLevel = value.thinkingLevel;
53
- hasKnownField = true;
54
- }
55
- if (hasOwn(value, "timeoutMs")) {
56
- if (value.timeoutMs !== null && (!isPositiveNumber(value.timeoutMs) || value.timeoutMs > MAX_SUBAGENT_TIMEOUT_MS)) {
57
- return void 0;
58
- }
59
- config.timeoutMs = value.timeoutMs;
60
- hasKnownField = true;
61
- }
62
- return hasKnownField ? config : void 0;
63
- }
64
- function normalizeSubagentSettings(value) {
65
- if (!isPlainObject(value)) return void 0;
66
- const settings = {};
67
- if (hasOwn(value, "agents")) {
68
- if (!isPlainObject(value.agents)) return void 0;
69
- const agents = {};
70
- for (const [name, rawConfig] of Object.entries(value.agents)) {
71
- const config = normalizeAgentSettings(rawConfig);
72
- if (config) agents[name] = config;
73
- }
74
- if (Object.keys(agents).length > 0) settings.agents = agents;
75
- }
76
- if (hasOwn(value, "blocking")) {
77
- if (!isPlainObject(value.blocking)) return void 0;
78
- const blocking = {};
79
- if (hasOwn(value.blocking, "enabled")) {
80
- if (typeof value.blocking.enabled !== "boolean") return void 0;
81
- blocking.enabled = value.blocking.enabled;
82
- }
83
- if (hasOwn(value.blocking, "maxParallelTasks")) {
84
- if (!isPositiveInteger(value.blocking.maxParallelTasks) || value.blocking.maxParallelTasks > MAX_CONFIGURABLE_PARALLEL_TASKS) {
85
- return void 0;
86
- }
87
- blocking.maxParallelTasks = value.blocking.maxParallelTasks;
88
- }
89
- settings.blocking = blocking;
90
- }
91
- if (hasOwn(value, "stateful")) {
92
- if (!isPlainObject(value.stateful)) return void 0;
93
- const runtime = {};
94
- if (hasOwn(value.stateful, "transport")) {
95
- if (value.stateful.transport !== "subprocess" && value.stateful.transport !== "in-process" && value.stateful.transport !== "rpc" && value.stateful.transport !== "auto") {
96
- return void 0;
97
- }
98
- runtime.transport = value.stateful.transport;
99
- }
100
- if (hasOwn(value.stateful, "completionDelivery")) {
101
- if (value.stateful.completionDelivery !== "next-turn" && value.stateful.completionDelivery !== "auto-resume") {
102
- return void 0;
103
- }
104
- runtime.completionDelivery = value.stateful.completionDelivery;
105
- }
106
- for (const key of STATEFUL_LIMIT_FIELDS) {
107
- if (hasOwn(value.stateful, key)) {
108
- if (!isValidStatefulLimit(key, value.stateful[key])) return void 0;
109
- runtime[key] = value.stateful[key];
110
- }
111
- }
112
- for (const key of ["maxMailboxMessages", "maxMailboxMessageBytes", "idleTtlMs"]) {
113
- if (hasOwn(value.stateful, key)) {
114
- if (!isPositiveInteger(value.stateful[key])) return void 0;
115
- runtime[key] = value.stateful[key];
116
- }
117
- }
118
- if (hasOwn(value.stateful, "retentionDays")) {
119
- if (!isPositiveNumber(value.stateful.retentionDays)) return void 0;
120
- runtime.retentionDays = value.stateful.retentionDays;
121
- }
122
- if (hasOwn(value.stateful, "enabled")) {
123
- if (typeof value.stateful.enabled !== "boolean") return void 0;
124
- runtime.enabled = value.stateful.enabled;
125
- }
126
- settings.stateful = runtime;
127
- }
128
- if (hasOwn(value, "consult")) {
129
- if (!isPlainObject(value.consult)) return void 0;
130
- const consult = {};
131
- if (hasOwn(value.consult, "resources")) {
132
- if (typeof value.consult.resources !== "string" || !CONSULT_RESOURCE_POLICIES.includes(value.consult.resources)) {
133
- return void 0;
134
- }
135
- consult.resources = value.consult.resources;
136
- }
137
- settings.consult = consult;
138
- }
139
- if (hasOwn(value, "cwdPolicy")) {
140
- if (!isPlainObject(value.cwdPolicy)) return void 0;
141
- const cwdPolicy = {};
142
- if (hasOwn(value.cwdPolicy, "consultation")) {
143
- if (typeof value.cwdPolicy.consultation !== "string" || !CONSULTATION_CWD_POLICIES.includes(value.cwdPolicy.consultation)) {
144
- return void 0;
145
- }
146
- cwdPolicy.consultation = value.cwdPolicy.consultation;
147
- }
148
- if (hasOwn(value.cwdPolicy, "delegation")) {
149
- if (typeof value.cwdPolicy.delegation !== "string" || !DELEGATION_CWD_POLICIES.includes(value.cwdPolicy.delegation)) {
150
- return void 0;
151
- }
152
- cwdPolicy.delegation = value.cwdPolicy.delegation;
153
- }
154
- settings.cwdPolicy = cwdPolicy;
155
- }
156
- if (hasOwn(value, "usageRecording")) {
157
- if (!isPlainObject(value.usageRecording)) return void 0;
158
- const usageRecording = {};
159
- if (hasOwn(value.usageRecording, "enabled")) {
160
- if (typeof value.usageRecording.enabled !== "boolean") return void 0;
161
- usageRecording.enabled = value.usageRecording.enabled;
162
- }
163
- settings.usageRecording = usageRecording;
164
- }
165
- return settings;
166
- }
167
-
168
- // src/settings/inspection.ts
169
- var DEFAULT_COMPLETION_DELIVERY = "next-turn";
170
- var DEFAULT_CONSULT_RESOURCE_POLICY = "project-context";
171
- var DEFAULT_CONSULTATION_CWD_POLICY = "anywhere";
172
- var DEFAULT_DELEGATION_CWD_POLICY = "trusted-targets";
173
- function resolveDelegationWorkflow(blockingEnabled, statefulEnabled) {
174
- if (blockingEnabled && statefulEnabled) return "all";
175
- if (statefulEnabled) return "async-only";
176
- if (blockingEnabled) return "blocking-only";
177
- return "disabled";
178
- }
179
- function resolveBlockingMaxParallelTasks(settings) {
180
- return settings?.blocking?.maxParallelTasks ?? DEFAULT_MAX_PARALLEL_TASKS;
181
- }
182
- function buildSubagentSettingsSnapshot(inspected) {
183
- return {
184
- path: inspected.path,
185
- settings: inspected.settings,
186
- source: inspected.settings ? "user settings" : "default",
187
- ...inspected.error ? { error: inspected.error } : {}
188
- };
189
- }
190
- function buildUsageRecordingSettingsSnapshot(inspected) {
191
- if (!inspected.raw || !inspected.settings) {
192
- return {
193
- path: inspected.path,
194
- enabled: false,
195
- source: "default",
196
- ...inspected.error ? { error: inspected.error } : {}
197
- };
198
- }
199
- const explicit = isPlainObject(inspected.raw.usageRecording) && hasOwn(inspected.raw.usageRecording, "enabled");
200
- return {
201
- path: inspected.path,
202
- enabled: inspected.settings.usageRecording?.enabled === true,
203
- source: explicit ? "user settings" : "default"
204
- };
205
- }
206
- function buildConsultResourceSettingsSnapshot(inspected) {
207
- if (!inspected.raw || !inspected.settings) {
208
- return {
209
- path: inspected.path,
210
- value: DEFAULT_CONSULT_RESOURCE_POLICY,
211
- source: "default",
212
- ...inspected.error ? { error: inspected.error } : {}
213
- };
214
- }
215
- const explicit = isPlainObject(inspected.raw.consult) && hasOwn(inspected.raw.consult, "resources");
216
- return {
217
- path: inspected.path,
218
- value: inspected.settings.consult?.resources ?? DEFAULT_CONSULT_RESOURCE_POLICY,
219
- source: explicit ? "user settings" : "default"
220
- };
221
- }
222
- function buildCwdPolicySettingsSnapshot(inspected) {
223
- if (!inspected.raw || !inspected.settings) {
224
- return {
225
- path: inspected.path,
226
- consultation: { value: DEFAULT_CONSULTATION_CWD_POLICY, source: "default" },
227
- delegation: { value: DEFAULT_DELEGATION_CWD_POLICY, source: "default" },
228
- ...inspected.error ? { error: inspected.error } : {}
229
- };
230
- }
231
- const rawPolicy = isPlainObject(inspected.raw.cwdPolicy) ? inspected.raw.cwdPolicy : void 0;
232
- return {
233
- path: inspected.path,
234
- consultation: {
235
- value: inspected.settings.cwdPolicy?.consultation ?? DEFAULT_CONSULTATION_CWD_POLICY,
236
- source: rawPolicy && hasOwn(rawPolicy, "consultation") ? "user settings" : "default"
237
- },
238
- delegation: {
239
- value: inspected.settings.cwdPolicy?.delegation ?? DEFAULT_DELEGATION_CWD_POLICY,
240
- source: rawPolicy && hasOwn(rawPolicy, "delegation") ? "user settings" : "default"
241
- }
242
- };
243
- }
244
- function buildDelegationWorkflowSettingsSnapshot(inspected) {
245
- if (!inspected.raw || !inspected.settings) {
246
- return {
247
- path: inspected.path,
248
- value: "all",
249
- source: "default",
250
- ...inspected.error ? { error: inspected.error } : {}
251
- };
252
- }
253
- const explicit = isPlainObject(inspected.raw.blocking) && hasOwn(inspected.raw.blocking, "enabled") || isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "enabled");
254
- return {
255
- path: inspected.path,
256
- value: resolveDelegationWorkflow(
257
- inspected.settings.blocking?.enabled !== false,
258
- inspected.settings.stateful?.enabled !== false
259
- ),
260
- source: explicit ? "user settings" : "default"
261
- };
262
- }
263
- function buildCompletionDeliverySettingsSnapshot(inspected) {
264
- if (!inspected.raw || !inspected.settings) {
265
- return {
266
- path: inspected.path,
267
- value: DEFAULT_COMPLETION_DELIVERY,
268
- source: "default",
269
- ...inspected.error ? { error: inspected.error } : {}
270
- };
271
- }
272
- const explicit = isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "completionDelivery");
273
- return {
274
- path: inspected.path,
275
- value: inspected.settings.stateful?.completionDelivery ?? DEFAULT_COMPLETION_DELIVERY,
276
- source: explicit ? "user settings" : "default"
277
- };
278
- }
279
- function buildStatefulTransportSettingsSnapshot(inspected) {
280
- if (!inspected.raw || !inspected.settings) {
281
- return {
282
- path: inspected.path,
283
- value: "subprocess",
284
- source: "default",
285
- ...inspected.error ? { error: inspected.error } : {}
286
- };
287
- }
288
- const explicit = isPlainObject(inspected.raw.stateful) && hasOwn(inspected.raw.stateful, "transport");
289
- return {
290
- path: inspected.path,
291
- value: inspected.settings.stateful?.transport ?? "subprocess",
292
- source: explicit ? "user settings" : "default"
293
- };
294
- }
295
- function buildBlockingParallelLimitSettingsSnapshot(inspected) {
296
- if (!inspected.raw || !inspected.settings) {
297
- return {
298
- path: inspected.path,
299
- value: DEFAULT_MAX_PARALLEL_TASKS,
300
- source: "default",
301
- ...inspected.error ? { error: inspected.error } : {}
302
- };
303
- }
304
- const explicit = isPlainObject(inspected.raw.blocking) && hasOwn(inspected.raw.blocking, "maxParallelTasks");
305
- return {
306
- path: inspected.path,
307
- value: resolveBlockingMaxParallelTasks(inspected.settings),
308
- source: explicit ? "user settings" : "default"
309
- };
310
- }
311
- function buildStatefulLimitSettingsSnapshot(inspected, writePath) {
312
- if (inspected.error) {
313
- return { path: inspected.path, writePath, error: inspected.error };
314
- }
315
- const resolved = resolveStatefulLimits(inspected.settings?.stateful);
316
- const rawStateful = isPlainObject(inspected.raw?.stateful) ? inspected.raw.stateful : void 0;
317
- return {
318
- path: inspected.path,
319
- writePath,
320
- values: Object.fromEntries(
321
- STATEFUL_LIMIT_FIELDS.map((field) => [
322
- field,
323
- {
324
- value: resolved[field],
325
- source: rawStateful && hasOwn(rawStateful, field) ? "user settings" : "default"
326
- }
327
- ])
328
- )
329
- };
330
- }
331
-
332
- // src/settings-reader.ts
333
- import * as fs from "node:fs";
334
- import * as path from "node:path";
335
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
336
- var SUBAGENT_SETTINGS_FILE = "pi-subagents.json";
337
- var LEGACY_SETTINGS_FILE = "pi-subagents-config.json";
338
- var pendingSettingsNotice;
339
- function resolveSubagentSettingsPaths() {
340
- const canonicalPath = path.join(getAgentDir(), SUBAGENT_SETTINGS_FILE);
341
- const legacyPath = path.join(getAgentDir(), LEGACY_SETTINGS_FILE);
342
- return {
343
- canonicalPath,
344
- legacyPath,
345
- activePath: fs.existsSync(canonicalPath) ? canonicalPath : fs.existsSync(legacyPath) ? legacyPath : void 0
346
- };
347
- }
348
- function readSubagentSettings() {
349
- pendingSettingsNotice = void 0;
350
- const { canonicalPath, legacyPath, activePath } = resolveSubagentSettingsPaths();
351
- if (activePath === canonicalPath) {
352
- const canonical = readSettingsFile(canonicalPath);
353
- const notices = [];
354
- if (!canonical) notices.push(`${SUBAGENT_SETTINGS_FILE} is invalid and was ignored.`);
355
- if (fs.existsSync(legacyPath)) {
356
- notices.push(
357
- `${LEGACY_SETTINGS_FILE} ignored because ${SUBAGENT_SETTINGS_FILE} takes precedence.`
358
- );
359
- }
360
- if (notices.length > 0) pendingSettingsNotice = notices.join("\n");
361
- return canonical;
362
- }
363
- if (activePath === void 0) return void 0;
364
- const legacy = readSettingsFile(legacyPath);
365
- if (fs.existsSync(canonicalPath)) {
366
- const canonical = readSettingsFile(canonicalPath);
367
- pendingSettingsNotice = [
368
- ...!canonical ? [`${SUBAGENT_SETTINGS_FILE} is invalid and was ignored.`] : [],
369
- `${LEGACY_SETTINGS_FILE} ignored because ${SUBAGENT_SETTINGS_FILE} was created concurrently.`
370
- ].join("\n");
371
- return canonical;
372
- }
373
- if (!legacy) {
374
- pendingSettingsNotice = `${LEGACY_SETTINGS_FILE} is invalid and was ignored.`;
375
- return void 0;
376
- }
377
- pendingSettingsNotice = `Using legacy ${LEGACY_SETTINGS_FILE}; rename it to ${SUBAGENT_SETTINGS_FILE}. Future saves write ${SUBAGENT_SETTINGS_FILE} without modifying the legacy file.`;
378
- return legacy;
379
- }
380
- function consumeSubagentSettingsNotice() {
381
- const notice = pendingSettingsNotice;
382
- pendingSettingsNotice = void 0;
383
- return notice;
384
- }
385
- function subagentSettingsFilePath() {
386
- return path.join(getAgentDir(), SUBAGENT_SETTINGS_FILE);
387
- }
388
- function inspectSubagentSettingsDocument() {
389
- const { canonicalPath, activePath } = resolveSubagentSettingsPaths();
390
- if (activePath === void 0) return { path: canonicalPath };
391
- const inspected = inspectSubagentSettingsPath(activePath);
392
- return activePath !== canonicalPath && fs.existsSync(canonicalPath) ? inspectSubagentSettingsPath(canonicalPath) : inspected;
393
- }
394
- function inspectSubagentSettingsPath(configPath) {
395
- const fileName = path.basename(configPath);
396
- let contents;
397
- try {
398
- contents = fs.readFileSync(configPath, "utf8");
399
- } catch (error) {
400
- const code = error.code;
401
- return {
402
- path: configPath,
403
- error: `${fileName} could not be read${code ? ` (${safeErrorCode(code)})` : ""}`
404
- };
405
- }
406
- let raw;
407
- try {
408
- raw = JSON.parse(contents);
409
- } catch {
410
- return { path: configPath, error: `${fileName} contains malformed JSON` };
411
- }
412
- const settings = normalizeSubagentSettings(raw);
413
- if (!isPlainObject(raw) || !settings) {
414
- return { path: configPath, error: `${fileName} is not a valid settings object` };
415
- }
416
- return { path: configPath, raw, settings };
417
- }
418
- function inspectSubagentSettings() {
419
- return buildSubagentSettingsSnapshot(inspectSubagentSettingsDocument());
420
- }
421
- function inspectConsultResourceSettings() {
422
- return buildConsultResourceSettingsSnapshot(inspectSubagentSettingsDocument());
423
- }
424
- function inspectCwdPolicySettings() {
425
- return buildCwdPolicySettingsSnapshot(inspectSubagentSettingsDocument());
426
- }
427
- function inspectDelegationWorkflowSettings() {
428
- return buildDelegationWorkflowSettingsSnapshot(inspectSubagentSettingsDocument());
429
- }
430
- function inspectCompletionDeliverySettings() {
431
- return buildCompletionDeliverySettingsSnapshot(inspectSubagentSettingsDocument());
432
- }
433
- function inspectUsageRecordingSettings() {
434
- return buildUsageRecordingSettingsSnapshot(inspectSubagentSettingsDocument());
435
- }
436
- function inspectStatefulTransportSettings() {
437
- return buildStatefulTransportSettingsSnapshot(inspectSubagentSettingsDocument());
438
- }
439
- function inspectBlockingParallelLimitSettings() {
440
- return buildBlockingParallelLimitSettingsSnapshot(inspectSubagentSettingsDocument());
441
- }
442
- function inspectStatefulLimitSettings() {
443
- return buildStatefulLimitSettingsSnapshot(
444
- inspectSubagentSettingsDocument(),
445
- subagentSettingsFilePath()
446
- );
447
- }
448
- function pathEntryExists(filePath) {
449
- try {
450
- fs.lstatSync(filePath);
451
- return true;
452
- } catch (error) {
453
- if (error.code === "ENOENT") return false;
454
- throw error;
455
- }
456
- }
457
- function readSettingsFile(configPath) {
458
- return readSettingsSnapshot(configPath).settings;
459
- }
460
- function readSettingsSnapshot(configPath) {
461
- try {
462
- const contents = fs.readFileSync(configPath, "utf8");
463
- return { settings: normalizeSubagentSettings(JSON.parse(contents)), contents };
464
- } catch {
465
- return {};
466
- }
467
- }
468
- function safeErrorCode(value) {
469
- return value.replace(/[^A-Z0-9_-]/giu, "?").slice(0, 64);
470
- }
471
-
472
- export {
473
- hasOwn,
474
- isPlainObject,
475
- isPositiveInteger,
476
- normalizeSubagentSettings,
477
- DEFAULT_CONSULT_RESOURCE_POLICY,
478
- DEFAULT_CONSULTATION_CWD_POLICY,
479
- DEFAULT_DELEGATION_CWD_POLICY,
480
- resolveDelegationWorkflow,
481
- resolveBlockingMaxParallelTasks,
482
- SUBAGENT_SETTINGS_FILE,
483
- resolveSubagentSettingsPaths,
484
- readSubagentSettings,
485
- consumeSubagentSettingsNotice,
486
- inspectSubagentSettings,
487
- inspectConsultResourceSettings,
488
- inspectCwdPolicySettings,
489
- inspectDelegationWorkflowSettings,
490
- inspectCompletionDeliverySettings,
491
- inspectUsageRecordingSettings,
492
- inspectStatefulTransportSettings,
493
- inspectBlockingParallelLimitSettings,
494
- inspectStatefulLimitSettings,
495
- pathEntryExists
496
- };
497
- //# sourceMappingURL=chunk-TMZRHIIK.ts.map