@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,168 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { getPackageDir } from "@earendil-works/pi-coding-agent";
4
-
5
- const CORE_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
6
- const MAX_DISPLAY_PATH_LENGTH = 500;
7
-
8
- export interface PiInvocation {
9
- command: string;
10
- args: string[];
11
- }
12
-
13
- export interface PiInvocationRuntime {
14
- execPath: string;
15
- packageDir: string;
16
- runtimeKind: "node" | "bun" | "unsupported";
17
- }
18
-
19
- export class PiInvocationError extends Error {
20
- constructor(message: string) {
21
- super(message);
22
- this.name = "PiInvocationError";
23
- }
24
- }
25
-
26
- function displayPath(value: string): string {
27
- const suffix = value.length > MAX_DISPLAY_PATH_LENGTH ? "…" : "";
28
- return JSON.stringify(`${value.slice(0, MAX_DISPLAY_PATH_LENGTH)}${suffix}`);
29
- }
30
-
31
- function resolutionError(packageDir: string, reason: string): PiInvocationError {
32
- return new PiInvocationError(
33
- `Unable to resolve the Pi CLI from the loaded ${CORE_PACKAGE_NAME} package at ${displayPath(packageDir)}: ${reason}. Reinstall the matching Pi core package before using the subprocess transport.`,
34
- );
35
- }
36
-
37
- function currentRuntime(): PiInvocationRuntime {
38
- let packageDir: string;
39
- try {
40
- packageDir = getPackageDir();
41
- } catch {
42
- throw resolutionError("<unavailable>", "Pi core did not provide its package directory");
43
- }
44
- const runtimeKind = process.versions.bun
45
- ? "bun"
46
- : process.release.name === "node" && !process.versions.electron
47
- ? "node"
48
- : "unsupported";
49
- return {
50
- execPath: process.execPath,
51
- packageDir,
52
- runtimeKind,
53
- };
54
- }
55
-
56
- function isRecord(value: unknown): value is Record<string, unknown> {
57
- return typeof value === "object" && value !== null && !Array.isArray(value);
58
- }
59
-
60
- function isWithinDirectory(parent: string, candidate: string): boolean {
61
- const relative = path.relative(parent, candidate);
62
- return (
63
- relative === "" ||
64
- (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative))
65
- );
66
- }
67
-
68
- function readCoreManifest(packageDir: string): Record<string, unknown> {
69
- const manifestPath = path.join(packageDir, "package.json");
70
- let source: string;
71
- try {
72
- source = fs.readFileSync(manifestPath, "utf8");
73
- } catch {
74
- throw resolutionError(packageDir, "the package manifest is unavailable");
75
- }
76
- let manifest: unknown;
77
- try {
78
- manifest = JSON.parse(source);
79
- } catch {
80
- throw resolutionError(packageDir, "the package manifest is invalid JSON");
81
- }
82
- if (!isRecord(manifest)) {
83
- throw resolutionError(packageDir, "the package manifest is invalid");
84
- }
85
- if (manifest.name !== CORE_PACKAGE_NAME) {
86
- throw resolutionError(packageDir, "the package manifest has an unexpected package name");
87
- }
88
- return manifest;
89
- }
90
-
91
- function resolveDeclaredBin(packageDir: string, manifest: Record<string, unknown>): string {
92
- const bin = manifest.bin;
93
- const piBin = isRecord(bin) ? bin.pi : undefined;
94
- if (typeof piBin !== "string" || !piBin.trim()) {
95
- throw resolutionError(packageDir, "package.json bin.pi must be a non-empty string");
96
- }
97
- const candidate = path.resolve(packageDir, piBin);
98
- if (path.isAbsolute(piBin) || !isWithinDirectory(packageDir, candidate)) {
99
- throw resolutionError(packageDir, "the declared bin.pi target escapes the package directory");
100
- }
101
- return candidate;
102
- }
103
-
104
- function resolveExistingFile(packageDir: string, candidate: string, reason: string): string {
105
- let resolved: string;
106
- try {
107
- resolved = fs.realpathSync(candidate);
108
- if (!fs.statSync(resolved).isFile()) throw new Error("not a file");
109
- } catch {
110
- throw resolutionError(packageDir, reason);
111
- }
112
- if (!isWithinDirectory(packageDir, resolved)) {
113
- throw resolutionError(packageDir, "the declared bin.pi target escapes the package directory");
114
- }
115
- return resolved;
116
- }
117
-
118
- function resolveStandaloneExecutable(
119
- packageDir: string,
120
- runtime: PiInvocationRuntime,
121
- ): string | undefined {
122
- if (runtime.runtimeKind !== "bun") return undefined;
123
- const { execPath } = runtime;
124
- if (!/^pi(?:\.exe)?$/i.test(path.basename(execPath))) return undefined;
125
- let resolved: string;
126
- let mode: number;
127
- try {
128
- resolved = fs.realpathSync(execPath);
129
- const stat = fs.statSync(resolved);
130
- if (!stat.isFile()) throw new Error("not a file");
131
- mode = stat.mode;
132
- } catch {
133
- throw resolutionError(packageDir, "the standalone Pi executable is unavailable");
134
- }
135
- if (path.dirname(resolved) !== packageDir) return undefined;
136
- if (process.platform !== "win32" && (mode & 0o111) === 0) {
137
- throw resolutionError(packageDir, "the standalone Pi executable is not executable");
138
- }
139
- return resolved;
140
- }
141
-
142
- export function resolvePiInvocation(
143
- args: string[],
144
- runtime: PiInvocationRuntime = currentRuntime(),
145
- ): PiInvocation {
146
- let packageDir: string;
147
- try {
148
- packageDir = fs.realpathSync(runtime.packageDir);
149
- if (!fs.statSync(packageDir).isDirectory()) throw new Error("not a directory");
150
- } catch {
151
- throw resolutionError(runtime.packageDir, "the package directory is unavailable");
152
- }
153
-
154
- const manifest = readCoreManifest(packageDir);
155
- const declaredBin = resolveDeclaredBin(packageDir, manifest);
156
- const standalone = resolveStandaloneExecutable(packageDir, runtime);
157
- if (standalone) return { command: standalone, args: [...args] };
158
-
159
- if (runtime.runtimeKind !== "node" && runtime.runtimeKind !== "bun") {
160
- throw resolutionError(packageDir, "the host does not provide a supported Node or Bun runtime");
161
- }
162
- const cliPath = resolveExistingFile(
163
- packageDir,
164
- declaredBin,
165
- "the declared bin.pi target is unavailable",
166
- );
167
- return { command: runtime.execPath, args: [cliPath, ...args] };
168
- }
@@ -1,43 +0,0 @@
1
- import type { spawn } from "node:child_process";
2
-
3
- export const KILL_GRACE_MS = 5000;
4
-
5
- function signalProcess(proc: ReturnType<typeof spawn>, signal: NodeJS.Signals): void {
6
- if (process.platform !== "win32" && proc.pid) {
7
- try {
8
- process.kill(-proc.pid, signal);
9
- return;
10
- } catch {
11
- // Fall back to signaling the immediate child when process-group signaling is unavailable.
12
- }
13
- }
14
- try {
15
- proc.kill(signal);
16
- } catch {
17
- // The process may already have exited.
18
- }
19
- }
20
-
21
- export function terminateProcess(
22
- proc: ReturnType<typeof spawn>,
23
- graceMs = KILL_GRACE_MS,
24
- ): () => void {
25
- const leaderExited = proc.exitCode !== null || proc.signalCode !== null;
26
- const capturedOutputClosed = [proc.stdout, proc.stderr].every(
27
- (stream) => !stream || stream.readableEnded || stream.destroyed,
28
- );
29
- let closed = leaderExited && capturedOutputClosed;
30
- const onClose = () => {
31
- closed = true;
32
- };
33
- proc.once("close", onClose);
34
- if (!closed) signalProcess(proc, "SIGTERM");
35
- const escalation = setTimeout(() => {
36
- if (!closed) signalProcess(proc, "SIGKILL");
37
- }, graceMs);
38
- escalation.unref();
39
- return () => {
40
- clearTimeout(escalation);
41
- proc.off("close", onClose);
42
- };
43
- }
@@ -1,38 +0,0 @@
1
- import {
2
- DefaultResourceLoader,
3
- getAgentDir,
4
- SettingsManager,
5
- } from "@earendil-works/pi-coding-agent";
6
- import { assertPiPromptSourcesAreReadableFiles } from "./prompt-source-safety.js";
7
-
8
- export interface PiPromptResources {
9
- systemPrompt?: string;
10
- appendSystemPromptPaths: string[];
11
- }
12
-
13
- /** Resolve Pi-owned prompt files without loading target packages, extensions, or settings. */
14
- export async function resolvePiPromptResources(
15
- cwd: string,
16
- projectTrusted: boolean,
17
- agentDir = getAgentDir(),
18
- ): Promise<PiPromptResources> {
19
- assertPiPromptSourcesAreReadableFiles(cwd, agentDir, projectTrusted, [
20
- "SYSTEM.md",
21
- "APPEND_SYSTEM.md",
22
- ]);
23
- const loader = new DefaultResourceLoader({
24
- cwd,
25
- agentDir,
26
- settingsManager: SettingsManager.inMemory({}, { projectTrusted }),
27
- noExtensions: true,
28
- noSkills: true,
29
- noPromptTemplates: true,
30
- noThemes: true,
31
- noContextFiles: true,
32
- });
33
- await loader.reload();
34
- return {
35
- systemPrompt: loader.getSystemPrompt(),
36
- appendSystemPromptPaths: loader.getAppendSystemPromptSources().map((source) => source.path),
37
- };
38
- }
@@ -1,48 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
4
-
5
- export type PiPromptFileName = "SYSTEM.md" | "APPEND_SYSTEM.md";
6
-
7
- /**
8
- * Prevent Pi's synchronous prompt loader from opening a selected directory, FIFO, socket, device,
9
- * or unreadable source. Candidate order mirrors core only as a preflight guard; core still resolves
10
- * and loads the prompt after this check.
11
- */
12
- export function assertPiPromptSourcesAreReadableFiles(
13
- cwd: string,
14
- agentDir: string,
15
- projectTrusted: boolean,
16
- fileNames: readonly PiPromptFileName[],
17
- ): void {
18
- for (const fileName of fileNames) {
19
- const candidates = [
20
- ...(projectTrusted ? [path.join(cwd, CONFIG_DIR_NAME, fileName)] : []),
21
- path.join(agentDir, fileName),
22
- ];
23
- for (const candidate of candidates) {
24
- const status = promptSourceStatus(candidate);
25
- if (status === "missing") continue;
26
- if (status === "invalid") {
27
- throw new Error(`Pi ${fileName} prompt source must be a readable regular file`);
28
- }
29
- break;
30
- }
31
- }
32
- }
33
-
34
- function promptSourceStatus(filePath: string): "missing" | "regular" | "invalid" {
35
- let descriptor: number | undefined;
36
- try {
37
- descriptor = fs.openSync(filePath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
38
- return fs.fstatSync(descriptor).isFile() ? "regular" : "invalid";
39
- } catch (error) {
40
- const code =
41
- error && typeof error === "object" && "code" in error
42
- ? (error as { code?: unknown }).code
43
- : undefined;
44
- return code === "ENOENT" || code === "ENOTDIR" ? "missing" : "invalid";
45
- } finally {
46
- if (descriptor !== undefined) fs.closeSync(descriptor);
47
- }
48
- }
package/src/protocol.ts DELETED
@@ -1,76 +0,0 @@
1
- import { StringDecoder } from "node:string_decoder";
2
-
3
- const DEFAULT_MAX_LINE_BYTES = 256 * 1024;
4
-
5
- export interface JsonLineDecoderOptions {
6
- maxLineBytes?: number;
7
- onValue: (value: unknown) => void;
8
- onMalformed?: (line: string) => void;
9
- onOversized?: (bytes: number) => void;
10
- }
11
-
12
- /** Bounded newline-delimited JSON decoder for child Pi event streams. */
13
- export class JsonLineDecoder {
14
- private buffer = "";
15
- private droppingOversizedLine = false;
16
- private readonly maxLineBytes: number;
17
- private readonly decoder = new StringDecoder("utf8");
18
-
19
- constructor(private readonly options: JsonLineDecoderOptions) {
20
- const maxLineBytes = options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;
21
- if (!Number.isSafeInteger(maxLineBytes) || maxLineBytes < 1) {
22
- throw new Error("JSON line limit must be a positive safe integer");
23
- }
24
- this.maxLineBytes = maxLineBytes;
25
- }
26
-
27
- push(chunk: string | Buffer): void {
28
- this.buffer += typeof chunk === "string" ? chunk : this.decoder.write(chunk);
29
- this.drain(false);
30
- }
31
-
32
- finish(): void {
33
- this.buffer += this.decoder.end();
34
- this.drain(true);
35
- this.buffer = "";
36
- this.droppingOversizedLine = false;
37
- }
38
-
39
- private drain(flush: boolean): void {
40
- while (true) {
41
- const newline = this.buffer.indexOf("\n");
42
- if (newline < 0) break;
43
- const line = this.buffer.slice(0, newline).replace(/\r$/, "");
44
- this.buffer = this.buffer.slice(newline + 1);
45
- if (this.droppingOversizedLine) {
46
- this.droppingOversizedLine = false;
47
- continue;
48
- }
49
- this.processLine(line);
50
- }
51
-
52
- if (!flush && Buffer.byteLength(this.buffer, "utf8") > this.maxLineBytes) {
53
- this.options.onOversized?.(Buffer.byteLength(this.buffer, "utf8"));
54
- this.buffer = "";
55
- this.droppingOversizedLine = true;
56
- }
57
-
58
- if (flush && this.buffer.length > 0 && !this.droppingOversizedLine) {
59
- this.processLine(this.buffer.replace(/\r$/, ""));
60
- }
61
- }
62
-
63
- private processLine(line: string): void {
64
- if (!line.trim()) return;
65
- const bytes = Buffer.byteLength(line, "utf8");
66
- if (bytes > this.maxLineBytes) {
67
- this.options.onOversized?.(bytes);
68
- return;
69
- }
70
- try {
71
- this.options.onValue(JSON.parse(line));
72
- } catch {
73
- this.options.onMalformed?.(line);
74
- }
75
- }
76
- }
@@ -1,204 +0,0 @@
1
- import type { SubagentThinkingLevel } from "./agents/types.js";
2
- import type { CapabilityGrant } from "./capability-grant.js";
3
- import type { CompletionRequirementRecord } from "./completion-requirement.js";
4
- import type { TargetPolicyAudit } from "./cwd-policy.js";
5
- import type { DelegationContract } from "./delegation-contract.js";
6
- import type { ExecutionPlan } from "./execution-plan.js";
7
- import type { ClassifiedSubagentOutcome } from "./outcome.js";
8
- import type { AnyStructuredSubagentResult, SubagentResultFormat } from "./result-contract.js";
9
- import type { SemanticCompatibility, SemanticSnapshot } from "./semantic-snapshot.js";
10
- import type { TurnTerminationReport } from "./timeout-checkpoint.js";
11
- import type { TransportTelemetry } from "./transport-types.js";
12
-
13
- export type AgentLifecycleState =
14
- | "starting"
15
- | "running"
16
- | "idle"
17
- | "completed"
18
- | "partial"
19
- | "blocked"
20
- | "needs-input"
21
- | "abstained"
22
- | "stale"
23
- | "interrupted"
24
- | "failed"
25
- | "closed";
26
-
27
- export interface AgentTurn {
28
- runId?: string;
29
- generation?: number;
30
- task: string;
31
- output: string;
32
- startedAt: number;
33
- completedAt: number;
34
- exitCode: number;
35
- truncated?: boolean;
36
- termination?: TurnTerminationReport;
37
- }
38
-
39
- export interface PersistedAgentCompletion {
40
- completionId: string;
41
- recipientId?: string;
42
- recipientPath?: string;
43
- runId: string;
44
- generation: number;
45
- task: string;
46
- output: string;
47
- error?: string;
48
- createdAt: number;
49
- }
50
-
51
- export interface AgentMailboxMessage {
52
- id: string;
53
- senderId: string;
54
- recipientId: string;
55
- content: string;
56
- createdAt: number;
57
- readAt?: number;
58
- deduplicationKey?: string;
59
- completionId?: string;
60
- }
61
-
62
- export interface ManagedAgent {
63
- id: string;
64
- taskName?: string;
65
- taskPath?: string;
66
- agent: string;
67
- parentId?: string;
68
- rootId: string;
69
- depth: number;
70
- children: string[];
71
- state: AgentLifecycleState;
72
- createdAt: number;
73
- updatedAt: number;
74
- cwd: string;
75
- agentScope?: "user" | "project" | "both";
76
- thinkingLevel?: SubagentThinkingLevel;
77
- timeoutMs?: number;
78
- currentTimeoutMs?: number;
79
- idleTimeoutMs?: number;
80
- currentIdleTimeoutMs?: number;
81
- maxTurns?: number;
82
- currentMaxTurns?: number;
83
- maxToolCalls?: number;
84
- currentMaxToolCalls?: number;
85
- currentTask?: string;
86
- turnGeneration?: number;
87
- currentRunId?: string;
88
- currentTurnGeneration?: number;
89
- pendingCompletions?: PersistedAgentCompletion[];
90
- completionRequirements?: CompletionRequirementRecord[];
91
- history: AgentTurn[];
92
- error?: string;
93
- context?: string;
94
- contextSourceIds?: string[];
95
- contextTruncated?: boolean;
96
- contextTurns?: number;
97
- contextBytes?: number;
98
- workspaceMode?: "worktree";
99
- spawnIdempotencyKey?: string;
100
- spawnRequestHash?: string;
101
- contract?: DelegationContract;
102
- resultFormat?: SubagentResultFormat;
103
- structuredResult?: AnyStructuredSubagentResult;
104
- outcome?: ClassifiedSubagentOutcome;
105
- executionPlan?: ExecutionPlan;
106
- capabilityGrant?: CapabilityGrant;
107
- semanticSnapshot?: SemanticSnapshot;
108
- semanticCompatibility?: SemanticCompatibility;
109
- termination?: TurnTerminationReport;
110
- telemetry?: TransportTelemetry;
111
- target?: TargetPolicyAudit;
112
- policy?: { inherited: string[]; overridden: string[]; unsupported: string[] };
113
- mailbox: AgentMailboxMessage[];
114
- currentMailboxMessageIds?: string[];
115
- }
116
-
117
- export interface AgentRunInspectionSummary {
118
- id: string;
119
- taskName?: string;
120
- taskPath?: string;
121
- agent: string;
122
- state: AgentLifecycleState;
123
- createdAt: number;
124
- updatedAt: number;
125
- historyCount: number;
126
- unreadMessages: number;
127
- turnGeneration: number;
128
- pendingCompletionCount: number;
129
- pendingRequiredCompletionCount?: number;
130
- }
131
-
132
- export interface AgentRunInspectionDetail extends AgentRunInspectionSummary {
133
- cwd: string;
134
- thinkingLevel?: SubagentThinkingLevel;
135
- timeoutMs?: number;
136
- currentTimeoutMs?: number;
137
- idleTimeoutMs?: number;
138
- currentIdleTimeoutMs?: number;
139
- maxTurns?: number;
140
- currentMaxTurns?: number;
141
- maxToolCalls?: number;
142
- currentMaxToolCalls?: number;
143
- currentTask?: string;
144
- currentRunId?: string;
145
- currentTurnGeneration?: number;
146
- error?: string;
147
- workspaceMode?: "worktree";
148
- contextTurns?: number;
149
- contextBytes?: number;
150
- contextSources?: number;
151
- contextTruncated?: boolean;
152
- contract?: DelegationContract;
153
- resultFormat?: SubagentResultFormat;
154
- target?: TargetPolicyAudit;
155
- policy?: { inherited: string[]; overridden: string[]; unsupported: string[] };
156
- structuredResult?: AnyStructuredSubagentResult;
157
- outcome?: ClassifiedSubagentOutcome;
158
- executionPlan?: ExecutionPlan;
159
- capabilityGrant?: CapabilityGrant;
160
- semanticSnapshot?: SemanticSnapshot;
161
- semanticCompatibility?: SemanticCompatibility;
162
- termination?: TurnTerminationReport;
163
- completionRequirements?: CompletionRequirementRecord[];
164
- telemetry?: TransportTelemetry;
165
- }
166
-
167
- export interface AgentInspectionCounts {
168
- activeAgents: number;
169
- retainedAgents: number;
170
- }
171
-
172
- export interface TurnOutcome {
173
- output: string;
174
- exitCode: number;
175
- aborted?: boolean;
176
- truncated?: boolean;
177
- error?: string;
178
- policy?: ManagedAgent["policy"];
179
- structuredResult?: AnyStructuredSubagentResult;
180
- outcome?: ClassifiedSubagentOutcome;
181
- executionPlan?: ExecutionPlan;
182
- termination?: TurnTerminationReport;
183
- telemetry?: TransportTelemetry;
184
- }
185
-
186
- export interface AgentTurnCompletion extends PersistedAgentCompletion {
187
- agent: ManagedAgent;
188
- }
189
-
190
- export interface AgentRegistryOptions {
191
- maxAgents?: number;
192
- maxActiveTurns?: number;
193
- maxHistoryTurns?: number;
194
- maxDepth?: number;
195
- maxChildrenPerAgent?: number;
196
- maxMailboxMessages?: number;
197
- maxMailboxMessageBytes?: number;
198
- maxTaskBytes?: number;
199
- maxTurnOutputBytes?: number;
200
- idleTtlMs?: number;
201
- now?: () => number;
202
- onChange?: (agents: ManagedAgent[]) => void | Promise<void>;
203
- onTurnComplete?: (completion: AgentTurnCompletion) => void | Promise<void>;
204
- }