@tickernelz/paperclip-pro-adapter-utils 2026.925.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1826) hide show
  1. package/README.md +37 -0
  2. package/dist/acpx-engine/cli.d.ts +2 -0
  3. package/dist/acpx-engine/cli.d.ts.map +1 -0
  4. package/dist/acpx-engine/cli.js +128 -0
  5. package/dist/acpx-engine/cli.js.map +1 -0
  6. package/dist/acpx-engine/composed-run-characterization.test.d.ts +2 -0
  7. package/dist/acpx-engine/composed-run-characterization.test.d.ts.map +1 -0
  8. package/dist/acpx-engine/composed-run-characterization.test.js +739 -0
  9. package/dist/acpx-engine/composed-run-characterization.test.js.map +1 -0
  10. package/dist/acpx-engine/constants.d.ts +20 -0
  11. package/dist/acpx-engine/constants.d.ts.map +1 -0
  12. package/dist/acpx-engine/constants.js +37 -0
  13. package/dist/acpx-engine/constants.js.map +1 -0
  14. package/dist/acpx-engine/execute-identity.test.d.ts +2 -0
  15. package/dist/acpx-engine/execute-identity.test.d.ts.map +1 -0
  16. package/dist/acpx-engine/execute-identity.test.js +218 -0
  17. package/dist/acpx-engine/execute-identity.test.js.map +1 -0
  18. package/dist/acpx-engine/execute.d.ts +325 -0
  19. package/dist/acpx-engine/execute.d.ts.map +1 -0
  20. package/dist/acpx-engine/execute.js +4448 -0
  21. package/dist/acpx-engine/execute.js.map +1 -0
  22. package/dist/acpx-engine/execute.test.d.ts +2 -0
  23. package/dist/acpx-engine/execute.test.d.ts.map +1 -0
  24. package/dist/acpx-engine/execute.test.js +6694 -0
  25. package/dist/acpx-engine/execute.test.js.map +1 -0
  26. package/dist/acpx-engine/index.d.ts +6 -0
  27. package/dist/acpx-engine/index.d.ts.map +1 -0
  28. package/dist/acpx-engine/index.js +6 -0
  29. package/dist/acpx-engine/index.js.map +1 -0
  30. package/dist/acpx-engine/local-process-control.d.ts +5 -0
  31. package/dist/acpx-engine/local-process-control.d.ts.map +1 -0
  32. package/dist/acpx-engine/local-process-control.js +39 -0
  33. package/dist/acpx-engine/local-process-control.js.map +1 -0
  34. package/dist/acpx-engine/local-process-control.test.d.ts +2 -0
  35. package/dist/acpx-engine/local-process-control.test.d.ts.map +1 -0
  36. package/dist/acpx-engine/local-process-control.test.js +38 -0
  37. package/dist/acpx-engine/local-process-control.test.js.map +1 -0
  38. package/dist/acpx-engine/operator-stop.test.d.ts +2 -0
  39. package/dist/acpx-engine/operator-stop.test.d.ts.map +1 -0
  40. package/dist/acpx-engine/operator-stop.test.js +107 -0
  41. package/dist/acpx-engine/operator-stop.test.js.map +1 -0
  42. package/dist/acpx-engine/remote-spawn-smoke.test.d.ts +2 -0
  43. package/dist/acpx-engine/remote-spawn-smoke.test.d.ts.map +1 -0
  44. package/dist/acpx-engine/remote-spawn-smoke.test.js +151 -0
  45. package/dist/acpx-engine/remote-spawn-smoke.test.js.map +1 -0
  46. package/dist/acpx-engine/run-contracts.d.ts +413 -0
  47. package/dist/acpx-engine/run-contracts.d.ts.map +1 -0
  48. package/dist/acpx-engine/run-contracts.js +20 -0
  49. package/dist/acpx-engine/run-contracts.js.map +1 -0
  50. package/dist/acpx-engine/run-contracts.test.d.ts +2 -0
  51. package/dist/acpx-engine/run-contracts.test.d.ts.map +1 -0
  52. package/dist/acpx-engine/run-contracts.test.js +57 -0
  53. package/dist/acpx-engine/run-contracts.test.js.map +1 -0
  54. package/dist/acpx-engine/run-coordinator.d.ts +57 -0
  55. package/dist/acpx-engine/run-coordinator.d.ts.map +1 -0
  56. package/dist/acpx-engine/run-coordinator.js +63 -0
  57. package/dist/acpx-engine/run-coordinator.js.map +1 -0
  58. package/dist/acpx-engine/run-coordinator.test.d.ts +2 -0
  59. package/dist/acpx-engine/run-coordinator.test.d.ts.map +1 -0
  60. package/dist/acpx-engine/run-coordinator.test.js +160 -0
  61. package/dist/acpx-engine/run-coordinator.test.js.map +1 -0
  62. package/dist/acpx-engine/run-fault-matrix.test.d.ts +2 -0
  63. package/dist/acpx-engine/run-fault-matrix.test.d.ts.map +1 -0
  64. package/dist/acpx-engine/run-fault-matrix.test.js +829 -0
  65. package/dist/acpx-engine/run-fault-matrix.test.js.map +1 -0
  66. package/dist/acpx-engine/run-resource-ledger.d.ts +30 -0
  67. package/dist/acpx-engine/run-resource-ledger.d.ts.map +1 -0
  68. package/dist/acpx-engine/run-resource-ledger.js +148 -0
  69. package/dist/acpx-engine/run-resource-ledger.js.map +1 -0
  70. package/dist/acpx-engine/run-resource-ledger.test.d.ts +2 -0
  71. package/dist/acpx-engine/run-resource-ledger.test.d.ts.map +1 -0
  72. package/dist/acpx-engine/run-resource-ledger.test.js +154 -0
  73. package/dist/acpx-engine/run-resource-ledger.test.js.map +1 -0
  74. package/dist/acpx-engine/run-site-host.d.ts +73 -0
  75. package/dist/acpx-engine/run-site-host.d.ts.map +1 -0
  76. package/dist/acpx-engine/run-site-host.js +65 -0
  77. package/dist/acpx-engine/run-site-host.js.map +1 -0
  78. package/dist/acpx-engine/run-site-host.test.d.ts +2 -0
  79. package/dist/acpx-engine/run-site-host.test.d.ts.map +1 -0
  80. package/dist/acpx-engine/run-site-host.test.js +98 -0
  81. package/dist/acpx-engine/run-site-host.test.js.map +1 -0
  82. package/dist/acpx-engine/run-site-sandbox.d.ts +142 -0
  83. package/dist/acpx-engine/run-site-sandbox.d.ts.map +1 -0
  84. package/dist/acpx-engine/run-site-sandbox.js +278 -0
  85. package/dist/acpx-engine/run-site-sandbox.js.map +1 -0
  86. package/dist/acpx-engine/run-site-sandbox.test.d.ts +2 -0
  87. package/dist/acpx-engine/run-site-sandbox.test.d.ts.map +1 -0
  88. package/dist/acpx-engine/run-site-sandbox.test.js +275 -0
  89. package/dist/acpx-engine/run-site-sandbox.test.js.map +1 -0
  90. package/dist/acpx-engine/session-codec.d.ts +3 -0
  91. package/dist/acpx-engine/session-codec.d.ts.map +1 -0
  92. package/dist/acpx-engine/session-codec.js +49 -0
  93. package/dist/acpx-engine/session-codec.js.map +1 -0
  94. package/dist/acpx-engine/session-reuse-store.d.ts +62 -0
  95. package/dist/acpx-engine/session-reuse-store.d.ts.map +1 -0
  96. package/dist/acpx-engine/session-reuse-store.js +134 -0
  97. package/dist/acpx-engine/session-reuse-store.js.map +1 -0
  98. package/dist/acpx-engine/session-reuse-store.test.d.ts +2 -0
  99. package/dist/acpx-engine/session-reuse-store.test.d.ts.map +1 -0
  100. package/dist/acpx-engine/session-reuse-store.test.js +134 -0
  101. package/dist/acpx-engine/session-reuse-store.test.js.map +1 -0
  102. package/dist/acpx-engine/settlement-characterization.test.d.ts +2 -0
  103. package/dist/acpx-engine/settlement-characterization.test.d.ts.map +1 -0
  104. package/dist/acpx-engine/settlement-characterization.test.js +880 -0
  105. package/dist/acpx-engine/settlement-characterization.test.js.map +1 -0
  106. package/dist/acpx-engine/settlement-sequence.d.ts +77 -0
  107. package/dist/acpx-engine/settlement-sequence.d.ts.map +1 -0
  108. package/dist/acpx-engine/settlement-sequence.js +119 -0
  109. package/dist/acpx-engine/settlement-sequence.js.map +1 -0
  110. package/dist/acpx-engine/settlement-sequence.test.d.ts +2 -0
  111. package/dist/acpx-engine/settlement-sequence.test.d.ts.map +1 -0
  112. package/dist/acpx-engine/settlement-sequence.test.js +272 -0
  113. package/dist/acpx-engine/settlement-sequence.test.js.map +1 -0
  114. package/dist/acpx-engine/spawn-smoke.test.d.ts +2 -0
  115. package/dist/acpx-engine/spawn-smoke.test.d.ts.map +1 -0
  116. package/dist/acpx-engine/spawn-smoke.test.js +184 -0
  117. package/dist/acpx-engine/spawn-smoke.test.js.map +1 -0
  118. package/dist/acpx-engine/startup-cancellation.d.ts +8 -0
  119. package/dist/acpx-engine/startup-cancellation.d.ts.map +1 -0
  120. package/dist/acpx-engine/startup-cancellation.js +92 -0
  121. package/dist/acpx-engine/startup-cancellation.js.map +1 -0
  122. package/dist/acpx-engine/startup-cancellation.test.d.ts +2 -0
  123. package/dist/acpx-engine/startup-cancellation.test.d.ts.map +1 -0
  124. package/dist/acpx-engine/startup-cancellation.test.js +115 -0
  125. package/dist/acpx-engine/startup-cancellation.test.js.map +1 -0
  126. package/dist/acpx-engine/startup-characterization.test.d.ts +2 -0
  127. package/dist/acpx-engine/startup-characterization.test.d.ts.map +1 -0
  128. package/dist/acpx-engine/startup-characterization.test.js +742 -0
  129. package/dist/acpx-engine/startup-characterization.test.js.map +1 -0
  130. package/dist/acpx-engine/startup-timing.d.ts +419 -0
  131. package/dist/acpx-engine/startup-timing.d.ts.map +1 -0
  132. package/dist/acpx-engine/startup-timing.js +616 -0
  133. package/dist/acpx-engine/startup-timing.js.map +1 -0
  134. package/dist/acpx-engine/startup-timing.test.d.ts +2 -0
  135. package/dist/acpx-engine/startup-timing.test.d.ts.map +1 -0
  136. package/dist/acpx-engine/startup-timing.test.js +619 -0
  137. package/dist/acpx-engine/startup-timing.test.js.map +1 -0
  138. package/dist/acpx-engine/turn-characterization.test.d.ts +2 -0
  139. package/dist/acpx-engine/turn-characterization.test.d.ts.map +1 -0
  140. package/dist/acpx-engine/turn-characterization.test.js +566 -0
  141. package/dist/acpx-engine/turn-characterization.test.js.map +1 -0
  142. package/dist/acpx-engine/turn-sequence.d.ts +54 -0
  143. package/dist/acpx-engine/turn-sequence.d.ts.map +1 -0
  144. package/dist/acpx-engine/turn-sequence.js +75 -0
  145. package/dist/acpx-engine/turn-sequence.js.map +1 -0
  146. package/dist/acpx-engine/turn-sequence.test.d.ts +2 -0
  147. package/dist/acpx-engine/turn-sequence.test.d.ts.map +1 -0
  148. package/dist/acpx-engine/turn-sequence.test.js +177 -0
  149. package/dist/acpx-engine/turn-sequence.test.js.map +1 -0
  150. package/dist/acpx-engine/ui.d.ts +3 -0
  151. package/dist/acpx-engine/ui.d.ts.map +1 -0
  152. package/dist/acpx-engine/ui.js +162 -0
  153. package/dist/acpx-engine/ui.js.map +1 -0
  154. package/dist/billing.d.ts +2 -0
  155. package/dist/billing.d.ts.map +1 -0
  156. package/dist/billing.js +16 -0
  157. package/dist/billing.js.map +1 -0
  158. package/dist/billing.test.d.ts +2 -0
  159. package/dist/billing.test.d.ts.map +1 -0
  160. package/dist/billing.test.js +14 -0
  161. package/dist/billing.test.js.map +1 -0
  162. package/dist/bridge-transport-contract.d.ts +43 -0
  163. package/dist/bridge-transport-contract.d.ts.map +1 -0
  164. package/dist/bridge-transport-contract.js +33 -0
  165. package/dist/bridge-transport-contract.js.map +1 -0
  166. package/dist/chat-file-delivery.d.ts +10 -0
  167. package/dist/chat-file-delivery.d.ts.map +1 -0
  168. package/dist/chat-file-delivery.js +38 -0
  169. package/dist/chat-file-delivery.js.map +1 -0
  170. package/dist/chat-file-delivery.test.d.ts +2 -0
  171. package/dist/chat-file-delivery.test.d.ts.map +1 -0
  172. package/dist/chat-file-delivery.test.js +92 -0
  173. package/dist/chat-file-delivery.test.js.map +1 -0
  174. package/dist/command-managed-runtime.d.ts +162 -0
  175. package/dist/command-managed-runtime.d.ts.map +1 -0
  176. package/dist/command-managed-runtime.js +456 -0
  177. package/dist/command-managed-runtime.js.map +1 -0
  178. package/dist/command-managed-runtime.test.d.ts +2 -0
  179. package/dist/command-managed-runtime.test.d.ts.map +1 -0
  180. package/dist/command-managed-runtime.test.js +908 -0
  181. package/dist/command-managed-runtime.test.js.map +1 -0
  182. package/dist/command-redaction.d.ts +15 -0
  183. package/dist/command-redaction.d.ts.map +1 -0
  184. package/dist/command-redaction.js +97 -0
  185. package/dist/command-redaction.js.map +1 -0
  186. package/dist/command-redaction.test.d.ts +2 -0
  187. package/dist/command-redaction.test.d.ts.map +1 -0
  188. package/dist/command-redaction.test.js +80 -0
  189. package/dist/command-redaction.test.js.map +1 -0
  190. package/dist/duplex-frame-codec.d.ts +124 -0
  191. package/dist/duplex-frame-codec.d.ts.map +1 -0
  192. package/dist/duplex-frame-codec.js +134 -0
  193. package/dist/duplex-frame-codec.js.map +1 -0
  194. package/dist/duplex-frame-codec.test.d.ts +2 -0
  195. package/dist/duplex-frame-codec.test.d.ts.map +1 -0
  196. package/dist/duplex-frame-codec.test.js +172 -0
  197. package/dist/duplex-frame-codec.test.js.map +1 -0
  198. package/dist/duplex-observability.d.ts +220 -0
  199. package/dist/duplex-observability.d.ts.map +1 -0
  200. package/dist/duplex-observability.js +248 -0
  201. package/dist/duplex-observability.js.map +1 -0
  202. package/dist/duplex-observability.test.d.ts +2 -0
  203. package/dist/duplex-observability.test.d.ts.map +1 -0
  204. package/dist/duplex-observability.test.js +55 -0
  205. package/dist/duplex-observability.test.js.map +1 -0
  206. package/dist/env-bindings.d.ts +17 -0
  207. package/dist/env-bindings.d.ts.map +1 -0
  208. package/dist/env-bindings.js +98 -0
  209. package/dist/env-bindings.js.map +1 -0
  210. package/dist/env-bindings.test.d.ts +2 -0
  211. package/dist/env-bindings.test.d.ts.map +1 -0
  212. package/dist/env-bindings.test.js +66 -0
  213. package/dist/env-bindings.test.js.map +1 -0
  214. package/dist/exclude-patterns.d.ts +4 -0
  215. package/dist/exclude-patterns.d.ts.map +1 -0
  216. package/dist/exclude-patterns.js +26 -0
  217. package/dist/exclude-patterns.js.map +1 -0
  218. package/dist/execution-target-sandbox.test.d.ts +2 -0
  219. package/dist/execution-target-sandbox.test.d.ts.map +1 -0
  220. package/dist/execution-target-sandbox.test.js +6522 -0
  221. package/dist/execution-target-sandbox.test.js.map +1 -0
  222. package/dist/execution-target-stdin-race.test.d.ts +2 -0
  223. package/dist/execution-target-stdin-race.test.d.ts.map +1 -0
  224. package/dist/execution-target-stdin-race.test.js +1842 -0
  225. package/dist/execution-target-stdin-race.test.js.map +1 -0
  226. package/dist/execution-target.d.ts +537 -0
  227. package/dist/execution-target.d.ts.map +1 -0
  228. package/dist/execution-target.js +3877 -0
  229. package/dist/execution-target.js.map +1 -0
  230. package/dist/execution-target.test.d.ts +2 -0
  231. package/dist/execution-target.test.d.ts.map +1 -0
  232. package/dist/execution-target.test.js +346 -0
  233. package/dist/execution-target.test.js.map +1 -0
  234. package/dist/git-workspace-sync.d.ts +193 -0
  235. package/dist/git-workspace-sync.d.ts.map +1 -0
  236. package/dist/git-workspace-sync.js +786 -0
  237. package/dist/git-workspace-sync.js.map +1 -0
  238. package/dist/git-workspace-sync.test.d.ts +2 -0
  239. package/dist/git-workspace-sync.test.d.ts.map +1 -0
  240. package/dist/git-workspace-sync.test.js +830 -0
  241. package/dist/git-workspace-sync.test.js.map +1 -0
  242. package/dist/github-launcher-environment.test.d.ts +2 -0
  243. package/dist/github-launcher-environment.test.d.ts.map +1 -0
  244. package/dist/github-launcher-environment.test.js +285 -0
  245. package/dist/github-launcher-environment.test.js.map +1 -0
  246. package/dist/github-launcher.d.ts +8 -0
  247. package/dist/github-launcher.d.ts.map +1 -0
  248. package/dist/github-launcher.js +127 -0
  249. package/dist/github-launcher.js.map +1 -0
  250. package/dist/github-launcher.test.d.ts +2 -0
  251. package/dist/github-launcher.test.d.ts.map +1 -0
  252. package/dist/github-launcher.test.js +166 -0
  253. package/dist/github-launcher.test.js.map +1 -0
  254. package/dist/http2-bridge-server.d.ts +465 -0
  255. package/dist/http2-bridge-server.d.ts.map +1 -0
  256. package/dist/http2-bridge-server.js +1087 -0
  257. package/dist/http2-bridge-server.js.map +1 -0
  258. package/dist/http2-bridge-server.test.d.ts +2 -0
  259. package/dist/http2-bridge-server.test.d.ts.map +1 -0
  260. package/dist/http2-bridge-server.test.js +2129 -0
  261. package/dist/http2-bridge-server.test.js.map +1 -0
  262. package/dist/index.d.ts +20 -0
  263. package/dist/index.d.ts.map +1 -0
  264. package/dist/index.js +12 -0
  265. package/dist/index.js.map +1 -0
  266. package/dist/local-process-sandbox.d.ts +41 -0
  267. package/dist/local-process-sandbox.d.ts.map +1 -0
  268. package/dist/local-process-sandbox.js +432 -0
  269. package/dist/local-process-sandbox.js.map +1 -0
  270. package/dist/local-process-sandbox.test.d.ts +2 -0
  271. package/dist/local-process-sandbox.test.d.ts.map +1 -0
  272. package/dist/local-process-sandbox.test.js +399 -0
  273. package/dist/local-process-sandbox.test.js.map +1 -0
  274. package/dist/log-redaction.d.ts +9 -0
  275. package/dist/log-redaction.d.ts.map +1 -0
  276. package/dist/log-redaction.js +88 -0
  277. package/dist/log-redaction.js.map +1 -0
  278. package/dist/login-capability.d.ts +88 -0
  279. package/dist/login-capability.d.ts.map +1 -0
  280. package/dist/login-capability.js +78 -0
  281. package/dist/login-capability.js.map +1 -0
  282. package/dist/login-capability.test.d.ts +2 -0
  283. package/dist/login-capability.test.d.ts.map +1 -0
  284. package/dist/login-capability.test.js +78 -0
  285. package/dist/login-capability.test.js.map +1 -0
  286. package/dist/login-pty-transport.d.ts +80 -0
  287. package/dist/login-pty-transport.d.ts.map +1 -0
  288. package/dist/login-pty-transport.js +75 -0
  289. package/dist/login-pty-transport.js.map +1 -0
  290. package/dist/login-pty-transport.test.d.ts +2 -0
  291. package/dist/login-pty-transport.test.d.ts.map +1 -0
  292. package/dist/login-pty-transport.test.js +185 -0
  293. package/dist/login-pty-transport.test.js.map +1 -0
  294. package/dist/login-runner-lifecycle.d.ts +70 -0
  295. package/dist/login-runner-lifecycle.d.ts.map +1 -0
  296. package/dist/login-runner-lifecycle.js +52 -0
  297. package/dist/login-runner-lifecycle.js.map +1 -0
  298. package/dist/login-runner-lifecycle.test.d.ts +2 -0
  299. package/dist/login-runner-lifecycle.test.d.ts.map +1 -0
  300. package/dist/login-runner-lifecycle.test.js +122 -0
  301. package/dist/login-runner-lifecycle.test.js.map +1 -0
  302. package/dist/mcp-isolation.integration.test.d.ts +2 -0
  303. package/dist/mcp-isolation.integration.test.d.ts.map +1 -0
  304. package/dist/mcp-isolation.integration.test.js +202 -0
  305. package/dist/mcp-isolation.integration.test.js.map +1 -0
  306. package/dist/paperclip-runner-permissions.d.ts +110 -0
  307. package/dist/paperclip-runner-permissions.d.ts.map +1 -0
  308. package/dist/paperclip-runner-permissions.js +150 -0
  309. package/dist/paperclip-runner-permissions.js.map +1 -0
  310. package/dist/paperclip-runner-permissions.test.d.ts +2 -0
  311. package/dist/paperclip-runner-permissions.test.d.ts.map +1 -0
  312. package/dist/paperclip-runner-permissions.test.js +47 -0
  313. package/dist/paperclip-runner-permissions.test.js.map +1 -0
  314. package/dist/published-exports.test.d.ts +2 -0
  315. package/dist/published-exports.test.d.ts.map +1 -0
  316. package/dist/published-exports.test.js +17 -0
  317. package/dist/published-exports.test.js.map +1 -0
  318. package/dist/remote-execution-env.d.ts +2 -0
  319. package/dist/remote-execution-env.d.ts.map +1 -0
  320. package/dist/remote-execution-env.js +46 -0
  321. package/dist/remote-execution-env.js.map +1 -0
  322. package/dist/remote-managed-runtime.d.ts +45 -0
  323. package/dist/remote-managed-runtime.d.ts.map +1 -0
  324. package/dist/remote-managed-runtime.js +183 -0
  325. package/dist/remote-managed-runtime.js.map +1 -0
  326. package/dist/remote-managed-runtime.test.d.ts +2 -0
  327. package/dist/remote-managed-runtime.test.d.ts.map +1 -0
  328. package/dist/remote-managed-runtime.test.js +294 -0
  329. package/dist/remote-managed-runtime.test.js.map +1 -0
  330. package/dist/runner-connectivity.d.ts +61 -0
  331. package/dist/runner-connectivity.d.ts.map +1 -0
  332. package/dist/runner-connectivity.js +81 -0
  333. package/dist/runner-connectivity.js.map +1 -0
  334. package/dist/runner-connectivity.test.d.ts +2 -0
  335. package/dist/runner-connectivity.test.d.ts.map +1 -0
  336. package/dist/runner-connectivity.test.js +183 -0
  337. package/dist/runner-connectivity.test.js.map +1 -0
  338. package/dist/runtime-progress.d.ts +48 -0
  339. package/dist/runtime-progress.d.ts.map +1 -0
  340. package/dist/runtime-progress.js +99 -0
  341. package/dist/runtime-progress.js.map +1 -0
  342. package/dist/runtime-progress.test.d.ts +2 -0
  343. package/dist/runtime-progress.test.d.ts.map +1 -0
  344. package/dist/runtime-progress.test.js +240 -0
  345. package/dist/runtime-progress.test.js.map +1 -0
  346. package/dist/sandbox-callback-bridge-body.d.ts +12 -0
  347. package/dist/sandbox-callback-bridge-body.d.ts.map +1 -0
  348. package/dist/sandbox-callback-bridge-body.js +39 -0
  349. package/dist/sandbox-callback-bridge-body.js.map +1 -0
  350. package/dist/sandbox-callback-bridge-body.test.d.ts +2 -0
  351. package/dist/sandbox-callback-bridge-body.test.d.ts.map +1 -0
  352. package/dist/sandbox-callback-bridge-body.test.js +31 -0
  353. package/dist/sandbox-callback-bridge-body.test.js.map +1 -0
  354. package/dist/sandbox-callback-bridge.d.ts +268 -0
  355. package/dist/sandbox-callback-bridge.d.ts.map +1 -0
  356. package/dist/sandbox-callback-bridge.js +2357 -0
  357. package/dist/sandbox-callback-bridge.js.map +1 -0
  358. package/dist/sandbox-callback-bridge.test.d.ts +2 -0
  359. package/dist/sandbox-callback-bridge.test.d.ts.map +1 -0
  360. package/dist/sandbox-callback-bridge.test.js +3253 -0
  361. package/dist/sandbox-callback-bridge.test.js.map +1 -0
  362. package/dist/sandbox-file-sync.test.d.ts +2 -0
  363. package/dist/sandbox-file-sync.test.d.ts.map +1 -0
  364. package/dist/sandbox-file-sync.test.js +419 -0
  365. package/dist/sandbox-file-sync.test.js.map +1 -0
  366. package/dist/sandbox-install-command.d.ts +2 -0
  367. package/dist/sandbox-install-command.d.ts.map +1 -0
  368. package/dist/sandbox-install-command.js +47 -0
  369. package/dist/sandbox-install-command.js.map +1 -0
  370. package/dist/sandbox-install-command.test.d.ts +2 -0
  371. package/dist/sandbox-install-command.test.d.ts.map +1 -0
  372. package/dist/sandbox-install-command.test.js +22 -0
  373. package/dist/sandbox-install-command.test.js.map +1 -0
  374. package/dist/sandbox-managed-runtime.d.ts +417 -0
  375. package/dist/sandbox-managed-runtime.d.ts.map +1 -0
  376. package/dist/sandbox-managed-runtime.js +1337 -0
  377. package/dist/sandbox-managed-runtime.js.map +1 -0
  378. package/dist/sandbox-managed-runtime.test.d.ts +2 -0
  379. package/dist/sandbox-managed-runtime.test.d.ts.map +1 -0
  380. package/dist/sandbox-managed-runtime.test.js +3746 -0
  381. package/dist/sandbox-managed-runtime.test.js.map +1 -0
  382. package/dist/sandbox-run-log-stream.d.ts +44 -0
  383. package/dist/sandbox-run-log-stream.d.ts.map +1 -0
  384. package/dist/sandbox-run-log-stream.js +203 -0
  385. package/dist/sandbox-run-log-stream.js.map +1 -0
  386. package/dist/sandbox-shell.d.ts +3 -0
  387. package/dist/sandbox-shell.d.ts.map +1 -0
  388. package/dist/sandbox-shell.js +7 -0
  389. package/dist/sandbox-shell.js.map +1 -0
  390. package/dist/server-utils-env.test.d.ts +2 -0
  391. package/dist/server-utils-env.test.d.ts.map +1 -0
  392. package/dist/server-utils-env.test.js +15 -0
  393. package/dist/server-utils-env.test.js.map +1 -0
  394. package/dist/server-utils.d.ts +617 -0
  395. package/dist/server-utils.d.ts.map +1 -0
  396. package/dist/server-utils.js +3258 -0
  397. package/dist/server-utils.js.map +1 -0
  398. package/dist/server-utils.test.d.ts +2 -0
  399. package/dist/server-utils.test.d.ts.map +1 -0
  400. package/dist/server-utils.test.js +3047 -0
  401. package/dist/server-utils.test.js.map +1 -0
  402. package/dist/session-compaction.d.ts +25 -0
  403. package/dist/session-compaction.d.ts.map +1 -0
  404. package/dist/session-compaction.js +165 -0
  405. package/dist/session-compaction.js.map +1 -0
  406. package/dist/skill-library-manifest.d.ts +6 -0
  407. package/dist/skill-library-manifest.d.ts.map +1 -0
  408. package/dist/skill-library-manifest.js +53 -0
  409. package/dist/skill-library-manifest.js.map +1 -0
  410. package/dist/skill-library-manifest.test.d.ts +2 -0
  411. package/dist/skill-library-manifest.test.d.ts.map +1 -0
  412. package/dist/skill-library-manifest.test.js +84 -0
  413. package/dist/skill-library-manifest.test.js.map +1 -0
  414. package/dist/skills-staging-follow-symlinks.test.d.ts +2 -0
  415. package/dist/skills-staging-follow-symlinks.test.d.ts.map +1 -0
  416. package/dist/skills-staging-follow-symlinks.test.js +126 -0
  417. package/dist/skills-staging-follow-symlinks.test.js.map +1 -0
  418. package/dist/ssh-fixture.test.d.ts +2 -0
  419. package/dist/ssh-fixture.test.d.ts.map +1 -0
  420. package/dist/ssh-fixture.test.js +832 -0
  421. package/dist/ssh-fixture.test.js.map +1 -0
  422. package/dist/ssh.d.ts +124 -0
  423. package/dist/ssh.d.ts.map +1 -0
  424. package/dist/ssh.js +1667 -0
  425. package/dist/ssh.js.map +1 -0
  426. package/dist/sync-operation-schedule.d.ts +17 -0
  427. package/dist/sync-operation-schedule.d.ts.map +1 -0
  428. package/dist/sync-operation-schedule.js +66 -0
  429. package/dist/sync-operation-schedule.js.map +1 -0
  430. package/dist/sync-operation-schedule.test.d.ts +2 -0
  431. package/dist/sync-operation-schedule.test.d.ts.map +1 -0
  432. package/dist/sync-operation-schedule.test.js +130 -0
  433. package/dist/sync-operation-schedule.test.js.map +1 -0
  434. package/dist/test-support/mcp-isolation-harness.d.ts +23 -0
  435. package/dist/test-support/mcp-isolation-harness.d.ts.map +1 -0
  436. package/dist/test-support/mcp-isolation-harness.js +67 -0
  437. package/dist/test-support/mcp-isolation-harness.js.map +1 -0
  438. package/dist/types.d.ts +780 -0
  439. package/dist/types.d.ts.map +1 -0
  440. package/dist/types.js +5 -0
  441. package/dist/types.js.map +1 -0
  442. package/dist/workspace-restore-merge.d.ts +77 -0
  443. package/dist/workspace-restore-merge.d.ts.map +1 -0
  444. package/dist/workspace-restore-merge.js +396 -0
  445. package/dist/workspace-restore-merge.js.map +1 -0
  446. package/dist/workspace-restore-merge.test.d.ts +2 -0
  447. package/dist/workspace-restore-merge.test.d.ts.map +1 -0
  448. package/dist/workspace-restore-merge.test.js +438 -0
  449. package/dist/workspace-restore-merge.test.js.map +1 -0
  450. package/dist/workspace-restore-teardown.d.ts +29 -0
  451. package/dist/workspace-restore-teardown.d.ts.map +1 -0
  452. package/dist/workspace-restore-teardown.js +34 -0
  453. package/dist/workspace-restore-teardown.js.map +1 -0
  454. package/dist/workspace-restore-teardown.test.d.ts +2 -0
  455. package/dist/workspace-restore-teardown.test.d.ts.map +1 -0
  456. package/dist/workspace-restore-teardown.test.js +71 -0
  457. package/dist/workspace-restore-teardown.test.js.map +1 -0
  458. package/node_modules/@agentclientprotocol/sdk/LICENSE +191 -0
  459. package/node_modules/@agentclientprotocol/sdk/README.md +70 -0
  460. package/node_modules/@agentclientprotocol/sdk/dist/acp.d.ts +1803 -0
  461. package/node_modules/@agentclientprotocol/sdk/dist/acp.js +1869 -0
  462. package/node_modules/@agentclientprotocol/sdk/dist/acp.js.map +1 -0
  463. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.d.ts +1 -0
  464. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.js +5036 -0
  465. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.js.map +1 -0
  466. package/node_modules/@agentclientprotocol/sdk/dist/connection.d.ts +89 -0
  467. package/node_modules/@agentclientprotocol/sdk/dist/connection.js +490 -0
  468. package/node_modules/@agentclientprotocol/sdk/dist/connection.js.map +1 -0
  469. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.d.ts +1 -0
  470. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.js +507 -0
  471. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.js.map +1 -0
  472. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.d.ts +26 -0
  473. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.js +96 -0
  474. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.js.map +1 -0
  475. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.d.ts +1 -0
  476. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.js +77 -0
  477. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.js.map +1 -0
  478. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.d.ts +2 -0
  479. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.js +232 -0
  480. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.js.map +1 -0
  481. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.d.ts +2 -0
  482. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.js +132 -0
  483. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.js.map +1 -0
  484. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.d.ts +9 -0
  485. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.js +221 -0
  486. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.js.map +1 -0
  487. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.d.ts +2 -0
  488. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.js +86 -0
  489. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.js.map +1 -0
  490. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.d.ts +2 -0
  491. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.js +112 -0
  492. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.js.map +1 -0
  493. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.d.ts +2 -0
  494. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.js +88 -0
  495. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.js.map +1 -0
  496. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.d.ts +33 -0
  497. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.js +435 -0
  498. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.js.map +1 -0
  499. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.d.ts +1 -0
  500. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.js +1380 -0
  501. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.js.map +1 -0
  502. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.d.ts +603 -0
  503. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.js +1076 -0
  504. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.js.map +1 -0
  505. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.d.ts +1 -0
  506. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.js +917 -0
  507. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.js.map +1 -0
  508. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.d.ts +22 -0
  509. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.js +64 -0
  510. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.js.map +1 -0
  511. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.d.ts +1 -0
  512. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.js +45 -0
  513. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.js.map +1 -0
  514. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.d.ts +17 -0
  515. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.js +426 -0
  516. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.js.map +1 -0
  517. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.d.ts +1 -0
  518. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.js +499 -0
  519. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.js.map +1 -0
  520. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.d.ts +37 -0
  521. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.js +474 -0
  522. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.js.map +1 -0
  523. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.d.ts +1 -0
  524. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.js +535 -0
  525. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.js.map +1 -0
  526. package/node_modules/@agentclientprotocol/sdk/dist/protocol.d.ts +11 -0
  527. package/node_modules/@agentclientprotocol/sdk/dist/protocol.js +69 -0
  528. package/node_modules/@agentclientprotocol/sdk/dist/protocol.js.map +1 -0
  529. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.d.ts +1 -0
  530. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.js +82 -0
  531. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.js.map +1 -0
  532. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.d.ts +183 -0
  533. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js +207 -0
  534. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js.map +1 -0
  535. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.d.ts +51 -0
  536. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.js +52 -0
  537. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.js.map +1 -0
  538. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.d.ts +6219 -0
  539. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.js +3 -0
  540. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.js.map +1 -0
  541. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.d.ts +15215 -0
  542. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js +3084 -0
  543. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js.map +1 -0
  544. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.d.ts +30 -0
  545. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.js +98 -0
  546. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.js.map +1 -0
  547. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.d.ts +1 -0
  548. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.js +93 -0
  549. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.js.map +1 -0
  550. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.d.ts +1 -0
  551. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.js +261 -0
  552. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.js.map +1 -0
  553. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.d.ts +1 -0
  554. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.js +536 -0
  555. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.js.map +1 -0
  556. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.d.ts +2 -0
  557. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.js +88 -0
  558. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.js.map +1 -0
  559. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.d.ts +1 -0
  560. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.js +53 -0
  561. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.js.map +1 -0
  562. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.d.ts +1 -0
  563. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.js +992 -0
  564. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.js.map +1 -0
  565. package/node_modules/@agentclientprotocol/sdk/dist/server.d.ts +81 -0
  566. package/node_modules/@agentclientprotocol/sdk/dist/server.js +386 -0
  567. package/node_modules/@agentclientprotocol/sdk/dist/server.js.map +1 -0
  568. package/node_modules/@agentclientprotocol/sdk/dist/server.test.d.ts +1 -0
  569. package/node_modules/@agentclientprotocol/sdk/dist/server.test.js +1116 -0
  570. package/node_modules/@agentclientprotocol/sdk/dist/server.test.js.map +1 -0
  571. package/node_modules/@agentclientprotocol/sdk/dist/sse.d.ts +4 -0
  572. package/node_modules/@agentclientprotocol/sdk/dist/sse.js +91 -0
  573. package/node_modules/@agentclientprotocol/sdk/dist/sse.js.map +1 -0
  574. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.d.ts +1 -0
  575. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.js +126 -0
  576. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.js.map +1 -0
  577. package/node_modules/@agentclientprotocol/sdk/dist/stream.d.ts +35 -0
  578. package/node_modules/@agentclientprotocol/sdk/dist/stream.js +115 -0
  579. package/node_modules/@agentclientprotocol/sdk/dist/stream.js.map +1 -0
  580. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.d.ts +1 -0
  581. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.js +195 -0
  582. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.js.map +1 -0
  583. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.d.ts +8 -0
  584. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.js +51 -0
  585. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.js.map +1 -0
  586. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.d.ts +24 -0
  587. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.js +163 -0
  588. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.js.map +1 -0
  589. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.d.ts +9 -0
  590. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.js +74 -0
  591. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.js.map +1 -0
  592. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.d.ts +957 -0
  593. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.js +1484 -0
  594. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.js.map +1 -0
  595. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.d.ts +1 -0
  596. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.js +1287 -0
  597. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.js.map +1 -0
  598. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.d.ts +946 -0
  599. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.js +1046 -0
  600. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.js.map +1 -0
  601. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.d.ts +42 -0
  602. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.js +43 -0
  603. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.js.map +1 -0
  604. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.d.ts +6208 -0
  605. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.js +3 -0
  606. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.js.map +1 -0
  607. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.d.ts +33267 -0
  608. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.js +3199 -0
  609. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.js.map +1 -0
  610. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.d.ts +14 -0
  611. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.js +357 -0
  612. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.js.map +1 -0
  613. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.d.ts +54 -0
  614. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.js +253 -0
  615. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.js.map +1 -0
  616. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.d.ts +1 -0
  617. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.js +836 -0
  618. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.js.map +1 -0
  619. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.d.ts +13 -0
  620. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.js +78 -0
  621. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.js.map +1 -0
  622. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.d.ts +1 -0
  623. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.js +42 -0
  624. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.js.map +1 -0
  625. package/node_modules/@agentclientprotocol/sdk/package.json +104 -0
  626. package/node_modules/@agentclientprotocol/sdk/schema/schema.json +8967 -0
  627. package/node_modules/@agentclientprotocol/sdk/schema/v2/schema.unstable.json +10242 -0
  628. package/node_modules/@clack/core/LICENSE +9 -0
  629. package/node_modules/@clack/core/README.md +22 -0
  630. package/node_modules/@clack/core/dist/index.d.mts +503 -0
  631. package/node_modules/@clack/core/dist/index.mjs +1003 -0
  632. package/node_modules/@clack/core/package.json +63 -0
  633. package/node_modules/@clack/prompts/LICENSE +9 -0
  634. package/node_modules/@clack/prompts/README.md +396 -0
  635. package/node_modules/@clack/prompts/dist/index.d.mts +949 -0
  636. package/node_modules/@clack/prompts/dist/index.mjs +1423 -0
  637. package/node_modules/@clack/prompts/package.json +67 -0
  638. package/node_modules/@esbuild/linux-x64/README.md +3 -0
  639. package/node_modules/@esbuild/linux-x64/bin/esbuild +0 -0
  640. package/node_modules/@esbuild/linux-x64/package.json +20 -0
  641. package/node_modules/acpx/LICENSE +21 -0
  642. package/node_modules/acpx/README.md +424 -0
  643. package/node_modules/acpx/dist/cli-CxsS1XQp.js +197 -0
  644. package/node_modules/acpx/dist/cli-CxsS1XQp.js.map +1 -0
  645. package/node_modules/acpx/dist/cli.d.ts +14 -0
  646. package/node_modules/acpx/dist/cli.d.ts.map +1 -0
  647. package/node_modules/acpx/dist/cli.js +2683 -0
  648. package/node_modules/acpx/dist/cli.js.map +1 -0
  649. package/node_modules/acpx/dist/client-DwNyFauq.d.ts +192 -0
  650. package/node_modules/acpx/dist/client-DwNyFauq.d.ts.map +1 -0
  651. package/node_modules/acpx/dist/flags-Bjq_XQ4-.js +260 -0
  652. package/node_modules/acpx/dist/flags-Bjq_XQ4-.js.map +1 -0
  653. package/node_modules/acpx/dist/flows-Db_LZKu9.js +1920 -0
  654. package/node_modules/acpx/dist/flows-Db_LZKu9.js.map +1 -0
  655. package/node_modules/acpx/dist/flows.d.ts +318 -0
  656. package/node_modules/acpx/dist/flows.d.ts.map +1 -0
  657. package/node_modules/acpx/dist/flows.js +2 -0
  658. package/node_modules/acpx/dist/live-checkpoint-ClPCSdrW.js +6210 -0
  659. package/node_modules/acpx/dist/live-checkpoint-ClPCSdrW.js.map +1 -0
  660. package/node_modules/acpx/dist/output-CjdF5rHk.js +4593 -0
  661. package/node_modules/acpx/dist/output-CjdF5rHk.js.map +1 -0
  662. package/node_modules/acpx/dist/runtime.d.ts +472 -0
  663. package/node_modules/acpx/dist/runtime.d.ts.map +1 -0
  664. package/node_modules/acpx/dist/runtime.js +1711 -0
  665. package/node_modules/acpx/dist/runtime.js.map +1 -0
  666. package/node_modules/acpx/dist/session-options-jkYbBxGE.d.ts +278 -0
  667. package/node_modules/acpx/dist/session-options-jkYbBxGE.d.ts.map +1 -0
  668. package/node_modules/acpx/package.json +129 -0
  669. package/node_modules/acpx/skills/acpx/SKILL.md +617 -0
  670. package/node_modules/b4a/LICENSE +201 -0
  671. package/node_modules/b4a/README.md +153 -0
  672. package/node_modules/b4a/browser.js +546 -0
  673. package/node_modules/b4a/index.d.ts +144 -0
  674. package/node_modules/b4a/index.js +193 -0
  675. package/node_modules/b4a/lib/ascii.js +31 -0
  676. package/node_modules/b4a/lib/base64.js +64 -0
  677. package/node_modules/b4a/lib/hex.js +51 -0
  678. package/node_modules/b4a/lib/latin1.js +31 -0
  679. package/node_modules/b4a/lib/utf16le.js +40 -0
  680. package/node_modules/b4a/lib/utf8.js +144 -0
  681. package/node_modules/b4a/package.json +54 -0
  682. package/node_modules/b4a/react-native.js +5 -0
  683. package/node_modules/b4a/runtime.d.ts +14 -0
  684. package/node_modules/bare-events/LICENSE +201 -0
  685. package/node_modules/bare-events/README.md +25 -0
  686. package/node_modules/bare-events/global.d.ts +15 -0
  687. package/node_modules/bare-events/global.js +5 -0
  688. package/node_modules/bare-events/index.d.ts +89 -0
  689. package/node_modules/bare-events/index.js +397 -0
  690. package/node_modules/bare-events/lib/errors.js +23 -0
  691. package/node_modules/bare-events/package.json +63 -0
  692. package/node_modules/bare-events/web.d.ts +79 -0
  693. package/node_modules/bare-events/web.js +417 -0
  694. package/node_modules/bare-fs/CMakeLists.txt +13 -0
  695. package/node_modules/bare-fs/LICENSE +201 -0
  696. package/node_modules/bare-fs/README.md +33 -0
  697. package/node_modules/bare-fs/binding.c +2913 -0
  698. package/node_modules/bare-fs/binding.js +1 -0
  699. package/node_modules/bare-fs/index.d.ts +1502 -0
  700. package/node_modules/bare-fs/index.js +2855 -0
  701. package/node_modules/bare-fs/lib/constants.d.ts +50 -0
  702. package/node_modules/bare-fs/lib/constants.js +49 -0
  703. package/node_modules/bare-fs/lib/errors.d.ts +13 -0
  704. package/node_modules/bare-fs/lib/errors.js +55 -0
  705. package/node_modules/bare-fs/package.json +74 -0
  706. package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  707. package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  708. package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  709. package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  710. package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  711. package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  712. package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
  713. package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  714. package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  715. package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  716. package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  717. package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
  718. package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
  719. package/node_modules/bare-fs/promises.d.ts +480 -0
  720. package/node_modules/bare-fs/promises.js +119 -0
  721. package/node_modules/bare-path/CMakeLists.txt +13 -0
  722. package/node_modules/bare-path/LICENSE +201 -0
  723. package/node_modules/bare-path/NOTICE +28 -0
  724. package/node_modules/bare-path/README.md +19 -0
  725. package/node_modules/bare-path/binding.c +106 -0
  726. package/node_modules/bare-path/binding.js +1 -0
  727. package/node_modules/bare-path/index.d.ts +27 -0
  728. package/node_modules/bare-path/index.js +9 -0
  729. package/node_modules/bare-path/lib/constants.js +11 -0
  730. package/node_modules/bare-path/lib/posix.js +263 -0
  731. package/node_modules/bare-path/lib/shared.js +81 -0
  732. package/node_modules/bare-path/lib/win32.js +564 -0
  733. package/node_modules/bare-path/package.json +47 -0
  734. package/node_modules/bare-path/prebuilds/android-arm/bare-path.bare +0 -0
  735. package/node_modules/bare-path/prebuilds/android-arm64/bare-path.bare +0 -0
  736. package/node_modules/bare-path/prebuilds/android-ia32/bare-path.bare +0 -0
  737. package/node_modules/bare-path/prebuilds/android-x64/bare-path.bare +0 -0
  738. package/node_modules/bare-path/prebuilds/darwin-arm64/bare-path.bare +0 -0
  739. package/node_modules/bare-path/prebuilds/darwin-x64/bare-path.bare +0 -0
  740. package/node_modules/bare-path/prebuilds/ios-arm64/bare-path.bare +0 -0
  741. package/node_modules/bare-path/prebuilds/ios-arm64-simulator/bare-path.bare +0 -0
  742. package/node_modules/bare-path/prebuilds/ios-x64-simulator/bare-path.bare +0 -0
  743. package/node_modules/bare-path/prebuilds/linux-arm64/bare-path.bare +0 -0
  744. package/node_modules/bare-path/prebuilds/linux-x64/bare-path.bare +0 -0
  745. package/node_modules/bare-path/prebuilds/win32-arm64/bare-path.bare +0 -0
  746. package/node_modules/bare-path/prebuilds/win32-x64/bare-path.bare +0 -0
  747. package/node_modules/bare-stream/LICENSE +201 -0
  748. package/node_modules/bare-stream/README.md +354 -0
  749. package/node_modules/bare-stream/global.d.ts +31 -0
  750. package/node_modules/bare-stream/global.js +15 -0
  751. package/node_modules/bare-stream/index.d.ts +235 -0
  752. package/node_modules/bare-stream/index.js +493 -0
  753. package/node_modules/bare-stream/package.json +75 -0
  754. package/node_modules/bare-stream/promises.js +3 -0
  755. package/node_modules/bare-stream/web.d.ts +152 -0
  756. package/node_modules/bare-stream/web.js +607 -0
  757. package/node_modules/bare-url/CMakeLists.txt +36 -0
  758. package/node_modules/bare-url/LICENSE +201 -0
  759. package/node_modules/bare-url/README.md +33 -0
  760. package/node_modules/bare-url/binding.c +422 -0
  761. package/node_modules/bare-url/binding.js +1 -0
  762. package/node_modules/bare-url/global.d.ts +24 -0
  763. package/node_modules/bare-url/global.js +2 -0
  764. package/node_modules/bare-url/index.d.ts +96 -0
  765. package/node_modules/bare-url/index.js +676 -0
  766. package/node_modules/bare-url/lib/errors.d.ts +10 -0
  767. package/node_modules/bare-url/lib/errors.js +33 -0
  768. package/node_modules/bare-url/lib/url-search-params.d.ts +66 -0
  769. package/node_modules/bare-url/lib/url-search-params.js +276 -0
  770. package/node_modules/bare-url/package.json +54 -0
  771. package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
  772. package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
  773. package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
  774. package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
  775. package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
  776. package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
  777. package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
  778. package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
  779. package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
  780. package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
  781. package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
  782. package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
  783. package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
  784. package/node_modules/commander/LICENSE +22 -0
  785. package/node_modules/commander/Readme.md +1172 -0
  786. package/node_modules/commander/index.js +21 -0
  787. package/node_modules/commander/lib/argument.js +147 -0
  788. package/node_modules/commander/lib/command.js +2790 -0
  789. package/node_modules/commander/lib/error.js +36 -0
  790. package/node_modules/commander/lib/help.js +731 -0
  791. package/node_modules/commander/lib/option.js +377 -0
  792. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  793. package/node_modules/commander/package-support.json +19 -0
  794. package/node_modules/commander/package.json +64 -0
  795. package/node_modules/commander/typings/index.d.ts +1113 -0
  796. package/node_modules/esbuild/LICENSE.md +21 -0
  797. package/node_modules/esbuild/README.md +3 -0
  798. package/node_modules/esbuild/bin/esbuild +223 -0
  799. package/node_modules/esbuild/install.js +300 -0
  800. package/node_modules/esbuild/lib/main.d.ts +720 -0
  801. package/node_modules/esbuild/lib/main.js +2536 -0
  802. package/node_modules/esbuild/package.json +74 -0
  803. package/node_modules/events-universal/LICENSE +201 -0
  804. package/node_modules/events-universal/README.md +17 -0
  805. package/node_modules/events-universal/bare.js +1 -0
  806. package/node_modules/events-universal/default.js +1 -0
  807. package/node_modules/events-universal/index.js +1 -0
  808. package/node_modules/events-universal/package.json +39 -0
  809. package/node_modules/events-universal/react-native.js +1 -0
  810. package/node_modules/fast-fifo/LICENSE +21 -0
  811. package/node_modules/fast-fifo/README.md +78 -0
  812. package/node_modules/fast-fifo/fixed-size.js +39 -0
  813. package/node_modules/fast-fifo/index.js +48 -0
  814. package/node_modules/fast-fifo/package.json +28 -0
  815. package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  816. package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  817. package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  818. package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  819. package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  820. package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  821. package/node_modules/fast-string-truncated-width/license +21 -0
  822. package/node_modules/fast-string-truncated-width/package.json +35 -0
  823. package/node_modules/fast-string-truncated-width/readme.md +59 -0
  824. package/node_modules/fast-string-width/dist/index.d.ts +4 -0
  825. package/node_modules/fast-string-width/dist/index.js +14 -0
  826. package/node_modules/fast-string-width/license +21 -0
  827. package/node_modules/fast-string-width/package.json +34 -0
  828. package/node_modules/fast-string-width/readme.md +42 -0
  829. package/node_modules/fast-wrap-ansi/LICENSE +23 -0
  830. package/node_modules/fast-wrap-ansi/README.md +26 -0
  831. package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  832. package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
  833. package/node_modules/fast-wrap-ansi/package.json +51 -0
  834. package/node_modules/sisteransi/license +21 -0
  835. package/node_modules/sisteransi/package.json +34 -0
  836. package/node_modules/sisteransi/readme.md +113 -0
  837. package/node_modules/sisteransi/src/index.js +58 -0
  838. package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  839. package/node_modules/skillflag/LICENSE +21 -0
  840. package/node_modules/skillflag/README.md +44 -0
  841. package/node_modules/skillflag/dist/bin/skill-install.d.ts +3 -0
  842. package/node_modules/skillflag/dist/bin/skill-install.d.ts.map +1 -0
  843. package/node_modules/skillflag/dist/bin/skill-install.js +6 -0
  844. package/node_modules/skillflag/dist/bin/skill-install.js.map +1 -0
  845. package/node_modules/skillflag/dist/bin/skillflag.d.ts +3 -0
  846. package/node_modules/skillflag/dist/bin/skillflag.d.ts.map +1 -0
  847. package/node_modules/skillflag/dist/bin/skillflag.js +25 -0
  848. package/node_modules/skillflag/dist/bin/skillflag.js.map +1 -0
  849. package/node_modules/skillflag/dist/core/digest.d.ts +2 -0
  850. package/node_modules/skillflag/dist/core/digest.d.ts.map +1 -0
  851. package/node_modules/skillflag/dist/core/digest.js +15 -0
  852. package/node_modules/skillflag/dist/core/digest.js.map +1 -0
  853. package/node_modules/skillflag/dist/core/errors.d.ts +6 -0
  854. package/node_modules/skillflag/dist/core/errors.d.ts.map +1 -0
  855. package/node_modules/skillflag/dist/core/errors.js +13 -0
  856. package/node_modules/skillflag/dist/core/errors.js.map +1 -0
  857. package/node_modules/skillflag/dist/core/export.d.ts +2 -0
  858. package/node_modules/skillflag/dist/core/export.d.ts.map +1 -0
  859. package/node_modules/skillflag/dist/core/export.js +28 -0
  860. package/node_modules/skillflag/dist/core/export.js.map +1 -0
  861. package/node_modules/skillflag/dist/core/list.d.ts +21 -0
  862. package/node_modules/skillflag/dist/core/list.d.ts.map +1 -0
  863. package/node_modules/skillflag/dist/core/list.js +71 -0
  864. package/node_modules/skillflag/dist/core/list.js.map +1 -0
  865. package/node_modules/skillflag/dist/core/paths.d.ts +15 -0
  866. package/node_modules/skillflag/dist/core/paths.d.ts.map +1 -0
  867. package/node_modules/skillflag/dist/core/paths.js +149 -0
  868. package/node_modules/skillflag/dist/core/paths.js.map +1 -0
  869. package/node_modules/skillflag/dist/core/show.d.ts +2 -0
  870. package/node_modules/skillflag/dist/core/show.d.ts.map +1 -0
  871. package/node_modules/skillflag/dist/core/show.js +8 -0
  872. package/node_modules/skillflag/dist/core/show.js.map +1 -0
  873. package/node_modules/skillflag/dist/core/skillflag.d.ts +3 -0
  874. package/node_modules/skillflag/dist/core/skillflag.d.ts.map +1 -0
  875. package/node_modules/skillflag/dist/core/skillflag.js +2 -0
  876. package/node_modules/skillflag/dist/core/skillflag.js.map +1 -0
  877. package/node_modules/skillflag/dist/core/tar.d.ts +16 -0
  878. package/node_modules/skillflag/dist/core/tar.d.ts.map +1 -0
  879. package/node_modules/skillflag/dist/core/tar.js +140 -0
  880. package/node_modules/skillflag/dist/core/tar.js.map +1 -0
  881. package/node_modules/skillflag/dist/index.d.ts +5 -0
  882. package/node_modules/skillflag/dist/index.d.ts.map +1 -0
  883. package/node_modules/skillflag/dist/index.js +3 -0
  884. package/node_modules/skillflag/dist/index.js.map +1 -0
  885. package/node_modules/skillflag/dist/install/cli.d.ts +57 -0
  886. package/node_modules/skillflag/dist/install/cli.d.ts.map +1 -0
  887. package/node_modules/skillflag/dist/install/cli.js +653 -0
  888. package/node_modules/skillflag/dist/install/cli.js.map +1 -0
  889. package/node_modules/skillflag/dist/install/copy.d.ts +2 -0
  890. package/node_modules/skillflag/dist/install/copy.d.ts.map +1 -0
  891. package/node_modules/skillflag/dist/install/copy.js +19 -0
  892. package/node_modules/skillflag/dist/install/copy.js.map +1 -0
  893. package/node_modules/skillflag/dist/install/errors.d.ts +6 -0
  894. package/node_modules/skillflag/dist/install/errors.d.ts.map +1 -0
  895. package/node_modules/skillflag/dist/install/errors.js +13 -0
  896. package/node_modules/skillflag/dist/install/errors.js.map +1 -0
  897. package/node_modules/skillflag/dist/install/extract.d.ts +3 -0
  898. package/node_modules/skillflag/dist/install/extract.d.ts.map +1 -0
  899. package/node_modules/skillflag/dist/install/extract.js +76 -0
  900. package/node_modules/skillflag/dist/install/extract.js.map +1 -0
  901. package/node_modules/skillflag/dist/install/install.d.ts +21 -0
  902. package/node_modules/skillflag/dist/install/install.d.ts.map +1 -0
  903. package/node_modules/skillflag/dist/install/install.js +35 -0
  904. package/node_modules/skillflag/dist/install/install.js.map +1 -0
  905. package/node_modules/skillflag/dist/install/resolve.d.ts +12 -0
  906. package/node_modules/skillflag/dist/install/resolve.d.ts.map +1 -0
  907. package/node_modules/skillflag/dist/install/resolve.js +119 -0
  908. package/node_modules/skillflag/dist/install/resolve.js.map +1 -0
  909. package/node_modules/skillflag/dist/install/validate.d.ts +7 -0
  910. package/node_modules/skillflag/dist/install/validate.d.ts.map +1 -0
  911. package/node_modules/skillflag/dist/install/validate.js +28 -0
  912. package/node_modules/skillflag/dist/install/validate.js.map +1 -0
  913. package/node_modules/skillflag/dist/shared/frontmatter.d.ts +2 -0
  914. package/node_modules/skillflag/dist/shared/frontmatter.d.ts.map +1 -0
  915. package/node_modules/skillflag/dist/shared/frontmatter.js +28 -0
  916. package/node_modules/skillflag/dist/shared/frontmatter.js.map +1 -0
  917. package/node_modules/skillflag/dist/skillflag.d.ts +29 -0
  918. package/node_modules/skillflag/dist/skillflag.d.ts.map +1 -0
  919. package/node_modules/skillflag/dist/skillflag.js +230 -0
  920. package/node_modules/skillflag/dist/skillflag.js.map +1 -0
  921. package/node_modules/skillflag/dist/utils/collections.d.ts +3 -0
  922. package/node_modules/skillflag/dist/utils/collections.d.ts.map +1 -0
  923. package/node_modules/skillflag/dist/utils/collections.js +18 -0
  924. package/node_modules/skillflag/dist/utils/collections.js.map +1 -0
  925. package/node_modules/skillflag/package.json +78 -0
  926. package/node_modules/skillflag/skills/skillflag/SKILL.md +144 -0
  927. package/node_modules/streamx/LICENSE +21 -0
  928. package/node_modules/streamx/README.md +550 -0
  929. package/node_modules/streamx/index.d.ts +198 -0
  930. package/node_modules/streamx/index.js +1314 -0
  931. package/node_modules/streamx/lib/errors.d.ts +13 -0
  932. package/node_modules/streamx/lib/errors.js +47 -0
  933. package/node_modules/streamx/package.json +51 -0
  934. package/node_modules/streamx/runtime.d.ts +55 -0
  935. package/node_modules/tar-stream/LICENSE +21 -0
  936. package/node_modules/tar-stream/README.md +183 -0
  937. package/node_modules/tar-stream/constants.js +14 -0
  938. package/node_modules/tar-stream/extract.js +418 -0
  939. package/node_modules/tar-stream/headers.js +322 -0
  940. package/node_modules/tar-stream/index.d.ts +60 -0
  941. package/node_modules/tar-stream/index.js +2 -0
  942. package/node_modules/tar-stream/pack.js +287 -0
  943. package/node_modules/tar-stream/package.json +50 -0
  944. package/node_modules/teex/LICENSE +21 -0
  945. package/node_modules/teex/README.md +31 -0
  946. package/node_modules/teex/example.js +16 -0
  947. package/node_modules/teex/index.js +52 -0
  948. package/node_modules/teex/package.json +26 -0
  949. package/node_modules/teex/test.js +68 -0
  950. package/node_modules/text-decoder/LICENSE +201 -0
  951. package/node_modules/text-decoder/README.md +36 -0
  952. package/node_modules/text-decoder/index.js +64 -0
  953. package/node_modules/text-decoder/lib/pass-through-decoder.js +19 -0
  954. package/node_modules/text-decoder/lib/utf8-decoder.js +185 -0
  955. package/node_modules/text-decoder/package.json +39 -0
  956. package/node_modules/tsx/LICENSE +21 -0
  957. package/node_modules/tsx/README.md +32 -0
  958. package/node_modules/tsx/dist/cjs/api/index.cjs +2 -0
  959. package/node_modules/tsx/dist/cjs/api/index.d.cts +35 -0
  960. package/node_modules/tsx/dist/cjs/api/index.d.mts +35 -0
  961. package/node_modules/tsx/dist/cjs/api/index.mjs +2 -0
  962. package/node_modules/tsx/dist/cjs/index.cjs +1 -0
  963. package/node_modules/tsx/dist/cli.mjs +55 -0
  964. package/node_modules/tsx/dist/client-XItNFmsq.cjs +1 -0
  965. package/node_modules/tsx/dist/esm/api/index.cjs +2 -0
  966. package/node_modules/tsx/dist/esm/api/index.d.cts +37 -0
  967. package/node_modules/tsx/dist/esm/api/index.d.mts +37 -0
  968. package/node_modules/tsx/dist/esm/api/index.mjs +2 -0
  969. package/node_modules/tsx/dist/esm/index.mjs +2 -0
  970. package/node_modules/tsx/dist/index-Bqjv9TxC.mjs +1 -0
  971. package/node_modules/tsx/dist/index-DE3OBZuV.mjs +14 -0
  972. package/node_modules/tsx/dist/lexer-CGfpMDSb.cjs +3 -0
  973. package/node_modules/tsx/dist/lexer-CanA6ArK.mjs +3 -0
  974. package/node_modules/tsx/dist/loader.mjs +2 -0
  975. package/node_modules/tsx/dist/package-Dj0mHsMt.mjs +1 -0
  976. package/node_modules/tsx/dist/patch-repl.cjs +1 -0
  977. package/node_modules/tsx/dist/preflight.cjs +1 -0
  978. package/node_modules/tsx/dist/register-B1c7OH6V.cjs +23 -0
  979. package/node_modules/tsx/dist/register-nyXW-TH3.mjs +2 -0
  980. package/node_modules/tsx/dist/repl.mjs +4 -0
  981. package/node_modules/tsx/dist/require-CBjy4Foe.mjs +10 -0
  982. package/node_modules/tsx/dist/require-CVaYn9z3.cjs +1 -0
  983. package/node_modules/tsx/dist/suppress-warnings.cjs +1 -0
  984. package/node_modules/tsx/dist/temporary-directory-Du7LpLp9.mjs +1 -0
  985. package/node_modules/tsx/package.json +70 -0
  986. package/node_modules/zod/LICENSE +21 -0
  987. package/node_modules/zod/README.md +218 -0
  988. package/node_modules/zod/compile.cjs +96 -0
  989. package/node_modules/zod/compile.d.cts +1 -0
  990. package/node_modules/zod/compile.d.ts +1 -0
  991. package/node_modules/zod/compile.js +52 -0
  992. package/node_modules/zod/index.cjs +52 -0
  993. package/node_modules/zod/index.d.cts +3 -0
  994. package/node_modules/zod/index.d.ts +3 -0
  995. package/node_modules/zod/index.js +7 -0
  996. package/node_modules/zod/locales/index.cjs +36 -0
  997. package/node_modules/zod/locales/index.d.cts +1 -0
  998. package/node_modules/zod/locales/index.d.ts +1 -0
  999. package/node_modules/zod/locales/index.js +1 -0
  1000. package/node_modules/zod/locales/package.json +7 -0
  1001. package/node_modules/zod/mini/index.cjs +51 -0
  1002. package/node_modules/zod/mini/index.d.cts +3 -0
  1003. package/node_modules/zod/mini/index.d.ts +3 -0
  1004. package/node_modules/zod/mini/index.js +3 -0
  1005. package/node_modules/zod/mini/package.json +7 -0
  1006. package/node_modules/zod/package.json +147 -0
  1007. package/node_modules/zod/src/compile.ts +56 -0
  1008. package/node_modules/zod/src/index.ts +7 -0
  1009. package/node_modules/zod/src/locales/index.ts +1 -0
  1010. package/node_modules/zod/src/mini/index.ts +3 -0
  1011. package/node_modules/zod/src/v3/ZodError.ts +340 -0
  1012. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  1013. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  1014. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  1015. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  1016. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  1017. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  1018. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  1019. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  1020. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  1021. package/node_modules/zod/src/v3/errors.ts +13 -0
  1022. package/node_modules/zod/src/v3/external.ts +6 -0
  1023. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  1024. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  1025. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  1026. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  1027. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  1028. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  1029. package/node_modules/zod/src/v3/index.ts +4 -0
  1030. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  1031. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  1032. package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
  1033. package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
  1034. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
  1035. package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
  1036. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
  1037. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
  1038. package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
  1039. package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
  1040. package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
  1041. package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
  1042. package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
  1043. package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
  1044. package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
  1045. package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
  1046. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
  1047. package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
  1048. package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
  1049. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  1050. package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
  1051. package/node_modules/zod/src/v3/tests/error.test.ts +586 -0
  1052. package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
  1053. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  1054. package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
  1055. package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
  1056. package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
  1057. package/node_modules/zod/src/v3/tests/intersection.test.ts +128 -0
  1058. package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
  1059. package/node_modules/zod/src/v3/tests/language-server.test.ts +206 -0
  1060. package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
  1061. package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
  1062. package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
  1063. package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
  1064. package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
  1065. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  1066. package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
  1067. package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
  1068. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  1069. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  1070. package/node_modules/zod/src/v3/tests/object.test.ts +431 -0
  1071. package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
  1072. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
  1073. package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
  1074. package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
  1075. package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
  1076. package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
  1077. package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
  1078. package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
  1079. package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
  1080. package/node_modules/zod/src/v3/tests/readonly.test.ts +114 -0
  1081. package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
  1082. package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
  1083. package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
  1084. package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
  1085. package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
  1086. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
  1087. package/node_modules/zod/src/v3/tests/string.test.ts +922 -0
  1088. package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
  1089. package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
  1090. package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
  1091. package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
  1092. package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
  1093. package/node_modules/zod/src/v3/types.ts +5138 -0
  1094. package/node_modules/zod/src/v4/classic/checks.ts +33 -0
  1095. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  1096. package/node_modules/zod/src/v4/classic/compat.ts +78 -0
  1097. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  1098. package/node_modules/zod/src/v4/classic/errors.ts +97 -0
  1099. package/node_modules/zod/src/v4/classic/external.ts +57 -0
  1100. package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
  1101. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  1102. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  1103. package/node_modules/zod/src/v4/classic/iso.ts +20 -0
  1104. package/node_modules/zod/src/v4/classic/parse.ts +88 -0
  1105. package/node_modules/zod/src/v4/classic/schemas.ts +2937 -0
  1106. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  1107. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
  1108. package/node_modules/zod/src/v4/classic/tests/array.test.ts +264 -0
  1109. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +402 -0
  1110. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  1111. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  1112. package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  1113. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +89 -0
  1114. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +106 -0
  1115. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +604 -0
  1116. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  1117. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
  1118. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
  1119. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  1120. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
  1121. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  1122. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  1123. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  1124. package/node_modules/zod/src/v4/classic/tests/date.test.ts +92 -0
  1125. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +316 -0
  1126. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  1127. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  1128. package/node_modules/zod/src/v4/classic/tests/default.test.ts +455 -0
  1129. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  1130. package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  1131. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
  1132. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
  1133. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +305 -0
  1134. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +917 -0
  1135. package/node_modules/zod/src/v4/classic/tests/error.test.ts +1108 -0
  1136. package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
  1137. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
  1138. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  1139. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  1140. package/node_modules/zod/src/v4/classic/tests/function.test.ts +391 -0
  1141. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  1142. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
  1143. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
  1144. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  1145. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  1146. package/node_modules/zod/src/v4/classic/tests/index.test.ts +958 -0
  1147. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  1148. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +127 -0
  1149. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +334 -0
  1150. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  1151. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  1152. package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
  1153. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +262 -0
  1154. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +128 -0
  1155. package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  1156. package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  1157. package/node_modules/zod/src/v4/classic/tests/map.test.ts +342 -0
  1158. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  1159. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  1160. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
  1161. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  1162. package/node_modules/zod/src/v4/classic/tests/number.test.ts +401 -0
  1163. package/node_modules/zod/src/v4/classic/tests/object.test.ts +1006 -0
  1164. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  1165. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +366 -0
  1166. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +497 -0
  1167. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +211 -0
  1168. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
  1169. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +144 -0
  1170. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  1171. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +351 -0
  1172. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  1173. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  1174. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  1175. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  1176. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +184 -0
  1177. package/node_modules/zod/src/v4/classic/tests/record.test.ts +885 -0
  1178. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +707 -0
  1179. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  1180. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +693 -0
  1181. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +243 -0
  1182. package/node_modules/zod/src/v4/classic/tests/set.test.ts +190 -0
  1183. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +153 -0
  1184. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
  1185. package/node_modules/zod/src/v4/classic/tests/string.test.ts +1440 -0
  1186. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +124 -0
  1187. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +812 -0
  1188. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  1189. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +4733 -0
  1190. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +378 -0
  1191. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +511 -0
  1192. package/node_modules/zod/src/v4/classic/tests/union.test.ts +310 -0
  1193. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  1194. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  1195. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
  1196. package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
  1197. package/node_modules/zod/src/v4/core/api.ts +1875 -0
  1198. package/node_modules/zod/src/v4/core/checks.ts +1266 -0
  1199. package/node_modules/zod/src/v4/core/compile.ts +2313 -0
  1200. package/node_modules/zod/src/v4/core/core.ts +230 -0
  1201. package/node_modules/zod/src/v4/core/doc.ts +52 -0
  1202. package/node_modules/zod/src/v4/core/errors.ts +543 -0
  1203. package/node_modules/zod/src/v4/core/index.ts +19 -0
  1204. package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
  1205. package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
  1206. package/node_modules/zod/src/v4/core/json-schema.ts +148 -0
  1207. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  1208. package/node_modules/zod/src/v4/core/parse.ts +309 -0
  1209. package/node_modules/zod/src/v4/core/regexes.ts +217 -0
  1210. package/node_modules/zod/src/v4/core/registries.ts +105 -0
  1211. package/node_modules/zod/src/v4/core/schemas.ts +5192 -0
  1212. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  1213. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  1214. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  1215. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  1216. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  1217. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  1218. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  1219. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  1220. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  1221. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  1222. package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
  1223. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  1224. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
  1225. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  1226. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
  1227. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  1228. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  1229. package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  1230. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  1231. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  1232. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  1233. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  1234. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  1235. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  1236. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
  1237. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  1238. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
  1239. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  1240. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  1241. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  1242. package/node_modules/zod/src/v4/core/to-json-schema.ts +857 -0
  1243. package/node_modules/zod/src/v4/core/util.ts +1280 -0
  1244. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  1245. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  1246. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  1247. package/node_modules/zod/src/v4/index.ts +4 -0
  1248. package/node_modules/zod/src/v4/locales/ar.ts +120 -0
  1249. package/node_modules/zod/src/v4/locales/az.ts +116 -0
  1250. package/node_modules/zod/src/v4/locales/be.ts +188 -0
  1251. package/node_modules/zod/src/v4/locales/bg.ts +133 -0
  1252. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  1253. package/node_modules/zod/src/v4/locales/ca.ts +121 -0
  1254. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  1255. package/node_modules/zod/src/v4/locales/cs.ts +123 -0
  1256. package/node_modules/zod/src/v4/locales/da.ts +128 -0
  1257. package/node_modules/zod/src/v4/locales/de.ts +121 -0
  1258. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  1259. package/node_modules/zod/src/v4/locales/en.ts +136 -0
  1260. package/node_modules/zod/src/v4/locales/eo.ts +123 -0
  1261. package/node_modules/zod/src/v4/locales/es.ts +145 -0
  1262. package/node_modules/zod/src/v4/locales/fa.ts +131 -0
  1263. package/node_modules/zod/src/v4/locales/fi.ts +126 -0
  1264. package/node_modules/zod/src/v4/locales/fr-CA.ts +121 -0
  1265. package/node_modules/zod/src/v4/locales/fr.ts +139 -0
  1266. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  1267. package/node_modules/zod/src/v4/locales/he.ts +253 -0
  1268. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  1269. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  1270. package/node_modules/zod/src/v4/locales/hu.ts +122 -0
  1271. package/node_modules/zod/src/v4/locales/hy.ts +175 -0
  1272. package/node_modules/zod/src/v4/locales/id.ts +120 -0
  1273. package/node_modules/zod/src/v4/locales/index.ts +63 -0
  1274. package/node_modules/zod/src/v4/locales/is.ts +124 -0
  1275. package/node_modules/zod/src/v4/locales/it.ts +121 -0
  1276. package/node_modules/zod/src/v4/locales/ja.ts +119 -0
  1277. package/node_modules/zod/src/v4/locales/ka.ts +128 -0
  1278. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  1279. package/node_modules/zod/src/v4/locales/km.ts +124 -0
  1280. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  1281. package/node_modules/zod/src/v4/locales/ko.ts +126 -0
  1282. package/node_modules/zod/src/v4/locales/lt.ts +243 -0
  1283. package/node_modules/zod/src/v4/locales/mk.ts +123 -0
  1284. package/node_modules/zod/src/v4/locales/ms.ts +120 -0
  1285. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  1286. package/node_modules/zod/src/v4/locales/nl.ts +126 -0
  1287. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  1288. package/node_modules/zod/src/v4/locales/no.ts +121 -0
  1289. package/node_modules/zod/src/v4/locales/ota.ts +122 -0
  1290. package/node_modules/zod/src/v4/locales/pl.ts +123 -0
  1291. package/node_modules/zod/src/v4/locales/ps.ts +131 -0
  1292. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  1293. package/node_modules/zod/src/v4/locales/pt.ts +159 -0
  1294. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  1295. package/node_modules/zod/src/v4/locales/ru.ts +188 -0
  1296. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  1297. package/node_modules/zod/src/v4/locales/sl.ts +123 -0
  1298. package/node_modules/zod/src/v4/locales/sv.ts +124 -0
  1299. package/node_modules/zod/src/v4/locales/ta.ts +123 -0
  1300. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  1301. package/node_modules/zod/src/v4/locales/th.ts +124 -0
  1302. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  1303. package/node_modules/zod/src/v4/locales/tr.ts +116 -0
  1304. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  1305. package/node_modules/zod/src/v4/locales/uk.ts +122 -0
  1306. package/node_modules/zod/src/v4/locales/ur.ts +124 -0
  1307. package/node_modules/zod/src/v4/locales/uz.ts +120 -0
  1308. package/node_modules/zod/src/v4/locales/vi.ts +122 -0
  1309. package/node_modules/zod/src/v4/locales/yo.ts +129 -0
  1310. package/node_modules/zod/src/v4/locales/zh-CN.ts +121 -0
  1311. package/node_modules/zod/src/v4/locales/zh-TW.ts +120 -0
  1312. package/node_modules/zod/src/v4/mini/checks.ts +33 -0
  1313. package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
  1314. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  1315. package/node_modules/zod/src/v4/mini/external.ts +52 -0
  1316. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  1317. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  1318. package/node_modules/zod/src/v4/mini/iso.ts +66 -0
  1319. package/node_modules/zod/src/v4/mini/parse.ts +16 -0
  1320. package/node_modules/zod/src/v4/mini/schemas.ts +2051 -0
  1321. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
  1322. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +190 -0
  1323. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +94 -0
  1324. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +158 -0
  1325. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
  1326. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +30 -0
  1327. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  1328. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  1329. package/node_modules/zod/src/v4/mini/tests/error.test.ts +41 -0
  1330. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +14 -0
  1331. package/node_modules/zod/src/v4/mini/tests/index.test.ts +1146 -0
  1332. package/node_modules/zod/src/v4/mini/tests/number.test.ts +109 -0
  1333. package/node_modules/zod/src/v4/mini/tests/object.test.ts +292 -0
  1334. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  1335. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +341 -0
  1336. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
  1337. package/node_modules/zod/src/v4/mini/tests/string.test.ts +396 -0
  1338. package/node_modules/zod/src/v4-mini/index.ts +3 -0
  1339. package/node_modules/zod/v3/ZodError.cjs +167 -0
  1340. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  1341. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  1342. package/node_modules/zod/v3/ZodError.js +143 -0
  1343. package/node_modules/zod/v3/errors.cjs +36 -0
  1344. package/node_modules/zod/v3/errors.d.cts +5 -0
  1345. package/node_modules/zod/v3/errors.d.ts +5 -0
  1346. package/node_modules/zod/v3/errors.js +9 -0
  1347. package/node_modules/zod/v3/external.cjs +41 -0
  1348. package/node_modules/zod/v3/external.d.cts +6 -0
  1349. package/node_modules/zod/v3/external.d.ts +6 -0
  1350. package/node_modules/zod/v3/external.js +6 -0
  1351. package/node_modules/zod/v3/helpers/enumUtil.cjs +21 -0
  1352. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  1353. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  1354. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  1355. package/node_modules/zod/v3/helpers/errorUtil.cjs +28 -0
  1356. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  1357. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  1358. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  1359. package/node_modules/zod/v3/helpers/parseUtil.cjs +143 -0
  1360. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  1361. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  1362. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  1363. package/node_modules/zod/v3/helpers/partialUtil.cjs +21 -0
  1364. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  1365. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  1366. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  1367. package/node_modules/zod/v3/helpers/typeAliases.cjs +21 -0
  1368. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  1369. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  1370. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  1371. package/node_modules/zod/v3/helpers/util.cjs +156 -0
  1372. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  1373. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  1374. package/node_modules/zod/v3/helpers/util.js +133 -0
  1375. package/node_modules/zod/v3/index.cjs +52 -0
  1376. package/node_modules/zod/v3/index.d.cts +4 -0
  1377. package/node_modules/zod/v3/index.d.ts +4 -0
  1378. package/node_modules/zod/v3/index.js +4 -0
  1379. package/node_modules/zod/v3/locales/en.cjs +112 -0
  1380. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  1381. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  1382. package/node_modules/zod/v3/locales/en.js +109 -0
  1383. package/node_modules/zod/v3/package.json +7 -0
  1384. package/node_modules/zod/v3/standard-schema.cjs +21 -0
  1385. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  1386. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  1387. package/node_modules/zod/v3/standard-schema.js +1 -0
  1388. package/node_modules/zod/v3/types.cjs +3798 -0
  1389. package/node_modules/zod/v3/types.d.cts +1034 -0
  1390. package/node_modules/zod/v3/types.d.ts +1034 -0
  1391. package/node_modules/zod/v3/types.js +3697 -0
  1392. package/node_modules/zod/v4/classic/checks.cjs +53 -0
  1393. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  1394. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  1395. package/node_modules/zod/v4/classic/checks.js +1 -0
  1396. package/node_modules/zod/v4/classic/coerce.cjs +66 -0
  1397. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  1398. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  1399. package/node_modules/zod/v4/classic/coerce.js +17 -0
  1400. package/node_modules/zod/v4/classic/compat.cjs +80 -0
  1401. package/node_modules/zod/v4/classic/compat.d.cts +48 -0
  1402. package/node_modules/zod/v4/classic/compat.d.ts +48 -0
  1403. package/node_modules/zod/v4/classic/compat.js +31 -0
  1404. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  1405. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  1406. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  1407. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  1408. package/node_modules/zod/v4/classic/errors.cjs +102 -0
  1409. package/node_modules/zod/v4/classic/errors.d.cts +29 -0
  1410. package/node_modules/zod/v4/classic/errors.d.ts +29 -0
  1411. package/node_modules/zod/v4/classic/errors.js +57 -0
  1412. package/node_modules/zod/v4/classic/external.cjs +97 -0
  1413. package/node_modules/zod/v4/classic/external.d.cts +19 -0
  1414. package/node_modules/zod/v4/classic/external.d.ts +19 -0
  1415. package/node_modules/zod/v4/classic/external.js +17 -0
  1416. package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
  1417. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  1418. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  1419. package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  1420. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  1421. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  1422. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  1423. package/node_modules/zod/v4/classic/in-out.js +36 -0
  1424. package/node_modules/zod/v4/classic/index.cjs +52 -0
  1425. package/node_modules/zod/v4/classic/index.d.cts +3 -0
  1426. package/node_modules/zod/v4/classic/index.d.ts +3 -0
  1427. package/node_modules/zod/v4/classic/index.js +4 -0
  1428. package/node_modules/zod/v4/classic/iso.cjs +68 -0
  1429. package/node_modules/zod/v4/classic/iso.d.cts +7 -0
  1430. package/node_modules/zod/v4/classic/iso.d.ts +7 -0
  1431. package/node_modules/zod/v4/classic/iso.js +15 -0
  1432. package/node_modules/zod/v4/classic/package.json +7 -0
  1433. package/node_modules/zod/v4/classic/parse.cjs +63 -0
  1434. package/node_modules/zod/v4/classic/parse.d.cts +44 -0
  1435. package/node_modules/zod/v4/classic/parse.d.ts +44 -0
  1436. package/node_modules/zod/v4/classic/parse.js +16 -0
  1437. package/node_modules/zod/v4/classic/schemas.cjs +1676 -0
  1438. package/node_modules/zod/v4/classic/schemas.d.cts +816 -0
  1439. package/node_modules/zod/v4/classic/schemas.d.ts +816 -0
  1440. package/node_modules/zod/v4/classic/schemas.js +1535 -0
  1441. package/node_modules/zod/v4/core/api.cjs +1269 -0
  1442. package/node_modules/zod/v4/core/api.d.cts +335 -0
  1443. package/node_modules/zod/v4/core/api.d.ts +335 -0
  1444. package/node_modules/zod/v4/core/api.js +1107 -0
  1445. package/node_modules/zod/v4/core/checks.cjs +561 -0
  1446. package/node_modules/zod/v4/core/checks.d.cts +294 -0
  1447. package/node_modules/zod/v4/core/checks.d.ts +294 -0
  1448. package/node_modules/zod/v4/core/checks.js +516 -0
  1449. package/node_modules/zod/v4/core/compile.cjs +1908 -0
  1450. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  1451. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  1452. package/node_modules/zod/v4/core/compile.js +1858 -0
  1453. package/node_modules/zod/v4/core/core.cjs +167 -0
  1454. package/node_modules/zod/v4/core/core.d.cts +82 -0
  1455. package/node_modules/zod/v4/core/core.d.ts +82 -0
  1456. package/node_modules/zod/v4/core/core.js +141 -0
  1457. package/node_modules/zod/v4/core/doc.cjs +61 -0
  1458. package/node_modules/zod/v4/core/doc.d.cts +16 -0
  1459. package/node_modules/zod/v4/core/doc.d.ts +16 -0
  1460. package/node_modules/zod/v4/core/doc.js +38 -0
  1461. package/node_modules/zod/v4/core/errors.cjs +317 -0
  1462. package/node_modules/zod/v4/core/errors.d.cts +225 -0
  1463. package/node_modules/zod/v4/core/errors.d.ts +225 -0
  1464. package/node_modules/zod/v4/core/errors.js +267 -0
  1465. package/node_modules/zod/v4/core/index.cjs +70 -0
  1466. package/node_modules/zod/v4/core/index.d.cts +19 -0
  1467. package/node_modules/zod/v4/core/index.d.ts +19 -0
  1468. package/node_modules/zod/v4/core/index.js +19 -0
  1469. package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
  1470. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  1471. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  1472. package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  1473. package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
  1474. package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
  1475. package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
  1476. package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  1477. package/node_modules/zod/v4/core/json-schema.cjs +21 -0
  1478. package/node_modules/zod/v4/core/json-schema.d.cts +89 -0
  1479. package/node_modules/zod/v4/core/json-schema.d.ts +89 -0
  1480. package/node_modules/zod/v4/core/json-schema.js +1 -0
  1481. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  1482. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  1483. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  1484. package/node_modules/zod/v4/core/memoizer.js +311 -0
  1485. package/node_modules/zod/v4/core/package.json +7 -0
  1486. package/node_modules/zod/v4/core/parse.cjs +233 -0
  1487. package/node_modules/zod/v4/core/parse.d.cts +52 -0
  1488. package/node_modules/zod/v4/core/parse.d.ts +52 -0
  1489. package/node_modules/zod/v4/core/parse.js +175 -0
  1490. package/node_modules/zod/v4/core/regexes.cjs +209 -0
  1491. package/node_modules/zod/v4/core/regexes.d.cts +90 -0
  1492. package/node_modules/zod/v4/core/regexes.d.ts +90 -0
  1493. package/node_modules/zod/v4/core/regexes.js +156 -0
  1494. package/node_modules/zod/v4/core/registries.cjs +75 -0
  1495. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  1496. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  1497. package/node_modules/zod/v4/core/registries.js +51 -0
  1498. package/node_modules/zod/v4/core/schemas.cjs +2669 -0
  1499. package/node_modules/zod/v4/core/schemas.d.cts +1273 -0
  1500. package/node_modules/zod/v4/core/schemas.d.ts +1273 -0
  1501. package/node_modules/zod/v4/core/schemas.js +2606 -0
  1502. package/node_modules/zod/v4/core/standard-schema.cjs +21 -0
  1503. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  1504. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  1505. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  1506. package/node_modules/zod/v4/core/to-json-schema.cjs +681 -0
  1507. package/node_modules/zod/v4/core/to-json-schema.d.cts +154 -0
  1508. package/node_modules/zod/v4/core/to-json-schema.d.ts +154 -0
  1509. package/node_modules/zod/v4/core/to-json-schema.js +651 -0
  1510. package/node_modules/zod/v4/core/util.cjs +949 -0
  1511. package/node_modules/zod/v4/core/util.d.cts +278 -0
  1512. package/node_modules/zod/v4/core/util.d.ts +278 -0
  1513. package/node_modules/zod/v4/core/util.js +859 -0
  1514. package/node_modules/zod/v4/core/versions.cjs +27 -0
  1515. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  1516. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  1517. package/node_modules/zod/v4/core/versions.js +5 -0
  1518. package/node_modules/zod/v4/core/visit.cjs +214 -0
  1519. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  1520. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  1521. package/node_modules/zod/v4/core/visit.js +169 -0
  1522. package/node_modules/zod/v4/index.cjs +51 -0
  1523. package/node_modules/zod/v4/index.d.cts +3 -0
  1524. package/node_modules/zod/v4/index.d.ts +3 -0
  1525. package/node_modules/zod/v4/index.js +4 -0
  1526. package/node_modules/zod/v4/locales/ar.cjs +138 -0
  1527. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  1528. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  1529. package/node_modules/zod/v4/locales/ar.js +111 -0
  1530. package/node_modules/zod/v4/locales/az.cjs +137 -0
  1531. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  1532. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  1533. package/node_modules/zod/v4/locales/az.js +110 -0
  1534. package/node_modules/zod/v4/locales/be.cjs +195 -0
  1535. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  1536. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  1537. package/node_modules/zod/v4/locales/be.js +168 -0
  1538. package/node_modules/zod/v4/locales/bg.cjs +152 -0
  1539. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  1540. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  1541. package/node_modules/zod/v4/locales/bg.js +125 -0
  1542. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  1543. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  1544. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  1545. package/node_modules/zod/v4/locales/bn.js +113 -0
  1546. package/node_modules/zod/v4/locales/ca.cjs +139 -0
  1547. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  1548. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  1549. package/node_modules/zod/v4/locales/ca.js +112 -0
  1550. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  1551. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  1552. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  1553. package/node_modules/zod/v4/locales/ckb.js +133 -0
  1554. package/node_modules/zod/v4/locales/cs.cjs +143 -0
  1555. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  1556. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  1557. package/node_modules/zod/v4/locales/cs.js +116 -0
  1558. package/node_modules/zod/v4/locales/da.cjs +147 -0
  1559. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  1560. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  1561. package/node_modules/zod/v4/locales/da.js +120 -0
  1562. package/node_modules/zod/v4/locales/de.cjs +140 -0
  1563. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  1564. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  1565. package/node_modules/zod/v4/locales/de.js +113 -0
  1566. package/node_modules/zod/v4/locales/el.cjs +139 -0
  1567. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  1568. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  1569. package/node_modules/zod/v4/locales/el.js +112 -0
  1570. package/node_modules/zod/v4/locales/en.cjs +152 -0
  1571. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  1572. package/node_modules/zod/v4/locales/en.d.ts +4 -0
  1573. package/node_modules/zod/v4/locales/en.js +125 -0
  1574. package/node_modules/zod/v4/locales/eo.cjs +141 -0
  1575. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  1576. package/node_modules/zod/v4/locales/eo.d.ts +4 -0
  1577. package/node_modules/zod/v4/locales/eo.js +114 -0
  1578. package/node_modules/zod/v4/locales/es.cjs +163 -0
  1579. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  1580. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  1581. package/node_modules/zod/v4/locales/es.js +136 -0
  1582. package/node_modules/zod/v4/locales/fa.cjs +146 -0
  1583. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  1584. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  1585. package/node_modules/zod/v4/locales/fa.js +119 -0
  1586. package/node_modules/zod/v4/locales/fi.cjs +144 -0
  1587. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  1588. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  1589. package/node_modules/zod/v4/locales/fi.js +117 -0
  1590. package/node_modules/zod/v4/locales/fr-CA.cjs +139 -0
  1591. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  1592. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  1593. package/node_modules/zod/v4/locales/fr-CA.js +112 -0
  1594. package/node_modules/zod/v4/locales/fr.cjs +156 -0
  1595. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  1596. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  1597. package/node_modules/zod/v4/locales/fr.js +129 -0
  1598. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  1599. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  1600. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  1601. package/node_modules/zod/v4/locales/gu.js +113 -0
  1602. package/node_modules/zod/v4/locales/he.cjs +248 -0
  1603. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  1604. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  1605. package/node_modules/zod/v4/locales/he.js +221 -0
  1606. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  1607. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  1608. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  1609. package/node_modules/zod/v4/locales/hi.js +111 -0
  1610. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  1611. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  1612. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  1613. package/node_modules/zod/v4/locales/hr.js +126 -0
  1614. package/node_modules/zod/v4/locales/hu.cjs +140 -0
  1615. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  1616. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  1617. package/node_modules/zod/v4/locales/hu.js +113 -0
  1618. package/node_modules/zod/v4/locales/hy.cjs +185 -0
  1619. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  1620. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  1621. package/node_modules/zod/v4/locales/hy.js +158 -0
  1622. package/node_modules/zod/v4/locales/id.cjs +138 -0
  1623. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  1624. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  1625. package/node_modules/zod/v4/locales/id.js +111 -0
  1626. package/node_modules/zod/v4/locales/index.cjs +152 -0
  1627. package/node_modules/zod/v4/locales/index.d.cts +63 -0
  1628. package/node_modules/zod/v4/locales/index.d.ts +63 -0
  1629. package/node_modules/zod/v4/locales/index.js +63 -0
  1630. package/node_modules/zod/v4/locales/is.cjs +141 -0
  1631. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  1632. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  1633. package/node_modules/zod/v4/locales/is.js +114 -0
  1634. package/node_modules/zod/v4/locales/it.cjs +140 -0
  1635. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  1636. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  1637. package/node_modules/zod/v4/locales/it.js +113 -0
  1638. package/node_modules/zod/v4/locales/ja.cjs +139 -0
  1639. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  1640. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  1641. package/node_modules/zod/v4/locales/ja.js +112 -0
  1642. package/node_modules/zod/v4/locales/ka.cjs +144 -0
  1643. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  1644. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  1645. package/node_modules/zod/v4/locales/ka.js +117 -0
  1646. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  1647. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  1648. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  1649. package/node_modules/zod/v4/locales/kh.js +5 -0
  1650. package/node_modules/zod/v4/locales/km.cjs +142 -0
  1651. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  1652. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  1653. package/node_modules/zod/v4/locales/km.js +115 -0
  1654. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  1655. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  1656. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  1657. package/node_modules/zod/v4/locales/kn.js +116 -0
  1658. package/node_modules/zod/v4/locales/ko.cjs +143 -0
  1659. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  1660. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  1661. package/node_modules/zod/v4/locales/ko.js +116 -0
  1662. package/node_modules/zod/v4/locales/lt.cjs +234 -0
  1663. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  1664. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  1665. package/node_modules/zod/v4/locales/lt.js +207 -0
  1666. package/node_modules/zod/v4/locales/mk.cjs +141 -0
  1667. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  1668. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  1669. package/node_modules/zod/v4/locales/mk.js +114 -0
  1670. package/node_modules/zod/v4/locales/ms.cjs +139 -0
  1671. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  1672. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  1673. package/node_modules/zod/v4/locales/ms.js +112 -0
  1674. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  1675. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  1676. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  1677. package/node_modules/zod/v4/locales/ne.js +111 -0
  1678. package/node_modules/zod/v4/locales/nl.cjs +142 -0
  1679. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  1680. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  1681. package/node_modules/zod/v4/locales/nl.js +115 -0
  1682. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  1683. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  1684. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  1685. package/node_modules/zod/v4/locales/nn.js +113 -0
  1686. package/node_modules/zod/v4/locales/no.cjs +140 -0
  1687. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  1688. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  1689. package/node_modules/zod/v4/locales/no.js +113 -0
  1690. package/node_modules/zod/v4/locales/ota.cjs +141 -0
  1691. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  1692. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  1693. package/node_modules/zod/v4/locales/ota.js +114 -0
  1694. package/node_modules/zod/v4/locales/package.json +7 -0
  1695. package/node_modules/zod/v4/locales/pl.cjs +141 -0
  1696. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  1697. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  1698. package/node_modules/zod/v4/locales/pl.js +114 -0
  1699. package/node_modules/zod/v4/locales/ps.cjs +146 -0
  1700. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  1701. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  1702. package/node_modules/zod/v4/locales/ps.js +119 -0
  1703. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  1704. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  1705. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  1706. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  1707. package/node_modules/zod/v4/locales/pt.cjs +169 -0
  1708. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  1709. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  1710. package/node_modules/zod/v4/locales/pt.js +142 -0
  1711. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  1712. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  1713. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  1714. package/node_modules/zod/v4/locales/ro.js +122 -0
  1715. package/node_modules/zod/v4/locales/ru.cjs +195 -0
  1716. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  1717. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  1718. package/node_modules/zod/v4/locales/ru.js +168 -0
  1719. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  1720. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  1721. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  1722. package/node_modules/zod/v4/locales/sk.js +116 -0
  1723. package/node_modules/zod/v4/locales/sl.cjs +141 -0
  1724. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  1725. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  1726. package/node_modules/zod/v4/locales/sl.js +114 -0
  1727. package/node_modules/zod/v4/locales/sv.cjs +142 -0
  1728. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  1729. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  1730. package/node_modules/zod/v4/locales/sv.js +115 -0
  1731. package/node_modules/zod/v4/locales/ta.cjs +142 -0
  1732. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  1733. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  1734. package/node_modules/zod/v4/locales/ta.js +115 -0
  1735. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  1736. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  1737. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  1738. package/node_modules/zod/v4/locales/tg.js +117 -0
  1739. package/node_modules/zod/v4/locales/th.cjs +142 -0
  1740. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  1741. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  1742. package/node_modules/zod/v4/locales/th.js +115 -0
  1743. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  1744. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  1745. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  1746. package/node_modules/zod/v4/locales/tk.js +107 -0
  1747. package/node_modules/zod/v4/locales/tr.cjs +137 -0
  1748. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  1749. package/node_modules/zod/v4/locales/tr.d.ts +4 -0
  1750. package/node_modules/zod/v4/locales/tr.js +110 -0
  1751. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  1752. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  1753. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  1754. package/node_modules/zod/v4/locales/ua.js +5 -0
  1755. package/node_modules/zod/v4/locales/uk.cjs +140 -0
  1756. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  1757. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  1758. package/node_modules/zod/v4/locales/uk.js +113 -0
  1759. package/node_modules/zod/v4/locales/ur.cjs +142 -0
  1760. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  1761. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  1762. package/node_modules/zod/v4/locales/ur.js +115 -0
  1763. package/node_modules/zod/v4/locales/uz.cjs +140 -0
  1764. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  1765. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  1766. package/node_modules/zod/v4/locales/uz.js +113 -0
  1767. package/node_modules/zod/v4/locales/vi.cjs +140 -0
  1768. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  1769. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  1770. package/node_modules/zod/v4/locales/vi.js +113 -0
  1771. package/node_modules/zod/v4/locales/yo.cjs +139 -0
  1772. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  1773. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  1774. package/node_modules/zod/v4/locales/yo.js +112 -0
  1775. package/node_modules/zod/v4/locales/zh-CN.cjs +141 -0
  1776. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  1777. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  1778. package/node_modules/zod/v4/locales/zh-CN.js +114 -0
  1779. package/node_modules/zod/v4/locales/zh-TW.cjs +139 -0
  1780. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  1781. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  1782. package/node_modules/zod/v4/locales/zh-TW.js +112 -0
  1783. package/node_modules/zod/v4/mini/checks.cjs +54 -0
  1784. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  1785. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  1786. package/node_modules/zod/v4/mini/checks.js +1 -0
  1787. package/node_modules/zod/v4/mini/coerce.cjs +71 -0
  1788. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  1789. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  1790. package/node_modules/zod/v4/mini/coerce.js +22 -0
  1791. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  1792. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  1793. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  1794. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  1795. package/node_modules/zod/v4/mini/external.cjs +95 -0
  1796. package/node_modules/zod/v4/mini/external.d.cts +16 -0
  1797. package/node_modules/zod/v4/mini/external.d.ts +16 -0
  1798. package/node_modules/zod/v4/mini/external.js +16 -0
  1799. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  1800. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  1801. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  1802. package/node_modules/zod/v4/mini/in-out.js +36 -0
  1803. package/node_modules/zod/v4/mini/index.cjs +51 -0
  1804. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  1805. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  1806. package/node_modules/zod/v4/mini/index.js +3 -0
  1807. package/node_modules/zod/v4/mini/iso.cjs +83 -0
  1808. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  1809. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  1810. package/node_modules/zod/v4/mini/iso.js +34 -0
  1811. package/node_modules/zod/v4/mini/package.json +7 -0
  1812. package/node_modules/zod/v4/mini/parse.cjs +37 -0
  1813. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  1814. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  1815. package/node_modules/zod/v4/mini/parse.js +1 -0
  1816. package/node_modules/zod/v4/mini/schemas.cjs +1147 -0
  1817. package/node_modules/zod/v4/mini/schemas.d.cts +480 -0
  1818. package/node_modules/zod/v4/mini/schemas.d.ts +480 -0
  1819. package/node_modules/zod/v4/mini/schemas.js +1002 -0
  1820. package/node_modules/zod/v4/package.json +7 -0
  1821. package/node_modules/zod/v4-mini/index.cjs +51 -0
  1822. package/node_modules/zod/v4-mini/index.d.cts +3 -0
  1823. package/node_modules/zod/v4-mini/index.d.ts +3 -0
  1824. package/node_modules/zod/v4-mini/index.js +3 -0
  1825. package/node_modules/zod/v4-mini/package.json +7 -0
  1826. package/package.json +50 -0
@@ -0,0 +1,4593 @@
1
+ import { $ as getPerfMetricsSnapshot, B as absolutePath, C as mergeSessionOptions, Ct as promptToDisplayText, D as applyLifecycleSnapshotToRecord, Dt as withInterrupt, E as applyConversation, Et as TimeoutError, F as modelStateFromConfigOptions, Ft as isRetryablePromptError, G as listSessions, H as findSession, I as splitCommandLine, It as normalizeOutputError, J as pruneSessions, K as listSessionsForAgent, Lt as extractAcpError, N as assertRequestedModelSupported, Ot as withTimeout, Pt as formatErrorMessage, Q as formatPerfMetric, Qt as QueueProtocolError, S as advertisedModelState, T as sessionOptionsFromRecord, Tt as InterruptedError, U as findSessionByDirectoryWalk, Ut as OUTPUT_ERROR_CODES, V as findGitRepositoryRoot, W as isoNow, Wt as OUTPUT_ERROR_ORIGINS, X as writeSessionRecord, Y as resolveSessionRecord, Zt as QueueConnectionError, _ as createSessionConversation, _t as parseJsonRpcErrorMessage, a as applyRequestedModelIfAdvertised, at as startPerfTimer, b as recordSessionUpdate, bt as isPromptInput, c as setCurrentModelId, ct as normalizeRuntimeSessionId, d as setDesiredModelId, dt as sessionBaseDir, et as incrementPerfCounter, f as syncAdvertisedModelState, ft as sessionEventActivePath, g as cloneSessionConversation, gt as isAcpJsonRpcMessage, h as cloneSessionAcpxState, ht as extractSessionUpdateNotification, i as connectAndLoadSession, it as setPerfGauge, k as AcpClient, l as setDesiredConfigOption, m as applyConfigOptionsToState, mt as sessionEventSegmentPath, n as runPromptTurn, nt as recordPerfDuration, o as currentModelIdFromSetModelResponse, p as applyConfigOptionsToRecord, pt as sessionEventLockPath, q as normalizeName, r as withConnectedSession, rt as resetPerfMetrics, s as clearDesiredConfigOption, t as LiveSessionCheckpoint, tt as measurePerf, u as setDesiredModeId, ut as defaultSessionEventLog, v as recordClientOperation, vt as parsePromptStopReason, w as persistSessionOptions, wt as textPrompt, x as trimConversationForRuntime, y as recordPromptSubmission, zt as toAcpErrorPayload } from "./live-checkpoint-ClPCSdrW.js";
2
+ import fs, { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import fs$1 from "node:fs/promises";
5
+ import os from "node:os";
6
+ import { createHash, randomInt, randomUUID } from "node:crypto";
7
+ import { execFile, spawn } from "node:child_process";
8
+ import { promisify } from "node:util";
9
+ import net from "node:net";
10
+ //#region \0rolldown/runtime.js
11
+ var __defProp = Object.defineProperty;
12
+ var __exportAll = (all, no_symbols) => {
13
+ let target = {};
14
+ for (var name in all) __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
+ return target;
20
+ };
21
+ //#endregion
22
+ //#region src/process-liveness.ts
23
+ function isProcessAlive(pid) {
24
+ if (!pid || !Number.isInteger(pid) || pid <= 0 || pid === process.pid) return false;
25
+ try {
26
+ process.kill(pid, 0);
27
+ return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+ //#endregion
33
+ //#region src/cli/session/contracts.ts
34
+ const DEFAULT_QUEUE_OWNER_TTL_MS = 3e5;
35
+ function normalizeQueueOwnerTtlMs(ttlMs) {
36
+ if (ttlMs == null) return DEFAULT_QUEUE_OWNER_TTL_MS;
37
+ if (!Number.isFinite(ttlMs) || ttlMs < 0) return DEFAULT_QUEUE_OWNER_TTL_MS;
38
+ return Math.round(ttlMs);
39
+ }
40
+ //#endregion
41
+ //#region src/cli/queue/paths.ts
42
+ function shortHash(value, length) {
43
+ return createHash("sha256").update(value).digest("hex").slice(0, length);
44
+ }
45
+ function queueKeyForSession(sessionId) {
46
+ return shortHash(sessionId, 24);
47
+ }
48
+ function queueBaseDir(homeDir = os.homedir()) {
49
+ return path.join(homeDir, ".acpx", "queues");
50
+ }
51
+ function queueSocketBaseDir(homeDir = os.homedir()) {
52
+ if (process.platform === "win32") return;
53
+ return path.join("/tmp", `acpx-${shortHash(homeDir, 10)}`);
54
+ }
55
+ function queueLockFilePath(sessionId, homeDir = os.homedir()) {
56
+ return path.join(queueBaseDir(homeDir), `${queueKeyForSession(sessionId)}.lock`);
57
+ }
58
+ function queueSocketPath(sessionId, homeDir = os.homedir()) {
59
+ const key = queueKeyForSession(sessionId);
60
+ if (process.platform === "win32") return `\\\\.\\pipe\\acpx-${key}`;
61
+ return path.join(queueSocketBaseDir(homeDir) ?? "/tmp", `${key}.sock`);
62
+ }
63
+ //#endregion
64
+ //#region src/cli/queue/lease-store.ts
65
+ const PROCESS_SIGTERM_GRACE_MS = 4e3;
66
+ const PROCESS_SIGKILL_GRACE_MS = 1500;
67
+ const PROCESS_POLL_MS = 50;
68
+ const QUEUE_OWNER_STALE_HEARTBEAT_MS = 15e3;
69
+ function parseQueueOwnerRecord(raw) {
70
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
71
+ const record = raw;
72
+ if (!hasValidQueueOwnerRecordFields(record)) return null;
73
+ return {
74
+ pid: record.pid,
75
+ sessionId: record.sessionId,
76
+ socketPath: record.socketPath,
77
+ createdAt: record.createdAt,
78
+ heartbeatAt: record.heartbeatAt,
79
+ ownerGeneration: record.ownerGeneration,
80
+ queueDepth: record.queueDepth,
81
+ ...typeof record.mcpConfigPath === "string" ? { mcpConfigPath: record.mcpConfigPath } : {},
82
+ ...typeof record.mcpConfigFingerprint === "string" ? { mcpConfigFingerprint: record.mcpConfigFingerprint } : {}
83
+ };
84
+ }
85
+ function hasValidQueueOwnerRecordFields(record) {
86
+ return isPositiveInteger(record.pid) && typeof record.sessionId === "string" && typeof record.socketPath === "string" && typeof record.createdAt === "string" && typeof record.heartbeatAt === "string" && isPositiveInteger(record.ownerGeneration) && isNonNegativeInteger(record.queueDepth);
87
+ }
88
+ function isPositiveInteger(value) {
89
+ return Number.isInteger(value) && value > 0;
90
+ }
91
+ function isNonNegativeInteger(value) {
92
+ return Number.isInteger(value) && value >= 0;
93
+ }
94
+ function createOwnerGeneration() {
95
+ return randomInt(1, 2 ** 48);
96
+ }
97
+ function nowIso() {
98
+ return (/* @__PURE__ */ new Date()).toISOString();
99
+ }
100
+ function isQueueOwnerHeartbeatStale(owner) {
101
+ const heartbeatMs = Date.parse(owner.heartbeatAt);
102
+ if (!Number.isFinite(heartbeatMs)) return true;
103
+ return Date.now() - heartbeatMs > QUEUE_OWNER_STALE_HEARTBEAT_MS;
104
+ }
105
+ async function ensureQueueDir() {
106
+ const baseDir = queueBaseDir();
107
+ await fs$1.mkdir(baseDir, {
108
+ recursive: true,
109
+ mode: 448
110
+ });
111
+ await fs$1.chmod(baseDir, 448);
112
+ const socketDir = queueSocketBaseDir();
113
+ if (socketDir) {
114
+ await fs$1.mkdir(socketDir, {
115
+ recursive: true,
116
+ mode: 448
117
+ });
118
+ await fs$1.chmod(socketDir, 448);
119
+ }
120
+ }
121
+ async function removeSocketFile(socketPath) {
122
+ if (process.platform === "win32") return;
123
+ try {
124
+ await fs$1.unlink(socketPath);
125
+ } catch (error) {
126
+ if (error.code !== "ENOENT") throw error;
127
+ }
128
+ }
129
+ async function waitForProcessExit(pid, timeoutMs) {
130
+ const deadline = Date.now() + Math.max(0, timeoutMs);
131
+ while (Date.now() <= deadline) {
132
+ if (!isProcessAlive(pid)) return true;
133
+ await waitMs(PROCESS_POLL_MS);
134
+ }
135
+ return !isProcessAlive(pid);
136
+ }
137
+ async function cleanupStaleQueueOwner(sessionId, owner) {
138
+ const lockPath = queueLockFilePath(sessionId);
139
+ await removeSocketFile(owner?.socketPath ?? queueSocketPath(sessionId)).catch(() => {});
140
+ await fs$1.unlink(lockPath).catch((error) => {
141
+ if (error.code !== "ENOENT") throw error;
142
+ });
143
+ }
144
+ async function retireStaleQueueOwner(sessionId, owner) {
145
+ if (owner && isProcessAlive(owner.pid)) await terminateProcess(owner.pid);
146
+ await cleanupStaleQueueOwner(sessionId, owner);
147
+ }
148
+ async function readQueueOwnerRecord(sessionId) {
149
+ const lockPath = queueLockFilePath(sessionId);
150
+ try {
151
+ const payload = await fs$1.readFile(lockPath, "utf8");
152
+ return parseQueueOwnerRecord(JSON.parse(payload)) ?? void 0;
153
+ } catch {
154
+ return;
155
+ }
156
+ }
157
+ async function terminateProcess(pid) {
158
+ if (!isProcessAlive(pid)) return false;
159
+ try {
160
+ process.kill(pid, "SIGTERM");
161
+ } catch {
162
+ return false;
163
+ }
164
+ if (await waitForProcessExit(pid, PROCESS_SIGTERM_GRACE_MS)) return true;
165
+ try {
166
+ process.kill(pid, "SIGKILL");
167
+ } catch {
168
+ return false;
169
+ }
170
+ await waitForProcessExit(pid, PROCESS_SIGKILL_GRACE_MS);
171
+ return true;
172
+ }
173
+ async function ensureOwnerIsUsable(sessionId, owner) {
174
+ const alive = isProcessAlive(owner.pid);
175
+ const stale = isQueueOwnerHeartbeatStale(owner);
176
+ if (alive && !stale) return true;
177
+ await retireStaleQueueOwner(sessionId, owner);
178
+ return false;
179
+ }
180
+ async function readQueueOwnerStatus(sessionId) {
181
+ const owner = await readQueueOwnerRecord(sessionId);
182
+ if (!owner) return;
183
+ const alive = await ensureOwnerIsUsable(sessionId, owner);
184
+ if (!alive) return;
185
+ return {
186
+ pid: owner.pid,
187
+ socketPath: owner.socketPath,
188
+ heartbeatAt: owner.heartbeatAt,
189
+ ownerGeneration: owner.ownerGeneration,
190
+ queueDepth: owner.queueDepth,
191
+ alive,
192
+ stale: isQueueOwnerHeartbeatStale(owner)
193
+ };
194
+ }
195
+ async function tryAcquireQueueOwnerLease(sessionId, mcpConfigOrNowIsoFactory, nowIsoFactory = nowIso) {
196
+ const { mcpConfigPath, clock } = resolveLeaseArguments(mcpConfigOrNowIsoFactory, nowIsoFactory);
197
+ const mcpConfigMetadata = createMcpConfigMetadata(mcpConfigPath, readMcpConfigFingerprint(mcpConfigOrNowIsoFactory));
198
+ await ensureQueueDir();
199
+ const lockPath = queueLockFilePath(sessionId);
200
+ const socketPath = queueSocketPath(sessionId);
201
+ const createdAt = clock();
202
+ const ownerGeneration = createOwnerGeneration();
203
+ const payload = JSON.stringify({
204
+ pid: process.pid,
205
+ sessionId,
206
+ socketPath,
207
+ createdAt,
208
+ heartbeatAt: createdAt,
209
+ ownerGeneration,
210
+ queueDepth: 0,
211
+ ...mcpConfigMetadata
212
+ }, null, 2);
213
+ try {
214
+ await fs$1.writeFile(lockPath, `${payload}\n`, {
215
+ encoding: "utf8",
216
+ flag: "wx"
217
+ });
218
+ await removeSocketFile(socketPath).catch(() => {});
219
+ return {
220
+ sessionId,
221
+ lockPath,
222
+ socketPath,
223
+ createdAt,
224
+ ownerGeneration,
225
+ ...mcpConfigMetadata
226
+ };
227
+ } catch (error) {
228
+ return await handleLeaseCollision(sessionId, error);
229
+ }
230
+ }
231
+ function readMcpConfigFingerprint(mcpConfigOrNowIsoFactory) {
232
+ return typeof mcpConfigOrNowIsoFactory === "object" ? mcpConfigOrNowIsoFactory?.fingerprint : void 0;
233
+ }
234
+ function createMcpConfigMetadata(mcpConfigPath, mcpConfigFingerprint) {
235
+ return {
236
+ ...mcpConfigPath ? { mcpConfigPath } : {},
237
+ ...mcpConfigFingerprint ? { mcpConfigFingerprint } : {}
238
+ };
239
+ }
240
+ async function handleLeaseCollision(sessionId, error) {
241
+ if (error.code !== "EEXIST") throw error;
242
+ const owner = await readQueueOwnerRecord(sessionId);
243
+ if (!owner) {
244
+ await cleanupStaleQueueOwner(sessionId, owner);
245
+ return;
246
+ }
247
+ if (!isProcessAlive(owner.pid) || isQueueOwnerHeartbeatStale(owner)) await retireStaleQueueOwner(sessionId, owner);
248
+ }
249
+ function resolveLeaseArguments(mcpConfigOrNowIsoFactory, nowIsoFactory) {
250
+ if (typeof mcpConfigOrNowIsoFactory === "string") return {
251
+ mcpConfigPath: mcpConfigOrNowIsoFactory,
252
+ clock: nowIsoFactory
253
+ };
254
+ if (typeof mcpConfigOrNowIsoFactory === "function") return {
255
+ mcpConfigPath: void 0,
256
+ clock: mcpConfigOrNowIsoFactory
257
+ };
258
+ if (mcpConfigOrNowIsoFactory) return {
259
+ mcpConfigPath: mcpConfigOrNowIsoFactory.path,
260
+ clock: nowIsoFactory
261
+ };
262
+ return {
263
+ mcpConfigPath: void 0,
264
+ clock: nowIsoFactory
265
+ };
266
+ }
267
+ async function refreshQueueOwnerLease(lease, options, nowIsoFactory = nowIso) {
268
+ const payload = JSON.stringify({
269
+ pid: process.pid,
270
+ sessionId: lease.sessionId,
271
+ socketPath: lease.socketPath,
272
+ createdAt: lease.createdAt,
273
+ heartbeatAt: nowIsoFactory(),
274
+ ownerGeneration: lease.ownerGeneration,
275
+ queueDepth: Math.max(0, Math.round(options.queueDepth)),
276
+ ...lease.mcpConfigPath ? { mcpConfigPath: lease.mcpConfigPath } : {},
277
+ ...lease.mcpConfigFingerprint ? { mcpConfigFingerprint: lease.mcpConfigFingerprint } : {}
278
+ }, null, 2);
279
+ await fs$1.writeFile(lease.lockPath, `${payload}\n`, { encoding: "utf8" });
280
+ }
281
+ async function releaseQueueOwnerLease(lease) {
282
+ await removeSocketFile(lease.socketPath).catch(() => {});
283
+ await fs$1.unlink(lease.lockPath).catch((error) => {
284
+ if (error.code !== "ENOENT") throw error;
285
+ });
286
+ }
287
+ async function terminateQueueOwnerForSession(sessionId) {
288
+ const owner = await readQueueOwnerRecord(sessionId);
289
+ if (!owner) return;
290
+ if (isProcessAlive(owner.pid)) await terminateProcess(owner.pid);
291
+ await cleanupStaleQueueOwner(sessionId, owner);
292
+ }
293
+ async function waitMs(ms) {
294
+ await new Promise((resolve) => {
295
+ setTimeout(resolve, ms);
296
+ });
297
+ }
298
+ //#endregion
299
+ //#region src/cli/queue/ipc-transport.ts
300
+ const QUEUE_CONNECT_ATTEMPTS = 40;
301
+ const SOCKET_CONNECTION_TIMEOUT_MS = 5e3;
302
+ function shouldRetryQueueConnect(error) {
303
+ const code = error.code;
304
+ return code === "ENOENT" || code === "ECONNREFUSED";
305
+ }
306
+ async function connectToSocket(socketPath, timeoutMs = SOCKET_CONNECTION_TIMEOUT_MS) {
307
+ return await new Promise((resolve, reject) => {
308
+ const socket = net.createConnection(socketPath);
309
+ let settled = false;
310
+ const timeout = setTimeout(() => {
311
+ if (settled) return;
312
+ settled = true;
313
+ socket.destroy();
314
+ reject(/* @__PURE__ */ new Error(`Connection to ${socketPath} timed out after ${timeoutMs}ms`));
315
+ }, timeoutMs);
316
+ const onConnect = () => {
317
+ if (settled) return;
318
+ settled = true;
319
+ clearTimeout(timeout);
320
+ socket.off("error", onError);
321
+ resolve(socket);
322
+ };
323
+ const onError = (error) => {
324
+ if (settled) return;
325
+ settled = true;
326
+ clearTimeout(timeout);
327
+ socket.off("connect", onConnect);
328
+ reject(error);
329
+ };
330
+ socket.once("connect", onConnect);
331
+ socket.once("error", onError);
332
+ });
333
+ }
334
+ async function connectToQueueOwner(owner, maxAttempts = QUEUE_CONNECT_ATTEMPTS) {
335
+ let lastError;
336
+ const attempts = Math.max(1, Math.trunc(maxAttempts));
337
+ for (let attempt = 0; attempt < attempts; attempt += 1) try {
338
+ return await measurePerf("queue.connect", async () => await connectToSocket(owner.socketPath));
339
+ } catch (error) {
340
+ lastError = error;
341
+ if (!shouldRetryQueueConnect(error)) throw error;
342
+ await waitMs(50);
343
+ }
344
+ if (lastError && !shouldRetryQueueConnect(lastError)) throw lastError;
345
+ }
346
+ //#endregion
347
+ //#region src/cli/queue/ipc-health.ts
348
+ async function probeQueueOwnerHealth(sessionId) {
349
+ const ownerRecord = await readQueueOwnerRecord(sessionId);
350
+ if (!ownerRecord) return {
351
+ sessionId,
352
+ hasLease: false,
353
+ healthy: false,
354
+ socketReachable: false,
355
+ pidAlive: false
356
+ };
357
+ const owner = await readQueueOwnerStatus(sessionId);
358
+ if (!owner) return {
359
+ sessionId,
360
+ hasLease: false,
361
+ healthy: false,
362
+ socketReachable: false,
363
+ pidAlive: false
364
+ };
365
+ const pidAlive = owner.alive;
366
+ let socketReachable = false;
367
+ try {
368
+ const socket = await connectToQueueOwner(ownerRecord, 2);
369
+ if (socket) {
370
+ socketReachable = true;
371
+ if (!socket.destroyed) socket.end();
372
+ }
373
+ } catch {
374
+ socketReachable = false;
375
+ }
376
+ return {
377
+ sessionId,
378
+ hasLease: true,
379
+ healthy: socketReachable,
380
+ socketReachable,
381
+ pidAlive,
382
+ pid: owner.pid,
383
+ socketPath: owner.socketPath,
384
+ ownerGeneration: owner.ownerGeneration,
385
+ queueDepth: owner.queueDepth
386
+ };
387
+ }
388
+ //#endregion
389
+ //#region src/cli/queue/messages.ts
390
+ function asRecord$2(value) {
391
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
392
+ return value;
393
+ }
394
+ function isPermissionMode(value) {
395
+ return value === "approve-all" || value === "approve-reads" || value === "deny-all";
396
+ }
397
+ function isSessionResumePolicy(value) {
398
+ return value === "allow-new" || value === "same-session-only";
399
+ }
400
+ function isNonInteractivePermissionPolicy(value) {
401
+ return value === "deny" || value === "fail";
402
+ }
403
+ function isPermissionPolicy(value) {
404
+ const record = asRecord$2(value);
405
+ if (!record) return false;
406
+ return hasValidPermissionRuleLists(record) && hasValidPermissionDefaultAction(record);
407
+ }
408
+ function hasValidPermissionRuleLists(record) {
409
+ for (const key of [
410
+ "autoApprove",
411
+ "autoDeny",
412
+ "escalate"
413
+ ]) if (!isOptionalStringList(record[key])) return false;
414
+ return true;
415
+ }
416
+ function isOptionalStringList(value) {
417
+ return value == null || Array.isArray(value) && value.every((item) => typeof item === "string");
418
+ }
419
+ function hasValidPermissionDefaultAction(record) {
420
+ return record.defaultAction == null || record.defaultAction === "approve" || record.defaultAction === "deny" || record.defaultAction === "escalate";
421
+ }
422
+ function isOutputErrorCode(value) {
423
+ return typeof value === "string" && OUTPUT_ERROR_CODES.includes(value);
424
+ }
425
+ function isOutputErrorOrigin(value) {
426
+ return typeof value === "string" && OUTPUT_ERROR_ORIGINS.includes(value);
427
+ }
428
+ function isPermissionEscalationEvent(value) {
429
+ const event = asRecord$2(value);
430
+ return !!event && hasRequiredPermissionEscalationFields(event) && hasOptionalStringFields(event, [
431
+ "toolName",
432
+ "toolKind",
433
+ "matchedRule"
434
+ ]);
435
+ }
436
+ function hasRequiredPermissionEscalationFields(event) {
437
+ return event.type === "permission_escalation" && typeof event.sessionId === "string" && typeof event.toolCallId === "string" && typeof event.toolTitle === "string" && event.action === "escalate" && typeof event.message === "string" && typeof event.timestamp === "string";
438
+ }
439
+ function hasOptionalStringFields(record, keys) {
440
+ return keys.every((key) => record[key] == null || typeof record[key] === "string");
441
+ }
442
+ function parseSessionOptions(value) {
443
+ if (value == null) return;
444
+ const record = asRecord$2(value);
445
+ if (!record) return null;
446
+ const sessionOptions = {};
447
+ if (!assignSessionModel(sessionOptions, record.model)) return null;
448
+ if (!assignSessionAllowedTools(sessionOptions, record.allowedTools)) return null;
449
+ if (!assignSessionMaxTurns(sessionOptions, record.maxTurns)) return null;
450
+ if (!assignSessionSystemPrompt(sessionOptions, record.systemPrompt)) return null;
451
+ if (!assignSessionEnv(sessionOptions, record.env)) return null;
452
+ return sessionOptions;
453
+ }
454
+ function assignSessionModel(options, value) {
455
+ if (value == null) return true;
456
+ if (typeof value !== "string" || value.trim().length === 0) return false;
457
+ options.model = value;
458
+ return true;
459
+ }
460
+ function assignSessionAllowedTools(options, value) {
461
+ if (value == null) return true;
462
+ if (!Array.isArray(value) || value.some((tool) => typeof tool !== "string")) return false;
463
+ options.allowedTools = value;
464
+ return true;
465
+ }
466
+ function assignSessionMaxTurns(options, value) {
467
+ if (value == null) return true;
468
+ if (typeof value !== "number" || !Number.isFinite(value)) return false;
469
+ options.maxTurns = Math.max(1, Math.round(value));
470
+ return true;
471
+ }
472
+ function assignSessionSystemPrompt(options, value) {
473
+ if (value == null) return true;
474
+ if (typeof value === "string") {
475
+ options.systemPrompt = value;
476
+ return true;
477
+ }
478
+ const systemPrompt = asRecord$2(value);
479
+ if (!systemPrompt || typeof systemPrompt.append !== "string") return false;
480
+ options.systemPrompt = { append: systemPrompt.append };
481
+ return true;
482
+ }
483
+ function assignSessionEnv(options, value) {
484
+ if (value == null) return true;
485
+ const env = asRecord$2(value);
486
+ if (!env) return false;
487
+ const entries = Object.entries(env);
488
+ if (entries.some(([, entryValue]) => typeof entryValue !== "string")) return false;
489
+ options.env = Object.fromEntries(entries);
490
+ return true;
491
+ }
492
+ function parseOwnerGeneration(value) {
493
+ if (value == null) return;
494
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) return null;
495
+ return value;
496
+ }
497
+ function parseNonNegativeInteger(value) {
498
+ if (value == null) return;
499
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return null;
500
+ return Math.round(value);
501
+ }
502
+ function parseQueueRequest(raw) {
503
+ const request = asRecord$2(raw);
504
+ if (!request || typeof request.type !== "string" || typeof request.requestId !== "string") return null;
505
+ const ownerGeneration = parseOwnerGeneration(request.ownerGeneration);
506
+ if (ownerGeneration === null) return null;
507
+ return parseTypedQueueRequest(request, parseQueueRequestContext(request.requestId, ownerGeneration, request.timeoutMs));
508
+ }
509
+ function parseQueueRequestContext(requestId, ownerGeneration, timeoutRaw) {
510
+ return {
511
+ requestId,
512
+ ownerGeneration,
513
+ timeoutMs: parsePositiveTimeout(timeoutRaw)
514
+ };
515
+ }
516
+ function parsePositiveTimeout(value) {
517
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return;
518
+ return Math.round(value);
519
+ }
520
+ function parseTypedQueueRequest(request, context) {
521
+ switch (request.type) {
522
+ case "submit_prompt": return parseSubmitRequest(request, context);
523
+ case "cancel_prompt": return {
524
+ type: "cancel_prompt",
525
+ requestId: context.requestId,
526
+ ownerGeneration: context.ownerGeneration
527
+ };
528
+ case "close_session": return {
529
+ type: "close_session",
530
+ ...context
531
+ };
532
+ case "set_mode": return parseStringFieldRequest(request, context, "set_mode", "modeId");
533
+ case "set_model": return parseStringFieldRequest(request, context, "set_model", "modelId");
534
+ case "set_config_option": return parseSetConfigOptionRequest(request, context);
535
+ default: return null;
536
+ }
537
+ }
538
+ function parseSubmitRequest(request, context) {
539
+ const parsed = parseSubmitRequestFields(request);
540
+ if (!parsed) return null;
541
+ return {
542
+ type: "submit_prompt",
543
+ requestId: context.requestId,
544
+ ownerGeneration: context.ownerGeneration,
545
+ message: parsed.message,
546
+ prompt: parsed.prompt ?? textPrompt(parsed.message),
547
+ permissionMode: parsed.permissionMode,
548
+ ...parsed.resumePolicy !== void 0 ? { resumePolicy: parsed.resumePolicy } : {},
549
+ nonInteractivePermissions: parsed.nonInteractivePermissions,
550
+ ...parsed.permissionPolicy !== void 0 ? { permissionPolicy: parsed.permissionPolicy } : {},
551
+ timeoutMs: context.timeoutMs,
552
+ ...parsed.suppressSdkConsoleErrors !== void 0 ? { suppressSdkConsoleErrors: parsed.suppressSdkConsoleErrors } : {},
553
+ ...parsed.promptRetries !== void 0 ? { promptRetries: parsed.promptRetries } : {},
554
+ waitForCompletion: parsed.waitForCompletion,
555
+ ...parsed.sessionOptions !== void 0 ? { sessionOptions: parsed.sessionOptions } : {}
556
+ };
557
+ }
558
+ function parseSubmitRequestFields(request) {
559
+ const parsed = {
560
+ message: typeof request.message === "string" ? request.message : null,
561
+ prompt: parseOptionalValue(request.prompt, isPromptInput),
562
+ permissionMode: parseRequiredValue(request.permissionMode, isPermissionMode),
563
+ resumePolicy: parseOptionalValue(request.resumePolicy, isSessionResumePolicy),
564
+ nonInteractivePermissions: parseOptionalValue(request.nonInteractivePermissions, isNonInteractivePermissionPolicy),
565
+ permissionPolicy: parseOptionalValue(request.permissionPolicy, isPermissionPolicy),
566
+ suppressSdkConsoleErrors: parseOptionalBoolean(request.suppressSdkConsoleErrors),
567
+ promptRetries: parseNonNegativeInteger(request.promptRetries),
568
+ waitForCompletion: typeof request.waitForCompletion === "boolean" ? request.waitForCompletion : null,
569
+ sessionOptions: parseSessionOptions(request.sessionOptions)
570
+ };
571
+ if (Object.values(parsed).some((value) => value === null)) return null;
572
+ return parsed;
573
+ }
574
+ function parseOptionalValue(value, guard) {
575
+ if (value == null) return;
576
+ return guard(value) ? value : null;
577
+ }
578
+ function parseRequiredValue(value, guard) {
579
+ return guard(value) ? value : null;
580
+ }
581
+ function parseOptionalBoolean(value) {
582
+ if (value == null) return;
583
+ return typeof value === "boolean" ? value : null;
584
+ }
585
+ function parseStringFieldRequest(request, context, type, field) {
586
+ const value = parseNonEmptyString(request[field]);
587
+ if (!value) return null;
588
+ return {
589
+ type,
590
+ ...context,
591
+ [field]: value
592
+ };
593
+ }
594
+ function parseSetConfigOptionRequest(request, context) {
595
+ const configId = parseNonEmptyString(request.configId);
596
+ const value = parseNonEmptyString(request.value);
597
+ if (!configId || !value) return null;
598
+ return {
599
+ type: "set_config_option",
600
+ ...context,
601
+ configId,
602
+ value
603
+ };
604
+ }
605
+ function parseNonEmptyString(value) {
606
+ if (typeof value !== "string" || value.trim().length === 0) return null;
607
+ return value;
608
+ }
609
+ function parseSessionSendResult(raw) {
610
+ const result = asRecord$2(raw);
611
+ if (!result || !hasValidSessionSendResultCore(result)) return null;
612
+ const permissionStats = asRecord$2(result.permissionStats);
613
+ const record = asRecord$2(result.record);
614
+ if (!permissionStats || !record) return null;
615
+ if (!hasValidPermissionStats(permissionStats)) return null;
616
+ if (!hasValidSessionRecordShape(record)) return null;
617
+ return result;
618
+ }
619
+ function hasValidSessionSendResultCore(result) {
620
+ return typeof result.stopReason === "string" && typeof result.sessionId === "string" && typeof result.resumed === "boolean";
621
+ }
622
+ function hasValidPermissionStats(permissionStats) {
623
+ return [
624
+ "requested",
625
+ "approved",
626
+ "denied",
627
+ "cancelled"
628
+ ].every((key) => typeof permissionStats[key] === "number");
629
+ }
630
+ function hasValidSessionRecordShape(record) {
631
+ return hasStringFields(record, [
632
+ "acpxRecordId",
633
+ "acpSessionId",
634
+ "agentCommand",
635
+ "cwd",
636
+ "createdAt",
637
+ "lastUsedAt",
638
+ "updated_at"
639
+ ]) && Array.isArray(record.messages) && typeof record.lastSeq === "number" && Number.isInteger(record.lastSeq) && !!record.eventLog && typeof record.eventLog === "object";
640
+ }
641
+ function hasStringFields(record, keys) {
642
+ return keys.every((key) => typeof record[key] === "string");
643
+ }
644
+ function parseQueueOwnerMessage(raw) {
645
+ const message = asRecord$2(raw);
646
+ if (!message || typeof message.type !== "string" || typeof message.requestId !== "string") return null;
647
+ const ownerGeneration = parseOwnerGeneration(message.ownerGeneration);
648
+ if (ownerGeneration === null) return null;
649
+ return parseTypedQueueOwnerMessage(message, {
650
+ requestId: message.requestId,
651
+ ownerGeneration
652
+ });
653
+ }
654
+ function parseTypedQueueOwnerMessage(message, context) {
655
+ const parser = queueOwnerMessageParser(message.type);
656
+ return parser ? parser(message, context) : null;
657
+ }
658
+ const QUEUE_OWNER_MESSAGE_PARSERS = {
659
+ accepted: (_message, context) => ({
660
+ type: "accepted",
661
+ ...context
662
+ }),
663
+ event: parseEventOwnerMessage,
664
+ permission_escalation: parsePermissionEscalationOwnerMessage,
665
+ result: parseResultOwnerMessage,
666
+ cancel_result: (message, context) => parseBooleanResultOwnerMessage(message, context, "cancel_result", "cancelled"),
667
+ close_session_result: (message, context) => parseBooleanResultOwnerMessage(message, context, "close_session_result", "closed"),
668
+ set_mode_result: (message, context) => parseStringResultOwnerMessage(message, context, "set_mode_result", "modeId"),
669
+ set_model_result: parseSetModelOwnerMessage,
670
+ set_config_option_result: parseSetConfigOptionOwnerMessage,
671
+ error: parseErrorOwnerMessage
672
+ };
673
+ function queueOwnerMessageParser(type) {
674
+ return Object.hasOwn(QUEUE_OWNER_MESSAGE_PARSERS, type) ? QUEUE_OWNER_MESSAGE_PARSERS[type] : void 0;
675
+ }
676
+ function parseEventOwnerMessage(message, context) {
677
+ if (!isAcpJsonRpcMessage(message.message)) return null;
678
+ return {
679
+ type: "event",
680
+ ...context,
681
+ message: message.message
682
+ };
683
+ }
684
+ function parsePermissionEscalationOwnerMessage(message, context) {
685
+ if (!isPermissionEscalationEvent(message.event)) return null;
686
+ return {
687
+ type: "permission_escalation",
688
+ ...context,
689
+ event: message.event
690
+ };
691
+ }
692
+ function parseResultOwnerMessage(message, context) {
693
+ const result = parseSessionSendResult(message.result);
694
+ if (!result) return null;
695
+ return {
696
+ type: "result",
697
+ ...context,
698
+ result
699
+ };
700
+ }
701
+ function parseBooleanResultOwnerMessage(message, context, type, field) {
702
+ if (typeof message[field] !== "boolean") return null;
703
+ return {
704
+ type,
705
+ ...context,
706
+ [field]: message[field]
707
+ };
708
+ }
709
+ function parseStringResultOwnerMessage(message, context, type, field) {
710
+ if (typeof message[field] !== "string") return null;
711
+ return {
712
+ type,
713
+ ...context,
714
+ [field]: message[field]
715
+ };
716
+ }
717
+ function parseSetModelOwnerMessage(message, context) {
718
+ if (typeof message.modelId !== "string") return null;
719
+ const response = asRecord$2(message.response);
720
+ if (message.response !== void 0 && (!response || !Array.isArray(response.configOptions))) return null;
721
+ return {
722
+ type: "set_model_result",
723
+ ...context,
724
+ modelId: message.modelId,
725
+ ...response ? { response } : {}
726
+ };
727
+ }
728
+ function parseSetConfigOptionOwnerMessage(message, context) {
729
+ const response = asRecord$2(message.response);
730
+ if (!response || !Array.isArray(response.configOptions)) return null;
731
+ return {
732
+ type: "set_config_option_result",
733
+ ...context,
734
+ response
735
+ };
736
+ }
737
+ function parseErrorOwnerMessage(message, context) {
738
+ if (!isValidOwnerErrorCore(message)) return null;
739
+ const outputAlreadyEmitted = typeof message.outputAlreadyEmitted === "boolean" ? message.outputAlreadyEmitted : void 0;
740
+ return {
741
+ type: "error",
742
+ ...context,
743
+ code: message.code,
744
+ detailCode: parseNonEmptyString(message.detailCode) ?? void 0,
745
+ origin: message.origin,
746
+ message: message.message,
747
+ retryable: typeof message.retryable === "boolean" ? message.retryable : void 0,
748
+ acp: toAcpErrorPayload(message.acp),
749
+ ...outputAlreadyEmitted === void 0 ? {} : { outputAlreadyEmitted }
750
+ };
751
+ }
752
+ function isValidOwnerErrorCore(message) {
753
+ return typeof message.message === "string" && isOutputErrorCode(message.code) && isOutputErrorOrigin(message.origin);
754
+ }
755
+ //#endregion
756
+ //#region src/cli/queue/ipc-server.ts
757
+ const QUEUE_SOCKET_DRAIN_TIMEOUT_MS = 1e3;
758
+ function makeQueueOwnerError(requestId, message, detailCode, options = {}) {
759
+ return {
760
+ type: "error",
761
+ requestId,
762
+ ownerGeneration: void 0,
763
+ code: "RUNTIME",
764
+ detailCode,
765
+ origin: "queue",
766
+ retryable: options.retryable,
767
+ message
768
+ };
769
+ }
770
+ function makeQueueOwnerErrorFromUnknown(requestId, error, detailCode, options = {}) {
771
+ const normalized = normalizeOutputError(error, {
772
+ defaultCode: "RUNTIME",
773
+ origin: "queue",
774
+ detailCode,
775
+ retryable: options.retryable
776
+ });
777
+ return {
778
+ type: "error",
779
+ requestId,
780
+ code: normalized.code,
781
+ detailCode: normalized.detailCode,
782
+ origin: normalized.origin,
783
+ message: normalized.message,
784
+ retryable: normalized.retryable,
785
+ acp: normalized.acp
786
+ };
787
+ }
788
+ function writeQueueMessage(socket, message) {
789
+ if (socket.destroyed || !socket.writable) return;
790
+ socket.write(`${JSON.stringify(message)}\n`);
791
+ }
792
+ var SessionQueueOwner = class SessionQueueOwner {
793
+ server;
794
+ controlHandlers;
795
+ ownerGeneration;
796
+ maxQueueDepth;
797
+ onQueueDepthChanged;
798
+ pending = [];
799
+ waiters = [];
800
+ sockets = /* @__PURE__ */ new Set();
801
+ taskSockets = /* @__PURE__ */ new Set();
802
+ drainingSockets = /* @__PURE__ */ new Set();
803
+ closed = false;
804
+ constructor(server, controlHandlers, lease, options) {
805
+ this.server = server;
806
+ this.controlHandlers = controlHandlers;
807
+ this.ownerGeneration = lease.ownerGeneration;
808
+ this.maxQueueDepth = Math.max(1, Math.round(options.maxQueueDepth));
809
+ this.onQueueDepthChanged = options.onQueueDepthChanged;
810
+ }
811
+ static async start(lease, controlHandlers, options = { maxQueueDepth: 16 }) {
812
+ const ownerRef = { current: void 0 };
813
+ const server = net.createServer((socket) => {
814
+ ownerRef.current?.handleConnection(socket);
815
+ });
816
+ ownerRef.current = new SessionQueueOwner(server, controlHandlers, lease, options);
817
+ await new Promise((resolve, reject) => {
818
+ const onListening = () => {
819
+ server.off("error", onError);
820
+ resolve();
821
+ };
822
+ const onError = (error) => {
823
+ server.off("listening", onListening);
824
+ reject(error);
825
+ };
826
+ server.once("listening", onListening);
827
+ server.once("error", onError);
828
+ server.listen(lease.socketPath);
829
+ });
830
+ return ownerRef.current;
831
+ }
832
+ beginShutdown() {
833
+ if (this.closed) return;
834
+ this.closed = true;
835
+ for (const waiter of this.waiters.splice(0)) waiter(void 0);
836
+ for (const task of this.pending.splice(0)) {
837
+ if (task.waitForCompletion) task.send(makeQueueOwnerError(task.requestId, "Queue owner shutting down before prompt execution", "QUEUE_OWNER_SHUTTING_DOWN", { retryable: true }));
838
+ task.close();
839
+ }
840
+ for (const socket of this.sockets) if (!this.taskSockets.has(socket) && !this.drainingSockets.has(socket)) socket.destroy();
841
+ this.emitQueueDepth();
842
+ }
843
+ async close() {
844
+ this.beginShutdown();
845
+ await new Promise((resolve) => {
846
+ const forceCloseTimer = setTimeout(() => {
847
+ for (const socket of this.sockets) socket.destroy();
848
+ }, QUEUE_SOCKET_DRAIN_TIMEOUT_MS);
849
+ forceCloseTimer.unref();
850
+ this.server.close(() => {
851
+ clearTimeout(forceCloseTimer);
852
+ resolve();
853
+ });
854
+ });
855
+ }
856
+ async nextTask(timeoutMs) {
857
+ if (this.pending.length > 0) {
858
+ const task = this.pending.shift();
859
+ this.emitQueueDepth();
860
+ if (task) recordPerfDuration("queue.owner.wait_ms", Date.now() - task.enqueuedAt);
861
+ return task;
862
+ }
863
+ if (this.closed) return;
864
+ return await new Promise((resolve) => {
865
+ const timer = timeoutMs != null && setTimeout(() => {
866
+ const index = this.waiters.indexOf(waiter);
867
+ if (index >= 0) this.waiters.splice(index, 1);
868
+ resolve(void 0);
869
+ }, Math.max(0, timeoutMs));
870
+ const waiter = (task) => {
871
+ if (timer) clearTimeout(timer);
872
+ resolve(task);
873
+ };
874
+ this.waiters.push(waiter);
875
+ });
876
+ }
877
+ queueDepth() {
878
+ return this.pending.length;
879
+ }
880
+ emitQueueDepth() {
881
+ this.onQueueDepthChanged?.(this.pending.length);
882
+ }
883
+ enqueue(task) {
884
+ if (this.closed) {
885
+ task.send(makeQueueOwnerError(task.requestId, "Queue owner is shutting down", "QUEUE_OWNER_SHUTTING_DOWN", { retryable: true }));
886
+ task.close();
887
+ return false;
888
+ }
889
+ const waiter = this.waiters.shift();
890
+ if (waiter) {
891
+ waiter(task);
892
+ return true;
893
+ }
894
+ if (this.pending.length >= this.maxQueueDepth) {
895
+ task.send({
896
+ ...makeQueueOwnerError(task.requestId, `Queue owner is overloaded (${this.pending.length}/${this.maxQueueDepth} queued)`, "QUEUE_OWNER_OVERLOADED", { retryable: true }),
897
+ ownerGeneration: this.ownerGeneration
898
+ });
899
+ task.close();
900
+ return false;
901
+ }
902
+ this.pending.push(task);
903
+ this.emitQueueDepth();
904
+ return true;
905
+ }
906
+ handleControlRequest(options) {
907
+ writeQueueMessage(options.socket, {
908
+ type: "accepted",
909
+ requestId: options.requestId,
910
+ ownerGeneration: this.ownerGeneration
911
+ });
912
+ options.run().then((message) => {
913
+ writeQueueMessage(options.socket, {
914
+ ...message,
915
+ ownerGeneration: this.ownerGeneration
916
+ });
917
+ }).catch((error) => {
918
+ writeQueueMessage(options.socket, {
919
+ ...makeQueueOwnerErrorFromUnknown(options.requestId, error, "QUEUE_CONTROL_REQUEST_FAILED"),
920
+ ownerGeneration: this.ownerGeneration
921
+ });
922
+ }).finally(() => {
923
+ this.endSocket(options.socket);
924
+ });
925
+ }
926
+ endSocket(socket) {
927
+ if (socket.destroyed || this.drainingSockets.has(socket)) return;
928
+ this.taskSockets.delete(socket);
929
+ this.drainingSockets.add(socket);
930
+ socket.end(() => {
931
+ this.drainingSockets.delete(socket);
932
+ socket.destroy();
933
+ });
934
+ }
935
+ failRequest(socket, requestId, message, detailCode) {
936
+ writeQueueMessage(socket, {
937
+ ...makeQueueOwnerError(requestId, message, detailCode, { retryable: false }),
938
+ ownerGeneration: this.ownerGeneration
939
+ });
940
+ this.endSocket(socket);
941
+ }
942
+ parseRequestLine(socket, line) {
943
+ let parsed;
944
+ try {
945
+ parsed = JSON.parse(line);
946
+ } catch {
947
+ this.failRequest(socket, "unknown", "Invalid queue request payload", "QUEUE_REQUEST_PAYLOAD_INVALID_JSON");
948
+ return;
949
+ }
950
+ const request = parseQueueRequest(parsed);
951
+ if (!request) this.failRequest(socket, "unknown", "Invalid queue request", "QUEUE_REQUEST_INVALID");
952
+ return request ?? void 0;
953
+ }
954
+ rejectStaleOwnerGeneration(socket, request) {
955
+ if (request.ownerGeneration === void 0 || this.ownerGeneration === void 0 || request.ownerGeneration === this.ownerGeneration) return false;
956
+ this.failRequest(socket, request.requestId, "Queue request targeted a stale queue owner generation", "QUEUE_OWNER_GENERATION_MISMATCH");
957
+ return true;
958
+ }
959
+ rejectClosedOwner(socket, request) {
960
+ if (!this.closed) return false;
961
+ writeQueueMessage(socket, {
962
+ ...makeQueueOwnerError(request.requestId, "Queue owner is shutting down", "QUEUE_OWNER_CLOSED", { retryable: true }),
963
+ ownerGeneration: this.ownerGeneration
964
+ });
965
+ this.endSocket(socket);
966
+ return true;
967
+ }
968
+ handleControlQueueRequest(socket, request) {
969
+ if (request.type === "cancel_prompt") {
970
+ this.handleControlRequest({
971
+ socket,
972
+ requestId: request.requestId,
973
+ run: async () => ({
974
+ type: "cancel_result",
975
+ requestId: request.requestId,
976
+ cancelled: await this.controlHandlers.cancelPrompt()
977
+ })
978
+ });
979
+ return true;
980
+ }
981
+ if (request.type === "close_session") {
982
+ this.handleControlRequest({
983
+ socket,
984
+ requestId: request.requestId,
985
+ run: async () => ({
986
+ type: "close_session_result",
987
+ requestId: request.requestId,
988
+ closed: await this.controlHandlers.closeSession(request.timeoutMs)
989
+ })
990
+ });
991
+ return true;
992
+ }
993
+ return this.handleSessionControlQueueRequest(socket, request);
994
+ }
995
+ handleSessionControlQueueRequest(socket, request) {
996
+ if (request.type === "set_mode") {
997
+ this.handleControlRequest({
998
+ socket,
999
+ requestId: request.requestId,
1000
+ run: async () => {
1001
+ await this.controlHandlers.setSessionMode(request.modeId, request.timeoutMs);
1002
+ return {
1003
+ type: "set_mode_result",
1004
+ requestId: request.requestId,
1005
+ modeId: request.modeId
1006
+ };
1007
+ }
1008
+ });
1009
+ return true;
1010
+ }
1011
+ if (request.type === "set_model") {
1012
+ this.handleControlRequest({
1013
+ socket,
1014
+ requestId: request.requestId,
1015
+ run: async () => {
1016
+ const response = await this.controlHandlers.setSessionModel(request.modelId, request.timeoutMs);
1017
+ return {
1018
+ type: "set_model_result",
1019
+ requestId: request.requestId,
1020
+ modelId: request.modelId,
1021
+ response
1022
+ };
1023
+ }
1024
+ });
1025
+ return true;
1026
+ }
1027
+ if (request.type === "set_config_option") {
1028
+ this.handleControlRequest({
1029
+ socket,
1030
+ requestId: request.requestId,
1031
+ run: async () => ({
1032
+ type: "set_config_option_result",
1033
+ requestId: request.requestId,
1034
+ response: await this.controlHandlers.setSessionConfigOption(request.configId, request.value, request.timeoutMs)
1035
+ })
1036
+ });
1037
+ return true;
1038
+ }
1039
+ return false;
1040
+ }
1041
+ enqueuePromptRequest(socket, request) {
1042
+ this.taskSockets.add(socket);
1043
+ const task = {
1044
+ requestId: request.requestId,
1045
+ message: request.message,
1046
+ prompt: request.prompt ?? textPrompt(request.message),
1047
+ permissionMode: request.permissionMode,
1048
+ resumePolicy: request.resumePolicy,
1049
+ nonInteractivePermissions: request.nonInteractivePermissions,
1050
+ permissionPolicy: request.permissionPolicy,
1051
+ timeoutMs: request.timeoutMs,
1052
+ suppressSdkConsoleErrors: request.suppressSdkConsoleErrors,
1053
+ promptRetries: request.promptRetries,
1054
+ sessionOptions: request.sessionOptions,
1055
+ waitForCompletion: request.waitForCompletion,
1056
+ enqueuedAt: Date.now(),
1057
+ send: (message) => {
1058
+ writeQueueMessage(socket, {
1059
+ ...message,
1060
+ ownerGeneration: this.ownerGeneration
1061
+ });
1062
+ },
1063
+ close: () => {
1064
+ this.endSocket(socket);
1065
+ }
1066
+ };
1067
+ if (!this.enqueue(task)) return;
1068
+ writeQueueMessage(socket, {
1069
+ type: "accepted",
1070
+ requestId: request.requestId,
1071
+ ownerGeneration: this.ownerGeneration
1072
+ });
1073
+ if (!request.waitForCompletion) task.close();
1074
+ }
1075
+ handleConnection(socket) {
1076
+ this.sockets.add(socket);
1077
+ socket.setEncoding("utf8");
1078
+ socket.once("close", () => {
1079
+ this.sockets.delete(socket);
1080
+ this.taskSockets.delete(socket);
1081
+ this.drainingSockets.delete(socket);
1082
+ });
1083
+ let buffer = "";
1084
+ let handled = false;
1085
+ const processLine = (line) => {
1086
+ if (handled) return;
1087
+ handled = true;
1088
+ const request = this.parseRequestLine(socket, line);
1089
+ if (!request || this.rejectClosedOwner(socket, request) || this.rejectStaleOwnerGeneration(socket, request)) return;
1090
+ if (this.handleControlQueueRequest(socket, request)) return;
1091
+ if (request.type !== "submit_prompt") {
1092
+ this.failRequest(socket, request.requestId, "Invalid queue request", "QUEUE_REQUEST_INVALID");
1093
+ return;
1094
+ }
1095
+ this.enqueuePromptRequest(socket, request);
1096
+ };
1097
+ socket.on("data", (chunk) => {
1098
+ buffer += chunk;
1099
+ let index = buffer.indexOf("\n");
1100
+ while (index >= 0) {
1101
+ const line = buffer.slice(0, index).trim();
1102
+ buffer = buffer.slice(index + 1);
1103
+ if (line.length > 0) processLine(line);
1104
+ index = buffer.indexOf("\n");
1105
+ }
1106
+ });
1107
+ socket.on("error", () => {});
1108
+ }
1109
+ };
1110
+ //#endregion
1111
+ //#region src/cli/queue/ipc.ts
1112
+ const MAX_MESSAGE_BUFFER_SIZE = 10 * 1024 * 1024;
1113
+ const STALE_OWNER_PROTOCOL_DETAIL_CODES = /* @__PURE__ */ new Set(["QUEUE_PROTOCOL_MALFORMED_MESSAGE", "QUEUE_PROTOCOL_UNEXPECTED_RESPONSE"]);
1114
+ async function maybeRecoverStaleOwnerAfterProtocolMismatch(params) {
1115
+ if (!(params.error instanceof QueueProtocolError)) return false;
1116
+ const detailCode = params.error.detailCode;
1117
+ if (!detailCode || !STALE_OWNER_PROTOCOL_DETAIL_CODES.has(detailCode)) return false;
1118
+ await terminateQueueOwnerForSession(params.sessionId).catch(() => {});
1119
+ incrementPerfCounter("queue.owner.stale_recovered");
1120
+ if (params.verbose) process.stderr.write(`[acpx] dropped stale queue owner metadata after protocol mismatch for session ${params.sessionId} (${detailCode})\n`);
1121
+ return true;
1122
+ }
1123
+ function assertOwnerGeneration(owner, message) {
1124
+ if (owner.ownerGeneration !== void 0 && message.ownerGeneration !== void 0 && message.ownerGeneration !== owner.ownerGeneration) throw new QueueProtocolError("Queue owner returned mismatched generation", {
1125
+ detailCode: "QUEUE_OWNER_GENERATION_MISMATCH",
1126
+ origin: "queue",
1127
+ retryable: true
1128
+ });
1129
+ return message;
1130
+ }
1131
+ function queueConnectionErrorFromOwner(message, outputAlreadyEmitted) {
1132
+ return new QueueConnectionError(message.message, {
1133
+ outputCode: message.code,
1134
+ detailCode: message.detailCode,
1135
+ origin: message.origin ?? "queue",
1136
+ retryable: message.retryable,
1137
+ acp: message.acp,
1138
+ ...outputAlreadyEmitted ? { outputAlreadyEmitted: true } : {}
1139
+ });
1140
+ }
1141
+ function makeMalformedQueueMessageError() {
1142
+ return new QueueProtocolError("Queue owner sent malformed message", {
1143
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1144
+ origin: "queue",
1145
+ retryable: true
1146
+ });
1147
+ }
1148
+ function emitQueueOwnerError(formatter, policy, sessionId, message) {
1149
+ formatter.setContext({ sessionId });
1150
+ const queueErrorAlreadyEmitted = policy?.queueErrorAlreadyEmitted ?? true;
1151
+ const shouldEmitInFormatter = message.outputAlreadyEmitted !== true || !queueErrorAlreadyEmitted;
1152
+ if (shouldEmitInFormatter) {
1153
+ formatter.onError({
1154
+ code: message.code ?? "RUNTIME",
1155
+ detailCode: message.detailCode,
1156
+ origin: message.origin ?? "queue",
1157
+ message: message.message,
1158
+ retryable: message.retryable,
1159
+ acp: message.acp
1160
+ });
1161
+ formatter.flush();
1162
+ }
1163
+ return queueConnectionErrorFromOwner(message, queueErrorAlreadyEmitted || shouldEmitInFormatter);
1164
+ }
1165
+ function parseQueueOwnerResponseLine(owner, requestId, line) {
1166
+ let parsed;
1167
+ try {
1168
+ parsed = JSON.parse(line);
1169
+ } catch {
1170
+ throw new QueueProtocolError("Queue owner sent invalid JSON payload", {
1171
+ detailCode: "QUEUE_PROTOCOL_INVALID_JSON",
1172
+ origin: "queue",
1173
+ retryable: true
1174
+ });
1175
+ }
1176
+ const parsedMessage = parseQueueOwnerMessage(parsed);
1177
+ if (!parsedMessage) throw makeMalformedQueueMessageError();
1178
+ const message = assertOwnerGeneration(owner, parsedMessage);
1179
+ if (message.requestId !== requestId) throw makeMalformedQueueMessageError();
1180
+ return message;
1181
+ }
1182
+ async function runQueueOwnerRequest(options) {
1183
+ const socket = await connectToQueueOwner(options.owner);
1184
+ if (!socket) return;
1185
+ socket.setEncoding("utf8");
1186
+ return await new Promise((resolve, reject) => {
1187
+ let settled = false;
1188
+ let buffer = "";
1189
+ const state = { acknowledged: false };
1190
+ const finishResolve = (result) => {
1191
+ if (settled) return;
1192
+ settled = true;
1193
+ socket.removeAllListeners();
1194
+ if (!socket.destroyed) socket.end();
1195
+ resolve(result);
1196
+ };
1197
+ const finishReject = (error) => {
1198
+ if (settled) return;
1199
+ settled = true;
1200
+ socket.removeAllListeners();
1201
+ if (!socket.destroyed) socket.destroy();
1202
+ reject(error);
1203
+ };
1204
+ const controls = {
1205
+ state,
1206
+ resolve: finishResolve,
1207
+ reject: finishReject
1208
+ };
1209
+ const processLine = (line) => {
1210
+ let message;
1211
+ try {
1212
+ message = parseQueueOwnerResponseLine(options.owner, options.request.requestId, line);
1213
+ } catch (error) {
1214
+ finishReject(error);
1215
+ return;
1216
+ }
1217
+ if (message.type === "accepted") {
1218
+ state.acknowledged = true;
1219
+ options.onAccepted?.(controls);
1220
+ return;
1221
+ }
1222
+ options.onMessage(message, controls);
1223
+ };
1224
+ socket.on("data", (chunk) => {
1225
+ buffer += chunk;
1226
+ if (buffer.length > 10485760) {
1227
+ socket.destroy();
1228
+ finishReject(/* @__PURE__ */ new Error(`Message buffer exceeded ${MAX_MESSAGE_BUFFER_SIZE} bytes`));
1229
+ return;
1230
+ }
1231
+ let index = buffer.indexOf("\n");
1232
+ while (index >= 0) {
1233
+ const line = buffer.slice(0, index).trim();
1234
+ buffer = buffer.slice(index + 1);
1235
+ if (line.length > 0) processLine(line);
1236
+ index = buffer.indexOf("\n");
1237
+ }
1238
+ });
1239
+ socket.once("error", (error) => {
1240
+ finishReject(error);
1241
+ });
1242
+ socket.once("close", () => {
1243
+ if (settled) return;
1244
+ options.onClose(controls);
1245
+ });
1246
+ socket.write(`${JSON.stringify(options.request)}\n`);
1247
+ });
1248
+ }
1249
+ function missingQueueAckError() {
1250
+ return new QueueConnectionError("Queue owner did not acknowledge request", {
1251
+ detailCode: "QUEUE_ACK_MISSING",
1252
+ origin: "queue",
1253
+ retryable: true
1254
+ });
1255
+ }
1256
+ function unexpectedQueueResponseError() {
1257
+ return new QueueProtocolError("Queue owner returned unexpected response", {
1258
+ detailCode: "QUEUE_PROTOCOL_UNEXPECTED_RESPONSE",
1259
+ origin: "queue",
1260
+ retryable: true
1261
+ });
1262
+ }
1263
+ function handleAcknowledgedSubmitMessage(message, controls, formatter) {
1264
+ if (message.type === "event") {
1265
+ formatter.onAcpMessage(message.message);
1266
+ return;
1267
+ }
1268
+ if (message.type === "permission_escalation") {
1269
+ formatter.onPermissionEscalation(message.event);
1270
+ return;
1271
+ }
1272
+ if (message.type === "result") {
1273
+ formatter.flush();
1274
+ controls.resolve(message.result);
1275
+ return;
1276
+ }
1277
+ controls.reject(unexpectedQueueResponseError());
1278
+ }
1279
+ function handleSubmitQueueOwnerMessage(message, controls, options) {
1280
+ if (message.type === "error") {
1281
+ controls.reject(emitQueueOwnerError(options.outputFormatter, options.errorEmissionPolicy, options.sessionId, message));
1282
+ return;
1283
+ }
1284
+ if (!controls.state.acknowledged) {
1285
+ controls.reject(missingQueueAckError());
1286
+ return;
1287
+ }
1288
+ handleAcknowledgedSubmitMessage(message, controls, options.outputFormatter);
1289
+ }
1290
+ async function submitToQueueOwner(owner, options) {
1291
+ const requestId = randomUUID();
1292
+ const request = {
1293
+ type: "submit_prompt",
1294
+ requestId,
1295
+ ownerGeneration: owner.ownerGeneration,
1296
+ message: options.message,
1297
+ prompt: options.prompt,
1298
+ permissionMode: options.permissionMode,
1299
+ resumePolicy: options.resumePolicy,
1300
+ nonInteractivePermissions: options.nonInteractivePermissions,
1301
+ permissionPolicy: options.permissionPolicy,
1302
+ timeoutMs: options.timeoutMs,
1303
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
1304
+ promptRetries: options.promptRetries ?? 0,
1305
+ waitForCompletion: options.waitForCompletion,
1306
+ sessionOptions: options.sessionOptions
1307
+ };
1308
+ options.outputFormatter.setContext({ sessionId: options.sessionId });
1309
+ return await runQueueOwnerRequest({
1310
+ owner,
1311
+ request,
1312
+ onAccepted: ({ resolve }) => {
1313
+ options.outputFormatter.setContext({ sessionId: options.sessionId });
1314
+ if (!options.waitForCompletion) resolve({
1315
+ queued: true,
1316
+ sessionId: options.sessionId,
1317
+ requestId
1318
+ });
1319
+ },
1320
+ onMessage: (message, controls) => {
1321
+ handleSubmitQueueOwnerMessage(message, controls, options);
1322
+ },
1323
+ onClose: ({ state, resolve, reject }) => {
1324
+ if (!state.acknowledged) {
1325
+ reject(new QueueConnectionError("Queue owner disconnected before acknowledging request", {
1326
+ detailCode: "QUEUE_DISCONNECTED_BEFORE_ACK",
1327
+ origin: "queue",
1328
+ retryable: true
1329
+ }));
1330
+ return;
1331
+ }
1332
+ if (!options.waitForCompletion) {
1333
+ resolve({
1334
+ queued: true,
1335
+ sessionId: options.sessionId,
1336
+ requestId
1337
+ });
1338
+ return;
1339
+ }
1340
+ reject(new QueueConnectionError("Queue owner disconnected before prompt completion", {
1341
+ detailCode: "QUEUE_DISCONNECTED_BEFORE_COMPLETION",
1342
+ origin: "queue",
1343
+ retryable: true
1344
+ }));
1345
+ }
1346
+ });
1347
+ }
1348
+ async function submitControlToQueueOwner(owner, request, isExpectedResponse) {
1349
+ return await runQueueOwnerRequest({
1350
+ owner,
1351
+ request,
1352
+ onMessage: (message, { state, resolve, reject }) => {
1353
+ if (message.type === "error") {
1354
+ reject(new QueueConnectionError(message.message, {
1355
+ outputCode: message.code,
1356
+ detailCode: message.detailCode,
1357
+ origin: message.origin ?? "queue",
1358
+ retryable: message.retryable,
1359
+ acp: message.acp
1360
+ }));
1361
+ return;
1362
+ }
1363
+ if (!state.acknowledged) {
1364
+ reject(new QueueConnectionError("Queue owner did not acknowledge request", {
1365
+ detailCode: "QUEUE_ACK_MISSING",
1366
+ origin: "queue",
1367
+ retryable: true
1368
+ }));
1369
+ return;
1370
+ }
1371
+ if (!isExpectedResponse(message)) {
1372
+ reject(new QueueProtocolError("Queue owner returned unexpected response", {
1373
+ detailCode: "QUEUE_PROTOCOL_UNEXPECTED_RESPONSE",
1374
+ origin: "queue",
1375
+ retryable: true
1376
+ }));
1377
+ return;
1378
+ }
1379
+ resolve(message);
1380
+ },
1381
+ onClose: ({ state, reject }) => {
1382
+ if (!state.acknowledged) {
1383
+ reject(new QueueConnectionError("Queue owner disconnected before acknowledging request", {
1384
+ detailCode: "QUEUE_DISCONNECTED_BEFORE_ACK",
1385
+ origin: "queue",
1386
+ retryable: true
1387
+ }));
1388
+ return;
1389
+ }
1390
+ reject(new QueueConnectionError("Queue owner disconnected before responding", {
1391
+ detailCode: "QUEUE_DISCONNECTED_BEFORE_COMPLETION",
1392
+ origin: "queue",
1393
+ retryable: true
1394
+ }));
1395
+ }
1396
+ });
1397
+ }
1398
+ async function submitCancelToQueueOwner(owner) {
1399
+ const request = {
1400
+ type: "cancel_prompt",
1401
+ requestId: randomUUID(),
1402
+ ownerGeneration: owner.ownerGeneration
1403
+ };
1404
+ const response = await submitControlToQueueOwner(owner, request, (message) => message.type === "cancel_result");
1405
+ if (!response) return;
1406
+ if (response.requestId !== request.requestId) throw new QueueProtocolError("Queue owner returned mismatched cancel response", {
1407
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1408
+ origin: "queue",
1409
+ retryable: true
1410
+ });
1411
+ return response.cancelled;
1412
+ }
1413
+ async function submitSetModeToQueueOwner(owner, modeId, timeoutMs) {
1414
+ const request = {
1415
+ type: "set_mode",
1416
+ requestId: randomUUID(),
1417
+ ownerGeneration: owner.ownerGeneration,
1418
+ modeId,
1419
+ timeoutMs
1420
+ };
1421
+ const response = await submitControlToQueueOwner(owner, request, (message) => message.type === "set_mode_result");
1422
+ if (!response) return;
1423
+ if (response.requestId !== request.requestId) throw new QueueProtocolError("Queue owner returned mismatched set_mode response", {
1424
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1425
+ origin: "queue",
1426
+ retryable: true
1427
+ });
1428
+ return true;
1429
+ }
1430
+ async function submitSetModelToQueueOwner(owner, modelId, timeoutMs) {
1431
+ const request = {
1432
+ type: "set_model",
1433
+ requestId: randomUUID(),
1434
+ ownerGeneration: owner.ownerGeneration,
1435
+ modelId,
1436
+ timeoutMs
1437
+ };
1438
+ const response = await submitControlToQueueOwner(owner, request, (message) => message.type === "set_model_result");
1439
+ if (!response) return;
1440
+ if (response.requestId !== request.requestId) throw new QueueProtocolError("Queue owner returned mismatched set_model response", {
1441
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1442
+ origin: "queue",
1443
+ retryable: true
1444
+ });
1445
+ return response;
1446
+ }
1447
+ async function submitSetConfigOptionToQueueOwner(owner, configId, value, timeoutMs) {
1448
+ const request = {
1449
+ type: "set_config_option",
1450
+ requestId: randomUUID(),
1451
+ ownerGeneration: owner.ownerGeneration,
1452
+ configId,
1453
+ value,
1454
+ timeoutMs
1455
+ };
1456
+ const response = await submitControlToQueueOwner(owner, request, (message) => message.type === "set_config_option_result");
1457
+ if (!response) return;
1458
+ if (response.requestId !== request.requestId) throw new QueueProtocolError("Queue owner returned mismatched set_config_option response", {
1459
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1460
+ origin: "queue",
1461
+ retryable: true
1462
+ });
1463
+ return response.response;
1464
+ }
1465
+ async function submitCloseSessionToQueueOwner(owner, timeoutMs) {
1466
+ const request = {
1467
+ type: "close_session",
1468
+ requestId: randomUUID(),
1469
+ ownerGeneration: owner.ownerGeneration,
1470
+ timeoutMs
1471
+ };
1472
+ const response = await submitControlToQueueOwner(owner, request, (message) => message.type === "close_session_result");
1473
+ if (!response) return;
1474
+ if (response.requestId !== request.requestId) throw new QueueProtocolError("Queue owner returned mismatched close_session response", {
1475
+ detailCode: "QUEUE_PROTOCOL_MALFORMED_MESSAGE",
1476
+ origin: "queue",
1477
+ retryable: true
1478
+ });
1479
+ return response.closed;
1480
+ }
1481
+ function queueOwnerMcpConfigMatches(owner, options) {
1482
+ return owner.mcpConfigPath === options.mcpConfigPath && owner.mcpConfigFingerprint === options.mcpConfigFingerprint;
1483
+ }
1484
+ function assertQueueOwnerMcpConfigMatches(owner, options) {
1485
+ if (queueOwnerMcpConfigMatches(owner, options)) return;
1486
+ throw new QueueConnectionError("Session queue owner uses a different MCP config; close the session before retrying", {
1487
+ detailCode: "QUEUE_MCP_CONFIG_CONFLICT",
1488
+ origin: "queue",
1489
+ retryable: false
1490
+ });
1491
+ }
1492
+ async function trySubmitToRunningOwner(options) {
1493
+ const owner = await readQueueOwnerRecord(options.sessionId);
1494
+ if (!owner) return;
1495
+ if (!await ensureOwnerIsUsable(options.sessionId, owner)) return;
1496
+ assertQueueOwnerMcpConfigMatches(owner, options);
1497
+ let submitted;
1498
+ try {
1499
+ submitted = await submitToQueueOwner(owner, options);
1500
+ } catch (error) {
1501
+ if (await maybeRecoverStaleOwnerAfterProtocolMismatch({
1502
+ sessionId: options.sessionId,
1503
+ owner,
1504
+ error,
1505
+ verbose: options.verbose
1506
+ })) return;
1507
+ throw error;
1508
+ }
1509
+ if (submitted) {
1510
+ if (options.verbose) process.stderr.write(`[acpx] queued prompt on active owner pid ${owner.pid} for session ${options.sessionId}\n`);
1511
+ return submitted;
1512
+ }
1513
+ if (!(await probeQueueOwnerHealth(options.sessionId)).hasLease) return;
1514
+ throw new QueueConnectionError("Session queue owner is running but not accepting queue requests", {
1515
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1516
+ origin: "queue",
1517
+ retryable: true
1518
+ });
1519
+ }
1520
+ async function tryCloseSessionOnRunningOwner(options) {
1521
+ const owner = await readQueueOwnerRecord(options.sessionId);
1522
+ if (!owner) return;
1523
+ const closed = await submitCloseSessionToQueueOwner(owner, options.timeoutMs);
1524
+ if (closed !== void 0) {
1525
+ if (options.verbose) process.stderr.write(`[acpx] requested session/close on active owner pid ${owner.pid} for session ${options.sessionId}\n`);
1526
+ return closed;
1527
+ }
1528
+ if (!(await probeQueueOwnerHealth(options.sessionId)).hasLease) return;
1529
+ throw new QueueConnectionError("Session queue owner is running but not accepting close_session requests", {
1530
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1531
+ origin: "queue",
1532
+ retryable: true
1533
+ });
1534
+ }
1535
+ async function tryCancelOnRunningOwner(options) {
1536
+ const owner = await readQueueOwnerRecord(options.sessionId);
1537
+ if (!owner) return;
1538
+ const cancelled = await submitCancelToQueueOwner(owner);
1539
+ if (cancelled !== void 0) {
1540
+ if (options.verbose) process.stderr.write(`[acpx] requested cancel on active owner pid ${owner.pid} for session ${options.sessionId}\n`);
1541
+ return cancelled;
1542
+ }
1543
+ if (!(await probeQueueOwnerHealth(options.sessionId)).hasLease) return;
1544
+ throw new QueueConnectionError("Session queue owner is running but not accepting cancel requests", {
1545
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1546
+ origin: "queue",
1547
+ retryable: true
1548
+ });
1549
+ }
1550
+ async function trySetModeOnRunningOwner(sessionId, modeId, timeoutMs, verbose) {
1551
+ const owner = await readQueueOwnerRecord(sessionId);
1552
+ if (!owner) return;
1553
+ if (await submitSetModeToQueueOwner(owner, modeId, timeoutMs)) {
1554
+ if (verbose) process.stderr.write(`[acpx] requested session/set_mode on owner pid ${owner.pid} for session ${sessionId}\n`);
1555
+ return true;
1556
+ }
1557
+ if (!(await probeQueueOwnerHealth(sessionId)).hasLease) return;
1558
+ throw new QueueConnectionError("Session queue owner is running but not accepting set_mode requests", {
1559
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1560
+ origin: "queue",
1561
+ retryable: true
1562
+ });
1563
+ }
1564
+ async function trySetModelOnRunningOwner(sessionId, modelId, timeoutMs, verbose) {
1565
+ const owner = await readQueueOwnerRecord(sessionId);
1566
+ if (!owner) return;
1567
+ const submitted = await submitSetModelToQueueOwner(owner, modelId, timeoutMs);
1568
+ if (submitted) {
1569
+ if (verbose) process.stderr.write(`[acpx] requested a model config update on owner pid ${owner.pid} for session ${sessionId}\n`);
1570
+ return submitted;
1571
+ }
1572
+ if (!(await probeQueueOwnerHealth(sessionId)).hasLease) return;
1573
+ throw new QueueConnectionError("Session queue owner is running but not accepting set_model requests", {
1574
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1575
+ origin: "queue",
1576
+ retryable: true
1577
+ });
1578
+ }
1579
+ async function trySetConfigOptionOnRunningOwner(sessionId, configId, value, timeoutMs, verbose) {
1580
+ const owner = await readQueueOwnerRecord(sessionId);
1581
+ if (!owner) return;
1582
+ const response = await submitSetConfigOptionToQueueOwner(owner, configId, value, timeoutMs);
1583
+ if (response) {
1584
+ if (verbose) process.stderr.write(`[acpx] requested session/set_config_option on owner pid ${owner.pid} for session ${sessionId}\n`);
1585
+ return response;
1586
+ }
1587
+ if (!(await probeQueueOwnerHealth(sessionId)).hasLease) return;
1588
+ throw new QueueConnectionError("Session queue owner is running but not accepting set_config_option requests", {
1589
+ detailCode: "QUEUE_NOT_ACCEPTING_REQUESTS",
1590
+ origin: "queue",
1591
+ retryable: true
1592
+ });
1593
+ }
1594
+ //#endregion
1595
+ //#region src/cli/session/prompt-runner.ts
1596
+ function buildDirectConnectedSessionOptions(options, run) {
1597
+ return {
1598
+ sessionRecordId: options.sessionRecordId,
1599
+ loadRecord: resolveSessionRecord,
1600
+ saveRecord: writeSessionRecord,
1601
+ mcpServers: options.mcpServers,
1602
+ nonInteractivePermissions: options.nonInteractivePermissions,
1603
+ authCredentials: options.authCredentials,
1604
+ authPolicy: options.authPolicy,
1605
+ terminal: options.terminal,
1606
+ timeoutMs: options.timeoutMs,
1607
+ verbose: options.verbose,
1608
+ onClientAvailable: (controller) => {
1609
+ options.onClientAvailable?.(controller);
1610
+ },
1611
+ onClientClosed: options.onClientClosed,
1612
+ run
1613
+ };
1614
+ }
1615
+ function toSessionMutationResult(result) {
1616
+ return {
1617
+ record: result.record,
1618
+ resumed: result.resumed,
1619
+ loadError: result.loadError
1620
+ };
1621
+ }
1622
+ async function runSessionSetModeDirect(options) {
1623
+ return toSessionMutationResult(await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
1624
+ await withTimeout(client.setSessionMode(sessionId, options.modeId), options.timeoutMs);
1625
+ setDesiredModeId(record, options.modeId);
1626
+ })));
1627
+ }
1628
+ async function runSessionSetModelDirect(options) {
1629
+ const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
1630
+ const models = advertisedModelState(record.acpx);
1631
+ const response = await withTimeout(client.setSessionModel(sessionId, options.modelId, models), options.timeoutMs);
1632
+ applyConfigOptionsToRecord(record, response);
1633
+ setDesiredModelId(record, options.modelId, models?.configId);
1634
+ setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.modelId));
1635
+ return response;
1636
+ }));
1637
+ return {
1638
+ ...toSessionMutationResult(result),
1639
+ response: result.value
1640
+ };
1641
+ }
1642
+ async function runSessionSetConfigOptionDirect(options) {
1643
+ const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
1644
+ const modelConfigId = advertisedModelState(record.acpx)?.configId;
1645
+ const response = await withTimeout(client.setSessionConfigOption(sessionId, options.configId, options.value), options.timeoutMs);
1646
+ applyConfigOptionsToRecord(record, response);
1647
+ if (options.configId === modelConfigId) {
1648
+ setDesiredModelId(record, options.value, options.configId);
1649
+ setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.value));
1650
+ } else if (options.configId === "mode") setDesiredModeId(record, options.value);
1651
+ else setDesiredConfigOption(record, options.configId, options.value);
1652
+ return response;
1653
+ }));
1654
+ return {
1655
+ record: result.record,
1656
+ response: result.value,
1657
+ resumed: result.resumed,
1658
+ loadError: result.loadError
1659
+ };
1660
+ }
1661
+ //#endregion
1662
+ //#region src/cli/session/session-control.ts
1663
+ const execFileAsync = promisify(execFile);
1664
+ async function cancelSessionPrompt(options) {
1665
+ const cancelled = await tryCancelOnRunningOwner(options);
1666
+ return {
1667
+ sessionId: options.sessionId,
1668
+ cancelled: cancelled === true
1669
+ };
1670
+ }
1671
+ async function setSessionMode(options) {
1672
+ if (await trySetModeOnRunningOwner(options.sessionId, options.modeId, options.timeoutMs, options.verbose)) {
1673
+ const record = await resolveSessionRecord(options.sessionId);
1674
+ setDesiredModeId(record, options.modeId);
1675
+ await writeSessionRecord(record);
1676
+ return {
1677
+ record,
1678
+ resumed: false
1679
+ };
1680
+ }
1681
+ return await runSessionSetModeDirect({
1682
+ sessionRecordId: options.sessionId,
1683
+ modeId: options.modeId,
1684
+ mcpServers: options.mcpServers,
1685
+ nonInteractivePermissions: options.nonInteractivePermissions,
1686
+ authCredentials: options.authCredentials,
1687
+ authPolicy: options.authPolicy,
1688
+ terminal: options.terminal,
1689
+ timeoutMs: options.timeoutMs,
1690
+ verbose: options.verbose
1691
+ });
1692
+ }
1693
+ async function setSessionModel(options) {
1694
+ const submittedToOwner = await trySetModelOnRunningOwner(options.sessionId, options.modelId, options.timeoutMs, options.verbose);
1695
+ if (submittedToOwner) {
1696
+ const record = await resolveSessionRecord(options.sessionId);
1697
+ applyConfigOptionsToRecord(record, submittedToOwner.response);
1698
+ setDesiredModelId(record, options.modelId, advertisedModelState(record.acpx)?.configId);
1699
+ setCurrentModelId(record, currentModelIdFromSetModelResponse(submittedToOwner.response, options.modelId));
1700
+ await writeSessionRecord(record);
1701
+ return {
1702
+ record,
1703
+ response: submittedToOwner.response,
1704
+ resumed: false
1705
+ };
1706
+ }
1707
+ return await runSessionSetModelDirect({
1708
+ sessionRecordId: options.sessionId,
1709
+ modelId: options.modelId,
1710
+ mcpServers: options.mcpServers,
1711
+ nonInteractivePermissions: options.nonInteractivePermissions,
1712
+ authCredentials: options.authCredentials,
1713
+ authPolicy: options.authPolicy,
1714
+ terminal: options.terminal,
1715
+ timeoutMs: options.timeoutMs,
1716
+ verbose: options.verbose
1717
+ });
1718
+ }
1719
+ async function setSessionConfigOption(options) {
1720
+ const ownerResponse = await trySetConfigOptionOnRunningOwner(options.sessionId, options.configId, options.value, options.timeoutMs, options.verbose);
1721
+ if (ownerResponse) {
1722
+ const record = await resolveSessionRecord(options.sessionId);
1723
+ const modelConfigId = advertisedModelState(record.acpx)?.configId;
1724
+ applyConfigOptionsToRecord(record, ownerResponse);
1725
+ if (options.configId === modelConfigId) {
1726
+ setDesiredModelId(record, options.value, options.configId);
1727
+ setCurrentModelId(record, currentModelIdFromSetModelResponse(ownerResponse, options.value));
1728
+ } else if (options.configId === "mode") setDesiredModeId(record, options.value);
1729
+ else setDesiredConfigOption(record, options.configId, options.value);
1730
+ await writeSessionRecord(record);
1731
+ return {
1732
+ record,
1733
+ response: ownerResponse,
1734
+ resumed: false
1735
+ };
1736
+ }
1737
+ return await runSessionSetConfigOptionDirect({
1738
+ sessionRecordId: options.sessionId,
1739
+ configId: options.configId,
1740
+ value: options.value,
1741
+ mcpServers: options.mcpServers,
1742
+ nonInteractivePermissions: options.nonInteractivePermissions,
1743
+ authCredentials: options.authCredentials,
1744
+ authPolicy: options.authPolicy,
1745
+ terminal: options.terminal,
1746
+ timeoutMs: options.timeoutMs,
1747
+ verbose: options.verbose
1748
+ });
1749
+ }
1750
+ function firstAgentCommandToken(command) {
1751
+ try {
1752
+ return splitCommandLine(command).command || void 0;
1753
+ } catch {
1754
+ return;
1755
+ }
1756
+ }
1757
+ async function isLikelyMatchingProcess(pid, agentCommand) {
1758
+ const expectedToken = firstAgentCommandToken(agentCommand);
1759
+ if (!expectedToken) return false;
1760
+ const argv = await readProcessArgv(pid);
1761
+ if (argv.length === 0) return false;
1762
+ const executableBase = path.basename(argv[0]);
1763
+ const expectedBase = path.basename(expectedToken);
1764
+ return executableBase === expectedBase || argv.some((entry) => path.basename(entry) === expectedBase);
1765
+ }
1766
+ async function readProcessArgv(pid) {
1767
+ const procArgv = await readProcCmdline(pid);
1768
+ if (procArgv) return procArgv;
1769
+ return splitCommandLineLike(process.platform === "win32" ? await readWindowsCommandLine(pid) : await readPosixCommandLine(pid));
1770
+ }
1771
+ async function readProcCmdline(pid) {
1772
+ try {
1773
+ return (await fs$1.readFile(`/proc/${pid}/cmdline`, "utf8")).split("\0").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
1774
+ } catch {
1775
+ return;
1776
+ }
1777
+ }
1778
+ async function readPosixCommandLine(pid) {
1779
+ try {
1780
+ const { stdout } = await execFileAsync("ps", [
1781
+ "-p",
1782
+ String(pid),
1783
+ "-o",
1784
+ "command="
1785
+ ]);
1786
+ return stdout.trim() || void 0;
1787
+ } catch {
1788
+ return;
1789
+ }
1790
+ }
1791
+ async function readWindowsCommandLine(pid) {
1792
+ try {
1793
+ const { stdout } = await execFileAsync("powershell.exe", [
1794
+ "-NoProfile",
1795
+ "-NonInteractive",
1796
+ "-Command",
1797
+ `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CommandLine`
1798
+ ], { windowsHide: true });
1799
+ return stdout.trim() || void 0;
1800
+ } catch {
1801
+ return;
1802
+ }
1803
+ }
1804
+ function splitCommandLineLike(commandLine) {
1805
+ if (!commandLine) return [];
1806
+ try {
1807
+ const parsed = splitCommandLine(commandLine);
1808
+ return [parsed.command, ...parsed.args];
1809
+ } catch {
1810
+ return commandLine.split(/\s+/u).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
1811
+ }
1812
+ }
1813
+ const sessionControlTestInternals = {
1814
+ firstAgentCommandToken,
1815
+ splitCommandLineLike
1816
+ };
1817
+ async function closeSession(sessionId) {
1818
+ const record = await resolveSessionRecord(sessionId);
1819
+ await tryCloseSessionOnRunningOwner({ sessionId: record.acpxRecordId }).catch(() => {});
1820
+ await terminateQueueOwnerForSession(record.acpxRecordId);
1821
+ if (record.pid != null && isProcessAlive(record.pid) && await isLikelyMatchingProcess(record.pid, record.agentCommand)) await terminateProcess(record.pid);
1822
+ record.pid = void 0;
1823
+ record.closed = true;
1824
+ record.closedAt = isoNow();
1825
+ await writeSessionRecord(record);
1826
+ return record;
1827
+ }
1828
+ //#endregion
1829
+ //#region src/cli/session/session-management.ts
1830
+ async function createSessionRecordWithClient(client, options) {
1831
+ const cwd = absolutePath(options.cwd);
1832
+ await withTimeout(client.start(), options.timeoutMs);
1833
+ const createdState = options.resumeSessionId ? await resumeSessionRecordWithClient(client, options, cwd) : await createFreshSessionState(client, options, cwd);
1834
+ const { sessionId, agentSessionId } = createdState;
1835
+ const lifecycle = client.getAgentLifecycleSnapshot();
1836
+ const now = isoNow();
1837
+ const record = {
1838
+ schema: "acpx.session.v1",
1839
+ acpxRecordId: sessionId,
1840
+ acpSessionId: sessionId,
1841
+ agentSessionId,
1842
+ agentCommand: options.agentCommand,
1843
+ cwd,
1844
+ name: normalizeName(options.name),
1845
+ createdAt: now,
1846
+ lastUsedAt: now,
1847
+ lastSeq: 0,
1848
+ lastRequestId: void 0,
1849
+ eventLog: defaultSessionEventLog(sessionId),
1850
+ closed: false,
1851
+ closedAt: void 0,
1852
+ pid: lifecycle.running ? lifecycle.pid : void 0,
1853
+ agentStartedAt: lifecycle.startedAt,
1854
+ protocolVersion: client.initializeResult?.protocolVersion,
1855
+ agentCapabilities: client.initializeResult?.agentCapabilities,
1856
+ ...createSessionConversation(now),
1857
+ acpx: {}
1858
+ };
1859
+ persistSessionOptions(record, options.sessionOptions);
1860
+ applyCreatedSessionModelState(record, createdState, options.sessionOptions?.model);
1861
+ await writeSessionRecord(record);
1862
+ return record;
1863
+ }
1864
+ function applyCreatedSessionModelState(record, state, requestedModel) {
1865
+ applyConfigOptionsToRecord(record, state.sessionResult);
1866
+ applyConfigOptionsToRecord(record, state.requestedModelResponse);
1867
+ syncAdvertisedModelState(record, state.requestedModelResponse ? modelStateFromConfigOptions(state.requestedModelResponse.configOptions) : state.sessionModels);
1868
+ if (state.requestedModelApplied) setCurrentModelId(record, currentModelIdFromSetModelResponse(state.requestedModelResponse, requestedModel));
1869
+ }
1870
+ async function createFreshSessionState(client, options, cwd) {
1871
+ const createdSession = await withTimeout(client.createSession(cwd), options.timeoutMs);
1872
+ const modelApplication = await applyRequestedModelIfAdvertised({
1873
+ client,
1874
+ sessionId: createdSession.sessionId,
1875
+ requestedModel: options.sessionOptions?.model,
1876
+ models: createdSession.models,
1877
+ agentCommand: options.agentCommand,
1878
+ timeoutMs: options.timeoutMs,
1879
+ onWarning: options.onModelWarning
1880
+ });
1881
+ return {
1882
+ sessionId: createdSession.sessionId,
1883
+ agentSessionId: normalizeRuntimeSessionId(createdSession.agentSessionId),
1884
+ sessionResult: createdSession,
1885
+ sessionModels: createdSession.models,
1886
+ requestedModelApplied: modelApplication.applied,
1887
+ requestedModelResponse: modelApplication.response
1888
+ };
1889
+ }
1890
+ async function resumeSessionRecordWithClient(client, options, cwd) {
1891
+ if (!options.resumeSessionId) throw new Error("resumeSessionId is required");
1892
+ const resumeMethod = client.supportsResumeSession() ? "session/resume" : client.supportsLoadSession() ? "session/load" : void 0;
1893
+ if (!resumeMethod) throw new Error(`Agent command "${options.agentCommand}" does not support session/resume or session/load; cannot resume session ${options.resumeSessionId}`);
1894
+ try {
1895
+ const resumedSession = await withTimeout(resumeMethod === "session/resume" ? client.resumeSession(options.resumeSessionId, cwd) : client.loadSession(options.resumeSessionId, cwd), options.timeoutMs);
1896
+ const sessionModels = resumedSession.models;
1897
+ const modelApplication = await applyRequestedModelIfAdvertised({
1898
+ client,
1899
+ sessionId: options.resumeSessionId,
1900
+ requestedModel: options.sessionOptions?.model,
1901
+ models: sessionModels,
1902
+ agentCommand: options.agentCommand,
1903
+ timeoutMs: options.timeoutMs,
1904
+ onWarning: options.onModelWarning
1905
+ });
1906
+ return {
1907
+ sessionId: options.resumeSessionId,
1908
+ agentSessionId: normalizeRuntimeSessionId(resumedSession.agentSessionId),
1909
+ sessionResult: resumedSession,
1910
+ sessionModels,
1911
+ requestedModelApplied: modelApplication.applied,
1912
+ requestedModelResponse: modelApplication.response
1913
+ };
1914
+ } catch (error) {
1915
+ throw new Error(`Failed to resume ACP session ${options.resumeSessionId}: ${formatErrorMessage(error)}`, { cause: error });
1916
+ }
1917
+ }
1918
+ async function createSessionWithClient(options) {
1919
+ const client = new AcpClient({
1920
+ agentCommand: options.agentCommand,
1921
+ cwd: absolutePath(options.cwd),
1922
+ mcpServers: options.mcpServers,
1923
+ permissionMode: options.permissionMode,
1924
+ nonInteractivePermissions: options.nonInteractivePermissions,
1925
+ permissionPolicy: options.permissionPolicy,
1926
+ authCredentials: options.authCredentials,
1927
+ authPolicy: options.authPolicy,
1928
+ terminal: options.terminal,
1929
+ verbose: options.verbose,
1930
+ sessionOptions: options.sessionOptions
1931
+ });
1932
+ try {
1933
+ return {
1934
+ record: await withInterrupt(async () => await createSessionRecordWithClient(client, options), async () => {
1935
+ await client.close();
1936
+ }),
1937
+ client
1938
+ };
1939
+ } catch (error) {
1940
+ await client.close();
1941
+ throw error;
1942
+ }
1943
+ }
1944
+ async function createSession(options) {
1945
+ const { record, client } = await createSessionWithClient(options);
1946
+ try {
1947
+ return record;
1948
+ } finally {
1949
+ await client.close();
1950
+ applyLifecycleSnapshotToRecord(record, client.getAgentLifecycleSnapshot());
1951
+ await writeSessionRecord(record);
1952
+ }
1953
+ }
1954
+ async function listAgentSessions(options) {
1955
+ const client = new AcpClient({
1956
+ agentCommand: options.agentCommand,
1957
+ cwd: absolutePath(options.cwd),
1958
+ mcpServers: options.mcpServers,
1959
+ permissionMode: options.permissionMode,
1960
+ nonInteractivePermissions: options.nonInteractivePermissions,
1961
+ permissionPolicy: options.permissionPolicy,
1962
+ authCredentials: options.authCredentials,
1963
+ authPolicy: options.authPolicy,
1964
+ terminal: options.terminal,
1965
+ verbose: options.verbose
1966
+ });
1967
+ try {
1968
+ return await withInterrupt(async () => {
1969
+ await withTimeout(client.start(), options.timeoutMs);
1970
+ if (!client.supportsListSessions()) return;
1971
+ const cwd = options.filterCwd ? absolutePath(options.filterCwd) : void 0;
1972
+ const response = await withTimeout(client.listSessions({
1973
+ ...cwd ? { cwd } : {},
1974
+ ...options.cursor ? { cursor: options.cursor } : {}
1975
+ }), options.timeoutMs);
1976
+ return {
1977
+ _meta: response._meta,
1978
+ source: "agent",
1979
+ sessions: response.sessions,
1980
+ cursor: options.cursor,
1981
+ cwd,
1982
+ nextCursor: response.nextCursor
1983
+ };
1984
+ }, async () => {
1985
+ await client.close();
1986
+ });
1987
+ } finally {
1988
+ await client.close();
1989
+ }
1990
+ }
1991
+ async function ensureSession(options) {
1992
+ const cwd = absolutePath(options.cwd);
1993
+ const gitRoot = findGitRepositoryRoot(cwd);
1994
+ const walkBoundary = options.walkBoundary ?? gitRoot ?? cwd;
1995
+ const existing = await findSessionByDirectoryWalk({
1996
+ agentCommand: options.agentCommand,
1997
+ cwd,
1998
+ name: options.name,
1999
+ boundary: walkBoundary
2000
+ });
2001
+ if (existing) {
2002
+ const requestedModel = options.sessionOptions?.model;
2003
+ if (requestedModel) return {
2004
+ record: (await setSessionModel({
2005
+ sessionId: existing.acpxRecordId,
2006
+ modelId: requestedModel,
2007
+ mcpServers: options.mcpServers,
2008
+ nonInteractivePermissions: options.nonInteractivePermissions,
2009
+ authCredentials: options.authCredentials,
2010
+ authPolicy: options.authPolicy,
2011
+ terminal: options.terminal,
2012
+ timeoutMs: options.timeoutMs,
2013
+ verbose: options.verbose
2014
+ })).record,
2015
+ created: false
2016
+ };
2017
+ return {
2018
+ record: existing,
2019
+ created: false
2020
+ };
2021
+ }
2022
+ return {
2023
+ record: await createSession({
2024
+ agentCommand: options.agentCommand,
2025
+ cwd,
2026
+ name: options.name,
2027
+ resumeSessionId: options.resumeSessionId,
2028
+ mcpServers: options.mcpServers,
2029
+ permissionMode: options.permissionMode,
2030
+ nonInteractivePermissions: options.nonInteractivePermissions,
2031
+ permissionPolicy: options.permissionPolicy,
2032
+ authCredentials: options.authCredentials,
2033
+ authPolicy: options.authPolicy,
2034
+ terminal: options.terminal,
2035
+ timeoutMs: options.timeoutMs,
2036
+ verbose: options.verbose,
2037
+ sessionOptions: options.sessionOptions
2038
+ }),
2039
+ created: true
2040
+ };
2041
+ }
2042
+ //#endregion
2043
+ //#region src/perf-metrics-capture.ts
2044
+ const PERF_METRICS_FILE_ENV = "ACPX_PERF_METRICS_FILE";
2045
+ let installed = false;
2046
+ let flushed = false;
2047
+ let captureFilePath;
2048
+ let captureRole = "cli";
2049
+ let captureArgv = [];
2050
+ let captureSequence = 0;
2051
+ function shouldCapture() {
2052
+ return typeof captureFilePath === "string" && captureFilePath.trim().length > 0;
2053
+ }
2054
+ function buildPayload(reason) {
2055
+ return {
2056
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2057
+ pid: process.pid,
2058
+ ppid: process.ppid,
2059
+ role: captureRole,
2060
+ argv: captureArgv,
2061
+ cwd: process.cwd(),
2062
+ sequence: captureSequence,
2063
+ reason,
2064
+ metrics: getPerfMetricsSnapshot()
2065
+ };
2066
+ }
2067
+ function payloadHasMetrics(payload) {
2068
+ const metrics = payload.metrics;
2069
+ return [
2070
+ metrics.counters,
2071
+ metrics.gauges,
2072
+ metrics.timings
2073
+ ].some((entries) => Object.keys(entries ?? {}).length > 0);
2074
+ }
2075
+ function appendPerfMetricsPayload(payload) {
2076
+ fs.mkdirSync(path.dirname(captureFilePath), { recursive: true });
2077
+ fs.appendFileSync(captureFilePath, `${JSON.stringify(payload)}\n`, "utf8");
2078
+ captureSequence += 1;
2079
+ }
2080
+ function writePerfMetricsCapture(reason, resetAfterWrite) {
2081
+ if (!shouldCapture()) return false;
2082
+ const payload = buildPayload(reason);
2083
+ if (!payloadHasMetrics(payload)) return false;
2084
+ try {
2085
+ appendPerfMetricsPayload(payload);
2086
+ if (resetAfterWrite) resetPerfMetrics();
2087
+ return true;
2088
+ } catch {
2089
+ return false;
2090
+ }
2091
+ }
2092
+ function checkpointPerfMetricsCapture() {
2093
+ flushed = false;
2094
+ writePerfMetricsCapture("checkpoint", true);
2095
+ }
2096
+ function flushPerfMetricsCapture(reason = "exit") {
2097
+ if (flushed || !shouldCapture()) return;
2098
+ flushed = true;
2099
+ writePerfMetricsCapture(reason, false);
2100
+ }
2101
+ function installPerfMetricsCapture(options = {}) {
2102
+ captureFilePath = options.filePath ?? process.env[PERF_METRICS_FILE_ENV];
2103
+ if (!shouldCapture()) return;
2104
+ resetPerfMetrics();
2105
+ captureRole = options.role ?? captureRole;
2106
+ captureArgv = options.argv ?? [];
2107
+ captureSequence = 0;
2108
+ flushed = false;
2109
+ if (installed) return;
2110
+ installed = true;
2111
+ process.once("exit", () => {
2112
+ flushPerfMetricsCapture("exit");
2113
+ });
2114
+ for (const signal of ["SIGINT", "SIGTERM"]) {
2115
+ const handler = () => {
2116
+ flushPerfMetricsCapture("signal");
2117
+ process.removeListener(signal, handler);
2118
+ process.kill(process.pid, signal);
2119
+ };
2120
+ process.once(signal, handler);
2121
+ }
2122
+ }
2123
+ //#endregion
2124
+ //#region src/cli/queue/owner-turn-controller.ts
2125
+ var QueueOwnerTurnController = class {
2126
+ options;
2127
+ state = "idle";
2128
+ pendingCancel = false;
2129
+ activeController;
2130
+ constructor(options) {
2131
+ this.options = options;
2132
+ }
2133
+ get lifecycleState() {
2134
+ return this.state;
2135
+ }
2136
+ get hasPendingCancel() {
2137
+ return this.pendingCancel;
2138
+ }
2139
+ beginTurn() {
2140
+ this.state = "starting";
2141
+ this.pendingCancel = false;
2142
+ }
2143
+ markPromptActive() {
2144
+ if (this.state === "starting" || this.state === "active") this.state = "active";
2145
+ }
2146
+ endTurn() {
2147
+ this.state = "idle";
2148
+ this.pendingCancel = false;
2149
+ }
2150
+ beginClosing() {
2151
+ this.state = "closing";
2152
+ this.pendingCancel = false;
2153
+ this.activeController = void 0;
2154
+ }
2155
+ setActiveController(controller) {
2156
+ this.activeController = controller;
2157
+ }
2158
+ clearActiveController() {
2159
+ this.activeController = void 0;
2160
+ }
2161
+ assertCanHandleControlRequest() {
2162
+ if (this.state === "closing") throw new QueueConnectionError("Queue owner is closing", {
2163
+ detailCode: "QUEUE_OWNER_SHUTTING_DOWN",
2164
+ origin: "queue",
2165
+ retryable: true
2166
+ });
2167
+ }
2168
+ async requestCancel() {
2169
+ const activeController = this.activeController;
2170
+ if (activeController?.hasActivePrompt()) {
2171
+ const cancelled = await activeController.requestCancelActivePrompt();
2172
+ if (cancelled) this.pendingCancel = false;
2173
+ return cancelled;
2174
+ }
2175
+ if (this.state === "starting" || this.state === "active") {
2176
+ this.pendingCancel = true;
2177
+ return true;
2178
+ }
2179
+ return false;
2180
+ }
2181
+ async applyPendingCancel() {
2182
+ const activeController = this.activeController;
2183
+ if (!this.pendingCancel || !activeController || !activeController.hasActivePrompt()) return false;
2184
+ const cancelled = await activeController.requestCancelActivePrompt();
2185
+ if (cancelled) this.pendingCancel = false;
2186
+ return cancelled;
2187
+ }
2188
+ async setSessionMode(modeId, timeoutMs) {
2189
+ this.assertCanHandleControlRequest();
2190
+ const activeController = this.activeController;
2191
+ if (activeController) {
2192
+ await this.options.withTimeout(async () => await activeController.setSessionMode(modeId), timeoutMs);
2193
+ return;
2194
+ }
2195
+ await this.options.setSessionModeFallback(modeId, timeoutMs);
2196
+ }
2197
+ async setSessionModel(modelId, timeoutMs) {
2198
+ this.assertCanHandleControlRequest();
2199
+ const activeController = this.activeController;
2200
+ if (activeController) return await this.options.withTimeout(async () => await activeController.setSessionModel(modelId), timeoutMs);
2201
+ return await this.options.setSessionModelFallback(modelId, timeoutMs);
2202
+ }
2203
+ async setSessionConfigOption(configId, value, timeoutMs) {
2204
+ this.assertCanHandleControlRequest();
2205
+ const activeController = this.activeController;
2206
+ if (activeController) return await this.options.withTimeout(async () => await activeController.setSessionConfigOption(configId, value), timeoutMs);
2207
+ return await this.options.setSessionConfigOptionFallback(configId, value, timeoutMs);
2208
+ }
2209
+ };
2210
+ //#endregion
2211
+ //#region src/cli/session/queue-owner-process.ts
2212
+ const QUEUE_OWNER_PAYLOAD_FILE_ENV = "ACPX_QUEUE_OWNER_PAYLOAD_FILE";
2213
+ const QUEUE_OWNER_PAYLOAD_ENV = "ACPX_QUEUE_OWNER_PAYLOAD";
2214
+ function isNonEmptyStringArray(value) {
2215
+ return Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "string" && entry.length > 0);
2216
+ }
2217
+ const NODE_TEST_FLAGS = /* @__PURE__ */ new Set([
2218
+ "--experimental-test-coverage",
2219
+ "--test",
2220
+ "--test-name-pattern",
2221
+ "--test-reporter",
2222
+ "--test-reporter-destination"
2223
+ ]);
2224
+ const NODE_TEST_FLAGS_WITH_VALUE = /* @__PURE__ */ new Set([
2225
+ "--test-name-pattern",
2226
+ "--test-reporter",
2227
+ "--test-reporter-destination"
2228
+ ]);
2229
+ const INSPECTOR_FLAGS_WITH_VALUE = /* @__PURE__ */ new Set([
2230
+ "--inspect",
2231
+ "--inspect-brk",
2232
+ "--inspect-port",
2233
+ "--inspect-publish-uid",
2234
+ "--debug-port"
2235
+ ]);
2236
+ const INSPECTOR_FLAG_PREFIXES = [
2237
+ "--inspect=",
2238
+ "--inspect-brk=",
2239
+ "--inspect-port=",
2240
+ "--inspect-publish-uid=",
2241
+ "--debug-port="
2242
+ ];
2243
+ function classifyExecArgv(value) {
2244
+ if (value === void 0) return "drop";
2245
+ if (NODE_TEST_FLAGS_WITH_VALUE.has(value) || INSPECTOR_FLAGS_WITH_VALUE.has(value)) return "drop-with-value";
2246
+ return dropSingleExecArgv(value) ? "drop" : "keep";
2247
+ }
2248
+ function dropSingleExecArgv(value) {
2249
+ return NODE_TEST_FLAGS.has(value) || value.startsWith("--test-") || INSPECTOR_FLAG_PREFIXES.some((prefix) => value.startsWith(prefix));
2250
+ }
2251
+ function sanitizeQueueOwnerExecArgv(execArgv = process.execArgv) {
2252
+ const sanitized = [];
2253
+ for (let index = 0; index < execArgv.length; index += 1) {
2254
+ const value = execArgv[index] ?? "";
2255
+ const decision = classifyExecArgv(value);
2256
+ if (decision === "drop") continue;
2257
+ if (decision === "drop-with-value") {
2258
+ index += 1;
2259
+ continue;
2260
+ }
2261
+ sanitized.push(value);
2262
+ }
2263
+ return sanitized;
2264
+ }
2265
+ function buildQueueOwnerArgOverride(entryPath, execArgv = process.execArgv) {
2266
+ const sanitized = sanitizeQueueOwnerExecArgv(execArgv);
2267
+ if (sanitized.length === 0) return null;
2268
+ return JSON.stringify([
2269
+ ...sanitized,
2270
+ entryPath,
2271
+ "__queue-owner"
2272
+ ]);
2273
+ }
2274
+ function resolveQueueOwnerSpawnArgs(argv = process.argv) {
2275
+ const override = process.env.ACPX_QUEUE_OWNER_ARGS;
2276
+ if (override) {
2277
+ const parsed = JSON.parse(override);
2278
+ if (isNonEmptyStringArray(parsed)) return [...parsed];
2279
+ throw new Error("acpx self-spawn failed: invalid ACPX_QUEUE_OWNER_ARGS");
2280
+ }
2281
+ const entry = argv[1];
2282
+ if (!entry || entry.trim().length === 0) throw new Error("acpx self-spawn failed: missing CLI entry path");
2283
+ return [realpathSync(entry), "__queue-owner"];
2284
+ }
2285
+ function queueOwnerRuntimeOptionsFromSend(options) {
2286
+ return {
2287
+ sessionId: options.sessionId,
2288
+ mcpServers: options.mcpServers,
2289
+ ...options.mcpConfigPath ? { mcpConfigPath: options.mcpConfigPath } : {},
2290
+ ...options.mcpConfigFingerprint ? { mcpConfigFingerprint: options.mcpConfigFingerprint } : {},
2291
+ permissionMode: options.permissionMode,
2292
+ nonInteractivePermissions: options.nonInteractivePermissions,
2293
+ authCredentials: options.authCredentials,
2294
+ authPolicy: options.authPolicy,
2295
+ terminal: options.terminal,
2296
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
2297
+ verbose: options.verbose,
2298
+ ttlMs: options.ttlMs,
2299
+ maxQueueDepth: options.maxQueueDepth,
2300
+ promptRetries: options.promptRetries,
2301
+ sessionOptions: options.sessionOptions
2302
+ };
2303
+ }
2304
+ function writeQueueOwnerPayloadFile(payload) {
2305
+ const dir = mkdtempSync(path.join(os.tmpdir(), "acpx-queue-owner-"));
2306
+ const payloadPath = path.join(dir, "payload.json");
2307
+ writeFileSync(payloadPath, payload, {
2308
+ encoding: "utf8",
2309
+ flag: "wx",
2310
+ mode: 384
2311
+ });
2312
+ return payloadPath;
2313
+ }
2314
+ function buildQueueOwnerSpawnOptions(payloadFilePath) {
2315
+ const env = {
2316
+ ...process.env,
2317
+ [QUEUE_OWNER_PAYLOAD_FILE_ENV]: payloadFilePath
2318
+ };
2319
+ delete env[QUEUE_OWNER_PAYLOAD_ENV];
2320
+ return {
2321
+ detached: true,
2322
+ stdio: "ignore",
2323
+ env,
2324
+ windowsHide: true
2325
+ };
2326
+ }
2327
+ function spawnQueueOwnerProcess(options) {
2328
+ const payloadPath = writeQueueOwnerPayloadFile(JSON.stringify(options));
2329
+ spawn(process.execPath, resolveQueueOwnerSpawnArgs(), buildQueueOwnerSpawnOptions(payloadPath)).unref();
2330
+ }
2331
+ //#endregion
2332
+ //#region src/session/events.ts
2333
+ const LOCK_RETRY_MS = 15;
2334
+ const EVENT_LOCK_STALE_MS = 15e3;
2335
+ async function ensureSessionDir() {
2336
+ await fs$1.mkdir(sessionBaseDir(), { recursive: true });
2337
+ }
2338
+ async function pathExists(filePath) {
2339
+ try {
2340
+ await fs$1.access(filePath);
2341
+ return true;
2342
+ } catch {
2343
+ return false;
2344
+ }
2345
+ }
2346
+ async function statSize(filePath) {
2347
+ try {
2348
+ return (await fs$1.stat(filePath)).size;
2349
+ } catch {
2350
+ return 0;
2351
+ }
2352
+ }
2353
+ async function countExistingSegments(sessionId, maxSegments) {
2354
+ let count = 0;
2355
+ for (let segment = 1; segment <= maxSegments; segment += 1) if (await pathExists(sessionEventSegmentPath(sessionId, segment))) count += 1;
2356
+ if (await pathExists(sessionEventActivePath(sessionId))) count += 1;
2357
+ return count;
2358
+ }
2359
+ async function resolveInitialSegmentCount(record, maxSegments) {
2360
+ if (Number.isInteger(record.eventLog.segment_count) && record.eventLog.segment_count > 0) return record.eventLog.segment_count;
2361
+ return await countExistingSegments(record.acpxRecordId, maxSegments) || 1;
2362
+ }
2363
+ async function rotateSegments(sessionId, maxSegments) {
2364
+ const active = sessionEventActivePath(sessionId);
2365
+ const overflow = sessionEventSegmentPath(sessionId, maxSegments);
2366
+ await fs$1.unlink(overflow).catch((error) => {
2367
+ if (error.code !== "ENOENT") throw error;
2368
+ });
2369
+ for (let segment = maxSegments - 1; segment >= 1; segment -= 1) {
2370
+ const from = sessionEventSegmentPath(sessionId, segment);
2371
+ const to = sessionEventSegmentPath(sessionId, segment + 1);
2372
+ if (!await pathExists(from)) continue;
2373
+ await fs$1.rename(from, to);
2374
+ }
2375
+ if (await pathExists(active)) await fs$1.rename(active, sessionEventSegmentPath(sessionId, 1));
2376
+ }
2377
+ function parseEventLockPayload(raw) {
2378
+ try {
2379
+ const parsed = JSON.parse(raw);
2380
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
2381
+ const record = parsed;
2382
+ return {
2383
+ pid: typeof record.pid === "number" ? record.pid : void 0,
2384
+ created_at: typeof record.created_at === "string" ? record.created_at : void 0
2385
+ };
2386
+ } catch {
2387
+ return {};
2388
+ }
2389
+ }
2390
+ async function removeStaleEventLock(lockPath) {
2391
+ try {
2392
+ const parsed = parseEventLockPayload(await fs$1.readFile(lockPath, "utf8"));
2393
+ const createdAtMs = parsed.created_at ? Date.parse(parsed.created_at) : NaN;
2394
+ const lockAgeMs = Number.isFinite(createdAtMs) ? Date.now() - createdAtMs : Number.POSITIVE_INFINITY;
2395
+ if (isProcessAlive(parsed.pid) && lockAgeMs <= EVENT_LOCK_STALE_MS) return false;
2396
+ await fs$1.unlink(lockPath);
2397
+ incrementPerfCounter("session.events.stale_lock_recovered");
2398
+ return true;
2399
+ } catch (error) {
2400
+ if (error.code === "ENOENT") return true;
2401
+ return false;
2402
+ }
2403
+ }
2404
+ async function acquireEventsLock(sessionId) {
2405
+ await ensureSessionDir();
2406
+ const lockPath = sessionEventLockPath(sessionId);
2407
+ const payload = JSON.stringify({
2408
+ pid: process.pid,
2409
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
2410
+ }, null, 2);
2411
+ for (;;) try {
2412
+ await fs$1.writeFile(lockPath, `${payload}\n`, {
2413
+ encoding: "utf8",
2414
+ flag: "wx"
2415
+ });
2416
+ return { filePath: lockPath };
2417
+ } catch (error) {
2418
+ if (error.code !== "EEXIST") throw error;
2419
+ if (await removeStaleEventLock(lockPath)) continue;
2420
+ await new Promise((resolve) => {
2421
+ setTimeout(resolve, LOCK_RETRY_MS);
2422
+ });
2423
+ }
2424
+ }
2425
+ async function releaseEventsLock(lock) {
2426
+ await fs$1.unlink(lock.filePath).catch((error) => {
2427
+ if (error.code !== "ENOENT") throw error;
2428
+ });
2429
+ }
2430
+ var SessionEventWriter = class SessionEventWriter {
2431
+ record;
2432
+ lock;
2433
+ maxSegmentBytes;
2434
+ maxSegments;
2435
+ activePath;
2436
+ activeSizeBytes;
2437
+ segmentCount;
2438
+ closed = false;
2439
+ constructor(record, lock, options, state) {
2440
+ this.record = record;
2441
+ this.lock = lock;
2442
+ this.maxSegmentBytes = options.maxSegmentBytes;
2443
+ this.maxSegments = options.maxSegments;
2444
+ this.activePath = state.activePath;
2445
+ this.activeSizeBytes = state.activeSizeBytes;
2446
+ this.segmentCount = state.segmentCount;
2447
+ }
2448
+ static async open(record, options = {}) {
2449
+ const lock = await acquireEventsLock(record.acpxRecordId);
2450
+ const maxSegmentBytes = options.maxSegmentBytes ?? record.eventLog.max_segment_bytes ?? 67108864;
2451
+ const maxSegments = options.maxSegments ?? record.eventLog.max_segments ?? 5;
2452
+ const activePath = sessionEventActivePath(record.acpxRecordId);
2453
+ const activeSizeBytes = await statSize(activePath);
2454
+ const segmentCount = await resolveInitialSegmentCount(record, maxSegments);
2455
+ return new SessionEventWriter(record, lock, {
2456
+ maxSegmentBytes,
2457
+ maxSegments
2458
+ }, {
2459
+ activePath,
2460
+ activeSizeBytes,
2461
+ segmentCount
2462
+ });
2463
+ }
2464
+ getRecord() {
2465
+ return this.record;
2466
+ }
2467
+ async appendMessage(message, options = {}) {
2468
+ await this.appendMessages([message], options);
2469
+ }
2470
+ async appendMessages(messages, options = {}) {
2471
+ if (this.closed) throw new Error("SessionEventWriter is closed");
2472
+ if (messages.length === 0) return;
2473
+ await ensureSessionDir();
2474
+ await measurePerf("session.events.append_batch", async () => {
2475
+ for (const message of messages) {
2476
+ if (!isAcpJsonRpcMessage(message)) throw new Error("Attempted to persist invalid ACP JSON-RPC payload");
2477
+ const line = `${JSON.stringify(message)}\n`;
2478
+ const lineBytes = Buffer.byteLength(line);
2479
+ if (this.activeSizeBytes > 0 && this.activeSizeBytes + lineBytes > this.maxSegmentBytes) {
2480
+ await rotateSegments(this.record.acpxRecordId, this.maxSegments);
2481
+ this.activePath = sessionEventActivePath(this.record.acpxRecordId);
2482
+ this.activeSizeBytes = 0;
2483
+ this.segmentCount = Math.min(this.segmentCount + 1, this.maxSegments);
2484
+ incrementPerfCounter("session.events.rotate");
2485
+ }
2486
+ await fs$1.appendFile(this.activePath, line, "utf8");
2487
+ this.activeSizeBytes += lineBytes;
2488
+ this.record.lastSeq += 1;
2489
+ if (Object.hasOwn(message, "id")) {
2490
+ const id = message.id;
2491
+ if (typeof id === "string" || typeof id === "number") this.record.lastRequestId = String(id);
2492
+ }
2493
+ const writeTs = (/* @__PURE__ */ new Date()).toISOString();
2494
+ this.record.lastUsedAt = writeTs;
2495
+ this.record.eventLog = {
2496
+ active_path: this.activePath,
2497
+ segment_count: this.segmentCount,
2498
+ max_segment_bytes: this.maxSegmentBytes,
2499
+ max_segments: this.maxSegments,
2500
+ last_write_at: writeTs,
2501
+ last_write_error: null
2502
+ };
2503
+ }
2504
+ });
2505
+ if (options.checkpoint === true) await writeSessionRecord(this.record);
2506
+ }
2507
+ async checkpoint() {
2508
+ if (this.closed) throw new Error("SessionEventWriter is closed");
2509
+ await writeSessionRecord(this.record);
2510
+ }
2511
+ async close(options = {}) {
2512
+ if (this.closed) return;
2513
+ try {
2514
+ if (options.checkpoint !== false) await writeSessionRecord(this.record);
2515
+ } finally {
2516
+ this.closed = true;
2517
+ await releaseEventsLock(this.lock);
2518
+ }
2519
+ }
2520
+ };
2521
+ //#endregion
2522
+ //#region src/cli/session/runtime.ts
2523
+ const INTERRUPT_CANCEL_WAIT_MS = 2500;
2524
+ var QueueTaskOutputFormatter = class {
2525
+ requestId;
2526
+ send;
2527
+ constructor(task) {
2528
+ this.requestId = task.requestId;
2529
+ this.send = task.send;
2530
+ }
2531
+ setContext(_context) {}
2532
+ onAcpMessage(message) {
2533
+ this.send({
2534
+ type: "event",
2535
+ requestId: this.requestId,
2536
+ message
2537
+ });
2538
+ }
2539
+ onError(params) {
2540
+ this.send({
2541
+ type: "error",
2542
+ requestId: this.requestId,
2543
+ code: params.code,
2544
+ detailCode: params.detailCode,
2545
+ origin: params.origin,
2546
+ message: params.message,
2547
+ retryable: params.retryable,
2548
+ acp: params.acp
2549
+ });
2550
+ }
2551
+ onPermissionEscalation(event) {
2552
+ this.send({
2553
+ type: "permission_escalation",
2554
+ requestId: this.requestId,
2555
+ event
2556
+ });
2557
+ }
2558
+ flush() {}
2559
+ };
2560
+ const DISCARD_OUTPUT_FORMATTER = {
2561
+ setContext() {},
2562
+ onAcpMessage() {},
2563
+ onError() {},
2564
+ onPermissionEscalation() {},
2565
+ flush() {}
2566
+ };
2567
+ function markOutputAlreadyEmitted(error, outputAlreadyEmitted) {
2568
+ if (!outputAlreadyEmitted || !error || typeof error !== "object") return;
2569
+ error.outputAlreadyEmitted = true;
2570
+ }
2571
+ async function runWithOptionalInterrupt(options) {
2572
+ if (options.handleProcessInterrupts === false) return await options.run();
2573
+ return await withInterrupt(options.run, options.handleInterrupt);
2574
+ }
2575
+ function attachAcpErrorPayload(error, acp) {
2576
+ if (!acp || !error || typeof error !== "object") return;
2577
+ error.acp = acp;
2578
+ }
2579
+ function rendersAcpErrors(policy) {
2580
+ return policy?.queueErrorAlreadyEmitted ?? true;
2581
+ }
2582
+ function normalizedErrorText(value) {
2583
+ return value.trim().toLowerCase();
2584
+ }
2585
+ function outboundAcpErrorMatches(error, acp) {
2586
+ const errorText = normalizedErrorText(formatErrorMessage(error));
2587
+ const details = acp.data?.details;
2588
+ const candidateText = normalizedErrorText(typeof details === "string" && details.trim().length > 0 ? details : acp.message);
2589
+ return errorText === candidateText || errorText.includes(candidateText);
2590
+ }
2591
+ var AcpErrorTracker = class {
2592
+ latestInbound;
2593
+ outbound = [];
2594
+ reset() {
2595
+ this.latestInbound = void 0;
2596
+ this.outbound.length = 0;
2597
+ }
2598
+ observe(output, direction, message) {
2599
+ output.onAcpMessage(message);
2600
+ const acp = extractAcpError(message);
2601
+ if (!acp) return;
2602
+ if (direction === "inbound") {
2603
+ this.latestInbound = acp;
2604
+ return;
2605
+ }
2606
+ this.outbound.push(acp);
2607
+ }
2608
+ match(error) {
2609
+ return this.latestInbound ?? this.outbound.findLast((acp) => outboundAcpErrorMatches(error, acp));
2610
+ }
2611
+ };
2612
+ function toPromptResult(stopReason, sessionId, client) {
2613
+ return {
2614
+ stopReason,
2615
+ sessionId,
2616
+ permissionStats: client.getPermissionStats()
2617
+ };
2618
+ }
2619
+ function requestedModelId(value) {
2620
+ return typeof value === "string" ? value.trim() : "";
2621
+ }
2622
+ function applyConfigOptionResponseToState(state, response) {
2623
+ if (!response?.configOptions) return state;
2624
+ return applyConfigOptionsToState(state, response.configOptions);
2625
+ }
2626
+ function mergeConnectedModelState(state, connectedState) {
2627
+ if (!connectedState) return state;
2628
+ const nextState = cloneSessionAcpxState(state) ?? {};
2629
+ mergeConnectedAdvertisedModelState(nextState, connectedState);
2630
+ mergeConnectedModelPreferences(nextState, connectedState);
2631
+ return nextState;
2632
+ }
2633
+ function mergeConnectedAdvertisedModelState(nextState, connectedState) {
2634
+ if (connectedState.config_options !== void 0) nextState.config_options = structuredClone(connectedState.config_options);
2635
+ else delete nextState.config_options;
2636
+ if (connectedState.current_model_id !== void 0) nextState.current_model_id = connectedState.current_model_id;
2637
+ else delete nextState.current_model_id;
2638
+ if (connectedState.available_models) nextState.available_models = [...connectedState.available_models];
2639
+ else delete nextState.available_models;
2640
+ if (connectedState.model_control) nextState.model_control = connectedState.model_control;
2641
+ else delete nextState.model_control;
2642
+ }
2643
+ function mergeConnectedModelPreferences(nextState, connectedState) {
2644
+ if (connectedState.session_options) nextState.session_options = cloneSessionAcpxState(connectedState)?.session_options;
2645
+ if (connectedState.desired_mode_id !== void 0) nextState.desired_mode_id = connectedState.desired_mode_id;
2646
+ if (connectedState.desired_config_options) nextState.desired_config_options = { ...connectedState.desired_config_options };
2647
+ }
2648
+ async function applyPromptModelIfAdvertised(params) {
2649
+ const requestedModel = requestedModelId(params.requestedModel);
2650
+ if (!requestedModel) return;
2651
+ const models = advertisedModelState(params.record.acpx);
2652
+ emitModelSupportWarning(assertRequestedModelSupported({
2653
+ requestedModel,
2654
+ models,
2655
+ agentCommand: params.record.agentCommand,
2656
+ context: "apply"
2657
+ }), params.suppressWarnings);
2658
+ if (!models) return;
2659
+ if (params.record.acpx?.current_model_id === requestedModel) {
2660
+ setDesiredModelId(params.record, requestedModel, models.configId);
2661
+ return;
2662
+ }
2663
+ const response = await withTimeout(params.client.setSessionModel(params.sessionId, requestedModel, models), params.timeoutMs);
2664
+ applyConfigOptionsToRecord(params.record, response);
2665
+ setDesiredModelId(params.record, requestedModel, models.configId);
2666
+ setCurrentModelId(params.record, currentModelIdFromSetModelResponse(response, requestedModel));
2667
+ }
2668
+ function emitModelSupportWarning(warning, suppressWarnings) {
2669
+ if (warning && !suppressWarnings) process.stderr.write(`[acpx] warning: ${warning}\n`);
2670
+ }
2671
+ function jsonRpcIdKey$1(value) {
2672
+ if (typeof value === "string") return `s:${value}`;
2673
+ if (typeof value === "number" && Number.isFinite(value)) return `n:${value}`;
2674
+ }
2675
+ function extractJsonRpcRequestInfo(message) {
2676
+ const candidate = message;
2677
+ if (typeof candidate.method !== "string") return;
2678
+ const idKey = jsonRpcIdKey$1(candidate.id);
2679
+ if (!idKey) return;
2680
+ return {
2681
+ idKey,
2682
+ method: candidate.method
2683
+ };
2684
+ }
2685
+ function extractJsonRpcResponseInfo(message) {
2686
+ const candidate = message;
2687
+ const idKey = jsonRpcIdKey$1(candidate.id);
2688
+ if (!idKey) return;
2689
+ const hasError = Object.hasOwn(candidate, "error");
2690
+ const hasResult = Object.hasOwn(candidate, "result");
2691
+ if (!hasError && !hasResult) return;
2692
+ return {
2693
+ idKey,
2694
+ hasError
2695
+ };
2696
+ }
2697
+ const SESSION_RECONNECT_METHODS = /* @__PURE__ */ new Set(["session/load", "session/resume"]);
2698
+ function filterRecoverableLoadFallbackOutput(messages) {
2699
+ const requestMethodById = /* @__PURE__ */ new Map();
2700
+ const failedLoadRequestIds = /* @__PURE__ */ new Set();
2701
+ for (const message of messages) {
2702
+ const request = extractJsonRpcRequestInfo(message);
2703
+ if (request) {
2704
+ requestMethodById.set(request.idKey, request.method);
2705
+ continue;
2706
+ }
2707
+ const response = extractJsonRpcResponseInfo(message);
2708
+ if (!response || !response.hasError) continue;
2709
+ const requestMethod = requestMethodById.get(response.idKey);
2710
+ if (requestMethod && SESSION_RECONNECT_METHODS.has(requestMethod)) failedLoadRequestIds.add(response.idKey);
2711
+ }
2712
+ if (failedLoadRequestIds.size === 0) return messages;
2713
+ return messages.filter((message) => {
2714
+ const request = extractJsonRpcRequestInfo(message);
2715
+ if (request && SESSION_RECONNECT_METHODS.has(request.method) && failedLoadRequestIds.has(request.idKey)) return false;
2716
+ const response = extractJsonRpcResponseInfo(message);
2717
+ if (response && failedLoadRequestIds.has(response.idKey)) return false;
2718
+ return true;
2719
+ });
2720
+ }
2721
+ function filterBufferedConnectOutput(messages, loadError) {
2722
+ if (loadError == null) return messages;
2723
+ const filteredMessages = new Set(filterRecoverableLoadFallbackOutput(messages.map(({ message }) => message)));
2724
+ return messages.filter(({ message }) => filteredMessages.has(message));
2725
+ }
2726
+ function emitPromptRetryNotice(params) {
2727
+ if (params.suppressSdkConsoleErrors) return;
2728
+ process.stderr.write(`[acpx] prompt failed (${formatErrorMessage(params.error)}), retrying in ${params.delayMs}ms (attempt ${params.attempt}/${params.maxRetries})\n`);
2729
+ }
2730
+ function emitConnectPerfMetric(startedAt, verbose) {
2731
+ if (!verbose) return;
2732
+ process.stderr.write(`[acpx] ${formatPerfMetric("prompt.connect_and_load", Date.now() - startedAt)}\n`);
2733
+ }
2734
+ function emitPromptPerfMetric(startedAt, verbose) {
2735
+ if (!verbose) return;
2736
+ process.stderr.write(`[acpx] ${formatPerfMetric("prompt.agent_turn", Date.now() - startedAt)}\n`);
2737
+ }
2738
+ function emitPromptHookError(error, verbose) {
2739
+ if (!verbose) return;
2740
+ process.stderr.write("[acpx] onPromptActive hook failed: " + formatErrorMessage(error) + "\n");
2741
+ }
2742
+ function emitPromptDisconnectNotice(snapshot, verbose) {
2743
+ const lastExit = snapshot.lastExit;
2744
+ if (!lastExit?.unexpectedDuringPrompt || !verbose) return;
2745
+ process.stderr.write("[acpx] agent disconnected during prompt (" + lastExit.reason + ", exit=" + lastExit.exitCode + ", signal=" + (lastExit.signal ?? "none") + ")\n");
2746
+ }
2747
+ function shouldRetryRuntimePrompt(error, attempt, maxRetries, snapshot, hasSideEffects) {
2748
+ if (!shouldRetryPromptAttempt(error, attempt, maxRetries, hasSideEffects)) return false;
2749
+ return snapshot.lastExit?.unexpectedDuringPrompt !== true;
2750
+ }
2751
+ function shouldRetryPromptAttempt(error, attempt, maxRetries, hasSideEffects) {
2752
+ return attempt < maxRetries && !hasSideEffects() && isRetryablePromptError(error);
2753
+ }
2754
+ async function waitBeforePromptRetry(error, attempt, maxRetries, suppressSdkConsoleErrors) {
2755
+ const delayMs = Math.min(1e3 * 2 ** attempt, 1e4);
2756
+ emitPromptRetryNotice({
2757
+ error,
2758
+ delayMs,
2759
+ attempt: attempt + 1,
2760
+ maxRetries,
2761
+ suppressSdkConsoleErrors
2762
+ });
2763
+ await waitMs(delayMs);
2764
+ }
2765
+ function buildQueuedTaskRunOptions(sessionRecordId, task, options, outputFormatter) {
2766
+ return {
2767
+ sessionRecordId,
2768
+ mcpServers: options.mcpServers,
2769
+ prompt: task.prompt ?? textPrompt(task.message),
2770
+ permissionMode: task.permissionMode,
2771
+ resumePolicy: task.resumePolicy,
2772
+ nonInteractivePermissions: task.nonInteractivePermissions ?? options.nonInteractivePermissions,
2773
+ permissionPolicy: task.permissionPolicy,
2774
+ authCredentials: options.authCredentials,
2775
+ authPolicy: options.authPolicy,
2776
+ outputFormatter,
2777
+ errorEmissionPolicy: { queueErrorAlreadyEmitted: true },
2778
+ timeoutMs: task.timeoutMs,
2779
+ suppressSdkConsoleErrors: task.suppressSdkConsoleErrors ?? options.suppressSdkConsoleErrors,
2780
+ verbose: options.verbose,
2781
+ promptRetries: task.promptRetries ?? options.promptRetries ?? 0,
2782
+ sessionOptions: mergeSessionOptions(task.sessionOptions, options.sessionOptions),
2783
+ onClientAvailable: options.onClientAvailable,
2784
+ onClientClosed: options.onClientClosed,
2785
+ onPromptActive: options.onPromptActive,
2786
+ handleProcessInterrupts: options.handleProcessInterrupts,
2787
+ client: options.sharedClient
2788
+ };
2789
+ }
2790
+ function sendQueuedTaskResult(task, result) {
2791
+ if (!task.waitForCompletion) return;
2792
+ task.send({
2793
+ type: "result",
2794
+ requestId: task.requestId,
2795
+ result
2796
+ });
2797
+ }
2798
+ function sendQueuedTaskError(task, error) {
2799
+ if (!task.waitForCompletion) return;
2800
+ const normalizedError = normalizeOutputError(error, {
2801
+ origin: "runtime",
2802
+ detailCode: "QUEUE_RUNTIME_PROMPT_FAILED"
2803
+ });
2804
+ const alreadyEmitted = error.outputAlreadyEmitted === true;
2805
+ task.send({
2806
+ type: "error",
2807
+ requestId: task.requestId,
2808
+ code: normalizedError.code,
2809
+ detailCode: normalizedError.detailCode,
2810
+ origin: normalizedError.origin,
2811
+ message: normalizedError.message,
2812
+ retryable: normalizedError.retryable,
2813
+ acp: normalizedError.acp,
2814
+ outputAlreadyEmitted: alreadyEmitted
2815
+ });
2816
+ }
2817
+ async function runQueuedTask(sessionRecordId, task, options) {
2818
+ const outputFormatter = task.waitForCompletion ? new QueueTaskOutputFormatter(task) : DISCARD_OUTPUT_FORMATTER;
2819
+ try {
2820
+ sendQueuedTaskResult(task, await runSessionPrompt(buildQueuedTaskRunOptions(sessionRecordId, task, options, outputFormatter)));
2821
+ } catch (error) {
2822
+ sendQueuedTaskError(task, error);
2823
+ if (error instanceof InterruptedError) throw error;
2824
+ } finally {
2825
+ task.close();
2826
+ }
2827
+ }
2828
+ async function runSessionPrompt(options) {
2829
+ const stopTotalTimer = startPerfTimer("runtime.prompt.total");
2830
+ const output = options.outputFormatter;
2831
+ const shouldMarkAcpErrorsEmitted = rendersAcpErrors(options.errorEmissionPolicy);
2832
+ const record = await measurePerf("session.resolve_prompt_record", async () => {
2833
+ return await resolveSessionRecord(options.sessionRecordId);
2834
+ });
2835
+ const conversation = cloneSessionConversation(record);
2836
+ let acpxState = cloneSessionAcpxState(record.acpx);
2837
+ const promptStartedAt = isoNow();
2838
+ const promptMessageId = recordPromptSubmission(conversation, options.prompt, promptStartedAt);
2839
+ record.lastPromptAt = promptStartedAt;
2840
+ record.lastUsedAt = promptStartedAt;
2841
+ applyConversation(record, conversation);
2842
+ record.acpx = acpxState;
2843
+ await writeSessionRecord(record);
2844
+ output.setContext({ sessionId: record.acpxRecordId });
2845
+ const eventWriter = await measurePerf("session.events.open", async () => {
2846
+ return await SessionEventWriter.open(record);
2847
+ });
2848
+ const pendingMessages = [];
2849
+ const pendingConnectOutputMessages = [];
2850
+ const sessionOptions = mergeSessionOptions(options.sessionOptions, sessionOptionsFromRecord(record));
2851
+ let bufferingConnectOutput = true;
2852
+ let promptTurnActive = false;
2853
+ let promptTurnHadSideEffects = false;
2854
+ const acpErrors = new AcpErrorTracker();
2855
+ let eventWriterClosed = false;
2856
+ const closeEventWriter = async (checkpoint) => {
2857
+ if (eventWriterClosed) return;
2858
+ eventWriterClosed = true;
2859
+ await eventWriter.close({ checkpoint });
2860
+ };
2861
+ const flushPendingMessages = async (checkpoint = false) => {
2862
+ if (pendingMessages.length === 0) return;
2863
+ const batch = pendingMessages.splice(0);
2864
+ await measurePerf("session.events.flush_pending", async () => {
2865
+ await eventWriter.appendMessages(batch, { checkpoint });
2866
+ });
2867
+ };
2868
+ const preserveClosedState = async () => {
2869
+ const latest = await resolveSessionRecord(record.acpxRecordId).catch(() => void 0);
2870
+ if (!latest?.closed) return;
2871
+ record.closed = true;
2872
+ record.closedAt = latest.closedAt ?? record.closedAt ?? isoNow();
2873
+ record.pid = latest.pid;
2874
+ if (latest.acpx) record.acpx = {
2875
+ ...record.acpx,
2876
+ ...latest.acpx
2877
+ };
2878
+ };
2879
+ const liveCheckpoint = new LiveSessionCheckpoint({
2880
+ save: async () => {
2881
+ await flushPendingMessages(false);
2882
+ record.lastUsedAt = isoNow();
2883
+ applyConversation(record, conversation);
2884
+ record.acpx = acpxState;
2885
+ await preserveClosedState();
2886
+ await eventWriter.checkpoint();
2887
+ },
2888
+ onError: (error) => {
2889
+ if (options.verbose) process.stderr.write("[acpx] live session checkpoint failed: " + formatErrorMessage(error) + "\n");
2890
+ }
2891
+ });
2892
+ const ownClient = options.client == null;
2893
+ const client = options.client ?? new AcpClient({
2894
+ agentCommand: record.agentCommand,
2895
+ cwd: absolutePath(record.cwd),
2896
+ mcpServers: options.mcpServers,
2897
+ permissionMode: options.permissionMode,
2898
+ nonInteractivePermissions: options.nonInteractivePermissions,
2899
+ permissionPolicy: options.permissionPolicy,
2900
+ authCredentials: options.authCredentials,
2901
+ authPolicy: options.authPolicy,
2902
+ terminal: options.terminal,
2903
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
2904
+ verbose: options.verbose,
2905
+ sessionOptions
2906
+ });
2907
+ client.updateRuntimeOptions({
2908
+ permissionMode: options.permissionMode,
2909
+ nonInteractivePermissions: options.nonInteractivePermissions,
2910
+ permissionPolicy: options.permissionPolicy,
2911
+ terminal: options.terminal,
2912
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
2913
+ verbose: options.verbose
2914
+ });
2915
+ client.setEventHandlers({
2916
+ onAcpMessage: (direction, message) => {
2917
+ pendingMessages.push(message);
2918
+ options.onAcpMessage?.(direction, message);
2919
+ },
2920
+ onAcpOutputMessage: (direction, message) => {
2921
+ if (bufferingConnectOutput) {
2922
+ pendingConnectOutputMessages.push({
2923
+ direction,
2924
+ message
2925
+ });
2926
+ return;
2927
+ }
2928
+ acpErrors.observe(output, direction, message);
2929
+ },
2930
+ onSessionUpdate: (notification) => {
2931
+ if (promptTurnActive) promptTurnHadSideEffects = true;
2932
+ acpxState = recordSessionUpdate(conversation, acpxState, notification);
2933
+ trimConversationForRuntime(conversation);
2934
+ liveCheckpoint.request();
2935
+ options.onSessionUpdate?.(notification);
2936
+ },
2937
+ onClientOperation: (operation) => {
2938
+ if (promptTurnActive) promptTurnHadSideEffects = true;
2939
+ acpxState = recordClientOperation(conversation, acpxState, operation);
2940
+ trimConversationForRuntime(conversation);
2941
+ liveCheckpoint.request();
2942
+ options.onClientOperation?.(operation);
2943
+ },
2944
+ onPermissionEscalation: (event) => {
2945
+ output.onPermissionEscalation(event);
2946
+ options.onPermissionEscalation?.(event);
2947
+ }
2948
+ });
2949
+ let activeSessionIdForControl = record.acpSessionId;
2950
+ let notifiedClientAvailable = false;
2951
+ const activeController = {
2952
+ hasActivePrompt: () => client.hasActivePrompt(),
2953
+ requestCancelActivePrompt: async () => await client.requestCancelActivePrompt(),
2954
+ setSessionMode: async (modeId) => {
2955
+ await client.setSessionMode(activeSessionIdForControl, modeId);
2956
+ },
2957
+ setSessionModel: async (modelId) => {
2958
+ const models = advertisedModelState(acpxState);
2959
+ const response = await client.setSessionModel(activeSessionIdForControl, modelId, models);
2960
+ acpxState = applyConfigOptionResponseToState(acpxState, response);
2961
+ const nextState = cloneSessionAcpxState(acpxState) ?? {};
2962
+ nextState.session_options = {
2963
+ ...nextState.session_options,
2964
+ model: modelId
2965
+ };
2966
+ nextState.current_model_id = currentModelIdFromSetModelResponse(response, modelId);
2967
+ clearDesiredConfigOption(nextState, models?.configId);
2968
+ acpxState = nextState;
2969
+ return response;
2970
+ },
2971
+ setSessionConfigOption: async (configId, value) => {
2972
+ const response = await client.setSessionConfigOption(activeSessionIdForControl, configId, value);
2973
+ acpxState = applyConfigOptionResponseToState(acpxState, response);
2974
+ const nextState = cloneSessionAcpxState(acpxState) ?? {};
2975
+ if (configId === modelStateFromConfigOptions(nextState.config_options)?.configId) {
2976
+ nextState.session_options = {
2977
+ ...nextState.session_options,
2978
+ model: value
2979
+ };
2980
+ nextState.current_model_id = currentModelIdFromSetModelResponse(response, value);
2981
+ clearDesiredConfigOption(nextState, configId);
2982
+ } else if (configId === "mode") nextState.desired_mode_id = value;
2983
+ else nextState.desired_config_options = {
2984
+ ...nextState.desired_config_options,
2985
+ [configId]: value
2986
+ };
2987
+ acpxState = nextState;
2988
+ return response;
2989
+ }
2990
+ };
2991
+ const flushConnectOutput = (loadError) => {
2992
+ bufferingConnectOutput = false;
2993
+ const outputMessages = filterBufferedConnectOutput(pendingConnectOutputMessages, loadError);
2994
+ for (const { direction, message } of outputMessages) acpErrors.observe(output, direction, message);
2995
+ pendingConnectOutputMessages.length = 0;
2996
+ };
2997
+ const connectForPrompt = async () => {
2998
+ const connectStartedAt = Date.now();
2999
+ try {
3000
+ const connected = await measurePerf("runtime.connect_and_load", async () => {
3001
+ return await connectAndLoadSession({
3002
+ client,
3003
+ record,
3004
+ resumePolicy: options.resumePolicy,
3005
+ timeoutMs: options.timeoutMs,
3006
+ verbose: options.verbose,
3007
+ suppressWarnings: options.suppressSdkConsoleErrors,
3008
+ activeController,
3009
+ onClientAvailable: (controller) => {
3010
+ options.onClientAvailable?.(controller);
3011
+ notifiedClientAvailable = true;
3012
+ },
3013
+ onConnectedRecord: (connectedRecord) => {
3014
+ connectedRecord.lastPromptAt = isoNow();
3015
+ },
3016
+ onSessionIdResolved: (sessionId) => {
3017
+ activeSessionIdForControl = sessionId;
3018
+ }
3019
+ });
3020
+ });
3021
+ acpxState = mergeConnectedModelState(acpxState, record.acpx);
3022
+ flushConnectOutput(connected.loadError);
3023
+ emitConnectPerfMetric(connectStartedAt, options.verbose);
3024
+ return connected;
3025
+ } catch (error) {
3026
+ flushConnectOutput();
3027
+ throw error;
3028
+ }
3029
+ };
3030
+ const buildPromptStartedHook = (attempt) => {
3031
+ if (attempt !== 0 || !options.onPromptActive) return;
3032
+ return async () => {
3033
+ try {
3034
+ await options.onPromptActive?.();
3035
+ } catch (error) {
3036
+ emitPromptHookError(error, options.verbose);
3037
+ }
3038
+ };
3039
+ };
3040
+ const runPromptAttempt = async (sessionId, attempt) => {
3041
+ acpErrors.reset();
3042
+ const promptStartedAt = Date.now();
3043
+ const response = await measurePerf("runtime.prompt.agent_turn", async () => {
3044
+ return await runPromptTurn({
3045
+ client,
3046
+ sessionId,
3047
+ prompt: options.prompt,
3048
+ timeoutMs: options.timeoutMs,
3049
+ conversation,
3050
+ promptMessageId,
3051
+ onPromptStarted: buildPromptStartedHook(attempt)
3052
+ });
3053
+ });
3054
+ emitPromptPerfMetric(promptStartedAt, options.verbose);
3055
+ return response;
3056
+ };
3057
+ const handlePromptFailure = async (error, attempt) => {
3058
+ const snapshot = client.getAgentLifecycleSnapshot();
3059
+ if (shouldRetryRuntimePrompt(error, attempt, options.promptRetries ?? 0, snapshot, () => promptTurnHadSideEffects)) {
3060
+ await waitBeforePromptRetry(error, attempt, options.promptRetries ?? 0, options.suppressSdkConsoleErrors);
3061
+ return promptTurnHadSideEffects ? await failRuntimePrompt(error, snapshot) : "retry";
3062
+ }
3063
+ return await failRuntimePrompt(error, snapshot);
3064
+ };
3065
+ const failRuntimePrompt = async (error, snapshot) => {
3066
+ promptTurnActive = false;
3067
+ applyLifecycleSnapshotToRecord(record, snapshot);
3068
+ emitPromptDisconnectNotice(snapshot, options.verbose);
3069
+ const matchedAcpError = acpErrors.match(error);
3070
+ const normalizedError = normalizeOutputError(error, {
3071
+ origin: "runtime",
3072
+ acp: matchedAcpError
3073
+ });
3074
+ await flushPendingMessages(false).catch(() => {});
3075
+ output.flush();
3076
+ record.lastUsedAt = isoNow();
3077
+ applyConversation(record, conversation);
3078
+ record.acpx = acpxState;
3079
+ const propagated = error instanceof Error ? error : new Error(formatErrorMessage(error));
3080
+ attachAcpErrorPayload(propagated, normalizedError.acp);
3081
+ propagated.outputAlreadyEmitted = matchedAcpError !== void 0 && shouldMarkAcpErrorsEmitted;
3082
+ propagated.normalizedOutputError = normalizedError;
3083
+ throw propagated;
3084
+ };
3085
+ const runPromptWithRetries = async (sessionId) => {
3086
+ promptTurnActive = true;
3087
+ for (let attempt = 0;; attempt++) try {
3088
+ return await runPromptAttempt(sessionId, attempt);
3089
+ } catch (error) {
3090
+ if (await handlePromptFailure(error, attempt) === "retry") continue;
3091
+ }
3092
+ };
3093
+ const savePromptSuccess = async (response) => {
3094
+ await flushPendingMessages(false);
3095
+ output.flush();
3096
+ record.lastUsedAt = isoNow();
3097
+ record.closed = false;
3098
+ record.closedAt = void 0;
3099
+ record.protocolVersion = client.initializeResult?.protocolVersion;
3100
+ record.agentCapabilities = client.initializeResult?.agentCapabilities;
3101
+ applyConversation(record, conversation);
3102
+ record.acpx = acpxState;
3103
+ applyLifecycleSnapshotToRecord(record, client.getAgentLifecycleSnapshot());
3104
+ stopTotalTimer();
3105
+ return response;
3106
+ };
3107
+ const runPrompt = async () => {
3108
+ const { sessionId: activeSessionId, resumed, loadError } = await connectForPrompt();
3109
+ await applyPromptModelIfAdvertised({
3110
+ client,
3111
+ sessionId: activeSessionId,
3112
+ requestedModel: sessionOptions?.model,
3113
+ record,
3114
+ timeoutMs: options.timeoutMs,
3115
+ suppressWarnings: options.suppressSdkConsoleErrors
3116
+ });
3117
+ acpxState = cloneSessionAcpxState(record.acpx);
3118
+ output.setContext({ sessionId: record.acpxRecordId });
3119
+ await liveCheckpoint.checkpoint();
3120
+ const response = await savePromptSuccess(await runPromptWithRetries(activeSessionId));
3121
+ promptTurnActive = false;
3122
+ return {
3123
+ ...toPromptResult(response.stopReason, record.acpxRecordId, client),
3124
+ record,
3125
+ resumed,
3126
+ loadError
3127
+ };
3128
+ };
3129
+ const handleInterrupt = async () => {
3130
+ await client.cancelActivePrompt(INTERRUPT_CANCEL_WAIT_MS);
3131
+ applyLifecycleSnapshotToRecord(record, client.getAgentLifecycleSnapshot());
3132
+ record.lastUsedAt = isoNow();
3133
+ applyConversation(record, conversation);
3134
+ record.acpx = acpxState;
3135
+ await flushPendingMessages(false).catch(() => {});
3136
+ if (ownClient) await client.close();
3137
+ };
3138
+ try {
3139
+ return await runWithOptionalInterrupt({
3140
+ handleProcessInterrupts: options.handleProcessInterrupts,
3141
+ run: runPrompt,
3142
+ handleInterrupt
3143
+ });
3144
+ } catch (error) {
3145
+ const matchedAcpError = acpErrors.match(error);
3146
+ attachAcpErrorPayload(error, matchedAcpError);
3147
+ markOutputAlreadyEmitted(error, matchedAcpError !== void 0 && shouldMarkAcpErrorsEmitted);
3148
+ throw error;
3149
+ } finally {
3150
+ if (options.verbose) process.stderr.write(`[acpx] ${formatPerfMetric("prompt.total", stopTotalTimer())}\n`);
3151
+ else stopTotalTimer();
3152
+ if (notifiedClientAvailable) options.onClientClosed?.();
3153
+ client.clearEventHandlers();
3154
+ if (ownClient) await client.close();
3155
+ applyLifecycleSnapshotToRecord(record, client.getAgentLifecycleSnapshot());
3156
+ applyConversation(record, conversation);
3157
+ record.acpx = acpxState;
3158
+ await liveCheckpoint.flush().catch(() => {});
3159
+ await flushPendingMessages(false).catch(() => {});
3160
+ await preserveClosedState().catch(() => {});
3161
+ await closeEventWriter(true).catch(() => {});
3162
+ }
3163
+ }
3164
+ async function runOnce(options) {
3165
+ const output = options.outputFormatter;
3166
+ const shouldMarkAcpErrorsEmitted = rendersAcpErrors(options.errorEmissionPolicy);
3167
+ let promptTurnActive = false;
3168
+ let promptTurnHadSideEffects = false;
3169
+ const acpErrors = new AcpErrorTracker();
3170
+ const client = new AcpClient({
3171
+ agentCommand: options.agentCommand,
3172
+ cwd: absolutePath(options.cwd),
3173
+ mcpServers: options.mcpServers,
3174
+ permissionMode: options.permissionMode,
3175
+ nonInteractivePermissions: options.nonInteractivePermissions,
3176
+ permissionPolicy: options.permissionPolicy,
3177
+ authCredentials: options.authCredentials,
3178
+ authPolicy: options.authPolicy,
3179
+ terminal: options.terminal,
3180
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
3181
+ verbose: options.verbose,
3182
+ onAcpMessage: options.onAcpMessage,
3183
+ onAcpOutputMessage: (direction, message) => {
3184
+ acpErrors.observe(output, direction, message);
3185
+ },
3186
+ onSessionUpdate: (notification) => {
3187
+ if (promptTurnActive) promptTurnHadSideEffects = true;
3188
+ options.onSessionUpdate?.(notification);
3189
+ },
3190
+ onClientOperation: (operation) => {
3191
+ if (promptTurnActive) promptTurnHadSideEffects = true;
3192
+ options.onClientOperation?.(operation);
3193
+ },
3194
+ onPermissionEscalation: (event) => {
3195
+ output.onPermissionEscalation(event);
3196
+ options.onPermissionEscalation?.(event);
3197
+ },
3198
+ sessionOptions: options.sessionOptions
3199
+ });
3200
+ const runExecPromptAttempt = async (sessionId) => {
3201
+ acpErrors.reset();
3202
+ return await measurePerf("runtime.exec.prompt", async () => {
3203
+ return await withTimeout(client.prompt(sessionId, options.prompt), options.timeoutMs);
3204
+ });
3205
+ };
3206
+ const runExecPromptWithRetries = async (sessionId) => {
3207
+ const maxRetries = options.promptRetries ?? 0;
3208
+ promptTurnActive = true;
3209
+ for (let attempt = 0;; attempt++) try {
3210
+ return await runExecPromptAttempt(sessionId);
3211
+ } catch (error) {
3212
+ if (shouldRetryPromptAttempt(error, attempt, maxRetries, () => promptTurnHadSideEffects)) {
3213
+ await waitBeforePromptRetry(error, attempt, maxRetries, options.suppressSdkConsoleErrors);
3214
+ if (!promptTurnHadSideEffects) continue;
3215
+ }
3216
+ promptTurnActive = false;
3217
+ throw error;
3218
+ }
3219
+ };
3220
+ try {
3221
+ return await withInterrupt(async () => {
3222
+ await measurePerf("runtime.exec.start", async () => {
3223
+ await withTimeout(client.start(), options.timeoutMs);
3224
+ });
3225
+ const createdSession = await measurePerf("runtime.exec.create_session", async () => {
3226
+ return await withTimeout(client.createSession(absolutePath(options.cwd)), options.timeoutMs);
3227
+ });
3228
+ const sessionId = createdSession.sessionId;
3229
+ await applyRequestedModelIfAdvertised({
3230
+ client,
3231
+ sessionId,
3232
+ requestedModel: options.sessionOptions?.model,
3233
+ models: createdSession.models,
3234
+ agentCommand: options.agentCommand,
3235
+ timeoutMs: options.timeoutMs,
3236
+ onWarning: options.suppressSdkConsoleErrors ? void 0 : (message) => process.stderr.write(`[acpx] warning: ${message}\n`)
3237
+ });
3238
+ output.setContext({ sessionId });
3239
+ const response = await runExecPromptWithRetries(sessionId);
3240
+ promptTurnActive = false;
3241
+ output.flush();
3242
+ return toPromptResult(response.stopReason, sessionId, client);
3243
+ }, async () => {
3244
+ await client.cancelActivePrompt(INTERRUPT_CANCEL_WAIT_MS);
3245
+ await client.close();
3246
+ });
3247
+ } catch (error) {
3248
+ const matchedAcpError = acpErrors.match(error);
3249
+ attachAcpErrorPayload(error, matchedAcpError);
3250
+ markOutputAlreadyEmitted(error, matchedAcpError !== void 0 && shouldMarkAcpErrorsEmitted);
3251
+ throw error;
3252
+ } finally {
3253
+ await client.close();
3254
+ }
3255
+ }
3256
+ async function sendSessionDirect(options) {
3257
+ return await runSessionPrompt({
3258
+ sessionRecordId: options.sessionId,
3259
+ prompt: options.prompt,
3260
+ mcpServers: options.mcpServers,
3261
+ permissionMode: options.permissionMode,
3262
+ resumePolicy: options.resumePolicy,
3263
+ nonInteractivePermissions: options.nonInteractivePermissions,
3264
+ permissionPolicy: options.permissionPolicy,
3265
+ authCredentials: options.authCredentials,
3266
+ authPolicy: options.authPolicy,
3267
+ terminal: options.terminal,
3268
+ outputFormatter: options.outputFormatter,
3269
+ errorEmissionPolicy: options.errorEmissionPolicy,
3270
+ onAcpMessage: options.onAcpMessage,
3271
+ onSessionUpdate: options.onSessionUpdate,
3272
+ onClientOperation: options.onClientOperation,
3273
+ onPermissionEscalation: options.onPermissionEscalation,
3274
+ timeoutMs: options.timeoutMs,
3275
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
3276
+ verbose: options.verbose,
3277
+ client: options.client
3278
+ });
3279
+ }
3280
+ //#endregion
3281
+ //#region src/cli/session/queue-owner-runtime.ts
3282
+ const QUEUE_OWNER_STARTUP_MAX_ATTEMPTS = 120;
3283
+ const QUEUE_OWNER_HEARTBEAT_INTERVAL_MS = 5e3;
3284
+ const QUEUE_OWNER_ACTIVE_TURN_CANCEL_GRACE_MS = 750;
3285
+ async function submitToRunningOwner(options, waitForCompletion) {
3286
+ return await trySubmitToRunningOwner({
3287
+ sessionId: options.sessionId,
3288
+ message: promptToDisplayText(options.prompt),
3289
+ prompt: options.prompt,
3290
+ mcpConfigPath: options.mcpConfigPath,
3291
+ mcpConfigFingerprint: options.mcpConfigFingerprint,
3292
+ permissionMode: options.permissionMode,
3293
+ nonInteractivePermissions: options.nonInteractivePermissions,
3294
+ permissionPolicy: options.permissionPolicy,
3295
+ outputFormatter: options.outputFormatter,
3296
+ errorEmissionPolicy: options.errorEmissionPolicy,
3297
+ timeoutMs: options.timeoutMs,
3298
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
3299
+ promptRetries: options.promptRetries,
3300
+ waitForCompletion,
3301
+ verbose: options.verbose,
3302
+ sessionOptions: options.sessionOptions
3303
+ });
3304
+ }
3305
+ function createQueueOwnerSharedClient(options, sessionRecord) {
3306
+ return new AcpClient({
3307
+ agentCommand: sessionRecord.agentCommand,
3308
+ cwd: absolutePath(sessionRecord.cwd),
3309
+ mcpServers: options.mcpServers,
3310
+ permissionMode: options.permissionMode,
3311
+ nonInteractivePermissions: options.nonInteractivePermissions,
3312
+ authCredentials: options.authCredentials,
3313
+ authPolicy: options.authPolicy,
3314
+ terminal: options.terminal,
3315
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
3316
+ verbose: options.verbose,
3317
+ sessionOptions: mergeSessionOptions(options.sessionOptions, sessionOptionsFromRecord(sessionRecord))
3318
+ });
3319
+ }
3320
+ function createQueueOwnerTurnController(options) {
3321
+ return new QueueOwnerTurnController({
3322
+ withTimeout: async (run, timeoutMs) => await withTimeout(run(), timeoutMs),
3323
+ setSessionModeFallback: async (modeId, timeoutMs) => {
3324
+ await runSessionSetModeDirect({
3325
+ sessionRecordId: options.sessionId,
3326
+ modeId,
3327
+ mcpServers: options.mcpServers,
3328
+ nonInteractivePermissions: options.nonInteractivePermissions,
3329
+ authCredentials: options.authCredentials,
3330
+ authPolicy: options.authPolicy,
3331
+ terminal: options.terminal,
3332
+ timeoutMs,
3333
+ verbose: options.verbose
3334
+ });
3335
+ },
3336
+ setSessionModelFallback: async (modelId, timeoutMs) => {
3337
+ return (await runSessionSetModelDirect({
3338
+ sessionRecordId: options.sessionId,
3339
+ modelId,
3340
+ mcpServers: options.mcpServers,
3341
+ nonInteractivePermissions: options.nonInteractivePermissions,
3342
+ authCredentials: options.authCredentials,
3343
+ authPolicy: options.authPolicy,
3344
+ terminal: options.terminal,
3345
+ timeoutMs,
3346
+ verbose: options.verbose
3347
+ })).response;
3348
+ },
3349
+ setSessionConfigOptionFallback: async (configId, value, timeoutMs) => {
3350
+ return (await runSessionSetConfigOptionDirect({
3351
+ sessionRecordId: options.sessionId,
3352
+ configId,
3353
+ value,
3354
+ mcpServers: options.mcpServers,
3355
+ nonInteractivePermissions: options.nonInteractivePermissions,
3356
+ authCredentials: options.authCredentials,
3357
+ authPolicy: options.authPolicy,
3358
+ terminal: options.terminal,
3359
+ timeoutMs,
3360
+ verbose: options.verbose
3361
+ })).response;
3362
+ }
3363
+ });
3364
+ }
3365
+ function logDeferredCancelFailure(error, verbose) {
3366
+ if (!verbose) return;
3367
+ process.stderr.write(`[acpx] failed to apply deferred cancel: ${formatErrorMessage(error)}\n`);
3368
+ }
3369
+ function logQueueOwnerReady(params) {
3370
+ if (!params.verbose) return;
3371
+ process.stderr.write(`[acpx] queue owner ready for session ${params.sessionId} (ttlMs=${params.ttlMs}, maxQueueDepth=${params.maxQueueDepth})\n`);
3372
+ }
3373
+ async function closeQueueOwnerRuntime(params) {
3374
+ if (params.heartbeatTimer) clearInterval(params.heartbeatTimer);
3375
+ params.turnController.beginClosing();
3376
+ await params.sharedClient.close().catch(() => {});
3377
+ await params.owner?.close();
3378
+ await writeQueueOwnerLifecycleSnapshot(params.sessionId, params.sharedClient);
3379
+ await releaseQueueOwnerLease(params.lease);
3380
+ if (params.verbose) process.stderr.write(`[acpx] queue owner stopped for session ${params.sessionId}\n`);
3381
+ }
3382
+ async function writeQueueOwnerLifecycleSnapshot(sessionId, sharedClient) {
3383
+ try {
3384
+ const record = await resolveSessionRecord(sessionId);
3385
+ applyLifecycleSnapshotToRecord(record, sharedClient.getAgentLifecycleSnapshot());
3386
+ await writeSessionRecord(record);
3387
+ } catch {}
3388
+ }
3389
+ async function settlesWithin(promise, timeoutMs) {
3390
+ let timer;
3391
+ const timeout = new Promise((resolve) => {
3392
+ timer = setTimeout(() => resolve(false), timeoutMs);
3393
+ });
3394
+ try {
3395
+ return await Promise.race([promise.then(() => true, () => true), timeout]);
3396
+ } finally {
3397
+ if (timer) clearTimeout(timer);
3398
+ }
3399
+ }
3400
+ function createQueueOwnerShutdownController(params) {
3401
+ let requested = false;
3402
+ let activeTurn;
3403
+ let activeTurnShutdown;
3404
+ let shutdownPromise;
3405
+ const drainActiveTurn = async () => {
3406
+ const turn = activeTurn;
3407
+ if (!turn) return;
3408
+ params.turnController.requestCancel().catch((error) => {
3409
+ logDeferredCancelFailure(error, params.verbose);
3410
+ });
3411
+ if (!await settlesWithin(turn, QUEUE_OWNER_ACTIVE_TURN_CANCEL_GRACE_MS)) await params.sharedClient.close().catch(() => {});
3412
+ await turn.catch(() => {});
3413
+ };
3414
+ const request = () => {
3415
+ requested = true;
3416
+ params.stopHeartbeat();
3417
+ params.getOwner()?.beginShutdown();
3418
+ activeTurnShutdown ??= drainActiveTurn();
3419
+ };
3420
+ return {
3421
+ get requested() {
3422
+ return requested;
3423
+ },
3424
+ request,
3425
+ setActiveTurn: (turn) => {
3426
+ activeTurn = turn;
3427
+ },
3428
+ clearActiveTurn: (turn) => {
3429
+ if (activeTurn === turn) activeTurn = void 0;
3430
+ },
3431
+ shutdown: () => {
3432
+ request();
3433
+ shutdownPromise ??= (async () => {
3434
+ await activeTurnShutdown;
3435
+ await closeQueueOwnerRuntime({
3436
+ lease: params.lease,
3437
+ owner: params.getOwner(),
3438
+ heartbeatTimer: void 0,
3439
+ turnController: params.turnController,
3440
+ sharedClient: params.sharedClient,
3441
+ sessionId: params.sessionId,
3442
+ verbose: params.verbose
3443
+ });
3444
+ })();
3445
+ return shutdownPromise;
3446
+ }
3447
+ };
3448
+ }
3449
+ function applyRequestedShutdown(owner, shutdown) {
3450
+ if (shutdown.requested) owner.beginShutdown();
3451
+ }
3452
+ function startQueueOwnerHeartbeat(params) {
3453
+ if (!params.enabled) return;
3454
+ return setInterval(() => {
3455
+ refreshQueueOwnerLease(params.lease, { queueDepth: params.owner.queueDepth() }).catch(() => {});
3456
+ }, QUEUE_OWNER_HEARTBEAT_INTERVAL_MS);
3457
+ }
3458
+ async function runSessionQueueOwner(options) {
3459
+ const lease = await tryAcquireQueueOwnerLease(options.sessionId, {
3460
+ path: options.mcpConfigPath,
3461
+ fingerprint: options.mcpConfigFingerprint
3462
+ });
3463
+ if (!lease) return;
3464
+ const sessionRecord = await resolveSessionRecord(options.sessionId);
3465
+ let owner;
3466
+ let heartbeatTimer;
3467
+ const sharedClient = createQueueOwnerSharedClient(options, sessionRecord);
3468
+ const ttlMs = normalizeQueueOwnerTtlMs(options.ttlMs);
3469
+ const maxQueueDepth = Math.max(1, Math.round(options.maxQueueDepth ?? 16));
3470
+ const taskPollTimeoutMs = ttlMs === 0 ? void 0 : ttlMs;
3471
+ const initialTaskPollTimeoutMs = taskPollTimeoutMs == null ? void 0 : Math.max(taskPollTimeoutMs, 1e3);
3472
+ const turnController = createQueueOwnerTurnController(options);
3473
+ const applyPendingCancel = async () => {
3474
+ return await turnController.applyPendingCancel();
3475
+ };
3476
+ const scheduleApplyPendingCancel = () => {
3477
+ applyPendingCancel().catch((error) => {
3478
+ logDeferredCancelFailure(error, options.verbose);
3479
+ });
3480
+ };
3481
+ const setActiveController = (controller) => {
3482
+ turnController.setActiveController(controller);
3483
+ scheduleApplyPendingCancel();
3484
+ };
3485
+ const clearActiveController = () => {
3486
+ turnController.clearActiveController();
3487
+ };
3488
+ const closeActiveBackendSession = async (timeoutMs) => {
3489
+ const latestRecord = await resolveSessionRecord(options.sessionId);
3490
+ if (!sharedClient.supportsCloseSession()) return false;
3491
+ await withTimeout(sharedClient.closeSession(latestRecord.acpSessionId), timeoutMs);
3492
+ return true;
3493
+ };
3494
+ const runPromptTurn = async (run) => {
3495
+ turnController.beginTurn();
3496
+ try {
3497
+ return await run();
3498
+ } finally {
3499
+ turnController.endTurn();
3500
+ }
3501
+ };
3502
+ const shutdown = createQueueOwnerShutdownController({
3503
+ lease,
3504
+ getOwner: () => owner,
3505
+ stopHeartbeat: () => {
3506
+ if (heartbeatTimer) {
3507
+ clearInterval(heartbeatTimer);
3508
+ heartbeatTimer = void 0;
3509
+ }
3510
+ },
3511
+ turnController,
3512
+ sharedClient,
3513
+ sessionId: options.sessionId,
3514
+ verbose: options.verbose
3515
+ });
3516
+ const onSignal = () => {
3517
+ shutdown.request();
3518
+ };
3519
+ process.once("SIGINT", onSignal);
3520
+ process.once("SIGTERM", onSignal);
3521
+ process.once("SIGHUP", onSignal);
3522
+ try {
3523
+ owner = await SessionQueueOwner.start(lease, {
3524
+ cancelPrompt: async () => {
3525
+ if (!await turnController.requestCancel()) return false;
3526
+ await applyPendingCancel();
3527
+ return true;
3528
+ },
3529
+ closeSession: async (timeoutMs) => await closeActiveBackendSession(timeoutMs),
3530
+ setSessionMode: async (modeId, timeoutMs) => {
3531
+ await turnController.setSessionMode(modeId, timeoutMs);
3532
+ },
3533
+ setSessionModel: async (modelId, timeoutMs) => await turnController.setSessionModel(modelId, timeoutMs),
3534
+ setSessionConfigOption: async (configId, value, timeoutMs) => {
3535
+ return await turnController.setSessionConfigOption(configId, value, timeoutMs);
3536
+ }
3537
+ }, {
3538
+ maxQueueDepth,
3539
+ onQueueDepthChanged: (queueDepth) => {
3540
+ setPerfGauge("queue.owner.depth", queueDepth);
3541
+ refreshQueueOwnerLease(lease, { queueDepth }).catch(() => {});
3542
+ }
3543
+ });
3544
+ applyRequestedShutdown(owner, shutdown);
3545
+ logQueueOwnerReady({
3546
+ sessionId: options.sessionId,
3547
+ ttlMs,
3548
+ maxQueueDepth,
3549
+ verbose: options.verbose
3550
+ });
3551
+ await refreshQueueOwnerLease(lease, { queueDepth: owner.queueDepth() }).catch(() => {});
3552
+ heartbeatTimer = startQueueOwnerHeartbeat({
3553
+ enabled: !shutdown.requested,
3554
+ lease,
3555
+ owner
3556
+ });
3557
+ let isFirstTask = true;
3558
+ while (true) {
3559
+ const pollTimeoutMs = isFirstTask ? initialTaskPollTimeoutMs : taskPollTimeoutMs;
3560
+ const task = await owner.nextTask(pollTimeoutMs);
3561
+ if (!task) break;
3562
+ isFirstTask = false;
3563
+ const turnPromise = runPromptTurn(async () => {
3564
+ try {
3565
+ await runQueuedTask(options.sessionId, task, {
3566
+ sharedClient,
3567
+ verbose: options.verbose,
3568
+ mcpServers: options.mcpServers,
3569
+ nonInteractivePermissions: options.nonInteractivePermissions,
3570
+ authCredentials: options.authCredentials,
3571
+ authPolicy: options.authPolicy,
3572
+ suppressSdkConsoleErrors: options.suppressSdkConsoleErrors,
3573
+ promptRetries: task.promptRetries ?? 0,
3574
+ sessionOptions: options.sessionOptions,
3575
+ onClientAvailable: setActiveController,
3576
+ onClientClosed: clearActiveController,
3577
+ onPromptActive: async () => {
3578
+ turnController.markPromptActive();
3579
+ await applyPendingCancel();
3580
+ },
3581
+ handleProcessInterrupts: false
3582
+ });
3583
+ } finally {
3584
+ checkpointPerfMetricsCapture();
3585
+ }
3586
+ });
3587
+ shutdown.setActiveTurn(turnPromise);
3588
+ try {
3589
+ await turnPromise;
3590
+ } finally {
3591
+ shutdown.clearActiveTurn(turnPromise);
3592
+ }
3593
+ }
3594
+ } finally {
3595
+ process.off("SIGINT", onSignal);
3596
+ process.off("SIGTERM", onSignal);
3597
+ process.off("SIGHUP", onSignal);
3598
+ await shutdown.shutdown();
3599
+ }
3600
+ }
3601
+ async function sendSession(options) {
3602
+ const waitForCompletion = options.waitForCompletion !== false;
3603
+ const queuedToOwner = await submitToRunningOwner(options, waitForCompletion);
3604
+ if (queuedToOwner) return queuedToOwner;
3605
+ spawnQueueOwnerProcess(queueOwnerRuntimeOptionsFromSend(options));
3606
+ for (let attempt = 0; attempt < QUEUE_OWNER_STARTUP_MAX_ATTEMPTS; attempt += 1) {
3607
+ const queued = await submitToRunningOwner(options, waitForCompletion);
3608
+ if (queued) return queued;
3609
+ await waitMs(50);
3610
+ }
3611
+ throw new Error(`Session queue owner failed to start for session ${options.sessionId}`);
3612
+ }
3613
+ //#endregion
3614
+ //#region src/session/session.ts
3615
+ var session_exports = /* @__PURE__ */ __exportAll({
3616
+ DEFAULT_HISTORY_LIMIT: () => 20,
3617
+ DEFAULT_QUEUE_OWNER_TTL_MS: () => DEFAULT_QUEUE_OWNER_TTL_MS,
3618
+ InterruptedError: () => InterruptedError,
3619
+ TimeoutError: () => TimeoutError,
3620
+ cancelSessionPrompt: () => cancelSessionPrompt,
3621
+ closeSession: () => closeSession,
3622
+ createSession: () => createSession,
3623
+ createSessionWithClient: () => createSessionWithClient,
3624
+ ensureSession: () => ensureSession,
3625
+ findGitRepositoryRoot: () => findGitRepositoryRoot,
3626
+ findSession: () => findSession,
3627
+ findSessionByDirectoryWalk: () => findSessionByDirectoryWalk,
3628
+ isProcessAlive: () => isProcessAlive,
3629
+ listAgentSessions: () => listAgentSessions,
3630
+ listSessions: () => listSessions,
3631
+ listSessionsForAgent: () => listSessionsForAgent,
3632
+ mergeConnectedModelState: () => mergeConnectedModelState,
3633
+ normalizeQueueOwnerTtlMs: () => normalizeQueueOwnerTtlMs,
3634
+ pruneSessions: () => pruneSessions,
3635
+ runOnce: () => runOnce,
3636
+ runQueuedTask: () => runQueuedTask,
3637
+ runSessionQueueOwner: () => runSessionQueueOwner,
3638
+ sendSession: () => sendSession,
3639
+ sendSessionDirect: () => sendSessionDirect,
3640
+ sessionControlTestInternals: () => sessionControlTestInternals,
3641
+ setSessionConfigOption: () => setSessionConfigOption,
3642
+ setSessionMode: () => setSessionMode,
3643
+ setSessionModel: () => setSessionModel
3644
+ });
3645
+ //#endregion
3646
+ //#region src/acp/jsonrpc-error.ts
3647
+ const OUTPUT_ERROR_JSONRPC_CODES = {
3648
+ NO_SESSION: -32002,
3649
+ TIMEOUT: -32070,
3650
+ PERMISSION_DENIED: -32071,
3651
+ PERMISSION_PROMPT_UNAVAILABLE: -32072,
3652
+ RUNTIME: -32603,
3653
+ USAGE: -32602
3654
+ };
3655
+ function hasValidAcpError(acp) {
3656
+ return Boolean(acp && Number.isFinite(acp.code) && typeof acp.message === "string" && acp.message.trim().length > 0);
3657
+ }
3658
+ function buildFallbackData(params) {
3659
+ const data = {
3660
+ acpxCode: params.outputCode,
3661
+ detailCode: params.detailCode,
3662
+ origin: params.origin,
3663
+ retryable: params.retryable,
3664
+ timestamp: params.timestamp,
3665
+ sessionId: params.sessionId
3666
+ };
3667
+ for (const [key, value] of Object.entries(data)) if (value === void 0) delete data[key];
3668
+ return data;
3669
+ }
3670
+ function mergeAcpErrorData(acpData, fallbackData) {
3671
+ if (Object.keys(fallbackData).length === 0) return acpData;
3672
+ if (acpData === void 0) return fallbackData;
3673
+ if (acpData && typeof acpData === "object" && !Array.isArray(acpData)) return {
3674
+ ...fallbackData,
3675
+ ...acpData
3676
+ };
3677
+ return acpData;
3678
+ }
3679
+ function buildErrorObject(params) {
3680
+ const fallbackData = buildFallbackData(params);
3681
+ if (hasValidAcpError(params.acp)) {
3682
+ const data = mergeAcpErrorData(params.acp.data, fallbackData);
3683
+ return {
3684
+ code: params.acp.code,
3685
+ message: params.acp.message,
3686
+ ...data !== void 0 ? { data } : {}
3687
+ };
3688
+ }
3689
+ const data = fallbackData;
3690
+ return {
3691
+ code: OUTPUT_ERROR_JSONRPC_CODES[params.outputCode] ?? -32603,
3692
+ message: params.message,
3693
+ ...Object.keys(data).length > 0 ? { data } : {}
3694
+ };
3695
+ }
3696
+ function buildJsonRpcErrorResponse(params) {
3697
+ return {
3698
+ jsonrpc: "2.0",
3699
+ id: params.id ?? null,
3700
+ error: buildErrorObject(params)
3701
+ };
3702
+ }
3703
+ //#endregion
3704
+ //#region src/cli/output/read-suppression.ts
3705
+ const SUPPRESSED_READ_OUTPUT = "[read output suppressed]";
3706
+ function inferToolKindFromTitle(title) {
3707
+ const normalized = title?.trim().toLowerCase();
3708
+ if (!normalized) return;
3709
+ const head = normalized.split(":", 1)[0]?.trim();
3710
+ if (!head) return;
3711
+ if ([
3712
+ "read",
3713
+ "cat",
3714
+ "open",
3715
+ "view"
3716
+ ].some((needle) => head.includes(needle))) return "read";
3717
+ }
3718
+ function isReadLikeTool(tool) {
3719
+ return tool.kind?.trim().toLowerCase() === "read" || inferToolKindFromTitle(tool.title) === "read";
3720
+ }
3721
+ //#endregion
3722
+ //#region src/cli/output/json-formatter.ts
3723
+ const DEFAULT_JSON_SESSION_ID = "unknown";
3724
+ function asRecord$1(value) {
3725
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
3726
+ return value;
3727
+ }
3728
+ function jsonRpcIdKey(value) {
3729
+ if (typeof value === "string") return `s:${value}`;
3730
+ if (typeof value === "number" && Number.isFinite(value)) return `n:${value}`;
3731
+ }
3732
+ function sanitizeReadResult(result) {
3733
+ const record = asRecord$1(result);
3734
+ if (!record || typeof record.content !== "string") return result;
3735
+ return {
3736
+ ...record,
3737
+ content: SUPPRESSED_READ_OUTPUT
3738
+ };
3739
+ }
3740
+ function sanitizeToolContent(content) {
3741
+ if (!Array.isArray(content)) return content;
3742
+ return [{
3743
+ type: "content",
3744
+ content: {
3745
+ type: "text",
3746
+ text: SUPPRESSED_READ_OUTPUT
3747
+ }
3748
+ }];
3749
+ }
3750
+ function sanitizeToolMessage(message) {
3751
+ const root = asRecord$1(message);
3752
+ const params = asRecord$1(root?.params);
3753
+ const update = asRecord$1(params?.update);
3754
+ if (!root || !params || !update) return message;
3755
+ return {
3756
+ ...root,
3757
+ params: {
3758
+ ...params,
3759
+ update: sanitizeToolUpdate(update)
3760
+ }
3761
+ };
3762
+ }
3763
+ function sanitizeToolUpdate(update) {
3764
+ return {
3765
+ ...update,
3766
+ rawOutput: sanitizedRawOutput(update),
3767
+ content: sanitizedContent(update)
3768
+ };
3769
+ }
3770
+ function sanitizedRawOutput(update) {
3771
+ if (Object.prototype.hasOwnProperty.call(update, "rawOutput") && update.rawOutput !== void 0) return { content: SUPPRESSED_READ_OUTPUT };
3772
+ return update.rawOutput;
3773
+ }
3774
+ function sanitizedContent(update) {
3775
+ if (Object.prototype.hasOwnProperty.call(update, "content") && update.content !== void 0) return sanitizeToolContent(update.content);
3776
+ return update.content;
3777
+ }
3778
+ var JsonOutputFormatter = class {
3779
+ stdout;
3780
+ suppressReads;
3781
+ sessionId;
3782
+ requestMethodById = /* @__PURE__ */ new Map();
3783
+ toolStateById = /* @__PURE__ */ new Map();
3784
+ constructor(stdout, suppressReads, context) {
3785
+ this.stdout = stdout;
3786
+ this.suppressReads = suppressReads;
3787
+ this.sessionId = context?.sessionId?.trim() || DEFAULT_JSON_SESSION_ID;
3788
+ }
3789
+ setContext(context) {
3790
+ this.sessionId = context.sessionId?.trim() || this.sessionId || DEFAULT_JSON_SESSION_ID;
3791
+ }
3792
+ onAcpMessage(message) {
3793
+ this.stdout.write(`${JSON.stringify(this.sanitizeMessage(message))}\n`);
3794
+ }
3795
+ sanitizeMessage(message) {
3796
+ if (!this.suppressReads) return message;
3797
+ const sanitizedResponse = this.sanitizeReadResponse(message);
3798
+ if (sanitizedResponse !== message) return sanitizedResponse;
3799
+ const sanitizedToolMessage = this.sanitizeReadToolMessage(message);
3800
+ if (sanitizedToolMessage !== message) return sanitizedToolMessage;
3801
+ this.trackRequestMethod(message);
3802
+ return message;
3803
+ }
3804
+ trackRequestMethod(message) {
3805
+ const candidate = message;
3806
+ if (typeof candidate.method !== "string") return;
3807
+ const idKey = jsonRpcIdKey(candidate.id);
3808
+ if (!idKey) return;
3809
+ this.requestMethodById.set(idKey, candidate.method);
3810
+ }
3811
+ sanitizeReadResponse(message) {
3812
+ const candidate = message;
3813
+ const idKey = jsonRpcIdKey(candidate.id);
3814
+ if (!idKey) return message;
3815
+ const hasResult = Object.hasOwn(candidate, "result");
3816
+ const hasError = Object.hasOwn(candidate, "error");
3817
+ if (!hasResult && !hasError) return message;
3818
+ const method = this.requestMethodById.get(idKey);
3819
+ this.requestMethodById.delete(idKey);
3820
+ if (method !== "fs/read_text_file" || !hasResult) return message;
3821
+ const root = asRecord$1(message);
3822
+ if (!root) return message;
3823
+ return {
3824
+ ...root,
3825
+ result: sanitizeReadResult(candidate.result)
3826
+ };
3827
+ }
3828
+ sanitizeReadToolMessage(message) {
3829
+ const update = this.readToolUpdate(message);
3830
+ if (!update) return message;
3831
+ const toolCallId = typeof update.toolCallId === "string" ? update.toolCallId : void 0;
3832
+ if (!toolCallId) return message;
3833
+ const current = this.mergeToolState(toolCallId, update);
3834
+ this.toolStateById.set(toolCallId, current);
3835
+ return isReadLikeTool(current) ? sanitizeToolMessage(message) : message;
3836
+ }
3837
+ readToolUpdate(message) {
3838
+ const root = asRecord$1(message);
3839
+ if (root?.method !== "session/update") return;
3840
+ const params = asRecord$1(root.params);
3841
+ const update = asRecord$1(params?.update);
3842
+ if (!params || !update) return;
3843
+ const sessionUpdate = update.sessionUpdate;
3844
+ if (sessionUpdate !== "tool_call" && sessionUpdate !== "tool_call_update") return;
3845
+ return update;
3846
+ }
3847
+ mergeToolState(toolCallId, update) {
3848
+ const previous = this.toolStateById.get(toolCallId) ?? {};
3849
+ return {
3850
+ title: typeof update.title === "string" ? update.title : previous.title,
3851
+ kind: typeof update.kind === "string" || update.kind === null ? update.kind : previous.kind
3852
+ };
3853
+ }
3854
+ onError(params) {
3855
+ this.stdout.write(`${JSON.stringify(buildJsonRpcErrorResponse({
3856
+ outputCode: params.code,
3857
+ detailCode: params.detailCode,
3858
+ origin: params.origin,
3859
+ message: params.message,
3860
+ retryable: params.retryable,
3861
+ timestamp: params.timestamp,
3862
+ sessionId: this.sessionId,
3863
+ acp: params.acp
3864
+ }))}\n`);
3865
+ }
3866
+ onPermissionEscalation() {}
3867
+ flush() {}
3868
+ };
3869
+ function createJsonOutputFormatter(stdout, suppressReads = false, context) {
3870
+ return new JsonOutputFormatter(stdout, suppressReads, context);
3871
+ }
3872
+ //#endregion
3873
+ //#region src/cli/output/output.ts
3874
+ var output_exports = /* @__PURE__ */ __exportAll({
3875
+ createOutputFormatter: () => createOutputFormatter,
3876
+ getTextErrorRemediationHints: () => getTextErrorRemediationHints
3877
+ });
3878
+ const MAX_THOUGHT_CHARS = 900;
3879
+ const MAX_INLINE_CHARS = 220;
3880
+ const MAX_OUTPUT_CHARS = 2e3;
3881
+ const MAX_OUTPUT_LINES = 28;
3882
+ const MAX_LOCATION_ITEMS = 5;
3883
+ const OUTPUT_PRIORITY_KEYS = [
3884
+ "stdout",
3885
+ "stderr",
3886
+ "output",
3887
+ "content",
3888
+ "text",
3889
+ "message",
3890
+ "result",
3891
+ "response",
3892
+ "value"
3893
+ ];
3894
+ function asStatus(status) {
3895
+ return status ?? "unknown";
3896
+ }
3897
+ function isFinalStatus(status) {
3898
+ return status === "completed" || status === "failed";
3899
+ }
3900
+ function toStatusLabel(status) {
3901
+ switch (status) {
3902
+ case "in_progress": return "running";
3903
+ case "pending": return "pending";
3904
+ case "completed": return "completed";
3905
+ case "failed": return "failed";
3906
+ default: return "running";
3907
+ }
3908
+ }
3909
+ function asRecord(value) {
3910
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
3911
+ return value;
3912
+ }
3913
+ function parseJsonRpcErrorSummary(message) {
3914
+ const fallback = parseJsonRpcErrorMessage(message);
3915
+ if (!fallback) return;
3916
+ const details = asRecord(asRecord(message.error)?.data)?.details;
3917
+ return typeof details === "string" && details.trim().length > 0 ? details.trim() : fallback;
3918
+ }
3919
+ function extractJsonRpcMethod(message) {
3920
+ return Object.hasOwn(message, "method") ? message.method?.toString() : void 0;
3921
+ }
3922
+ function collapseWhitespace(value) {
3923
+ return value.replace(/\s+/g, " ").trim();
3924
+ }
3925
+ function normalizeLineEndings(value) {
3926
+ return value.replace(/\r\n?/g, "\n");
3927
+ }
3928
+ function truncate(value, maxChars) {
3929
+ if (value.length <= maxChars) return value;
3930
+ if (maxChars <= 3) return value.slice(0, maxChars);
3931
+ return `${value.slice(0, maxChars - 3)}...`;
3932
+ }
3933
+ function toInline(value, maxChars = MAX_INLINE_CHARS) {
3934
+ return truncate(collapseWhitespace(value), maxChars);
3935
+ }
3936
+ function indentBlock(value, prefix) {
3937
+ return value.split("\n").map((line) => `${prefix}${line}`).join("\n");
3938
+ }
3939
+ function dedupeStrings(values) {
3940
+ const seen = /* @__PURE__ */ new Set();
3941
+ const result = [];
3942
+ for (const value of values) {
3943
+ if (seen.has(value)) continue;
3944
+ seen.add(value);
3945
+ result.push(value);
3946
+ }
3947
+ return result;
3948
+ }
3949
+ function safeJson(value, spacing) {
3950
+ const seen = /* @__PURE__ */ new WeakSet();
3951
+ try {
3952
+ return JSON.stringify(value, (_key, entry) => {
3953
+ if (typeof entry === "bigint") return `${entry}n`;
3954
+ if (typeof entry === "function") return `[Function ${entry.name || "anonymous"}]`;
3955
+ if (typeof entry === "symbol") return entry.toString();
3956
+ if (entry && typeof entry === "object") {
3957
+ if (seen.has(entry)) return "[Circular]";
3958
+ seen.add(entry);
3959
+ }
3960
+ return entry;
3961
+ }, spacing);
3962
+ } catch {
3963
+ return;
3964
+ }
3965
+ }
3966
+ function readFirstString(source, keys) {
3967
+ for (const key of keys) {
3968
+ const value = source[key];
3969
+ if (typeof value === "string" && value.trim()) return value.trim();
3970
+ }
3971
+ }
3972
+ function readFirstFiniteNumber(source, keys) {
3973
+ for (const key of keys) {
3974
+ const value = source[key];
3975
+ if (typeof value === "number" && Number.isFinite(value)) return value;
3976
+ }
3977
+ }
3978
+ function formatMetadataNumber(value) {
3979
+ return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(8)));
3980
+ }
3981
+ function readFirstStringArray(source, keys) {
3982
+ for (const key of keys) {
3983
+ const value = source[key];
3984
+ if (!Array.isArray(value)) continue;
3985
+ const entries = value.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
3986
+ if (entries.length > 0) return entries;
3987
+ }
3988
+ }
3989
+ function formatDisjunction(values) {
3990
+ if (values.length <= 1) return values[0] ?? "";
3991
+ if (values.length === 2) return `${values[0]} or ${values[1]}`;
3992
+ return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`;
3993
+ }
3994
+ function parseAuthMethodIdsFromMessage(message) {
3995
+ const methods = [];
3996
+ const methodListMatch = message.match(/auth methods \[([^\]]+)\]/iu);
3997
+ if (methodListMatch) methods.push(...methodListMatch[1].split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0));
3998
+ const singleMethodMatch = message.match(/auth method ([\w.-]+)/iu);
3999
+ if (singleMethodMatch) methods.push(singleMethodMatch[1]);
4000
+ return dedupeStrings(methods);
4001
+ }
4002
+ function parseAuthMethodIdsFromAcpData(data) {
4003
+ const record = asRecord(data);
4004
+ if (!record) return [];
4005
+ const methodIds = [];
4006
+ if (typeof record.methodId === "string" && record.methodId.trim().length > 0) methodIds.push(record.methodId.trim());
4007
+ if (Array.isArray(record.methods)) for (const entry of record.methods) {
4008
+ const id = parseAuthMethodIdEntry(entry);
4009
+ if (id) methodIds.push(id);
4010
+ }
4011
+ return dedupeStrings(methodIds);
4012
+ }
4013
+ function parseAuthMethodIdEntry(entry) {
4014
+ if (typeof entry === "string" && entry.trim().length > 0) return entry.trim();
4015
+ const id = asRecord(entry)?.id;
4016
+ return typeof id === "string" && id.trim().length > 0 ? id.trim() : void 0;
4017
+ }
4018
+ function renderAuthRequiredHint(params) {
4019
+ const methodIds = dedupeStrings([...parseAuthMethodIdsFromAcpData(params.acp?.data), ...parseAuthMethodIdsFromMessage(params.message)]);
4020
+ if (methodIds.length === 0) return "hint: run `acpx config show` to locate the active config, then add the required credential under `auth` and retry.";
4021
+ return `hint: run \`acpx config show\` to locate the active config, then add ${formatDisjunction(methodIds.map((methodId) => `\`auth.${methodId}\``))} and retry.`;
4022
+ }
4023
+ function getTextErrorRemediationHints(params) {
4024
+ const lowerMessage = params.message.toLowerCase();
4025
+ if (params.detailCode === "AUTH_REQUIRED") return [renderAuthRequiredHint(params)];
4026
+ if (params.code === "TIMEOUT") return ["hint: increase `--timeout <seconds>` for long-running prompts, or check whether the agent/provider is stalled."];
4027
+ if (params.code === "NO_SESSION") return noSessionHints(lowerMessage);
4028
+ return matchingTextErrorRule(params, lowerMessage)?.hints ?? [];
4029
+ }
4030
+ const TEXT_ERROR_HINT_RULES = [
4031
+ {
4032
+ matches: (_params, lowerMessage) => isUnsupportedSessionLoadError(lowerMessage),
4033
+ hints: ["hint: this adapter cannot resume saved ACP sessions; create a fresh one with `acpx <agent> sessions new` instead of reusing `--resume-session`."]
4034
+ },
4035
+ {
4036
+ matches: (_params, lowerMessage) => isSessionLoadError(lowerMessage),
4037
+ hints: ["hint: rerun with `--verbose` to capture the ACP load failure details.", "hint: if you do not need the old backend session, start a fresh one with `acpx <agent> sessions new` and retry."]
4038
+ },
4039
+ {
4040
+ matches: (params, lowerMessage) => isRateLimitError(params.message, lowerMessage),
4041
+ hints: ["hint: the provider appears rate-limited; retry later, switch model, or check provider quota/billing."]
4042
+ },
4043
+ {
4044
+ matches: (_params, lowerMessage) => isModelLookupError(lowerMessage),
4045
+ hints: ["hint: check the configured model name for this agent, then retry with `--model <model>` or `sessions set-model <model>`."]
4046
+ },
4047
+ {
4048
+ matches: (_params, lowerMessage) => isSessionConfigMethodError(lowerMessage),
4049
+ hints: ["hint: rerun with `--verbose` to capture the ACP method/error details before retrying."]
4050
+ },
4051
+ {
4052
+ matches: isRuntimeAcpProtocolError,
4053
+ hints: ["hint: rerun with `--verbose` to capture the underlying ACP error details."]
4054
+ }
4055
+ ];
4056
+ function matchingTextErrorRule(params, lowerMessage) {
4057
+ return TEXT_ERROR_HINT_RULES.find((rule) => rule.matches(params, lowerMessage));
4058
+ }
4059
+ function noSessionHints(lowerMessage) {
4060
+ if (lowerMessage.includes("create one:")) return [];
4061
+ return ["hint: the saved ACP session is missing or stale; start a fresh session with `acpx <agent> sessions new`, then retry."];
4062
+ }
4063
+ function isUnsupportedSessionLoadError(lowerMessage) {
4064
+ return lowerMessage.includes("does not support session/resume") || lowerMessage.includes("does not support session/load");
4065
+ }
4066
+ function isSessionLoadError(lowerMessage) {
4067
+ return lowerMessage.includes("failed to resume acp session") || lowerMessage.includes("session/resume") || lowerMessage.includes("session/load");
4068
+ }
4069
+ function isRateLimitError(message, lowerMessage) {
4070
+ return /\b429\b/u.test(message) || ["rate limit", "quota exceeded"].some((text) => lowerMessage.includes(text));
4071
+ }
4072
+ function isModelLookupError(lowerMessage) {
4073
+ return [
4074
+ "model not found",
4075
+ "unknown model",
4076
+ "invalid model"
4077
+ ].some((text) => lowerMessage.includes(text));
4078
+ }
4079
+ function isSessionConfigMethodError(lowerMessage) {
4080
+ return [
4081
+ "session/set_mode",
4082
+ "session/set_model",
4083
+ "session/set_config_option"
4084
+ ].some((text) => lowerMessage.includes(text));
4085
+ }
4086
+ function isRuntimeAcpProtocolError(params, lowerMessage) {
4087
+ return params.origin === "acp" && params.code === "RUNTIME" && (params.acp?.code === -32602 || params.acp?.code === -32603 || lowerMessage.includes("internal error"));
4088
+ }
4089
+ function summarizeToolInput(rawInput) {
4090
+ if (rawInput == null) return;
4091
+ if (isScalarToolInput(rawInput)) return toInline(String(rawInput));
4092
+ const record = asRecord(rawInput);
4093
+ if (record) return summarizeToolInputRecord(record) ?? summarizeToolInputJson(rawInput);
4094
+ return summarizeToolInputJson(rawInput);
4095
+ }
4096
+ function isScalarToolInput(value) {
4097
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
4098
+ }
4099
+ function summarizeToolInputRecord(record) {
4100
+ const command = readFirstString(record, [
4101
+ "command",
4102
+ "cmd",
4103
+ "program"
4104
+ ]);
4105
+ const args = readFirstStringArray(record, ["args", "arguments"]);
4106
+ if (command) return toInline([command, ...args ?? []].join(" "));
4107
+ const location = readFirstString(record, [
4108
+ "path",
4109
+ "file",
4110
+ "filePath",
4111
+ "filepath",
4112
+ "target",
4113
+ "uri",
4114
+ "url"
4115
+ ]);
4116
+ const query = readFirstString(record, [
4117
+ "query",
4118
+ "pattern",
4119
+ "text",
4120
+ "search"
4121
+ ]);
4122
+ return location || query ? toInline(location ?? query ?? "") : void 0;
4123
+ }
4124
+ function summarizeToolInputJson(rawInput) {
4125
+ const json = safeJson(rawInput, 0);
4126
+ return json ? toInline(json) : void 0;
4127
+ }
4128
+ function formatLocations(locations) {
4129
+ if (!locations || locations.length === 0) return;
4130
+ const unique = /* @__PURE__ */ new Set();
4131
+ for (const location of locations) {
4132
+ const formatted = formatLocation(location);
4133
+ if (formatted) unique.add(formatted);
4134
+ }
4135
+ const items = [...unique];
4136
+ if (items.length === 0) return;
4137
+ const visible = items.slice(0, MAX_LOCATION_ITEMS);
4138
+ const hidden = items.length - visible.length;
4139
+ if (hidden <= 0) return visible.join(", ");
4140
+ return `${visible.join(", ")}, +${hidden} more`;
4141
+ }
4142
+ function formatLocation(location) {
4143
+ const path = location.path?.trim();
4144
+ if (!path) return;
4145
+ return `${path}${typeof location.line === "number" && Number.isFinite(location.line) ? `:${Math.max(1, Math.trunc(location.line))}` : ""}`;
4146
+ }
4147
+ function summarizeDiff(path, oldText, newText) {
4148
+ const oldLines = oldText ? oldText.split("\n").length : 0;
4149
+ const delta = newText.split("\n").length - oldLines;
4150
+ if (delta === 0) return `diff ${path} (line count unchanged)`;
4151
+ return `diff ${path} (${`${delta > 0 ? "+" : ""}${delta}`} lines)`;
4152
+ }
4153
+ function textFromContentBlock(content) {
4154
+ switch (content.type) {
4155
+ case "text": return content.text;
4156
+ case "resource_link": return content.title ?? content.name ?? content.uri;
4157
+ case "resource": return textFromResourceBlock(content);
4158
+ case "image": return `[image] ${content.mimeType}`;
4159
+ case "audio": return `[audio] ${content.mimeType}`;
4160
+ default: return;
4161
+ }
4162
+ }
4163
+ function textFromResourceBlock(content) {
4164
+ if ("text" in content.resource && typeof content.resource.text === "string") return content.resource.text;
4165
+ const uri = content.resource.uri;
4166
+ const mimeType = content.resource.mimeType;
4167
+ return `[resource] ${uri}${mimeType ? ` (${mimeType})` : ""}`;
4168
+ }
4169
+ function summarizeToolContent(content) {
4170
+ if (!content || content.length === 0) return;
4171
+ const fragments = [];
4172
+ for (const entry of content) {
4173
+ const fragment = summarizeToolContentEntry(entry);
4174
+ if (fragment) fragments.push(fragment);
4175
+ }
4176
+ const unique = dedupeStrings(fragments.map((fragment) => fragment.trim()).filter((fragment) => fragment.length > 0));
4177
+ if (unique.length === 0) return;
4178
+ return unique.join("\n\n");
4179
+ }
4180
+ function summarizeToolContentEntry(entry) {
4181
+ if (entry.type === "content") {
4182
+ const text = textFromContentBlock(entry.content);
4183
+ return text && text.trim() ? text.trimEnd() : void 0;
4184
+ }
4185
+ if (entry.type === "diff") return summarizeDiff(entry.path, entry.oldText, entry.newText);
4186
+ if (entry.type === "terminal") return `[terminal] ${entry.terminalId}`;
4187
+ }
4188
+ function extractOutputText(value, depth = 0, seen = /* @__PURE__ */ new Set()) {
4189
+ if (value == null) return;
4190
+ const scalar = extractScalarOutputText(value);
4191
+ if (scalar !== null) return scalar;
4192
+ if (depth >= 4) return;
4193
+ if (Array.isArray(value)) return extractOutputTextArray(value, depth, seen);
4194
+ return extractOutputTextRecord(value, depth, seen);
4195
+ }
4196
+ function extractOutputTextRecord(value, depth, seen) {
4197
+ const record = asRecord(value);
4198
+ if (!record || seen.has(record)) return;
4199
+ seen.add(record);
4200
+ return extractPreferredOutputText(record, depth, seen) ?? extractJsonOutputText(record);
4201
+ }
4202
+ function extractScalarOutputText(value) {
4203
+ if (typeof value === "string") {
4204
+ const trimmed = value.trimEnd();
4205
+ return trimmed.length > 0 ? trimmed : void 0;
4206
+ }
4207
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
4208
+ return null;
4209
+ }
4210
+ function extractOutputTextArray(value, depth, seen) {
4211
+ const parts = value.map((entry) => extractOutputText(entry, depth + 1, seen)).filter((entry) => Boolean(entry));
4212
+ return parts.length > 0 ? dedupeStrings(parts).join("\n") : void 0;
4213
+ }
4214
+ function extractPreferredOutputText(record, depth, seen) {
4215
+ const uniquePreferred = dedupeStrings(OUTPUT_PRIORITY_KEYS.flatMap((key) => {
4216
+ if (!(key in record)) return [];
4217
+ const extracted = extractOutputText(record[key], depth + 1, seen);
4218
+ return extracted ? [extracted] : [];
4219
+ }));
4220
+ return uniquePreferred.length > 0 ? uniquePreferred.join("\n") : void 0;
4221
+ }
4222
+ function extractJsonOutputText(record) {
4223
+ const json = safeJson(record, 2);
4224
+ return !json || json === "{}" ? void 0 : json;
4225
+ }
4226
+ function summarizeToolOutput(rawOutput, content) {
4227
+ const fragments = dedupeStrings([extractOutputText(rawOutput), summarizeToolContent(content)].map((fragment) => fragment?.trim()).filter((fragment) => Boolean(fragment)));
4228
+ if (fragments.length === 0) return;
4229
+ return fragments.join("\n\n");
4230
+ }
4231
+ function renderToolOutput(state, suppressReads) {
4232
+ if (suppressReads && isReadLikeTool(state)) return SUPPRESSED_READ_OUTPUT;
4233
+ return summarizeToolOutput(state.rawOutput, state.content);
4234
+ }
4235
+ function limitOutputBlock(value) {
4236
+ const normalized = value.replace(/\r\n/g, "\n").trim();
4237
+ if (!normalized) return "";
4238
+ const lines = normalized.split("\n");
4239
+ const visible = lines.slice(0, MAX_OUTPUT_LINES);
4240
+ let result = visible.join("\n");
4241
+ if (lines.length > visible.length) {
4242
+ const hidden = lines.length - visible.length;
4243
+ result += `\n... (${hidden} more lines)`;
4244
+ }
4245
+ if (result.length > MAX_OUTPUT_CHARS) result = `${result.slice(0, MAX_OUTPUT_CHARS - 3)}...`;
4246
+ return result;
4247
+ }
4248
+ var TextOutputFormatter = class {
4249
+ stdout;
4250
+ useColor;
4251
+ suppressReads;
4252
+ toolStates = /* @__PURE__ */ new Map();
4253
+ thoughtBuffer = "";
4254
+ wroteAny = false;
4255
+ atLineStart = true;
4256
+ section = null;
4257
+ constructor(stdout, suppressReads) {
4258
+ this.stdout = stdout;
4259
+ this.useColor = Boolean(stdout.isTTY);
4260
+ this.suppressReads = suppressReads;
4261
+ }
4262
+ setContext(_context) {}
4263
+ onAcpMessage(message) {
4264
+ const notification = extractSessionUpdateNotification(message);
4265
+ if (notification) {
4266
+ this.renderSessionUpdate(notification);
4267
+ return;
4268
+ }
4269
+ const method = extractJsonRpcMethod(message);
4270
+ if (method && method !== "session/prompt" && method !== "session/cancel") {
4271
+ this.onClientOperation({
4272
+ method,
4273
+ status: "running",
4274
+ summary: method,
4275
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
4276
+ });
4277
+ return;
4278
+ }
4279
+ const stopReason = parsePromptStopReason(message);
4280
+ if (stopReason) {
4281
+ this.renderDone(stopReason);
4282
+ return;
4283
+ }
4284
+ const errorMessage = parseJsonRpcErrorSummary(message);
4285
+ if (errorMessage) this.onError({
4286
+ code: "RUNTIME",
4287
+ origin: "acp",
4288
+ message: errorMessage
4289
+ });
4290
+ }
4291
+ renderSessionUpdate(notification) {
4292
+ const update = notification.update;
4293
+ if (update.sessionUpdate !== "agent_thought_chunk") this.flushThoughtBuffer();
4294
+ this.renderSessionUpdateBody(update);
4295
+ }
4296
+ renderSessionUpdateBody(update) {
4297
+ switch (update.sessionUpdate) {
4298
+ case "agent_message_chunk":
4299
+ if (update.content.type === "text") this.writeAssistantChunk(update.content.text);
4300
+ return;
4301
+ case "agent_thought_chunk":
4302
+ if (update.content.type === "text") this.thoughtBuffer += update.content.text;
4303
+ return;
4304
+ case "tool_call":
4305
+ this.renderToolUpdate(update);
4306
+ return;
4307
+ case "tool_call_update":
4308
+ this.renderToolUpdate(update);
4309
+ return;
4310
+ case "plan":
4311
+ this.renderPlanUpdate(update.entries);
4312
+ return;
4313
+ default: return;
4314
+ }
4315
+ }
4316
+ renderPlanUpdate(entries) {
4317
+ this.beginSection("plan");
4318
+ this.writeLine(this.bold("[plan]"));
4319
+ for (const entry of entries) this.writeLine(` - [${entry.status}] ${entry.content}`);
4320
+ }
4321
+ renderDone(stopReason) {
4322
+ this.flushThoughtBuffer();
4323
+ this.beginSection("done");
4324
+ this.writeLine(this.dim(`[done] ${stopReason}`));
4325
+ }
4326
+ onError(params) {
4327
+ this.flushThoughtBuffer();
4328
+ this.beginSection("done");
4329
+ this.writeLine(this.formatAnsi(`[error] ${params.code}: ${params.message}`, "31"));
4330
+ for (const hint of getTextErrorRemediationHints(params)) this.writeLine(this.dim(hint));
4331
+ }
4332
+ onClientOperation(operation) {
4333
+ this.flushThoughtBuffer();
4334
+ this.beginSection("client");
4335
+ const normalizedStatus = operation.status === "completed" ? "completed" : operation.status === "failed" ? "failed" : "in_progress";
4336
+ const statusText = this.colorStatus(operation.status, normalizedStatus);
4337
+ this.writeLine(`${this.bold("[client]")} ${operation.summary} (${statusText})`);
4338
+ if (operation.details && operation.details.trim().length > 0) {
4339
+ this.writeLine(" details:");
4340
+ this.writeLine(indentBlock(operation.details, " "));
4341
+ }
4342
+ }
4343
+ onPermissionEscalation(event) {
4344
+ this.flushThoughtBuffer();
4345
+ this.beginSection("client");
4346
+ this.writeLine(`${this.bold("[permission]")} ${event.message}`);
4347
+ const details = [
4348
+ `sessionId: ${event.sessionId}`,
4349
+ `toolCallId: ${event.toolCallId}`,
4350
+ event.toolName ? `toolName: ${event.toolName}` : void 0,
4351
+ `toolTitle: ${event.toolTitle}`,
4352
+ event.toolInput !== void 0 ? `toolInput: ${summarizeToolInput(event.toolInput) ?? "(structured input)"}` : void 0,
4353
+ event.toolKind ? `toolKind: ${event.toolKind}` : void 0,
4354
+ event.matchedRule ? `matchedRule: ${event.matchedRule}` : void 0
4355
+ ].filter((line) => Boolean(line));
4356
+ this.writeLine(indentBlock(details.join("\n"), " "));
4357
+ }
4358
+ flush() {
4359
+ this.flushThoughtBuffer();
4360
+ if (!this.atLineStart) this.write("\n");
4361
+ }
4362
+ write(chunk) {
4363
+ if (!chunk) return;
4364
+ this.stdout.write(chunk);
4365
+ this.wroteAny = true;
4366
+ this.atLineStart = chunk.endsWith("\n");
4367
+ }
4368
+ writeLine(line) {
4369
+ this.write(`${line}\n`);
4370
+ }
4371
+ beginSection(next) {
4372
+ if (!this.atLineStart) this.write("\n");
4373
+ if (this.wroteAny) this.write("\n");
4374
+ this.section = next;
4375
+ }
4376
+ writeAssistantChunk(text) {
4377
+ if (!text) return;
4378
+ this.section = "assistant";
4379
+ this.write(text);
4380
+ }
4381
+ flushThoughtBuffer() {
4382
+ const thought = truncate(normalizeLineEndings(this.thoughtBuffer).trim(), MAX_THOUGHT_CHARS);
4383
+ this.thoughtBuffer = "";
4384
+ if (!thought) return;
4385
+ this.beginSection("thought");
4386
+ const [firstLine, ...restLines] = thought.split("\n");
4387
+ this.writeLine(this.dim(`[thinking] ${firstLine}`));
4388
+ for (const line of restLines) this.writeLine(this.dim(` ${line}`));
4389
+ }
4390
+ renderToolUpdate(update) {
4391
+ const state = this.getOrCreateToolState(update.toolCallId);
4392
+ this.mergeToolState(state, update);
4393
+ const status = asStatus(state.status);
4394
+ if (isFinalStatus(status)) {
4395
+ const signature = this.toolSignature(state);
4396
+ if (signature !== state.finalSignature) {
4397
+ state.finalSignature = signature;
4398
+ this.renderFinalToolState(state, status);
4399
+ }
4400
+ return;
4401
+ }
4402
+ if (state.startedPrinted) return;
4403
+ state.startedPrinted = true;
4404
+ this.renderStartingToolState(state, status);
4405
+ }
4406
+ getOrCreateToolState(toolCallId) {
4407
+ const existing = this.toolStates.get(toolCallId);
4408
+ if (existing) return existing;
4409
+ const created = {
4410
+ id: toolCallId,
4411
+ startedPrinted: false
4412
+ };
4413
+ this.toolStates.set(toolCallId, created);
4414
+ return created;
4415
+ }
4416
+ mergeToolState(state, update) {
4417
+ this.mergeToolTitle(state, update.title);
4418
+ this.mergeToolPayloadState(state, update);
4419
+ }
4420
+ mergeToolTitle(state, title) {
4421
+ if (typeof title === "string" && title.trim().length > 0) state.title = title;
4422
+ }
4423
+ mergeToolPayloadState(state, update) {
4424
+ if (update.status !== void 0) state.status = update.status;
4425
+ if (update.kind !== void 0) state.kind = update.kind;
4426
+ if (update.locations !== void 0) state.locations = update.locations;
4427
+ if (update.rawInput !== void 0) state.rawInput = update.rawInput;
4428
+ if (update.rawOutput !== void 0) state.rawOutput = update.rawOutput;
4429
+ if (update.content !== void 0) state.content = update.content;
4430
+ }
4431
+ toolSignature(state) {
4432
+ const signaturePayload = {
4433
+ title: state.title,
4434
+ status: state.status,
4435
+ kind: state.kind,
4436
+ input: summarizeToolInput(state.rawInput),
4437
+ files: formatLocations(state.locations),
4438
+ output: renderToolOutput(state, this.suppressReads)
4439
+ };
4440
+ return safeJson(signaturePayload, 0) ?? JSON.stringify(signaturePayload);
4441
+ }
4442
+ renderStartingToolState(state, status) {
4443
+ this.beginSection("tool");
4444
+ const title = state.title ?? state.id;
4445
+ const label = status === "pending" ? "pending" : "running";
4446
+ const statusText = this.colorStatus(label, status);
4447
+ this.writeLine(`${this.bold("[tool]")} ${title} (${statusText})`);
4448
+ const input = summarizeToolInput(state.rawInput);
4449
+ if (input) this.writeLine(` input: ${input}`);
4450
+ const files = formatLocations(state.locations);
4451
+ if (files) this.writeLine(` files: ${files}`);
4452
+ }
4453
+ renderFinalToolState(state, status) {
4454
+ this.beginSection("tool");
4455
+ const title = state.title ?? state.id;
4456
+ const statusText = this.colorStatus(toStatusLabel(status), status);
4457
+ this.writeLine(`${this.bold("[tool]")} ${title} (${statusText})`);
4458
+ if (state.kind) this.writeLine(` kind: ${state.kind}`);
4459
+ const input = summarizeToolInput(state.rawInput);
4460
+ if (input) this.writeLine(` input: ${input}`);
4461
+ const files = formatLocations(state.locations);
4462
+ if (files) this.writeLine(` files: ${files}`);
4463
+ const output = renderToolOutput(state, this.suppressReads);
4464
+ if (output) {
4465
+ this.writeLine(" output:");
4466
+ this.writeLine(indentBlock(limitOutputBlock(output), " "));
4467
+ }
4468
+ }
4469
+ formatAnsi(text, code) {
4470
+ if (!this.useColor) return text;
4471
+ return `\u001b[${code}m${text}\u001b[0m`;
4472
+ }
4473
+ bold(text) {
4474
+ return this.formatAnsi(text, "1");
4475
+ }
4476
+ dim(text) {
4477
+ return this.formatAnsi(text, "2");
4478
+ }
4479
+ colorStatus(text, status) {
4480
+ if (!this.useColor) return text;
4481
+ switch (status) {
4482
+ case "completed": return this.formatAnsi(text, "32");
4483
+ case "failed": return this.formatAnsi(text, "31");
4484
+ default: return this.formatAnsi(text, "33");
4485
+ }
4486
+ }
4487
+ };
4488
+ var QuietOutputFormatter = class {
4489
+ stdout;
4490
+ stderr;
4491
+ chunks = [];
4492
+ flushed = false;
4493
+ metadataFlushed = false;
4494
+ constructor(stdout, stderr) {
4495
+ this.stdout = stdout;
4496
+ this.stderr = stderr;
4497
+ }
4498
+ setContext(_context) {}
4499
+ onAcpMessage(message) {
4500
+ const update = extractSessionUpdateNotification(message);
4501
+ if (update?.update.sessionUpdate === "agent_message_chunk" && update.update.content.type === "text") {
4502
+ this.chunks.push(update.update.content.text);
4503
+ return;
4504
+ }
4505
+ if (parsePromptStopReason(message)) {
4506
+ this.flushBufferedOutput();
4507
+ this.flushMetadata(message);
4508
+ }
4509
+ }
4510
+ onError(params) {
4511
+ const qualifier = params.detailCode ? `${params.code} ${params.detailCode}` : params.code;
4512
+ const message = preferredAcpErrorDetails(params.acp) ?? params.message;
4513
+ this.stderr.write(`[acpx] error: ${qualifier} ${message.replace(/\r\n?|\n/g, " ")}\n`);
4514
+ }
4515
+ onPermissionEscalation(_event) {}
4516
+ flush() {}
4517
+ flushBufferedOutput() {
4518
+ if (this.flushed) return;
4519
+ this.flushed = true;
4520
+ const text = this.chunks.join("");
4521
+ this.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
4522
+ }
4523
+ flushMetadata(message) {
4524
+ if (this.metadataFlushed) return;
4525
+ this.metadataFlushed = true;
4526
+ const result = asRecord(message.result);
4527
+ if (!result) return;
4528
+ const usageLine = this.formatUsageLine(asRecord(result.usage));
4529
+ if (usageLine) this.stderr.write(`${usageLine}\n`);
4530
+ const costLine = this.formatCostLine(result.cost);
4531
+ if (costLine) this.stderr.write(`${costLine}\n`);
4532
+ }
4533
+ formatUsageLine(usage) {
4534
+ if (!usage) return;
4535
+ const parts = [];
4536
+ for (const [label, keys] of [
4537
+ ["input", ["inputTokens", "input_tokens"]],
4538
+ ["output", ["outputTokens", "output_tokens"]],
4539
+ ["cache_read", [
4540
+ "cachedReadTokens",
4541
+ "cacheReadInputTokens",
4542
+ "cache_read_input_tokens"
4543
+ ]],
4544
+ ["cache_write", [
4545
+ "cachedWriteTokens",
4546
+ "cacheCreationInputTokens",
4547
+ "cache_creation_input_tokens"
4548
+ ]],
4549
+ ["total", ["totalTokens", "total_tokens"]]
4550
+ ]) {
4551
+ const value = readFirstFiniteNumber(usage, keys);
4552
+ if (value !== void 0) parts.push(`${label}=${formatMetadataNumber(value)}`);
4553
+ }
4554
+ return parts.length > 0 ? `[acpx] tokens: ${parts.join(" ")}` : void 0;
4555
+ }
4556
+ formatCostLine(cost) {
4557
+ const scalar = this.formatScalarCostLine(cost);
4558
+ if (scalar) return scalar;
4559
+ const record = asRecord(cost);
4560
+ if (!record) return;
4561
+ const amount = readFirstFiniteNumber(record, [
4562
+ "amount",
4563
+ "value",
4564
+ "total"
4565
+ ]);
4566
+ if (amount === void 0) return;
4567
+ const currency = typeof record.currency === "string" && record.currency.trim() ? ` ${record.currency.trim()}` : "";
4568
+ return `[acpx] cost: ${formatMetadataNumber(amount)}${currency}`;
4569
+ }
4570
+ formatScalarCostLine(cost) {
4571
+ if (typeof cost === "number" && Number.isFinite(cost)) return `[acpx] cost: ${formatMetadataNumber(cost)}`;
4572
+ if (typeof cost === "string" && cost.trim()) return `[acpx] cost: ${cost.trim()}`;
4573
+ }
4574
+ };
4575
+ function preferredAcpErrorDetails(acp) {
4576
+ const details = asRecord(acp?.data)?.details;
4577
+ return typeof details === "string" && details.trim().length > 0 ? details.trim() : void 0;
4578
+ }
4579
+ function createOutputFormatter(format, options = {}) {
4580
+ const stdout = options.stdout ?? process.stdout;
4581
+ const stderr = options.stderr ?? process.stderr;
4582
+ const suppressReads = options.suppressReads === true;
4583
+ switch (format) {
4584
+ case "text": return new TextOutputFormatter(stdout, suppressReads);
4585
+ case "json": return createJsonOutputFormatter(stdout, suppressReads, options.jsonContext);
4586
+ case "quiet": return new QuietOutputFormatter(stdout, stderr);
4587
+ default: throw new Error("Unsupported output format");
4588
+ }
4589
+ }
4590
+ //#endregion
4591
+ export { runSessionQueueOwner as a, buildQueueOwnerArgOverride as c, createSessionWithClient as d, cancelSessionPrompt as f, __exportAll as g, isProcessAlive as h, session_exports as i, flushPerfMetricsCapture as l, DEFAULT_QUEUE_OWNER_TTL_MS as m, getTextErrorRemediationHints as n, runOnce as o, probeQueueOwnerHealth as p, output_exports as r, sendSessionDirect as s, createOutputFormatter as t, installPerfMetricsCapture as u };
4592
+
4593
+ //# sourceMappingURL=output-CjdF5rHk.js.map