@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,305 +0,0 @@
1
- import { redactPrivateText } from "./context.js";
2
- import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
3
-
4
- export const TIMEOUT_CHECKPOINT_VERSION = "pi-subagents:checkpoint:v1" as const;
5
- export const TURN_TERMINATION_VERSION = "pi-subagents:termination:v1" as const;
6
-
7
- const DEFAULT_CHECKPOINT_BYTES = 16 * 1024;
8
- const MAX_ITEMS = 10;
9
- const MAX_ITEM_BYTES = 2 * 1024;
10
- const MAX_PENDING_TOOLS = 50;
11
- const MUTATING_TOOLS = new Set(["bash", "edit", "write"]);
12
- const FILE_TOOLS = new Set(["edit", "write"]);
13
-
14
- export type TurnTerminationReason =
15
- | "work_timeout"
16
- | "idle_timeout"
17
- | "turn_limit"
18
- | "tool_call_limit"
19
- | "orchestration_timeout";
20
-
21
- export interface CompletedToolEvidence {
22
- toolName: string;
23
- output: string;
24
- isError: boolean;
25
- }
26
-
27
- export interface TimeoutCheckpoint {
28
- version: typeof TIMEOUT_CHECKPOINT_VERSION;
29
- task: string;
30
- partialOutput?: string;
31
- assistantNotes: string[];
32
- completedTools: CompletedToolEvidence[];
33
- changedFiles: string[];
34
- sideEffectsMayHaveOccurred: boolean;
35
- truncated: boolean;
36
- }
37
-
38
- export interface TurnFinalizationReport {
39
- attempted: boolean;
40
- status: "completed" | "failed" | "timed_out" | "skipped";
41
- durationMs: number;
42
- error?: string;
43
- }
44
-
45
- export interface TurnTerminationReport {
46
- version: typeof TURN_TERMINATION_VERSION;
47
- reason: TurnTerminationReason;
48
- limit: number;
49
- checkpoint: TimeoutCheckpoint;
50
- finalization: TurnFinalizationReport;
51
- }
52
-
53
- export interface TimeoutProgressJournalOptions {
54
- maxBytes?: number;
55
- }
56
-
57
- interface PendingToolCall {
58
- name: string;
59
- path?: string;
60
- }
61
-
62
- export class TimeoutProgressJournal {
63
- private readonly assistantNotes: string[] = [];
64
- private readonly completedTools: CompletedToolEvidence[] = [];
65
- private readonly changedFiles = new Set<string>();
66
- private readonly pendingTools = new Map<string, PendingToolCall>();
67
- private readonly maxBytes: number;
68
- private sideEffectsMayHaveOccurred = false;
69
- private truncated = false;
70
-
71
- constructor(options: TimeoutProgressJournalOptions = {}) {
72
- const requested = options.maxBytes ?? DEFAULT_CHECKPOINT_BYTES;
73
- if (
74
- !Number.isSafeInteger(requested) ||
75
- requested < 512 ||
76
- requested > DEFAULT_MAX_CONTEXT_BYTES
77
- ) {
78
- throw new Error(
79
- `Timeout checkpoint limit must be an integer between 512 and ${DEFAULT_MAX_CONTEXT_BYTES}`,
80
- );
81
- }
82
- this.maxBytes = requested;
83
- }
84
-
85
- recordAssistantText(text: string): void {
86
- const bounded = boundedPrivate(text, MAX_ITEM_BYTES);
87
- if (!bounded) return;
88
- this.assistantNotes.push(bounded);
89
- this.trimItems(this.assistantNotes);
90
- }
91
-
92
- recordToolCall(id: string, name: string, args: Record<string, unknown> = {}): void {
93
- const toolName = boundedPrivate(name, 256);
94
- if (!toolName) return;
95
- const path = toolPath(args);
96
- this.pendingTools.set(id, { name: toolName, path });
97
- while (this.pendingTools.size > MAX_PENDING_TOOLS) {
98
- const oldest = this.pendingTools.keys().next().value;
99
- if (typeof oldest !== "string") break;
100
- this.pendingTools.delete(oldest);
101
- this.truncated = true;
102
- }
103
- if (MUTATING_TOOLS.has(toolName)) this.sideEffectsMayHaveOccurred = true;
104
- }
105
-
106
- recordToolResult(
107
- id: string,
108
- name: string,
109
- result: { content?: unknown; isError?: unknown },
110
- ): void {
111
- const pending = this.pendingTools.get(id);
112
- this.pendingTools.delete(id);
113
- const toolName = boundedPrivate(pending?.name || name, 256);
114
- if (!toolName) return;
115
- if (pending?.path && FILE_TOOLS.has(toolName)) this.changedFiles.add(pending.path);
116
- const output = boundedPrivate(textContent(result.content), MAX_ITEM_BYTES);
117
- this.completedTools.push({
118
- toolName,
119
- output: output || "(no text output)",
120
- isError: result.isError === true,
121
- });
122
- this.trimItems(this.completedTools);
123
- }
124
-
125
- checkpoint(task: string, partialOutput?: string): TimeoutCheckpoint {
126
- const checkpoint: TimeoutCheckpoint = {
127
- version: TIMEOUT_CHECKPOINT_VERSION,
128
- task: boundedPrivate(task, 4 * 1024),
129
- partialOutput: partialOutput ? boundedPrivate(partialOutput, 4 * 1024) : undefined,
130
- assistantNotes: [...this.assistantNotes],
131
- completedTools: this.completedTools.map((item) => ({ ...item })),
132
- changedFiles: [...this.changedFiles].slice(-MAX_ITEMS),
133
- sideEffectsMayHaveOccurred: this.sideEffectsMayHaveOccurred,
134
- truncated: this.truncated || this.changedFiles.size > MAX_ITEMS,
135
- };
136
- return fitCheckpoint(checkpoint, this.maxBytes);
137
- }
138
-
139
- private trimItems(items: unknown[]): void {
140
- if (items.length <= MAX_ITEMS) return;
141
- items.splice(0, items.length - MAX_ITEMS);
142
- this.truncated = true;
143
- }
144
- }
145
-
146
- export function formatTurnTerminationMessage(
147
- reason: TurnTerminationReason,
148
- limit: number,
149
- prefix = "Subagent",
150
- ): string {
151
- switch (reason) {
152
- case "work_timeout":
153
- return `${prefix} timed out after ${limit}ms`;
154
- case "orchestration_timeout":
155
- return `${prefix} orchestration deadline expired after ${limit}ms`;
156
- case "idle_timeout":
157
- return `${prefix} made no completed progress for ${limit}ms`;
158
- case "turn_limit":
159
- return `${prefix} reached the ${limit}-turn limit before producing a final answer`;
160
- case "tool_call_limit":
161
- return `${prefix} exceeded the ${limit}-tool-call limit`;
162
- }
163
- }
164
-
165
- export function copyTurnTerminationReport(report: TurnTerminationReport): TurnTerminationReport {
166
- return {
167
- ...report,
168
- checkpoint: {
169
- ...report.checkpoint,
170
- assistantNotes: [...report.checkpoint.assistantNotes],
171
- completedTools: report.checkpoint.completedTools.map((item) => ({ ...item })),
172
- changedFiles: [...report.checkpoint.changedFiles],
173
- },
174
- finalization: { ...report.finalization },
175
- };
176
- }
177
-
178
- export function formatTimeoutCheckpoint(checkpoint: TimeoutCheckpoint): string {
179
- const sections = [
180
- checkpoint.partialOutput ? `Partial output:\n${checkpoint.partialOutput}` : undefined,
181
- checkpoint.assistantNotes.length > 0
182
- ? `Assistant checkpoints:\n${checkpoint.assistantNotes.map((note) => `- ${note}`).join("\n")}`
183
- : undefined,
184
- checkpoint.completedTools.length > 0
185
- ? `Completed tool evidence:\n${checkpoint.completedTools
186
- .map((item) => `- ${item.toolName}${item.isError ? " (error)" : ""}: ${item.output}`)
187
- .join("\n")}`
188
- : undefined,
189
- checkpoint.changedFiles.length > 0
190
- ? `Changed files: ${checkpoint.changedFiles.join(", ")}`
191
- : undefined,
192
- checkpoint.sideEffectsMayHaveOccurred
193
- ? "Side effects may have occurred before termination."
194
- : undefined,
195
- checkpoint.truncated ? "Checkpoint evidence was truncated." : undefined,
196
- ].filter((value): value is string => Boolean(value));
197
- return truncateUtf8(
198
- sections.join("\n\n") || "No completed evidence was captured.",
199
- DEFAULT_MAX_CONTEXT_BYTES,
200
- ).text;
201
- }
202
-
203
- export function journalMessages(
204
- journal: TimeoutProgressJournal,
205
- messages: readonly unknown[],
206
- ): void {
207
- for (const message of messages) {
208
- if (!message || typeof message !== "object" || Array.isArray(message)) continue;
209
- const value = message as Record<string, unknown>;
210
- if (value.role === "assistant" && Array.isArray(value.content)) {
211
- for (const part of value.content) {
212
- if (!part || typeof part !== "object" || Array.isArray(part)) continue;
213
- const item = part as Record<string, unknown>;
214
- if (item.type === "text" && typeof item.text === "string") {
215
- journal.recordAssistantText(item.text);
216
- } else if (
217
- item.type === "toolCall" &&
218
- typeof item.id === "string" &&
219
- typeof item.name === "string"
220
- ) {
221
- journal.recordToolCall(
222
- item.id,
223
- item.name,
224
- isRecord(item.arguments) ? item.arguments : {},
225
- );
226
- }
227
- }
228
- } else if (value.role === "toolResult") {
229
- journal.recordToolResult(
230
- typeof value.toolCallId === "string" ? value.toolCallId : "",
231
- typeof value.toolName === "string" ? value.toolName : "tool",
232
- { content: value.content, isError: value.isError },
233
- );
234
- }
235
- }
236
- }
237
-
238
- function fitCheckpoint(checkpoint: TimeoutCheckpoint, maxBytes: number): TimeoutCheckpoint {
239
- const copy: TimeoutCheckpoint = {
240
- ...checkpoint,
241
- assistantNotes: [...checkpoint.assistantNotes],
242
- completedTools: checkpoint.completedTools.map((item) => ({ ...item })),
243
- changedFiles: [...checkpoint.changedFiles],
244
- };
245
- while (serializedBytes(copy) > maxBytes) {
246
- copy.truncated = true;
247
- if (copy.assistantNotes.length > 0) copy.assistantNotes.shift();
248
- else if (copy.completedTools.length > 0) copy.completedTools.shift();
249
- else if (copy.changedFiles.length > 0) copy.changedFiles.shift();
250
- else if (copy.partialOutput) {
251
- copy.partialOutput =
252
- shrinkCheckpointText(copy.partialOutput, Math.floor(maxBytes / 4), 128) || undefined;
253
- } else if (copy.task) {
254
- copy.task = shrinkCheckpointText(copy.task, Math.floor(maxBytes / 8), 64);
255
- } else break;
256
- }
257
- return copy;
258
- }
259
-
260
- function shrinkCheckpointText(
261
- value: string,
262
- preferredMaxBytes: number,
263
- minimumBytes: number,
264
- ): string {
265
- const currentBytes = Buffer.byteLength(value, "utf8");
266
- if (currentBytes <= minimumBytes) return "";
267
- const nextMaxBytes = Math.min(
268
- currentBytes - 1,
269
- preferredMaxBytes,
270
- Math.max(minimumBytes, Math.floor(currentBytes / 2)),
271
- );
272
- return truncateUtf8(value, nextMaxBytes).text;
273
- }
274
-
275
- function serializedBytes(value: unknown): number {
276
- return Buffer.byteLength(JSON.stringify(value), "utf8");
277
- }
278
-
279
- function boundedPrivate(value: string, maxBytes: number): string {
280
- return truncateUtf8(redactPrivateText(value).trim(), maxBytes).text;
281
- }
282
-
283
- function textContent(value: unknown): string {
284
- if (typeof value === "string") return value;
285
- if (!Array.isArray(value)) return "";
286
- return value
287
- .flatMap((part) => {
288
- if (!part || typeof part !== "object" || Array.isArray(part)) return [];
289
- const item = part as Record<string, unknown>;
290
- return item.type === "text" && typeof item.text === "string" ? [item.text] : [];
291
- })
292
- .join("\n");
293
- }
294
-
295
- function toolPath(args: Record<string, unknown>): string | undefined {
296
- for (const key of ["path", "file_path"]) {
297
- const value = args[key];
298
- if (typeof value === "string" && value.trim()) return boundedPrivate(value, 1024);
299
- }
300
- return undefined;
301
- }
302
-
303
- function isRecord(value: unknown): value is Record<string, unknown> {
304
- return Boolean(value && typeof value === "object" && !Array.isArray(value));
305
- }
@@ -1,75 +0,0 @@
1
- import { redactPrivateText } from "./context.js";
2
- import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
3
- import { appendResultInstruction, type SubagentResultFormat } from "./result-contract.js";
4
- import type { RecentActivityItem } from "./runner-types.js";
5
- import {
6
- formatTimeoutCheckpoint,
7
- type TimeoutCheckpoint,
8
- type TurnTerminationReason,
9
- } from "./timeout-checkpoint.js";
10
-
11
- export const DEFAULT_TIMEOUT_FINALIZATION_MS = 45_000;
12
-
13
- export interface TimeoutFinalizationEvidence {
14
- task: string;
15
- partialOutput?: string;
16
- recentActivity?: readonly RecentActivityItem[];
17
- checkpoint?: TimeoutCheckpoint;
18
- terminationReason?: TurnTerminationReason;
19
- resultFormat?: SubagentResultFormat;
20
- }
21
-
22
- export function resolveTimeoutFinalizationMs(workTimeoutMs: number, override?: number): number {
23
- const requested = override ?? Math.min(workTimeoutMs, DEFAULT_TIMEOUT_FINALIZATION_MS);
24
- if (!Number.isFinite(requested) || requested < 1) {
25
- throw new Error("Timeout finalization deadline must be a positive finite number");
26
- }
27
- return Math.min(Math.floor(requested), DEFAULT_TIMEOUT_FINALIZATION_MS);
28
- }
29
-
30
- export function buildTimeoutFinalizationPrompt(
31
- evidence: TimeoutFinalizationEvidence,
32
- maxBytes = DEFAULT_MAX_CONTEXT_BYTES,
33
- ): string {
34
- const activity = (evidence.recentActivity ?? [])
35
- .slice(-10)
36
- .map((item) =>
37
- item.type === "text"
38
- ? `- Assistant note: ${redactPrivateText(item.text)}`
39
- : `- Tool activity: ${redactPrivateText(item.name)}`,
40
- )
41
- .join("\n");
42
- const prompt = [
43
- terminationHeading(evidence.terminationReason),
44
- "Do not continue investigating, call tools, modify files, or retry the original task.",
45
- "Return a concise summary of only verified findings and completed evidence already available.",
46
- "Explicitly label unfinished or unverified areas.",
47
- `Original task:\n${redactPrivateText(evidence.task)}`,
48
- evidence.partialOutput
49
- ? `Partial assistant output:\n${redactPrivateText(evidence.partialOutput)}`
50
- : "Partial assistant output: (none)",
51
- evidence.checkpoint
52
- ? `Deterministic progress checkpoint:\n${formatTimeoutCheckpoint(evidence.checkpoint)}`
53
- : undefined,
54
- activity ? `Recent bounded activity:\n${activity}` : "Recent bounded activity: (none)",
55
- ]
56
- .filter((value): value is string => Boolean(value))
57
- .join("\n\n");
58
- return truncateUtf8(appendResultInstruction(prompt, evidence.resultFormat, maxBytes), maxBytes)
59
- .text;
60
- }
61
-
62
- function terminationHeading(reason: TurnTerminationReason | undefined): string {
63
- switch (reason) {
64
- case "idle_timeout":
65
- return "The idle deadline expired and the active work was aborted.";
66
- case "turn_limit":
67
- return "The assistant-turn budget was exhausted and the active work was aborted.";
68
- case "tool_call_limit":
69
- return "The tool-call budget was exhausted and the active work was aborted.";
70
- case "orchestration_timeout":
71
- return "The orchestration deadline expired and the active work was aborted.";
72
- default:
73
- return "Work deadline expired and the active work was aborted.";
74
- }
75
- }
@@ -1,73 +0,0 @@
1
- import { type TObject, type TObjectOptions, type TProperties, type TSchema, Type } from "typebox";
2
-
3
- const LLAMA_CPP_MAX_REPETITION_THRESHOLD = 2_000;
4
-
5
- /**
6
- * Remove large nested string repetitions that llama.cpp cannot compile into GBNF.
7
- *
8
- * Runtime normalization and validation continue to bound these inputs.
9
- * See https://github.com/ggml-org/llama.cpp/issues/25746.
10
- */
11
- export function grammarSafeToolObject<Properties extends TProperties>(
12
- properties: Properties,
13
- options?: TObjectOptions,
14
- ): TObject<Properties> {
15
- return makeGrammarSafeToolSchema(Type.Object(properties, options));
16
- }
17
-
18
- function makeGrammarSafeToolSchema<Schema extends TSchema>(schema: Schema): Schema {
19
- return cloneSchema(schema, 0) as Schema;
20
- }
21
-
22
- function cloneSchema(schema: unknown, depth: number): unknown {
23
- if (!isRecord(schema)) return schema;
24
- const clone = cloneWithDescriptors(schema);
25
- if (
26
- depth > 1 &&
27
- clone.type === "string" &&
28
- typeof clone.maxLength === "number" &&
29
- clone.maxLength >= LLAMA_CPP_MAX_REPETITION_THRESHOLD
30
- ) {
31
- delete clone.maxLength;
32
- }
33
- if (isRecord(clone.properties)) {
34
- clone.properties = mapSchemas(clone.properties, depth + 1);
35
- }
36
- if (clone.items !== undefined) {
37
- clone.items = Array.isArray(clone.items)
38
- ? clone.items.map((item) => cloneSchema(item, depth + 1))
39
- : cloneSchema(clone.items, depth + 1);
40
- }
41
- if (Array.isArray(clone.prefixItems)) {
42
- clone.prefixItems = clone.prefixItems.map((item) => cloneSchema(item, depth + 1));
43
- }
44
- for (const keyword of ["allOf", "anyOf", "oneOf"] as const) {
45
- if (Array.isArray(clone[keyword])) {
46
- clone[keyword] = clone[keyword].map((item) => cloneSchema(item, depth));
47
- }
48
- }
49
- if (isRecord(clone.patternProperties)) {
50
- clone.patternProperties = mapSchemas(clone.patternProperties, depth + 1);
51
- }
52
- if (isRecord(clone.additionalProperties)) {
53
- clone.additionalProperties = cloneSchema(clone.additionalProperties, depth + 1);
54
- }
55
- return clone;
56
- }
57
-
58
- function mapSchemas(schemas: Record<string, unknown>, depth: number): Record<string, unknown> {
59
- return Object.fromEntries(
60
- Object.entries(schemas).map(([name, schema]) => [name, cloneSchema(schema, depth)]),
61
- );
62
- }
63
-
64
- function cloneWithDescriptors(value: Record<string, unknown>): Record<string, unknown> {
65
- return Object.defineProperties(
66
- Object.create(Object.getPrototypeOf(value)),
67
- Object.getOwnPropertyDescriptors(value),
68
- ) as Record<string, unknown>;
69
- }
70
-
71
- function isRecord(value: unknown): value is Record<string, unknown> {
72
- return typeof value === "object" && value !== null && !Array.isArray(value);
73
- }
@@ -1,74 +0,0 @@
1
- import type { SubagentThinkingLevel } from "./agents/types.js";
2
-
3
- export const PI_SUBAGENTS_RPC_PROTOCOL = "pi-subagents:v1" as const;
4
-
5
- export type EffectiveSubagentTransportKind = "subprocess" | "in-process" | "rpc";
6
-
7
- export type TransportProgressPhase =
8
- | "queued"
9
- | "starting"
10
- | "ready"
11
- | "accepted"
12
- | "running"
13
- | "finalizing"
14
- | "retrying"
15
- | "compacting"
16
- | "settled"
17
- | "failed"
18
- | "interrupted";
19
-
20
- export interface TransportUsage {
21
- input: number;
22
- output: number;
23
- cacheRead: number;
24
- cacheWrite: number;
25
- totalTokens: number;
26
- cost: number;
27
- turns: number;
28
- }
29
-
30
- export interface TransportTiming {
31
- queuedAt?: number;
32
- startedAt?: number;
33
- transportStartedAt?: number;
34
- readyAt?: number;
35
- promptAcceptedAt?: number;
36
- firstActivityAt?: number;
37
- settledAt?: number;
38
- completionDeliveredAt?: number;
39
- }
40
-
41
- export interface TransportTelemetry {
42
- transport?: EffectiveSubagentTransportKind;
43
- selectionReason?: string;
44
- protocol?: typeof PI_SUBAGENTS_RPC_PROTOCOL;
45
- phase: TransportProgressPhase;
46
- queuePosition?: number;
47
- updatedAt: number;
48
- timing: TransportTiming;
49
- provider?: string;
50
- model?: string;
51
- thinkingLevel?: SubagentThinkingLevel;
52
- usage?: TransportUsage;
53
- budgetSource?: {
54
- timeout: "runtime" | "explicit";
55
- idleTimeout: "runtime" | "explicit";
56
- turnLimit: "runtime" | "explicit";
57
- toolCallLimit: "runtime" | "explicit";
58
- };
59
- failurePhase?: TransportProgressPhase;
60
- }
61
-
62
- export type TransportProgressCallback = (progress: TransportTelemetry) => void;
63
-
64
- export function emptyTransportUsage(): TransportUsage {
65
- return {
66
- input: 0,
67
- output: 0,
68
- cacheRead: 0,
69
- cacheWrite: 0,
70
- totalTokens: 0,
71
- cost: 0,
72
- turns: 0,
73
- };
74
- }
@@ -1,135 +0,0 @@
1
- import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import type { SubagentTransportKind } from "./agents/types.js";
3
- import { safeTerminalLine as safeTerminalText } from "./safe-text.js";
4
- import { inspectStatefulTransportSettings, updateStatefulTransportSetting } from "./settings.js";
5
- import type { StatefulSubagentRuntimeStatus } from "./stateful.js";
6
-
7
- const TRANSPORT_OPTIONS: Array<{
8
- value: SubagentTransportKind;
9
- label: string;
10
- description: string;
11
- }> = [
12
- {
13
- value: "subprocess",
14
- label: "Fresh process",
15
- description:
16
- "Start a separate Pi process for every turn. Most compatible, but slower for follow-ups.",
17
- },
18
- {
19
- value: "in-process",
20
- label: "Inside Pi",
21
- description:
22
- "Run built-in tools inside Pi for faster follow-ups. Shares Pi's memory and crash boundary.",
23
- },
24
- {
25
- value: "rpc",
26
- label: "Persistent process (RPC)",
27
- description:
28
- "Keep one separate Pi process per background subagent so follow-ups preserve history.",
29
- },
30
- {
31
- value: "auto",
32
- label: "Automatic · Recommended",
33
- description: "Let Pi choose a compatible method for each subagent and its tools.",
34
- },
35
- ];
36
-
37
- export interface TransportUiRuntime {
38
- getRuntimeStatus(): StatefulSubagentRuntimeStatus;
39
- }
40
-
41
- export function transportSettingsScreen(runtime: TransportUiRuntime) {
42
- const configured = inspectStatefulTransportSettings();
43
- const current = runtime.getRuntimeStatus();
44
- return {
45
- kind: "actions" as const,
46
- title: configured.error
47
- ? "Background Agent Transport · Read only"
48
- : "Background Agent Transport",
49
- lines: [
50
- "Advanced: choose how Pi hosts background subagents.",
51
- `Current session: ${transportLabel(current.transport)}`,
52
- `Configured after reload: ${transportLabel(configured.value)} (${configured.source})`,
53
- "Separate processes do not restrict filesystem or network access.",
54
- "Persistent process (RPC) supports built-in Pi tools and does not load child extensions.",
55
- ...(configured.error
56
- ? [
57
- `Settings cannot be edited: ${safeTerminalText(configured.error)}`,
58
- `Repair ${safeTerminalText(configured.path)} and retry.`,
59
- ]
60
- : []),
61
- ],
62
- items: [
63
- ...(configured.error
64
- ? []
65
- : TRANSPORT_OPTIONS.map((option) => ({
66
- id: option.value,
67
- label: option.label,
68
- description: option.description,
69
- action: "set-transport" as const,
70
- }))),
71
- { id: "back", label: "Back", action: "back" as const },
72
- ],
73
- hint: "back" as const,
74
- };
75
- }
76
-
77
- export async function applyTransportSetting(
78
- value: string,
79
- ctx: ExtensionCommandContext,
80
- runtime: TransportUiRuntime,
81
- signal: AbortSignal,
82
- isCurrent: () => boolean,
83
- ) {
84
- if (!isTransport(value)) return { kind: "rejected" as const };
85
- const before = inspectStatefulTransportSettings();
86
- if (before.error) return { kind: "rejected" as const };
87
- if (value === before.value) return { kind: "stay" as const };
88
- const status = runtime.getRuntimeStatus();
89
- if (status.retainedAgents > 0) {
90
- ctx.ui.notify(
91
- `Cannot change transport while ${status.retainedAgents} subagent${status.retainedAgents === 1 ? " is" : "s are"} saved for follow-up. Clear Current subagents first.`,
92
- "warning",
93
- );
94
- return { kind: "rejected" as const };
95
- }
96
- const option = TRANSPORT_OPTIONS.find((candidate) => candidate.value === value);
97
- const confirmed = await ctx.ui.confirm(
98
- `Use ${transportLabel(value)} after reload?`,
99
- `${option?.description ?? ""}\n\nThis saves the setting but does not reload Pi automatically.`,
100
- { signal },
101
- );
102
- if (signal.aborted || !isCurrent()) return { kind: "close" as const };
103
- if (!confirmed) return { kind: "rejected" as const };
104
- const after = inspectStatefulTransportSettings();
105
- if (after.error || after.value !== before.value || after.source !== before.source) {
106
- ctx.ui.notify("Transport settings changed while confirming; review again.", "warning");
107
- return { kind: "rejected" as const };
108
- }
109
- if (runtime.getRuntimeStatus().retainedAgents > 0) {
110
- ctx.ui.notify(
111
- "New subagents were saved for follow-up while confirming. Clear them before changing transport.",
112
- "warning",
113
- );
114
- return { kind: "rejected" as const };
115
- }
116
- try {
117
- updateStatefulTransportSetting(value);
118
- ctx.ui.notify(`Saved ${transportLabel(value)}. Run /reload when ready.`, "info");
119
- return { kind: "stay" as const };
120
- } catch (error) {
121
- ctx.ui.notify(
122
- `Transport was not saved; the previous setting remains: ${safeTerminalText(error instanceof Error ? error.message : String(error))}`,
123
- "error",
124
- );
125
- return { kind: "rejected" as const };
126
- }
127
- }
128
-
129
- export function transportLabel(value: SubagentTransportKind): string {
130
- return TRANSPORT_OPTIONS.find((option) => option.value === value)?.label ?? value;
131
- }
132
-
133
- function isTransport(value: string): value is SubagentTransportKind {
134
- return ["subprocess", "in-process", "rpc", "auto"].includes(value);
135
- }