@code-yeongyu/senpi 2026.9.21-2 → 2026.9.22-2

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 (379) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/bundle/chunks/{anthropic-messages-C3ZY2ANT.js → anthropic-messages-2P7APOOQ.js} +1 -1
  3. package/dist/bundle/chunks/{app-server-command-HSX5RFAP.js → app-server-command-PRNA6QQU.js} +1 -1
  4. package/dist/bundle/chunks/{azure-openai-responses-7TAGS2VU.js → azure-openai-responses-3AH7MJWF.js} +1 -1
  5. package/dist/bundle/chunks/{bun-extension-importer-UO7V2MZ7.js → bun-extension-importer-H4IJCWWQ.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-OSDJ2SYO.js → chunk-5XC2FNJ5.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-D5CL7PPD.js → chunk-64JQFFHH.js} +2 -2
  8. package/dist/bundle/chunks/{chunk-Z3KQB2R3.js → chunk-6OD4TT33.js} +95 -39
  9. package/dist/bundle/chunks/{chunk-NEEAKXDT.js → chunk-7EH64T6E.js} +2 -2
  10. package/dist/bundle/chunks/{chunk-MIVOQT3Q.js → chunk-ARJJU3MS.js} +1 -1
  11. package/dist/bundle/chunks/chunk-BOZ37BOT.js +14 -0
  12. package/dist/bundle/chunks/{chunk-POMPEGWQ.js → chunk-F3DXL5MX.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-GLKVDRNP.js → chunk-GXUYWMN2.js} +1 -1
  14. package/dist/bundle/chunks/chunk-HH3KJDWA.js +2 -0
  15. package/dist/bundle/chunks/{chunk-B7W62BM7.js → chunk-IPRJIKLL.js} +1 -1
  16. package/dist/bundle/chunks/chunk-JEFYJDHP.js +8 -0
  17. package/dist/bundle/chunks/{chunk-T6XA2IZR.js → chunk-JR4X6ECO.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-I425CMTO.js → chunk-JZ6YQU3A.js} +4 -4
  19. package/dist/bundle/chunks/{chunk-KNM6SRPE.js → chunk-K3HEWWSS.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-M2XAY6I7.js → chunk-M2HSO7MH.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-UYVPLEOL.js → chunk-NK2RNX25.js} +1 -1
  22. package/dist/bundle/chunks/chunk-NMB4C6ZZ.js +2 -0
  23. package/dist/bundle/chunks/{chunk-VEO3ABZR.js → chunk-OLJ7LQJY.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-GVI2HP7N.js → chunk-OPNVT7BU.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-XHMOFY4T.js → chunk-R6LVC7SP.js} +4 -4
  26. package/dist/bundle/chunks/{chunk-3SLCHXZO.js → chunk-UCPWK6TZ.js} +2 -2
  27. package/dist/bundle/chunks/{chunk-B2IM56LB.js → chunk-VYIJQQ5I.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-47GF6XYZ.js → chunk-YT2ZSZOY.js} +1 -1
  29. package/dist/bundle/chunks/{cli-main-GQTEEZ2V.js → cli-main-AFJNXUSL.js} +1 -1
  30. package/dist/bundle/chunks/github-copilot.js +1 -1
  31. package/dist/bundle/chunks/{google-generative-ai-JWIH75VF.js → google-generative-ai-Y2IYMUVC.js} +1 -1
  32. package/dist/bundle/chunks/{google-vertex-IRGAY5XR.js → google-vertex-TKBBMPHV.js} +1 -1
  33. package/dist/bundle/chunks/{host-command-KOEKIHIZ.js → host-command-OVA6GEWC.js} +1 -1
  34. package/dist/bundle/chunks/host-lifecycle-IDQPLYEA.js +3 -0
  35. package/dist/bundle/chunks/host-lifecycle.js +10 -6
  36. package/dist/bundle/chunks/{interactive-host-runtime-2KTFEW7O.js → interactive-host-runtime-F5L4USLR.js} +1 -1
  37. package/dist/bundle/chunks/{interactive-mode-I3ILWXQB.js → interactive-mode-UFBSCOP7.js} +1 -1
  38. package/dist/bundle/chunks/kimi-coding.js +2 -2
  39. package/dist/bundle/chunks/{list-tips-2KX65NWZ.js → list-tips-2QG7ASHS.js} +1 -1
  40. package/dist/bundle/chunks/{mistral-conversations-VOBYATVJ.js → mistral-conversations-ZYDVFRYF.js} +1 -1
  41. package/dist/bundle/chunks/multi-session-host-EUTEGVLS.js +21 -0
  42. package/dist/bundle/chunks/openai-codex-responses-MEIUNROM.js +10 -0
  43. package/dist/bundle/chunks/{openai-completions-YK6QTYOH.js → openai-completions-4V76L5ZJ.js} +1 -1
  44. package/dist/bundle/chunks/openai-responses-YR7WRBG3.js +2 -0
  45. package/dist/bundle/chunks/{package-manager-cli-HOL6CAI6.js → package-manager-cli-JPUWMUEJ.js} +1 -1
  46. package/dist/bundle/chunks/rotation-stream-S56Y7WMM.js +2 -0
  47. package/dist/bundle/chunks/{rpc-mode-L3DSGTVM.js → rpc-mode-JDVHUBZY.js} +1 -1
  48. package/dist/bundle/chunks/{session-picker-L3FYEQBL.js → session-picker-PFPJVVIC.js} +1 -1
  49. package/dist/bundle/chunks/session-worker.js +225 -164
  50. package/dist/bundle/cli.js +1 -1
  51. package/dist/bundle/index.js +1 -1
  52. package/dist/bundle/rpc-entry.js +1 -1
  53. package/dist/core/agent-session.d.ts +6 -4
  54. package/dist/core/agent-session.d.ts.map +1 -1
  55. package/dist/core/agent-session.js +9 -7
  56. package/dist/core/agent-session.js.map +1 -1
  57. package/dist/core/credential-pool/classify.d.ts.map +1 -1
  58. package/dist/core/credential-pool/classify.js +12 -0
  59. package/dist/core/credential-pool/classify.js.map +1 -1
  60. package/dist/core/credential-pool/failover.d.ts +37 -5
  61. package/dist/core/credential-pool/failover.d.ts.map +1 -1
  62. package/dist/core/credential-pool/failover.js +60 -24
  63. package/dist/core/credential-pool/failover.js.map +1 -1
  64. package/dist/core/credential-pool/rotation-events.d.ts +5 -0
  65. package/dist/core/credential-pool/rotation-events.d.ts.map +1 -0
  66. package/dist/core/credential-pool/rotation-events.js +25 -0
  67. package/dist/core/credential-pool/rotation-events.js.map +1 -0
  68. package/dist/core/credential-pool/rotation-stream.d.ts +4 -3
  69. package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -1
  70. package/dist/core/credential-pool/rotation-stream.js +8 -11
  71. package/dist/core/credential-pool/rotation-stream.js.map +1 -1
  72. package/dist/core/extensions/builtin/ask-user/schema.d.ts +2 -25
  73. package/dist/core/extensions/builtin/ask-user/schema.d.ts.map +1 -1
  74. package/dist/core/extensions/builtin/ask-user/schema.js.map +1 -1
  75. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.d.ts +7 -0
  76. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.d.ts.map +1 -0
  77. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.js +7 -0
  78. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.js.map +1 -0
  79. package/dist/core/extensions/builtin/claude-sdk-oauth/index.d.ts.map +1 -1
  80. package/dist/core/extensions/builtin/claude-sdk-oauth/index.js +3 -2
  81. package/dist/core/extensions/builtin/claude-sdk-oauth/index.js.map +1 -1
  82. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +22 -1
  83. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
  84. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +2 -0
  85. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -1
  86. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +4 -0
  87. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -1
  88. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
  89. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +18 -1
  90. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
  91. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.d.ts.map +1 -1
  92. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js +18 -0
  93. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
  94. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +2 -7
  95. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
  96. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +2 -8
  97. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
  98. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js +1 -1
  99. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js.map +1 -1
  100. package/dist/core/extensions/builtin/mcp/expose/naming.d.ts +0 -1
  101. package/dist/core/extensions/builtin/mcp/expose/naming.d.ts.map +1 -1
  102. package/dist/core/extensions/builtin/mcp/expose/naming.js +0 -3
  103. package/dist/core/extensions/builtin/mcp/expose/naming.js.map +1 -1
  104. package/dist/core/extensions/builtin/mcp/expose/register.d.ts +1 -2
  105. package/dist/core/extensions/builtin/mcp/expose/register.d.ts.map +1 -1
  106. package/dist/core/extensions/builtin/mcp/expose/register.js +0 -21
  107. package/dist/core/extensions/builtin/mcp/expose/register.js.map +1 -1
  108. package/dist/core/extensions/builtin/mcp/expose/schema-compat.d.ts +2 -2
  109. package/dist/core/extensions/builtin/mcp/expose/schema-compat.d.ts.map +1 -1
  110. package/dist/core/extensions/builtin/mcp/expose/schema-compat.js +2 -2
  111. package/dist/core/extensions/builtin/mcp/expose/schema-compat.js.map +1 -1
  112. package/dist/core/extensions/builtin/prompt-preset/file-operations.js +1 -1
  113. package/dist/core/extensions/builtin/prompt-preset/file-operations.js.map +1 -1
  114. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.d.ts +3 -0
  115. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.d.ts.map +1 -0
  116. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.js +105 -0
  117. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.js.map +1 -0
  118. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  119. package/dist/core/extensions/builtin/prompt-preset/presets.js +14 -0
  120. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  121. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  122. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  123. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  124. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  125. package/dist/core/extensions/bun-extension-importer.d.ts +1 -0
  126. package/dist/core/extensions/bun-extension-importer.d.ts.map +1 -1
  127. package/dist/core/extensions/bun-extension-importer.js +4 -0
  128. package/dist/core/extensions/bun-extension-importer.js.map +1 -1
  129. package/dist/core/extensions/extension-module-cache.d.ts +48 -0
  130. package/dist/core/extensions/extension-module-cache.d.ts.map +1 -0
  131. package/dist/core/extensions/extension-module-cache.js +111 -0
  132. package/dist/core/extensions/extension-module-cache.js.map +1 -0
  133. package/dist/core/extensions/loader.d.ts +1 -1
  134. package/dist/core/extensions/loader.d.ts.map +1 -1
  135. package/dist/core/extensions/loader.js +14 -56
  136. package/dist/core/extensions/loader.js.map +1 -1
  137. package/dist/core/http-dispatcher.d.ts +29 -0
  138. package/dist/core/http-dispatcher.d.ts.map +1 -1
  139. package/dist/core/http-dispatcher.js +30 -3
  140. package/dist/core/http-dispatcher.js.map +1 -1
  141. package/dist/core/model-resolver.js +1 -1
  142. package/dist/core/model-resolver.js.map +1 -1
  143. package/dist/core/retry-fallback/billing.d.ts.map +1 -1
  144. package/dist/core/retry-fallback/billing.js +20 -1
  145. package/dist/core/retry-fallback/billing.js.map +1 -1
  146. package/dist/core/session-manager.d.ts +3 -1
  147. package/dist/core/session-manager.d.ts.map +1 -1
  148. package/dist/core/session-manager.js +12 -6
  149. package/dist/core/session-manager.js.map +1 -1
  150. package/dist/modes/interactive/components/assistant-render-descriptors.d.ts.map +1 -1
  151. package/dist/modes/interactive/components/assistant-render-descriptors.js +8 -7
  152. package/dist/modes/interactive/components/assistant-render-descriptors.js.map +1 -1
  153. package/dist/modes/print-mode.d.ts.map +1 -1
  154. package/dist/modes/print-mode.js +7 -5
  155. package/dist/modes/print-mode.js.map +1 -1
  156. package/dist/modes/rpc/custom-capability.d.ts +7 -0
  157. package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
  158. package/dist/modes/rpc/custom-capability.js +7 -0
  159. package/dist/modes/rpc/custom-capability.js.map +1 -1
  160. package/dist/modes/rpc/handoff-activity.d.ts +4 -0
  161. package/dist/modes/rpc/handoff-activity.d.ts.map +1 -0
  162. package/dist/modes/rpc/handoff-activity.js +6 -0
  163. package/dist/modes/rpc/handoff-activity.js.map +1 -0
  164. package/dist/modes/rpc/host-child-exit.d.ts +19 -0
  165. package/dist/modes/rpc/host-child-exit.d.ts.map +1 -0
  166. package/dist/modes/rpc/host-child-exit.js +35 -0
  167. package/dist/modes/rpc/host-child-exit.js.map +1 -0
  168. package/dist/modes/rpc/host-crash-record.d.ts +24 -0
  169. package/dist/modes/rpc/host-crash-record.d.ts.map +1 -0
  170. package/dist/modes/rpc/host-crash-record.js +75 -0
  171. package/dist/modes/rpc/host-crash-record.js.map +1 -0
  172. package/dist/modes/rpc/host-crash-record.test.d.ts +2 -0
  173. package/dist/modes/rpc/host-crash-record.test.d.ts.map +1 -0
  174. package/dist/modes/rpc/host-crash-record.test.js +91 -0
  175. package/dist/modes/rpc/host-crash-record.test.js.map +1 -0
  176. package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
  177. package/dist/modes/rpc/host-ensure.js +60 -17
  178. package/dist/modes/rpc/host-ensure.js.map +1 -1
  179. package/dist/modes/rpc/host-lifecycle.d.ts +4 -10
  180. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
  181. package/dist/modes/rpc/host-lifecycle.js +83 -51
  182. package/dist/modes/rpc/host-lifecycle.js.map +1 -1
  183. package/dist/modes/rpc/host-supersession.d.ts +13 -2
  184. package/dist/modes/rpc/host-supersession.d.ts.map +1 -1
  185. package/dist/modes/rpc/host-supersession.js +40 -7
  186. package/dist/modes/rpc/host-supersession.js.map +1 -1
  187. package/dist/modes/rpc/multi-session-host.d.ts +1 -0
  188. package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
  189. package/dist/modes/rpc/multi-session-host.js +40 -7
  190. package/dist/modes/rpc/multi-session-host.js.map +1 -1
  191. package/dist/modes/rpc/observer-link.d.ts +48 -0
  192. package/dist/modes/rpc/observer-link.d.ts.map +1 -0
  193. package/dist/modes/rpc/observer-link.js +56 -0
  194. package/dist/modes/rpc/observer-link.js.map +1 -0
  195. package/dist/modes/rpc/rpc-mode.d.ts +12 -2
  196. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  197. package/dist/modes/rpc/rpc-mode.js +12 -2
  198. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  199. package/dist/modes/rpc/rpc-types.d.ts +36 -1
  200. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  201. package/dist/modes/rpc/rpc-types.js +8 -0
  202. package/dist/modes/rpc/rpc-types.js.map +1 -1
  203. package/dist/modes/rpc/session-command-router.d.ts +10 -4
  204. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  205. package/dist/modes/rpc/session-command-router.js +95 -19
  206. package/dist/modes/rpc/session-command-router.js.map +1 -1
  207. package/dist/modes/rpc/session-event-writer.d.ts +5 -3
  208. package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
  209. package/dist/modes/rpc/session-event-writer.js +21 -2
  210. package/dist/modes/rpc/session-event-writer.js.map +1 -1
  211. package/dist/modes/rpc/session-registry.d.ts +6 -1
  212. package/dist/modes/rpc/session-registry.d.ts.map +1 -1
  213. package/dist/modes/rpc/session-registry.js +34 -3
  214. package/dist/modes/rpc/session-registry.js.map +1 -1
  215. package/dist/modes/rpc/session-worker-client.d.ts +1 -0
  216. package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
  217. package/dist/modes/rpc/session-worker-client.js +3 -0
  218. package/dist/modes/rpc/session-worker-client.js.map +1 -1
  219. package/dist/modes/rpc/session-worker-protocol.d.ts +3 -1
  220. package/dist/modes/rpc/session-worker-protocol.d.ts.map +1 -1
  221. package/dist/modes/rpc/session-worker-protocol.js.map +1 -1
  222. package/dist/modes/rpc/session-worker.js +7 -1
  223. package/dist/modes/rpc/session-worker.js.map +1 -1
  224. package/dist/modes/rpc/socket-ownership.d.ts +16 -0
  225. package/dist/modes/rpc/socket-ownership.d.ts.map +1 -1
  226. package/dist/modes/rpc/socket-ownership.js +28 -4
  227. package/dist/modes/rpc/socket-ownership.js.map +1 -1
  228. package/dist/modes/rpc/worker-session-registry.d.ts +12 -5
  229. package/dist/modes/rpc/worker-session-registry.d.ts.map +1 -1
  230. package/dist/modes/rpc/worker-session-registry.js +10 -2
  231. package/dist/modes/rpc/worker-session-registry.js.map +1 -1
  232. package/docs/providers.md +9 -1
  233. package/docs/rpc.md +72 -10
  234. package/docs/settings.md +1 -1
  235. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +29 -0
  236. package/node_modules/@code-yeongyu/senpi-codemode/README.md +51 -13
  237. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  238. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +53 -9
  239. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/reserved-dispatch.ts +1 -0
  240. package/node_modules/@code-yeongyu/senpi-codemode/src/config/settings.ts +18 -0
  241. package/node_modules/@code-yeongyu/senpi-codemode/src/extension/eval-status.ts +9 -4
  242. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +6 -0
  243. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/AGENTS.md +2 -2
  244. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +10 -0
  245. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +18 -6
  246. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +2 -6
  247. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +1 -1
  248. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/run-queue.ts +17 -7
  249. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +6 -1
  250. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel-contract.ts +2 -5
  251. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +37 -5
  252. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +11 -2
  253. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +6 -0
  254. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-contract.ts +2 -5
  255. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +14 -4
  256. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +18 -5
  257. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +3 -2
  258. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +4 -1
  259. package/node_modules/@code-yeongyu/senpi-codemode/src/timeouts/idle-timeout.ts +9 -2
  260. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/AGENTS.md +2 -0
  261. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-execution.ts +19 -2
  262. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-runtime.ts +11 -3
  263. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-contract.ts +6 -1
  264. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +72 -20
  265. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-snapshot.ts +28 -4
  266. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-state.ts +5 -4
  267. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-status.ts +5 -2
  268. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-eval-result.ts +76 -25
  269. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-execution-event.ts +4 -0
  270. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-kernel-reset-refused-error.ts +12 -0
  271. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-request.ts +2 -1
  272. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +3 -1
  273. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +58 -37
  274. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/managed-cell.ts +15 -8
  275. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +32 -8
  276. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/run-eval-cell.ts +89 -25
  277. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/terminal-snapshot-store.ts +4 -0
  278. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +51 -10
  279. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +2 -1
  280. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  281. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -13
  282. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  283. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -0
  284. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  285. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +1 -0
  286. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  287. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.d.ts +5 -0
  288. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.d.ts.map +1 -0
  289. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.js +20 -0
  290. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.js.map +1 -0
  291. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  292. package/node_modules/@earendil-works/pi-ai/README.md +1 -1
  293. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +14 -56
  294. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  295. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
  296. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +18 -27
  297. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
  298. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.d.ts +40 -0
  299. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.d.ts.map +1 -0
  300. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.js +102 -0
  301. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.js.map +1 -0
  302. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts +4 -3
  303. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
  304. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +28 -14
  305. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
  306. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.d.ts +44 -0
  307. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.d.ts.map +1 -0
  308. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.js +120 -0
  309. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.js.map +1 -0
  310. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts +2 -2
  311. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts.map +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js +2 -2
  313. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js.map +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +3 -0
  315. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
  316. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +21 -15
  317. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
  318. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  320. package/node_modules/@earendil-works/pi-ai/dist/compat.js +1 -0
  321. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  322. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  324. package/node_modules/@earendil-works/pi-ai/dist/index.js +2 -0
  325. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.d.ts +8 -0
  327. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.d.ts.map +1 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.js +26 -0
  329. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.js.map +1 -0
  330. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  331. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  332. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  333. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  334. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  335. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  336. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  337. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  338. package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
  339. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  340. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  341. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  342. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  343. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  344. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  345. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.d.ts +9 -0
  346. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.d.ts.map +1 -0
  347. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.js +43 -0
  348. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.js.map +1 -0
  349. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.d.ts.map +1 -1
  350. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +3 -2
  351. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js.map +1 -1
  352. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.d.ts +19 -0
  353. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.d.ts.map +1 -0
  354. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.js +63 -0
  355. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.js.map +1 -0
  356. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.d.ts.map +1 -1
  357. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js +5 -1
  358. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js.map +1 -1
  359. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +17 -0
  360. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  361. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +22 -1
  362. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  363. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  364. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  365. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  366. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  367. package/node_modules/@earendil-works/pi-tui/dist/tui.js +12 -2
  368. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  369. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  370. package/package.json +7 -7
  371. package/dist/bundle/chunks/chunk-5J5R5AMP.js +0 -8
  372. package/dist/bundle/chunks/chunk-I3F6VZZF.js +0 -2
  373. package/dist/bundle/chunks/chunk-IDTLJYJ5.js +0 -10
  374. package/dist/bundle/chunks/chunk-U6Z6OBX4.js +0 -2
  375. package/dist/bundle/chunks/host-lifecycle-DGZJTBDJ.js +0 -3
  376. package/dist/bundle/chunks/multi-session-host-S5FWCIWE.js +0 -20
  377. package/dist/bundle/chunks/openai-codex-responses-L2PO2D6F.js +0 -10
  378. package/dist/bundle/chunks/openai-responses-YDUBVF4S.js +0 -2
  379. package/dist/bundle/chunks/rotation-stream-Y4YU6HV4.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"session-event-writer.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-event-writer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAIlE,OAAO,KAAK,EACX,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,EAElB,sBAAsB,EAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGN,KAAK,4BAA4B,EACjC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,yBAAyB,EAAE,KAAK,4BAA4B,EAAE,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.delete(sessionId);
139
139
  }
140
+ /** Drain just this connection before closing it after its last handoff park. */
141
+ async flushConnection(id) {
142
+ const target = this.fanout.get(id);
143
+ if (target)
144
+ await settleActors([target.actor]);
145
+ }
140
146
  /** Execute a connection's command with its response destination in context. */
141
147
  withConnection(id, task) {
142
148
  return this.connectionContext.run(id, task);
@@ -274,6 +280,14 @@ export class SessionEventWriter {
274
280
  // Reconstruct so desktop `refresh-senpi-events.ts` sees literal `type:` sites in this file.
275
281
  let wire;
276
282
  switch (record.type) {
283
+ case "host_superseded":
284
+ wire = {
285
+ type: "host_superseded",
286
+ instanceId: record.instanceId,
287
+ generation: record.generation,
288
+ successor: record.successor,
289
+ };
290
+ break;
277
291
  case "host_stalled":
278
292
  wire = {
279
293
  type: "host_stalled",
@@ -303,7 +317,7 @@ export class SessionEventWriter {
303
317
  * Existing records retain FIFO order; this response is therefore that
304
318
  * session's final stdout record.
305
319
  */
306
- closeSession(sessionId, response, reason) {
320
+ closeSession(sessionId, response, reason, sessionPath) {
307
321
  if (this.sealedSessions.has(sessionId))
308
322
  return;
309
323
  this.sealedSessions.add(sessionId);
@@ -311,7 +325,12 @@ export class SessionEventWriter {
311
325
  const targetId = this.connectionContext.getStore();
312
326
  // `reason` tells an attached client WHY the handle ended, so a park it can reopen by path is
313
327
  // not read as a session that is gone. Absent unless the caller names one; clients tolerate that.
314
- const lifecycle = { type: "session_closed", sessionId, ...(reason && { reason }) };
328
+ const lifecycle = {
329
+ type: "session_closed",
330
+ sessionId,
331
+ ...(reason && { reason }),
332
+ ...(sessionPath && { sessionPath }),
333
+ };
315
334
  if (this.fanout.isEmpty())
316
335
  this.appendSessionRecord(sessionId, lifecycle);
317
336
  else if (this.workerSessions.has(sessionId))
@@ -1 +1 @@
1
- {"version":3,"file":"session-event-writer.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-event-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,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C,YAAY;YAAE,OAAO;QACnF,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC;IAEO,IAAI,CAAC,KAAc;QAC1B,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO;QACvC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACtC,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI;gBAAE,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC;IACF,CAAC;IAEO,CAAC,SAAS;QACjB,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,YAAY,CAAC;IACzB,CAAC;CACD","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { SessionKind } from \"../../core/extensions/types.ts\";\nimport { MEDIA_PLACEHOLDERS_CAPABILITY } from \"./custom-capability.ts\";\nimport { serializeJsonLine } from \"./jsonl.ts\";\nimport { omitInlineMedia } from \"./media-placeholders.ts\";\nimport type {\n\tRpcHostMemoryPressureEvent,\n\tRpcHostStalledEvent,\n\tRpcOpenQueuedEvent,\n\tRpcSessionClosedEvent,\n\tRpcSessionClosedReason,\n\tRpcSessionParkedEvent,\n} from \"./rpc-types.ts\";\nimport {\n\tRENDERED_COMPONENT_RECORD,\n\tSessionEventFanout,\n\ttype SessionEventWriterConnection,\n} from \"./session-event-fanout.ts\";\nimport type { SocketEventSinkActor } from \"./socket-event-fanout.ts\";\n\nexport { RENDERED_COMPONENT_RECORD, type SessionEventWriterConnection } from \"./session-event-fanout.ts\";\n\n/** Await every actor's drain; a failed actor is a cut peer, not a writer failure. */\nconst settleActors = (actors: readonly SocketEventSinkActor[]): Promise<void> =>\n\tPromise.all(actors.map((actor) => actor.flush().catch(() => undefined))).then(() => undefined);\n\n/** Await every actor's ACCEPTANCE of what it was given; never the peer's kernel drain. */\nconst acceptActors = (actors: readonly SocketEventSinkActor[]): Promise<void> =>\n\tPromise.all(actors.map((actor) => actor.waitForAcceptance())).then(() => undefined);\n\ntype RawWriter = (chunk: string) => void;\ntype BackpressureWaiter = () => Promise<void>;\ntype FlushScheduler = (flush: () => Promise<void>) => void;\ntype RpcRecord = Record<string, unknown>;\ntype CompactDeltaType = \"text_delta\" | \"thinking_delta\" | \"toolcall_delta\";\n\ntype QueueNode = {\n\tvalue: RpcRecord;\n\tkey?: string;\n\tprevious?: QueueNode;\n\tnext?: QueueNode;\n\tresolve?: () => void;\n\treject?: (cause: unknown) => void;\n};\n\ntype RecordQueue = {\n\tsessionId?: string;\n\ttargetId?: string;\n\thead?: QueueNode;\n\ttail?: QueueNode;\n\tlatestByKey: Map<string, QueueNode>;\n\tready: boolean;\n};\n\nexport const MAX_SHARED_STDIO_QUEUE_BYTES = 64 * 1024 * 1024;\nexport const MAX_SHARED_STDIO_QUEUE_RECORDS = 4096;\n\nconst MESSAGE_KEY = \"message\";\nconst COMPACT_DELTA_TYPES = new Set<CompactDeltaType>([\"text_delta\", \"thinking_delta\", \"toolcall_delta\"]);\n\nfunction compactDelta(value: RpcRecord): { type: CompactDeltaType; contentIndex: number; delta: string } | undefined {\n\tif (value.type !== \"message_update\" || !Object.hasOwn(value, \"message\")) return undefined;\n\tconst event = value.assistantMessageEvent;\n\tif (typeof event !== \"object\" || event === null) return undefined;\n\tconst typedEvent = event as Record<string, unknown>;\n\tif (\n\t\ttypeof typedEvent.type !== \"string\" ||\n\t\t!COMPACT_DELTA_TYPES.has(typedEvent.type as CompactDeltaType) ||\n\t\ttypeof typedEvent.contentIndex !== \"number\" ||\n\t\ttypeof typedEvent.delta !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\ttype: typedEvent.type as CompactDeltaType,\n\t\tcontentIndex: typedEvent.contentIndex,\n\t\tdelta: typedEvent.delta,\n\t};\n}\n\n/** The delta-only form of a compact message_update: cumulative snapshot fields blanked, delta kept. */\nfunction demoteToDeltaOnly(value: RpcRecord): RpcRecord {\n\tconst event = value.assistantMessageEvent as Record<string, unknown>;\n\treturn { ...value, message: null, assistantMessageEvent: { ...event, partial: null } };\n}\n\nfunction toolUpdateKey(value: RpcRecord): string | undefined {\n\treturn value.type === \"tool_execution_update\" && typeof value.toolCallId === \"string\"\n\t\t? `tool:${value.toolCallId}`\n\t\t: undefined;\n}\n\n/**\n * Process-wide stdout scheduler for multi-session RPC mode.\n *\n * Each queue contains complete structured JSONL records for one routing handle.\n * Draining takes one record per queue in round-robin order and waits for stdout\n * backpressure before selecting the next one. A record is deliberately written\n * by itself: coalescing records from different sessions would obscure the\n * scheduling boundary and violate D9.\n */\nexport class SessionEventWriter {\n\tprivate readonly queues = new Map<string, RecordQueue>();\n\tprivate readonly fanout = new SessionEventFanout();\n\tprivate readonly connectionContext = new AsyncLocalStorage<string>();\n\tprivate readonly controlQueue: RecordQueue = { latestByKey: new Map(), ready: false };\n\tprivate readonly readyQueues: RecordQueue[] = [];\n\tprivate readonly sealedSessions = new Set<string>();\n\t/** Sessions whose lifecycle records stay on their attached connections (`kind: \"worker\"`). */\n\tprivate readonly workerSessions = new Set<string>();\n\tprivate readonly writeRaw: RawWriter;\n\tprivate readonly waitForBackpressure?: BackpressureWaiter;\n\tprivate readonly scheduleFlush: FlushScheduler;\n\tprivate flushScheduled = false;\n\tprivate drainPromise?: Promise<void>;\n\tprivate inFlight?: { queue: RecordQueue; node: QueueNode };\n\tprivate failure?: unknown;\n\tprivate controlOverflowReported = false;\n\tprivate closeOverflowReported = false;\n\tprivate readonly closeOverflowActors = new WeakSet<SocketEventSinkActor>();\n\tprivate reservedCloseRecords = 0;\n\tprivate reservedCloseBytes = 0;\n\n\tget pendingCloseRecordCount(): number {\n\t\treturn this.reservedCloseRecords;\n\t}\n\n\tget pendingCloseByteLength(): number {\n\t\treturn this.reservedCloseBytes;\n\t}\n\n\tconstructor(writeRaw: RawWriter, scheduleFlush?: FlushScheduler);\n\tconstructor(writeRaw: RawWriter, waitForBackpressure: BackpressureWaiter, scheduleFlush?: FlushScheduler);\n\tconstructor(\n\t\twriteRaw: RawWriter,\n\t\twaitOrSchedule?: BackpressureWaiter | FlushScheduler,\n\t\tscheduleFlush?: FlushScheduler,\n\t) {\n\t\tthis.writeRaw = writeRaw;\n\t\tif (waitOrSchedule && scheduleFlush === undefined && waitOrSchedule.length > 0) {\n\t\t\tthis.scheduleFlush = waitOrSchedule as FlushScheduler;\n\t\t} else {\n\t\t\tthis.waitForBackpressure = waitOrSchedule as BackpressureWaiter | undefined;\n\t\t\tthis.scheduleFlush = scheduleFlush ?? ((flush) => queueMicrotask(() => void flush()));\n\t\t}\n\t}\n\n\tget bufferedRecordCount(): number {\n\t\tlet count = this.inFlight ? 1 : 0;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) count++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tget bufferedByteLength(): number {\n\t\tlet bytes = this.inFlight ? Buffer.byteLength(serializeJsonLine(this.inFlight.node.value)) : 0;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) {\n\t\t\t\tbytes += Buffer.byteLength(serializeJsonLine(node.value));\n\t\t\t}\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tregisterConnection(\n\t\tid: string,\n\t\tconnection: SessionEventWriterConnection,\n\t\toptions: { readonly maxQueueBytes?: number; readonly stallMs?: number } = {},\n\t): void {\n\t\tthis.fanout.registerConnection(id, connection, options);\n\t}\n\n\tunregisterConnection(id: string): void {\n\t\tthis.fanout.unregisterConnection(id);\n\t}\n\n\tattachConnectionToSession(id: string, sessionId: string): void {\n\t\tthis.fanout.attachConnectionToSession(id, sessionId);\n\t}\n\n\tdetachConnectionFromSession(id: string, sessionId: string): void {\n\t\tthis.fanout.detachConnectionFromSession(id, sessionId);\n\t}\n\n\tsetConnectionCapabilities(id: string, capabilities: readonly string[]): void {\n\t\tthis.fanout.setConnectionCapabilities(id, capabilities);\n\t}\n\n\tclearConnectionCapabilities(id: string): void {\n\t\tthis.fanout.clearConnectionCapabilities(id);\n\t}\n\n\thasRegisteredConnectionCapabilities(id: string): boolean {\n\t\treturn this.fanout.hasRegisteredConnectionCapabilities(id);\n\t}\n\n\tgetConnectionCapabilities(id: string): readonly string[] | undefined {\n\t\treturn this.fanout.getConnectionCapabilities(id);\n\t}\n\n\thasCapableConnection(sessionId: string): boolean {\n\t\treturn this.fanout.hasCapableConnection(sessionId);\n\t}\n\n\t/**\n\t * Records a session's visibility class. A worker session is machine-driven work that\n\t * only its attached connections track, so its lifecycle records are delivered to them\n\t * instead of broadcast; an interactive session keeps the broadcast every client (the\n\t * desktop mirror, the supervisor's idle observer) relies on.\n\t */\n\tsetSessionKind(sessionId: string, kind: SessionKind): void {\n\t\tif (kind === \"worker\") this.workerSessions.add(sessionId);\n\t\telse this.workerSessions.delete(sessionId);\n\t}\n\n\t/** Execute a connection's command with its response destination in context. */\n\twithConnection<T>(id: string, task: () => T): T {\n\t\treturn this.connectionContext.run(id, task);\n\t}\n\n\t/** Connection id of the command currently being dispatched, when one owns it. */\n\tcurrentConnection(): string | undefined {\n\t\treturn this.connectionContext.getStore();\n\t}\n\n\t/** Queue a session record. Content events target connections attached to the session. */\n\tenqueue(sessionId: string, value: object): boolean {\n\t\tif (this.sealedSessions.has(sessionId)) return false;\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst record = value as RpcRecord;\n\t\tconst isTargeted =\n\t\t\trecord.type === \"response\" ||\n\t\t\trecord.type === \"bash_execution_update\" ||\n\t\t\t(record.type === \"extension_ui_request\" &&\n\t\t\t\t[\"select\", \"confirm\", \"input\", \"editor\"].includes(String(record.method)));\n\t\tconst tagged = { ...value, sessionId } as RpcRecord;\n\t\tconst { [RENDERED_COMPONENT_RECORD]: _rendered, ...wireTagged } = tagged;\n\t\tconst line = serializeJsonLine(wireTagged);\n\t\tif (this.fanout.isEmpty() && this.exceedsStdioCapacity(line)) {\n\t\t\tthis.closeSession(\n\t\t\t\tsessionId,\n\t\t\t\t{\n\t\t\t\t\ttype: \"response\",\n\t\t\t\t\tcommand: \"close_session\",\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: \"session_output_overflow, resync required\",\n\t\t\t\t},\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t\treturn false;\n\t\t}\n\t\tconst targets = this.fanout.targets(\n\t\t\tsessionId,\n\t\t\ttargetId,\n\t\t\tisTargeted,\n\t\t\trecord[RENDERED_COMPONENT_RECORD] === true,\n\t\t\trecord.type,\n\t\t);\n\t\t// A record is only walked and re-serialized when a target asked for placeholders;\n\t\t// otherwise this is byte-for-byte today's path, with serializeJsonLine called once.\n\t\tconst hasPlaceholderTarget = targets.some((target) =>\n\t\t\tthis.fanout.connectionHas(target, MEDIA_PLACEHOLDERS_CAPABILITY),\n\t\t);\n\t\tconst redacted = hasPlaceholderTarget ? omitInlineMedia(wireTagged) : wireTagged;\n\t\tconst placeholderLine = redacted === wireTagged ? undefined : serializeJsonLine(redacted);\n\t\tif (!isTargeted) this.fanout.rememberSnapshot(sessionId, tagged, line, placeholderLine, wireTagged);\n\t\tfor (const target of targets) {\n\t\t\tif (target !== undefined && !this.fanout.get(target)) continue;\n\t\t\tconst registered = target === undefined ? undefined : this.fanout.get(target);\n\t\t\tconst wants =\n\t\t\t\tplaceholderLine !== undefined && this.fanout.connectionHas(target, MEDIA_PLACEHOLDERS_CAPABILITY);\n\t\t\tif (registered) {\n\t\t\t\tconst keyed = compactDelta(tagged) !== undefined && tagged.message !== null;\n\t\t\t\tregistered.actor.enqueue(\n\t\t\t\t\twants ? placeholderLine : line,\n\t\t\t\t\tkeyed ? MESSAGE_KEY : undefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tkeyed ? serializeJsonLine(demoteToDeltaOnly(wireTagged)) : undefined,\n\t\t\t\t);\n\t\t\t} else this.appendSessionRecord(sessionId, wants ? (redacted as RpcRecord) : wireTagged, target);\n\t\t}\n\t\tthis.requestFlush();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Return worker credit once this session's destinations have ACCEPTED the record\n\t * into their bounded queues - never when the slowest peer's kernel has drained it.\n\t * A client that is merely busy would otherwise pace the producing worker into\n\t * session_worker_credit_timeout and force the dead-peer budget under\n\t * SESSION_WORKER_LIMITS.controlMs (#1774). Delivery stays bounded by each queue's\n\t * maxQueueBytes and its dead-peer cut. A destination that failed (byte overflow or\n\t * stall) was already cut and closed by the fanout's onFailure; it is a cut peer,\n\t * not a writer failure. The shared stdio lane keeps its stdout backpressure wait.\n\t */\n\twaitForSessionBackpressure(sessionId: string): Promise<void> {\n\t\tif (this.fanout.isEmpty()) return this.flush();\n\t\treturn acceptActors(this.sessionActors(sessionId));\n\t}\n\n\t/** Registered actors this session's records are delivered to, plus the caller's own. */\n\tprivate sessionActors(sessionId: string): SocketEventSinkActor[] {\n\t\tconst targets = new Set([\n\t\t\t...this.fanout.targets(sessionId, this.currentConnection(), false, false, undefined),\n\t\t\tthis.currentConnection(),\n\t\t]);\n\t\treturn [...targets].flatMap((target) => {\n\t\t\tconst registered = target === undefined ? undefined : this.fanout.get(target);\n\t\t\treturn registered ? [registered.actor] : [];\n\t\t});\n\t}\n\n\t/** Queue one untagged host-control response for the current connection. */\n\tenqueueControl(value: object): Promise<void> {\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) {\n\t\t\tregistered.actor.enqueue(serializeJsonLine(value));\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tif (this.exceedsStdioCapacity(serializeJsonLine(value))) {\n\t\t\tif (!this.controlOverflowReported) {\n\t\t\t\tthis.controlOverflowReported = true;\n\t\t\t\tthis.append(this.controlQueue, { type: \"overflow\", error: \"rpc_control_output_overflow, resync required\" });\n\t\t\t\tthis.markReady(this.controlQueue);\n\t\t\t\tthis.requestFlush();\n\t\t\t}\n\t\t\treturn Promise.reject(new Error(\"rpc_control_output_overflow, resync required\"));\n\t\t}\n\t\tconst queue = targetId === undefined ? this.controlQueue : this.connectionQueue(targetId);\n\t\tconst completion = new Promise<void>((resolve, reject) => {\n\t\t\tthis.append(queue, { ...value }, undefined, resolve, reject);\n\t\t});\n\t\tthis.markReady(queue);\n\t\tthis.requestFlush();\n\t\treturn completion;\n\t}\n\n\t/**\n\t * Queue one HOST-level lifecycle record for every registered connection, or the\n\t * shared stdio lane when none is registered. Unlike session records it is not tagged\n\t * with a routing handle by the writer: `host_stalled` carries the handle it blames,\n\t * and `host_memory_pressure` belongs to the process, not to a session.\n\t */\n\t/**\n\t * Tell ONE opener where it sits in the open queue, before its open reaches the loop.\n\t *\n\t * Sent to the opening connection only: a queue position is about that caller's request, not\n\t * about the host. If the connection is gone the record is dropped rather than queued - a\n\t * position is worthless to a client that already left.\n\t */\n\tsendOpenQueued(connection: string, record: RpcOpenQueuedEvent): void {\n\t\t// Reconstruct so desktop `refresh-senpi-events.ts` sees a literal `type:` site in this file.\n\t\tconst wire: RpcRecord = {\n\t\t\ttype: \"queued\",\n\t\t\tfor_request: record.for_request,\n\t\t\tposition: record.position,\n\t\t\tin_flight: record.in_flight,\n\t\t};\n\t\tconst target = this.fanout.get(connection);\n\t\tif (target === undefined) return;\n\t\ttarget.actor.enqueue(serializeJsonLine(wire));\n\t\tthis.requestFlush();\n\t}\n\n\tbroadcastHostRecord(record: RpcHostStalledEvent | RpcHostMemoryPressureEvent): void {\n\t\t// Reconstruct so desktop `refresh-senpi-events.ts` sees literal `type:` sites in this file.\n\t\tlet wire: RpcRecord;\n\t\tswitch (record.type) {\n\t\t\tcase \"host_stalled\":\n\t\t\t\twire = {\n\t\t\t\t\ttype: \"host_stalled\",\n\t\t\t\t\tdriftMs: record.driftMs,\n\t\t\t\t\t...(record.sessionId !== undefined ? { sessionId: record.sessionId } : {}),\n\t\t\t\t\t...(record.tool !== undefined ? { tool: record.tool } : {}),\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host_memory_pressure\":\n\t\t\t\twire = { type: \"host_memory_pressure\", rssMb: record.rssMb, sessions: record.sessions };\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = record;\n\t\t\t\tthrow new Error(`unexpected host record ${exhaustive}`);\n\t\t\t}\n\t\t}\n\t\tif (this.fanout.isEmpty()) {\n\t\t\tthis.append(this.controlQueue, wire);\n\t\t\tthis.markReady(this.controlQueue);\n\t\t} else this.fanout.broadcast(serializeJsonLine(wire));\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Prevent subsequent records for a session and append its terminal response.\n\t * Existing records retain FIFO order; this response is therefore that\n\t * session's final stdout record.\n\t */\n\tcloseSession(sessionId: string, response: object, reason?: RpcSessionClosedReason): void {\n\t\tif (this.sealedSessions.has(sessionId)) return;\n\t\tthis.sealedSessions.add(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t\tconst targetId = this.connectionContext.getStore();\n\t\t// `reason` tells an attached client WHY the handle ended, so a park it can reopen by path is\n\t\t// not read as a session that is gone. Absent unless the caller names one; clients tolerate that.\n\t\tconst lifecycle: RpcSessionClosedEvent = { type: \"session_closed\", sessionId, ...(reason && { reason }) };\n\t\tif (this.fanout.isEmpty()) this.appendSessionRecord(sessionId, lifecycle);\n\t\telse if (this.workerSessions.has(sessionId))\n\t\t\tthis.fanout.deliverToSession(sessionId, serializeJsonLine(lifecycle));\n\t\telse this.fanout.broadcast(serializeJsonLine(lifecycle));\n\t\tconst taggedResponse = { ...response, sessionId };\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) registered.actor.enqueue(serializeJsonLine(taggedResponse));\n\t\telse this.appendSessionRecord(sessionId, taggedResponse, targetId);\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Seal a session the host PARKED and publish `session_parked`.\n\t *\n\t * Parking is the idle sweep putting a RETAINED session back on disk: the routing\n\t * handle ends exactly as a close ends it, but the session survives and reopens with\n\t * `open_session { sessionPath }`, so the record a client dispatches on must say so\n\t * instead of claiming the session ended. Delivery follows the `session_closed` rule -\n\t * a worker session's record reaches only its attached connections, an interactive\n\t * session's reaches every connection. No client asked for this teardown, so there is\n\t * no close response to answer.\n\t */\n\tparkSession(sessionId: string, sessionPath: string): void {\n\t\tif (this.sealedSessions.has(sessionId)) return;\n\t\tthis.sealedSessions.add(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t\tconst lifecycle: RpcSessionParkedEvent = { type: \"session_parked\", sessionId, sessionPath };\n\t\tif (this.fanout.isEmpty()) this.appendSessionRecord(sessionId, lifecycle);\n\t\telse if (this.workerSessions.has(sessionId))\n\t\t\tthis.fanout.deliverToSession(sessionId, serializeJsonLine(lifecycle));\n\t\telse this.fanout.broadcast(serializeJsonLine(lifecycle));\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Admit reply debt before routing can mutate attachments or await finalization.\n\t * Reserve the lifecycle as well: the claimant's role is not known yet. Rejected\n\t * closes do not wait, retain their ids, or create per-request stderr output.\n\t */\n\treserveCloseResponse(\n\t\tsessionId: string,\n\t\tresponse: object,\n\t\trecords = 2,\n\t): { release: () => void; complete: (terminal: boolean, reason?: RpcSessionClosedReason) => void } | undefined {\n\t\tconst bytes =\n\t\t\tBuffer.byteLength(serializeJsonLine({ ...response, sessionId })) +\n\t\t\t(records === 2\n\t\t\t\t? Buffer.byteLength(serializeJsonLine({ type: \"session_closed\", sessionId, reason: \"client_close\" }))\n\t\t\t\t: 0);\n\t\tif (\n\t\t\tthis.bufferedRecordCount + this.reservedCloseRecords + records > MAX_SHARED_STDIO_QUEUE_RECORDS ||\n\t\t\tthis.bufferedByteLength + this.reservedCloseBytes + bytes > MAX_SHARED_STDIO_QUEUE_BYTES\n\t\t) {\n\t\t\tconst overflow = {\n\t\t\t\ttype: \"overflow\",\n\t\t\t\tcommand: \"close_session\",\n\t\t\t\terror: \"rpc_close_output_overflow, resync required\",\n\t\t\t};\n\t\t\tconst targetId = this.currentConnection();\n\t\t\tif (targetId !== undefined) {\n\t\t\t\tconst actor = this.fanout.get(targetId)?.actor;\n\t\t\t\tif (actor && !this.closeOverflowActors.has(actor)) {\n\t\t\t\t\tthis.closeOverflowActors.add(actor);\n\t\t\t\t\t// One outstanding notice per sink, released only on consumption.\n\t\t\t\t\t// Actor identity isolates reconnects and does not retain dead sinks.\n\t\t\t\t\tactor.enqueue(serializeJsonLine(overflow), undefined, () => this.closeOverflowActors.delete(actor));\n\t\t\t\t}\n\t\t\t} else if (!this.closeOverflowReported) {\n\t\t\t\tthis.closeOverflowReported = true;\n\t\t\t\tthis.append(this.controlQueue, overflow);\n\t\t\t\tthis.markReady(this.controlQueue);\n\t\t\t\tthis.requestFlush();\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.reservedCloseRecords += records;\n\t\tthis.reservedCloseBytes += bytes;\n\t\tlet active = true;\n\t\tconst release = () => {\n\t\t\tif (!active) return;\n\t\t\tactive = false;\n\t\t\tthis.reservedCloseRecords -= records;\n\t\t\tthis.reservedCloseBytes -= bytes;\n\t\t};\n\t\treturn {\n\t\t\trelease,\n\t\t\tcomplete: (terminal, reason) => {\n\t\t\t\tif (!active) return;\n\t\t\t\trelease();\n\t\t\t\tif (terminal) this.closeSession(sessionId, response, reason);\n\t\t\t\telse this.appendClosedResponse(sessionId, response);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Queue a joined close only after admitting its noncompactable reply. */\n\tenqueueClosedResponse(sessionId: string, response: object): void {\n\t\tthis.reserveCloseResponse(sessionId, response, 1)?.complete(false);\n\t}\n\n\tprivate appendClosedResponse(sessionId: string, response: object): void {\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst taggedResponse = { ...response, sessionId };\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) registered.actor.enqueue(serializeJsonLine(taggedResponse));\n\t\telse this.appendSessionRecord(sessionId, taggedResponse, targetId);\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Drops per-session bookkeeping for a handle whose runtime is fully disposed.\n\t * Routing handles are unique per process epoch, so nothing can legitimately\n\t * emit under this id again; without this every host-closed session would\n\t * leave a permanent sealed-handle (and snapshot) entry behind.\n\t */\n\tforgetSession(sessionId: string): void {\n\t\tthis.sealedSessions.delete(sessionId);\n\t\tthis.workerSessions.delete(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t}\n\n\t/** Drain every retained lane and the current in-flight record. */\n\tflush(): Promise<void> {\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tthis.flushScheduled = false;\n\t\tif (this.drainPromise) return this.drainPromise;\n\t\tif (this.readyQueues.length === 0) return settleActors([...this.fanout.values()].map(({ actor }) => actor));\n\t\tlet resolveDrain!: () => void;\n\t\tlet rejectDrain!: (cause: unknown) => void;\n\t\tconst drain = new Promise<void>((resolve, reject) => {\n\t\t\tresolveDrain = resolve;\n\t\t\trejectDrain = reject;\n\t\t});\n\t\tthis.drainPromise = drain;\n\t\tvoid this.drainUntilEmpty().then(resolveDrain, rejectDrain);\n\t\tvoid drain.then(\n\t\t\t() => {\n\t\t\t\tif (this.drainPromise === drain) this.drainPromise = undefined;\n\t\t\t\tif (this.readyQueues.length > 0) this.requestFlush();\n\t\t\t},\n\t\t\t(cause) => {\n\t\t\t\tif (this.drainPromise === drain) this.drainPromise = undefined;\n\t\t\t\tthis.fail(cause);\n\t\t\t},\n\t\t);\n\t\treturn drain;\n\t}\n\n\tprivate async drainUntilEmpty(): Promise<void> {\n\t\tdo {\n\t\t\tawait this.drainReadyQueues();\n\t\t} while (this.readyQueues.length > 0);\n\t\t// Per-connection failures are handled by the fanout (cut + close); only the\n\t\t// shared stdio lane may fail this writer.\n\t\tawait settleActors([...this.fanout.values()].map(({ actor }) => actor));\n\t\tthis.controlOverflowReported = false;\n\t\tif (this.reservedCloseRecords === 0) this.closeOverflowReported = false;\n\t}\n\n\tprivate async drainReadyQueues(): Promise<void> {\n\t\twhile (this.readyQueues.length > 0) {\n\t\t\tconst queue = this.readyQueues.shift()!;\n\t\t\tqueue.ready = false;\n\t\t\tconst node = queue.head;\n\t\t\tif (!node) continue;\n\n\t\t\tthis.unlink(queue, node);\n\t\t\tthis.inFlight = { queue, node };\n\t\t\ttry {\n\t\t\t\t// D9: exactly one complete record per raw write. The next lane is not\n\t\t\t\t// selected until this record has cleared stdout backpressure.\n\t\t\t\tconst connection = queue.targetId ? this.fanout.get(queue.targetId)?.connection : undefined;\n\t\t\t\tconst writeRaw = connection?.writeRaw ?? this.writeRaw;\n\t\t\t\tconst waitForBackpressure = connection?.waitForBackpressure ?? this.waitForBackpressure;\n\t\t\t\tif (!connection && queue.targetId) {\n\t\t\t\t\tnode.resolve?.();\n\t\t\t\t} else {\n\t\t\t\t\twriteRaw(serializeJsonLine(node.value));\n\t\t\t\t\tif (waitForBackpressure) await waitForBackpressure();\n\t\t\t\t\tnode.resolve?.();\n\t\t\t\t}\n\t\t\t} catch (cause) {\n\t\t\t\tnode.reject?.(cause);\n\t\t\t\tthrow cause;\n\t\t\t} finally {\n\t\t\t\tthis.inFlight = undefined;\n\t\t\t}\n\n\t\t\tif (queue.head) {\n\t\t\t\tthis.markReady(queue);\n\t\t\t} else if (queue.sessionId || queue.targetId) {\n\t\t\t\tfor (const [key, candidate] of this.queues) {\n\t\t\t\t\tif (candidate === queue) this.queues.delete(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate exceedsStdioCapacity(line: string): boolean {\n\t\treturn (\n\t\t\tthis.bufferedRecordCount + this.reservedCloseRecords >= MAX_SHARED_STDIO_QUEUE_RECORDS ||\n\t\t\tthis.bufferedByteLength + this.reservedCloseBytes + Buffer.byteLength(line) > MAX_SHARED_STDIO_QUEUE_BYTES\n\t\t);\n\t}\n\n\tprivate connectionQueue(targetId: string): RecordQueue {\n\t\tconst key = `connection:${targetId}`;\n\t\tlet queue = this.queues.get(key);\n\t\tif (!queue) {\n\t\t\tqueue = { targetId, latestByKey: new Map(), ready: false };\n\t\t\tthis.queues.set(key, queue);\n\t\t}\n\t\treturn queue;\n\t}\n\n\tprivate appendSessionRecord(sessionId: string, value: RpcRecord, targetId?: string): void {\n\t\tconst key = `${targetId ?? \"default\"}:${sessionId}`;\n\t\tlet queue = this.queues.get(key);\n\t\tif (!queue) {\n\t\t\tqueue = { sessionId, targetId, latestByKey: new Map(), ready: false };\n\t\t\tthis.queues.set(key, queue);\n\t\t}\n\n\t\tconst delta = compactDelta(value);\n\t\tif (delta) {\n\t\t\tconst previousFull = queue.latestByKey.get(MESSAGE_KEY);\n\t\t\tif (previousFull) this.demoteAndMerge(queue, previousFull);\n\t\t\tconst node = this.append(queue, value, MESSAGE_KEY);\n\t\t\tqueue.latestByKey.set(MESSAGE_KEY, node);\n\t\t\tthis.markReady(queue);\n\t\t\treturn;\n\t\t}\n\n\t\tconst toolKey = toolUpdateKey(value);\n\t\tif (toolKey) {\n\t\t\tconst previous = queue.latestByKey.get(toolKey);\n\t\t\tif (previous) this.unlink(queue, previous);\n\t\t\tconst node = this.append(queue, value, toolKey);\n\t\t\tqueue.latestByKey.set(toolKey, node);\n\t\t\tthis.markReady(queue);\n\t\t\treturn;\n\t\t}\n\n\t\t// All non-compactable records are ordering barriers. In particular this\n\t\t// includes delta-only/full non-delta message updates, protocol responses,\n\t\t// extension UI requests, errors, retries, lifecycle, and unknown records.\n\t\tqueue.latestByKey.clear();\n\t\tthis.append(queue, value);\n\t\tthis.markReady(queue);\n\t}\n\n\tprivate demoteAndMerge(queue: RecordQueue, node: QueueNode): void {\n\t\tnode.value = demoteToDeltaOnly(node.value);\n\t\tconst current = compactDelta(node.value);\n\t\tconst preceding = node.previous;\n\t\tconst previous = preceding ? compactDelta(preceding.value) : undefined;\n\t\tif (\n\t\t\tpreceding &&\n\t\t\tprevious &&\n\t\t\tcurrent &&\n\t\t\tpreceding.value.message === null &&\n\t\t\tprevious.type === current.type &&\n\t\t\tprevious.contentIndex === current.contentIndex\n\t\t) {\n\t\t\tconst precedingEvent = preceding.value.assistantMessageEvent as Record<string, unknown>;\n\t\t\tpreceding.value = {\n\t\t\t\t...preceding.value,\n\t\t\t\tassistantMessageEvent: { ...precedingEvent, delta: previous.delta + current.delta },\n\t\t\t};\n\t\t\tthis.unlink(queue, node);\n\t\t}\n\t}\n\n\tprivate append(\n\t\tqueue: RecordQueue,\n\t\tvalue: RpcRecord,\n\t\tkey?: string,\n\t\tresolve?: () => void,\n\t\treject?: (cause: unknown) => void,\n\t): QueueNode {\n\t\tconst node: QueueNode = { value, key, previous: queue.tail, resolve, reject };\n\t\tif (queue.tail) queue.tail.next = node;\n\t\telse queue.head = node;\n\t\tqueue.tail = node;\n\t\treturn node;\n\t}\n\n\tprivate unlink(queue: RecordQueue, node: QueueNode): void {\n\t\tif (node.previous) node.previous.next = node.next;\n\t\telse queue.head = node.next;\n\t\tif (node.next) node.next.previous = node.previous;\n\t\telse queue.tail = node.previous;\n\t\tif (node.key && queue.latestByKey.get(node.key) === node) queue.latestByKey.delete(node.key);\n\t\tnode.previous = undefined;\n\t\tnode.next = undefined;\n\t}\n\n\tprivate markReady(queue: RecordQueue): void {\n\t\tif (queue.ready || this.inFlight?.queue === queue || !queue.head) return;\n\t\tqueue.ready = true;\n\t\tthis.readyQueues.push(queue);\n\t}\n\n\tprivate requestFlush(): void {\n\t\tif (this.failure !== undefined || this.flushScheduled || this.drainPromise) return;\n\t\tthis.flushScheduled = true;\n\t\tthis.scheduleFlush(() => this.flush());\n\t}\n\n\tprivate fail(cause: unknown): void {\n\t\tif (this.failure !== undefined) return;\n\t\tthis.failure = cause;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) node.reject?.(cause);\n\t\t}\n\t}\n\n\tprivate *allQueues(): Iterable<RecordQueue> {\n\t\tyield* this.queues.values();\n\t\tyield this.controlQueue;\n\t}\n}\n"]}
1
+ {"version":3,"file":"session-event-writer.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-event-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ1D,OAAO,EACN,yBAAyB,EACzB,kBAAkB,GAElB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,yBAAyB,EAAqC,MAAM,2BAA2B,CAAC;AAEzG,qFAAqF;AACrF,MAAM,YAAY,GAAG,CAAC,MAAuC,EAAiB,EAAE,CAC/E,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAEhG,0FAA0F;AAC1F,MAAM,YAAY,GAAG,CAAC,MAAuC,EAAiB,EAAE,CAC/E,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AA0BrF,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAC7D,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAEnD,MAAM,WAAW,GAAG,SAAS,C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EAAE,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC;IACF,CAAC;IAEO,CAAC,SAAS;QACjB,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,YAAY,CAAC;IACzB,CAAC;CACD","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { SessionKind } from \"../../core/extensions/types.ts\";\nimport { MEDIA_PLACEHOLDERS_CAPABILITY } from \"./custom-capability.ts\";\nimport { serializeJsonLine } from \"./jsonl.ts\";\nimport { omitInlineMedia } from \"./media-placeholders.ts\";\nimport type {\n\tRpcHostLifecycleEvent,\n\tRpcOpenQueuedEvent,\n\tRpcSessionClosedEvent,\n\tRpcSessionClosedReason,\n\tRpcSessionParkedEvent,\n} from \"./rpc-types.ts\";\nimport {\n\tRENDERED_COMPONENT_RECORD,\n\tSessionEventFanout,\n\ttype SessionEventWriterConnection,\n} from \"./session-event-fanout.ts\";\nimport type { SocketEventSinkActor } from \"./socket-event-fanout.ts\";\n\nexport { RENDERED_COMPONENT_RECORD, type SessionEventWriterConnection } from \"./session-event-fanout.ts\";\n\n/** Await every actor's drain; a failed actor is a cut peer, not a writer failure. */\nconst settleActors = (actors: readonly SocketEventSinkActor[]): Promise<void> =>\n\tPromise.all(actors.map((actor) => actor.flush().catch(() => undefined))).then(() => undefined);\n\n/** Await every actor's ACCEPTANCE of what it was given; never the peer's kernel drain. */\nconst acceptActors = (actors: readonly SocketEventSinkActor[]): Promise<void> =>\n\tPromise.all(actors.map((actor) => actor.waitForAcceptance())).then(() => undefined);\n\ntype RawWriter = (chunk: string) => void;\ntype BackpressureWaiter = () => Promise<void>;\ntype FlushScheduler = (flush: () => Promise<void>) => void;\ntype RpcRecord = Record<string, unknown>;\ntype CompactDeltaType = \"text_delta\" | \"thinking_delta\" | \"toolcall_delta\";\n\ntype QueueNode = {\n\tvalue: RpcRecord;\n\tkey?: string;\n\tprevious?: QueueNode;\n\tnext?: QueueNode;\n\tresolve?: () => void;\n\treject?: (cause: unknown) => void;\n};\n\ntype RecordQueue = {\n\tsessionId?: string;\n\ttargetId?: string;\n\thead?: QueueNode;\n\ttail?: QueueNode;\n\tlatestByKey: Map<string, QueueNode>;\n\tready: boolean;\n};\n\nexport const MAX_SHARED_STDIO_QUEUE_BYTES = 64 * 1024 * 1024;\nexport const MAX_SHARED_STDIO_QUEUE_RECORDS = 4096;\n\nconst MESSAGE_KEY = \"message\";\nconst COMPACT_DELTA_TYPES = new Set<CompactDeltaType>([\"text_delta\", \"thinking_delta\", \"toolcall_delta\"]);\n\nfunction compactDelta(value: RpcRecord): { type: CompactDeltaType; contentIndex: number; delta: string } | undefined {\n\tif (value.type !== \"message_update\" || !Object.hasOwn(value, \"message\")) return undefined;\n\tconst event = value.assistantMessageEvent;\n\tif (typeof event !== \"object\" || event === null) return undefined;\n\tconst typedEvent = event as Record<string, unknown>;\n\tif (\n\t\ttypeof typedEvent.type !== \"string\" ||\n\t\t!COMPACT_DELTA_TYPES.has(typedEvent.type as CompactDeltaType) ||\n\t\ttypeof typedEvent.contentIndex !== \"number\" ||\n\t\ttypeof typedEvent.delta !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\ttype: typedEvent.type as CompactDeltaType,\n\t\tcontentIndex: typedEvent.contentIndex,\n\t\tdelta: typedEvent.delta,\n\t};\n}\n\n/** The delta-only form of a compact message_update: cumulative snapshot fields blanked, delta kept. */\nfunction demoteToDeltaOnly(value: RpcRecord): RpcRecord {\n\tconst event = value.assistantMessageEvent as Record<string, unknown>;\n\treturn { ...value, message: null, assistantMessageEvent: { ...event, partial: null } };\n}\n\nfunction toolUpdateKey(value: RpcRecord): string | undefined {\n\treturn value.type === \"tool_execution_update\" && typeof value.toolCallId === \"string\"\n\t\t? `tool:${value.toolCallId}`\n\t\t: undefined;\n}\n\n/**\n * Process-wide stdout scheduler for multi-session RPC mode.\n *\n * Each queue contains complete structured JSONL records for one routing handle.\n * Draining takes one record per queue in round-robin order and waits for stdout\n * backpressure before selecting the next one. A record is deliberately written\n * by itself: coalescing records from different sessions would obscure the\n * scheduling boundary and violate D9.\n */\nexport class SessionEventWriter {\n\tprivate readonly queues = new Map<string, RecordQueue>();\n\tprivate readonly fanout = new SessionEventFanout();\n\tprivate readonly connectionContext = new AsyncLocalStorage<string>();\n\tprivate readonly controlQueue: RecordQueue = { latestByKey: new Map(), ready: false };\n\tprivate readonly readyQueues: RecordQueue[] = [];\n\tprivate readonly sealedSessions = new Set<string>();\n\t/** Sessions whose lifecycle records stay on their attached connections (`kind: \"worker\"`). */\n\tprivate readonly workerSessions = new Set<string>();\n\tprivate readonly writeRaw: RawWriter;\n\tprivate readonly waitForBackpressure?: BackpressureWaiter;\n\tprivate readonly scheduleFlush: FlushScheduler;\n\tprivate flushScheduled = false;\n\tprivate drainPromise?: Promise<void>;\n\tprivate inFlight?: { queue: RecordQueue; node: QueueNode };\n\tprivate failure?: unknown;\n\tprivate controlOverflowReported = false;\n\tprivate closeOverflowReported = false;\n\tprivate readonly closeOverflowActors = new WeakSet<SocketEventSinkActor>();\n\tprivate reservedCloseRecords = 0;\n\tprivate reservedCloseBytes = 0;\n\n\tget pendingCloseRecordCount(): number {\n\t\treturn this.reservedCloseRecords;\n\t}\n\n\tget pendingCloseByteLength(): number {\n\t\treturn this.reservedCloseBytes;\n\t}\n\n\tconstructor(writeRaw: RawWriter, scheduleFlush?: FlushScheduler);\n\tconstructor(writeRaw: RawWriter, waitForBackpressure: BackpressureWaiter, scheduleFlush?: FlushScheduler);\n\tconstructor(\n\t\twriteRaw: RawWriter,\n\t\twaitOrSchedule?: BackpressureWaiter | FlushScheduler,\n\t\tscheduleFlush?: FlushScheduler,\n\t) {\n\t\tthis.writeRaw = writeRaw;\n\t\tif (waitOrSchedule && scheduleFlush === undefined && waitOrSchedule.length > 0) {\n\t\t\tthis.scheduleFlush = waitOrSchedule as FlushScheduler;\n\t\t} else {\n\t\t\tthis.waitForBackpressure = waitOrSchedule as BackpressureWaiter | undefined;\n\t\t\tthis.scheduleFlush = scheduleFlush ?? ((flush) => queueMicrotask(() => void flush()));\n\t\t}\n\t}\n\n\tget bufferedRecordCount(): number {\n\t\tlet count = this.inFlight ? 1 : 0;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) count++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tget bufferedByteLength(): number {\n\t\tlet bytes = this.inFlight ? Buffer.byteLength(serializeJsonLine(this.inFlight.node.value)) : 0;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) {\n\t\t\t\tbytes += Buffer.byteLength(serializeJsonLine(node.value));\n\t\t\t}\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tregisterConnection(\n\t\tid: string,\n\t\tconnection: SessionEventWriterConnection,\n\t\toptions: { readonly maxQueueBytes?: number; readonly stallMs?: number } = {},\n\t): void {\n\t\tthis.fanout.registerConnection(id, connection, options);\n\t}\n\n\tunregisterConnection(id: string): void {\n\t\tthis.fanout.unregisterConnection(id);\n\t}\n\n\tattachConnectionToSession(id: string, sessionId: string): void {\n\t\tthis.fanout.attachConnectionToSession(id, sessionId);\n\t}\n\n\tdetachConnectionFromSession(id: string, sessionId: string): void {\n\t\tthis.fanout.detachConnectionFromSession(id, sessionId);\n\t}\n\n\tsetConnectionCapabilities(id: string, capabilities: readonly string[]): void {\n\t\tthis.fanout.setConnectionCapabilities(id, capabilities);\n\t}\n\n\tclearConnectionCapabilities(id: string): void {\n\t\tthis.fanout.clearConnectionCapabilities(id);\n\t}\n\n\thasRegisteredConnectionCapabilities(id: string): boolean {\n\t\treturn this.fanout.hasRegisteredConnectionCapabilities(id);\n\t}\n\n\tgetConnectionCapabilities(id: string): readonly string[] | undefined {\n\t\treturn this.fanout.getConnectionCapabilities(id);\n\t}\n\n\thasCapableConnection(sessionId: string): boolean {\n\t\treturn this.fanout.hasCapableConnection(sessionId);\n\t}\n\n\t/**\n\t * Records a session's visibility class. A worker session is machine-driven work that\n\t * only its attached connections track, so its lifecycle records are delivered to them\n\t * instead of broadcast; an interactive session keeps the broadcast every client (the\n\t * desktop mirror, the supervisor's idle observer) relies on.\n\t */\n\tsetSessionKind(sessionId: string, kind: SessionKind): void {\n\t\tif (kind === \"worker\") this.workerSessions.add(sessionId);\n\t\telse this.workerSessions.delete(sessionId);\n\t}\n\n\t/** Drain just this connection before closing it after its last handoff park. */\n\tasync flushConnection(id: string): Promise<void> {\n\t\tconst target = this.fanout.get(id);\n\t\tif (target) await settleActors([target.actor]);\n\t}\n\n\t/** Execute a connection's command with its response destination in context. */\n\twithConnection<T>(id: string, task: () => T): T {\n\t\treturn this.connectionContext.run(id, task);\n\t}\n\n\t/** Connection id of the command currently being dispatched, when one owns it. */\n\tcurrentConnection(): string | undefined {\n\t\treturn this.connectionContext.getStore();\n\t}\n\n\t/** Queue a session record. Content events target connections attached to the session. */\n\tenqueue(sessionId: string, value: object): boolean {\n\t\tif (this.sealedSessions.has(sessionId)) return false;\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst record = value as RpcRecord;\n\t\tconst isTargeted =\n\t\t\trecord.type === \"response\" ||\n\t\t\trecord.type === \"bash_execution_update\" ||\n\t\t\t(record.type === \"extension_ui_request\" &&\n\t\t\t\t[\"select\", \"confirm\", \"input\", \"editor\"].includes(String(record.method)));\n\t\tconst tagged = { ...value, sessionId } as RpcRecord;\n\t\tconst { [RENDERED_COMPONENT_RECORD]: _rendered, ...wireTagged } = tagged;\n\t\tconst line = serializeJsonLine(wireTagged);\n\t\tif (this.fanout.isEmpty() && this.exceedsStdioCapacity(line)) {\n\t\t\tthis.closeSession(\n\t\t\t\tsessionId,\n\t\t\t\t{\n\t\t\t\t\ttype: \"response\",\n\t\t\t\t\tcommand: \"close_session\",\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: \"session_output_overflow, resync required\",\n\t\t\t\t},\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t\treturn false;\n\t\t}\n\t\tconst targets = this.fanout.targets(\n\t\t\tsessionId,\n\t\t\ttargetId,\n\t\t\tisTargeted,\n\t\t\trecord[RENDERED_COMPONENT_RECORD] === true,\n\t\t\trecord.type,\n\t\t);\n\t\t// A record is only walked and re-serialized when a target asked for placeholders;\n\t\t// otherwise this is byte-for-byte today's path, with serializeJsonLine called once.\n\t\tconst hasPlaceholderTarget = targets.some((target) =>\n\t\t\tthis.fanout.connectionHas(target, MEDIA_PLACEHOLDERS_CAPABILITY),\n\t\t);\n\t\tconst redacted = hasPlaceholderTarget ? omitInlineMedia(wireTagged) : wireTagged;\n\t\tconst placeholderLine = redacted === wireTagged ? undefined : serializeJsonLine(redacted);\n\t\tif (!isTargeted) this.fanout.rememberSnapshot(sessionId, tagged, line, placeholderLine, wireTagged);\n\t\tfor (const target of targets) {\n\t\t\tif (target !== undefined && !this.fanout.get(target)) continue;\n\t\t\tconst registered = target === undefined ? undefined : this.fanout.get(target);\n\t\t\tconst wants =\n\t\t\t\tplaceholderLine !== undefined && this.fanout.connectionHas(target, MEDIA_PLACEHOLDERS_CAPABILITY);\n\t\t\tif (registered) {\n\t\t\t\tconst keyed = compactDelta(tagged) !== undefined && tagged.message !== null;\n\t\t\t\tregistered.actor.enqueue(\n\t\t\t\t\twants ? placeholderLine : line,\n\t\t\t\t\tkeyed ? MESSAGE_KEY : undefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tkeyed ? serializeJsonLine(demoteToDeltaOnly(wireTagged)) : undefined,\n\t\t\t\t);\n\t\t\t} else this.appendSessionRecord(sessionId, wants ? (redacted as RpcRecord) : wireTagged, target);\n\t\t}\n\t\tthis.requestFlush();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Return worker credit once this session's destinations have ACCEPTED the record\n\t * into their bounded queues - never when the slowest peer's kernel has drained it.\n\t * A client that is merely busy would otherwise pace the producing worker into\n\t * session_worker_credit_timeout and force the dead-peer budget under\n\t * SESSION_WORKER_LIMITS.controlMs (#1774). Delivery stays bounded by each queue's\n\t * maxQueueBytes and its dead-peer cut. A destination that failed (byte overflow or\n\t * stall) was already cut and closed by the fanout's onFailure; it is a cut peer,\n\t * not a writer failure. The shared stdio lane keeps its stdout backpressure wait.\n\t */\n\twaitForSessionBackpressure(sessionId: string): Promise<void> {\n\t\tif (this.fanout.isEmpty()) return this.flush();\n\t\treturn acceptActors(this.sessionActors(sessionId));\n\t}\n\n\t/** Registered actors this session's records are delivered to, plus the caller's own. */\n\tprivate sessionActors(sessionId: string): SocketEventSinkActor[] {\n\t\tconst targets = new Set([\n\t\t\t...this.fanout.targets(sessionId, this.currentConnection(), false, false, undefined),\n\t\t\tthis.currentConnection(),\n\t\t]);\n\t\treturn [...targets].flatMap((target) => {\n\t\t\tconst registered = target === undefined ? undefined : this.fanout.get(target);\n\t\t\treturn registered ? [registered.actor] : [];\n\t\t});\n\t}\n\n\t/** Queue one untagged host-control response for the current connection. */\n\tenqueueControl(value: object): Promise<void> {\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) {\n\t\t\tregistered.actor.enqueue(serializeJsonLine(value));\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tif (this.exceedsStdioCapacity(serializeJsonLine(value))) {\n\t\t\tif (!this.controlOverflowReported) {\n\t\t\t\tthis.controlOverflowReported = true;\n\t\t\t\tthis.append(this.controlQueue, { type: \"overflow\", error: \"rpc_control_output_overflow, resync required\" });\n\t\t\t\tthis.markReady(this.controlQueue);\n\t\t\t\tthis.requestFlush();\n\t\t\t}\n\t\t\treturn Promise.reject(new Error(\"rpc_control_output_overflow, resync required\"));\n\t\t}\n\t\tconst queue = targetId === undefined ? this.controlQueue : this.connectionQueue(targetId);\n\t\tconst completion = new Promise<void>((resolve, reject) => {\n\t\t\tthis.append(queue, { ...value }, undefined, resolve, reject);\n\t\t});\n\t\tthis.markReady(queue);\n\t\tthis.requestFlush();\n\t\treturn completion;\n\t}\n\n\t/**\n\t * Queue one HOST-level lifecycle record for every registered connection, or the\n\t * shared stdio lane when none is registered. Unlike session records it is not tagged\n\t * with a routing handle by the writer: `host_stalled` carries the handle it blames,\n\t * and `host_memory_pressure` belongs to the process, not to a session.\n\t */\n\t/**\n\t * Tell ONE opener where it sits in the open queue, before its open reaches the loop.\n\t *\n\t * Sent to the opening connection only: a queue position is about that caller's request, not\n\t * about the host. If the connection is gone the record is dropped rather than queued - a\n\t * position is worthless to a client that already left.\n\t */\n\tsendOpenQueued(connection: string, record: RpcOpenQueuedEvent): void {\n\t\t// Reconstruct so desktop `refresh-senpi-events.ts` sees a literal `type:` site in this file.\n\t\tconst wire: RpcRecord = {\n\t\t\ttype: \"queued\",\n\t\t\tfor_request: record.for_request,\n\t\t\tposition: record.position,\n\t\t\tin_flight: record.in_flight,\n\t\t};\n\t\tconst target = this.fanout.get(connection);\n\t\tif (target === undefined) return;\n\t\ttarget.actor.enqueue(serializeJsonLine(wire));\n\t\tthis.requestFlush();\n\t}\n\n\tbroadcastHostRecord(record: RpcHostLifecycleEvent): void {\n\t\t// Reconstruct so desktop `refresh-senpi-events.ts` sees literal `type:` sites in this file.\n\t\tlet wire: RpcRecord;\n\t\tswitch (record.type) {\n\t\t\tcase \"host_superseded\":\n\t\t\t\twire = {\n\t\t\t\t\ttype: \"host_superseded\",\n\t\t\t\t\tinstanceId: record.instanceId,\n\t\t\t\t\tgeneration: record.generation,\n\t\t\t\t\tsuccessor: record.successor,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host_stalled\":\n\t\t\t\twire = {\n\t\t\t\t\ttype: \"host_stalled\",\n\t\t\t\t\tdriftMs: record.driftMs,\n\t\t\t\t\t...(record.sessionId !== undefined ? { sessionId: record.sessionId } : {}),\n\t\t\t\t\t...(record.tool !== undefined ? { tool: record.tool } : {}),\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host_memory_pressure\":\n\t\t\t\twire = { type: \"host_memory_pressure\", rssMb: record.rssMb, sessions: record.sessions };\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = record;\n\t\t\t\tthrow new Error(`unexpected host record ${exhaustive}`);\n\t\t\t}\n\t\t}\n\t\tif (this.fanout.isEmpty()) {\n\t\t\tthis.append(this.controlQueue, wire);\n\t\t\tthis.markReady(this.controlQueue);\n\t\t} else this.fanout.broadcast(serializeJsonLine(wire));\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Prevent subsequent records for a session and append its terminal response.\n\t * Existing records retain FIFO order; this response is therefore that\n\t * session's final stdout record.\n\t */\n\tcloseSession(sessionId: string, response: object, reason?: RpcSessionClosedReason, sessionPath?: string): void {\n\t\tif (this.sealedSessions.has(sessionId)) return;\n\t\tthis.sealedSessions.add(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t\tconst targetId = this.connectionContext.getStore();\n\t\t// `reason` tells an attached client WHY the handle ended, so a park it can reopen by path is\n\t\t// not read as a session that is gone. Absent unless the caller names one; clients tolerate that.\n\t\tconst lifecycle: RpcSessionClosedEvent = {\n\t\t\ttype: \"session_closed\",\n\t\t\tsessionId,\n\t\t\t...(reason && { reason }),\n\t\t\t...(sessionPath && { sessionPath }),\n\t\t};\n\t\tif (this.fanout.isEmpty()) this.appendSessionRecord(sessionId, lifecycle);\n\t\telse if (this.workerSessions.has(sessionId))\n\t\t\tthis.fanout.deliverToSession(sessionId, serializeJsonLine(lifecycle));\n\t\telse this.fanout.broadcast(serializeJsonLine(lifecycle));\n\t\tconst taggedResponse = { ...response, sessionId };\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) registered.actor.enqueue(serializeJsonLine(taggedResponse));\n\t\telse this.appendSessionRecord(sessionId, taggedResponse, targetId);\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Seal a session the host PARKED and publish `session_parked`.\n\t *\n\t * Parking is the idle sweep putting a RETAINED session back on disk: the routing\n\t * handle ends exactly as a close ends it, but the session survives and reopens with\n\t * `open_session { sessionPath }`, so the record a client dispatches on must say so\n\t * instead of claiming the session ended. Delivery follows the `session_closed` rule -\n\t * a worker session's record reaches only its attached connections, an interactive\n\t * session's reaches every connection. No client asked for this teardown, so there is\n\t * no close response to answer.\n\t */\n\tparkSession(sessionId: string, sessionPath: string): void {\n\t\tif (this.sealedSessions.has(sessionId)) return;\n\t\tthis.sealedSessions.add(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t\tconst lifecycle: RpcSessionParkedEvent = { type: \"session_parked\", sessionId, sessionPath };\n\t\tif (this.fanout.isEmpty()) this.appendSessionRecord(sessionId, lifecycle);\n\t\telse if (this.workerSessions.has(sessionId))\n\t\t\tthis.fanout.deliverToSession(sessionId, serializeJsonLine(lifecycle));\n\t\telse this.fanout.broadcast(serializeJsonLine(lifecycle));\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Admit reply debt before routing can mutate attachments or await finalization.\n\t * Reserve the lifecycle as well: the claimant's role is not known yet. Rejected\n\t * closes do not wait, retain their ids, or create per-request stderr output.\n\t */\n\treserveCloseResponse(\n\t\tsessionId: string,\n\t\tresponse: object,\n\t\trecords = 2,\n\t): { release: () => void; complete: (terminal: boolean, reason?: RpcSessionClosedReason) => void } | undefined {\n\t\tconst bytes =\n\t\t\tBuffer.byteLength(serializeJsonLine({ ...response, sessionId })) +\n\t\t\t(records === 2\n\t\t\t\t? Buffer.byteLength(serializeJsonLine({ type: \"session_closed\", sessionId, reason: \"client_close\" }))\n\t\t\t\t: 0);\n\t\tif (\n\t\t\tthis.bufferedRecordCount + this.reservedCloseRecords + records > MAX_SHARED_STDIO_QUEUE_RECORDS ||\n\t\t\tthis.bufferedByteLength + this.reservedCloseBytes + bytes > MAX_SHARED_STDIO_QUEUE_BYTES\n\t\t) {\n\t\t\tconst overflow = {\n\t\t\t\ttype: \"overflow\",\n\t\t\t\tcommand: \"close_session\",\n\t\t\t\terror: \"rpc_close_output_overflow, resync required\",\n\t\t\t};\n\t\t\tconst targetId = this.currentConnection();\n\t\t\tif (targetId !== undefined) {\n\t\t\t\tconst actor = this.fanout.get(targetId)?.actor;\n\t\t\t\tif (actor && !this.closeOverflowActors.has(actor)) {\n\t\t\t\t\tthis.closeOverflowActors.add(actor);\n\t\t\t\t\t// One outstanding notice per sink, released only on consumption.\n\t\t\t\t\t// Actor identity isolates reconnects and does not retain dead sinks.\n\t\t\t\t\tactor.enqueue(serializeJsonLine(overflow), undefined, () => this.closeOverflowActors.delete(actor));\n\t\t\t\t}\n\t\t\t} else if (!this.closeOverflowReported) {\n\t\t\t\tthis.closeOverflowReported = true;\n\t\t\t\tthis.append(this.controlQueue, overflow);\n\t\t\t\tthis.markReady(this.controlQueue);\n\t\t\t\tthis.requestFlush();\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.reservedCloseRecords += records;\n\t\tthis.reservedCloseBytes += bytes;\n\t\tlet active = true;\n\t\tconst release = () => {\n\t\t\tif (!active) return;\n\t\t\tactive = false;\n\t\t\tthis.reservedCloseRecords -= records;\n\t\t\tthis.reservedCloseBytes -= bytes;\n\t\t};\n\t\treturn {\n\t\t\trelease,\n\t\t\tcomplete: (terminal, reason) => {\n\t\t\t\tif (!active) return;\n\t\t\t\trelease();\n\t\t\t\tif (terminal) this.closeSession(sessionId, response, reason);\n\t\t\t\telse this.appendClosedResponse(sessionId, response);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Queue a joined close only after admitting its noncompactable reply. */\n\tenqueueClosedResponse(sessionId: string, response: object): void {\n\t\tthis.reserveCloseResponse(sessionId, response, 1)?.complete(false);\n\t}\n\n\tprivate appendClosedResponse(sessionId: string, response: object): void {\n\t\tconst targetId = this.connectionContext.getStore();\n\t\tconst taggedResponse = { ...response, sessionId };\n\t\tconst registered = targetId === undefined ? undefined : this.fanout.get(targetId);\n\t\tif (registered) registered.actor.enqueue(serializeJsonLine(taggedResponse));\n\t\telse this.appendSessionRecord(sessionId, taggedResponse, targetId);\n\t\tthis.requestFlush();\n\t}\n\n\t/**\n\t * Drops per-session bookkeeping for a handle whose runtime is fully disposed.\n\t * Routing handles are unique per process epoch, so nothing can legitimately\n\t * emit under this id again; without this every host-closed session would\n\t * leave a permanent sealed-handle (and snapshot) entry behind.\n\t */\n\tforgetSession(sessionId: string): void {\n\t\tthis.sealedSessions.delete(sessionId);\n\t\tthis.workerSessions.delete(sessionId);\n\t\tthis.fanout.forgetSession(sessionId);\n\t}\n\n\t/** Drain every retained lane and the current in-flight record. */\n\tflush(): Promise<void> {\n\t\tif (this.failure !== undefined) return Promise.reject(this.failure);\n\t\tthis.flushScheduled = false;\n\t\tif (this.drainPromise) return this.drainPromise;\n\t\tif (this.readyQueues.length === 0) return settleActors([...this.fanout.values()].map(({ actor }) => actor));\n\t\tlet resolveDrain!: () => void;\n\t\tlet rejectDrain!: (cause: unknown) => void;\n\t\tconst drain = new Promise<void>((resolve, reject) => {\n\t\t\tresolveDrain = resolve;\n\t\t\trejectDrain = reject;\n\t\t});\n\t\tthis.drainPromise = drain;\n\t\tvoid this.drainUntilEmpty().then(resolveDrain, rejectDrain);\n\t\tvoid drain.then(\n\t\t\t() => {\n\t\t\t\tif (this.drainPromise === drain) this.drainPromise = undefined;\n\t\t\t\tif (this.readyQueues.length > 0) this.requestFlush();\n\t\t\t},\n\t\t\t(cause) => {\n\t\t\t\tif (this.drainPromise === drain) this.drainPromise = undefined;\n\t\t\t\tthis.fail(cause);\n\t\t\t},\n\t\t);\n\t\treturn drain;\n\t}\n\n\tprivate async drainUntilEmpty(): Promise<void> {\n\t\tdo {\n\t\t\tawait this.drainReadyQueues();\n\t\t} while (this.readyQueues.length > 0);\n\t\t// Per-connection failures are handled by the fanout (cut + close); only the\n\t\t// shared stdio lane may fail this writer.\n\t\tawait settleActors([...this.fanout.values()].map(({ actor }) => actor));\n\t\tthis.controlOverflowReported = false;\n\t\tif (this.reservedCloseRecords === 0) this.closeOverflowReported = false;\n\t}\n\n\tprivate async drainReadyQueues(): Promise<void> {\n\t\twhile (this.readyQueues.length > 0) {\n\t\t\tconst queue = this.readyQueues.shift()!;\n\t\t\tqueue.ready = false;\n\t\t\tconst node = queue.head;\n\t\t\tif (!node) continue;\n\n\t\t\tthis.unlink(queue, node);\n\t\t\tthis.inFlight = { queue, node };\n\t\t\ttry {\n\t\t\t\t// D9: exactly one complete record per raw write. The next lane is not\n\t\t\t\t// selected until this record has cleared stdout backpressure.\n\t\t\t\tconst connection = queue.targetId ? this.fanout.get(queue.targetId)?.connection : undefined;\n\t\t\t\tconst writeRaw = connection?.writeRaw ?? this.writeRaw;\n\t\t\t\tconst waitForBackpressure = connection?.waitForBackpressure ?? this.waitForBackpressure;\n\t\t\t\tif (!connection && queue.targetId) {\n\t\t\t\t\tnode.resolve?.();\n\t\t\t\t} else {\n\t\t\t\t\twriteRaw(serializeJsonLine(node.value));\n\t\t\t\t\tif (waitForBackpressure) await waitForBackpressure();\n\t\t\t\t\tnode.resolve?.();\n\t\t\t\t}\n\t\t\t} catch (cause) {\n\t\t\t\tnode.reject?.(cause);\n\t\t\t\tthrow cause;\n\t\t\t} finally {\n\t\t\t\tthis.inFlight = undefined;\n\t\t\t}\n\n\t\t\tif (queue.head) {\n\t\t\t\tthis.markReady(queue);\n\t\t\t} else if (queue.sessionId || queue.targetId) {\n\t\t\t\tfor (const [key, candidate] of this.queues) {\n\t\t\t\t\tif (candidate === queue) this.queues.delete(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate exceedsStdioCapacity(line: string): boolean {\n\t\treturn (\n\t\t\tthis.bufferedRecordCount + this.reservedCloseRecords >= MAX_SHARED_STDIO_QUEUE_RECORDS ||\n\t\t\tthis.bufferedByteLength + this.reservedCloseBytes + Buffer.byteLength(line) > MAX_SHARED_STDIO_QUEUE_BYTES\n\t\t);\n\t}\n\n\tprivate connectionQueue(targetId: string): RecordQueue {\n\t\tconst key = `connection:${targetId}`;\n\t\tlet queue = this.queues.get(key);\n\t\tif (!queue) {\n\t\t\tqueue = { targetId, latestByKey: new Map(), ready: false };\n\t\t\tthis.queues.set(key, queue);\n\t\t}\n\t\treturn queue;\n\t}\n\n\tprivate appendSessionRecord(sessionId: string, value: RpcRecord, targetId?: string): void {\n\t\tconst key = `${targetId ?? \"default\"}:${sessionId}`;\n\t\tlet queue = this.queues.get(key);\n\t\tif (!queue) {\n\t\t\tqueue = { sessionId, targetId, latestByKey: new Map(), ready: false };\n\t\t\tthis.queues.set(key, queue);\n\t\t}\n\n\t\tconst delta = compactDelta(value);\n\t\tif (delta) {\n\t\t\tconst previousFull = queue.latestByKey.get(MESSAGE_KEY);\n\t\t\tif (previousFull) this.demoteAndMerge(queue, previousFull);\n\t\t\tconst node = this.append(queue, value, MESSAGE_KEY);\n\t\t\tqueue.latestByKey.set(MESSAGE_KEY, node);\n\t\t\tthis.markReady(queue);\n\t\t\treturn;\n\t\t}\n\n\t\tconst toolKey = toolUpdateKey(value);\n\t\tif (toolKey) {\n\t\t\tconst previous = queue.latestByKey.get(toolKey);\n\t\t\tif (previous) this.unlink(queue, previous);\n\t\t\tconst node = this.append(queue, value, toolKey);\n\t\t\tqueue.latestByKey.set(toolKey, node);\n\t\t\tthis.markReady(queue);\n\t\t\treturn;\n\t\t}\n\n\t\t// All non-compactable records are ordering barriers. In particular this\n\t\t// includes delta-only/full non-delta message updates, protocol responses,\n\t\t// extension UI requests, errors, retries, lifecycle, and unknown records.\n\t\tqueue.latestByKey.clear();\n\t\tthis.append(queue, value);\n\t\tthis.markReady(queue);\n\t}\n\n\tprivate demoteAndMerge(queue: RecordQueue, node: QueueNode): void {\n\t\tnode.value = demoteToDeltaOnly(node.value);\n\t\tconst current = compactDelta(node.value);\n\t\tconst preceding = node.previous;\n\t\tconst previous = preceding ? compactDelta(preceding.value) : undefined;\n\t\tif (\n\t\t\tpreceding &&\n\t\t\tprevious &&\n\t\t\tcurrent &&\n\t\t\tpreceding.value.message === null &&\n\t\t\tprevious.type === current.type &&\n\t\t\tprevious.contentIndex === current.contentIndex\n\t\t) {\n\t\t\tconst precedingEvent = preceding.value.assistantMessageEvent as Record<string, unknown>;\n\t\t\tpreceding.value = {\n\t\t\t\t...preceding.value,\n\t\t\t\tassistantMessageEvent: { ...precedingEvent, delta: previous.delta + current.delta },\n\t\t\t};\n\t\t\tthis.unlink(queue, node);\n\t\t}\n\t}\n\n\tprivate append(\n\t\tqueue: RecordQueue,\n\t\tvalue: RpcRecord,\n\t\tkey?: string,\n\t\tresolve?: () => void,\n\t\treject?: (cause: unknown) => void,\n\t): QueueNode {\n\t\tconst node: QueueNode = { value, key, previous: queue.tail, resolve, reject };\n\t\tif (queue.tail) queue.tail.next = node;\n\t\telse queue.head = node;\n\t\tqueue.tail = node;\n\t\treturn node;\n\t}\n\n\tprivate unlink(queue: RecordQueue, node: QueueNode): void {\n\t\tif (node.previous) node.previous.next = node.next;\n\t\telse queue.head = node.next;\n\t\tif (node.next) node.next.previous = node.previous;\n\t\telse queue.tail = node.previous;\n\t\tif (node.key && queue.latestByKey.get(node.key) === node) queue.latestByKey.delete(node.key);\n\t\tnode.previous = undefined;\n\t\tnode.next = undefined;\n\t}\n\n\tprivate markReady(queue: RecordQueue): void {\n\t\tif (queue.ready || this.inFlight?.queue === queue || !queue.head) return;\n\t\tqueue.ready = true;\n\t\tthis.readyQueues.push(queue);\n\t}\n\n\tprivate requestFlush(): void {\n\t\tif (this.failure !== undefined || this.flushScheduled || this.drainPromise) return;\n\t\tthis.flushScheduled = true;\n\t\tthis.scheduleFlush(() => this.flush());\n\t}\n\n\tprivate fail(cause: unknown): void {\n\t\tif (this.failure !== undefined) return;\n\t\tthis.failure = cause;\n\t\tfor (const queue of this.allQueues()) {\n\t\t\tfor (let node = queue.head; node; node = node.next) node.reject?.(cause);\n\t\t}\n\t}\n\n\tprivate *allQueues(): Iterable<RecordQueue> {\n\t\tyield* this.queues.values();\n\t\tyield this.controlQueue;\n\t}\n}\n"]}
@@ -7,6 +7,11 @@ import type { SessionWorkerClient } from "./session-worker-client.ts";
7
7
  /** The immutable flags selected when a routing session is opened. */
8
8
  export interface RpcSessionLaunchProfile extends AgentSessionLaunchProfile {
9
9
  sessionPath?: string;
10
+ /**
11
+ * Durable session id chosen by the caller, applied ONLY when this open creates the session.
12
+ * An existing session file keeps the id in its header, so a resume never rewrites identity.
13
+ */
14
+ durableSessionId?: string;
10
15
  }
11
16
  export type SessionRuntime = AgentSessionRuntime;
12
17
  export type RpcSessionState = "opening" | "open" | "closing" | "quarantined" | "closed";
@@ -49,7 +54,7 @@ export interface RpcSessionEntry {
49
54
  closeStarted?: boolean;
50
55
  }
51
56
  export declare class RpcSessionRegistryError extends Error {
52
- readonly code: "unknown_session" | "session_closing" | "session_path_in_use" | "session_reservation_limit" | "invalid_path" | "host_memory_pressure" | "open_failed";
57
+ readonly code: "unknown_session" | "session_closing" | "session_path_in_use" | "session_id_in_use" | "session_reservation_limit" | "invalid_path" | "invalid_session_id" | "host_memory_pressure" | "open_failed";
53
58
  /** Machine-readable context for the wire (`errorData`): who holds a path, when to retry. */
54
59
  readonly detail?: Readonly<Record<string, unknown>>;
55
60
  constructor(code: RpcSessionRegistryError["code"], reason?: string, detail?: Readonly<Record<string, unknown>>);
@@ -1 +1 @@
1
- {"version":3,"file":"session-registry.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAwB,MAAM,2CAA2C,CAAC;AAChG,OAAO,EACN,KAAK,yBAAyB,EAC9B,mBAAmB,EACnB,KAAK,gCAAgC,EAErC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAqB,MAAM,gCAAgC,CAAC;AAGrG,OAAO,EAA+B,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEnG,OAAO,KAAK,EAAE,mBAA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C,OAAO,EAAE,sBAAsB,GAAG,SAAS,GAAG,IAAI,CAEpE;IAEK,WAAW,CAAC,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2L5G;IAED;;;;;;;;;;;OAWG;YACW,wBAAwB;IAkBtC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAEhD;IAED,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAc9D;IAED;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,eAAe,CAEjH;IAEK,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzC;IAED,iEAAiE;IAC3D,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;IAED,IAAI,IAAI,aAAa,EAAE,CActB;IAED,qEAAqE;IACrE,OAAO,CAAC,mBAAmB;IAqC3B,OAAO,CAAC,eAAe;CAYvB"}
@@ -3,7 +3,7 @@ import { basename, dirname, isAbsolute, resolve } from "node:path";
3
3
  import { ProviderScope, runWithProviderScope } from "@earendil-works/pi-ai/node/provider-scope";
4
4
  import { AgentSessionRuntime, createAgentSessionRuntime, } from "../../core/agent-session-runtime.js";
5
5
  import { EMPTY_SESSION_CONTEXT } from "../../core/extensions/types.js";
6
- import { SessionManager } from "../../core/session-manager.js";
6
+ import { assertValidSessionId, SessionManager } from "../../core/session-manager.js";
7
7
  import { SESSION_PATH_RETRY_AFTER_MS } from "./host-reservations.js";
8
8
  import { beginSessionClose, closeMarkedSession, closeSession } from "./session-teardown.js";
9
9
  export class RpcSessionRegistryError extends Error {
@@ -80,6 +80,23 @@ export class RpcSessionRegistry {
80
80
  this.validateProfile(profile);
81
81
  this.syncRuntimeMetadata();
82
82
  const sessionPath = profile.sessionPath ? canonicalPath(profile.sessionPath) : undefined;
83
+ // Taken SYNCHRONOUSLY, before any await, exactly like the path reservation below: a
84
+ // concurrent open naming the same durable id must find this one already recorded rather
85
+ // than a window between the decision and the record of it. Two LIVE sessions may never
86
+ // share a durable id - every per-session artifact a client keys by it would collide.
87
+ // Re-opening the SAME file is an attach/resume, not a collision: the id is the file's own.
88
+ const requestedDurableId = profile.durableSessionId;
89
+ if (requestedDurableId !== undefined) {
90
+ for (const entry of this.entries.values()) {
91
+ if (entry.state === "closed")
92
+ continue;
93
+ if (entry.durableSessionId !== requestedDurableId)
94
+ continue;
95
+ if (sessionPath !== undefined && entry.reservationKey === sessionPath)
96
+ continue;
97
+ throw new RpcSessionRegistryError("session_id_in_use");
98
+ }
99
+ }
83
100
  if (sessionPath)
84
101
  await this.settleClosingReservation(sessionPath);
85
102
  if (sessionPath && this.reservations.has(sessionPath)) {
@@ -191,11 +208,17 @@ export class RpcSessionRegistry {
191
208
  entry.lifecycleMutex = operation.then(() => undefined, () => undefined);
192
209
  return operation;
193
210
  };
211
+ // Recorded before the first await so the synchronous collision guard above sees an open
212
+ // that is still being built. `manager.getSessionId()` overwrites it below with the
213
+ // authoritative value, which on a resume is the header's id, not the requested one.
214
+ if (requestedDurableId !== undefined)
215
+ entry.durableSessionId = requestedDurableId;
194
216
  this.entries.set(handle, entry);
195
217
  try {
218
+ const newSessionOptions = requestedDurableId !== undefined ? { id: requestedDurableId } : undefined;
196
219
  const manager = sessionPath
197
- ? SessionManager.open(sessionPath, undefined, storedProfile.cwd)
198
- : SessionManager.create(storedProfile.cwd);
220
+ ? SessionManager.open(sessionPath, undefined, storedProfile.cwd, newSessionOptions)
221
+ : SessionManager.create(storedProfile.cwd, undefined, newSessionOptions);
199
222
  entry.runtime = await runWithProviderScope(entry.scope, () => createAgentSessionRuntime(this.options.createRuntime, {
200
223
  cwd: manager.getCwd(),
201
224
  agentDir: this.options.agentDir,
@@ -362,6 +385,14 @@ export class RpcSessionRegistry {
362
385
  if (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath))) {
363
386
  throw new RpcSessionRegistryError("invalid_path");
364
387
  }
388
+ if (profile.durableSessionId !== undefined) {
389
+ try {
390
+ assertValidSessionId(profile.durableSessionId);
391
+ }
392
+ catch (cause) {
393
+ throw new RpcSessionRegistryError("invalid_session_id", String(cause));
394
+ }
395
+ }
365
396
  }
366
397
  }
367
398
  //# sourceMappingURL=session-registry.js.map