@code-yeongyu/senpi 2026.8.26 → 2026.8.28

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 (297) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +3 -3
  3. package/dist/cli/args.d.ts +3 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +14 -1
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/core/agent-session.d.ts.map +1 -1
  8. package/dist/core/agent-session.js +10 -1
  9. package/dist/core/agent-session.js.map +1 -1
  10. package/dist/core/bash-executor.d.ts.map +1 -1
  11. package/dist/core/bash-executor.js +67 -29
  12. package/dist/core/bash-executor.js.map +1 -1
  13. package/dist/core/credential-accounts.d.ts +31 -0
  14. package/dist/core/credential-accounts.d.ts.map +1 -0
  15. package/dist/core/credential-accounts.js +125 -0
  16. package/dist/core/credential-accounts.js.map +1 -0
  17. package/dist/core/credential-pool/classify.d.ts +42 -0
  18. package/dist/core/credential-pool/classify.d.ts.map +1 -0
  19. package/dist/core/credential-pool/classify.js +75 -0
  20. package/dist/core/credential-pool/classify.js.map +1 -0
  21. package/dist/core/credential-pool/env-slots.d.ts +22 -0
  22. package/dist/core/credential-pool/env-slots.d.ts.map +1 -0
  23. package/dist/core/credential-pool/env-slots.js +37 -0
  24. package/dist/core/credential-pool/env-slots.js.map +1 -0
  25. package/dist/core/credential-pool/failover.d.ts +54 -0
  26. package/dist/core/credential-pool/failover.d.ts.map +1 -0
  27. package/dist/core/credential-pool/failover.js +106 -0
  28. package/dist/core/credential-pool/failover.js.map +1 -0
  29. package/dist/core/credential-pool/rotation-stream.d.ts +43 -0
  30. package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -0
  31. package/dist/core/credential-pool/rotation-stream.js +96 -0
  32. package/dist/core/credential-pool/rotation-stream.js.map +1 -0
  33. package/dist/core/credential-pool/state-store.d.ts +89 -0
  34. package/dist/core/credential-pool/state-store.d.ts.map +1 -0
  35. package/dist/core/credential-pool/state-store.js +166 -0
  36. package/dist/core/credential-pool/state-store.js.map +1 -0
  37. package/dist/core/extensions/builtin/account/index.d.ts +9 -0
  38. package/dist/core/extensions/builtin/account/index.d.ts.map +1 -0
  39. package/dist/core/extensions/builtin/account/index.js +69 -0
  40. package/dist/core/extensions/builtin/account/index.js.map +1 -0
  41. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  42. package/dist/core/extensions/builtin/compaction/index.js +67 -0
  43. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  44. package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
  45. package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
  46. package/dist/core/extensions/builtin/compaction/log.js +1 -0
  47. package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
  48. package/dist/core/extensions/builtin/config-reload/index.js +14 -22
  49. package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
  50. package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts +1 -0
  51. package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts.map +1 -1
  52. package/dist/core/extensions/builtin/goal/continuation-recovery.js +2 -0
  53. package/dist/core/extensions/builtin/goal/continuation-recovery.js.map +1 -1
  54. package/dist/core/extensions/builtin/goal/continuation.d.ts +8 -1
  55. package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
  56. package/dist/core/extensions/builtin/goal/continuation.js +15 -0
  57. package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
  58. package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js +2 -2
  59. package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js.map +1 -1
  60. package/dist/core/extensions/builtin/goal/format.d.ts +6 -1
  61. package/dist/core/extensions/builtin/goal/format.d.ts.map +1 -1
  62. package/dist/core/extensions/builtin/goal/format.js +6 -0
  63. package/dist/core/extensions/builtin/goal/format.js.map +1 -1
  64. package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
  65. package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +5 -2
  66. package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
  67. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
  68. package/dist/core/extensions/builtin/goal/monitor-continuation.js +31 -7
  69. package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
  70. package/dist/core/extensions/builtin/goal/persistence.js +2 -0
  71. package/dist/core/extensions/builtin/goal/persistence.js.map +1 -1
  72. package/dist/core/extensions/builtin/goal/renderers.d.ts +14 -0
  73. package/dist/core/extensions/builtin/goal/renderers.d.ts.map +1 -0
  74. package/dist/core/extensions/builtin/goal/renderers.js +153 -0
  75. package/dist/core/extensions/builtin/goal/renderers.js.map +1 -0
  76. package/dist/core/extensions/builtin/goal/store.d.ts +6 -2
  77. package/dist/core/extensions/builtin/goal/store.d.ts.map +1 -1
  78. package/dist/core/extensions/builtin/goal/store.js +8 -2
  79. package/dist/core/extensions/builtin/goal/store.js.map +1 -1
  80. package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
  81. package/dist/core/extensions/builtin/goal/tool-registration.js +16 -6
  82. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  83. package/dist/core/extensions/builtin/goal/types.d.ts +1 -0
  84. package/dist/core/extensions/builtin/goal/types.d.ts.map +1 -1
  85. package/dist/core/extensions/builtin/goal/types.js.map +1 -1
  86. package/dist/core/extensions/builtin/imagegen/index.d.ts.map +1 -1
  87. package/dist/core/extensions/builtin/imagegen/index.js +10 -3
  88. package/dist/core/extensions/builtin/imagegen/index.js.map +1 -1
  89. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  90. package/dist/core/extensions/builtin/index.js +4 -0
  91. package/dist/core/extensions/builtin/index.js.map +1 -1
  92. package/dist/core/extensions/builtin/todotools/index.js +1 -1
  93. package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
  94. package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts +1 -1
  95. package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts.map +1 -1
  96. package/dist/core/extensions/builtin/todotools/native-todo-mirror.js +1 -1
  97. package/dist/core/extensions/builtin/todotools/native-todo-mirror.js.map +1 -1
  98. package/dist/core/hidden-stdout-log.d.ts +10 -0
  99. package/dist/core/hidden-stdout-log.d.ts.map +1 -1
  100. package/dist/core/hidden-stdout-log.js +36 -5
  101. package/dist/core/hidden-stdout-log.js.map +1 -1
  102. package/dist/core/model-config-schema.d.ts +85 -12
  103. package/dist/core/model-config-schema.d.ts.map +1 -1
  104. package/dist/core/model-config-schema.js +25 -0
  105. package/dist/core/model-config-schema.js.map +1 -1
  106. package/dist/core/model-runtime.d.ts +34 -1
  107. package/dist/core/model-runtime.d.ts.map +1 -1
  108. package/dist/core/model-runtime.js +98 -5
  109. package/dist/core/model-runtime.js.map +1 -1
  110. package/dist/core/tools/output-accumulator.d.ts +2 -0
  111. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  112. package/dist/core/tools/output-accumulator.js +32 -7
  113. package/dist/core/tools/output-accumulator.js.map +1 -1
  114. package/dist/index.d.ts +1 -1
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +1 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/main.d.ts.map +1 -1
  119. package/dist/main.js +38 -3
  120. package/dist/main.js.map +1 -1
  121. package/dist/modes/app-server/server/account.d.ts.map +1 -1
  122. package/dist/modes/app-server/server/account.js +5 -5
  123. package/dist/modes/app-server/server/account.js.map +1 -1
  124. package/dist/modes/index.d.ts +1 -0
  125. package/dist/modes/index.d.ts.map +1 -1
  126. package/dist/modes/index.js +1 -0
  127. package/dist/modes/index.js.map +1 -1
  128. package/dist/modes/interactive/components/footer.d.ts +11 -3
  129. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  130. package/dist/modes/interactive/components/footer.js +31 -1
  131. package/dist/modes/interactive/components/footer.js.map +1 -1
  132. package/dist/modes/interactive/components/tool-execution-fallback.d.ts.map +1 -1
  133. package/dist/modes/interactive/components/tool-execution-fallback.js +82 -1
  134. package/dist/modes/interactive/components/tool-execution-fallback.js.map +1 -1
  135. package/dist/modes/interactive/grok/chrome.d.ts +4 -4
  136. package/dist/modes/interactive/grok/chrome.d.ts.map +1 -1
  137. package/dist/modes/interactive/grok/chrome.js.map +1 -1
  138. package/dist/modes/interactive/grok/footer.d.ts +3 -3
  139. package/dist/modes/interactive/grok/footer.d.ts.map +1 -1
  140. package/dist/modes/interactive/grok/footer.js.map +1 -1
  141. package/dist/modes/interactive/interactive-host-runtime.d.ts +44 -0
  142. package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -0
  143. package/dist/modes/interactive/interactive-host-runtime.js +271 -0
  144. package/dist/modes/interactive/interactive-host-runtime.js.map +1 -0
  145. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  146. package/dist/modes/interactive/interactive-mode.js +65 -21
  147. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  148. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  149. package/dist/modes/rpc/connection-handler.js +19 -6
  150. package/dist/modes/rpc/connection-handler.js.map +1 -1
  151. package/dist/modes/rpc/host-ensure.d.ts +41 -0
  152. package/dist/modes/rpc/host-ensure.d.ts.map +1 -0
  153. package/dist/modes/rpc/host-ensure.js +245 -0
  154. package/dist/modes/rpc/host-ensure.js.map +1 -0
  155. package/dist/modes/rpc/host-lifecycle.d.ts +57 -0
  156. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -0
  157. package/dist/modes/rpc/host-lifecycle.js +491 -0
  158. package/dist/modes/rpc/host-lifecycle.js.map +1 -0
  159. package/dist/modes/rpc/host-watchdog.d.ts +33 -0
  160. package/dist/modes/rpc/host-watchdog.d.ts.map +1 -0
  161. package/dist/modes/rpc/host-watchdog.js +142 -0
  162. package/dist/modes/rpc/host-watchdog.js.map +1 -0
  163. package/dist/modes/rpc/multi-session-host.d.ts +7 -1
  164. package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
  165. package/dist/modes/rpc/multi-session-host.js +206 -32
  166. package/dist/modes/rpc/multi-session-host.js.map +1 -1
  167. package/dist/modes/rpc/rpc-client.d.ts +41 -3
  168. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  169. package/dist/modes/rpc/rpc-client.js +125 -14
  170. package/dist/modes/rpc/rpc-client.js.map +1 -1
  171. package/dist/modes/rpc/rpc-mode.d.ts +1 -1
  172. package/dist/modes/rpc/rpc-mode.js +1 -1
  173. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  174. package/dist/modes/rpc/rpc-types.d.ts +6 -2
  175. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  176. package/dist/modes/rpc/rpc-types.js.map +1 -1
  177. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  178. package/dist/modes/rpc/session-command-router.js +24 -6
  179. package/dist/modes/rpc/session-command-router.js.map +1 -1
  180. package/dist/modes/rpc/session-event-writer.d.ts +13 -2
  181. package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
  182. package/dist/modes/rpc/session-event-writer.js +65 -25
  183. package/dist/modes/rpc/session-event-writer.js.map +1 -1
  184. package/dist/modes/rpc/session-registry.d.ts +9 -0
  185. package/dist/modes/rpc/session-registry.d.ts.map +1 -1
  186. package/dist/modes/rpc/session-registry.js +31 -3
  187. package/dist/modes/rpc/session-registry.js.map +1 -1
  188. package/docs/providers.md +48 -0
  189. package/docs/rpc.md +59 -5
  190. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +44 -0
  191. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  192. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +13 -1
  193. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/inline-worker.ts +15 -1
  194. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +711 -1
  195. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/transport.ts +14 -1
  196. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +10 -10
  197. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-eval-result.ts +9 -3
  198. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +6 -1
  199. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.d.ts.map +1 -1
  200. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.js +20 -4
  201. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/edit.js.map +1 -1
  202. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.d.ts +1 -1
  203. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.d.ts.map +1 -1
  204. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/index.js.map +1 -1
  205. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/post-mutate.d.ts +21 -0
  206. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/post-mutate.d.ts.map +1 -0
  207. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/post-mutate.js +27 -0
  208. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/post-mutate.js.map +1 -0
  209. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.d.ts +24 -0
  210. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.d.ts.map +1 -1
  211. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/tool-context.js.map +1 -1
  212. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.d.ts.map +1 -1
  213. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.js +7 -2
  214. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/write.js.map +1 -1
  215. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  216. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts +1 -1
  217. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts.map +1 -1
  218. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js +46 -14
  219. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js.map +1 -1
  220. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts +11 -0
  221. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts.map +1 -1
  222. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +30 -16
  223. package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
  224. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts +2 -1
  225. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts.map +1 -1
  226. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js +2 -1
  227. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js.map +1 -1
  228. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts +16 -0
  229. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts.map +1 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js +75 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js.map +1 -0
  232. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts +45 -0
  233. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts.map +1 -0
  234. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js +81 -0
  235. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js.map +1 -0
  236. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts +31 -0
  237. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts.map +1 -0
  238. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js +65 -0
  239. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js.map +1 -0
  240. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +12 -0
  241. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
  242. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +37 -0
  243. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
  244. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +6 -0
  245. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
  246. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +32 -6
  247. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
  248. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +3 -2
  249. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
  250. package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
  251. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +6 -0
  252. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
  253. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +6 -1
  254. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
  255. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +75 -0
  256. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  257. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +75 -0
  258. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  259. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  260. package/node_modules/@earendil-works/pi-ai/dist/providers/data/alibaba-token-plan.json +1 -1
  261. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  262. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  263. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  264. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  265. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  266. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  267. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  268. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  269. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  270. package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  271. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  272. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  273. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  274. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  275. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  276. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
  277. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  278. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  279. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  280. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  281. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  282. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  283. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  284. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  285. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +4 -0
  286. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  287. package/node_modules/@earendil-works/pi-ai/package.json +5 -5
  288. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  289. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  290. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +5 -0
  291. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  292. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +90 -1
  293. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  294. package/node_modules/@earendil-works/pi-tui/dist/tui.js +1 -1
  295. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  296. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  297. package/package.json +7 -7
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Opt-in supervisor-lifetime watchdog for the RPC socket host.
3
+ *
4
+ * A host started under the `host-lifecycle.ts` supervisor must not outlive it.
5
+ * Catchable signals cannot carry that guarantee: `kill -9`, an OOM kill, or a
6
+ * crashed supervisor run no JS handler, and the host is then reparented to init
7
+ * as a permanent orphan holding its private socket forever.
8
+ *
9
+ * The binding used here is the OS itself. The supervisor spawns the host with an
10
+ * extra inherited pipe and keeps the write end open without ever writing to it.
11
+ * The kernel closes that end when the supervisor dies for ANY reason, so the
12
+ * host's read end reaches EOF and the host shuts down cleanly.
13
+ *
14
+ * Both variables are unset for every other host launch, so nothing changes for
15
+ * plain `senpi --mode rpc` runs, hosts started by hand, or embedders.
16
+ */
17
+ import { createReadStream } from "node:fs";
18
+ import { rm } from "node:fs/promises";
19
+ import { envValue } from "../../core/brand.js";
20
+ /** Inherited fd whose EOF means "the supervisor died"; set by the supervisor only. */
21
+ export const HOST_WATCH_FD_ENV = "SENPI_RPC_HOST_WATCH_FD";
22
+ /** Supervisor-owned private directory the host removes on watchdog shutdown. */
23
+ export const HOST_SCRATCH_DIR_ENV = "SENPI_RPC_HOST_SCRATCH_DIR";
24
+ /** Fallback binding when no inherited fd is available: poll this pid. */
25
+ export const HOST_WATCH_PPID_ENV = "SENPI_RPC_HOST_WATCH_PPID";
26
+ /** Poll cadence for the ppid fallback. */
27
+ export const HOST_WATCH_PPID_INTERVAL_MS = 2_000;
28
+ function parsePositiveInteger(value) {
29
+ if (value === undefined || !/^\d+$/.test(value.trim()))
30
+ return undefined;
31
+ const parsed = Number(value.trim());
32
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
33
+ }
34
+ /**
35
+ * Reads the watchdog configuration from the environment. Returns `undefined`
36
+ * when neither binding is requested, which is the case for every host launch
37
+ * that does not come from the lifecycle supervisor.
38
+ */
39
+ export function readHostWatchdogConfig(env = process.env) {
40
+ const fd = parsePositiveInteger(env[HOST_WATCH_FD_ENV]);
41
+ const ppid = parsePositiveInteger(env[HOST_WATCH_PPID_ENV]);
42
+ if (fd === undefined && ppid === undefined)
43
+ return undefined;
44
+ const scratchDir = env[HOST_SCRATCH_DIR_ENV];
45
+ return { fd, ppid, scratchDir: scratchDir === undefined || scratchDir === "" ? undefined : scratchDir };
46
+ }
47
+ /** Same configuration, resolved through the brand-aware env prefixes. */
48
+ export function readHostWatchdogConfigFromBrandEnv() {
49
+ return readHostWatchdogConfig({
50
+ [HOST_WATCH_FD_ENV]: envValue("RPC_HOST_WATCH_FD"),
51
+ [HOST_WATCH_PPID_ENV]: envValue("RPC_HOST_WATCH_PPID"),
52
+ [HOST_SCRATCH_DIR_ENV]: envValue("RPC_HOST_SCRATCH_DIR"),
53
+ });
54
+ }
55
+ /**
56
+ * Arms the configured watchdog. `onSupervisorGone` receives the reason and is
57
+ * expected to perform the host's normal clean shutdown; the scratch directory
58
+ * (the supervisor's private socket directory, which no longer has an owner) is
59
+ * removed first so nothing is left behind even if shutdown then hangs.
60
+ *
61
+ * Takes ownership of `config.fd`: disarming (or firing) closes it, so callers
62
+ * must not close it themselves. Returns a disarm function; a no-op when no
63
+ * binding is configured.
64
+ */
65
+ export function armHostWatchdog(config, onSupervisorGone) {
66
+ if (!config)
67
+ return () => { };
68
+ const fire = (reason) => {
69
+ disarm();
70
+ void cleanupScratchDir(config.scratchDir).finally(() => onSupervisorGone(reason));
71
+ };
72
+ const disarmers = [];
73
+ const disarm = () => {
74
+ for (const stop of disarmers.splice(0))
75
+ stop();
76
+ };
77
+ if (config.fd !== undefined)
78
+ disarmers.push(watchFdForEof(config.fd, fire));
79
+ if (config.ppid !== undefined)
80
+ disarmers.push(watchPpid(config.ppid, fire));
81
+ return disarm;
82
+ }
83
+ /**
84
+ * EOF on the inherited pipe is the primary signal. The supervisor never writes
85
+ * to it, so any readable data is ignored; only close matters. An fd that cannot
86
+ * be opened (never inherited) leaves the binding inert rather than killing a
87
+ * healthy host.
88
+ */
89
+ function watchFdForEof(fd, fire) {
90
+ let stream;
91
+ try {
92
+ stream = createReadStream("", { fd, autoClose: false });
93
+ }
94
+ catch {
95
+ return () => { };
96
+ }
97
+ stream.resume();
98
+ const onEnd = () => fire(`supervisor pipe fd ${fd} closed`);
99
+ stream.once("end", onEnd);
100
+ // A read error means the pipe is unusable, which is indistinguishable from a
101
+ // dead supervisor from this side; treating it as EOF keeps the binding safe.
102
+ stream.once("error", onEnd);
103
+ return () => {
104
+ stream.off("end", onEnd);
105
+ stream.off("error", onEnd);
106
+ stream.destroy();
107
+ };
108
+ }
109
+ /**
110
+ * Fallback binding: the supervisor pid is gone, or this process was reparented
111
+ * to init because the supervisor died. Polling covers the case where no extra
112
+ * fd could be inherited.
113
+ */
114
+ function watchPpid(supervisorPid, fire) {
115
+ const timer = setInterval(() => {
116
+ if (process.ppid === supervisorPid && processAlive(supervisorPid))
117
+ return;
118
+ fire(`supervisor pid ${supervisorPid} is gone (ppid=${process.ppid})`);
119
+ }, HOST_WATCH_PPID_INTERVAL_MS);
120
+ timer.unref?.();
121
+ return () => clearInterval(timer);
122
+ }
123
+ function processAlive(pid) {
124
+ try {
125
+ process.kill(pid, 0);
126
+ return true;
127
+ }
128
+ catch (cause) {
129
+ return cause instanceof Error && "code" in cause && cause.code === "EPERM";
130
+ }
131
+ }
132
+ async function cleanupScratchDir(scratchDir) {
133
+ if (scratchDir === undefined)
134
+ return;
135
+ try {
136
+ await rm(scratchDir, { recursive: true, force: true });
137
+ }
138
+ catch {
139
+ /* best effort: the host is exiting either way. */
140
+ }
141
+ }
142
+ //# sourceMappingURL=host-watchdog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-watchdog.js","sourceRoot":"","sources":["../../../src/modes/rpc/host-watchdog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,sFAAsF;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AAC3D,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AACjE,yEAAyE;AACzE,MAAM,CAAC,MAAM,mBAAmB,GAAG,2BAA2B,CAAC;AAC/D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAQjD,SAAS,oBAAoB,CAAC,KAAyB;IACtD,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,SAAS,CAAC;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACrC,MAAoD,OAAO,CAAC,GAAG;IAE/D,MAAM,EAAE,GAAG,oBAAoB,CAAC,GAAG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C,aAAa,CAAC;YAAE,OAAO;QAC1E,IAAI,CAAC,kBAAkB,aAAa,kBAAkB,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;IACxE,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAChC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IAChB,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,IAAI,CAAC;QACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;IAC5E,CAAC;AACF,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,UAA8B;IAC9D,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO;IACrC,IAAI,CAAC;QACJ,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACR,kDAAkD;IACnD,CAAC;AACF,CAAC","sourcesContent":["/**\n * Opt-in supervisor-lifetime watchdog for the RPC socket host.\n *\n * A host started under the `host-lifecycle.ts` supervisor must not outlive it.\n * Catchable signals cannot carry that guarantee: `kill -9`, an OOM kill, or a\n * crashed supervisor run no JS handler, and the host is then reparented to init\n * as a permanent orphan holding its private socket forever.\n *\n * The binding used here is the OS itself. The supervisor spawns the host with an\n * extra inherited pipe and keeps the write end open without ever writing to it.\n * The kernel closes that end when the supervisor dies for ANY reason, so the\n * host's read end reaches EOF and the host shuts down cleanly.\n *\n * Both variables are unset for every other host launch, so nothing changes for\n * plain `senpi --mode rpc` runs, hosts started by hand, or embedders.\n */\nimport { createReadStream } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\nimport { envValue } from \"../../core/brand.ts\";\n\n/** Inherited fd whose EOF means \"the supervisor died\"; set by the supervisor only. */\nexport const HOST_WATCH_FD_ENV = \"SENPI_RPC_HOST_WATCH_FD\";\n/** Supervisor-owned private directory the host removes on watchdog shutdown. */\nexport const HOST_SCRATCH_DIR_ENV = \"SENPI_RPC_HOST_SCRATCH_DIR\";\n/** Fallback binding when no inherited fd is available: poll this pid. */\nexport const HOST_WATCH_PPID_ENV = \"SENPI_RPC_HOST_WATCH_PPID\";\n/** Poll cadence for the ppid fallback. */\nexport const HOST_WATCH_PPID_INTERVAL_MS = 2_000;\n\nexport interface HostWatchdogConfig {\n\treadonly fd?: number;\n\treadonly ppid?: number;\n\treadonly scratchDir?: string;\n}\n\nfunction parsePositiveInteger(value: string | undefined): number | undefined {\n\tif (value === undefined || !/^\\d+$/.test(value.trim())) return undefined;\n\tconst parsed = Number(value.trim());\n\treturn Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;\n}\n\n/**\n * Reads the watchdog configuration from the environment. Returns `undefined`\n * when neither binding is requested, which is the case for every host launch\n * that does not come from the lifecycle supervisor.\n */\nexport function readHostWatchdogConfig(\n\tenv: Readonly<Record<string, string | undefined>> = process.env,\n): HostWatchdogConfig | undefined {\n\tconst fd = parsePositiveInteger(env[HOST_WATCH_FD_ENV]);\n\tconst ppid = parsePositiveInteger(env[HOST_WATCH_PPID_ENV]);\n\tif (fd === undefined && ppid === undefined) return undefined;\n\tconst scratchDir = env[HOST_SCRATCH_DIR_ENV];\n\treturn { fd, ppid, scratchDir: scratchDir === undefined || scratchDir === \"\" ? undefined : scratchDir };\n}\n\n/** Same configuration, resolved through the brand-aware env prefixes. */\nexport function readHostWatchdogConfigFromBrandEnv(): HostWatchdogConfig | undefined {\n\treturn readHostWatchdogConfig({\n\t\t[HOST_WATCH_FD_ENV]: envValue(\"RPC_HOST_WATCH_FD\"),\n\t\t[HOST_WATCH_PPID_ENV]: envValue(\"RPC_HOST_WATCH_PPID\"),\n\t\t[HOST_SCRATCH_DIR_ENV]: envValue(\"RPC_HOST_SCRATCH_DIR\"),\n\t});\n}\n\n/**\n * Arms the configured watchdog. `onSupervisorGone` receives the reason and is\n * expected to perform the host's normal clean shutdown; the scratch directory\n * (the supervisor's private socket directory, which no longer has an owner) is\n * removed first so nothing is left behind even if shutdown then hangs.\n *\n * Takes ownership of `config.fd`: disarming (or firing) closes it, so callers\n * must not close it themselves. Returns a disarm function; a no-op when no\n * binding is configured.\n */\nexport function armHostWatchdog(\n\tconfig: HostWatchdogConfig | undefined,\n\tonSupervisorGone: (reason: string) => void,\n): () => void {\n\tif (!config) return () => {};\n\tconst fire = (reason: string): void => {\n\t\tdisarm();\n\t\tvoid cleanupScratchDir(config.scratchDir).finally(() => onSupervisorGone(reason));\n\t};\n\tconst disarmers: Array<() => void> = [];\n\tconst disarm = (): void => {\n\t\tfor (const stop of disarmers.splice(0)) stop();\n\t};\n\tif (config.fd !== undefined) disarmers.push(watchFdForEof(config.fd, fire));\n\tif (config.ppid !== undefined) disarmers.push(watchPpid(config.ppid, fire));\n\treturn disarm;\n}\n\n/**\n * EOF on the inherited pipe is the primary signal. The supervisor never writes\n * to it, so any readable data is ignored; only close matters. An fd that cannot\n * be opened (never inherited) leaves the binding inert rather than killing a\n * healthy host.\n */\nfunction watchFdForEof(fd: number, fire: (reason: string) => void): () => void {\n\tlet stream: ReturnType<typeof createReadStream>;\n\ttry {\n\t\tstream = createReadStream(\"\", { fd, autoClose: false });\n\t} catch {\n\t\treturn () => {};\n\t}\n\tstream.resume();\n\tconst onEnd = (): void => fire(`supervisor pipe fd ${fd} closed`);\n\tstream.once(\"end\", onEnd);\n\t// A read error means the pipe is unusable, which is indistinguishable from a\n\t// dead supervisor from this side; treating it as EOF keeps the binding safe.\n\tstream.once(\"error\", onEnd);\n\treturn () => {\n\t\tstream.off(\"end\", onEnd);\n\t\tstream.off(\"error\", onEnd);\n\t\tstream.destroy();\n\t};\n}\n\n/**\n * Fallback binding: the supervisor pid is gone, or this process was reparented\n * to init because the supervisor died. Polling covers the case where no extra\n * fd could be inherited.\n */\nfunction watchPpid(supervisorPid: number, fire: (reason: string) => void): () => void {\n\tconst timer = setInterval(() => {\n\t\tif (process.ppid === supervisorPid && processAlive(supervisorPid)) return;\n\t\tfire(`supervisor pid ${supervisorPid} is gone (ppid=${process.ppid})`);\n\t}, HOST_WATCH_PPID_INTERVAL_MS);\n\ttimer.unref?.();\n\treturn () => clearInterval(timer);\n}\n\nfunction processAlive(pid: number): boolean {\n\ttry {\n\t\tprocess.kill(pid, 0);\n\t\treturn true;\n\t} catch (cause) {\n\t\treturn cause instanceof Error && \"code\" in cause && cause.code === \"EPERM\";\n\t}\n}\n\nasync function cleanupScratchDir(scratchDir: string | undefined): Promise<void> {\n\tif (scratchDir === undefined) return;\n\ttry {\n\t\tawait rm(scratchDir, { recursive: true, force: true });\n\t} catch {\n\t\t/* best effort: the host is exiting either way. */\n\t}\n}\n"]}
@@ -9,7 +9,13 @@ export interface MultiSessionHostOptions {
9
9
  modelId: string;
10
10
  };
11
11
  initialThinkingLevel?: string;
12
+ listen?: string;
12
13
  }
13
- /** Plain-stdio host with no eagerly-created AgentSessionRuntime. */
14
+ /**
15
+ * Socket event visibility is an all-sessions broadcast: every connected client
16
+ * receives every session lifecycle/agent event, tagged with its routing
17
+ * sessionId. Responses and extension UI requests remain requester-only. This
18
+ * keeps observers stateless while preventing correlated replies from leaking.
19
+ */
14
20
  export declare function runMultiSessionHost(options: MultiSessionHostOptions): Promise<never>;
15
21
  //# sourceMappingURL=multi-session-host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multi-session-host.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/multi-session-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,qCAAqC,CAAC;AAkB5F,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,gCAAgC,CAAC;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,oEAAoE;AACpE,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,KAAK,CAAC,CA4E1F"}
1
+ {"version":3,"file":"multi-session-host.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/multi-session-host.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,qCAAqC,CAAC;AAmB5F,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,gCAAgC,CAAC;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AASD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,KAAK,CAAC,CAG1F"}
@@ -1,52 +1,57 @@
1
+ import { access, chmod, mkdir, unlink } from "node:fs/promises";
2
+ import { createConnection, createServer } from "node:net";
3
+ import { dirname, join } from "node:path";
1
4
  import { envValue } from "../../core/brand.js";
2
5
  import { flushRawStdout, takeOverStdout, waitForRawStdoutBackpressure, writeRawStdout, } from "../../core/output-guard.js";
3
6
  import { killTrackedDetachedChildren } from "../../utils/shell.js";
4
7
  import { parseClientCapabilities } from "./custom-capability.js";
8
+ import { armHostWatchdog, readHostWatchdogConfigFromBrandEnv } from "./host-watchdog.js";
5
9
  import { attachJsonlLineReader, MAX_RPC_LINE_CHARACTERS } from "./jsonl.js";
6
10
  import { rpcCommandShapeError } from "./rpc-input-validation.js";
7
11
  import { SessionCommandRouter } from "./session-command-router.js";
8
12
  import { SessionEventWriter } from "./session-event-writer.js";
9
13
  import { RpcSessionRegistry } from "./session-registry.js";
10
- /** Plain-stdio host with no eagerly-created AgentSessionRuntime. */
14
+ /**
15
+ * Socket event visibility is an all-sessions broadcast: every connected client
16
+ * receives every session lifecycle/agent event, tagged with its routing
17
+ * sessionId. Responses and extension UI requests remain requester-only. This
18
+ * keeps observers stateless while preventing correlated replies from leaking.
19
+ */
11
20
  export async function runMultiSessionHost(options) {
12
- takeOverStdout();
13
- const sink = { writeRaw: writeRawStdout, waitForBackpressure: waitForRawStdoutBackpressure };
14
- const writer = new SessionEventWriter(sink.writeRaw, sink.waitForBackpressure);
21
+ if (options.listen === undefined || options.listen === "stdio://")
22
+ return runStdioHost(options);
23
+ return runSocketHost(options, resolveSocketPath(options.listen, options.agentDir));
24
+ }
25
+ function createHostCore(options, writer) {
15
26
  const capabilities = parseClientCapabilities(envValue("RPC_CLIENT_CAPABILITIES"));
16
27
  const router = new SessionCommandRouter(new RpcSessionRegistry({ agentDir: options.agentDir, createRuntime: options.createRuntime }), writer, options, undefined, { capabilities });
17
- let shuttingDown = false;
18
- const output = async (response) => {
19
- await writer.enqueueControl(response);
20
- };
21
28
  const handle = async (line) => {
22
29
  let parsed;
23
30
  try {
24
31
  parsed = JSON.parse(line);
25
32
  }
26
33
  catch (cause) {
27
- await output({
28
- type: "response",
29
- command: "parse",
30
- success: false,
31
- error: `Failed to parse command: ${cause instanceof Error ? cause.message : String(cause)}`,
32
- });
34
+ await writer.enqueueControl(parseError(`Failed to parse command: ${errorMessage(cause)}`));
33
35
  return;
34
36
  }
35
37
  const shapeError = rpcCommandShapeError(parsed);
36
38
  if (shapeError) {
37
- await output({
38
- type: "response",
39
- command: "parse",
40
- success: false,
41
- error: shapeError,
42
- });
39
+ await writer.enqueueControl(parseError(shapeError));
43
40
  return;
44
41
  }
45
- const command = parsed;
46
- const response = await router.handle(command);
42
+ const response = await router.handle(parsed);
47
43
  if (response)
48
- await output(response);
44
+ await writer.enqueueControl(response);
49
45
  };
46
+ return { router, handle };
47
+ }
48
+ /** Plain-stdio host with no eagerly-created AgentSessionRuntime. */
49
+ async function runStdioHost(options) {
50
+ takeOverStdout();
51
+ const sink = { writeRaw: writeRawStdout, waitForBackpressure: waitForRawStdoutBackpressure };
52
+ const writer = new SessionEventWriter(sink.writeRaw, sink.waitForBackpressure);
53
+ const { router, handle } = createHostCore(options, writer);
54
+ let shuttingDown = false;
50
55
  const shutdown = async (exitCode = 0) => {
51
56
  if (shuttingDown)
52
57
  process.exit(exitCode);
@@ -61,25 +66,194 @@ export async function runMultiSessionHost(options) {
61
66
  process.stdin.on("end", onEnd);
62
67
  const detachReader = attachJsonlLineReader(process.stdin, (line) => void handle(line), {
63
68
  maxLineLength: MAX_RPC_LINE_CHARACTERS,
64
- onOversizedLine: () => {
65
- void output({
66
- type: "response",
67
- command: "parse",
68
- success: false,
69
- error: `RPC input line exceeds ${MAX_RPC_LINE_CHARACTERS} characters.`,
70
- });
71
- },
69
+ onOversizedLine: () => void writer.enqueueControl(parseError(oversizedLineError())),
72
70
  });
73
71
  const detach = () => {
74
72
  detachReader();
75
73
  process.stdin.off("end", onEnd);
76
74
  };
75
+ registerShutdownSignals(shutdown);
76
+ return new Promise(() => { });
77
+ }
78
+ async function runSocketHost(options, socketPath) {
79
+ await prepareSocketPath(socketPath);
80
+ const writer = new SessionEventWriter(() => { });
81
+ const { router, handle } = createHostCore(options, writer);
82
+ const connections = new Map();
83
+ let nextConnection = 0;
84
+ let shuttingDown = false;
85
+ const server = createServer((socket) => {
86
+ const id = `socket-${++nextConnection}`;
87
+ const sink = socketSink(socket);
88
+ writer.registerConnection(id, sink);
89
+ let commandChain = Promise.resolve();
90
+ const detachReader = attachJsonlLineReader(socket, (line) => {
91
+ commandChain = commandChain
92
+ .then(() => writer.withConnection(id, () => handle(line)))
93
+ .catch((cause) => {
94
+ process.stderr.write(`senpi rpc connection ${id} failed: ${errorMessage(cause)}\n`);
95
+ });
96
+ }, {
97
+ maxLineLength: MAX_RPC_LINE_CHARACTERS,
98
+ onOversizedLine: () => {
99
+ commandChain = commandChain.then(() => writer.withConnection(id, () => writer.enqueueControl(parseError(oversizedLineError()))));
100
+ },
101
+ });
102
+ let detached = false;
103
+ const detach = () => {
104
+ if (detached)
105
+ return;
106
+ detached = true;
107
+ detachReader();
108
+ writer.unregisterConnection(id);
109
+ connections.delete(id);
110
+ };
111
+ connections.set(id, { id, sink, detach, close: () => socket.destroy() });
112
+ socket.once("close", detach);
113
+ socket.once("error", () => detach());
114
+ });
115
+ server.on("error", (cause) => {
116
+ if (!shuttingDown)
117
+ process.stderr.write(`senpi rpc socket listener failed: ${errorMessage(cause)}\n`);
118
+ });
119
+ await listen(server, socketPath);
120
+ process.stderr.write(`senpi rpc listening on ${formatSocketAddress(socketPath)}\n`);
121
+ const shutdown = async (exitCode = 0) => {
122
+ if (shuttingDown)
123
+ process.exit(exitCode);
124
+ shuttingDown = true;
125
+ for (const connection of connections.values()) {
126
+ connection.detach();
127
+ connection.close();
128
+ }
129
+ await closeServer(server);
130
+ await router.dispose();
131
+ await writer.flush();
132
+ await removeSocketPath(socketPath);
133
+ process.exit(exitCode);
134
+ };
135
+ registerShutdownSignals(shutdown);
136
+ // Opt-in only: set by the lifecycle supervisor so this host can never outlive
137
+ // it, including when the supervisor is SIGKILLed and runs no handler at all.
138
+ armHostWatchdog(readHostWatchdogConfigFromBrandEnv(), (reason) => {
139
+ process.stderr.write(`senpi rpc host: ${reason}; shutting down\n`);
140
+ killTrackedDetachedChildren();
141
+ void shutdown(0);
142
+ });
143
+ return new Promise(() => { });
144
+ }
145
+ function parseError(error) {
146
+ return { type: "response", command: "parse", success: false, error };
147
+ }
148
+ function oversizedLineError() {
149
+ return `RPC input line exceeds ${MAX_RPC_LINE_CHARACTERS} characters.`;
150
+ }
151
+ function errorMessage(cause) {
152
+ return cause instanceof Error ? cause.message : String(cause);
153
+ }
154
+ function resolveSocketPath(value, agentDir) {
155
+ if (value === "unix://")
156
+ return join(agentDir, "rpc", "rpc.sock");
157
+ if (value.startsWith("unix://")) {
158
+ const path = value.slice("unix://".length);
159
+ if (path.length === 0)
160
+ return join(agentDir, "rpc", "rpc.sock");
161
+ if (path.startsWith("@") && process.platform === "linux")
162
+ return `\0${path.slice(1)}`;
163
+ return path;
164
+ }
165
+ return value;
166
+ }
167
+ function formatSocketAddress(socketPath) {
168
+ return socketPath.startsWith("\0") ? `unix://@${socketPath.slice(1)}` : `unix://${socketPath}`;
169
+ }
170
+ function socketSink(socket) {
171
+ let needsDrain = false;
172
+ return {
173
+ writeRaw(chunk) {
174
+ if (!socket.destroyed)
175
+ needsDrain = !socket.write(chunk);
176
+ },
177
+ waitForBackpressure() {
178
+ if (socket.destroyed || !needsDrain)
179
+ return Promise.resolve();
180
+ needsDrain = false;
181
+ return new Promise((resolve) => {
182
+ const done = () => {
183
+ socket.off("drain", done);
184
+ socket.off("close", done);
185
+ resolve();
186
+ };
187
+ socket.once("drain", done);
188
+ socket.once("close", done);
189
+ });
190
+ },
191
+ };
192
+ }
193
+ async function prepareSocketPath(socketPath) {
194
+ if (socketPath.startsWith("\0"))
195
+ return;
196
+ await mkdir(dirname(socketPath), { recursive: true, mode: 0o700 });
197
+ try {
198
+ await access(socketPath);
199
+ }
200
+ catch (cause) {
201
+ if (isNodeErrorCode(cause, "ENOENT"))
202
+ return;
203
+ throw cause;
204
+ }
205
+ if (await probeSocket(socketPath))
206
+ throw new Error(`${socketPath}: address already in use by a live server.`);
207
+ await unlink(socketPath);
208
+ }
209
+ function probeSocket(socketPath) {
210
+ return new Promise((resolve) => {
211
+ const socket = createConnection(socketPath);
212
+ const settle = (live) => {
213
+ socket.destroy();
214
+ resolve(live);
215
+ };
216
+ socket.once("connect", () => settle(true));
217
+ socket.once("error", () => settle(false));
218
+ socket.setTimeout(1_000, () => settle(false));
219
+ });
220
+ }
221
+ function listen(server, socketPath) {
222
+ return new Promise((resolve, reject) => {
223
+ server.once("error", reject);
224
+ server.listen(socketPath, async () => {
225
+ server.off("error", reject);
226
+ if (!socketPath.startsWith("\0"))
227
+ await chmod(socketPath, 0o600);
228
+ resolve();
229
+ });
230
+ });
231
+ }
232
+ function closeServer(server) {
233
+ return new Promise((resolve, reject) => {
234
+ server.close((cause) => (cause ? reject(cause) : resolve()));
235
+ });
236
+ }
237
+ async function removeSocketPath(socketPath) {
238
+ if (socketPath.startsWith("\0"))
239
+ return;
240
+ try {
241
+ await unlink(socketPath);
242
+ }
243
+ catch (cause) {
244
+ if (!isNodeErrorCode(cause, "ENOENT"))
245
+ throw cause;
246
+ }
247
+ }
248
+ function isNodeErrorCode(cause, code) {
249
+ return cause instanceof Error && "code" in cause && cause.code === code;
250
+ }
251
+ function registerShutdownSignals(shutdown) {
77
252
  for (const signal of process.platform === "win32" ? ["SIGTERM"] : ["SIGTERM", "SIGHUP"]) {
78
253
  process.on(signal, () => {
79
254
  killTrackedDetachedChildren();
80
255
  void shutdown(signal === "SIGHUP" ? 129 : 143);
81
256
  });
82
257
  }
83
- return new Promise(() => { });
84
258
  }
85
259
  //# sourceMappingURL=multi-session-host.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"multi-session-host.js","sourceRoot":"","sources":["../../../src/modes/rpc/multi-session-host.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EACN,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,cAAc,GACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,uB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,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;QACtF,aAAa,EAAE,uBAAuB;QACtC,eAAe,EAAE,GAAG,EAAE;YACrB,KAAK,MAAM,CAAC;gBACX,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,0BAA0B,uBAAuB,cAAc;aACtE,CAAC,CAAC;QACJ,CAAC;KACD,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,GAAG,EAAE;QACnB,YAAY,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;IACF,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAE,CAAC,SAAS,CAAW,CAAC,CAAC,CAAE,CAAC,SAAS,EAAE,QAAQ,CAAW,EAAE,CAAC;QAC/G,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACvB,2BAA2B,EAAE,CAAC;YAC9B,KAAK,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { CreateAgentSessionRuntimeFactory } from \"../../core/agent-session-runtime.ts\";\nimport { envValue } from \"../../core/brand.ts\";\nimport {\n\tflushRawStdout,\n\ttakeOverStdout,\n\twaitForRawStdoutBackpressure,\n\twriteRawStdout,\n} from \"../../core/output-guard.ts\";\nimport { killTrackedDetachedChildren } from \"../../utils/shell.ts\";\nimport type { RpcConnectionSink } from \"./connection-handler.ts\";\nimport { parseClientCapabilities } from \"./custom-capability.ts\";\nimport { attachJsonlLineReader, MAX_RPC_LINE_CHARACTERS } from \"./jsonl.ts\";\nimport { rpcCommandShapeError } from \"./rpc-input-validation.ts\";\nimport type { RpcCommand, RpcResponse } from \"./rpc-types.ts\";\nimport { SessionCommandRouter } from \"./session-command-router.ts\";\nimport { SessionEventWriter } from \"./session-event-writer.ts\";\nimport { RpcSessionRegistry } from \"./session-registry.ts\";\n\nexport interface MultiSessionHostOptions {\n\tagentDir: string;\n\tcreateRuntime: CreateAgentSessionRuntimeFactory;\n\tcwd: string;\n\tpermissionPreset?: string;\n\tcreationModel?: { provider: string; modelId: string };\n\tinitialThinkingLevel?: string;\n}\n\n/** Plain-stdio host with no eagerly-created AgentSessionRuntime. */\nexport async function runMultiSessionHost(options: MultiSessionHostOptions): Promise<never> {\n\ttakeOverStdout();\n\tconst sink: RpcConnectionSink = { writeRaw: writeRawStdout, waitForBackpressure: waitForRawStdoutBackpressure };\n\tconst writer = new SessionEventWriter(sink.writeRaw, sink.waitForBackpressure);\n\tconst capabilities = parseClientCapabilities(envValue(\"RPC_CLIENT_CAPABILITIES\"));\n\tconst router = new SessionCommandRouter(\n\t\tnew RpcSessionRegistry({ agentDir: options.agentDir, createRuntime: options.createRuntime }),\n\t\twriter,\n\t\toptions,\n\t\tundefined,\n\t\t{ capabilities },\n\t);\n\tlet shuttingDown = false;\n\tconst output = async (response: RpcResponse) => {\n\t\tawait writer.enqueueControl(response);\n\t};\n\tconst handle = async (line: string) => {\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(line);\n\t\t} catch (cause) {\n\t\t\tawait output({\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"parse\",\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `Failed to parse command: ${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst shapeError = rpcCommandShapeError(parsed);\n\t\tif (shapeError) {\n\t\t\tawait output({\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"parse\",\n\t\t\t\tsuccess: false,\n\t\t\t\terror: shapeError,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst command = parsed as RpcCommand;\n\t\tconst response = await router.handle(command);\n\t\tif (response) await output(response);\n\t};\n\tconst shutdown = async (exitCode = 0): Promise<never> => {\n\t\tif (shuttingDown) process.exit(exitCode);\n\t\tshuttingDown = true;\n\t\tdetach();\n\t\tawait router.dispose();\n\t\tawait writer.flush();\n\t\tawait flushRawStdout();\n\t\tprocess.exit(exitCode);\n\t};\n\tconst onEnd = () => void shutdown();\n\tprocess.stdin.on(\"end\", onEnd);\n\tconst detachReader = attachJsonlLineReader(process.stdin, (line) => void handle(line), {\n\t\tmaxLineLength: MAX_RPC_LINE_CHARACTERS,\n\t\tonOversizedLine: () => {\n\t\t\tvoid output({\n\t\t\t\ttype: \"response\",\n\t\t\t\tcommand: \"parse\",\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `RPC input line exceeds ${MAX_RPC_LINE_CHARACTERS} characters.`,\n\t\t\t});\n\t\t},\n\t});\n\tconst detach = () => {\n\t\tdetachReader();\n\t\tprocess.stdin.off(\"end\", onEnd);\n\t};\n\tfor (const signal of process.platform === \"win32\" ? ([\"SIGTERM\"] as const) : ([\"SIGTERM\", \"SIGHUP\"] as const)) {\n\t\tprocess.on(signal, () => {\n\t\t\tkillTrackedDetachedChildren();\n\t\t\tvoid shutdown(signal === \"SIGHUP\" ? 129 : 143);\n\t\t});\n\t}\n\treturn new Promise(() => {});\n}\n"]}
1
+ {"version":3,"file":"multi-session-host.js","sourceRoot":"","sources":["../../../src/modes/rpc/multi-session-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,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AK,IAAI,CAAC;AACzE,CAAC;AAED,SAAS,uBAAuB,CAAC,QAA+C;IAC/E,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAE,CAAC,SAAS,CAAW,CAAC,CAAC,CAAE,CAAC,SAAS,EAAE,QAAQ,CAAW,EAAE,CAAC;QAC/G,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACvB,2BAA2B,EAAE,CAAC;YAC9B,KAAK,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["import { access, chmod, mkdir, unlink } from \"node:fs/promises\";\nimport { createConnection, createServer, type Server, type Socket } from \"node:net\";\nimport { dirname, join } from \"node:path\";\nimport type { CreateAgentSessionRuntimeFactory } from \"../../core/agent-session-runtime.ts\";\nimport { envValue } from \"../../core/brand.ts\";\nimport {\n\tflushRawStdout,\n\ttakeOverStdout,\n\twaitForRawStdoutBackpressure,\n\twriteRawStdout,\n} from \"../../core/output-guard.ts\";\nimport { killTrackedDetachedChildren } from \"../../utils/shell.ts\";\nimport type { RpcConnectionSink } from \"./connection-handler.ts\";\nimport { parseClientCapabilities } from \"./custom-capability.ts\";\nimport { armHostWatchdog, readHostWatchdogConfigFromBrandEnv } from \"./host-watchdog.ts\";\nimport { attachJsonlLineReader, MAX_RPC_LINE_CHARACTERS } from \"./jsonl.ts\";\nimport { rpcCommandShapeError } from \"./rpc-input-validation.ts\";\nimport type { RpcCommand, RpcResponse } from \"./rpc-types.ts\";\nimport { SessionCommandRouter } from \"./session-command-router.ts\";\nimport { SessionEventWriter } from \"./session-event-writer.ts\";\nimport { RpcSessionRegistry } from \"./session-registry.ts\";\n\nexport interface MultiSessionHostOptions {\n\tagentDir: string;\n\tcreateRuntime: CreateAgentSessionRuntimeFactory;\n\tcwd: string;\n\tpermissionPreset?: string;\n\tcreationModel?: { provider: string; modelId: string };\n\tinitialThinkingLevel?: string;\n\tlisten?: string;\n}\n\ninterface Connection {\n\treadonly id: string;\n\treadonly sink: RpcConnectionSink;\n\treadonly detach: () => void;\n\treadonly close: () => void;\n}\n\n/**\n * Socket event visibility is an all-sessions broadcast: every connected client\n * receives every session lifecycle/agent event, tagged with its routing\n * sessionId. Responses and extension UI requests remain requester-only. This\n * keeps observers stateless while preventing correlated replies from leaking.\n */\nexport async function runMultiSessionHost(options: MultiSessionHostOptions): Promise<never> {\n\tif (options.listen === undefined || options.listen === \"stdio://\") return runStdioHost(options);\n\treturn runSocketHost(options, resolveSocketPath(options.listen, options.agentDir));\n}\n\nfunction createHostCore(options: MultiSessionHostOptions, writer: SessionEventWriter) {\n\tconst capabilities = parseClientCapabilities(envValue(\"RPC_CLIENT_CAPABILITIES\"));\n\tconst router = new SessionCommandRouter(\n\t\tnew RpcSessionRegistry({ agentDir: options.agentDir, createRuntime: options.createRuntime }),\n\t\twriter,\n\t\toptions,\n\t\tundefined,\n\t\t{ capabilities },\n\t);\n\tconst handle = async (line: string): Promise<void> => {\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(line);\n\t\t} catch (cause) {\n\t\t\tawait writer.enqueueControl(parseError(`Failed to parse command: ${errorMessage(cause)}`));\n\t\t\treturn;\n\t\t}\n\t\tconst shapeError = rpcCommandShapeError(parsed);\n\t\tif (shapeError) {\n\t\t\tawait writer.enqueueControl(parseError(shapeError));\n\t\t\treturn;\n\t\t}\n\t\tconst response = await router.handle(parsed as RpcCommand);\n\t\tif (response) await writer.enqueueControl(response);\n\t};\n\treturn { router, handle };\n}\n\n/** Plain-stdio host with no eagerly-created AgentSessionRuntime. */\nasync function runStdioHost(options: MultiSessionHostOptions): Promise<never> {\n\ttakeOverStdout();\n\tconst sink: RpcConnectionSink = { writeRaw: writeRawStdout, waitForBackpressure: waitForRawStdoutBackpressure };\n\tconst writer = new SessionEventWriter(sink.writeRaw, sink.waitForBackpressure);\n\tconst { router, handle } = createHostCore(options, writer);\n\tlet shuttingDown = false;\n\tconst shutdown = async (exitCode = 0): Promise<never> => {\n\t\tif (shuttingDown) process.exit(exitCode);\n\t\tshuttingDown = true;\n\t\tdetach();\n\t\tawait router.dispose();\n\t\tawait writer.flush();\n\t\tawait flushRawStdout();\n\t\tprocess.exit(exitCode);\n\t};\n\tconst onEnd = () => void shutdown();\n\tprocess.stdin.on(\"end\", onEnd);\n\tconst detachReader = attachJsonlLineReader(process.stdin, (line) => void handle(line), {\n\t\tmaxLineLength: MAX_RPC_LINE_CHARACTERS,\n\t\tonOversizedLine: () => void writer.enqueueControl(parseError(oversizedLineError())),\n\t});\n\tconst detach = () => {\n\t\tdetachReader();\n\t\tprocess.stdin.off(\"end\", onEnd);\n\t};\n\tregisterShutdownSignals(shutdown);\n\treturn new Promise(() => {});\n}\n\nasync function runSocketHost(options: MultiSessionHostOptions, socketPath: string): Promise<never> {\n\tawait prepareSocketPath(socketPath);\n\tconst writer = new SessionEventWriter(() => {});\n\tconst { router, handle } = createHostCore(options, writer);\n\tconst connections = new Map<string, Connection>();\n\tlet nextConnection = 0;\n\tlet shuttingDown = false;\n\tconst server = createServer((socket) => {\n\t\tconst id = `socket-${++nextConnection}`;\n\t\tconst sink = socketSink(socket);\n\t\twriter.registerConnection(id, sink);\n\t\tlet commandChain = Promise.resolve();\n\t\tconst detachReader = attachJsonlLineReader(\n\t\t\tsocket,\n\t\t\t(line) => {\n\t\t\t\tcommandChain = commandChain\n\t\t\t\t\t.then(() => writer.withConnection(id, () => handle(line)))\n\t\t\t\t\t.catch((cause) => {\n\t\t\t\t\t\tprocess.stderr.write(`senpi rpc connection ${id} failed: ${errorMessage(cause)}\\n`);\n\t\t\t\t\t});\n\t\t\t},\n\t\t\t{\n\t\t\t\tmaxLineLength: MAX_RPC_LINE_CHARACTERS,\n\t\t\t\tonOversizedLine: () => {\n\t\t\t\t\tcommandChain = commandChain.then(() =>\n\t\t\t\t\t\twriter.withConnection(id, () => writer.enqueueControl(parseError(oversizedLineError()))),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tlet detached = false;\n\t\tconst detach = () => {\n\t\t\tif (detached) return;\n\t\t\tdetached = true;\n\t\t\tdetachReader();\n\t\t\twriter.unregisterConnection(id);\n\t\t\tconnections.delete(id);\n\t\t};\n\t\tconnections.set(id, { id, sink, detach, close: () => socket.destroy() });\n\t\tsocket.once(\"close\", detach);\n\t\tsocket.once(\"error\", () => detach());\n\t});\n\tserver.on(\"error\", (cause) => {\n\t\tif (!shuttingDown) process.stderr.write(`senpi rpc socket listener failed: ${errorMessage(cause)}\\n`);\n\t});\n\tawait listen(server, socketPath);\n\tprocess.stderr.write(`senpi rpc listening on ${formatSocketAddress(socketPath)}\\n`);\n\n\tconst shutdown = async (exitCode = 0): Promise<never> => {\n\t\tif (shuttingDown) process.exit(exitCode);\n\t\tshuttingDown = true;\n\t\tfor (const connection of connections.values()) {\n\t\t\tconnection.detach();\n\t\t\tconnection.close();\n\t\t}\n\t\tawait closeServer(server);\n\t\tawait router.dispose();\n\t\tawait writer.flush();\n\t\tawait removeSocketPath(socketPath);\n\t\tprocess.exit(exitCode);\n\t};\n\tregisterShutdownSignals(shutdown);\n\t// Opt-in only: set by the lifecycle supervisor so this host can never outlive\n\t// it, including when the supervisor is SIGKILLed and runs no handler at all.\n\tarmHostWatchdog(readHostWatchdogConfigFromBrandEnv(), (reason) => {\n\t\tprocess.stderr.write(`senpi rpc host: ${reason}; shutting down\\n`);\n\t\tkillTrackedDetachedChildren();\n\t\tvoid shutdown(0);\n\t});\n\treturn new Promise(() => {});\n}\n\nfunction parseError(error: string): RpcResponse {\n\treturn { type: \"response\", command: \"parse\", success: false, error };\n}\n\nfunction oversizedLineError(): string {\n\treturn `RPC input line exceeds ${MAX_RPC_LINE_CHARACTERS} characters.`;\n}\n\nfunction errorMessage(cause: unknown): string {\n\treturn cause instanceof Error ? cause.message : String(cause);\n}\n\nfunction resolveSocketPath(value: string, agentDir: string): string {\n\tif (value === \"unix://\") return join(agentDir, \"rpc\", \"rpc.sock\");\n\tif (value.startsWith(\"unix://\")) {\n\t\tconst path = value.slice(\"unix://\".length);\n\t\tif (path.length === 0) return join(agentDir, \"rpc\", \"rpc.sock\");\n\t\tif (path.startsWith(\"@\") && process.platform === \"linux\") return `\\0${path.slice(1)}`;\n\t\treturn path;\n\t}\n\treturn value;\n}\n\nfunction formatSocketAddress(socketPath: string): string {\n\treturn socketPath.startsWith(\"\\0\") ? `unix://@${socketPath.slice(1)}` : `unix://${socketPath}`;\n}\n\nfunction socketSink(socket: Socket): RpcConnectionSink {\n\tlet needsDrain = false;\n\treturn {\n\t\twriteRaw(chunk) {\n\t\t\tif (!socket.destroyed) needsDrain = !socket.write(chunk);\n\t\t},\n\t\twaitForBackpressure() {\n\t\t\tif (socket.destroyed || !needsDrain) return Promise.resolve();\n\t\t\tneedsDrain = false;\n\t\t\treturn new Promise<void>((resolve) => {\n\t\t\t\tconst done = () => {\n\t\t\t\t\tsocket.off(\"drain\", done);\n\t\t\t\t\tsocket.off(\"close\", done);\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t\tsocket.once(\"drain\", done);\n\t\t\t\tsocket.once(\"close\", done);\n\t\t\t});\n\t\t},\n\t};\n}\n\nasync function prepareSocketPath(socketPath: string): Promise<void> {\n\tif (socketPath.startsWith(\"\\0\")) return;\n\tawait mkdir(dirname(socketPath), { recursive: true, mode: 0o700 });\n\ttry {\n\t\tawait access(socketPath);\n\t} catch (cause) {\n\t\tif (isNodeErrorCode(cause, \"ENOENT\")) return;\n\t\tthrow cause;\n\t}\n\tif (await probeSocket(socketPath)) throw new Error(`${socketPath}: address already in use by a live server.`);\n\tawait unlink(socketPath);\n}\n\nfunction probeSocket(socketPath: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst socket = createConnection(socketPath);\n\t\tconst settle = (live: boolean) => {\n\t\t\tsocket.destroy();\n\t\t\tresolve(live);\n\t\t};\n\t\tsocket.once(\"connect\", () => settle(true));\n\t\tsocket.once(\"error\", () => settle(false));\n\t\tsocket.setTimeout(1_000, () => settle(false));\n\t});\n}\n\nfunction listen(server: Server, socketPath: string): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tserver.once(\"error\", reject);\n\t\tserver.listen(socketPath, async () => {\n\t\t\tserver.off(\"error\", reject);\n\t\t\tif (!socketPath.startsWith(\"\\0\")) await chmod(socketPath, 0o600);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction closeServer(server: Server): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tserver.close((cause) => (cause ? reject(cause) : resolve()));\n\t});\n}\n\nasync function removeSocketPath(socketPath: string): Promise<void> {\n\tif (socketPath.startsWith(\"\\0\")) return;\n\ttry {\n\t\tawait unlink(socketPath);\n\t} catch (cause) {\n\t\tif (!isNodeErrorCode(cause, \"ENOENT\")) throw cause;\n\t}\n}\n\nfunction isNodeErrorCode(cause: unknown, code: string): boolean {\n\treturn cause instanceof Error && \"code\" in cause && cause.code === code;\n}\n\nfunction registerShutdownSignals(shutdown: (exitCode?: number) => Promise<never>): void {\n\tfor (const signal of process.platform === \"win32\" ? ([\"SIGTERM\"] as const) : ([\"SIGTERM\", \"SIGHUP\"] as const)) {\n\t\tprocess.on(signal, () => {\n\t\t\tkillTrackedDetachedChildren();\n\t\t\tvoid shutdown(signal === \"SIGHUP\" ? 129 : 143);\n\t\t});\n\t}\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { AgentMessage, ThinkingLevel } from "@earendil-works/pi-agent-core";
7
7
  import type { ImageContent } from "@earendil-works/pi-ai";
8
- import type { SessionStats } from "../../core/agent-session.ts";
8
+ import type { PromptDisposition, SessionStats } from "../../core/agent-session.ts";
9
9
  import type { BashResult } from "../../core/bash-executor.ts";
10
10
  import type { CompactionResult } from "../../core/compaction/index.ts";
11
11
  import type { ServiceTier } from "../../core/extensions/builtin/service-tier.ts";
@@ -13,6 +13,8 @@ import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.t
13
13
  import type { JsonAgentSessionEvent } from "../json-event.ts";
14
14
  import type { RpcAccountFailoverEvent, RpcAuthAccountsChangedEvent, RpcExtensionEvent, RpcProviderAccount, RpcSessionState, RpcSlashCommand } from "./rpc-types.ts";
15
15
  export interface RpcClientOptions {
16
+ /** Connect to an existing multi-session Unix socket instead of spawning a child. */
17
+ socketPath?: string;
16
18
  /** Path to the CLI entry point (default: searches for dist/cli.js) */
17
19
  cliPath?: string;
18
20
  /** Working directory for the agent */
@@ -38,10 +40,12 @@ export type RpcClientEvent = JsonAgentSessionEvent | RpcProviderAccountEvent | R
38
40
  export type RpcEventListener = (event: RpcClientEvent) => void;
39
41
  export declare class RpcClient {
40
42
  private process;
43
+ private socket;
41
44
  private stopReadingStdout;
42
45
  private eventListeners;
43
46
  private pendingRequests;
44
47
  private requestId;
48
+ private sessionId;
45
49
  private stderr;
46
50
  private exitError;
47
51
  private options;
@@ -54,6 +58,7 @@ export declare class RpcClient {
54
58
  * Stop the RPC agent process.
55
59
  */
56
60
  stop(): Promise<void>;
61
+ private startSocket;
57
62
  /**
58
63
  * Subscribe to agent events.
59
64
  */
@@ -62,12 +67,45 @@ export declare class RpcClient {
62
67
  * Get collected stderr output (useful for debugging).
63
68
  */
64
69
  getStderr(): string;
70
+ openSession(options: {
71
+ sessionPath?: string;
72
+ cwd?: string;
73
+ provider?: string;
74
+ modelId?: string;
75
+ thinkingLevel?: ThinkingLevel;
76
+ permissionPreset?: string;
77
+ }): Promise<{
78
+ sessionId: string;
79
+ state: RpcSessionState;
80
+ attached?: boolean;
81
+ }>;
82
+ closeSession(sessionId?: string | undefined): Promise<void>;
83
+ listSessions(): Promise<Array<{
84
+ sessionId: string;
85
+ durableSessionId?: string;
86
+ sessionPath?: string;
87
+ cwd: string;
88
+ name?: string;
89
+ status: "opening" | "open" | "closing" | "closed";
90
+ }>>;
65
91
  /**
66
92
  * Send a prompt to the agent.
67
93
  * Returns immediately after sending; use onEvent() to receive streaming events.
68
94
  * Use waitForIdle() to wait for completion.
69
- */
70
- prompt(message: string, images?: ImageContent[]): Promise<void>;
95
+ *
96
+ * The disposition/preflight callbacks mirror AgentSession's local prompt contract:
97
+ * they fire synchronously while the response frame is dispatched — before any
98
+ * queued message_start event — so optimistic-echo eligibility is settled in wire
99
+ * order. A success response without a disposition (older host) maps to "handled"
100
+ * so the echo degrades to canonical-only rendering instead of double-rendering.
101
+ */
102
+ prompt(message: string, options?: {
103
+ images?: ImageContent[];
104
+ streamingBehavior?: "steer" | "followUp";
105
+ thinkingLevel?: ThinkingLevel;
106
+ promptDisposition?: (disposition: PromptDisposition) => void;
107
+ preflightResult?: (success: boolean) => void;
108
+ }): Promise<void>;
71
109
  /**
72
110
  * Queue a steering message to interrupt the agent mid-run.
73
111
  */