@tickernelz/wardmote-adapter-utils 0.0.0 → 2026.1108.1

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 (2040) hide show
  1. package/README.md +47 -5
  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 +720 -0
  9. package/dist/acpx-engine/composed-run-characterization.test.js.map +1 -0
  10. package/dist/acpx-engine/constants.d.ts +10 -0
  11. package/dist/acpx-engine/constants.d.ts.map +1 -0
  12. package/dist/acpx-engine/constants.js +25 -0
  13. package/dist/acpx-engine/constants.js.map +1 -0
  14. package/dist/acpx-engine/ephemeral-session-environment.d.ts +4 -0
  15. package/dist/acpx-engine/ephemeral-session-environment.d.ts.map +1 -0
  16. package/dist/acpx-engine/ephemeral-session-environment.js +29 -0
  17. package/dist/acpx-engine/ephemeral-session-environment.js.map +1 -0
  18. package/dist/acpx-engine/ephemeral-session-environment.test.d.ts +2 -0
  19. package/dist/acpx-engine/ephemeral-session-environment.test.d.ts.map +1 -0
  20. package/dist/acpx-engine/ephemeral-session-environment.test.js +177 -0
  21. package/dist/acpx-engine/ephemeral-session-environment.test.js.map +1 -0
  22. package/dist/acpx-engine/execute-identity.test.d.ts +2 -0
  23. package/dist/acpx-engine/execute-identity.test.d.ts.map +1 -0
  24. package/dist/acpx-engine/execute-identity.test.js +218 -0
  25. package/dist/acpx-engine/execute-identity.test.js.map +1 -0
  26. package/dist/acpx-engine/execute.d.ts +322 -0
  27. package/dist/acpx-engine/execute.d.ts.map +1 -0
  28. package/dist/acpx-engine/execute.js +4671 -0
  29. package/dist/acpx-engine/execute.js.map +1 -0
  30. package/dist/acpx-engine/execute.test.d.ts +2 -0
  31. package/dist/acpx-engine/execute.test.d.ts.map +1 -0
  32. package/dist/acpx-engine/execute.test.js +7282 -0
  33. package/dist/acpx-engine/execute.test.js.map +1 -0
  34. package/dist/acpx-engine/filesystem-protocol.test.d.ts +2 -0
  35. package/dist/acpx-engine/filesystem-protocol.test.d.ts.map +1 -0
  36. package/dist/acpx-engine/filesystem-protocol.test.js +99 -0
  37. package/dist/acpx-engine/filesystem-protocol.test.js.map +1 -0
  38. package/dist/acpx-engine/index.d.ts +6 -0
  39. package/dist/acpx-engine/index.d.ts.map +1 -0
  40. package/dist/acpx-engine/index.js +6 -0
  41. package/dist/acpx-engine/index.js.map +1 -0
  42. package/dist/acpx-engine/local-process-control.d.ts +5 -0
  43. package/dist/acpx-engine/local-process-control.d.ts.map +1 -0
  44. package/dist/acpx-engine/local-process-control.js +39 -0
  45. package/dist/acpx-engine/local-process-control.js.map +1 -0
  46. package/dist/acpx-engine/local-process-control.test.d.ts +2 -0
  47. package/dist/acpx-engine/local-process-control.test.d.ts.map +1 -0
  48. package/dist/acpx-engine/local-process-control.test.js +38 -0
  49. package/dist/acpx-engine/local-process-control.test.js.map +1 -0
  50. package/dist/acpx-engine/operator-stop.test.d.ts +2 -0
  51. package/dist/acpx-engine/operator-stop.test.d.ts.map +1 -0
  52. package/dist/acpx-engine/operator-stop.test.js +107 -0
  53. package/dist/acpx-engine/operator-stop.test.js.map +1 -0
  54. package/dist/acpx-engine/read-only-permissions.test.d.ts +2 -0
  55. package/dist/acpx-engine/read-only-permissions.test.d.ts.map +1 -0
  56. package/dist/acpx-engine/read-only-permissions.test.js +33 -0
  57. package/dist/acpx-engine/read-only-permissions.test.js.map +1 -0
  58. package/dist/acpx-engine/remote-spawn-smoke.test.d.ts +2 -0
  59. package/dist/acpx-engine/remote-spawn-smoke.test.d.ts.map +1 -0
  60. package/dist/acpx-engine/remote-spawn-smoke.test.js +151 -0
  61. package/dist/acpx-engine/remote-spawn-smoke.test.js.map +1 -0
  62. package/dist/acpx-engine/run-contracts.d.ts +415 -0
  63. package/dist/acpx-engine/run-contracts.d.ts.map +1 -0
  64. package/dist/acpx-engine/run-contracts.js +20 -0
  65. package/dist/acpx-engine/run-contracts.js.map +1 -0
  66. package/dist/acpx-engine/run-contracts.test.d.ts +2 -0
  67. package/dist/acpx-engine/run-contracts.test.d.ts.map +1 -0
  68. package/dist/acpx-engine/run-contracts.test.js +57 -0
  69. package/dist/acpx-engine/run-contracts.test.js.map +1 -0
  70. package/dist/acpx-engine/run-coordinator.d.ts +57 -0
  71. package/dist/acpx-engine/run-coordinator.d.ts.map +1 -0
  72. package/dist/acpx-engine/run-coordinator.js +63 -0
  73. package/dist/acpx-engine/run-coordinator.js.map +1 -0
  74. package/dist/acpx-engine/run-coordinator.test.d.ts +2 -0
  75. package/dist/acpx-engine/run-coordinator.test.d.ts.map +1 -0
  76. package/dist/acpx-engine/run-coordinator.test.js +160 -0
  77. package/dist/acpx-engine/run-coordinator.test.js.map +1 -0
  78. package/dist/acpx-engine/run-fault-matrix.test.d.ts +2 -0
  79. package/dist/acpx-engine/run-fault-matrix.test.d.ts.map +1 -0
  80. package/dist/acpx-engine/run-fault-matrix.test.js +829 -0
  81. package/dist/acpx-engine/run-fault-matrix.test.js.map +1 -0
  82. package/dist/acpx-engine/run-resource-ledger.d.ts +30 -0
  83. package/dist/acpx-engine/run-resource-ledger.d.ts.map +1 -0
  84. package/dist/acpx-engine/run-resource-ledger.js +148 -0
  85. package/dist/acpx-engine/run-resource-ledger.js.map +1 -0
  86. package/dist/acpx-engine/run-resource-ledger.test.d.ts +2 -0
  87. package/dist/acpx-engine/run-resource-ledger.test.d.ts.map +1 -0
  88. package/dist/acpx-engine/run-resource-ledger.test.js +154 -0
  89. package/dist/acpx-engine/run-resource-ledger.test.js.map +1 -0
  90. package/dist/acpx-engine/run-site-host.d.ts +73 -0
  91. package/dist/acpx-engine/run-site-host.d.ts.map +1 -0
  92. package/dist/acpx-engine/run-site-host.js +65 -0
  93. package/dist/acpx-engine/run-site-host.js.map +1 -0
  94. package/dist/acpx-engine/run-site-host.test.d.ts +2 -0
  95. package/dist/acpx-engine/run-site-host.test.d.ts.map +1 -0
  96. package/dist/acpx-engine/run-site-host.test.js +98 -0
  97. package/dist/acpx-engine/run-site-host.test.js.map +1 -0
  98. package/dist/acpx-engine/run-site-sandbox.d.ts +142 -0
  99. package/dist/acpx-engine/run-site-sandbox.d.ts.map +1 -0
  100. package/dist/acpx-engine/run-site-sandbox.js +278 -0
  101. package/dist/acpx-engine/run-site-sandbox.js.map +1 -0
  102. package/dist/acpx-engine/run-site-sandbox.test.d.ts +2 -0
  103. package/dist/acpx-engine/run-site-sandbox.test.d.ts.map +1 -0
  104. package/dist/acpx-engine/run-site-sandbox.test.js +275 -0
  105. package/dist/acpx-engine/run-site-sandbox.test.js.map +1 -0
  106. package/dist/acpx-engine/session-codec.d.ts +3 -0
  107. package/dist/acpx-engine/session-codec.d.ts.map +1 -0
  108. package/dist/acpx-engine/session-codec.js +50 -0
  109. package/dist/acpx-engine/session-codec.js.map +1 -0
  110. package/dist/acpx-engine/session-reuse-store.d.ts +62 -0
  111. package/dist/acpx-engine/session-reuse-store.d.ts.map +1 -0
  112. package/dist/acpx-engine/session-reuse-store.js +134 -0
  113. package/dist/acpx-engine/session-reuse-store.js.map +1 -0
  114. package/dist/acpx-engine/session-reuse-store.test.d.ts +2 -0
  115. package/dist/acpx-engine/session-reuse-store.test.d.ts.map +1 -0
  116. package/dist/acpx-engine/session-reuse-store.test.js +134 -0
  117. package/dist/acpx-engine/session-reuse-store.test.js.map +1 -0
  118. package/dist/acpx-engine/settlement-characterization.test.d.ts +2 -0
  119. package/dist/acpx-engine/settlement-characterization.test.d.ts.map +1 -0
  120. package/dist/acpx-engine/settlement-characterization.test.js +966 -0
  121. package/dist/acpx-engine/settlement-characterization.test.js.map +1 -0
  122. package/dist/acpx-engine/settlement-sequence.d.ts +77 -0
  123. package/dist/acpx-engine/settlement-sequence.d.ts.map +1 -0
  124. package/dist/acpx-engine/settlement-sequence.js +119 -0
  125. package/dist/acpx-engine/settlement-sequence.js.map +1 -0
  126. package/dist/acpx-engine/settlement-sequence.test.d.ts +2 -0
  127. package/dist/acpx-engine/settlement-sequence.test.d.ts.map +1 -0
  128. package/dist/acpx-engine/settlement-sequence.test.js +272 -0
  129. package/dist/acpx-engine/settlement-sequence.test.js.map +1 -0
  130. package/dist/acpx-engine/spawn-smoke.test.d.ts +2 -0
  131. package/dist/acpx-engine/spawn-smoke.test.d.ts.map +1 -0
  132. package/dist/acpx-engine/spawn-smoke.test.js +193 -0
  133. package/dist/acpx-engine/spawn-smoke.test.js.map +1 -0
  134. package/dist/acpx-engine/startup-cancellation.d.ts +9 -0
  135. package/dist/acpx-engine/startup-cancellation.d.ts.map +1 -0
  136. package/dist/acpx-engine/startup-cancellation.js +97 -0
  137. package/dist/acpx-engine/startup-cancellation.js.map +1 -0
  138. package/dist/acpx-engine/startup-cancellation.test.d.ts +2 -0
  139. package/dist/acpx-engine/startup-cancellation.test.d.ts.map +1 -0
  140. package/dist/acpx-engine/startup-cancellation.test.js +115 -0
  141. package/dist/acpx-engine/startup-cancellation.test.js.map +1 -0
  142. package/dist/acpx-engine/startup-characterization.test.d.ts +2 -0
  143. package/dist/acpx-engine/startup-characterization.test.d.ts.map +1 -0
  144. package/dist/acpx-engine/startup-characterization.test.js +742 -0
  145. package/dist/acpx-engine/startup-characterization.test.js.map +1 -0
  146. package/dist/acpx-engine/startup-timing.d.ts +419 -0
  147. package/dist/acpx-engine/startup-timing.d.ts.map +1 -0
  148. package/dist/acpx-engine/startup-timing.js +616 -0
  149. package/dist/acpx-engine/startup-timing.js.map +1 -0
  150. package/dist/acpx-engine/startup-timing.test.d.ts +2 -0
  151. package/dist/acpx-engine/startup-timing.test.d.ts.map +1 -0
  152. package/dist/acpx-engine/startup-timing.test.js +619 -0
  153. package/dist/acpx-engine/startup-timing.test.js.map +1 -0
  154. package/dist/acpx-engine/terminal-session-failure.d.ts +18 -0
  155. package/dist/acpx-engine/terminal-session-failure.d.ts.map +1 -0
  156. package/dist/acpx-engine/terminal-session-failure.js +106 -0
  157. package/dist/acpx-engine/terminal-session-failure.js.map +1 -0
  158. package/dist/acpx-engine/terminal-session-failure.test.d.ts +2 -0
  159. package/dist/acpx-engine/terminal-session-failure.test.d.ts.map +1 -0
  160. package/dist/acpx-engine/terminal-session-failure.test.js +139 -0
  161. package/dist/acpx-engine/terminal-session-failure.test.js.map +1 -0
  162. package/dist/acpx-engine/turn-characterization.test.d.ts +2 -0
  163. package/dist/acpx-engine/turn-characterization.test.d.ts.map +1 -0
  164. package/dist/acpx-engine/turn-characterization.test.js +567 -0
  165. package/dist/acpx-engine/turn-characterization.test.js.map +1 -0
  166. package/dist/acpx-engine/turn-sequence.d.ts +54 -0
  167. package/dist/acpx-engine/turn-sequence.d.ts.map +1 -0
  168. package/dist/acpx-engine/turn-sequence.js +75 -0
  169. package/dist/acpx-engine/turn-sequence.js.map +1 -0
  170. package/dist/acpx-engine/turn-sequence.test.d.ts +2 -0
  171. package/dist/acpx-engine/turn-sequence.test.d.ts.map +1 -0
  172. package/dist/acpx-engine/turn-sequence.test.js +177 -0
  173. package/dist/acpx-engine/turn-sequence.test.js.map +1 -0
  174. package/dist/acpx-engine/ui.d.ts +3 -0
  175. package/dist/acpx-engine/ui.d.ts.map +1 -0
  176. package/dist/acpx-engine/ui.js +162 -0
  177. package/dist/acpx-engine/ui.js.map +1 -0
  178. package/dist/adapter-steer-registry.d.ts +24 -0
  179. package/dist/adapter-steer-registry.d.ts.map +1 -0
  180. package/dist/adapter-steer-registry.js +65 -0
  181. package/dist/adapter-steer-registry.js.map +1 -0
  182. package/dist/adapter-steer-registry.test.d.ts +2 -0
  183. package/dist/adapter-steer-registry.test.d.ts.map +1 -0
  184. package/dist/adapter-steer-registry.test.js +121 -0
  185. package/dist/adapter-steer-registry.test.js.map +1 -0
  186. package/dist/agent-todo.d.ts +2 -0
  187. package/dist/agent-todo.d.ts.map +1 -0
  188. package/dist/agent-todo.js +2 -0
  189. package/dist/agent-todo.js.map +1 -0
  190. package/dist/billing.d.ts +9 -0
  191. package/dist/billing.d.ts.map +1 -0
  192. package/dist/billing.js +39 -0
  193. package/dist/billing.js.map +1 -0
  194. package/dist/billing.test.d.ts +2 -0
  195. package/dist/billing.test.d.ts.map +1 -0
  196. package/dist/billing.test.js +30 -0
  197. package/dist/billing.test.js.map +1 -0
  198. package/dist/bridge-transport-contract.d.ts +43 -0
  199. package/dist/bridge-transport-contract.d.ts.map +1 -0
  200. package/dist/bridge-transport-contract.js +33 -0
  201. package/dist/bridge-transport-contract.js.map +1 -0
  202. package/dist/chat-file-delivery.d.ts +10 -0
  203. package/dist/chat-file-delivery.d.ts.map +1 -0
  204. package/dist/chat-file-delivery.js +39 -0
  205. package/dist/chat-file-delivery.js.map +1 -0
  206. package/dist/chat-file-delivery.test.d.ts +2 -0
  207. package/dist/chat-file-delivery.test.d.ts.map +1 -0
  208. package/dist/chat-file-delivery.test.js +92 -0
  209. package/dist/chat-file-delivery.test.js.map +1 -0
  210. package/dist/command-managed-runtime.d.ts +165 -0
  211. package/dist/command-managed-runtime.d.ts.map +1 -0
  212. package/dist/command-managed-runtime.js +460 -0
  213. package/dist/command-managed-runtime.js.map +1 -0
  214. package/dist/command-managed-runtime.test.d.ts +2 -0
  215. package/dist/command-managed-runtime.test.d.ts.map +1 -0
  216. package/dist/command-managed-runtime.test.js +908 -0
  217. package/dist/command-managed-runtime.test.js.map +1 -0
  218. package/dist/command-redaction.d.ts +17 -0
  219. package/dist/command-redaction.d.ts.map +1 -0
  220. package/dist/command-redaction.js +107 -0
  221. package/dist/command-redaction.js.map +1 -0
  222. package/dist/command-redaction.test.d.ts +2 -0
  223. package/dist/command-redaction.test.d.ts.map +1 -0
  224. package/dist/command-redaction.test.js +99 -0
  225. package/dist/command-redaction.test.js.map +1 -0
  226. package/dist/connection-failure.d.ts +23 -0
  227. package/dist/connection-failure.d.ts.map +1 -0
  228. package/dist/connection-failure.js +36 -0
  229. package/dist/connection-failure.js.map +1 -0
  230. package/dist/connection-failure.test.d.ts +2 -0
  231. package/dist/connection-failure.test.d.ts.map +1 -0
  232. package/dist/connection-failure.test.js +85 -0
  233. package/dist/connection-failure.test.js.map +1 -0
  234. package/dist/directory-merge-lock.test.d.ts +2 -0
  235. package/dist/directory-merge-lock.test.d.ts.map +1 -0
  236. package/dist/directory-merge-lock.test.js +168 -0
  237. package/dist/directory-merge-lock.test.js.map +1 -0
  238. package/dist/duplex-frame-codec.d.ts +124 -0
  239. package/dist/duplex-frame-codec.d.ts.map +1 -0
  240. package/dist/duplex-frame-codec.js +134 -0
  241. package/dist/duplex-frame-codec.js.map +1 -0
  242. package/dist/duplex-frame-codec.test.d.ts +2 -0
  243. package/dist/duplex-frame-codec.test.d.ts.map +1 -0
  244. package/dist/duplex-frame-codec.test.js +172 -0
  245. package/dist/duplex-frame-codec.test.js.map +1 -0
  246. package/dist/duplex-observability.d.ts +220 -0
  247. package/dist/duplex-observability.d.ts.map +1 -0
  248. package/dist/duplex-observability.js +248 -0
  249. package/dist/duplex-observability.js.map +1 -0
  250. package/dist/duplex-observability.test.d.ts +2 -0
  251. package/dist/duplex-observability.test.d.ts.map +1 -0
  252. package/dist/duplex-observability.test.js +55 -0
  253. package/dist/duplex-observability.test.js.map +1 -0
  254. package/dist/env-aliases-run.test.d.ts +2 -0
  255. package/dist/env-aliases-run.test.d.ts.map +1 -0
  256. package/dist/env-aliases-run.test.js +49 -0
  257. package/dist/env-aliases-run.test.js.map +1 -0
  258. package/dist/env-bindings.d.ts +17 -0
  259. package/dist/env-bindings.d.ts.map +1 -0
  260. package/dist/env-bindings.js +98 -0
  261. package/dist/env-bindings.js.map +1 -0
  262. package/dist/env-bindings.test.d.ts +2 -0
  263. package/dist/env-bindings.test.d.ts.map +1 -0
  264. package/dist/env-bindings.test.js +66 -0
  265. package/dist/env-bindings.test.js.map +1 -0
  266. package/dist/exclude-patterns.d.ts +4 -0
  267. package/dist/exclude-patterns.d.ts.map +1 -0
  268. package/dist/exclude-patterns.js +26 -0
  269. package/dist/exclude-patterns.js.map +1 -0
  270. package/dist/execution-phase.d.ts +10 -0
  271. package/dist/execution-phase.d.ts.map +1 -0
  272. package/dist/execution-phase.js +27 -0
  273. package/dist/execution-phase.js.map +1 -0
  274. package/dist/execution-phase.test.d.ts +2 -0
  275. package/dist/execution-phase.test.d.ts.map +1 -0
  276. package/dist/execution-phase.test.js +26 -0
  277. package/dist/execution-phase.test.js.map +1 -0
  278. package/dist/execution-target-sandbox.test.d.ts +2 -0
  279. package/dist/execution-target-sandbox.test.d.ts.map +1 -0
  280. package/dist/execution-target-sandbox.test.js +6792 -0
  281. package/dist/execution-target-sandbox.test.js.map +1 -0
  282. package/dist/execution-target-stdin-race.test.d.ts +2 -0
  283. package/dist/execution-target-stdin-race.test.d.ts.map +1 -0
  284. package/dist/execution-target-stdin-race.test.js +2085 -0
  285. package/dist/execution-target-stdin-race.test.js.map +1 -0
  286. package/dist/execution-target.d.ts +553 -0
  287. package/dist/execution-target.d.ts.map +1 -0
  288. package/dist/execution-target.js +3973 -0
  289. package/dist/execution-target.js.map +1 -0
  290. package/dist/execution-target.test.d.ts +2 -0
  291. package/dist/execution-target.test.d.ts.map +1 -0
  292. package/dist/execution-target.test.js +346 -0
  293. package/dist/execution-target.test.js.map +1 -0
  294. package/dist/git-workspace-sync.d.ts +203 -0
  295. package/dist/git-workspace-sync.d.ts.map +1 -0
  296. package/dist/git-workspace-sync.js +938 -0
  297. package/dist/git-workspace-sync.js.map +1 -0
  298. package/dist/git-workspace-sync.test.d.ts +2 -0
  299. package/dist/git-workspace-sync.test.d.ts.map +1 -0
  300. package/dist/git-workspace-sync.test.js +1183 -0
  301. package/dist/git-workspace-sync.test.js.map +1 -0
  302. package/dist/github-launcher-environment.test.d.ts +2 -0
  303. package/dist/github-launcher-environment.test.d.ts.map +1 -0
  304. package/dist/github-launcher-environment.test.js +322 -0
  305. package/dist/github-launcher-environment.test.js.map +1 -0
  306. package/dist/github-launcher.d.ts +8 -0
  307. package/dist/github-launcher.d.ts.map +1 -0
  308. package/dist/github-launcher.js +142 -0
  309. package/dist/github-launcher.js.map +1 -0
  310. package/dist/github-launcher.test.d.ts +2 -0
  311. package/dist/github-launcher.test.d.ts.map +1 -0
  312. package/dist/github-launcher.test.js +199 -0
  313. package/dist/github-launcher.test.js.map +1 -0
  314. package/dist/http2-bridge-server.d.ts +465 -0
  315. package/dist/http2-bridge-server.d.ts.map +1 -0
  316. package/dist/http2-bridge-server.js +1087 -0
  317. package/dist/http2-bridge-server.js.map +1 -0
  318. package/dist/http2-bridge-server.test.d.ts +2 -0
  319. package/dist/http2-bridge-server.test.d.ts.map +1 -0
  320. package/dist/http2-bridge-server.test.js +2129 -0
  321. package/dist/http2-bridge-server.test.js.map +1 -0
  322. package/dist/index.d.ts +22 -0
  323. package/dist/index.d.ts.map +1 -0
  324. package/dist/index.js +13 -0
  325. package/dist/index.js.map +1 -0
  326. package/dist/live-stdin-channel.d.ts +11 -0
  327. package/dist/live-stdin-channel.d.ts.map +1 -0
  328. package/dist/live-stdin-channel.js +56 -0
  329. package/dist/live-stdin-channel.js.map +1 -0
  330. package/dist/live-stdin-reachability.test.d.ts +2 -0
  331. package/dist/live-stdin-reachability.test.d.ts.map +1 -0
  332. package/dist/live-stdin-reachability.test.js +25 -0
  333. package/dist/live-stdin-reachability.test.js.map +1 -0
  334. package/dist/local-process-sandbox.d.ts +41 -0
  335. package/dist/local-process-sandbox.d.ts.map +1 -0
  336. package/dist/local-process-sandbox.js +432 -0
  337. package/dist/local-process-sandbox.js.map +1 -0
  338. package/dist/local-process-sandbox.test.d.ts +2 -0
  339. package/dist/local-process-sandbox.test.d.ts.map +1 -0
  340. package/dist/local-process-sandbox.test.js +399 -0
  341. package/dist/local-process-sandbox.test.js.map +1 -0
  342. package/dist/log-redaction.d.ts +9 -0
  343. package/dist/log-redaction.d.ts.map +1 -0
  344. package/dist/log-redaction.js +88 -0
  345. package/dist/log-redaction.js.map +1 -0
  346. package/dist/login-capability.d.ts +88 -0
  347. package/dist/login-capability.d.ts.map +1 -0
  348. package/dist/login-capability.js +78 -0
  349. package/dist/login-capability.js.map +1 -0
  350. package/dist/login-capability.test.d.ts +2 -0
  351. package/dist/login-capability.test.d.ts.map +1 -0
  352. package/dist/login-capability.test.js +78 -0
  353. package/dist/login-capability.test.js.map +1 -0
  354. package/dist/login-pty-transport.d.ts +80 -0
  355. package/dist/login-pty-transport.d.ts.map +1 -0
  356. package/dist/login-pty-transport.js +75 -0
  357. package/dist/login-pty-transport.js.map +1 -0
  358. package/dist/login-pty-transport.test.d.ts +2 -0
  359. package/dist/login-pty-transport.test.d.ts.map +1 -0
  360. package/dist/login-pty-transport.test.js +185 -0
  361. package/dist/login-pty-transport.test.js.map +1 -0
  362. package/dist/login-runner-lifecycle.d.ts +70 -0
  363. package/dist/login-runner-lifecycle.d.ts.map +1 -0
  364. package/dist/login-runner-lifecycle.js +52 -0
  365. package/dist/login-runner-lifecycle.js.map +1 -0
  366. package/dist/login-runner-lifecycle.test.d.ts +2 -0
  367. package/dist/login-runner-lifecycle.test.d.ts.map +1 -0
  368. package/dist/login-runner-lifecycle.test.js +122 -0
  369. package/dist/login-runner-lifecycle.test.js.map +1 -0
  370. package/dist/mcp-isolation.integration.test.d.ts +2 -0
  371. package/dist/mcp-isolation.integration.test.d.ts.map +1 -0
  372. package/dist/mcp-isolation.integration.test.js +202 -0
  373. package/dist/mcp-isolation.integration.test.js.map +1 -0
  374. package/dist/paperclip-mcp-mount.d.ts +36 -0
  375. package/dist/paperclip-mcp-mount.d.ts.map +1 -0
  376. package/dist/paperclip-mcp-mount.js +101 -0
  377. package/dist/paperclip-mcp-mount.js.map +1 -0
  378. package/dist/paperclip-mcp.d.ts +53 -0
  379. package/dist/paperclip-mcp.d.ts.map +1 -0
  380. package/dist/paperclip-mcp.js +149 -0
  381. package/dist/paperclip-mcp.js.map +1 -0
  382. package/dist/paperclip-mcp.test.d.ts +2 -0
  383. package/dist/paperclip-mcp.test.d.ts.map +1 -0
  384. package/dist/paperclip-mcp.test.js +133 -0
  385. package/dist/paperclip-mcp.test.js.map +1 -0
  386. package/dist/paperclip-runner-permissions.d.ts +148 -0
  387. package/dist/paperclip-runner-permissions.d.ts.map +1 -0
  388. package/dist/paperclip-runner-permissions.js +184 -0
  389. package/dist/paperclip-runner-permissions.js.map +1 -0
  390. package/dist/paperclip-runner-permissions.test.d.ts +2 -0
  391. package/dist/paperclip-runner-permissions.test.d.ts.map +1 -0
  392. package/dist/paperclip-runner-permissions.test.js +80 -0
  393. package/dist/paperclip-runner-permissions.test.js.map +1 -0
  394. package/dist/prompt-sections.test.d.ts +2 -0
  395. package/dist/prompt-sections.test.d.ts.map +1 -0
  396. package/dist/prompt-sections.test.js +53 -0
  397. package/dist/prompt-sections.test.js.map +1 -0
  398. package/dist/provider-models/claude.d.ts +10 -0
  399. package/dist/provider-models/claude.d.ts.map +1 -0
  400. package/dist/provider-models/claude.js +49 -0
  401. package/dist/provider-models/claude.js.map +1 -0
  402. package/dist/provider-models/codex.d.ts +23 -0
  403. package/dist/provider-models/codex.d.ts.map +1 -0
  404. package/dist/provider-models/codex.js +160 -0
  405. package/dist/provider-models/codex.js.map +1 -0
  406. package/dist/provider-models/gemini.d.ts +6 -0
  407. package/dist/provider-models/gemini.d.ts.map +1 -0
  408. package/dist/provider-models/gemini.js +17 -0
  409. package/dist/provider-models/gemini.js.map +1 -0
  410. package/dist/provider-models/grok.d.ts +7 -0
  411. package/dist/provider-models/grok.d.ts.map +1 -0
  412. package/dist/provider-models/grok.js +13 -0
  413. package/dist/provider-models/grok.js.map +1 -0
  414. package/dist/provider-models/opencode.d.ts +8 -0
  415. package/dist/provider-models/opencode.d.ts.map +1 -0
  416. package/dist/provider-models/opencode.js +71 -0
  417. package/dist/provider-models/opencode.js.map +1 -0
  418. package/dist/provider-stopped-boundary.d.ts +7 -0
  419. package/dist/provider-stopped-boundary.d.ts.map +1 -0
  420. package/dist/provider-stopped-boundary.js +22 -0
  421. package/dist/provider-stopped-boundary.js.map +1 -0
  422. package/dist/provider-stopped-boundary.test.d.ts +2 -0
  423. package/dist/provider-stopped-boundary.test.d.ts.map +1 -0
  424. package/dist/provider-stopped-boundary.test.js +76 -0
  425. package/dist/provider-stopped-boundary.test.js.map +1 -0
  426. package/dist/published-exports.test.d.ts +2 -0
  427. package/dist/published-exports.test.d.ts.map +1 -0
  428. package/dist/published-exports.test.js +17 -0
  429. package/dist/published-exports.test.js.map +1 -0
  430. package/dist/remote-execution-env.d.ts +2 -0
  431. package/dist/remote-execution-env.d.ts.map +1 -0
  432. package/dist/remote-execution-env.js +46 -0
  433. package/dist/remote-execution-env.js.map +1 -0
  434. package/dist/remote-managed-runtime.d.ts +47 -0
  435. package/dist/remote-managed-runtime.d.ts.map +1 -0
  436. package/dist/remote-managed-runtime.js +201 -0
  437. package/dist/remote-managed-runtime.js.map +1 -0
  438. package/dist/remote-managed-runtime.test.d.ts +2 -0
  439. package/dist/remote-managed-runtime.test.d.ts.map +1 -0
  440. package/dist/remote-managed-runtime.test.js +319 -0
  441. package/dist/remote-managed-runtime.test.js.map +1 -0
  442. package/dist/run-oom-score.d.ts +16 -0
  443. package/dist/run-oom-score.d.ts.map +1 -0
  444. package/dist/run-oom-score.js +29 -0
  445. package/dist/run-oom-score.js.map +1 -0
  446. package/dist/run-oom-score.test.d.ts +2 -0
  447. package/dist/run-oom-score.test.d.ts.map +1 -0
  448. package/dist/run-oom-score.test.js +78 -0
  449. package/dist/run-oom-score.test.js.map +1 -0
  450. package/dist/runner-connectivity.d.ts +61 -0
  451. package/dist/runner-connectivity.d.ts.map +1 -0
  452. package/dist/runner-connectivity.js +81 -0
  453. package/dist/runner-connectivity.js.map +1 -0
  454. package/dist/runner-connectivity.test.d.ts +2 -0
  455. package/dist/runner-connectivity.test.d.ts.map +1 -0
  456. package/dist/runner-connectivity.test.js +183 -0
  457. package/dist/runner-connectivity.test.js.map +1 -0
  458. package/dist/runtime-progress.d.ts +48 -0
  459. package/dist/runtime-progress.d.ts.map +1 -0
  460. package/dist/runtime-progress.js +99 -0
  461. package/dist/runtime-progress.js.map +1 -0
  462. package/dist/runtime-progress.test.d.ts +2 -0
  463. package/dist/runtime-progress.test.d.ts.map +1 -0
  464. package/dist/runtime-progress.test.js +240 -0
  465. package/dist/runtime-progress.test.js.map +1 -0
  466. package/dist/sandbox-callback-bridge-body.d.ts +12 -0
  467. package/dist/sandbox-callback-bridge-body.d.ts.map +1 -0
  468. package/dist/sandbox-callback-bridge-body.js +39 -0
  469. package/dist/sandbox-callback-bridge-body.js.map +1 -0
  470. package/dist/sandbox-callback-bridge-body.test.d.ts +2 -0
  471. package/dist/sandbox-callback-bridge-body.test.d.ts.map +1 -0
  472. package/dist/sandbox-callback-bridge-body.test.js +31 -0
  473. package/dist/sandbox-callback-bridge-body.test.js.map +1 -0
  474. package/dist/sandbox-callback-bridge.d.ts +270 -0
  475. package/dist/sandbox-callback-bridge.d.ts.map +1 -0
  476. package/dist/sandbox-callback-bridge.js +2382 -0
  477. package/dist/sandbox-callback-bridge.js.map +1 -0
  478. package/dist/sandbox-callback-bridge.test.d.ts +2 -0
  479. package/dist/sandbox-callback-bridge.test.d.ts.map +1 -0
  480. package/dist/sandbox-callback-bridge.test.js +3453 -0
  481. package/dist/sandbox-callback-bridge.test.js.map +1 -0
  482. package/dist/sandbox-file-sync.test.d.ts +2 -0
  483. package/dist/sandbox-file-sync.test.d.ts.map +1 -0
  484. package/dist/sandbox-file-sync.test.js +419 -0
  485. package/dist/sandbox-file-sync.test.js.map +1 -0
  486. package/dist/sandbox-install-command.d.ts +2 -0
  487. package/dist/sandbox-install-command.d.ts.map +1 -0
  488. package/dist/sandbox-install-command.js +47 -0
  489. package/dist/sandbox-install-command.js.map +1 -0
  490. package/dist/sandbox-install-command.test.d.ts +2 -0
  491. package/dist/sandbox-install-command.test.d.ts.map +1 -0
  492. package/dist/sandbox-install-command.test.js +22 -0
  493. package/dist/sandbox-install-command.test.js.map +1 -0
  494. package/dist/sandbox-managed-runtime.d.ts +423 -0
  495. package/dist/sandbox-managed-runtime.d.ts.map +1 -0
  496. package/dist/sandbox-managed-runtime.js +1425 -0
  497. package/dist/sandbox-managed-runtime.js.map +1 -0
  498. package/dist/sandbox-managed-runtime.test.d.ts +2 -0
  499. package/dist/sandbox-managed-runtime.test.d.ts.map +1 -0
  500. package/dist/sandbox-managed-runtime.test.js +4044 -0
  501. package/dist/sandbox-managed-runtime.test.js.map +1 -0
  502. package/dist/sandbox-run-log-stream.d.ts +44 -0
  503. package/dist/sandbox-run-log-stream.d.ts.map +1 -0
  504. package/dist/sandbox-run-log-stream.js +203 -0
  505. package/dist/sandbox-run-log-stream.js.map +1 -0
  506. package/dist/sandbox-shell.d.ts +3 -0
  507. package/dist/sandbox-shell.d.ts.map +1 -0
  508. package/dist/sandbox-shell.js +7 -0
  509. package/dist/sandbox-shell.js.map +1 -0
  510. package/dist/server-utils-env.test.d.ts +2 -0
  511. package/dist/server-utils-env.test.d.ts.map +1 -0
  512. package/dist/server-utils-env.test.js +23 -0
  513. package/dist/server-utils-env.test.js.map +1 -0
  514. package/dist/server-utils.d.ts +676 -0
  515. package/dist/server-utils.d.ts.map +1 -0
  516. package/dist/server-utils.js +3450 -0
  517. package/dist/server-utils.js.map +1 -0
  518. package/dist/server-utils.test.d.ts +2 -0
  519. package/dist/server-utils.test.d.ts.map +1 -0
  520. package/dist/server-utils.test.js +3367 -0
  521. package/dist/server-utils.test.js.map +1 -0
  522. package/dist/session-compaction.d.ts +25 -0
  523. package/dist/session-compaction.d.ts.map +1 -0
  524. package/dist/session-compaction.js +115 -0
  525. package/dist/session-compaction.js.map +1 -0
  526. package/dist/skill-library-manifest.d.ts +6 -0
  527. package/dist/skill-library-manifest.d.ts.map +1 -0
  528. package/dist/skill-library-manifest.js +53 -0
  529. package/dist/skill-library-manifest.js.map +1 -0
  530. package/dist/skill-library-manifest.test.d.ts +2 -0
  531. package/dist/skill-library-manifest.test.d.ts.map +1 -0
  532. package/dist/skill-library-manifest.test.js +84 -0
  533. package/dist/skill-library-manifest.test.js.map +1 -0
  534. package/dist/skills-staging-follow-symlinks.test.d.ts +2 -0
  535. package/dist/skills-staging-follow-symlinks.test.d.ts.map +1 -0
  536. package/dist/skills-staging-follow-symlinks.test.js +97 -0
  537. package/dist/skills-staging-follow-symlinks.test.js.map +1 -0
  538. package/dist/ssh-fixture.test.d.ts +2 -0
  539. package/dist/ssh-fixture.test.d.ts.map +1 -0
  540. package/dist/ssh-fixture.test.js +1026 -0
  541. package/dist/ssh-fixture.test.js.map +1 -0
  542. package/dist/ssh.d.ts +131 -0
  543. package/dist/ssh.d.ts.map +1 -0
  544. package/dist/ssh.js +1785 -0
  545. package/dist/ssh.js.map +1 -0
  546. package/dist/sync-operation-schedule.d.ts +17 -0
  547. package/dist/sync-operation-schedule.d.ts.map +1 -0
  548. package/dist/sync-operation-schedule.js +66 -0
  549. package/dist/sync-operation-schedule.js.map +1 -0
  550. package/dist/sync-operation-schedule.test.d.ts +2 -0
  551. package/dist/sync-operation-schedule.test.d.ts.map +1 -0
  552. package/dist/sync-operation-schedule.test.js +130 -0
  553. package/dist/sync-operation-schedule.test.js.map +1 -0
  554. package/dist/test-fixtures/prompt-context.d.ts +54 -0
  555. package/dist/test-fixtures/prompt-context.d.ts.map +1 -0
  556. package/dist/test-fixtures/prompt-context.js +55 -0
  557. package/dist/test-fixtures/prompt-context.js.map +1 -0
  558. package/dist/test-support/mcp-isolation-harness.d.ts +23 -0
  559. package/dist/test-support/mcp-isolation-harness.d.ts.map +1 -0
  560. package/dist/test-support/mcp-isolation-harness.js +67 -0
  561. package/dist/test-support/mcp-isolation-harness.js.map +1 -0
  562. package/dist/tool-profile.d.ts +5 -0
  563. package/dist/tool-profile.d.ts.map +1 -0
  564. package/dist/tool-profile.js +5 -0
  565. package/dist/tool-profile.js.map +1 -0
  566. package/dist/types.d.ts +867 -0
  567. package/dist/types.d.ts.map +1 -0
  568. package/dist/types.js +5 -0
  569. package/dist/types.js.map +1 -0
  570. package/dist/usage-checkpoint.d.ts +11 -0
  571. package/dist/usage-checkpoint.d.ts.map +1 -0
  572. package/dist/usage-checkpoint.js +165 -0
  573. package/dist/usage-checkpoint.js.map +1 -0
  574. package/dist/usage-checkpoint.test.d.ts +2 -0
  575. package/dist/usage-checkpoint.test.d.ts.map +1 -0
  576. package/dist/usage-checkpoint.test.js +131 -0
  577. package/dist/usage-checkpoint.test.js.map +1 -0
  578. package/dist/workspace-git-stream.d.ts +19 -0
  579. package/dist/workspace-git-stream.d.ts.map +1 -0
  580. package/dist/workspace-git-stream.js +99 -0
  581. package/dist/workspace-git-stream.js.map +1 -0
  582. package/dist/workspace-git-stream.test.d.ts +2 -0
  583. package/dist/workspace-git-stream.test.d.ts.map +1 -0
  584. package/dist/workspace-git-stream.test.js +71 -0
  585. package/dist/workspace-git-stream.test.js.map +1 -0
  586. package/dist/workspace-manifest.d.ts +61 -0
  587. package/dist/workspace-manifest.d.ts.map +1 -0
  588. package/dist/workspace-manifest.js +257 -0
  589. package/dist/workspace-manifest.js.map +1 -0
  590. package/dist/workspace-manifest.test.d.ts +2 -0
  591. package/dist/workspace-manifest.test.d.ts.map +1 -0
  592. package/dist/workspace-manifest.test.js +160 -0
  593. package/dist/workspace-manifest.test.js.map +1 -0
  594. package/dist/workspace-restore-diagnostics.d.ts +41 -0
  595. package/dist/workspace-restore-diagnostics.d.ts.map +1 -0
  596. package/dist/workspace-restore-diagnostics.js +265 -0
  597. package/dist/workspace-restore-diagnostics.js.map +1 -0
  598. package/dist/workspace-restore-diagnostics.test.d.ts +2 -0
  599. package/dist/workspace-restore-diagnostics.test.d.ts.map +1 -0
  600. package/dist/workspace-restore-diagnostics.test.js +288 -0
  601. package/dist/workspace-restore-diagnostics.test.js.map +1 -0
  602. package/dist/workspace-restore-merge.d.ts +118 -0
  603. package/dist/workspace-restore-merge.d.ts.map +1 -0
  604. package/dist/workspace-restore-merge.js +664 -0
  605. package/dist/workspace-restore-merge.js.map +1 -0
  606. package/dist/workspace-restore-merge.test.d.ts +2 -0
  607. package/dist/workspace-restore-merge.test.d.ts.map +1 -0
  608. package/dist/workspace-restore-merge.test.js +687 -0
  609. package/dist/workspace-restore-merge.test.js.map +1 -0
  610. package/dist/workspace-restore-result.d.ts +6 -0
  611. package/dist/workspace-restore-result.d.ts.map +1 -0
  612. package/dist/workspace-restore-result.js +72 -0
  613. package/dist/workspace-restore-result.js.map +1 -0
  614. package/dist/workspace-restore-result.test.d.ts +2 -0
  615. package/dist/workspace-restore-result.test.d.ts.map +1 -0
  616. package/dist/workspace-restore-result.test.js +74 -0
  617. package/dist/workspace-restore-result.test.js.map +1 -0
  618. package/dist/workspace-restore-teardown.d.ts +29 -0
  619. package/dist/workspace-restore-teardown.d.ts.map +1 -0
  620. package/dist/workspace-restore-teardown.js +36 -0
  621. package/dist/workspace-restore-teardown.js.map +1 -0
  622. package/dist/workspace-restore-teardown.test.d.ts +2 -0
  623. package/dist/workspace-restore-teardown.test.d.ts.map +1 -0
  624. package/dist/workspace-restore-teardown.test.js +95 -0
  625. package/dist/workspace-restore-teardown.test.js.map +1 -0
  626. package/node_modules/@agentclientprotocol/sdk/LICENSE +191 -0
  627. package/node_modules/@agentclientprotocol/sdk/README.md +77 -0
  628. package/node_modules/@agentclientprotocol/sdk/dist/acp.d.ts +1637 -0
  629. package/node_modules/@agentclientprotocol/sdk/dist/acp.js +1729 -0
  630. package/node_modules/@agentclientprotocol/sdk/dist/acp.js.map +1 -0
  631. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.d.ts +1 -0
  632. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.js +5093 -0
  633. package/node_modules/@agentclientprotocol/sdk/dist/acp.test.js.map +1 -0
  634. package/node_modules/@agentclientprotocol/sdk/dist/connection.d.ts +277 -0
  635. package/node_modules/@agentclientprotocol/sdk/dist/connection.js +898 -0
  636. package/node_modules/@agentclientprotocol/sdk/dist/connection.js.map +1 -0
  637. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.d.ts +1 -0
  638. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.js +666 -0
  639. package/node_modules/@agentclientprotocol/sdk/dist/connection.test.js.map +1 -0
  640. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.d.ts +26 -0
  641. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.js +96 -0
  642. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.js.map +1 -0
  643. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.d.ts +1 -0
  644. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.js +77 -0
  645. package/node_modules/@agentclientprotocol/sdk/dist/cookie-store.test.js.map +1 -0
  646. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.d.ts +2 -0
  647. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.js +232 -0
  648. package/node_modules/@agentclientprotocol/sdk/dist/examples/agent.js.map +1 -0
  649. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.d.ts +2 -0
  650. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.js +132 -0
  651. package/node_modules/@agentclientprotocol/sdk/dist/examples/client.js.map +1 -0
  652. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.d.ts +9 -0
  653. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.js +229 -0
  654. package/node_modules/@agentclientprotocol/sdk/dist/examples/dual-version-agent.js.map +1 -0
  655. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.d.ts +2 -0
  656. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.js +86 -0
  657. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-client.js.map +1 -0
  658. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.d.ts +2 -0
  659. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.js +117 -0
  660. package/node_modules/@agentclientprotocol/sdk/dist/examples/http-server.js.map +1 -0
  661. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.d.ts +2 -0
  662. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.js +88 -0
  663. package/node_modules/@agentclientprotocol/sdk/dist/examples/ws-client.js.map +1 -0
  664. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.d.ts +35 -0
  665. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.js +473 -0
  666. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.js.map +1 -0
  667. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.d.ts +1 -0
  668. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.js +1380 -0
  669. package/node_modules/@agentclientprotocol/sdk/dist/http-stream.test.js.map +1 -0
  670. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.d.ts +604 -0
  671. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.js +1082 -0
  672. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.js.map +1 -0
  673. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.d.ts +1 -0
  674. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.js +917 -0
  675. package/node_modules/@agentclientprotocol/sdk/dist/jsonrpc.test.js.map +1 -0
  676. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.d.ts +24 -0
  677. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.js +71 -0
  678. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.js.map +1 -0
  679. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.d.ts +1 -0
  680. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.js +45 -0
  681. package/node_modules/@agentclientprotocol/sdk/dist/line-buffer.test.js.map +1 -0
  682. package/node_modules/@agentclientprotocol/sdk/dist/nes/acp.d.ts +563 -0
  683. package/node_modules/@agentclientprotocol/sdk/dist/nes/acp.js +106 -0
  684. package/node_modules/@agentclientprotocol/sdk/dist/nes/acp.js.map +1 -0
  685. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/types.gen.d.ts +1261 -0
  686. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/types.gen.js +4 -0
  687. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/types.gen.js.map +1 -0
  688. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/zod.gen.d.ts +962 -0
  689. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/zod.gen.js +526 -0
  690. package/node_modules/@agentclientprotocol/sdk/dist/nes/schema/zod.gen.js.map +1 -0
  691. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.d.ts +17 -0
  692. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.js +457 -0
  693. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.js.map +1 -0
  694. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.d.ts +1 -0
  695. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.js +586 -0
  696. package/node_modules/@agentclientprotocol/sdk/dist/node-adapter.test.js.map +1 -0
  697. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.d.ts +43 -0
  698. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.js +467 -0
  699. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.js.map +1 -0
  700. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.d.ts +1 -0
  701. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.js +592 -0
  702. package/node_modules/@agentclientprotocol/sdk/dist/protocol-router.test.js.map +1 -0
  703. package/node_modules/@agentclientprotocol/sdk/dist/protocol.d.ts +11 -0
  704. package/node_modules/@agentclientprotocol/sdk/dist/protocol.js +60 -0
  705. package/node_modules/@agentclientprotocol/sdk/dist/protocol.js.map +1 -0
  706. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.d.ts +1 -0
  707. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.js +72 -0
  708. package/node_modules/@agentclientprotocol/sdk/dist/protocol.test.js.map +1 -0
  709. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.d.ts +305 -0
  710. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js +355 -0
  711. package/node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js.map +1 -0
  712. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.d.ts +39 -0
  713. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.js +40 -0
  714. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.js.map +1 -0
  715. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.d.ts +5438 -0
  716. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.js +3 -0
  717. package/node_modules/@agentclientprotocol/sdk/dist/schema/types.gen.js.map +1 -0
  718. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.d.ts +15955 -0
  719. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js +2827 -0
  720. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js.map +1 -0
  721. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.d.ts +31 -0
  722. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.js +117 -0
  723. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.js.map +1 -0
  724. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.d.ts +1 -0
  725. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.js +93 -0
  726. package/node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.test.js.map +1 -0
  727. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.d.ts +1 -0
  728. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.js +261 -0
  729. package/node_modules/@agentclientprotocol/sdk/dist/server-permission.test.js.map +1 -0
  730. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.d.ts +1 -0
  731. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.js +536 -0
  732. package/node_modules/@agentclientprotocol/sdk/dist/server-session-sse.test.js.map +1 -0
  733. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.d.ts +7 -0
  734. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.js +136 -0
  735. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.js.map +1 -0
  736. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.d.ts +1 -0
  737. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.js +106 -0
  738. package/node_modules/@agentclientprotocol/sdk/dist/server-sse.test.js.map +1 -0
  739. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.d.ts +1 -0
  740. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.js +1310 -0
  741. package/node_modules/@agentclientprotocol/sdk/dist/server-websocket-upgrade.test.js.map +1 -0
  742. package/node_modules/@agentclientprotocol/sdk/dist/server.d.ts +82 -0
  743. package/node_modules/@agentclientprotocol/sdk/dist/server.js +414 -0
  744. package/node_modules/@agentclientprotocol/sdk/dist/server.js.map +1 -0
  745. package/node_modules/@agentclientprotocol/sdk/dist/server.test.d.ts +1 -0
  746. package/node_modules/@agentclientprotocol/sdk/dist/server.test.js +1646 -0
  747. package/node_modules/@agentclientprotocol/sdk/dist/server.test.js.map +1 -0
  748. package/node_modules/@agentclientprotocol/sdk/dist/sse.d.ts +6 -0
  749. package/node_modules/@agentclientprotocol/sdk/dist/sse.js +114 -0
  750. package/node_modules/@agentclientprotocol/sdk/dist/sse.js.map +1 -0
  751. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.d.ts +1 -0
  752. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.js +126 -0
  753. package/node_modules/@agentclientprotocol/sdk/dist/sse.test.js.map +1 -0
  754. package/node_modules/@agentclientprotocol/sdk/dist/stream-limits.d.ts +15 -0
  755. package/node_modules/@agentclientprotocol/sdk/dist/stream-limits.js +58 -0
  756. package/node_modules/@agentclientprotocol/sdk/dist/stream-limits.js.map +1 -0
  757. package/node_modules/@agentclientprotocol/sdk/dist/stream.d.ts +38 -0
  758. package/node_modules/@agentclientprotocol/sdk/dist/stream.js +119 -0
  759. package/node_modules/@agentclientprotocol/sdk/dist/stream.js.map +1 -0
  760. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.d.ts +1 -0
  761. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.js +195 -0
  762. package/node_modules/@agentclientprotocol/sdk/dist/stream.test.js.map +1 -0
  763. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.d.ts +8 -0
  764. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.js +51 -0
  765. package/node_modules/@agentclientprotocol/sdk/dist/test-support/streams.js.map +1 -0
  766. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.d.ts +24 -0
  767. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.js +163 -0
  768. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-agent.js.map +1 -0
  769. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.d.ts +9 -0
  770. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.js +74 -0
  771. package/node_modules/@agentclientprotocol/sdk/dist/test-support/test-http-server.js.map +1 -0
  772. package/node_modules/@agentclientprotocol/sdk/dist/test-support/until.d.ts +5 -0
  773. package/node_modules/@agentclientprotocol/sdk/dist/test-support/until.js +14 -0
  774. package/node_modules/@agentclientprotocol/sdk/dist/test-support/until.js.map +1 -0
  775. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.d.ts +961 -0
  776. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.js +1451 -0
  777. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.js.map +1 -0
  778. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.d.ts +1 -0
  779. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.js +1423 -0
  780. package/node_modules/@agentclientprotocol/sdk/dist/v2/acp.test.js.map +1 -0
  781. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.d.ts +1084 -0
  782. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.js +1157 -0
  783. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/guards.gen.js.map +1 -0
  784. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.d.ts +30 -0
  785. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.js +31 -0
  786. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/index.js.map +1 -0
  787. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.d.ts +5672 -0
  788. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.js +3 -0
  789. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/types.gen.js.map +1 -0
  790. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.d.ts +37653 -0
  791. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.js +2952 -0
  792. package/node_modules/@agentclientprotocol/sdk/dist/v2/schema/zod.gen.js.map +1 -0
  793. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.d.ts +14 -0
  794. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.js +485 -0
  795. package/node_modules/@agentclientprotocol/sdk/dist/ws-server.js.map +1 -0
  796. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.d.ts +54 -0
  797. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.js +253 -0
  798. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.js.map +1 -0
  799. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.d.ts +1 -0
  800. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.js +836 -0
  801. package/node_modules/@agentclientprotocol/sdk/dist/ws-stream.test.js.map +1 -0
  802. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.d.ts +19 -0
  803. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.js +78 -0
  804. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.js.map +1 -0
  805. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.d.ts +1 -0
  806. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.js +42 -0
  807. package/node_modules/@agentclientprotocol/sdk/dist/ws-utils.test.js.map +1 -0
  808. package/node_modules/@agentclientprotocol/sdk/package.json +110 -0
  809. package/node_modules/@agentclientprotocol/sdk/schema/schema.json +7852 -0
  810. package/node_modules/@agentclientprotocol/sdk/schema/v2/schema.unstable.json +8814 -0
  811. package/node_modules/@clack/core/LICENSE +9 -0
  812. package/node_modules/@clack/core/README.md +22 -0
  813. package/node_modules/@clack/core/dist/index.d.mts +503 -0
  814. package/node_modules/@clack/core/dist/index.mjs +1003 -0
  815. package/node_modules/@clack/core/package.json +63 -0
  816. package/node_modules/@clack/prompts/LICENSE +9 -0
  817. package/node_modules/@clack/prompts/README.md +396 -0
  818. package/node_modules/@clack/prompts/dist/index.d.mts +949 -0
  819. package/node_modules/@clack/prompts/dist/index.mjs +1423 -0
  820. package/node_modules/@clack/prompts/package.json +67 -0
  821. package/node_modules/acpx/LICENSE +21 -0
  822. package/node_modules/acpx/README.md +424 -0
  823. package/node_modules/acpx/dist/cli-CxsS1XQp.js +197 -0
  824. package/node_modules/acpx/dist/cli-CxsS1XQp.js.map +1 -0
  825. package/node_modules/acpx/dist/cli.d.ts +14 -0
  826. package/node_modules/acpx/dist/cli.d.ts.map +1 -0
  827. package/node_modules/acpx/dist/cli.js +2683 -0
  828. package/node_modules/acpx/dist/cli.js.map +1 -0
  829. package/node_modules/acpx/dist/client-DwNyFauq.d.ts +192 -0
  830. package/node_modules/acpx/dist/client-DwNyFauq.d.ts.map +1 -0
  831. package/node_modules/acpx/dist/flags-Bjq_XQ4-.js +260 -0
  832. package/node_modules/acpx/dist/flags-Bjq_XQ4-.js.map +1 -0
  833. package/node_modules/acpx/dist/flows-Db_LZKu9.js +1920 -0
  834. package/node_modules/acpx/dist/flows-Db_LZKu9.js.map +1 -0
  835. package/node_modules/acpx/dist/flows.d.ts +318 -0
  836. package/node_modules/acpx/dist/flows.d.ts.map +1 -0
  837. package/node_modules/acpx/dist/flows.js +2 -0
  838. package/node_modules/acpx/dist/live-checkpoint-ClPCSdrW.js +6214 -0
  839. package/node_modules/acpx/dist/live-checkpoint-ClPCSdrW.js.map +1 -0
  840. package/node_modules/acpx/dist/output-CjdF5rHk.js +4593 -0
  841. package/node_modules/acpx/dist/output-CjdF5rHk.js.map +1 -0
  842. package/node_modules/acpx/dist/runtime.d.ts +472 -0
  843. package/node_modules/acpx/dist/runtime.d.ts.map +1 -0
  844. package/node_modules/acpx/dist/runtime.js +1711 -0
  845. package/node_modules/acpx/dist/runtime.js.map +1 -0
  846. package/node_modules/acpx/dist/session-options-jkYbBxGE.d.ts +278 -0
  847. package/node_modules/acpx/dist/session-options-jkYbBxGE.d.ts.map +1 -0
  848. package/node_modules/acpx/package.json +129 -0
  849. package/node_modules/acpx/skills/acpx/SKILL.md +617 -0
  850. package/node_modules/b4a/LICENSE +201 -0
  851. package/node_modules/b4a/README.md +153 -0
  852. package/node_modules/b4a/browser.js +546 -0
  853. package/node_modules/b4a/index.d.ts +144 -0
  854. package/node_modules/b4a/index.js +193 -0
  855. package/node_modules/b4a/lib/ascii.js +31 -0
  856. package/node_modules/b4a/lib/base64.js +64 -0
  857. package/node_modules/b4a/lib/hex.js +51 -0
  858. package/node_modules/b4a/lib/latin1.js +31 -0
  859. package/node_modules/b4a/lib/utf16le.js +40 -0
  860. package/node_modules/b4a/lib/utf8.js +144 -0
  861. package/node_modules/b4a/package.json +54 -0
  862. package/node_modules/b4a/react-native.js +5 -0
  863. package/node_modules/b4a/runtime.d.ts +14 -0
  864. package/node_modules/bare-buffer/CMakeLists.txt +30 -0
  865. package/node_modules/bare-buffer/LICENSE +201 -0
  866. package/node_modules/bare-buffer/README.md +26 -0
  867. package/node_modules/bare-buffer/binding.c +2041 -0
  868. package/node_modules/bare-buffer/binding.js +1 -0
  869. package/node_modules/bare-buffer/global.d.ts +21 -0
  870. package/node_modules/bare-buffer/global.js +6 -0
  871. package/node_modules/bare-buffer/index.d.ts +769 -0
  872. package/node_modules/bare-buffer/index.js +1339 -0
  873. package/node_modules/bare-buffer/lib/ascii.js +36 -0
  874. package/node_modules/bare-buffer/lib/base64.js +25 -0
  875. package/node_modules/bare-buffer/lib/base64url.js +25 -0
  876. package/node_modules/bare-buffer/lib/checked.js +23 -0
  877. package/node_modules/bare-buffer/lib/constants.d.ts +7 -0
  878. package/node_modules/bare-buffer/lib/constants.js +3 -0
  879. package/node_modules/bare-buffer/lib/hex.js +20 -0
  880. package/node_modules/bare-buffer/lib/latin1.js +14 -0
  881. package/node_modules/bare-buffer/lib/utf16le.js +20 -0
  882. package/node_modules/bare-buffer/lib/utf8.js +18 -0
  883. package/node_modules/bare-buffer/package.json +59 -0
  884. package/node_modules/bare-buffer/prebuilds/android-arm/bare-buffer.bare +0 -0
  885. package/node_modules/bare-buffer/prebuilds/android-arm64/bare-buffer.bare +0 -0
  886. package/node_modules/bare-buffer/prebuilds/android-ia32/bare-buffer.bare +0 -0
  887. package/node_modules/bare-buffer/prebuilds/android-x64/bare-buffer.bare +0 -0
  888. package/node_modules/bare-buffer/prebuilds/darwin-arm64/bare-buffer.bare +0 -0
  889. package/node_modules/bare-buffer/prebuilds/darwin-x64/bare-buffer.bare +0 -0
  890. package/node_modules/bare-buffer/prebuilds/ios-arm64/bare-buffer.bare +0 -0
  891. package/node_modules/bare-buffer/prebuilds/ios-arm64-simulator/bare-buffer.bare +0 -0
  892. package/node_modules/bare-buffer/prebuilds/ios-x64-simulator/bare-buffer.bare +0 -0
  893. package/node_modules/bare-buffer/prebuilds/linux-arm64/bare-buffer.bare +0 -0
  894. package/node_modules/bare-buffer/prebuilds/linux-x64/bare-buffer.bare +0 -0
  895. package/node_modules/bare-buffer/prebuilds/win32-arm64/bare-buffer.bare +0 -0
  896. package/node_modules/bare-buffer/prebuilds/win32-x64/bare-buffer.bare +0 -0
  897. package/node_modules/bare-events/LICENSE +201 -0
  898. package/node_modules/bare-events/README.md +25 -0
  899. package/node_modules/bare-events/global.d.ts +15 -0
  900. package/node_modules/bare-events/global.js +5 -0
  901. package/node_modules/bare-events/index.d.ts +89 -0
  902. package/node_modules/bare-events/index.js +397 -0
  903. package/node_modules/bare-events/lib/errors.js +23 -0
  904. package/node_modules/bare-events/package.json +63 -0
  905. package/node_modules/bare-events/web.d.ts +79 -0
  906. package/node_modules/bare-events/web.js +417 -0
  907. package/node_modules/bare-fs/CMakeLists.txt +13 -0
  908. package/node_modules/bare-fs/LICENSE +201 -0
  909. package/node_modules/bare-fs/README.md +33 -0
  910. package/node_modules/bare-fs/binding.c +2942 -0
  911. package/node_modules/bare-fs/binding.js +1 -0
  912. package/node_modules/bare-fs/index.d.ts +1504 -0
  913. package/node_modules/bare-fs/index.js +2888 -0
  914. package/node_modules/bare-fs/lib/constants.d.ts +50 -0
  915. package/node_modules/bare-fs/lib/constants.js +49 -0
  916. package/node_modules/bare-fs/lib/errors.d.ts +13 -0
  917. package/node_modules/bare-fs/lib/errors.js +55 -0
  918. package/node_modules/bare-fs/package.json +75 -0
  919. package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  920. package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  921. package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  922. package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  923. package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  924. package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  925. package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
  926. package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  927. package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  928. package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  929. package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  930. package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
  931. package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
  932. package/node_modules/bare-fs/promises.d.ts +480 -0
  933. package/node_modules/bare-fs/promises.js +119 -0
  934. package/node_modules/bare-path/CMakeLists.txt +13 -0
  935. package/node_modules/bare-path/LICENSE +201 -0
  936. package/node_modules/bare-path/NOTICE +28 -0
  937. package/node_modules/bare-path/README.md +19 -0
  938. package/node_modules/bare-path/binding.c +106 -0
  939. package/node_modules/bare-path/binding.js +1 -0
  940. package/node_modules/bare-path/index.d.ts +27 -0
  941. package/node_modules/bare-path/index.js +9 -0
  942. package/node_modules/bare-path/lib/constants.js +11 -0
  943. package/node_modules/bare-path/lib/posix.js +263 -0
  944. package/node_modules/bare-path/lib/shared.js +81 -0
  945. package/node_modules/bare-path/lib/win32.js +564 -0
  946. package/node_modules/bare-path/package.json +47 -0
  947. package/node_modules/bare-path/prebuilds/android-arm/bare-path.bare +0 -0
  948. package/node_modules/bare-path/prebuilds/android-arm64/bare-path.bare +0 -0
  949. package/node_modules/bare-path/prebuilds/android-ia32/bare-path.bare +0 -0
  950. package/node_modules/bare-path/prebuilds/android-x64/bare-path.bare +0 -0
  951. package/node_modules/bare-path/prebuilds/darwin-arm64/bare-path.bare +0 -0
  952. package/node_modules/bare-path/prebuilds/darwin-x64/bare-path.bare +0 -0
  953. package/node_modules/bare-path/prebuilds/ios-arm64/bare-path.bare +0 -0
  954. package/node_modules/bare-path/prebuilds/ios-arm64-simulator/bare-path.bare +0 -0
  955. package/node_modules/bare-path/prebuilds/ios-x64-simulator/bare-path.bare +0 -0
  956. package/node_modules/bare-path/prebuilds/linux-arm64/bare-path.bare +0 -0
  957. package/node_modules/bare-path/prebuilds/linux-x64/bare-path.bare +0 -0
  958. package/node_modules/bare-path/prebuilds/win32-arm64/bare-path.bare +0 -0
  959. package/node_modules/bare-path/prebuilds/win32-x64/bare-path.bare +0 -0
  960. package/node_modules/bare-stream/LICENSE +201 -0
  961. package/node_modules/bare-stream/README.md +354 -0
  962. package/node_modules/bare-stream/global.d.ts +31 -0
  963. package/node_modules/bare-stream/global.js +15 -0
  964. package/node_modules/bare-stream/index.d.ts +235 -0
  965. package/node_modules/bare-stream/index.js +493 -0
  966. package/node_modules/bare-stream/package.json +75 -0
  967. package/node_modules/bare-stream/promises.js +3 -0
  968. package/node_modules/bare-stream/web.d.ts +152 -0
  969. package/node_modules/bare-stream/web.js +607 -0
  970. package/node_modules/bare-url/CMakeLists.txt +36 -0
  971. package/node_modules/bare-url/LICENSE +201 -0
  972. package/node_modules/bare-url/README.md +37 -0
  973. package/node_modules/bare-url/binding.c +422 -0
  974. package/node_modules/bare-url/binding.js +1 -0
  975. package/node_modules/bare-url/global.d.ts +24 -0
  976. package/node_modules/bare-url/global.js +2 -0
  977. package/node_modules/bare-url/index.d.ts +99 -0
  978. package/node_modules/bare-url/index.js +700 -0
  979. package/node_modules/bare-url/lib/errors.d.ts +10 -0
  980. package/node_modules/bare-url/lib/errors.js +37 -0
  981. package/node_modules/bare-url/lib/url-search-params.d.ts +66 -0
  982. package/node_modules/bare-url/lib/url-search-params.js +291 -0
  983. package/node_modules/bare-url/package.json +55 -0
  984. package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
  985. package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
  986. package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
  987. package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
  988. package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
  989. package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
  990. package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
  991. package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
  992. package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
  993. package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
  994. package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
  995. package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
  996. package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
  997. package/node_modules/commander/LICENSE +22 -0
  998. package/node_modules/commander/Readme.md +1146 -0
  999. package/node_modules/commander/index.js +21 -0
  1000. package/node_modules/commander/lib/argument.js +147 -0
  1001. package/node_modules/commander/lib/command.js +2803 -0
  1002. package/node_modules/commander/lib/error.js +36 -0
  1003. package/node_modules/commander/lib/help.js +735 -0
  1004. package/node_modules/commander/lib/option.js +377 -0
  1005. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  1006. package/node_modules/commander/package-support.json +19 -0
  1007. package/node_modules/commander/package.json +65 -0
  1008. package/node_modules/commander/typings/index.d.ts +1116 -0
  1009. package/node_modules/esbuild/LICENSE.md +21 -0
  1010. package/node_modules/esbuild/README.md +3 -0
  1011. package/node_modules/esbuild/bin/esbuild +223 -0
  1012. package/node_modules/esbuild/install.js +300 -0
  1013. package/node_modules/esbuild/lib/main.d.ts +720 -0
  1014. package/node_modules/esbuild/lib/main.js +2536 -0
  1015. package/node_modules/esbuild/package.json +74 -0
  1016. package/node_modules/events-universal/LICENSE +201 -0
  1017. package/node_modules/events-universal/README.md +17 -0
  1018. package/node_modules/events-universal/bare.js +1 -0
  1019. package/node_modules/events-universal/default.js +1 -0
  1020. package/node_modules/events-universal/index.js +1 -0
  1021. package/node_modules/events-universal/package.json +39 -0
  1022. package/node_modules/events-universal/react-native.js +1 -0
  1023. package/node_modules/fast-fifo/LICENSE +21 -0
  1024. package/node_modules/fast-fifo/README.md +78 -0
  1025. package/node_modules/fast-fifo/fixed-size.js +39 -0
  1026. package/node_modules/fast-fifo/index.js +48 -0
  1027. package/node_modules/fast-fifo/package.json +28 -0
  1028. package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  1029. package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  1030. package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  1031. package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  1032. package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  1033. package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  1034. package/node_modules/fast-string-truncated-width/license +21 -0
  1035. package/node_modules/fast-string-truncated-width/package.json +35 -0
  1036. package/node_modules/fast-string-truncated-width/readme.md +59 -0
  1037. package/node_modules/fast-string-width/dist/index.d.ts +4 -0
  1038. package/node_modules/fast-string-width/dist/index.js +14 -0
  1039. package/node_modules/fast-string-width/license +21 -0
  1040. package/node_modules/fast-string-width/package.json +34 -0
  1041. package/node_modules/fast-string-width/readme.md +42 -0
  1042. package/node_modules/fast-wrap-ansi/LICENSE +23 -0
  1043. package/node_modules/fast-wrap-ansi/README.md +26 -0
  1044. package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  1045. package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
  1046. package/node_modules/fast-wrap-ansi/package.json +51 -0
  1047. package/node_modules/sisteransi/license +21 -0
  1048. package/node_modules/sisteransi/package.json +34 -0
  1049. package/node_modules/sisteransi/readme.md +113 -0
  1050. package/node_modules/sisteransi/src/index.js +58 -0
  1051. package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  1052. package/node_modules/skillflag/LICENSE +21 -0
  1053. package/node_modules/skillflag/README.md +44 -0
  1054. package/node_modules/skillflag/dist/bin/skill-install.d.ts +3 -0
  1055. package/node_modules/skillflag/dist/bin/skill-install.d.ts.map +1 -0
  1056. package/node_modules/skillflag/dist/bin/skill-install.js +6 -0
  1057. package/node_modules/skillflag/dist/bin/skill-install.js.map +1 -0
  1058. package/node_modules/skillflag/dist/bin/skillflag.d.ts +3 -0
  1059. package/node_modules/skillflag/dist/bin/skillflag.d.ts.map +1 -0
  1060. package/node_modules/skillflag/dist/bin/skillflag.js +25 -0
  1061. package/node_modules/skillflag/dist/bin/skillflag.js.map +1 -0
  1062. package/node_modules/skillflag/dist/core/digest.d.ts +2 -0
  1063. package/node_modules/skillflag/dist/core/digest.d.ts.map +1 -0
  1064. package/node_modules/skillflag/dist/core/digest.js +15 -0
  1065. package/node_modules/skillflag/dist/core/digest.js.map +1 -0
  1066. package/node_modules/skillflag/dist/core/errors.d.ts +6 -0
  1067. package/node_modules/skillflag/dist/core/errors.d.ts.map +1 -0
  1068. package/node_modules/skillflag/dist/core/errors.js +13 -0
  1069. package/node_modules/skillflag/dist/core/errors.js.map +1 -0
  1070. package/node_modules/skillflag/dist/core/export.d.ts +2 -0
  1071. package/node_modules/skillflag/dist/core/export.d.ts.map +1 -0
  1072. package/node_modules/skillflag/dist/core/export.js +28 -0
  1073. package/node_modules/skillflag/dist/core/export.js.map +1 -0
  1074. package/node_modules/skillflag/dist/core/list.d.ts +21 -0
  1075. package/node_modules/skillflag/dist/core/list.d.ts.map +1 -0
  1076. package/node_modules/skillflag/dist/core/list.js +71 -0
  1077. package/node_modules/skillflag/dist/core/list.js.map +1 -0
  1078. package/node_modules/skillflag/dist/core/paths.d.ts +15 -0
  1079. package/node_modules/skillflag/dist/core/paths.d.ts.map +1 -0
  1080. package/node_modules/skillflag/dist/core/paths.js +149 -0
  1081. package/node_modules/skillflag/dist/core/paths.js.map +1 -0
  1082. package/node_modules/skillflag/dist/core/show.d.ts +2 -0
  1083. package/node_modules/skillflag/dist/core/show.d.ts.map +1 -0
  1084. package/node_modules/skillflag/dist/core/show.js +8 -0
  1085. package/node_modules/skillflag/dist/core/show.js.map +1 -0
  1086. package/node_modules/skillflag/dist/core/skillflag.d.ts +3 -0
  1087. package/node_modules/skillflag/dist/core/skillflag.d.ts.map +1 -0
  1088. package/node_modules/skillflag/dist/core/skillflag.js +2 -0
  1089. package/node_modules/skillflag/dist/core/skillflag.js.map +1 -0
  1090. package/node_modules/skillflag/dist/core/tar.d.ts +16 -0
  1091. package/node_modules/skillflag/dist/core/tar.d.ts.map +1 -0
  1092. package/node_modules/skillflag/dist/core/tar.js +140 -0
  1093. package/node_modules/skillflag/dist/core/tar.js.map +1 -0
  1094. package/node_modules/skillflag/dist/index.d.ts +5 -0
  1095. package/node_modules/skillflag/dist/index.d.ts.map +1 -0
  1096. package/node_modules/skillflag/dist/index.js +3 -0
  1097. package/node_modules/skillflag/dist/index.js.map +1 -0
  1098. package/node_modules/skillflag/dist/install/cli.d.ts +57 -0
  1099. package/node_modules/skillflag/dist/install/cli.d.ts.map +1 -0
  1100. package/node_modules/skillflag/dist/install/cli.js +653 -0
  1101. package/node_modules/skillflag/dist/install/cli.js.map +1 -0
  1102. package/node_modules/skillflag/dist/install/copy.d.ts +2 -0
  1103. package/node_modules/skillflag/dist/install/copy.d.ts.map +1 -0
  1104. package/node_modules/skillflag/dist/install/copy.js +19 -0
  1105. package/node_modules/skillflag/dist/install/copy.js.map +1 -0
  1106. package/node_modules/skillflag/dist/install/errors.d.ts +6 -0
  1107. package/node_modules/skillflag/dist/install/errors.d.ts.map +1 -0
  1108. package/node_modules/skillflag/dist/install/errors.js +13 -0
  1109. package/node_modules/skillflag/dist/install/errors.js.map +1 -0
  1110. package/node_modules/skillflag/dist/install/extract.d.ts +3 -0
  1111. package/node_modules/skillflag/dist/install/extract.d.ts.map +1 -0
  1112. package/node_modules/skillflag/dist/install/extract.js +76 -0
  1113. package/node_modules/skillflag/dist/install/extract.js.map +1 -0
  1114. package/node_modules/skillflag/dist/install/install.d.ts +21 -0
  1115. package/node_modules/skillflag/dist/install/install.d.ts.map +1 -0
  1116. package/node_modules/skillflag/dist/install/install.js +35 -0
  1117. package/node_modules/skillflag/dist/install/install.js.map +1 -0
  1118. package/node_modules/skillflag/dist/install/resolve.d.ts +12 -0
  1119. package/node_modules/skillflag/dist/install/resolve.d.ts.map +1 -0
  1120. package/node_modules/skillflag/dist/install/resolve.js +119 -0
  1121. package/node_modules/skillflag/dist/install/resolve.js.map +1 -0
  1122. package/node_modules/skillflag/dist/install/validate.d.ts +7 -0
  1123. package/node_modules/skillflag/dist/install/validate.d.ts.map +1 -0
  1124. package/node_modules/skillflag/dist/install/validate.js +28 -0
  1125. package/node_modules/skillflag/dist/install/validate.js.map +1 -0
  1126. package/node_modules/skillflag/dist/shared/frontmatter.d.ts +2 -0
  1127. package/node_modules/skillflag/dist/shared/frontmatter.d.ts.map +1 -0
  1128. package/node_modules/skillflag/dist/shared/frontmatter.js +28 -0
  1129. package/node_modules/skillflag/dist/shared/frontmatter.js.map +1 -0
  1130. package/node_modules/skillflag/dist/skillflag.d.ts +29 -0
  1131. package/node_modules/skillflag/dist/skillflag.d.ts.map +1 -0
  1132. package/node_modules/skillflag/dist/skillflag.js +230 -0
  1133. package/node_modules/skillflag/dist/skillflag.js.map +1 -0
  1134. package/node_modules/skillflag/dist/utils/collections.d.ts +3 -0
  1135. package/node_modules/skillflag/dist/utils/collections.d.ts.map +1 -0
  1136. package/node_modules/skillflag/dist/utils/collections.js +18 -0
  1137. package/node_modules/skillflag/dist/utils/collections.js.map +1 -0
  1138. package/node_modules/skillflag/package.json +78 -0
  1139. package/node_modules/skillflag/skills/skillflag/SKILL.md +144 -0
  1140. package/node_modules/streamx/LICENSE +21 -0
  1141. package/node_modules/streamx/README.md +550 -0
  1142. package/node_modules/streamx/index.d.ts +198 -0
  1143. package/node_modules/streamx/index.js +1314 -0
  1144. package/node_modules/streamx/lib/errors.d.ts +13 -0
  1145. package/node_modules/streamx/lib/errors.js +47 -0
  1146. package/node_modules/streamx/package.json +51 -0
  1147. package/node_modules/streamx/runtime.d.ts +55 -0
  1148. package/node_modules/tar-stream/LICENSE +21 -0
  1149. package/node_modules/tar-stream/README.md +183 -0
  1150. package/node_modules/tar-stream/constants.js +14 -0
  1151. package/node_modules/tar-stream/extract.js +418 -0
  1152. package/node_modules/tar-stream/headers.js +322 -0
  1153. package/node_modules/tar-stream/index.d.ts +60 -0
  1154. package/node_modules/tar-stream/index.js +2 -0
  1155. package/node_modules/tar-stream/pack.js +287 -0
  1156. package/node_modules/tar-stream/package.json +50 -0
  1157. package/node_modules/teex/LICENSE +21 -0
  1158. package/node_modules/teex/README.md +31 -0
  1159. package/node_modules/teex/example.js +16 -0
  1160. package/node_modules/teex/index.js +52 -0
  1161. package/node_modules/teex/package.json +26 -0
  1162. package/node_modules/teex/test.js +68 -0
  1163. package/node_modules/text-decoder/LICENSE +201 -0
  1164. package/node_modules/text-decoder/README.md +36 -0
  1165. package/node_modules/text-decoder/index.js +64 -0
  1166. package/node_modules/text-decoder/lib/pass-through-decoder.js +19 -0
  1167. package/node_modules/text-decoder/lib/utf8-decoder.js +185 -0
  1168. package/node_modules/text-decoder/package.json +39 -0
  1169. package/node_modules/tsx/LICENSE +21 -0
  1170. package/node_modules/tsx/README.md +32 -0
  1171. package/node_modules/tsx/dist/cjs/api/index.cjs +2 -0
  1172. package/node_modules/tsx/dist/cjs/api/index.d.cts +35 -0
  1173. package/node_modules/tsx/dist/cjs/api/index.d.mts +35 -0
  1174. package/node_modules/tsx/dist/cjs/api/index.mjs +2 -0
  1175. package/node_modules/tsx/dist/cjs/index.cjs +1 -0
  1176. package/node_modules/tsx/dist/cli.mjs +55 -0
  1177. package/node_modules/tsx/dist/client-XItNFmsq.cjs +1 -0
  1178. package/node_modules/tsx/dist/esm/api/index.cjs +2 -0
  1179. package/node_modules/tsx/dist/esm/api/index.d.cts +37 -0
  1180. package/node_modules/tsx/dist/esm/api/index.d.mts +37 -0
  1181. package/node_modules/tsx/dist/esm/api/index.mjs +2 -0
  1182. package/node_modules/tsx/dist/esm/index.mjs +2 -0
  1183. package/node_modules/tsx/dist/index-Bqjv9TxC.mjs +1 -0
  1184. package/node_modules/tsx/dist/index-DE3OBZuV.mjs +14 -0
  1185. package/node_modules/tsx/dist/lexer-CGfpMDSb.cjs +3 -0
  1186. package/node_modules/tsx/dist/lexer-CanA6ArK.mjs +3 -0
  1187. package/node_modules/tsx/dist/loader.mjs +2 -0
  1188. package/node_modules/tsx/dist/package-Dj0mHsMt.mjs +1 -0
  1189. package/node_modules/tsx/dist/patch-repl.cjs +1 -0
  1190. package/node_modules/tsx/dist/preflight.cjs +1 -0
  1191. package/node_modules/tsx/dist/register-B1c7OH6V.cjs +23 -0
  1192. package/node_modules/tsx/dist/register-nyXW-TH3.mjs +2 -0
  1193. package/node_modules/tsx/dist/repl.mjs +4 -0
  1194. package/node_modules/tsx/dist/require-CBjy4Foe.mjs +10 -0
  1195. package/node_modules/tsx/dist/require-CVaYn9z3.cjs +1 -0
  1196. package/node_modules/tsx/dist/suppress-warnings.cjs +1 -0
  1197. package/node_modules/tsx/dist/temporary-directory-Du7LpLp9.mjs +1 -0
  1198. package/node_modules/tsx/package.json +70 -0
  1199. package/node_modules/zod/LICENSE +21 -0
  1200. package/node_modules/zod/README.md +218 -0
  1201. package/node_modules/zod/compile.cjs +96 -0
  1202. package/node_modules/zod/compile.d.cts +1 -0
  1203. package/node_modules/zod/compile.d.ts +1 -0
  1204. package/node_modules/zod/compile.js +52 -0
  1205. package/node_modules/zod/index.cjs +52 -0
  1206. package/node_modules/zod/index.d.cts +3 -0
  1207. package/node_modules/zod/index.d.ts +3 -0
  1208. package/node_modules/zod/index.js +7 -0
  1209. package/node_modules/zod/locales/index.cjs +36 -0
  1210. package/node_modules/zod/locales/index.d.cts +1 -0
  1211. package/node_modules/zod/locales/index.d.ts +1 -0
  1212. package/node_modules/zod/locales/index.js +1 -0
  1213. package/node_modules/zod/locales/package.json +7 -0
  1214. package/node_modules/zod/mini/index.cjs +51 -0
  1215. package/node_modules/zod/mini/index.d.cts +3 -0
  1216. package/node_modules/zod/mini/index.d.ts +3 -0
  1217. package/node_modules/zod/mini/index.js +3 -0
  1218. package/node_modules/zod/mini/package.json +7 -0
  1219. package/node_modules/zod/package.json +147 -0
  1220. package/node_modules/zod/src/compile.ts +56 -0
  1221. package/node_modules/zod/src/index.ts +7 -0
  1222. package/node_modules/zod/src/locales/index.ts +1 -0
  1223. package/node_modules/zod/src/mini/index.ts +3 -0
  1224. package/node_modules/zod/src/v3/ZodError.ts +340 -0
  1225. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  1226. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  1227. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  1228. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  1229. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  1230. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  1231. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  1232. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  1233. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  1234. package/node_modules/zod/src/v3/errors.ts +13 -0
  1235. package/node_modules/zod/src/v3/external.ts +6 -0
  1236. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  1237. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  1238. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  1239. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  1240. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  1241. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  1242. package/node_modules/zod/src/v3/index.ts +4 -0
  1243. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  1244. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  1245. package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
  1246. package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
  1247. package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
  1248. package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
  1249. package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
  1250. package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
  1251. package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
  1252. package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
  1253. package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
  1254. package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
  1255. package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
  1256. package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
  1257. package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
  1258. package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
  1259. package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
  1260. package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
  1261. package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
  1262. package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  1263. package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
  1264. package/node_modules/zod/src/v3/tests/error.test.ts +586 -0
  1265. package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
  1266. package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  1267. package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
  1268. package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
  1269. package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
  1270. package/node_modules/zod/src/v3/tests/intersection.test.ts +128 -0
  1271. package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
  1272. package/node_modules/zod/src/v3/tests/language-server.test.ts +206 -0
  1273. package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
  1274. package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
  1275. package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
  1276. package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
  1277. package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
  1278. package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  1279. package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
  1280. package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
  1281. package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  1282. package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  1283. package/node_modules/zod/src/v3/tests/object.test.ts +431 -0
  1284. package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
  1285. package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
  1286. package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
  1287. package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
  1288. package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
  1289. package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
  1290. package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
  1291. package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
  1292. package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
  1293. package/node_modules/zod/src/v3/tests/readonly.test.ts +114 -0
  1294. package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
  1295. package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
  1296. package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
  1297. package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
  1298. package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
  1299. package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
  1300. package/node_modules/zod/src/v3/tests/string.test.ts +922 -0
  1301. package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
  1302. package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
  1303. package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
  1304. package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
  1305. package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
  1306. package/node_modules/zod/src/v3/types.ts +5138 -0
  1307. package/node_modules/zod/src/v4/classic/checks.ts +33 -0
  1308. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  1309. package/node_modules/zod/src/v4/classic/compat.ts +78 -0
  1310. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  1311. package/node_modules/zod/src/v4/classic/errors.ts +97 -0
  1312. package/node_modules/zod/src/v4/classic/external.ts +57 -0
  1313. package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
  1314. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  1315. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  1316. package/node_modules/zod/src/v4/classic/iso.ts +20 -0
  1317. package/node_modules/zod/src/v4/classic/parse.ts +88 -0
  1318. package/node_modules/zod/src/v4/classic/schemas.ts +2937 -0
  1319. package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  1320. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
  1321. package/node_modules/zod/src/v4/classic/tests/array.test.ts +291 -0
  1322. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +402 -0
  1323. package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  1324. package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  1325. package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
  1326. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +89 -0
  1327. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +106 -0
  1328. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +604 -0
  1329. package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  1330. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
  1331. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
  1332. package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  1333. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
  1334. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  1335. package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
  1336. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  1337. package/node_modules/zod/src/v4/classic/tests/date.test.ts +92 -0
  1338. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +316 -0
  1339. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  1340. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  1341. package/node_modules/zod/src/v4/classic/tests/default.test.ts +455 -0
  1342. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  1343. package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
  1344. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
  1345. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
  1346. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +305 -0
  1347. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +917 -0
  1348. package/node_modules/zod/src/v4/classic/tests/error.test.ts +1108 -0
  1349. package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
  1350. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
  1351. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  1352. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  1353. package/node_modules/zod/src/v4/classic/tests/function.test.ts +391 -0
  1354. package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
  1355. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
  1356. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
  1357. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  1358. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  1359. package/node_modules/zod/src/v4/classic/tests/index.test.ts +958 -0
  1360. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  1361. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +127 -0
  1362. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +334 -0
  1363. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  1364. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  1365. package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
  1366. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +262 -0
  1367. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +128 -0
  1368. package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  1369. package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  1370. package/node_modules/zod/src/v4/classic/tests/map.test.ts +349 -0
  1371. package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
  1372. package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  1373. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
  1374. package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  1375. package/node_modules/zod/src/v4/classic/tests/number.test.ts +401 -0
  1376. package/node_modules/zod/src/v4/classic/tests/object.test.ts +1006 -0
  1377. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  1378. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +366 -0
  1379. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +497 -0
  1380. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +211 -0
  1381. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
  1382. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +144 -0
  1383. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  1384. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +351 -0
  1385. package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  1386. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
  1387. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  1388. package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  1389. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +184 -0
  1390. package/node_modules/zod/src/v4/classic/tests/record.test.ts +885 -0
  1391. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +707 -0
  1392. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  1393. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +693 -0
  1394. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +243 -0
  1395. package/node_modules/zod/src/v4/classic/tests/set.test.ts +196 -0
  1396. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +153 -0
  1397. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
  1398. package/node_modules/zod/src/v4/classic/tests/string.test.ts +1440 -0
  1399. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +124 -0
  1400. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +812 -0
  1401. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  1402. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +4733 -0
  1403. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +378 -0
  1404. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +511 -0
  1405. package/node_modules/zod/src/v4/classic/tests/union.test.ts +310 -0
  1406. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  1407. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  1408. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
  1409. package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
  1410. package/node_modules/zod/src/v4/core/api.ts +1875 -0
  1411. package/node_modules/zod/src/v4/core/checks.ts +1266 -0
  1412. package/node_modules/zod/src/v4/core/compile.ts +2322 -0
  1413. package/node_modules/zod/src/v4/core/core.ts +230 -0
  1414. package/node_modules/zod/src/v4/core/doc.ts +52 -0
  1415. package/node_modules/zod/src/v4/core/errors.ts +543 -0
  1416. package/node_modules/zod/src/v4/core/index.ts +19 -0
  1417. package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
  1418. package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
  1419. package/node_modules/zod/src/v4/core/json-schema.ts +148 -0
  1420. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  1421. package/node_modules/zod/src/v4/core/parse.ts +309 -0
  1422. package/node_modules/zod/src/v4/core/regexes.ts +217 -0
  1423. package/node_modules/zod/src/v4/core/registries.ts +105 -0
  1424. package/node_modules/zod/src/v4/core/schemas.ts +5226 -0
  1425. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  1426. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  1427. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  1428. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  1429. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  1430. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  1431. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  1432. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  1433. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  1434. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  1435. package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
  1436. package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  1437. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
  1438. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  1439. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
  1440. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  1441. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  1442. package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  1443. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  1444. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  1445. package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  1446. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  1447. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  1448. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  1449. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
  1450. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  1451. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
  1452. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  1453. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  1454. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  1455. package/node_modules/zod/src/v4/core/to-json-schema.ts +857 -0
  1456. package/node_modules/zod/src/v4/core/util.ts +1293 -0
  1457. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  1458. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  1459. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  1460. package/node_modules/zod/src/v4/index.ts +4 -0
  1461. package/node_modules/zod/src/v4/locales/ar.ts +120 -0
  1462. package/node_modules/zod/src/v4/locales/az.ts +116 -0
  1463. package/node_modules/zod/src/v4/locales/be.ts +188 -0
  1464. package/node_modules/zod/src/v4/locales/bg.ts +133 -0
  1465. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  1466. package/node_modules/zod/src/v4/locales/ca.ts +121 -0
  1467. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  1468. package/node_modules/zod/src/v4/locales/cs.ts +123 -0
  1469. package/node_modules/zod/src/v4/locales/da.ts +128 -0
  1470. package/node_modules/zod/src/v4/locales/de.ts +121 -0
  1471. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  1472. package/node_modules/zod/src/v4/locales/en.ts +136 -0
  1473. package/node_modules/zod/src/v4/locales/eo.ts +123 -0
  1474. package/node_modules/zod/src/v4/locales/es.ts +145 -0
  1475. package/node_modules/zod/src/v4/locales/fa.ts +131 -0
  1476. package/node_modules/zod/src/v4/locales/fi.ts +126 -0
  1477. package/node_modules/zod/src/v4/locales/fr-CA.ts +121 -0
  1478. package/node_modules/zod/src/v4/locales/fr.ts +139 -0
  1479. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  1480. package/node_modules/zod/src/v4/locales/he.ts +253 -0
  1481. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  1482. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  1483. package/node_modules/zod/src/v4/locales/hu.ts +122 -0
  1484. package/node_modules/zod/src/v4/locales/hy.ts +175 -0
  1485. package/node_modules/zod/src/v4/locales/id.ts +120 -0
  1486. package/node_modules/zod/src/v4/locales/index.ts +63 -0
  1487. package/node_modules/zod/src/v4/locales/is.ts +124 -0
  1488. package/node_modules/zod/src/v4/locales/it.ts +121 -0
  1489. package/node_modules/zod/src/v4/locales/ja.ts +119 -0
  1490. package/node_modules/zod/src/v4/locales/ka.ts +128 -0
  1491. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  1492. package/node_modules/zod/src/v4/locales/km.ts +124 -0
  1493. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  1494. package/node_modules/zod/src/v4/locales/ko.ts +126 -0
  1495. package/node_modules/zod/src/v4/locales/lt.ts +243 -0
  1496. package/node_modules/zod/src/v4/locales/mk.ts +123 -0
  1497. package/node_modules/zod/src/v4/locales/ms.ts +120 -0
  1498. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  1499. package/node_modules/zod/src/v4/locales/nl.ts +126 -0
  1500. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  1501. package/node_modules/zod/src/v4/locales/no.ts +121 -0
  1502. package/node_modules/zod/src/v4/locales/ota.ts +122 -0
  1503. package/node_modules/zod/src/v4/locales/pl.ts +123 -0
  1504. package/node_modules/zod/src/v4/locales/ps.ts +131 -0
  1505. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  1506. package/node_modules/zod/src/v4/locales/pt.ts +159 -0
  1507. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  1508. package/node_modules/zod/src/v4/locales/ru.ts +188 -0
  1509. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  1510. package/node_modules/zod/src/v4/locales/sl.ts +123 -0
  1511. package/node_modules/zod/src/v4/locales/sv.ts +124 -0
  1512. package/node_modules/zod/src/v4/locales/ta.ts +123 -0
  1513. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  1514. package/node_modules/zod/src/v4/locales/th.ts +124 -0
  1515. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  1516. package/node_modules/zod/src/v4/locales/tr.ts +116 -0
  1517. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  1518. package/node_modules/zod/src/v4/locales/uk.ts +122 -0
  1519. package/node_modules/zod/src/v4/locales/ur.ts +124 -0
  1520. package/node_modules/zod/src/v4/locales/uz.ts +120 -0
  1521. package/node_modules/zod/src/v4/locales/vi.ts +122 -0
  1522. package/node_modules/zod/src/v4/locales/yo.ts +129 -0
  1523. package/node_modules/zod/src/v4/locales/zh-CN.ts +121 -0
  1524. package/node_modules/zod/src/v4/locales/zh-TW.ts +120 -0
  1525. package/node_modules/zod/src/v4/mini/checks.ts +33 -0
  1526. package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
  1527. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  1528. package/node_modules/zod/src/v4/mini/external.ts +52 -0
  1529. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  1530. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  1531. package/node_modules/zod/src/v4/mini/iso.ts +66 -0
  1532. package/node_modules/zod/src/v4/mini/parse.ts +16 -0
  1533. package/node_modules/zod/src/v4/mini/schemas.ts +2051 -0
  1534. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
  1535. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +190 -0
  1536. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +94 -0
  1537. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +158 -0
  1538. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
  1539. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +30 -0
  1540. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  1541. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  1542. package/node_modules/zod/src/v4/mini/tests/error.test.ts +41 -0
  1543. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +14 -0
  1544. package/node_modules/zod/src/v4/mini/tests/index.test.ts +1146 -0
  1545. package/node_modules/zod/src/v4/mini/tests/number.test.ts +109 -0
  1546. package/node_modules/zod/src/v4/mini/tests/object.test.ts +292 -0
  1547. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  1548. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +341 -0
  1549. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
  1550. package/node_modules/zod/src/v4/mini/tests/string.test.ts +396 -0
  1551. package/node_modules/zod/src/v4-mini/index.ts +3 -0
  1552. package/node_modules/zod/v3/ZodError.cjs +167 -0
  1553. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  1554. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  1555. package/node_modules/zod/v3/ZodError.js +143 -0
  1556. package/node_modules/zod/v3/errors.cjs +36 -0
  1557. package/node_modules/zod/v3/errors.d.cts +5 -0
  1558. package/node_modules/zod/v3/errors.d.ts +5 -0
  1559. package/node_modules/zod/v3/errors.js +9 -0
  1560. package/node_modules/zod/v3/external.cjs +41 -0
  1561. package/node_modules/zod/v3/external.d.cts +6 -0
  1562. package/node_modules/zod/v3/external.d.ts +6 -0
  1563. package/node_modules/zod/v3/external.js +6 -0
  1564. package/node_modules/zod/v3/helpers/enumUtil.cjs +21 -0
  1565. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  1566. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  1567. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  1568. package/node_modules/zod/v3/helpers/errorUtil.cjs +28 -0
  1569. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  1570. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  1571. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  1572. package/node_modules/zod/v3/helpers/parseUtil.cjs +143 -0
  1573. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  1574. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  1575. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  1576. package/node_modules/zod/v3/helpers/partialUtil.cjs +21 -0
  1577. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  1578. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  1579. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  1580. package/node_modules/zod/v3/helpers/typeAliases.cjs +21 -0
  1581. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  1582. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  1583. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  1584. package/node_modules/zod/v3/helpers/util.cjs +156 -0
  1585. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  1586. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  1587. package/node_modules/zod/v3/helpers/util.js +133 -0
  1588. package/node_modules/zod/v3/index.cjs +52 -0
  1589. package/node_modules/zod/v3/index.d.cts +4 -0
  1590. package/node_modules/zod/v3/index.d.ts +4 -0
  1591. package/node_modules/zod/v3/index.js +4 -0
  1592. package/node_modules/zod/v3/locales/en.cjs +112 -0
  1593. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  1594. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  1595. package/node_modules/zod/v3/locales/en.js +109 -0
  1596. package/node_modules/zod/v3/package.json +7 -0
  1597. package/node_modules/zod/v3/standard-schema.cjs +21 -0
  1598. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  1599. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  1600. package/node_modules/zod/v3/standard-schema.js +1 -0
  1601. package/node_modules/zod/v3/types.cjs +3798 -0
  1602. package/node_modules/zod/v3/types.d.cts +1034 -0
  1603. package/node_modules/zod/v3/types.d.ts +1034 -0
  1604. package/node_modules/zod/v3/types.js +3697 -0
  1605. package/node_modules/zod/v4/classic/checks.cjs +53 -0
  1606. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  1607. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  1608. package/node_modules/zod/v4/classic/checks.js +1 -0
  1609. package/node_modules/zod/v4/classic/coerce.cjs +66 -0
  1610. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  1611. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  1612. package/node_modules/zod/v4/classic/coerce.js +17 -0
  1613. package/node_modules/zod/v4/classic/compat.cjs +80 -0
  1614. package/node_modules/zod/v4/classic/compat.d.cts +48 -0
  1615. package/node_modules/zod/v4/classic/compat.d.ts +48 -0
  1616. package/node_modules/zod/v4/classic/compat.js +31 -0
  1617. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  1618. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  1619. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  1620. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  1621. package/node_modules/zod/v4/classic/errors.cjs +102 -0
  1622. package/node_modules/zod/v4/classic/errors.d.cts +29 -0
  1623. package/node_modules/zod/v4/classic/errors.d.ts +29 -0
  1624. package/node_modules/zod/v4/classic/errors.js +57 -0
  1625. package/node_modules/zod/v4/classic/external.cjs +97 -0
  1626. package/node_modules/zod/v4/classic/external.d.cts +19 -0
  1627. package/node_modules/zod/v4/classic/external.d.ts +19 -0
  1628. package/node_modules/zod/v4/classic/external.js +17 -0
  1629. package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
  1630. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  1631. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  1632. package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  1633. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  1634. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  1635. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  1636. package/node_modules/zod/v4/classic/in-out.js +36 -0
  1637. package/node_modules/zod/v4/classic/index.cjs +52 -0
  1638. package/node_modules/zod/v4/classic/index.d.cts +3 -0
  1639. package/node_modules/zod/v4/classic/index.d.ts +3 -0
  1640. package/node_modules/zod/v4/classic/index.js +4 -0
  1641. package/node_modules/zod/v4/classic/iso.cjs +68 -0
  1642. package/node_modules/zod/v4/classic/iso.d.cts +7 -0
  1643. package/node_modules/zod/v4/classic/iso.d.ts +7 -0
  1644. package/node_modules/zod/v4/classic/iso.js +15 -0
  1645. package/node_modules/zod/v4/classic/package.json +7 -0
  1646. package/node_modules/zod/v4/classic/parse.cjs +63 -0
  1647. package/node_modules/zod/v4/classic/parse.d.cts +44 -0
  1648. package/node_modules/zod/v4/classic/parse.d.ts +44 -0
  1649. package/node_modules/zod/v4/classic/parse.js +16 -0
  1650. package/node_modules/zod/v4/classic/schemas.cjs +1676 -0
  1651. package/node_modules/zod/v4/classic/schemas.d.cts +816 -0
  1652. package/node_modules/zod/v4/classic/schemas.d.ts +816 -0
  1653. package/node_modules/zod/v4/classic/schemas.js +1535 -0
  1654. package/node_modules/zod/v4/core/api.cjs +1269 -0
  1655. package/node_modules/zod/v4/core/api.d.cts +335 -0
  1656. package/node_modules/zod/v4/core/api.d.ts +335 -0
  1657. package/node_modules/zod/v4/core/api.js +1107 -0
  1658. package/node_modules/zod/v4/core/checks.cjs +561 -0
  1659. package/node_modules/zod/v4/core/checks.d.cts +294 -0
  1660. package/node_modules/zod/v4/core/checks.d.ts +294 -0
  1661. package/node_modules/zod/v4/core/checks.js +516 -0
  1662. package/node_modules/zod/v4/core/compile.cjs +1916 -0
  1663. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  1664. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  1665. package/node_modules/zod/v4/core/compile.js +1866 -0
  1666. package/node_modules/zod/v4/core/core.cjs +167 -0
  1667. package/node_modules/zod/v4/core/core.d.cts +82 -0
  1668. package/node_modules/zod/v4/core/core.d.ts +82 -0
  1669. package/node_modules/zod/v4/core/core.js +141 -0
  1670. package/node_modules/zod/v4/core/doc.cjs +61 -0
  1671. package/node_modules/zod/v4/core/doc.d.cts +16 -0
  1672. package/node_modules/zod/v4/core/doc.d.ts +16 -0
  1673. package/node_modules/zod/v4/core/doc.js +38 -0
  1674. package/node_modules/zod/v4/core/errors.cjs +317 -0
  1675. package/node_modules/zod/v4/core/errors.d.cts +225 -0
  1676. package/node_modules/zod/v4/core/errors.d.ts +225 -0
  1677. package/node_modules/zod/v4/core/errors.js +267 -0
  1678. package/node_modules/zod/v4/core/index.cjs +70 -0
  1679. package/node_modules/zod/v4/core/index.d.cts +19 -0
  1680. package/node_modules/zod/v4/core/index.d.ts +19 -0
  1681. package/node_modules/zod/v4/core/index.js +19 -0
  1682. package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
  1683. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  1684. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  1685. package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  1686. package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
  1687. package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
  1688. package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
  1689. package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  1690. package/node_modules/zod/v4/core/json-schema.cjs +21 -0
  1691. package/node_modules/zod/v4/core/json-schema.d.cts +89 -0
  1692. package/node_modules/zod/v4/core/json-schema.d.ts +89 -0
  1693. package/node_modules/zod/v4/core/json-schema.js +1 -0
  1694. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  1695. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  1696. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  1697. package/node_modules/zod/v4/core/memoizer.js +311 -0
  1698. package/node_modules/zod/v4/core/package.json +7 -0
  1699. package/node_modules/zod/v4/core/parse.cjs +233 -0
  1700. package/node_modules/zod/v4/core/parse.d.cts +52 -0
  1701. package/node_modules/zod/v4/core/parse.d.ts +52 -0
  1702. package/node_modules/zod/v4/core/parse.js +175 -0
  1703. package/node_modules/zod/v4/core/regexes.cjs +209 -0
  1704. package/node_modules/zod/v4/core/regexes.d.cts +90 -0
  1705. package/node_modules/zod/v4/core/regexes.d.ts +90 -0
  1706. package/node_modules/zod/v4/core/regexes.js +156 -0
  1707. package/node_modules/zod/v4/core/registries.cjs +75 -0
  1708. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  1709. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  1710. package/node_modules/zod/v4/core/registries.js +51 -0
  1711. package/node_modules/zod/v4/core/schemas.cjs +2699 -0
  1712. package/node_modules/zod/v4/core/schemas.d.cts +1275 -0
  1713. package/node_modules/zod/v4/core/schemas.d.ts +1275 -0
  1714. package/node_modules/zod/v4/core/schemas.js +2636 -0
  1715. package/node_modules/zod/v4/core/standard-schema.cjs +21 -0
  1716. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  1717. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  1718. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  1719. package/node_modules/zod/v4/core/to-json-schema.cjs +681 -0
  1720. package/node_modules/zod/v4/core/to-json-schema.d.cts +154 -0
  1721. package/node_modules/zod/v4/core/to-json-schema.d.ts +154 -0
  1722. package/node_modules/zod/v4/core/to-json-schema.js +651 -0
  1723. package/node_modules/zod/v4/core/util.cjs +964 -0
  1724. package/node_modules/zod/v4/core/util.d.cts +280 -0
  1725. package/node_modules/zod/v4/core/util.d.ts +280 -0
  1726. package/node_modules/zod/v4/core/util.js +873 -0
  1727. package/node_modules/zod/v4/core/versions.cjs +27 -0
  1728. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  1729. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  1730. package/node_modules/zod/v4/core/versions.js +5 -0
  1731. package/node_modules/zod/v4/core/visit.cjs +214 -0
  1732. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  1733. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  1734. package/node_modules/zod/v4/core/visit.js +169 -0
  1735. package/node_modules/zod/v4/index.cjs +51 -0
  1736. package/node_modules/zod/v4/index.d.cts +3 -0
  1737. package/node_modules/zod/v4/index.d.ts +3 -0
  1738. package/node_modules/zod/v4/index.js +4 -0
  1739. package/node_modules/zod/v4/locales/ar.cjs +138 -0
  1740. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  1741. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  1742. package/node_modules/zod/v4/locales/ar.js +111 -0
  1743. package/node_modules/zod/v4/locales/az.cjs +137 -0
  1744. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  1745. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  1746. package/node_modules/zod/v4/locales/az.js +110 -0
  1747. package/node_modules/zod/v4/locales/be.cjs +195 -0
  1748. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  1749. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  1750. package/node_modules/zod/v4/locales/be.js +168 -0
  1751. package/node_modules/zod/v4/locales/bg.cjs +152 -0
  1752. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  1753. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  1754. package/node_modules/zod/v4/locales/bg.js +125 -0
  1755. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  1756. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  1757. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  1758. package/node_modules/zod/v4/locales/bn.js +113 -0
  1759. package/node_modules/zod/v4/locales/ca.cjs +139 -0
  1760. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  1761. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  1762. package/node_modules/zod/v4/locales/ca.js +112 -0
  1763. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  1764. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  1765. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  1766. package/node_modules/zod/v4/locales/ckb.js +133 -0
  1767. package/node_modules/zod/v4/locales/cs.cjs +143 -0
  1768. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  1769. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  1770. package/node_modules/zod/v4/locales/cs.js +116 -0
  1771. package/node_modules/zod/v4/locales/da.cjs +147 -0
  1772. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  1773. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  1774. package/node_modules/zod/v4/locales/da.js +120 -0
  1775. package/node_modules/zod/v4/locales/de.cjs +140 -0
  1776. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  1777. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  1778. package/node_modules/zod/v4/locales/de.js +113 -0
  1779. package/node_modules/zod/v4/locales/el.cjs +139 -0
  1780. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  1781. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  1782. package/node_modules/zod/v4/locales/el.js +112 -0
  1783. package/node_modules/zod/v4/locales/en.cjs +152 -0
  1784. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  1785. package/node_modules/zod/v4/locales/en.d.ts +4 -0
  1786. package/node_modules/zod/v4/locales/en.js +125 -0
  1787. package/node_modules/zod/v4/locales/eo.cjs +141 -0
  1788. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  1789. package/node_modules/zod/v4/locales/eo.d.ts +4 -0
  1790. package/node_modules/zod/v4/locales/eo.js +114 -0
  1791. package/node_modules/zod/v4/locales/es.cjs +163 -0
  1792. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  1793. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  1794. package/node_modules/zod/v4/locales/es.js +136 -0
  1795. package/node_modules/zod/v4/locales/fa.cjs +146 -0
  1796. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  1797. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  1798. package/node_modules/zod/v4/locales/fa.js +119 -0
  1799. package/node_modules/zod/v4/locales/fi.cjs +144 -0
  1800. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  1801. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  1802. package/node_modules/zod/v4/locales/fi.js +117 -0
  1803. package/node_modules/zod/v4/locales/fr-CA.cjs +139 -0
  1804. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  1805. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  1806. package/node_modules/zod/v4/locales/fr-CA.js +112 -0
  1807. package/node_modules/zod/v4/locales/fr.cjs +156 -0
  1808. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  1809. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  1810. package/node_modules/zod/v4/locales/fr.js +129 -0
  1811. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  1812. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  1813. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  1814. package/node_modules/zod/v4/locales/gu.js +113 -0
  1815. package/node_modules/zod/v4/locales/he.cjs +248 -0
  1816. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  1817. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  1818. package/node_modules/zod/v4/locales/he.js +221 -0
  1819. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  1820. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  1821. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  1822. package/node_modules/zod/v4/locales/hi.js +111 -0
  1823. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  1824. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  1825. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  1826. package/node_modules/zod/v4/locales/hr.js +126 -0
  1827. package/node_modules/zod/v4/locales/hu.cjs +140 -0
  1828. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  1829. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  1830. package/node_modules/zod/v4/locales/hu.js +113 -0
  1831. package/node_modules/zod/v4/locales/hy.cjs +185 -0
  1832. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  1833. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  1834. package/node_modules/zod/v4/locales/hy.js +158 -0
  1835. package/node_modules/zod/v4/locales/id.cjs +138 -0
  1836. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  1837. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  1838. package/node_modules/zod/v4/locales/id.js +111 -0
  1839. package/node_modules/zod/v4/locales/index.cjs +152 -0
  1840. package/node_modules/zod/v4/locales/index.d.cts +63 -0
  1841. package/node_modules/zod/v4/locales/index.d.ts +63 -0
  1842. package/node_modules/zod/v4/locales/index.js +63 -0
  1843. package/node_modules/zod/v4/locales/is.cjs +141 -0
  1844. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  1845. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  1846. package/node_modules/zod/v4/locales/is.js +114 -0
  1847. package/node_modules/zod/v4/locales/it.cjs +140 -0
  1848. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  1849. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  1850. package/node_modules/zod/v4/locales/it.js +113 -0
  1851. package/node_modules/zod/v4/locales/ja.cjs +139 -0
  1852. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  1853. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  1854. package/node_modules/zod/v4/locales/ja.js +112 -0
  1855. package/node_modules/zod/v4/locales/ka.cjs +144 -0
  1856. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  1857. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  1858. package/node_modules/zod/v4/locales/ka.js +117 -0
  1859. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  1860. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  1861. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  1862. package/node_modules/zod/v4/locales/kh.js +5 -0
  1863. package/node_modules/zod/v4/locales/km.cjs +142 -0
  1864. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  1865. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  1866. package/node_modules/zod/v4/locales/km.js +115 -0
  1867. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  1868. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  1869. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  1870. package/node_modules/zod/v4/locales/kn.js +116 -0
  1871. package/node_modules/zod/v4/locales/ko.cjs +143 -0
  1872. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  1873. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  1874. package/node_modules/zod/v4/locales/ko.js +116 -0
  1875. package/node_modules/zod/v4/locales/lt.cjs +234 -0
  1876. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  1877. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  1878. package/node_modules/zod/v4/locales/lt.js +207 -0
  1879. package/node_modules/zod/v4/locales/mk.cjs +141 -0
  1880. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  1881. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  1882. package/node_modules/zod/v4/locales/mk.js +114 -0
  1883. package/node_modules/zod/v4/locales/ms.cjs +139 -0
  1884. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  1885. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  1886. package/node_modules/zod/v4/locales/ms.js +112 -0
  1887. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  1888. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  1889. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  1890. package/node_modules/zod/v4/locales/ne.js +111 -0
  1891. package/node_modules/zod/v4/locales/nl.cjs +142 -0
  1892. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  1893. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  1894. package/node_modules/zod/v4/locales/nl.js +115 -0
  1895. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  1896. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  1897. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  1898. package/node_modules/zod/v4/locales/nn.js +113 -0
  1899. package/node_modules/zod/v4/locales/no.cjs +140 -0
  1900. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  1901. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  1902. package/node_modules/zod/v4/locales/no.js +113 -0
  1903. package/node_modules/zod/v4/locales/ota.cjs +141 -0
  1904. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  1905. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  1906. package/node_modules/zod/v4/locales/ota.js +114 -0
  1907. package/node_modules/zod/v4/locales/package.json +7 -0
  1908. package/node_modules/zod/v4/locales/pl.cjs +141 -0
  1909. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  1910. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  1911. package/node_modules/zod/v4/locales/pl.js +114 -0
  1912. package/node_modules/zod/v4/locales/ps.cjs +146 -0
  1913. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  1914. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  1915. package/node_modules/zod/v4/locales/ps.js +119 -0
  1916. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  1917. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  1918. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  1919. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  1920. package/node_modules/zod/v4/locales/pt.cjs +169 -0
  1921. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  1922. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  1923. package/node_modules/zod/v4/locales/pt.js +142 -0
  1924. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  1925. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  1926. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  1927. package/node_modules/zod/v4/locales/ro.js +122 -0
  1928. package/node_modules/zod/v4/locales/ru.cjs +195 -0
  1929. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  1930. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  1931. package/node_modules/zod/v4/locales/ru.js +168 -0
  1932. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  1933. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  1934. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  1935. package/node_modules/zod/v4/locales/sk.js +116 -0
  1936. package/node_modules/zod/v4/locales/sl.cjs +141 -0
  1937. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  1938. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  1939. package/node_modules/zod/v4/locales/sl.js +114 -0
  1940. package/node_modules/zod/v4/locales/sv.cjs +142 -0
  1941. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  1942. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  1943. package/node_modules/zod/v4/locales/sv.js +115 -0
  1944. package/node_modules/zod/v4/locales/ta.cjs +142 -0
  1945. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  1946. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  1947. package/node_modules/zod/v4/locales/ta.js +115 -0
  1948. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  1949. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  1950. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  1951. package/node_modules/zod/v4/locales/tg.js +117 -0
  1952. package/node_modules/zod/v4/locales/th.cjs +142 -0
  1953. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  1954. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  1955. package/node_modules/zod/v4/locales/th.js +115 -0
  1956. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  1957. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  1958. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  1959. package/node_modules/zod/v4/locales/tk.js +107 -0
  1960. package/node_modules/zod/v4/locales/tr.cjs +137 -0
  1961. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  1962. package/node_modules/zod/v4/locales/tr.d.ts +4 -0
  1963. package/node_modules/zod/v4/locales/tr.js +110 -0
  1964. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  1965. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  1966. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  1967. package/node_modules/zod/v4/locales/ua.js +5 -0
  1968. package/node_modules/zod/v4/locales/uk.cjs +140 -0
  1969. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  1970. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  1971. package/node_modules/zod/v4/locales/uk.js +113 -0
  1972. package/node_modules/zod/v4/locales/ur.cjs +142 -0
  1973. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  1974. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  1975. package/node_modules/zod/v4/locales/ur.js +115 -0
  1976. package/node_modules/zod/v4/locales/uz.cjs +140 -0
  1977. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  1978. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  1979. package/node_modules/zod/v4/locales/uz.js +113 -0
  1980. package/node_modules/zod/v4/locales/vi.cjs +140 -0
  1981. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  1982. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  1983. package/node_modules/zod/v4/locales/vi.js +113 -0
  1984. package/node_modules/zod/v4/locales/yo.cjs +139 -0
  1985. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  1986. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  1987. package/node_modules/zod/v4/locales/yo.js +112 -0
  1988. package/node_modules/zod/v4/locales/zh-CN.cjs +141 -0
  1989. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  1990. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  1991. package/node_modules/zod/v4/locales/zh-CN.js +114 -0
  1992. package/node_modules/zod/v4/locales/zh-TW.cjs +139 -0
  1993. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  1994. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  1995. package/node_modules/zod/v4/locales/zh-TW.js +112 -0
  1996. package/node_modules/zod/v4/mini/checks.cjs +54 -0
  1997. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  1998. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  1999. package/node_modules/zod/v4/mini/checks.js +1 -0
  2000. package/node_modules/zod/v4/mini/coerce.cjs +71 -0
  2001. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  2002. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  2003. package/node_modules/zod/v4/mini/coerce.js +22 -0
  2004. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  2005. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  2006. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  2007. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  2008. package/node_modules/zod/v4/mini/external.cjs +95 -0
  2009. package/node_modules/zod/v4/mini/external.d.cts +16 -0
  2010. package/node_modules/zod/v4/mini/external.d.ts +16 -0
  2011. package/node_modules/zod/v4/mini/external.js +16 -0
  2012. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  2013. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  2014. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  2015. package/node_modules/zod/v4/mini/in-out.js +36 -0
  2016. package/node_modules/zod/v4/mini/index.cjs +51 -0
  2017. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  2018. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  2019. package/node_modules/zod/v4/mini/index.js +3 -0
  2020. package/node_modules/zod/v4/mini/iso.cjs +83 -0
  2021. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  2022. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  2023. package/node_modules/zod/v4/mini/iso.js +34 -0
  2024. package/node_modules/zod/v4/mini/package.json +7 -0
  2025. package/node_modules/zod/v4/mini/parse.cjs +37 -0
  2026. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  2027. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  2028. package/node_modules/zod/v4/mini/parse.js +1 -0
  2029. package/node_modules/zod/v4/mini/schemas.cjs +1147 -0
  2030. package/node_modules/zod/v4/mini/schemas.d.cts +480 -0
  2031. package/node_modules/zod/v4/mini/schemas.d.ts +480 -0
  2032. package/node_modules/zod/v4/mini/schemas.js +1002 -0
  2033. package/node_modules/zod/v4/package.json +7 -0
  2034. package/node_modules/zod/v4-mini/index.cjs +51 -0
  2035. package/node_modules/zod/v4-mini/index.d.cts +3 -0
  2036. package/node_modules/zod/v4-mini/index.d.ts +3 -0
  2037. package/node_modules/zod/v4-mini/index.js +3 -0
  2038. package/node_modules/zod/v4-mini/package.json +7 -0
  2039. package/package.json +70 -10
  2040. package/index.js +0 -1
@@ -0,0 +1,3973 @@
1
+ import fs from "node:fs/promises";
2
+ import { execFile } from "node:child_process";
3
+ import { promisify } from "node:util";
4
+ import net from "node:net";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { randomBytes, randomUUID } from "node:crypto";
8
+ import { githubLauncherSource } from "./github-launcher.js";
9
+ import { prepareCommandManagedRuntime, } from "./command-managed-runtime.js";
10
+ import { buildRemoteExecutionSessionIdentity, prepareRemoteManagedRuntime, remoteExecutionSessionMatches, } from "./remote-managed-runtime.js";
11
+ export { resolveReferencedSourceIgnore } from "./sandbox-managed-runtime.js";
12
+ import { createCommandManagedSandboxCallbackBridgeQueueClient, createSandboxCallbackBridgeAsset, createSandboxCallbackBridgeToken, DEFAULT_SANDBOX_CALLBACK_BRIDGE_MAX_BODY_BYTES, HTTP2_SANDBOX_CALLBACK_BRIDGE_ROUTE_ALLOWLIST, runSandboxBridgeControlCommand, SANDBOX_CALLBACK_BRIDGE_HTTP2_MODE, sandboxCallbackBridgeDirectories, startSandboxCallbackBridgeServer, startSandboxCallbackBridgeWorker, syncRemoteTextFileWithHashSkip, syncSandboxCallbackBridgeEntrypoint, } from "./sandbox-callback-bridge.js";
13
+ import { createHttp2BridgeServer, BridgeProcessCapacityError, } from "./http2-bridge-server.js";
14
+ import { createSandboxRunLogTailFactory, } from "./sandbox-run-log-stream.js";
15
+ import { DEFAULT_DUPLEX_BROKER_BUDGETS, DUPLEX_CHANNEL_LOST_ERROR_CODE, isSafeBridgeMethod, } from "./bridge-transport-contract.js";
16
+ import { decodeDuplexLine, DEFAULT_MAX_DUPLEX_FRAME_BYTES } from "./duplex-frame-codec.js";
17
+ import { createDuplexObservability, mapHttp2EventToDuplexLossReason, } from "./duplex-observability.js";
18
+ import { createSshCommandManagedRuntimeRunner, parseSshRemoteExecutionSpec, runSshCommand, shellQuote } from "./ssh.js";
19
+ import { ensureCommandResolvable, resolveCommandForLogs, runChildProcess, } from "./server-utils.js";
20
+ import { sanitizeRemoteExecutionEnv } from "./remote-execution-env.js";
21
+ import { withWardmoteEnvAliases } from "@tickernelz/wardmote-shared/env-aliases";
22
+ import { preferredShellForSandbox, shellCommandArgs } from "./sandbox-shell.js";
23
+ import { runWithRuntimeParent, } from "./acpx-engine/startup-timing.js";
24
+ export function postedIssueCommentLogMarker(method, requestPath, status, body) {
25
+ if (method !== "POST" || !/^\/api\/issues\/[^/]+\/comments$/.test(requestPath) || status < 200 || status >= 300) {
26
+ return null;
27
+ }
28
+ const bodyText = typeof body === "string" ? body : body.toString("utf8");
29
+ try {
30
+ const parsed = JSON.parse(bodyText);
31
+ return typeof parsed.id === "string" && parsed.id.length > 0 ? `comment id: ${parsed.id}\n` : null;
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ export { sanitizeRemoteExecutionEnv } from "./remote-execution-env.js";
38
+ // Four-hour wall-clock backstop for sandbox-backed adapter runs. Keep this
39
+ // execution limit independent of the earlier informational silence warnings
40
+ // and the short deadlines for bridge control operations.
41
+ export const DEFAULT_REMOTE_SANDBOX_ADAPTER_TIMEOUT_SEC = 14_400;
42
+ function parseObject(value) {
43
+ return value && typeof value === "object" && !Array.isArray(value)
44
+ ? value
45
+ : {};
46
+ }
47
+ function readString(value) {
48
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
49
+ }
50
+ // Read a serialized effective-capability snapshot back into a full record. A
51
+ // missing or non-boolean field reads as `false`, so a round-tripped target
52
+ // never grants a capability that the snapshot did not carry. Returns null when
53
+ // there is no object to read.
54
+ function parseEffectiveExecutionCapabilities(value) {
55
+ const parsed = parseObject(value);
56
+ if (Object.keys(parsed).length === 0)
57
+ return null;
58
+ return {
59
+ reusableLeases: parsed.reusableLeases === true,
60
+ nativeSyncIn: parsed.nativeSyncIn === true,
61
+ nativeSyncOut: parsed.nativeSyncOut === true,
62
+ persistentProcessSessions: parsed.persistentProcessSessions === true,
63
+ independentControlCommands: parsed.independentControlCommands === true,
64
+ incrementalSessionOutput: parsed.incrementalSessionOutput === true,
65
+ concurrentSyncOperations: parsed.concurrentSyncOperations === true,
66
+ duplexCommandStream: parsed.duplexCommandStream === true,
67
+ runnerWebSocketIngress: parsed.runnerWebSocketIngress === true,
68
+ };
69
+ }
70
+ function readStringMeta(parsed, key) {
71
+ return readString(parsed[key]);
72
+ }
73
+ function resolveHostForUrl(rawHost) {
74
+ const host = rawHost.trim();
75
+ // Preserve the wildcard bind's address family: a server bound to 0.0.0.0
76
+ // accepts IPv4, so target the IPv4 loopback (and [::1] for ::) instead of
77
+ // "localhost", which the resolver may map to the other family.
78
+ if (host === "0.0.0.0")
79
+ return "127.0.0.1";
80
+ if (host === "::")
81
+ return "[::1]";
82
+ if (!host)
83
+ return "localhost";
84
+ if (host.includes(":") && !host.startsWith("[") && !host.endsWith("]"))
85
+ return `[${host}]`;
86
+ return host;
87
+ }
88
+ function resolveDefaultPaperclipApiUrl() {
89
+ const runtimeHost = resolveHostForUrl(process.env.PAPERCLIP_LISTEN_HOST ?? process.env.HOST ?? "localhost");
90
+ // 3100 matches the default Paperclip dev server port when the runtime does not provide one.
91
+ const runtimePort = process.env.PAPERCLIP_LISTEN_PORT ?? process.env.PORT ?? "3100";
92
+ return `http://${runtimeHost}:${runtimePort}`;
93
+ }
94
+ function isBridgeDebugEnabled(env) {
95
+ const value = env.PAPERCLIP_BRIDGE_DEBUG?.trim().toLowerCase();
96
+ return value === "1" || value === "true" || value === "yes";
97
+ }
98
+ function isAdapterExecutionTargetInstance(value) {
99
+ const parsed = parseObject(value);
100
+ if (parsed.kind === "local")
101
+ return true;
102
+ if (parsed.kind !== "remote")
103
+ return false;
104
+ if (parsed.transport === "ssh")
105
+ return parseSshRemoteExecutionSpec(parseObject(parsed.spec)) !== null;
106
+ if (parsed.transport !== "sandbox")
107
+ return false;
108
+ return readStringMeta(parsed, "remoteCwd") !== null;
109
+ }
110
+ export function adapterExecutionTargetToRemoteSpec(target) {
111
+ return target?.kind === "remote" && target.transport === "ssh" ? target.spec : null;
112
+ }
113
+ export function adapterExecutionTargetIsRemote(target) {
114
+ return target?.kind === "remote";
115
+ }
116
+ /** Whether `runAdapterExecutionTargetProcess` can forward a live stdin channel to this target. */
117
+ export function adapterExecutionTargetSupportsLiveStdin(target) {
118
+ return !target || target.kind === "local" || target.transport === "ssh";
119
+ }
120
+ export function adapterExecutionTargetUsesManagedHome(target) {
121
+ return target?.kind === "remote" && target.transport === "sandbox";
122
+ }
123
+ /**
124
+ * Read the per-run duplex bridge kill switch off a target. Only a sandbox
125
+ * target with `enableSandboxDuplexBridge` set to `true` returns `true`. Every
126
+ * other target and every other value returns `false`, so the caller fails
127
+ * closed to the file bridge.
128
+ */
129
+ export function adapterExecutionTargetEnablesSandboxDuplexBridge(target) {
130
+ return (target?.kind === "remote" &&
131
+ target.transport === "sandbox" &&
132
+ target.enableSandboxDuplexBridge === true);
133
+ }
134
+ /**
135
+ * Read the injected duplex observability recorder off a target. Only a
136
+ * sandbox target with a recorder attached returns it. Every other target
137
+ * returns null, so the bridge falls back to the safe no-op recorder.
138
+ */
139
+ export function adapterExecutionTargetDuplexObservabilityRecorder(target) {
140
+ return target?.kind === "remote" && target.transport === "sandbox"
141
+ ? target.duplexObservabilityRecorder ?? null
142
+ : null;
143
+ }
144
+ export function adapterExecutionTargetRemoteCwd(target, localCwd) {
145
+ return target?.kind === "remote" ? target.remoteCwd : localCwd;
146
+ }
147
+ export function overrideAdapterExecutionTargetRemoteCwd(target, remoteCwd) {
148
+ const nextRemoteCwd = remoteCwd?.trim();
149
+ if (!target || target.kind !== "remote" || !nextRemoteCwd) {
150
+ return target;
151
+ }
152
+ if (target.remoteCwd === nextRemoteCwd) {
153
+ return target;
154
+ }
155
+ if (target.transport === "ssh") {
156
+ return {
157
+ ...target,
158
+ remoteCwd: nextRemoteCwd,
159
+ spec: {
160
+ ...target.spec,
161
+ remoteCwd: nextRemoteCwd,
162
+ },
163
+ };
164
+ }
165
+ return {
166
+ ...target,
167
+ remoteCwd: nextRemoteCwd,
168
+ };
169
+ }
170
+ export function resolveAdapterExecutionTargetCwd(target, configuredCwd, localFallbackCwd) {
171
+ if (typeof configuredCwd === "string" && configuredCwd.trim().length > 0) {
172
+ return configuredCwd;
173
+ }
174
+ return adapterExecutionTargetRemoteCwd(target, localFallbackCwd);
175
+ }
176
+ export function adapterExecutionTargetUsesPaperclipBridge(target) {
177
+ return target?.kind === "remote";
178
+ }
179
+ export function describeAdapterExecutionTarget(target) {
180
+ if (!target || target.kind === "local")
181
+ return "local environment";
182
+ if (target.transport === "ssh") {
183
+ return `SSH environment ${target.spec.username}@${target.spec.host}:${target.spec.port}`;
184
+ }
185
+ return `sandbox environment${target.providerKey ? ` (${target.providerKey})` : ""}`;
186
+ }
187
+ export function resolveAdapterExecutionTargetTimeout(target, configuredTimeoutSec) {
188
+ if (typeof configuredTimeoutSec === "number" && Number.isFinite(configuredTimeoutSec)) {
189
+ // Preserve fractional (sub-second) configured values instead of flooring:
190
+ // adapters historically honored e.g. timeoutSec=0.5, and flooring would
191
+ // silently turn it into "no timeout".
192
+ if (configuredTimeoutSec > 0) {
193
+ return { timeoutSec: configuredTimeoutSec, source: "configured" };
194
+ }
195
+ // A negative timeoutSec is the explicit "no adapter wall-clock timeout"
196
+ // opt-out, honored even on sandbox targets. Zero cannot carry that
197
+ // meaning: the adapter config UI persists the schema default of 0 for
198
+ // untouched fields, so timeoutSec=0 in stored config does not signal
199
+ // operator intent and falls through to target defaults below.
200
+ if (configuredTimeoutSec < 0) {
201
+ return { timeoutSec: 0, source: "configured" };
202
+ }
203
+ }
204
+ // Local and SSH adapters preserve the historical "0 means no adapter
205
+ // timeout" behavior. Sandbox-backed runs execute through provider RPCs
206
+ // that usually apply their own shorter command defaults, so request an
207
+ // explicit longer timeout for full adapter runs when the adapter leaves
208
+ // timeoutSec unset.
209
+ if (target?.kind === "remote" && target.transport === "sandbox") {
210
+ return { timeoutSec: DEFAULT_REMOTE_SANDBOX_ADAPTER_TIMEOUT_SEC, source: "sandbox_default" };
211
+ }
212
+ return { timeoutSec: 0, source: "unlimited" };
213
+ }
214
+ export function resolveAdapterExecutionTargetTimeoutSec(target, configuredTimeoutSec) {
215
+ return resolveAdapterExecutionTargetTimeout(target, configuredTimeoutSec).timeoutSec;
216
+ }
217
+ function describeAdapterExecutionTimeoutSource(source) {
218
+ switch (source) {
219
+ case "configured":
220
+ return "configured via adapterConfig.timeoutSec";
221
+ case "sandbox_default":
222
+ return "sandbox default";
223
+ case "unlimited":
224
+ return "no adapter wall-clock timeout";
225
+ }
226
+ }
227
+ /**
228
+ * Self-describing error message for when the adapter wall-clock execution
229
+ * timeout kills a run. Names the timer that fired and the knob that controls
230
+ * it so run failures never surface as a bare "Timed out".
231
+ */
232
+ export function formatAdapterExecutionTimeoutErrorMessage(resolution) {
233
+ return (`Run exceeded the adapter execution timeout ` +
234
+ `(timeoutSec=${resolution.timeoutSec}, ${describeAdapterExecutionTimeoutSource(resolution.source)}). ` +
235
+ `Set adapterConfig.timeoutSec to raise it.`);
236
+ }
237
+ /**
238
+ * One-line start-of-run statement of the effective wall-clock timeout and its
239
+ * source. Callers prefix with `[paperclip] ` and append a newline.
240
+ */
241
+ export function formatAdapterExecutionTimeoutStartLogLine(resolution) {
242
+ if (resolution.timeoutSec <= 0) {
243
+ if (resolution.source === "configured") {
244
+ return ("Adapter execution timeout: none " +
245
+ "(explicitly disabled via adapterConfig.timeoutSec; set it to a positive value to add one).");
246
+ }
247
+ return ("Adapter execution timeout: none " +
248
+ "(no adapter wall-clock timeout for this target; set adapterConfig.timeoutSec to add one).");
249
+ }
250
+ return (`Adapter execution timeout: timeoutSec=${resolution.timeoutSec} ` +
251
+ `(${describeAdapterExecutionTimeoutSource(resolution.source)}; set adapterConfig.timeoutSec to override).`);
252
+ }
253
+ function requireSandboxRunner(target) {
254
+ if (target.runner)
255
+ return target.runner;
256
+ throw new Error("Sandbox execution target is missing its provider runtime runner. Sandbox commands must execute through the environment runtime.");
257
+ }
258
+ function preferredSandboxShell(target) {
259
+ return preferredShellForSandbox(target.shellCommand);
260
+ }
261
+ // The Secure Shell command runner's own output buffer. This value used to
262
+ // derive from the bridge body limit (`DEFAULT_SANDBOX_CALLBACK_BRIDGE_MAX_BODY_BYTES
263
+ // * 4`), so a bridge limit rise silently grew it too. It now stands on its
264
+ // own local constant, independent of the bridge body limit, so a later
265
+ // bridge limit change never resizes this buffer as a side effect.
266
+ const SSH_COMMAND_MAX_BUFFER_BYTES = 1024 * 1024;
267
+ function adapterExecutionTargetCommandRunner(target) {
268
+ if (target.transport === "ssh") {
269
+ return createSshCommandManagedRuntimeRunner({
270
+ spec: target.spec,
271
+ defaultCwd: target.remoteCwd,
272
+ maxBufferBytes: SSH_COMMAND_MAX_BUFFER_BYTES,
273
+ });
274
+ }
275
+ return requireSandboxRunner(target);
276
+ }
277
+ function adapterExecutionTargetShellCommand(target) {
278
+ return target.transport === "ssh" ? "sh" : preferredSandboxShell(target);
279
+ }
280
+ function adapterExecutionTargetTimeoutMs(target) {
281
+ return target.transport === "sandbox" ? target.timeoutMs : undefined;
282
+ }
283
+ export async function ensureAdapterExecutionTargetCommandResolvable(command, target, cwd, env, options = {}) {
284
+ if (target?.kind === "remote" && target.transport === "sandbox") {
285
+ await ensureSandboxCommandResolvable(command, target, sanitizeRemoteExecutionEnv(Object.fromEntries(Object.entries(env).filter((entry) => typeof entry[1] === "string"))), options.installCommand?.trim() || null, options.timeoutSec);
286
+ return;
287
+ }
288
+ await ensureCommandResolvable(command, cwd, env, {
289
+ remoteExecution: adapterExecutionTargetToRemoteSpec(target),
290
+ });
291
+ }
292
+ async function probeSandboxCommandResolvable(command, target, env) {
293
+ const runner = requireSandboxRunner(target);
294
+ const probeScript = `command -v ${shellQuote(command)}`;
295
+ const result = await runner.execute({
296
+ command: "sh",
297
+ args: ["-c", probeScript],
298
+ cwd: target.remoteCwd,
299
+ env,
300
+ timeoutMs: target.timeoutMs ?? 15_000,
301
+ });
302
+ return {
303
+ resolved: !result.timedOut && (result.exitCode ?? 1) === 0,
304
+ timedOut: result.timedOut,
305
+ stderr: result.stderr.trim(),
306
+ };
307
+ }
308
+ async function ensureSandboxCommandResolvable(command, target, env, installCommand, timeoutSec) {
309
+ // Probe whether the binary is resolvable inside the sandbox. We previously
310
+ // short-circuited this for sandbox targets, which let the caller report a
311
+ // success message even when the CLI was missing from the image. Now we run
312
+ // a real `command -v` through the same runner the hello probe will use, so
313
+ // the first step honestly reflects whether the binary is on PATH. The
314
+ // sandbox provider is responsible for sourcing login profiles (e2b mirrors
315
+ // SSH's buildSshSpawnTarget) so this and the hello probe agree on PATH.
316
+ let probe = await probeSandboxCommandResolvable(command, target, env);
317
+ if (probe.resolved)
318
+ return;
319
+ if (probe.timedOut) {
320
+ throw new Error(`Timed out checking command "${command}" on sandbox target.`);
321
+ }
322
+ // If the caller supplied an install command, attempt the install once via
323
+ // the sandbox runner (which the sandbox provider wraps in a login shell)
324
+ // and re-probe before reporting failure. This lets fresh sandbox leases
325
+ // bring up the CLI before the resolvability gate, mirroring the test path.
326
+ let installFailureDetail = null;
327
+ if (installCommand) {
328
+ const runner = requireSandboxRunner(target);
329
+ const installTimeoutMs = typeof timeoutSec === "number" && Number.isFinite(timeoutSec) && timeoutSec > 0
330
+ ? Math.floor(timeoutSec * 1000)
331
+ : target.timeoutMs ?? 300_000;
332
+ try {
333
+ const installResult = await runner.execute({
334
+ command: "sh",
335
+ args: shellCommandArgs(installCommand),
336
+ cwd: target.remoteCwd,
337
+ env,
338
+ timeoutMs: installTimeoutMs,
339
+ });
340
+ if (installResult.timedOut) {
341
+ installFailureDetail = `install command timed out: ${installCommand}`;
342
+ }
343
+ else if ((installResult.exitCode ?? 0) !== 0) {
344
+ const tail = (text) => text.split(/\r?\n/).filter((line) => line.trim().length > 0).slice(-2).join(" | ").slice(0, 240);
345
+ const reason = tail(installResult.stderr || installResult.stdout) || `exit ${installResult.exitCode ?? "?"}`;
346
+ installFailureDetail = `install command exited ${installResult.exitCode ?? "?"}: ${reason}`;
347
+ }
348
+ }
349
+ catch (err) {
350
+ installFailureDetail = `install command threw: ${err instanceof Error ? err.message : String(err)}`;
351
+ }
352
+ probe = await probeSandboxCommandResolvable(command, target, env);
353
+ if (probe.resolved)
354
+ return;
355
+ if (probe.timedOut) {
356
+ throw new Error(`Timed out checking command "${command}" on sandbox target.`);
357
+ }
358
+ }
359
+ const probeStderr = probe.stderr.length > 0 ? ` probe stderr: ${probe.stderr}` : "";
360
+ const installDetail = installFailureDetail ? `; ${installFailureDetail}` : "";
361
+ throw new Error(`Command "${command}" is not installed or not on PATH in the sandbox environment${installDetail}.${probeStderr}`);
362
+ }
363
+ export async function resolveAdapterExecutionTargetCommandForLogs(command, target, cwd, env) {
364
+ if (target?.kind === "remote" && target.transport === "sandbox") {
365
+ return `sandbox://${target.providerKey ?? "provider"}/${target.leaseId ?? "lease"}/${target.remoteCwd} :: ${command}`;
366
+ }
367
+ return await resolveCommandForLogs(command, cwd, env, {
368
+ remoteExecution: adapterExecutionTargetToRemoteSpec(target),
369
+ });
370
+ }
371
+ // Apply the run-disposition seam to one clean process result. Only a clean
372
+ // completion is success-eligible: a timed-out, signalled, or non-zero-exit
373
+ // result is already a failure, so the seam leaves it unchanged. This is the same
374
+ // success-eligibility rule the ACP lane applies. For a success-eligible result
375
+ // the seam settles the disposition in one atomic broker step: it reads the
376
+ // disposition and marks the host-observed orderly completion together, so a
377
+ // gateway exit after the clean completion cannot latch a false mid-run loss. A
378
+ // duplex control channel that died before the clean completion fails the run
379
+ // closed: the seam sets a non-zero exit code, the typed `duplex_channel_lost`
380
+ // error code, and a stderr note that names only the typed loss reason.
381
+ function applyRunDispositionSeam(result, settleRunDisposition) {
382
+ const successEligible = result.exitCode === 0 && !result.timedOut && result.signal === null;
383
+ if (!successEligible || !settleRunDisposition)
384
+ return result;
385
+ const disposition = settleRunDisposition();
386
+ if (!disposition.failed)
387
+ return result;
388
+ const lossReason = disposition.lossReason ?? "other";
389
+ const note = `[paperclip] The sandbox duplex control channel was lost (${lossReason}) before the run completed.\n`;
390
+ const separator = result.stderr.length > 0 && !result.stderr.endsWith("\n") ? "\n" : "";
391
+ return {
392
+ ...result,
393
+ exitCode: 1,
394
+ errorCode: DUPLEX_CHANNEL_LOST_ERROR_CODE,
395
+ stderr: `${result.stderr}${separator}${note}`,
396
+ };
397
+ }
398
+ export async function runAdapterExecutionTargetProcess(runId, target, command, args, options) {
399
+ if (target?.kind === "remote" && target.transport === "sandbox") {
400
+ const runner = requireSandboxRunner(target);
401
+ const env = withWardmoteEnvAliases(sanitizeRemoteExecutionEnv(options.env));
402
+ await options.onRuntimeProgress?.({
403
+ phase: "adapter_startup",
404
+ message: "Starting adapter in environment",
405
+ });
406
+ const runLogTail = options.runLogTail?.create() ?? null;
407
+ let execCommand = command;
408
+ let execArgs = args;
409
+ if (runLogTail) {
410
+ ({ command: execCommand, args: execArgs } = runLogTail.wrapCommand(command, args));
411
+ runLogTail.start(options.onLog);
412
+ }
413
+ try {
414
+ const result = await runner.execute({
415
+ command: execCommand,
416
+ args: execArgs,
417
+ cwd: target.remoteCwd,
418
+ env,
419
+ stdin: options.stdin,
420
+ timeoutMs: options.timeoutSec > 0 ? options.timeoutSec * 1000 : target.timeoutMs ?? undefined,
421
+ // The tail loop already streams incremental chunks; suppress the
422
+ // runner's end-of-run batched onLog to avoid duplicate log bytes.
423
+ onLog: runLogTail ? undefined : options.onLog,
424
+ onSpawn: options.onSpawn
425
+ ? async (meta) => options.onSpawn?.({ ...meta, processGroupId: null })
426
+ : undefined,
427
+ });
428
+ // Settle the duplex run disposition synchronously at the clean-completion
429
+ // boundary, before the run-log tail finishes. The atomic settle marks the
430
+ // host-observed orderly completion in one broker step, so a gateway exit
431
+ // after the clean process completion cannot latch a false mid-run loss. A
432
+ // control channel that died before this clean completion still fails the
433
+ // run closed.
434
+ if (!result.timedOut && typeof result.exitCode === "number" && Number.isInteger(result.exitCode) && result.exitCode >= 0)
435
+ options.onProcessStopped?.();
436
+ const settled = applyRunDispositionSeam(result, options.settleRunDisposition);
437
+ if (runLogTail) {
438
+ await runLogTail.finish({ stdout: result.stdout, stderr: result.stderr });
439
+ }
440
+ return settled;
441
+ }
442
+ catch (error) {
443
+ if (runLogTail) {
444
+ await runLogTail.abort();
445
+ }
446
+ throw error;
447
+ }
448
+ }
449
+ const env = target?.kind === "remote" && target.transport === "ssh"
450
+ ? sanitizeRemoteExecutionEnv(options.env)
451
+ : options.env;
452
+ const result = await runChildProcess(runId, command, args, {
453
+ cwd: options.cwd,
454
+ env,
455
+ stdin: options.stdin,
456
+ liveStdin: options.liveStdin,
457
+ timeoutSec: options.timeoutSec,
458
+ graceSec: options.graceSec,
459
+ onLog: options.onLog,
460
+ onSpawn: options.onSpawn,
461
+ terminalResultCleanup: options.terminalResultCleanup,
462
+ localProcessSandbox: target?.kind === "local" || !target ? options.localProcessSandbox : null,
463
+ remoteExecution: adapterExecutionTargetToRemoteSpec(target),
464
+ });
465
+ // Closing an SSH client on timeout/disconnect does not prove the remote
466
+ // provider exited. SSH status 255 is transport failure, never a stop receipt.
467
+ if (!target || target.kind === "local" ||
468
+ (!result.timedOut && !result.signal && result.exitCode !== null && result.exitCode >= 0 && result.exitCode < 255)) {
469
+ options.onProcessStopped?.();
470
+ }
471
+ return result;
472
+ }
473
+ export async function runAdapterExecutionTargetShellCommand(runId, target, command, options) {
474
+ const onLog = options.onLog ?? (async () => { });
475
+ if (target?.kind === "remote") {
476
+ const startedAt = new Date().toISOString();
477
+ const env = sanitizeRemoteExecutionEnv(options.env);
478
+ if (target.transport === "ssh") {
479
+ try {
480
+ // Pass the raw command — `runSshCommand` owns profile sourcing and
481
+ // the outer shell wrapper. Wrapping again here would nest a second
482
+ // shell after the explicit `env KEY=VAL` overrides, re-sourcing
483
+ // login profiles AFTER the override and silently undoing any
484
+ // identity var (NVM_DIR / PATH / etc.) that a profile re-exports.
485
+ const result = await runSshCommand(target.spec, command, {
486
+ env,
487
+ timeoutMs: (options.timeoutSec ?? 15) * 1000,
488
+ });
489
+ if (result.stdout)
490
+ await onLog("stdout", result.stdout);
491
+ if (result.stderr)
492
+ await onLog("stderr", result.stderr);
493
+ return {
494
+ exitCode: 0,
495
+ signal: null,
496
+ timedOut: false,
497
+ stdout: result.stdout,
498
+ stderr: result.stderr,
499
+ pid: null,
500
+ startedAt,
501
+ };
502
+ }
503
+ catch (error) {
504
+ const timedOutError = error;
505
+ const stdout = timedOutError.stdout ?? "";
506
+ const stderr = timedOutError.stderr ?? "";
507
+ if (typeof timedOutError.code === "number") {
508
+ if (stdout)
509
+ await onLog("stdout", stdout);
510
+ if (stderr)
511
+ await onLog("stderr", stderr);
512
+ return {
513
+ exitCode: timedOutError.code,
514
+ signal: timedOutError.signal ?? null,
515
+ timedOut: false,
516
+ stdout,
517
+ stderr,
518
+ pid: null,
519
+ startedAt,
520
+ };
521
+ }
522
+ if (timedOutError.code !== "ETIMEDOUT") {
523
+ throw error;
524
+ }
525
+ if (stdout)
526
+ await onLog("stdout", stdout);
527
+ if (stderr)
528
+ await onLog("stderr", stderr);
529
+ return {
530
+ exitCode: null,
531
+ signal: timedOutError.signal ?? null,
532
+ timedOut: true,
533
+ stdout,
534
+ stderr,
535
+ pid: null,
536
+ startedAt,
537
+ };
538
+ }
539
+ }
540
+ const shellCommand = preferredSandboxShell(target);
541
+ return await requireSandboxRunner(target).execute({
542
+ command: shellCommand,
543
+ args: shellCommandArgs(command),
544
+ cwd: target.remoteCwd,
545
+ env,
546
+ timeoutMs: (options.timeoutSec ?? 15) * 1000,
547
+ onLog,
548
+ });
549
+ }
550
+ return await runAdapterExecutionTargetProcess(runId, target, "sh", ["-lc", command], {
551
+ cwd: options.cwd,
552
+ env: options.env,
553
+ timeoutSec: options.timeoutSec ?? 15,
554
+ graceSec: options.graceSec ?? 5,
555
+ onLog,
556
+ });
557
+ }
558
+ // Best-effort run of an adapter-supplied install command on a sandbox target
559
+ // before the resolvability + hello probe. Returns null for non-sandbox
560
+ // targets so callers can no-op. Returns a structured check otherwise — never
561
+ // throws — so the rest of the test still runs and reports the post-install
562
+ // state honestly. Caller pushes the check into its result array; the test
563
+ // report shows whether install was attempted and what came back.
564
+ export async function maybeRunSandboxInstallCommand(input) {
565
+ const { target, adapterKey, installCommand } = input;
566
+ if (!target || target.kind !== "remote" || target.transport !== "sandbox") {
567
+ return null;
568
+ }
569
+ const trimmed = installCommand.trim();
570
+ if (trimmed.length === 0)
571
+ return null;
572
+ const code = `${adapterKey}_install_command_run`;
573
+ // Skip install when the binary is already on PATH. Avoids running
574
+ // network-dependent installers (e.g. `curl ... | bash`) on every test
575
+ // probe when the CLI is preinstalled on the lease/template.
576
+ const detectCommand = input.detectCommand?.trim();
577
+ if (detectCommand) {
578
+ try {
579
+ const probe = await runAdapterExecutionTargetShellCommand(input.runId, target, `command -v ${shellQuote(detectCommand)} >/dev/null 2>&1`, {
580
+ cwd: target.remoteCwd,
581
+ env: input.env ?? {},
582
+ timeoutSec: 30,
583
+ graceSec: 5,
584
+ });
585
+ if (!probe.timedOut && probe.exitCode === 0) {
586
+ return {
587
+ code,
588
+ level: "info",
589
+ message: `${detectCommand} already on PATH; skipped install.`,
590
+ };
591
+ }
592
+ }
593
+ catch {
594
+ // Fall through to actually running the install — failure to probe
595
+ // is not a reason to skip the install gate.
596
+ }
597
+ }
598
+ let result;
599
+ try {
600
+ result = await runAdapterExecutionTargetShellCommand(input.runId, target, trimmed, {
601
+ cwd: target.remoteCwd,
602
+ env: input.env ?? {},
603
+ timeoutSec: input.timeoutSec ?? 240,
604
+ graceSec: 10,
605
+ });
606
+ }
607
+ catch (err) {
608
+ return {
609
+ code,
610
+ level: "warn",
611
+ message: "Install command threw before completion.",
612
+ detail: err instanceof Error ? err.message : String(err),
613
+ };
614
+ }
615
+ const tail = (text) => text.split(/\r?\n/).filter((line) => line.trim().length > 0).slice(-3).join(" | ").slice(0, 480);
616
+ if (result.timedOut) {
617
+ return {
618
+ code,
619
+ level: "warn",
620
+ message: `Install command timed out: ${trimmed}`,
621
+ detail: tail(result.stderr || result.stdout),
622
+ };
623
+ }
624
+ if ((result.exitCode ?? 1) === 0) {
625
+ return {
626
+ code,
627
+ level: "info",
628
+ message: `Install command ran: ${trimmed}`,
629
+ ...(tail(result.stdout) ? { detail: tail(result.stdout) } : {}),
630
+ };
631
+ }
632
+ return {
633
+ code,
634
+ level: "warn",
635
+ message: `Install command exited ${result.exitCode}: ${trimmed}`,
636
+ detail: tail(result.stderr || result.stdout),
637
+ };
638
+ }
639
+ export async function readAdapterExecutionTargetHomeDir(runId, target, options) {
640
+ const result = await runAdapterExecutionTargetShellCommand(runId, target, 'printf %s "$HOME"', options);
641
+ const homeDir = result.stdout.trim();
642
+ return homeDir.length > 0 ? homeDir : null;
643
+ }
644
+ export async function ensureAdapterExecutionTargetRuntimeCommandInstalled(input) {
645
+ const installCommand = input.installCommand?.trim();
646
+ if (!installCommand || input.target?.kind !== "remote" || input.target.transport !== "sandbox") {
647
+ return;
648
+ }
649
+ const detectCommand = input.detectCommand?.trim();
650
+ if (detectCommand) {
651
+ const probe = await runAdapterExecutionTargetShellCommand(input.runId, input.target, `command -v ${shellQuote(detectCommand)} >/dev/null 2>&1`, {
652
+ cwd: input.cwd,
653
+ env: input.env,
654
+ timeoutSec: input.timeoutSec,
655
+ graceSec: input.graceSec,
656
+ });
657
+ if (!probe.timedOut && probe.exitCode === 0) {
658
+ return;
659
+ }
660
+ }
661
+ const result = await runAdapterExecutionTargetShellCommand(input.runId, input.target, installCommand, {
662
+ cwd: input.cwd,
663
+ env: input.env,
664
+ timeoutSec: input.timeoutSec,
665
+ graceSec: input.graceSec,
666
+ onLog: input.onLog,
667
+ });
668
+ // A failed or timed-out install is not necessarily fatal: the CLI may already
669
+ // be on PATH from a previous lease's install, the template image, or another
670
+ // path entry. Re-run the detect probe (when one is configured) so a transient
671
+ // install failure does not abort the agent run when the binary is reachable.
672
+ const installFailed = result.timedOut || (result.exitCode ?? 0) !== 0;
673
+ if (!installFailed) {
674
+ return;
675
+ }
676
+ if (detectCommand) {
677
+ const recheck = await runAdapterExecutionTargetShellCommand(input.runId, input.target, `command -v ${shellQuote(detectCommand)} >/dev/null 2>&1`, {
678
+ cwd: input.cwd,
679
+ env: input.env,
680
+ timeoutSec: input.timeoutSec,
681
+ graceSec: input.graceSec,
682
+ });
683
+ if (!recheck.timedOut && recheck.exitCode === 0) {
684
+ if (input.onLog) {
685
+ const reason = result.timedOut ? "timed out" : `exited ${result.exitCode ?? "?"}`;
686
+ await input.onLog("stderr", `[paperclip] Install command ${reason} (${installCommand}) but ${detectCommand} is on PATH; continuing.\n`);
687
+ }
688
+ return;
689
+ }
690
+ }
691
+ if (result.timedOut) {
692
+ throw new Error(`Timed out while installing the adapter runtime command via: ${installCommand}`);
693
+ }
694
+ throw new Error(`Failed to install the adapter runtime command via: ${installCommand}`);
695
+ }
696
+ export async function ensureAdapterExecutionTargetFile(runId, target, filePath, options) {
697
+ await runAdapterExecutionTargetShellCommand(runId, target, `mkdir -p ${shellQuote(path.posix.dirname(filePath))} && : > ${shellQuote(filePath)}`, options);
698
+ }
699
+ /**
700
+ * Ensure a working directory exists (and is a directory) on the execution target.
701
+ *
702
+ * For local targets this delegates to the local `ensureAbsoluteDirectory` helper
703
+ * (Node fs). For remote (SSH/sandbox) targets it shells out and runs
704
+ * `mkdir -p` (when allowed) followed by a `[ -d ]` check so the result reflects
705
+ * the directory state inside the environment, not on the Paperclip host.
706
+ *
707
+ * Throws an Error with a human-readable message on failure.
708
+ */
709
+ export async function ensureAdapterExecutionTargetDirectory(runId, target, cwd, options) {
710
+ const createIfMissing = options.createIfMissing ?? false;
711
+ if (!target || target.kind === "local") {
712
+ const { ensureAbsoluteDirectory } = await import("./server-utils.js");
713
+ await ensureAbsoluteDirectory(cwd, { createIfMissing });
714
+ return;
715
+ }
716
+ // Remote (SSH or sandbox): both expect POSIX absolute paths inside the env.
717
+ if (!cwd.startsWith("/")) {
718
+ throw new Error(`Working directory must be an absolute POSIX path on the remote target: "${cwd}"`);
719
+ }
720
+ const quoted = shellQuote(cwd);
721
+ const script = createIfMissing
722
+ ? `mkdir -p ${quoted} && [ -d ${quoted} ]`
723
+ : `[ -d ${quoted} ]`;
724
+ const result = await runAdapterExecutionTargetShellCommand(runId, target, script, {
725
+ cwd: target.kind === "remote" ? target.remoteCwd : cwd,
726
+ env: options.env,
727
+ timeoutSec: options.timeoutSec ?? 15,
728
+ graceSec: options.graceSec ?? 5,
729
+ onLog: options.onLog,
730
+ });
731
+ if (result.timedOut) {
732
+ throw new Error(`Timed out checking working directory on remote target: "${cwd}"`);
733
+ }
734
+ if ((result.exitCode ?? 1) !== 0) {
735
+ const detail = (result.stderr || result.stdout || "").trim();
736
+ if (createIfMissing) {
737
+ throw new Error(`Could not create working directory "${cwd}" on remote target${detail ? `: ${detail}` : "."}`);
738
+ }
739
+ throw new Error(`Working directory does not exist on remote target: "${cwd}"${detail ? ` (${detail})` : ""}`);
740
+ }
741
+ }
742
+ export function adapterExecutionTargetSessionIdentity(target) {
743
+ if (!target || target.kind === "local")
744
+ return null;
745
+ if (target.transport === "ssh")
746
+ return buildRemoteExecutionSessionIdentity(target.spec);
747
+ return {
748
+ transport: "sandbox",
749
+ providerKey: target.providerKey ?? null,
750
+ environmentId: target.environmentId ?? null,
751
+ leaseId: target.leaseId ?? null,
752
+ remoteCwd: target.remoteCwd,
753
+ };
754
+ }
755
+ export function adapterExecutionTargetSessionMatches(saved, target) {
756
+ if (!target || target.kind === "local") {
757
+ return Object.keys(parseObject(saved)).length === 0;
758
+ }
759
+ if (target.transport === "ssh")
760
+ return remoteExecutionSessionMatches(saved, target.spec);
761
+ const current = adapterExecutionTargetSessionIdentity(target);
762
+ const parsedSaved = parseObject(saved);
763
+ return (readStringMeta(parsedSaved, "transport") === current?.transport &&
764
+ readStringMeta(parsedSaved, "providerKey") === current?.providerKey &&
765
+ readStringMeta(parsedSaved, "environmentId") === current?.environmentId &&
766
+ readStringMeta(parsedSaved, "leaseId") === current?.leaseId &&
767
+ readStringMeta(parsedSaved, "remoteCwd") === current?.remoteCwd);
768
+ }
769
+ export function parseAdapterExecutionTarget(value) {
770
+ const parsed = parseObject(value);
771
+ const kind = readStringMeta(parsed, "kind");
772
+ if (kind === "local") {
773
+ return {
774
+ kind: "local",
775
+ environmentId: readStringMeta(parsed, "environmentId"),
776
+ leaseId: readStringMeta(parsed, "leaseId"),
777
+ };
778
+ }
779
+ if (kind === "remote" && readStringMeta(parsed, "transport") === "ssh") {
780
+ const spec = parseSshRemoteExecutionSpec(parseObject(parsed.spec));
781
+ if (!spec)
782
+ return null;
783
+ return {
784
+ kind: "remote",
785
+ transport: "ssh",
786
+ environmentId: readStringMeta(parsed, "environmentId"),
787
+ leaseId: readStringMeta(parsed, "leaseId"),
788
+ remoteCwd: spec.remoteCwd,
789
+ spec,
790
+ };
791
+ }
792
+ if (kind === "remote" && readStringMeta(parsed, "transport") === "sandbox") {
793
+ const remoteCwd = readStringMeta(parsed, "remoteCwd");
794
+ if (!remoteCwd)
795
+ return null;
796
+ const effectiveCapabilities = parseEffectiveExecutionCapabilities(parsed.effectiveCapabilities);
797
+ return {
798
+ kind: "remote",
799
+ transport: "sandbox",
800
+ providerKey: readStringMeta(parsed, "providerKey"),
801
+ environmentId: readStringMeta(parsed, "environmentId"),
802
+ leaseId: readStringMeta(parsed, "leaseId"),
803
+ remoteCwd,
804
+ timeoutMs: typeof parsed.timeoutMs === "number" ? parsed.timeoutMs : null,
805
+ streamRunLogs: typeof parsed.streamRunLogs === "boolean" ? parsed.streamRunLogs : null,
806
+ // Fail closed: only the literal `true` reads as a grant. An absent field
807
+ // or any other value parses as no grant, so a round-trip never invents one.
808
+ enableSandboxDuplexBridge: parsed.enableSandboxDuplexBridge === true,
809
+ ...(effectiveCapabilities ? { effectiveCapabilities } : {}),
810
+ };
811
+ }
812
+ return null;
813
+ }
814
+ export function adapterExecutionTargetFromRemoteExecution(remoteExecution, metadata = {}) {
815
+ const parsed = parseObject(remoteExecution);
816
+ const ssh = parseSshRemoteExecutionSpec(parsed);
817
+ if (ssh) {
818
+ return {
819
+ kind: "remote",
820
+ transport: "ssh",
821
+ environmentId: metadata.environmentId ?? null,
822
+ leaseId: metadata.leaseId ?? null,
823
+ remoteCwd: ssh.remoteCwd,
824
+ spec: ssh,
825
+ };
826
+ }
827
+ return null;
828
+ }
829
+ export function readAdapterExecutionTarget(input) {
830
+ if (isAdapterExecutionTargetInstance(input.executionTarget)) {
831
+ return input.executionTarget;
832
+ }
833
+ return (parseAdapterExecutionTarget(input.executionTarget) ??
834
+ adapterExecutionTargetFromRemoteExecution(input.legacyRemoteExecution));
835
+ }
836
+ export async function prepareAdapterExecutionTargetRuntime(input) {
837
+ const target = input.target ?? { kind: "local" };
838
+ if (target.kind === "local") {
839
+ return {
840
+ target,
841
+ workspaceRemoteDir: null,
842
+ runtimeRootDir: null,
843
+ assetDirs: {},
844
+ additionalSourceDirs: {},
845
+ additionalSourceFailures: [],
846
+ workspaceSyncSnapshot: null,
847
+ restoreWorkspace: async () => { },
848
+ };
849
+ }
850
+ if (target.transport === "ssh") {
851
+ const prepared = await prepareRemoteManagedRuntime({
852
+ spec: target.spec,
853
+ runId: input.runId,
854
+ adapterKey: input.adapterKey,
855
+ workspaceLocalDir: input.workspaceLocalDir,
856
+ workspaceRemoteDir: input.workspaceRemoteDir,
857
+ syncWorkspace: input.syncWorkspace,
858
+ workspaceFileMode: input.workspaceFileMode,
859
+ workspaceExclude: input.workspaceExclude,
860
+ assets: input.assets,
861
+ additionalSources: input.additionalSources,
862
+ onProgress: input.onProgress,
863
+ });
864
+ return {
865
+ target,
866
+ workspaceRemoteDir: prepared.workspaceRemoteDir,
867
+ runtimeRootDir: prepared.runtimeRootDir,
868
+ assetDirs: prepared.assetDirs,
869
+ additionalSourceDirs: prepared.additionalSourceDirs,
870
+ // The SSH transport does not stage referenced projects (it is out of scope), so it never
871
+ // reports a per-project staging failure.
872
+ additionalSourceFailures: [],
873
+ workspaceSyncSnapshot: null,
874
+ restoreWorkspace: prepared.restoreWorkspace,
875
+ };
876
+ }
877
+ const prepared = await prepareCommandManagedRuntime({
878
+ runner: requireSandboxRunner(target),
879
+ spec: {
880
+ providerKey: target.providerKey,
881
+ shellCommand: target.shellCommand,
882
+ leaseId: target.leaseId,
883
+ remoteCwd: target.remoteCwd,
884
+ timeoutMs: input.timeoutSec && input.timeoutSec > 0
885
+ ? input.timeoutSec * 1000
886
+ : target.timeoutMs,
887
+ },
888
+ adapterKey: input.adapterKey,
889
+ workspaceLocalDir: input.workspaceLocalDir,
890
+ workspaceRemoteDir: input.workspaceRemoteDir,
891
+ runtimeRootDir: input.runtimeRootDir,
892
+ syncWorkspace: input.syncWorkspace,
893
+ workspaceInboundMode: input.workspaceInboundMode,
894
+ workspaceDurableSeed: input.workspaceDurableSeed,
895
+ workspaceBaseline: input.workspaceBaseline,
896
+ workspaceGitSnapshot: input.workspaceGitSnapshot,
897
+ workspaceExclude: input.workspaceExclude,
898
+ workspaceFileMode: input.workspaceFileMode,
899
+ preserveAbsentOnRestore: input.preserveAbsentOnRestore,
900
+ assets: input.assets,
901
+ additionalSources: input.additionalSources,
902
+ installCommand: input.installCommand,
903
+ detectCommand: input.detectCommand,
904
+ onProgress: input.onProgress,
905
+ onRuntimeProgress: input.onRuntimeProgress,
906
+ runtimeSpan: input.runtimeSpan,
907
+ });
908
+ return {
909
+ target,
910
+ workspaceRemoteDir: prepared.workspaceRemoteDir,
911
+ runtimeRootDir: prepared.runtimeRootDir,
912
+ assetDirs: prepared.assetDirs,
913
+ additionalSourceDirs: prepared.additionalSourceDirs,
914
+ additionalSourceFailures: prepared.additionalSourceFailures,
915
+ workspaceSyncSnapshot: prepared.workspaceSyncSnapshot,
916
+ cleanupWorkspaceSnapshot: prepared.cleanupWorkspaceSnapshot,
917
+ restoreWorkspace: prepared.restoreWorkspace,
918
+ };
919
+ }
920
+ export function runtimeAssetDir(prepared, key, fallbackRemoteCwd) {
921
+ return prepared.assetDirs[key] ?? path.posix.join(fallbackRemoteCwd, ".paperclip-runtime", key);
922
+ }
923
+ /** Keep sandbox housekeeping within the producer-owned Runner runtime. */
924
+ export function githubOperationLauncherDirectory(input) {
925
+ // Only controller-generated run IDs may name a removable directory.
926
+ if (!/^[a-zA-Z0-9_-]+$/.test(input.runId))
927
+ throw new Error("Invalid GitHub launcher run ID");
928
+ return input.target?.kind === "remote"
929
+ ? path.posix.join(input.target.remoteCwd, ".paperclip-runtime", ...(input.target.transport === "sandbox" ? ["paperclip-runner"] : []), "github", input.runId)
930
+ : path.join(os.tmpdir(), "paperclip-github-runtime", input.runId);
931
+ }
932
+ /** Call only after execution settles, before releasing its remote environment lease. */
933
+ export async function cleanupGitHubOperationLaunchers(input) {
934
+ const directory = githubOperationLauncherDirectory(input);
935
+ if (input.target?.kind === "remote") {
936
+ const result = await adapterExecutionTargetCommandRunner(input.target).execute({
937
+ command: "sh", args: ["-c", `rm -rf -- ${shellQuote(directory)}`],
938
+ cwd: input.target.remoteCwd, timeoutMs: 5_000,
939
+ });
940
+ if (result.exitCode !== 0)
941
+ throw new Error("Could not clean managed GitHub launchers");
942
+ }
943
+ else {
944
+ await fs.rm(directory, { recursive: true, force: true });
945
+ }
946
+ }
947
+ async function githubOperationLauncherBasePath(target, env) {
948
+ if (!target)
949
+ return env.PATH || process.env.PATH || "/usr/bin:/bin";
950
+ const configuredPath = sanitizeRemoteExecutionEnv(env).PATH;
951
+ if (configuredPath !== undefined)
952
+ return configuredPath;
953
+ // The provider owns login/profile setup. Query its effective PATH before
954
+ // staging BASH_ENV, rather than substituting the controller's toolchain or
955
+ // a minimal PATH that hides legacy NVM/user-local agent installations.
956
+ const result = await adapterExecutionTargetCommandRunner(target).execute({
957
+ command: "sh",
958
+ args: ["-c", "printf '\\000%s\\000' \"$PATH\""],
959
+ cwd: target.remoteCwd,
960
+ timeoutMs: 15_000,
961
+ });
962
+ // Frame the value so login banners cannot become executable search paths.
963
+ const remotePath = result.stdout.match(/\0([^\0]+)\0/)?.[1];
964
+ if (result.timedOut || result.exitCode !== 0 || !remotePath) {
965
+ throw new Error("Could not resolve remote PATH for managed GitHub launchers");
966
+ }
967
+ return remotePath;
968
+ }
969
+ /** Read only execution-target Git context; never import the controller's credentials into SSH. */
970
+ export async function prepareGitHubExecutionEnvironment(input) {
971
+ const script = String.raw `
972
+ const fs = require('node:fs');
973
+ const path = require('node:path');
974
+ const cp = require('node:child_process');
975
+ const env = {};
976
+ env.PAPERCLIP_RUNNER_NETWORK_ROOTS = JSON.stringify(['/etc/resolv.conf','/etc/hosts','/etc/nsswitch.conf','/etc/ssl/certs','/etc/ssl/cert.pem'].flatMap(p => { try { return [fs.realpathSync(p)]; } catch { return []; } }));
977
+ if (process.argv[1] === 'host') {
978
+ for (const [key, value] of Object.entries(process.env)) {
979
+ if (/^(GH_TOKEN|GITHUB_TOKEN|GH_ENTERPRISE_TOKEN|GITHUB_ENTERPRISE_TOKEN|PAPERCLIP_GIT_TOKEN|GH_CONFIG_DIR|GIT_CONFIG_(GLOBAL|SYSTEM|NOSYSTEM|COUNT|KEY_\d+|VALUE_\d+)|GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)|GIT_ASKPASS|SSH_ASKPASS|SSH_AUTH_SOCK|GIT_SSH_COMMAND|GIT_SSH)$/.test(key)) env[key] = value;
980
+ }
981
+ env.PAPERCLIP_GITHUB_HOST_HOME = process.env.HOME || '';
982
+ env.GH_CONFIG_DIR ||= path.join(process.env.XDG_CONFIG_HOME || path.join(process.env.HOME || '', '.config'), 'gh');
983
+ }
984
+ try {
985
+ const top = cp.execFileSync('git', ['rev-parse', '--show-toplevel'], {encoding:'utf8',stdio:['ignore','pipe','ignore']}).trim();
986
+ if (fs.realpathSync(top) === fs.realpathSync(process.cwd())) {
987
+ env.PAPERCLIP_GIT_METADATA_ROOTS = JSON.stringify(cp.execFileSync('git', ['rev-parse','--path-format=absolute','--git-common-dir','--git-dir'], {encoding:'utf8',stdio:['ignore','pipe','ignore']}).trim().split('\n').map(p => fs.realpathSync(p)));
988
+ }
989
+ } catch {}
990
+ process.stdout.write("\0" + JSON.stringify(env) + "\0");
991
+ `;
992
+ const args = ["-e", script, input.hostCredentials ? "host" : "managed"];
993
+ const remote = input.target?.kind === "remote" ? input.target : null;
994
+ let discovered;
995
+ if (remote) {
996
+ // A legacy SSH host may run a standalone agent binary without Node. Use
997
+ // only the shell and Git, and emit bounded, NUL-framed environment records.
998
+ const probe = String.raw `
999
+ printf '\0PAPERCLIP_GIT_CONTEXT_V1\0'
1000
+ if [ "$1" = host ]; then
1001
+ for key in GH_TOKEN GITHUB_TOKEN GH_ENTERPRISE_TOKEN GITHUB_ENTERPRISE_TOKEN PAPERCLIP_GIT_TOKEN GH_CONFIG_DIR GIT_CONFIG_GLOBAL GIT_CONFIG_SYSTEM GIT_CONFIG_NOSYSTEM GIT_CONFIG_COUNT GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_ASKPASS SSH_ASKPASS SSH_AUTH_SOCK GIT_SSH_COMMAND GIT_SSH; do
1002
+ eval 'value=${"$"}{'"$key"'-}'
1003
+ [ -z "$value" ] || printf '%s\0%s\0' "$key" "$value"
1004
+ done
1005
+ index=0
1006
+ while [ "$index" -lt 32 ]; do
1007
+ for prefix in GIT_CONFIG_KEY_ GIT_CONFIG_VALUE_; do
1008
+ key="$prefix$index"
1009
+ eval 'value=${"$"}{'"$key"'-}'
1010
+ [ -z "$value" ] || printf '%s\0%s\0' "$key" "$value"
1011
+ done
1012
+ index=$((index + 1))
1013
+ done
1014
+ printf 'PAPERCLIP_GITHUB_HOST_HOME\0%s\0' "$HOME"
1015
+ printf 'GH_CONFIG_DIR\0%s\0' "${"$"}{GH_CONFIG_DIR:-${"$"}{XDG_CONFIG_HOME:-$HOME/.config}/gh}"
1016
+ fi
1017
+ for file in /etc/resolv.conf /etc/hosts /etc/nsswitch.conf /etc/ssl/certs /etc/ssl/cert.pem; do
1018
+ index=0
1019
+ while [ -L "$file" ] && [ "$index" -lt 40 ]; do
1020
+ target=$(readlink "$file") || break
1021
+ case "$target" in /*) file="$target" ;; *) file="$(dirname "$file")/$target" ;; esac
1022
+ index=$((index + 1))
1023
+ done
1024
+ if [ -e "$file" ]; then
1025
+ parent=$(cd "$(dirname "$file")" && pwd -P) || continue
1026
+ printf 'PAPERCLIP_RUNNER_NETWORK_ROOT\0%s\0' "$parent/$(basename "$file")"
1027
+ fi
1028
+ done
1029
+ cwd=$(pwd -P)
1030
+ top=$(git rev-parse --show-toplevel 2>/dev/null) || top=
1031
+ if [ -n "$top" ] && [ "$(cd "$top" && pwd -P)" = "$cwd" ]; then
1032
+ for kind in --git-common-dir --git-dir; do
1033
+ root=$(git rev-parse --path-format=absolute "$kind" 2>/dev/null) || continue
1034
+ root=$(cd "$root" && pwd -P) || continue
1035
+ printf 'PAPERCLIP_GIT_METADATA_ROOT\0%s\0' "$root"
1036
+ done
1037
+ fi
1038
+ printf '\0PAPERCLIP_GIT_CONTEXT_END\0'
1039
+ `;
1040
+ const result = await adapterExecutionTargetCommandRunner(remote).execute({
1041
+ command: "sh", args: ["-c", probe, "paperclip-git-context", input.hostCredentials ? "host" : "managed"],
1042
+ // The caller's cwd belongs to the controller. Copied sandbox/SSH
1043
+ // workspaces can live at a different path on the execution target.
1044
+ cwd: remote.remoteCwd, timeoutMs: 15_000,
1045
+ });
1046
+ if (result.exitCode !== 0)
1047
+ throw new Error("Could not read execution-target Git context");
1048
+ const payload = result.stdout.split("\0PAPERCLIP_GIT_CONTEXT_V1\0")[1]?.split("\0PAPERCLIP_GIT_CONTEXT_END\0")[0];
1049
+ if (payload === undefined)
1050
+ throw new Error("Could not read execution-target Git context");
1051
+ discovered = {};
1052
+ const records = payload.split("\0");
1053
+ const roots = [];
1054
+ const networkRoots = [];
1055
+ for (let index = 0; index + 1 < records.length; index += 2) {
1056
+ const key = records[index];
1057
+ const value = records[index + 1];
1058
+ if (key === "PAPERCLIP_GIT_METADATA_ROOT")
1059
+ roots.push(value);
1060
+ else if (key === "PAPERCLIP_RUNNER_NETWORK_ROOT")
1061
+ networkRoots.push(value);
1062
+ else
1063
+ discovered[key] = value;
1064
+ }
1065
+ discovered.PAPERCLIP_GIT_METADATA_ROOTS = JSON.stringify([...new Set(roots)]);
1066
+ discovered.PAPERCLIP_RUNNER_NETWORK_ROOTS = JSON.stringify([...new Set(networkRoots)]);
1067
+ }
1068
+ else {
1069
+ const result = await promisify(execFile)(process.execPath, args, { cwd: input.cwd, timeout: 15_000, maxBuffer: 1024 * 1024 });
1070
+ try {
1071
+ discovered = JSON.parse(result.stdout.split("\0")[1] ?? "");
1072
+ }
1073
+ catch {
1074
+ throw new Error("Could not read execution-target Git context");
1075
+ }
1076
+ }
1077
+ // Controller-derived roots and mode must not be replaced by agent bindings.
1078
+ return { ...discovered, ...input.env,
1079
+ ...(input.hostCredentials ? { PAPERCLIP_GITHUB_HOST_HOME: discovered.PAPERCLIP_GITHUB_HOST_HOME } : {}),
1080
+ PAPERCLIP_GIT_METADATA_ROOTS: discovered.PAPERCLIP_GIT_METADATA_ROOTS ?? "[]",
1081
+ PAPERCLIP_RUNNER_NETWORK_ROOTS: discovered.PAPERCLIP_RUNNER_NETWORK_ROOTS ?? "[]",
1082
+ PAPERCLIP_GITHUB_AUTH_MODE: input.hostCredentials ? "host" : "managed",
1083
+ PAPERCLIP_RUNNER_NETWORK_ACCESS: input.networkAccess ? "enabled" : "disabled",
1084
+ };
1085
+ }
1086
+ /** Stage token-free launchers next to the execution, not in shared global Git config. */
1087
+ export async function prepareGitHubOperationLaunchers(input) {
1088
+ const remote = input.target?.kind === "remote" ? input.target : null;
1089
+ const directory = githubOperationLauncherDirectory(input);
1090
+ const configDirectory = path.posix.join(directory, "gh-config");
1091
+ const basePath = await githubOperationLauncherBasePath(remote, input.env);
1092
+ const managedPath = basePath ? `${directory}:${basePath}` : directory;
1093
+ // Login shells may reorder PATH through /etc/profile or path_helper. Restore
1094
+ // the managed launchers after startup without loading a host user's profile.
1095
+ // Empty merge overrides clear host identity before launch, but Git treats
1096
+ // them as an explicit empty author. Remove them once the shell has inherited
1097
+ // its final environment; preserve nonempty per-operation identity values.
1098
+ const clearEmptyGitIdentity = ["GIT_AUTHOR_NAME", "GIT_AUTHOR_EMAIL", "GIT_COMMITTER_NAME", "GIT_COMMITTER_EMAIL"]
1099
+ .map((key) => `if [ -z "\${${key}-}" ]; then unset ${key}; fi\n`)
1100
+ .join("");
1101
+ const profile = `export PATH=${shellQuote(managedPath)}\n${clearEmptyGitIdentity}`;
1102
+ const files = Object.fromEntries([
1103
+ // Remote launchers live beneath the checkout. Pin their own package scope
1104
+ // so an enclosing project's "type": "module" cannot reinterpret require().
1105
+ ["package.json", '{"type":"commonjs"}\n'],
1106
+ ...["git", "gh"].map((name) => [name, githubLauncherSource()]),
1107
+ ...[".zshenv", ".zprofile", ".zshrc", ".bash_profile", ".bashrc", ".profile"].map((name) => [name, profile]),
1108
+ ]);
1109
+ if (remote) {
1110
+ const runner = adapterExecutionTargetCommandRunner(remote);
1111
+ for (const [program, body] of Object.entries(files)) {
1112
+ await syncRemoteTextFileWithHashSkip({
1113
+ runner, remoteCwd: remote.remoteCwd, remoteDir: directory,
1114
+ remotePath: path.posix.join(directory, program), body,
1115
+ label: "GitHub operation launcher", action: "stage GitHub operation launcher",
1116
+ lockDir: path.posix.join(directory, `.${program}.lock`),
1117
+ timeoutMs: 15_000, shellCommand: adapterExecutionTargetShellCommand(remote),
1118
+ });
1119
+ }
1120
+ const permissions = await runner.execute({ command: "sh", args: ["-c", `chmod 700 ${shellQuote(directory)}/git ${shellQuote(directory)}/gh && mkdir -p ${shellQuote(configDirectory)}`], cwd: remote.remoteCwd, timeoutMs: 15_000 });
1121
+ if (permissions.exitCode !== 0)
1122
+ throw new Error("Could not prepare managed GitHub launchers");
1123
+ }
1124
+ else {
1125
+ await fs.mkdir(directory, { recursive: true, mode: 0o700 });
1126
+ await fs.mkdir(configDirectory, { recursive: true, mode: 0o700 });
1127
+ for (const [program, body] of Object.entries(files))
1128
+ await fs.writeFile(path.join(directory, program), body, { mode: 0o700 });
1129
+ }
1130
+ return { ...input.env, PATH: managedPath, ZDOTDIR: directory, BASH_ENV: `${directory}/.bashrc`,
1131
+ GH_CONFIG_DIR: configDirectory, PAPERCLIP_GITHUB_LAUNCHER_DIR: directory };
1132
+ }
1133
+ function buildBridgeResponseHeaders(response) {
1134
+ const out = {};
1135
+ // Keep `x-paperclip-bridge-outcome` in this list. The host marks a
1136
+ // possibly-committed mutation with the `indeterminate` outcome. The in-sandbox
1137
+ // server reads that header to map the 504 to a terminal 409. If the forward
1138
+ // drops the header, the server keeps the retryable 504 and a caller that
1139
+ // retries 5xx can repeat a mutation that already committed.
1140
+ for (const key of ["content-type", "etag", "last-modified", "x-paperclip-bridge-outcome"]) {
1141
+ const value = response.headers.get(key);
1142
+ if (value && value.trim().length > 0)
1143
+ out[key] = value.trim();
1144
+ }
1145
+ return out;
1146
+ }
1147
+ function buildBridgeForwardUrl(baseUrl, request) {
1148
+ const url = new URL(request.path, baseUrl);
1149
+ const query = request.query.trim();
1150
+ url.search = query.startsWith("?") ? query.slice(1) : query;
1151
+ return url;
1152
+ }
1153
+ function bridgeResponseBodyLimitError(maxBodyBytes) {
1154
+ return new Error(`Bridge response body exceeded the configured size limit of ${maxBodyBytes} bytes.`);
1155
+ }
1156
+ /**
1157
+ * Read the forward response body into a `Buffer`, with no text decoding. The
1158
+ * per-request `maxBodyBytes` limit rejects a body larger than the configured
1159
+ * per-request ceiling.
1160
+ *
1161
+ * When the caller passes a `reservation`, this reserves each chunk's bytes
1162
+ * against it immediately after `reader.read()` yields the chunk, and before
1163
+ * `Buffer.from(value)` copies it — the allocation happens inside that
1164
+ * expression, so reserving only before the later `chunks.push` would let the
1165
+ * copy happen first. It also reserves the concatenated buffer's own byte
1166
+ * count before `Buffer.concat` allocates it: the chunk array and the
1167
+ * concatenated buffer are two separate live copies. A denied reservation
1168
+ * cancels the reader and throws {@link BridgeProcessCapacityError}, copying
1169
+ * no further chunk. This function never releases the reservation; the
1170
+ * stream owner that created it does, once the whole forward call settles.
1171
+ *
1172
+ * With no `reservation`, this function enforces only the one request's own
1173
+ * ceiling, exactly as it did before this parameter existed — the queue
1174
+ * transport calls it with no reservation, and its behavior must not change.
1175
+ */
1176
+ async function readBridgeForwardResponseBody(response, maxBodyBytes, reservation) {
1177
+ const rawContentLength = response.headers.get("content-length");
1178
+ if (rawContentLength) {
1179
+ const contentLength = Number.parseInt(rawContentLength, 10);
1180
+ if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) {
1181
+ throw bridgeResponseBodyLimitError(maxBodyBytes);
1182
+ }
1183
+ }
1184
+ if (!response.body) {
1185
+ return Buffer.alloc(0);
1186
+ }
1187
+ const reader = response.body.getReader();
1188
+ const chunks = [];
1189
+ let totalBytes = 0;
1190
+ while (true) {
1191
+ const { done, value } = await reader.read();
1192
+ if (done)
1193
+ break;
1194
+ if (!value)
1195
+ continue;
1196
+ const chunkBytes = value.byteLength;
1197
+ totalBytes += chunkBytes;
1198
+ if (totalBytes > maxBodyBytes) {
1199
+ await reader.cancel().catch(() => undefined);
1200
+ throw bridgeResponseBodyLimitError(maxBodyBytes);
1201
+ }
1202
+ if (reservation && !reservation.reserve(chunkBytes)) {
1203
+ await reader.cancel().catch(() => undefined);
1204
+ throw new BridgeProcessCapacityError();
1205
+ }
1206
+ chunks.push(Buffer.from(value));
1207
+ }
1208
+ if (reservation && !reservation.reserve(totalBytes)) {
1209
+ await reader.cancel().catch(() => undefined);
1210
+ throw new BridgeProcessCapacityError();
1211
+ }
1212
+ return Buffer.concat(chunks, totalBytes);
1213
+ }
1214
+ const PROCESS_SESSION_PROXY_SCRIPT = "paperclip-process-session-proxy.mjs";
1215
+ const PROCESS_SESSION_REMOTE_SCRIPT = "paperclip-process-session-remote.mjs";
1216
+ // The streamed variant writes its output frames to stdout, so it rides a
1217
+ // separate remote path. A sandbox can hold both scripts without the content
1218
+ // hash-skip gate thrashing when a run switches output mode.
1219
+ const PROCESS_SESSION_REMOTE_STREAM_SCRIPT = "paperclip-process-session-remote-stream.mjs";
1220
+ const PROCESS_SESSION_AUTH_TIMEOUT_MS = 5_000;
1221
+ // The bounded budget `stop()` waits for the wrapper's `shutdownAck` event
1222
+ // before it removes `sessionDir` unconditionally. The wrapper writes the
1223
+ // acknowledgement right after it arms its own kill timer, well before its
1224
+ // child actually exits, so this budget only needs to cover message delivery,
1225
+ // not the child's full shutdown.
1226
+ const DEFAULT_PROCESS_SESSION_SHUTDOWN_WAIT_MS = 3_000;
1227
+ function jsonLine(value) {
1228
+ return `${JSON.stringify(value)}\n`;
1229
+ }
1230
+ function splitJsonLines(buffer) {
1231
+ const parts = buffer.split(/\n/);
1232
+ return { lines: parts.slice(0, -1), rest: parts.at(-1) ?? "" };
1233
+ }
1234
+ async function writeProcessSessionProxyScript(dir, port, token) {
1235
+ await fs.mkdir(dir, { recursive: true });
1236
+ const proxyPath = path.join(dir, PROCESS_SESSION_PROXY_SCRIPT);
1237
+ await fs.writeFile(proxyPath, getProcessSessionProxySource({ port, token }), { mode: 0o700 });
1238
+ return proxyPath;
1239
+ }
1240
+ // Content-hash-skip the process-session remote script write, mirroring the
1241
+ // sandbox callback bridge entrypoint sha256 gate. The script is a static
1242
+ // Paperclip-authored `.mjs` that only changes when the build changes, so on a
1243
+ // warm start (same sandbox, script already present) the single sha-gate exec
1244
+ // skips the ~3-exec base64 upload entirely. `syncRemoteTextFileWithHashSkip`
1245
+ // fails loud on a check error rather than silently re-uploading.
1246
+ async function syncProcessSessionRemoteScript(input) {
1247
+ const { uploaded } = await syncRemoteTextFileWithHashSkip({
1248
+ runner: input.runner,
1249
+ remoteCwd: input.remoteCwd,
1250
+ remoteDir: input.remoteScriptDir,
1251
+ remotePath: input.remoteScriptPath,
1252
+ body: getProcessSessionRemoteSource({ outputToStdout: input.outputToStdout === true }),
1253
+ label: "Process session remote script",
1254
+ action: "sync process session remote script",
1255
+ lockDir: path.posix.join(input.remoteScriptDir, ".paperclip-process-session-script.lock"),
1256
+ timeoutMs: input.timeoutMs,
1257
+ shellCommand: input.shellCommand,
1258
+ });
1259
+ return { uploaded };
1260
+ }
1261
+ async function readRemoteJsonFiles(input) {
1262
+ const names = await input.client.listJsonFiles(input.dir);
1263
+ const out = [];
1264
+ for (const name of names) {
1265
+ const filePath = path.posix.join(input.dir, name);
1266
+ const body = await input.client.readTextFile(filePath);
1267
+ await input.client.remove(filePath).catch(() => undefined);
1268
+ out.push({ name, body });
1269
+ }
1270
+ return out;
1271
+ }
1272
+ async function waitForLocalServerListen(server) {
1273
+ await new Promise((resolve, reject) => {
1274
+ server.once("error", reject);
1275
+ server.listen(0, "127.0.0.1", () => {
1276
+ server.off("error", reject);
1277
+ resolve();
1278
+ });
1279
+ });
1280
+ const address = server.address();
1281
+ if (!address || typeof address === "string") {
1282
+ throw new Error("Process session bridge did not expose a TCP port.");
1283
+ }
1284
+ return address.port;
1285
+ }
1286
+ /** Span name that wraps the socket handler's one `writeTextFile` exec — one
1287
+ * outbound ACP message to the agent. */
1288
+ const AGENT_SESSION_SEND_INPUT_SPAN = "sandbox.agentSession.sendInput";
1289
+ /** Span name that wraps one 100 ms poll tick — `list`, then `read`+`remove` per
1290
+ * file found (`1 + 2n` execs). */
1291
+ const AGENT_SESSION_POLL_OUTPUT_SPAN = "sandbox.agentSession.pollOutput";
1292
+ export async function startAdapterExecutionTargetProcessSessionBridge(input) {
1293
+ if (!input.target || input.target.kind !== "remote" || input.target.transport !== "sandbox") {
1294
+ return null;
1295
+ }
1296
+ const target = input.target;
1297
+ const onLog = input.onLog ?? (async () => { });
1298
+ // Failure diagnostics are best effort: stalled or failed run-log persistence
1299
+ // must not prevent sending shutdown or removing the bridge's session files.
1300
+ const logFailureWithoutWaiting = (message) => {
1301
+ void Promise.resolve().then(() => onLog("stderr", message)).catch(() => undefined);
1302
+ };
1303
+ const runner = requireSandboxRunner(target);
1304
+ // Run one unit of run-time work under its named wrapper span when a span
1305
+ // runner is injected. Without a runner, run the work under the current run
1306
+ // parent, so the inner `sandbox.exec` spans parent to the live run span,
1307
+ // exactly like the earlier behavior.
1308
+ const runRuntimeWork = (name, work) => input.runtimeSpan
1309
+ ? input.runtimeSpan(name, work)
1310
+ : runWithRuntimeParent(input.getRuntimeParentContext?.(), work);
1311
+ const shellCommand = preferredSandboxShell(target);
1312
+ const timeoutMs = typeof input.timeoutSec === "number" && Number.isFinite(input.timeoutSec) && input.timeoutSec > 0
1313
+ ? Math.trunc(input.timeoutSec * 1000)
1314
+ : target.timeoutMs ?? undefined;
1315
+ const bridgeRuntimeDir = path.posix.join(input.runtimeRootDir?.trim() || path.posix.join(target.remoteCwd, ".paperclip-runtime", input.adapterKey), "process-sessions");
1316
+ const sessionId = randomUUID();
1317
+ const sessionDir = path.posix.join(bridgeRuntimeDir, sessionId);
1318
+ const stdinDir = path.posix.join(sessionDir, "stdin");
1319
+ const eventsDir = path.posix.join(sessionDir, "events");
1320
+ // The streamed wrapper writes its frames to stdout and rides a separate remote
1321
+ // path, so a warm sandbox can hold both wrapper scripts without the content
1322
+ // hash-skip gate thrashing when a run switches output mode.
1323
+ const streamOutput = input.streamOutputViaSession === true;
1324
+ const remoteScriptPath = path.posix.join(bridgeRuntimeDir, streamOutput ? PROCESS_SESSION_REMOTE_STREAM_SCRIPT : PROCESS_SESSION_REMOTE_SCRIPT);
1325
+ const client = createCommandManagedSandboxCallbackBridgeQueueClient({
1326
+ runner,
1327
+ remoteCwd: target.remoteCwd,
1328
+ timeoutMs,
1329
+ shellCommand,
1330
+ });
1331
+ // The launch exec below re-creates stdinDir and eventsDir with one `mkdir -p`,
1332
+ // and the remote script also creates them on start. No reader touches the two
1333
+ // directories before the launch exec runs, so upfront makeDir execs are redundant.
1334
+ await syncProcessSessionRemoteScript({
1335
+ runner,
1336
+ remoteCwd: target.remoteCwd,
1337
+ remoteScriptDir: bridgeRuntimeDir,
1338
+ remoteScriptPath,
1339
+ timeoutMs,
1340
+ shellCommand,
1341
+ outputToStdout: streamOutput,
1342
+ });
1343
+ // Resolve the launch env AFTER the env-independent setup above, so a caller
1344
+ // can defer it until an upstream dependency (e.g. the paperclip bridge's env)
1345
+ // is ready without blocking the dir/script setup.
1346
+ const launchEnv = typeof input.env === "function" ? await input.env() : input.env;
1347
+ const commandPayload = Buffer.from(JSON.stringify({
1348
+ command: input.command,
1349
+ args: input.args,
1350
+ cwd: input.cwd || target.remoteCwd,
1351
+ // The ACP engine has already projected this launch env from explicit
1352
+ // adapter/runtime inputs and registered contributions. Compare against an
1353
+ // empty inherited baseline so an explicit identity value (notably PATH)
1354
+ // is not reclassified as ambient merely because it equals the host value.
1355
+ env: sanitizeRemoteExecutionEnv(launchEnv, {}),
1356
+ }), "utf8").toString("base64");
1357
+ // Base64 plus JSON escaping can push an otherwise valid child environment
1358
+ // past Linux's per-argument/per-variable exec limit. Keep small launches on
1359
+ // the existing path; upload larger envelopes in bounded chunks instead.
1360
+ const commandEnv = {};
1361
+ if (commandPayload.length <= 64 * 1024) {
1362
+ commandEnv.PAPERCLIP_PROCESS_SESSION_COMMAND_B64 = commandPayload;
1363
+ }
1364
+ else {
1365
+ const payloadPath = path.posix.join(sessionDir, "command.b64");
1366
+ const runPayloadSetup = async (script) => {
1367
+ const result = await runSandboxBridgeControlCommand(runner, {
1368
+ command: shellCommand,
1369
+ args: shellCommandArgs(script),
1370
+ cwd: target.remoteCwd,
1371
+ timeoutMs,
1372
+ bypassSession: true,
1373
+ });
1374
+ if (result.timedOut || result.exitCode !== 0) {
1375
+ throw new Error("Failed to stage sandbox process session command payload.");
1376
+ }
1377
+ };
1378
+ try {
1379
+ // The envelope can contain credentials. Its upload intermediates stay
1380
+ // inside a private session directory, and the wrapper deletes it before
1381
+ // spawning the child. Teardown removes it if the wrapper cannot start.
1382
+ await runPayloadSetup(`umask 077 && mkdir -m 700 ${shellQuote(sessionDir)}`);
1383
+ await client.writeTextFile(payloadPath, commandPayload);
1384
+ await runPayloadSetup(`chmod 600 ${shellQuote(payloadPath)}`);
1385
+ }
1386
+ catch (error) {
1387
+ await client.remove(sessionDir).catch(() => undefined);
1388
+ throw error;
1389
+ }
1390
+ }
1391
+ // Legacy poll path: background the wrapper with `nohup` and read its output
1392
+ // event files with the host poll below. The streamed path launches the wrapper
1393
+ // as one foreground session command further down instead, so skip this.
1394
+ if (!streamOutput) {
1395
+ await onLog("stdout", `[paperclip] Starting ACP process session bridge in sandbox (${target.providerKey ?? "provider"}).\n`);
1396
+ const startResult = await runSandboxBridgeControlCommand(runner, {
1397
+ command: shellCommand,
1398
+ args: shellCommandArgs([
1399
+ `mkdir -p ${shellQuote(stdinDir)} ${shellQuote(eventsDir)}`,
1400
+ // I3: no numeric process identifier anywhere. Background the
1401
+ // wrapper and let it go; do not capture `$!`.
1402
+ `PAPERCLIP_PROCESS_SESSION_DIR=${shellQuote(sessionDir)} ` +
1403
+ Object.entries(commandEnv).map(([key, value]) => `${key}=${shellQuote(value)} `).join("") +
1404
+ `nohup node ${shellQuote(remoteScriptPath)} >/dev/null 2>&1 < /dev/null &`,
1405
+ ].join("\n")),
1406
+ cwd: target.remoteCwd,
1407
+ env: {
1408
+ PAPERCLIP_SANDBOX_EXEC_CHANNEL: "bridge",
1409
+ },
1410
+ timeoutMs,
1411
+ // The wrapper launch is bridge plumbing. Keep it off the persistent
1412
+ // session so it never queues behind an in-run session command.
1413
+ bypassSession: true,
1414
+ }).catch(async (error) => {
1415
+ await client.remove(sessionDir).catch(() => undefined);
1416
+ throw error;
1417
+ });
1418
+ if (startResult.timedOut || (startResult.exitCode ?? 1) !== 0) {
1419
+ await client.remove(sessionDir).catch(() => undefined);
1420
+ throw new Error(`Failed to start sandbox ACP process session bridge: ${startResult.stderr || startResult.stdout}`);
1421
+ }
1422
+ }
1423
+ let socket = null;
1424
+ let stopping = false;
1425
+ // Resolves when `stop()` tears the bridge down. The streamed `sandbox.agentProcess`
1426
+ // span races its work against this, so the span ends at teardown at the latest
1427
+ // even when the remote process lingers, and never outlives the run root span.
1428
+ let signalStopped = () => { };
1429
+ const stopped = new Promise((resolve) => {
1430
+ signalStopped = resolve;
1431
+ });
1432
+ let stdinSeq = 0;
1433
+ // One promise chain per session that serializes the stdin file writes. Each
1434
+ // write is multi-exec on the command-managed client: prepare, append per 32
1435
+ // KiB, then an atomic rename. The chain makes the rename for file N finish
1436
+ // before the write for file N+1 starts, so the files land in send order.
1437
+ // Without it the writes overlap. A small later chunk can then rename ahead of
1438
+ // a big earlier chunk, so the wrapper reads the stdin bytes out of order and
1439
+ // corrupts a large prompt on the stdin path.
1440
+ let stdinWriteChain = Promise.resolve();
1441
+ let stdinDeliveryFailed = false;
1442
+ const writeStdinFile = async (filePath, body) => {
1443
+ // Retry the same sequence, never the ACP request or the tool itself. Each
1444
+ // upload uses private temporary paths, and the wrapper drops sequences it
1445
+ // already consumed when a provider loses the final rename's response.
1446
+ for (let attempt = 1;; attempt += 1) {
1447
+ try {
1448
+ await client.writeTextFile(filePath, body);
1449
+ return;
1450
+ }
1451
+ catch (error) {
1452
+ // Plugin RPC preserves provider messages but not HTTP error classes.
1453
+ // Match the Daytona SDK and Cloudflare bridge's gateway diagnostics
1454
+ // exactly; shell failures and auth errors must still fail immediately.
1455
+ const gatewayFailure = error instanceof Error && (/^Request failed with status code (502|503|504)$/.test(error.message) ||
1456
+ /^Cloudflare sandbox bridge request failed with HTTP (502|503|504)\.$/.test(error.message));
1457
+ if (!gatewayFailure || attempt >= 3)
1458
+ throw error;
1459
+ await new Promise((resolve) => setTimeout(resolve, attempt * 250));
1460
+ }
1461
+ }
1462
+ };
1463
+ let pollTimer = null;
1464
+ let terminalEvidenceRecorded = false;
1465
+ const recordTerminalEvidence = (source, event) => {
1466
+ if (terminalEvidenceRecorded)
1467
+ return;
1468
+ terminalEvidenceRecorded = true;
1469
+ // Remote frames are untrusted. Keep the retained diagnostic bounded and
1470
+ // independent of messages, commands, paths, payloads, and provider errors.
1471
+ const outcome = event.type === "exit" ? "exit" : "error";
1472
+ const code = typeof event.code === "number" && Number.isInteger(event.code)
1473
+ && event.code >= 0 && event.code <= 255 ? event.code : "unknown";
1474
+ const signal = typeof event.signal === "string" && [
1475
+ "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGABRT", "SIGFPE", "SIGKILL",
1476
+ "SIGSEGV", "SIGPIPE", "SIGALRM", "SIGTERM", "SIGBUS", "SIGXCPU", "SIGXFSZ",
1477
+ ].includes(event.signal) ? event.signal : "unknown";
1478
+ logFailureWithoutWaiting(`[paperclip] ACP process session terminal: source=${source} outcome=${outcome} exitCode=${code} signal=${signal}.\n`);
1479
+ };
1480
+ const pendingRemoteEvents = [];
1481
+ const token = createSandboxCallbackBridgeToken(18);
1482
+ const proxyDir = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-process-session-proxy-"));
1483
+ // `stop()` waits on this promise, bounded, for the wrapper's `shutdownAck`
1484
+ // event. `deliverRemoteEvent` resolves it below and never forwards the
1485
+ // event further: it is a host-internal control ack, not part of the ACP
1486
+ // output stream. An event under `sessionDir` is untrusted telemetry: an
1487
+ // `exit` or `error` event is never treated as proof of shutdown, because
1488
+ // any process running under the sandbox can write one. Only `shutdownAck`
1489
+ // counts, and `stop()` also gives itself a dedicated reader for it below,
1490
+ // so a late `shutdownAck` still lands even after the long-lived poll has
1491
+ // stopped re-arming.
1492
+ let signalShutdownAcknowledged = () => { };
1493
+ const shutdownAcknowledged = new Promise((resolve) => {
1494
+ signalShutdownAcknowledged = resolve;
1495
+ });
1496
+ const writeRemoteEventToSocket = (event) => {
1497
+ if (!socket)
1498
+ return false;
1499
+ // `stopping` can already be set by a terminal frame buffered before auth.
1500
+ // Use the socket's outbound state instead: once end() has been called,
1501
+ // another write would destroy it and truncate the frame still draining.
1502
+ // This also covers input-delivery failure, which ends the socket directly.
1503
+ if (socket.writableEnded || socket.destroyed)
1504
+ return true;
1505
+ socket.write(jsonLine(event));
1506
+ if (event.type === "exit" || event.type === "error") {
1507
+ stopping = true;
1508
+ // Flush the terminal frame and all earlier output before closing. An
1509
+ // immediate destroy can discard the cause and leave only connection_close.
1510
+ socket.end();
1511
+ }
1512
+ return true;
1513
+ };
1514
+ const deliverRemoteEvent = (event, source = "remote_event") => {
1515
+ if (event.type === "shutdownAck") {
1516
+ signalShutdownAcknowledged();
1517
+ return;
1518
+ }
1519
+ if (event.type === "exit" || event.type === "error")
1520
+ recordTerminalEvidence(source, event);
1521
+ if (socket) {
1522
+ writeRemoteEventToSocket(event);
1523
+ return;
1524
+ }
1525
+ pendingRemoteEvents.push(event);
1526
+ if (event.type === "exit" || event.type === "error") {
1527
+ stopping = true;
1528
+ }
1529
+ };
1530
+ const flushPendingRemoteEvents = () => {
1531
+ if (!socket)
1532
+ return;
1533
+ while (pendingRemoteEvents.length > 0 && socket) {
1534
+ const event = pendingRemoteEvents.shift();
1535
+ if (event)
1536
+ writeRemoteEventToSocket(event);
1537
+ }
1538
+ };
1539
+ const liveSockets = new Set();
1540
+ // Register the per-connection socket handlers with no run parent context.
1541
+ // A stdin write from a socket handler is a run-time exec, not startup work.
1542
+ // The connection can open under `task.run` and receive stdin later, during an
1543
+ // `agent.turn`. So the handler must read the current-run parent at send time,
1544
+ // not at connect time. A connect-time read captures the parent that was live
1545
+ // when the socket opened, and every later exec span parents to that stale
1546
+ // parent. The `data` handler below reads the getter per message instead.
1547
+ const server = net.createServer((nextSocket) => {
1548
+ liveSockets.add(nextSocket);
1549
+ nextSocket.setEncoding("utf8");
1550
+ nextSocket.on("error", () => undefined);
1551
+ let connectionBuffer = "";
1552
+ let authenticated = false;
1553
+ // Connections own the session (and receive buffered process output) only
1554
+ // after presenting the bridge token; idle unauthenticated peers are dropped.
1555
+ const authTimer = setTimeout(() => {
1556
+ if (!authenticated)
1557
+ nextSocket.destroy();
1558
+ }, PROCESS_SESSION_AUTH_TIMEOUT_MS);
1559
+ authTimer.unref?.();
1560
+ nextSocket.on("close", () => {
1561
+ clearTimeout(authTimer);
1562
+ liveSockets.delete(nextSocket);
1563
+ if (authenticated && !stopping)
1564
+ recordTerminalEvidence("proxy_close", { type: "error" });
1565
+ });
1566
+ nextSocket.on("data", (chunk) => {
1567
+ connectionBuffer += chunk;
1568
+ const split = splitJsonLines(connectionBuffer);
1569
+ connectionBuffer = split.rest;
1570
+ for (const line of split.lines) {
1571
+ if (!line.trim())
1572
+ continue;
1573
+ let message;
1574
+ try {
1575
+ message = JSON.parse(line);
1576
+ }
1577
+ catch {
1578
+ nextSocket.destroy();
1579
+ return;
1580
+ }
1581
+ if (message.token !== token) {
1582
+ nextSocket.destroy();
1583
+ return;
1584
+ }
1585
+ if (!authenticated) {
1586
+ if (socket) {
1587
+ nextSocket.destroy();
1588
+ return;
1589
+ }
1590
+ authenticated = true;
1591
+ clearTimeout(authTimer);
1592
+ socket = nextSocket;
1593
+ flushPendingRemoteEvents();
1594
+ }
1595
+ // Wrap one outbound ACP message to the agent in a
1596
+ // `sandbox.agentSession.sendInput` span, so its one `writeTextFile` exec
1597
+ // groups under one named span. The span runner reads the current-run
1598
+ // parent at send time: the live parent switches to `agent.turn` during
1599
+ // the turn and back to `task.run` after it. A message that is neither
1600
+ // `stdin` nor `stdinEnd` writes nothing, so it opens no span.
1601
+ const stdinPayload = message.type === "stdin" && typeof message.data === "string"
1602
+ ? { type: "stdin", data: message.data }
1603
+ : message.type === "stdinEnd"
1604
+ ? { type: "stdinEnd" }
1605
+ : null;
1606
+ if (stdinPayload) {
1607
+ stdinSeq += 1;
1608
+ const name = `${String(stdinSeq).padStart(12, "0")}.json`;
1609
+ const filePath = path.posix.join(stdinDir, name);
1610
+ // Chain this write after the previous one, so the atomic rename for
1611
+ // file N finishes before the write for file N+1 starts. Keep the
1612
+ // per-message `sandbox.agentSession.sendInput` span inside the chain.
1613
+ stdinWriteChain = stdinWriteChain.then(async () => {
1614
+ if (stdinDeliveryFailed)
1615
+ return;
1616
+ try {
1617
+ await runRuntimeWork(AGENT_SESSION_SEND_INPUT_SPAN, () => writeStdinFile(filePath, jsonLine(stdinPayload)));
1618
+ }
1619
+ catch {
1620
+ stdinDeliveryFailed = true;
1621
+ stopping = true;
1622
+ recordTerminalEvidence("input_delivery", { type: "error" });
1623
+ const message = "ACP process session input delivery failed.";
1624
+ // Flush the diagnostic before closing; destroy() can discard it
1625
+ // and leave only ACP's generic connection_close error. Do not
1626
+ // expose provider error text, which may contain a command payload.
1627
+ // A remote terminal frame may already be draining while this
1628
+ // accepted stdin write fails. end(data) would write after end
1629
+ // and discard that first failure just like socket.write(data).
1630
+ if (!nextSocket.writableEnded && !nextSocket.destroyed) {
1631
+ nextSocket.end(jsonLine({ type: "error", message }));
1632
+ }
1633
+ // stop() awaits this input chain before sending shutdown. Run-log
1634
+ // persistence must not hold teardown open when it stalls or fails.
1635
+ logFailureWithoutWaiting(`[paperclip] ${message}\n`);
1636
+ }
1637
+ });
1638
+ }
1639
+ }
1640
+ });
1641
+ });
1642
+ const poll = async () => {
1643
+ if (stopping)
1644
+ return;
1645
+ try {
1646
+ // Read every file this tick fetched before this loop decides whether to
1647
+ // keep polling. A `shutdownAck` can land in the same batch right after
1648
+ // an `exit` event; deliver it too, so this tick never drops an
1649
+ // already-fetched (and already-removed-from-disk) event.
1650
+ const events = await readRemoteJsonFiles({ client, dir: eventsDir });
1651
+ for (const event of events) {
1652
+ const parsed = JSON.parse(event.body);
1653
+ deliverRemoteEvent(parsed);
1654
+ }
1655
+ }
1656
+ catch (error) {
1657
+ const message = error instanceof Error ? error.message : String(error);
1658
+ // A stuck log sink must not strand the adapter waiting for this failure.
1659
+ deliverRemoteEvent({ type: "error", message }, "output_poll");
1660
+ return;
1661
+ }
1662
+ finally {
1663
+ if (!stopping) {
1664
+ schedulePoll();
1665
+ }
1666
+ }
1667
+ };
1668
+ // Schedule the long-lived poll timer. Wrap each 100 ms poll tick in a
1669
+ // `sandbox.agentSession.pollOutput` span, so the tick's `list` plus per-file
1670
+ // `read`/`remove` execs group under one named span. The poll loop reads remote
1671
+ // event files with run-time execs, not startup work, so the wrapper span and
1672
+ // its child execs parent to the live run span, not to the ended bridge step.
1673
+ // The span runner reads the run parent per tick, because the re-arm timer that
1674
+ // the poll body schedules opens a new tick span: the live parent switches to
1675
+ // `agent.turn` during the turn and back to `task.run` after it.
1676
+ const schedulePoll = () => {
1677
+ pollTimer = setTimeout(() => void runRuntimeWork(AGENT_SESSION_POLL_OUTPUT_SPAN, poll), 100);
1678
+ pollTimer.unref?.();
1679
+ };
1680
+ const port = await waitForLocalServerListen(server);
1681
+ const agentCommand = await writeProcessSessionProxyScript(proxyDir, port, token);
1682
+ if (streamOutput) {
1683
+ // Streamed output path. Run the wrapper as one long-lived session command;
1684
+ // its stdout carries newline-delimited JSON frames that reach the host
1685
+ // through the provider session log stream. Deliver each frame exactly once
1686
+ // by its monotonic `seq`, so a frame that arrives both live and in the final
1687
+ // result is not repeated. There is no host output-file poll here.
1688
+ let streamBuffer = "";
1689
+ let lastSeq = 0;
1690
+ let sawTerminal = false;
1691
+ const deliverFrame = (frame) => {
1692
+ if (typeof frame.seq === "number") {
1693
+ if (frame.seq <= lastSeq)
1694
+ return;
1695
+ lastSeq = frame.seq;
1696
+ }
1697
+ if (frame.type === "exit" || frame.type === "error")
1698
+ sawTerminal = true;
1699
+ deliverRemoteEvent(frame);
1700
+ };
1701
+ const parseFrameLine = (line) => {
1702
+ if (!line.trim())
1703
+ return;
1704
+ let frame;
1705
+ try {
1706
+ frame = JSON.parse(line);
1707
+ }
1708
+ catch {
1709
+ return;
1710
+ }
1711
+ deliverFrame(frame);
1712
+ };
1713
+ // Live delivery: buffer partial lines across stream chunks, deliver each
1714
+ // complete frame line as it arrives.
1715
+ const ingestStreamChunk = (text) => {
1716
+ streamBuffer += text;
1717
+ const split = splitJsonLines(streamBuffer);
1718
+ streamBuffer = split.rest;
1719
+ for (const line of split.lines)
1720
+ parseFrameLine(line);
1721
+ };
1722
+ // Terminal delivery (the defined fallback to the poll): the resolved result
1723
+ // carries the full wrapper stdout even when the live stream degraded to the
1724
+ // provider session-log poll. The text is complete and self-contained, so
1725
+ // re-parse it on its own; the `seq` guard drops every frame the live stream
1726
+ // already delivered. Drop any partial live line — its complete form is in the
1727
+ // full text.
1728
+ const ingestFinalText = (text) => {
1729
+ streamBuffer = "";
1730
+ for (const line of text.split(/\n/))
1731
+ parseFrameLine(line);
1732
+ };
1733
+ await onLog("stdout", `[paperclip] Starting streamed ACP process session bridge in sandbox (${target.providerKey ?? "provider"}).\n`);
1734
+ // Fire the long-lived command; do NOT await it here. `useSession` forces the
1735
+ // persistent session so the provider streams the wrapper stdout back through
1736
+ // `onLog`. On resolve, the terminal re-parse fills any frames the live stream
1737
+ // missed; on reject, deliver one error frame so the local proxy fails loud.
1738
+ //
1739
+ // Wrap the launch in a `sandbox.agentProcess` span. `runRuntimeWork` parents
1740
+ // it to the LIVE RUN root (`task.run` at launch time — no turn has started
1741
+ // yet), not to the ephemeral `bridge.process-session` bring-up step, and it
1742
+ // stays open for the whole process lifetime. The inner `sandbox.exec` nests
1743
+ // under it. Without the wrapper the raw exec's span inherits the ~2.28s
1744
+ // bring-up step as its parent and then dangles ~50s past it, overlapping
1745
+ // `agent.turn` — a child outliving its parent. As a run-scoped span it reads
1746
+ // instead as a resource that OVERLAPS the sibling `agent.turn`, which is the
1747
+ // correct shape (the persistent process hosts the turn; it is not a child of
1748
+ // it, and on multi-turn runs one process spans several turns). `runRuntimeWork`
1749
+ // is voided, not awaited, so bring-up never blocks on the long-lived command,
1750
+ // and it defaults to a no-op parent when no span runner is injected.
1751
+ //
1752
+ // The span is bounded to the bridge lifecycle: it ends when the command
1753
+ // settles OR when `stop()` runs, whichever comes first. `stop()` runs during
1754
+ // run teardown, before the caller ends the `task.run` root span, so the span
1755
+ // never outlives the run root even if the remote process lingers past
1756
+ // teardown (`execute` has no cancel, so a lingering process cannot be forced
1757
+ // to resolve). The command promise keeps running after the span ends so its
1758
+ // frame handlers still deliver; they no-op once `stopping` is set.
1759
+ void runRuntimeWork("sandbox.agentProcess", async () => {
1760
+ const commandSettled = (async () => {
1761
+ try {
1762
+ const result = await runner.execute({
1763
+ command: shellCommand,
1764
+ args: shellCommandArgs(`node ${shellQuote(remoteScriptPath)}`),
1765
+ cwd: target.remoteCwd,
1766
+ env: {
1767
+ PAPERCLIP_PROCESS_SESSION_DIR: sessionDir,
1768
+ ...commandEnv,
1769
+ PAPERCLIP_SANDBOX_EXEC_CHANNEL: "bridge",
1770
+ },
1771
+ timeoutMs,
1772
+ useSession: true,
1773
+ onLog: async (stream, chunk) => {
1774
+ if (stream === "stdout")
1775
+ ingestStreamChunk(chunk);
1776
+ },
1777
+ });
1778
+ ingestFinalText(result.stdout);
1779
+ if (!sawTerminal && !stopping) {
1780
+ // A shell can fail before the wrapper emits any frames. Preserve
1781
+ // that launch diagnostic instead of reporting only its exit code.
1782
+ if (result.stderr)
1783
+ await onLog("stderr", result.stderr);
1784
+ deliverRemoteEvent({
1785
+ type: "exit",
1786
+ code: typeof result.exitCode === "number" ? result.exitCode : null,
1787
+ signal: result.signal,
1788
+ }, "output_stream");
1789
+ }
1790
+ }
1791
+ catch (error) {
1792
+ if (!stopping) {
1793
+ deliverRemoteEvent({
1794
+ type: "error",
1795
+ message: error instanceof Error ? error.message : String(error),
1796
+ }, "output_stream");
1797
+ }
1798
+ }
1799
+ })();
1800
+ await Promise.race([commandSettled, stopped]);
1801
+ });
1802
+ }
1803
+ else {
1804
+ schedulePoll();
1805
+ }
1806
+ // `stop()` cannot rely on the long-lived poll above to observe a late
1807
+ // `shutdownAck`: that poll stops re-arming as soon as it forwards a
1808
+ // terminal `exit`/`error` event, and `stop()` itself sets `stopping` on
1809
+ // its own first line. A normal completion's `shutdownAck` file, written a
1810
+ // moment after `exit`, can then land on disk after nobody reads the events
1811
+ // directory any more. Give `stop()` its own bounded reader that looks only
1812
+ // for `shutdownAck` and ignores every other event type, so the wait below
1813
+ // shortens on the wrapper's own proof of shutdown -- never on an `exit` or
1814
+ // `error` event, which any process running under `sessionDir` can forge.
1815
+ let stopReadingForShutdownAck = false;
1816
+ const readShutdownAckUntil = (deadlineEpochMs) => {
1817
+ if (stopReadingForShutdownAck)
1818
+ return;
1819
+ void (async () => {
1820
+ try {
1821
+ const events = await readRemoteJsonFiles({ client, dir: eventsDir });
1822
+ if (stopReadingForShutdownAck)
1823
+ return;
1824
+ for (const event of events) {
1825
+ try {
1826
+ const parsed = JSON.parse(event.body);
1827
+ if (parsed.type === "shutdownAck") {
1828
+ signalShutdownAcknowledged();
1829
+ return;
1830
+ }
1831
+ }
1832
+ catch {
1833
+ // Not readable JSON yet. It is not a `shutdownAck`; ignore it.
1834
+ }
1835
+ }
1836
+ }
1837
+ catch {
1838
+ // Best-effort: a read failure here is not proof of anything.
1839
+ }
1840
+ if (!stopReadingForShutdownAck && Date.now() < deadlineEpochMs) {
1841
+ const timer = setTimeout(() => readShutdownAckUntil(deadlineEpochMs), 100);
1842
+ timer.unref?.();
1843
+ }
1844
+ })();
1845
+ };
1846
+ return {
1847
+ agentCommand,
1848
+ stop: async () => {
1849
+ stopping = true;
1850
+ // End the `sandbox.agentProcess` span now, before the caller ends the run
1851
+ // root span, even if the remote command has not resolved yet.
1852
+ signalStopped();
1853
+ if (pollTimer)
1854
+ clearTimeout(pollTimer);
1855
+ for (const liveSocket of liveSockets)
1856
+ liveSocket.destroy();
1857
+ await new Promise((resolve) => server.close(() => resolve())).catch(() => undefined);
1858
+ // Wait for every accepted stdin write before `stdinEnd`. The socket handler
1859
+ // fires each chunk write un-awaited through `stdinWriteChain`, so an earlier
1860
+ // chunk can still be pending here. Chain the `stdinEnd` write onto the same
1861
+ // per-session chain, so its file rename never finishes before an earlier
1862
+ // chunk. `stdinSeq` is stable now, because the sockets are destroyed and the
1863
+ // server is closed, so no new message can increment it.
1864
+ const stdinEndPath = path.posix.join(stdinDir, `${String(stdinSeq + 1).padStart(12, "0")}.json`);
1865
+ const stdinEndWrite = stdinWriteChain.then(() => client.writeTextFile(stdinEndPath, jsonLine({ type: "stdinEnd" })));
1866
+ stdinWriteChain = stdinEndWrite.then(() => undefined, () => undefined);
1867
+ await stdinEndWrite.catch(() => undefined);
1868
+ // The `shutdown` control message tells the wrapper to terminate itself
1869
+ // and its own child (I3: no operating-system signal and no process
1870
+ // identifier cross this boundary — only a file-queue message does).
1871
+ // Chain it onto the same per-session write order as `stdinEnd`, so its
1872
+ // file never lands before the earlier one.
1873
+ const shutdownPath = path.posix.join(stdinDir, `${String(stdinSeq + 2).padStart(12, "0")}.json`);
1874
+ const shutdownWrite = stdinWriteChain.then(() => client.writeTextFile(shutdownPath, jsonLine({ type: "shutdown" })));
1875
+ stdinWriteChain = shutdownWrite.then(() => undefined, () => undefined);
1876
+ await shutdownWrite.catch(() => undefined);
1877
+ // Wait a bounded budget for a hint that the wrapper stopped: only the
1878
+ // `shutdownAck` event counts; an `exit` or `error` event is untrusted
1879
+ // telemetry from inside the sandbox and never shortens this wait or
1880
+ // suppresses the warning below. `shutdownAck` itself is ALSO an
1881
+ // untrusted hint, not proof: any process that shares the sandbox can
1882
+ // write the same event under this session's event directory. It can
1883
+ // only shorten this wait and suppress the warning below; it never
1884
+ // gates, shortens, or replaces the unconditional removal further down.
1885
+ // What actually makes the wrapper's own termination deterministic is
1886
+ // the wrapper-side session-identity latch, not this event.
1887
+ let acknowledgedInTime = false;
1888
+ readShutdownAckUntil(Date.now() + DEFAULT_PROCESS_SESSION_SHUTDOWN_WAIT_MS);
1889
+ await Promise.race([
1890
+ shutdownAcknowledged.then(() => {
1891
+ acknowledgedInTime = true;
1892
+ }),
1893
+ new Promise((resolve) => {
1894
+ const budgetTimer = setTimeout(resolve, DEFAULT_PROCESS_SESSION_SHUTDOWN_WAIT_MS);
1895
+ budgetTimer.unref?.();
1896
+ }),
1897
+ ]);
1898
+ stopReadingForShutdownAck = true;
1899
+ if (!acknowledgedInTime) {
1900
+ logFailureWithoutWaiting(`[paperclip] ACP process session wrapper did not acknowledge shutdown within ${DEFAULT_PROCESS_SESSION_SHUTDOWN_WAIT_MS}ms; removing the session directory anyway.\n`);
1901
+ }
1902
+ // Unconditional: this removal runs whether or not the wrapper
1903
+ // acknowledged, and whether or not any event (real or forged) arrived
1904
+ // under `sessionDir`. `stop()` runs during run teardown and must stay
1905
+ // non-fatal, so every step above is best-effort and this step never
1906
+ // throws.
1907
+ await client.remove(sessionDir).catch(() => undefined);
1908
+ await fs.rm(proxyDir, { recursive: true, force: true }).catch(() => undefined);
1909
+ },
1910
+ };
1911
+ }
1912
+ function getProcessSessionProxySource(input) {
1913
+ return `#!/usr/bin/env node
1914
+ import net from "node:net";
1915
+
1916
+ const socket = net.createConnection({ host: "127.0.0.1", port: ${input.port} });
1917
+ const token = ${JSON.stringify(input.token)};
1918
+ let buffer = "";
1919
+ let exiting = false;
1920
+
1921
+ function send(message) {
1922
+ if (exiting) return;
1923
+ socket.write(JSON.stringify({ token, ...message }) + "\\n");
1924
+ }
1925
+
1926
+ function finish(code) {
1927
+ if (exiting) return;
1928
+ exiting = true;
1929
+ process.exitCode = code;
1930
+ // ACP keeps stdin open while waiting for a reply. Release that handle when
1931
+ // the remote process stops, but let pending stdout/stderr writes drain.
1932
+ process.stdin.destroy();
1933
+ socket.end();
1934
+ }
1935
+
1936
+ socket.on("connect", () => send({ type: "hello" }));
1937
+ process.stdin.on("data", (chunk) => send({ type: "stdin", data: Buffer.from(chunk).toString("base64") }));
1938
+ process.stdin.on("end", () => send({ type: "stdinEnd" }));
1939
+ process.stdin.resume();
1940
+
1941
+ socket.setEncoding("utf8");
1942
+ socket.on("data", (chunk) => {
1943
+ buffer += chunk;
1944
+ const parts = buffer.split(/\\n/);
1945
+ buffer = parts.pop() || "";
1946
+ for (const line of parts) {
1947
+ if (!line.trim()) continue;
1948
+ const message = JSON.parse(line);
1949
+ if (message.type === "data") {
1950
+ const out = Buffer.from(message.data || "", "base64");
1951
+ (message.stream === "stderr" ? process.stderr : process.stdout).write(out);
1952
+ } else if (message.type === "error") {
1953
+ process.stderr.write(String(message.message || "Process session bridge failed.") + "\\n");
1954
+ finish(1);
1955
+ } else if (message.type === "exit") {
1956
+ finish(typeof message.code === "number" ? message.code : 1);
1957
+ }
1958
+ }
1959
+ });
1960
+ socket.on("close", () => {
1961
+ if (!exiting) process.exit(1);
1962
+ });
1963
+ `;
1964
+ }
1965
+ export function getProcessSessionRemoteSource(input) {
1966
+ return input?.outputToStdout === true
1967
+ ? getProcessSessionRemoteStreamSource()
1968
+ : getProcessSessionRemoteEventFileSource();
1969
+ }
1970
+ // The shared stdin drain. Both wrappers read newline-delimited stdin messages
1971
+ // from the stdin file queue and write them to the child, then end the child
1972
+ // stdin on `stdinEnd`. A write to a closed child stdin only emits an `error`
1973
+ // event, so the wrapper installs a no-op handler at the call site.
1974
+ const PROCESS_SESSION_STDIN_POLL_TAIL = `child.stdin.on("error", () => {});
1975
+
1976
+ // A stdin file can appear before the host finishes the write. An empty read is
1977
+ // the non-atomic-write window; a partial read makes JSON.parse throw. The
1978
+ // poller must not delete a file before it validates the content. So read and
1979
+ // parse each file first, and delete it only after a successful parse. The files
1980
+ // sort in send order. If an earlier file is not readable yet, stop the cycle and
1981
+ // keep the order: a later file (for example stdinEnd) must not run ahead of it.
1982
+ // Retry the earlier file on a later cycle. After the retry limit, drop the file
1983
+ // and write an error event, so a lost message fails loud, and let later files
1984
+ // run.
1985
+ const stdinMaxParseRetries = (() => {
1986
+ const raw = Number.parseInt(process.env.PAPERCLIP_PROCESS_SESSION_STDIN_MAX_RETRIES || "", 10);
1987
+ return Number.isFinite(raw) && raw > 0 ? raw : 100;
1988
+ })();
1989
+ const stdinParseRetries = new Map();
1990
+ // Track the next expected sequence number. The host writes the stdin files in
1991
+ // send order and pads the number to 12 digits, starting at 1. The files sort in
1992
+ // send order. When the smallest present number is greater than expected, an
1993
+ // earlier file has not appeared yet: a missing file, not an unreadable one. Hold
1994
+ // the send order and wait for it, bounded by the same retry budget as the
1995
+ // unreadable-file path. This turns a reordering into a loud error, never silent
1996
+ // corruption.
1997
+ let stdinExpectedSeq = 1;
1998
+ let stdinGapRetries = 0;
1999
+
2000
+ // The bounded grace period between the SIGTERM and the SIGKILL a terminate()
2001
+ // call sends. A test can override it through the environment, so a stubborn
2002
+ // child does not force a slow test.
2003
+ const terminateGraceMs = (() => {
2004
+ const raw = Number.parseInt(process.env.PAPERCLIP_PROCESS_SESSION_TERMINATE_GRACE_MS || "", 10);
2005
+ return Number.isFinite(raw) && raw > 0 ? raw : 3000;
2006
+ })();
2007
+
2008
+ // I2: terminate() is the only function in this wrapper that calls
2009
+ // child.kill(). No child event handler and no sibling callback calls it.
2010
+ // terminate() is idempotent: a second call, or a first call after the child
2011
+ // already exited on its own, does nothing beyond what already ran.
2012
+ async function terminate() {
2013
+ if (terminated) return;
2014
+ terminated = true;
2015
+ shuttingDown = true;
2016
+ stdinClosed = true;
2017
+ child.stdin.end();
2018
+ // A \`false\` return means the child's process handle is already gone (the
2019
+ // child exited before this call ran). ChildProcess#kill() is handle-scoped:
2020
+ // once Node clears the handle at reap, the method call above sends no
2021
+ // signal and never falls back to a stored process identifier (I3). Treat
2022
+ // \`false\` as a no-op and do not retry through a numeric identifier.
2023
+ const sentTerm = child.kill("SIGTERM");
2024
+ if (sentTerm) {
2025
+ killTimer = setTimeout(() => {
2026
+ // Escalate on the same handle only (I2): the grace period expired, so
2027
+ // send SIGKILL through the same child handle, never a numeric
2028
+ // identifier and never a process-group signal.
2029
+ child.kill("SIGKILL");
2030
+ }, terminateGraceMs);
2031
+ killTimer.unref?.();
2032
+ }
2033
+ // This event is an untrusted latency hint, not proof. Any process that can
2034
+ // reach this session's event directory can write the same event type. It
2035
+ // can only shorten the host's shutdown wait and suppress the host's
2036
+ // timeout warning; it is never evidence that this wrapper's lifecycle
2037
+ // completed, and the host's cleanup never depends on it. The identity
2038
+ // latch below is what makes this wrapper's own termination deterministic.
2039
+ await writeEvent({ type: "shutdownAck" });
2040
+ }
2041
+
2042
+ // A sandbox peer can delete sessionDir and stdinDir, then recreate a
2043
+ // directory at the same pathname. A pathname does not prove identity: any
2044
+ // process that shares the sandbox can write it. So this wrapper captures the
2045
+ // OS-level identity of both paths once at startup, before the first poll
2046
+ // cycle, and checks it on every later cycle.
2047
+ //
2048
+ // The identity is the device number, the inode number, AND the inode's own
2049
+ // creation time. The device/inode pair alone is not enough: a filesystem can
2050
+ // reissue the exact inode number a just-removed directory held to the very
2051
+ // next directory created at the same path, with no attacker action needed
2052
+ // beyond the recreate the finding already describes. The creation time does
2053
+ // not have this gap: it is set fresh on every inode allocation, even when the
2054
+ // allocator reissues an old inode number, so a recreated directory always
2055
+ // carries a different creation time. The creation time alone is not enough
2056
+ // either, on a filesystem or kernel too old to report it, so this wrapper
2057
+ // keeps the device/inode pair as a second signal rather than relying on
2058
+ // either alone. Ordinary use of stdinDir (the host writing and this wrapper
2059
+ // deleting individual stdin files) changes that directory's OWN change time,
2060
+ // but never its creation time, so the creation time is safe to latch on
2061
+ // without producing a false positive on every stdin message.
2062
+ //
2063
+ // A filesystem or kernel that cannot report a real creation time does not
2064
+ // always report a value of zero. Node fails in one of two ways, and both are
2065
+ // grounded, not assumed: on Linux, when the statx() call finds no creation
2066
+ // time support, the kernel leaves the field unset and Node reports 0. On a
2067
+ // platform whose stat() call has no creation-time field at all, Node copies
2068
+ // the change time into the creation time instead. A 0 value fails open (any
2069
+ // recreated directory then matches on birthtimeMs alone), and a change-time
2070
+ // copy fails closed but far too often (it would move on every stdin file
2071
+ // this wrapper deletes). captureSessionIdentity() below proves the value is
2072
+ // usable before it trusts it, and fails closed on both known fallbacks.
2073
+ let sessionDirIdentity = null;
2074
+ let stdinDirIdentity = null;
2075
+ // The latch. Once set, it never clears. This replaces a counter that a
2076
+ // successful read reset to zero: an attacker who recreated the directory
2077
+ // before the counter reached its threshold kept the wrapper polling forever.
2078
+ // A latch has no threshold to race and no reset path.
2079
+ let identityLost = false;
2080
+
2081
+ async function statPathIdentity(candidatePath) {
2082
+ const stats = await fs.lstat(candidatePath);
2083
+ if (stats.isSymbolicLink()) {
2084
+ const error = new Error("Refusing a symbolic link on a process session control path.");
2085
+ error.code = "EPAPERCLIP_SYMLINK";
2086
+ throw error;
2087
+ }
2088
+ if (!stats.isDirectory()) {
2089
+ const error = new Error("A process session control path is not a directory.");
2090
+ error.code = "ENOTDIR";
2091
+ throw error;
2092
+ }
2093
+ return { dev: stats.dev, ino: stats.ino, birthtimeMs: stats.birthtimeMs };
2094
+ }
2095
+
2096
+ function sameIdentity(left, right) {
2097
+ return left.dev === right.dev && left.ino === right.ino && left.birthtimeMs === right.birthtimeMs;
2098
+ }
2099
+
2100
+ async function latchAndTerminate() {
2101
+ if (identityLost) return;
2102
+ identityLost = true;
2103
+ await terminate();
2104
+ }
2105
+
2106
+ let probeSeq = 0;
2107
+
2108
+ // A probe file name that pollStdin() can never read as a stdin message: it
2109
+ // does not end in ".json", so the ".json" filter in pollStdin() skips it if
2110
+ // a poll cycle ever lists the directory during the probe's short window.
2111
+ function nextProbeFileName() {
2112
+ probeSeq += 1;
2113
+ return ".paperclip-birthtime-probe-" + process.pid + "-" + probeSeq;
2114
+ }
2115
+
2116
+ // Proves a directory's reported birthtimeMs is a real creation time, not a
2117
+ // change-time copy. Creating and removing a file inside a directory changes
2118
+ // that directory's OWN change time but never its true creation time, so a
2119
+ // birthtimeMs that moves across the probe is a change-time copy. Returns
2120
+ // null when the value is proven real. Returns a stderr-ready reason string
2121
+ // on any failure (a detected copy, or a probe that cannot run at all, for
2122
+ // example a permission error or a pre-created probe path): either way the
2123
+ // caller must not trust the value.
2124
+ //
2125
+ // The open uses the "wx" flag: exclusive create, fail if the path exists.
2126
+ // A sandbox peer cannot pre-create the probe path as a symbolic link and
2127
+ // have this call follow it, because "wx" fails closed on an existing path
2128
+ // instead of following a link to it.
2129
+ //
2130
+ // Cleanup checks identity, not only ownership of the initial create. This
2131
+ // wrapper reads the probe file's identity, (dev, ino, ctimeMs), off the open
2132
+ // file descriptor itself (fstat), not off the path, so a peer that swaps the
2133
+ // path in the short gap after create cannot poison the identity this
2134
+ // wrapper trusts as its own. Right before removal, this wrapper reads the
2135
+ // path's identity again and removes it only when that identity still
2136
+ // matches. A same-sandbox peer that deletes the probe file and creates its
2137
+ // own entry at the same path in between leaves a different identity behind,
2138
+ // so this wrapper leaves that entry untouched instead of removing it. This
2139
+ // covers a peer's replacement file, a peer's replacement directory, and a
2140
+ // peer's replacement symbolic link alike, because all three change the
2141
+ // identity this wrapper reads back. The identity check includes ctimeMs,
2142
+ // not only (dev, ino): a filesystem can hand this call's freed inode number
2143
+ // straight back out to a peer's very next create at the same path, so
2144
+ // (dev, ino) alone can match a path this call no longer owns; ctimeMs resets
2145
+ // on every create, so a peer's replacement carries a different one even when
2146
+ // the inode number repeats. Node's filesystem API has no call that removes a
2147
+ // path only when its identity still matches an earlier read as one atomic
2148
+ // step, so a gap remains between this wrapper's final identity read and the
2149
+ // removal call itself. A peer that wins this gap can put any entry at the
2150
+ // probe path before the removal call runs. This can include a pre-existing
2151
+ // file the peer renames into place, not only a file the peer creates fresh.
2152
+ // The removal call then removes whatever entry sits at the probe path at
2153
+ // that moment. Two bounds still hold on that removal. The path always
2154
+ // stays under dirPath. If the entry is a symbolic link, the removal call
2155
+ // removes the link itself instead of following it to a different target.
2156
+ // A non-recursive removal call also fails if the entry is a directory.
2157
+ async function birthtimeSurvivesProbe(dirPath) {
2158
+ let before;
2159
+ try {
2160
+ before = (await fs.lstat(dirPath)).birthtimeMs;
2161
+ } catch {
2162
+ return "its reported creation time could not be read";
2163
+ }
2164
+ const probePath = path.posix.join(dirPath, nextProbeFileName());
2165
+ let handle;
2166
+ try {
2167
+ handle = await fs.open(probePath, "wx");
2168
+ } catch {
2169
+ return "its probe file could not be created exclusively (the path may already exist)";
2170
+ }
2171
+ // fstat on the open handle names the exact inode this call just created.
2172
+ // A path-based lstat here instead would be racy against a peer that swaps
2173
+ // the path in the gap between the create above and the stat: fstat has no
2174
+ // such gap, because a file descriptor keeps naming the inode it opened no
2175
+ // matter what a later swap does to the path.
2176
+ let ownedIdentity = null;
2177
+ try {
2178
+ const createdStats = await handle.stat();
2179
+ // ctimeMs guards against inode reuse; see the function comment above.
2180
+ ownedIdentity = { dev: createdStats.dev, ino: createdStats.ino, ctimeMs: createdStats.ctimeMs };
2181
+ } catch {
2182
+ ownedIdentity = null;
2183
+ } finally {
2184
+ await handle.close().catch(() => undefined);
2185
+ }
2186
+ if (!ownedIdentity) {
2187
+ // fstat on this call's own just-opened descriptor failed. This call then
2188
+ // has no verified identity for the probe file it created, so it must not
2189
+ // check or remove that file by path: a peer could already own the entry
2190
+ // at that path, and a path-based removal here could delete the peer's
2191
+ // entry instead of this call's own file. Fail closed right here instead
2192
+ // of falling through to the birthtime comparison below, so a failed
2193
+ // identity read can never let this probe report success.
2194
+ return "its own probe file's identity could not be read from the open file descriptor";
2195
+ }
2196
+ // The one gap the fs API cannot close: this lstat and the removal below
2197
+ // are two separate calls, not one atomic "remove if identity still
2198
+ // matches" step. A peer that wins this narrow gap can put any entry at
2199
+ // the probe path, including a pre-existing file it renames into place,
2200
+ // and the removal call below removes whatever entry is there when it
2201
+ // runs.
2202
+ const currentStats = await fs.lstat(probePath).catch(() => null);
2203
+ const stillOwned =
2204
+ currentStats !== null &&
2205
+ currentStats.dev === ownedIdentity.dev &&
2206
+ currentStats.ino === ownedIdentity.ino &&
2207
+ currentStats.ctimeMs === ownedIdentity.ctimeMs;
2208
+ if (stillOwned) {
2209
+ await fs.rm(probePath, { force: true }).catch(() => undefined);
2210
+ }
2211
+ let after;
2212
+ try {
2213
+ after = (await fs.lstat(dirPath)).birthtimeMs;
2214
+ } catch {
2215
+ return "its reported creation time could not be read";
2216
+ }
2217
+ return before === after ? null : "its reported creation time changed after a probe write";
2218
+ }
2219
+
2220
+ async function refuseUnusableCreationTime(label, dirPath, reason) {
2221
+ process.stderr.write(
2222
+ "Refusing to trust the process session control path " + label + " (" + dirPath + "): " + reason +
2223
+ ". This filesystem or kernel gives no usable creation time. Terminating.\\n",
2224
+ );
2225
+ await latchAndTerminate();
2226
+ }
2227
+
2228
+ // Runs once, before the first poll cycle, and before this wrapper captures
2229
+ // the identities it later checks on every cycle. A failed capture fails
2230
+ // closed: the wrapper has no verified identity to check on later cycles, so
2231
+ // it terminates now instead of polling a control path it never verified.
2232
+ //
2233
+ // This wrapper cannot assume stats.birthtimeMs is a real creation time. Node
2234
+ // can report a change-time copy as a creation time. That value fails closed
2235
+ // far too aggressively (it would move on every stdin file this wrapper
2236
+ // deletes), so this wrapper proves the value is not a copy with a probe before
2237
+ // it trusts it, run once here, before either directory's identity is captured.
2238
+ async function captureSessionIdentity() {
2239
+ try {
2240
+ const sessionProbeFailure = await birthtimeSurvivesProbe(sessionDir);
2241
+ if (sessionProbeFailure) {
2242
+ await refuseUnusableCreationTime("sessionDir", sessionDir, sessionProbeFailure);
2243
+ return;
2244
+ }
2245
+ const stdinProbeFailure = await birthtimeSurvivesProbe(stdinDir);
2246
+ if (stdinProbeFailure) {
2247
+ await refuseUnusableCreationTime("stdinDir", stdinDir, stdinProbeFailure);
2248
+ return;
2249
+ }
2250
+ const session = await statPathIdentity(sessionDir);
2251
+ const stdin = await statPathIdentity(stdinDir);
2252
+ sessionDirIdentity = session;
2253
+ stdinDirIdentity = stdin;
2254
+ } catch (error) {
2255
+ process.stderr.write(
2256
+ "Failed to capture the process session identity: " +
2257
+ (error instanceof Error ? error.message : String(error)) + ". Terminating.\\n",
2258
+ );
2259
+ await latchAndTerminate();
2260
+ }
2261
+ }
2262
+
2263
+ // Runs on every poll cycle, before the wrapper reads stdinDir. Terminate and
2264
+ // latch on any proof the control path is no longer the one this wrapper
2265
+ // captured at startup (a missing path, a path that is no longer a directory,
2266
+ // a symbolic link, or a directory whose identity changed), AND on every
2267
+ // other lstat failure. A permission error is not transient here: a sandbox
2268
+ // peer can deny search permission on the control directory without removing
2269
+ // it, and treating that as transient would leave the wrapper and its child
2270
+ // alive forever. The error code below only picks the stderr message, so an
2271
+ // operator can still tell a removed directory from a permission error; it
2272
+ // never decides whether to latch.
2273
+ //
2274
+ // Contrast readStdinDirNames() right below, whose catch block stays narrow
2275
+ // on purpose: readdir() opens a directory descriptor, so it can fail with a
2276
+ // genuinely transient error under descriptor exhaustion, and latching there
2277
+ // would kill live sessions under load. lstat() opens no descriptor, and this
2278
+ // function already runs before every call to readStdinDirNames(), so a
2279
+ // permission error latches here before readdir() is ever reached.
2280
+ async function verifySessionIdentity() {
2281
+ if (identityLost) return false;
2282
+ try {
2283
+ const session = await statPathIdentity(sessionDir);
2284
+ const stdin = await statPathIdentity(stdinDir);
2285
+ if (!sameIdentity(session, sessionDirIdentity) || !sameIdentity(stdin, stdinDirIdentity)) {
2286
+ await latchAndTerminate();
2287
+ return false;
2288
+ }
2289
+ return true;
2290
+ } catch (error) {
2291
+ const code = error && typeof error === "object" ? error.code : undefined;
2292
+ const reason =
2293
+ code === "ENOENT"
2294
+ ? "the control path no longer exists"
2295
+ : code === "ENOTDIR"
2296
+ ? "the control path is no longer a directory"
2297
+ : code === "EPAPERCLIP_SYMLINK"
2298
+ ? "the control path is now a symbolic link"
2299
+ : "lstat failed" + (code ? " with " + code : "");
2300
+ process.stderr.write("Latching on a lost process session identity: " + reason + ". Terminating.\\n");
2301
+ await latchAndTerminate();
2302
+ return false;
2303
+ }
2304
+ }
2305
+
2306
+ // This catch block stays narrow on purpose: see the comment above
2307
+ // verifySessionIdentity() for why a permission error here is treated as
2308
+ // transient while the same error latches there.
2309
+ async function readStdinDirNames() {
2310
+ if (!(await verifySessionIdentity())) return [];
2311
+ try {
2312
+ return await fs.readdir(stdinDir);
2313
+ } catch (error) {
2314
+ const code = error && typeof error === "object" ? error.code : undefined;
2315
+ if (code === "ENOENT" || code === "ENOTDIR") {
2316
+ await latchAndTerminate();
2317
+ }
2318
+ return [];
2319
+ }
2320
+ }
2321
+
2322
+ async function pollStdin() {
2323
+ while (!shuttingDown) {
2324
+ const entries = (await readStdinDirNames()).filter((name) => name.endsWith(".json")).sort();
2325
+ for (const name of entries) {
2326
+ if (shuttingDown) break;
2327
+ const entrySeq = Number.parseInt(name, 10);
2328
+ const file = path.posix.join(stdinDir, name);
2329
+ // A successful publication can be retried after its provider response
2330
+ // was lost, even after we consumed it. Never send those bytes twice or
2331
+ // move the expected sequence backwards. This also handles late uploads.
2332
+ if (Number.isFinite(entrySeq) && entrySeq < stdinExpectedSeq) {
2333
+ await fs.rm(file, { force: true }).catch(() => undefined);
2334
+ continue;
2335
+ }
2336
+ // Hold the send order when an earlier file has not appeared. Do not consume
2337
+ // this later file: wait for the missing file on a later cycle, bounded by
2338
+ // the retry budget. After the budget, fail loud and advance past the gap,
2339
+ // so the present file can run.
2340
+ if (Number.isFinite(entrySeq) && entrySeq > stdinExpectedSeq) {
2341
+ stdinGapRetries += 1;
2342
+ if (stdinGapRetries < stdinMaxParseRetries) {
2343
+ break;
2344
+ }
2345
+ await writeEvent({
2346
+ type: "error",
2347
+ message:
2348
+ "Advanced past missing stdin files " + stdinExpectedSeq + " to " + (entrySeq - 1) +
2349
+ " after " + stdinMaxParseRetries + " retries.",
2350
+ });
2351
+ stdinGapRetries = 0;
2352
+ stdinExpectedSeq = entrySeq;
2353
+ }
2354
+ let message;
2355
+ try {
2356
+ // Hardening (I3): open with O_NOFOLLOW where the platform defines it,
2357
+ // so a control-path symbolic link swapped in after the directory
2358
+ // check fails the read instead of following it.
2359
+ const readFlag =
2360
+ typeof fsConstants.O_NOFOLLOW === "number" ? fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW : "r";
2361
+ const raw = await fs.readFile(file, { encoding: "utf8", flag: readFlag });
2362
+ // An empty read means the content is not on disk yet. Treat it the same
2363
+ // as a parse failure: keep the file and retry on a later cycle.
2364
+ if (!raw) throw new Error("stdin file is empty");
2365
+ message = JSON.parse(raw);
2366
+ } catch (error) {
2367
+ const retries = (stdinParseRetries.get(name) || 0) + 1;
2368
+ if (retries >= stdinMaxParseRetries) {
2369
+ // The retry limit is reached. Drop the file and write an error event,
2370
+ // so the lost message fails loud. The file is resolved now, so let the
2371
+ // loop go on to the next entry.
2372
+ stdinParseRetries.delete(name);
2373
+ await fs.rm(file, { force: true }).catch(() => undefined);
2374
+ await writeEvent({
2375
+ type: "error",
2376
+ message:
2377
+ "Dropped unreadable stdin file after " + stdinMaxParseRetries + " retries: " + name + ": " +
2378
+ (error instanceof Error ? error.message : String(error)),
2379
+ });
2380
+ // The file is resolved (dropped). Advance the expected number and reset
2381
+ // the gap budget, then let the loop go on to the next entry.
2382
+ if (Number.isFinite(entrySeq)) stdinExpectedSeq = entrySeq + 1;
2383
+ stdinGapRetries = 0;
2384
+ continue;
2385
+ }
2386
+ // The file is not readable yet and is not past the retry limit. Keep it
2387
+ // and stop this cycle to hold the send order. A later file (for example
2388
+ // stdinEnd) must not run before this earlier file. A later cycle reads
2389
+ // from the start again.
2390
+ stdinParseRetries.set(name, retries);
2391
+ break;
2392
+ }
2393
+ // The parse succeeded, so the content is complete. Delete the file first,
2394
+ // then act on the message. A later cycle never re-reads a handled file.
2395
+ stdinParseRetries.delete(name);
2396
+ await fs.rm(file, { force: true }).catch(() => undefined);
2397
+ // The file is handled. Advance the expected number and reset the gap
2398
+ // budget, so the next expected file starts fresh.
2399
+ if (Number.isFinite(entrySeq)) stdinExpectedSeq = entrySeq + 1;
2400
+ stdinGapRetries = 0;
2401
+ if (message.type === "stdin" && typeof message.data === "string") {
2402
+ if (!stdinClosed) child.stdin.write(Buffer.from(message.data, "base64"));
2403
+ } else if (message.type === "stdinEnd") {
2404
+ stdinClosed = true;
2405
+ child.stdin.end();
2406
+ break;
2407
+ } else if (message.type === "shutdown") {
2408
+ await terminate();
2409
+ break;
2410
+ }
2411
+ }
2412
+ if (!shuttingDown) await new Promise((resolve) => setTimeout(resolve, 50));
2413
+ }
2414
+ }
2415
+
2416
+ await captureSessionIdentity();
2417
+
2418
+ void pollStdin().catch((error) => void writeEvent({ type: "error", message: error instanceof Error ? error.message : String(error) }));
2419
+ `;
2420
+ // Shared by both wrappers. Refuse a symlink and remove the private envelope
2421
+ // before creating the child; no launch payload file belongs to the agent.
2422
+ const PROCESS_SESSION_READ_COMMAND = `
2423
+ let config;
2424
+ try {
2425
+ let commandPayload = process.env.PAPERCLIP_PROCESS_SESSION_COMMAND_B64;
2426
+ if (!commandPayload) {
2427
+ const payloadPath = path.posix.join(sessionDir, "command.b64");
2428
+ const handle = await fs.open(payloadPath, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
2429
+ try {
2430
+ commandPayload = await handle.readFile("utf8");
2431
+ } finally {
2432
+ await handle.close();
2433
+ await fs.rm(payloadPath, { force: true });
2434
+ }
2435
+ }
2436
+ config = JSON.parse(Buffer.from(commandPayload, "base64").toString("utf8"));
2437
+ } catch {
2438
+ // No child exists yet. Emit a terminal event on both transports and attest
2439
+ // shutdown, instead of letting a detached polled wrapper fail silently.
2440
+ // Parse errors can quote credential bytes, so use a fixed diagnostic.
2441
+ await writeEvent({ type: "error", message: "Failed to read sandbox process session command payload." });
2442
+ await writeEvent({ type: "shutdownAck" });
2443
+ await new Promise((resolve) => process.stdout.write("", resolve));
2444
+ process.exit(1);
2445
+ }
2446
+ `;
2447
+ // Streamed variant: the wrapper writes each output frame as one newline-
2448
+ // delimited JSON line to its stdout. The host runs this wrapper as one
2449
+ // long-lived session command and reads the frames from the session log stream,
2450
+ // so there is no host output-file poll. Each frame carries a monotonic `seq`,
2451
+ // so the host delivers every frame exactly once whether it arrives live or in
2452
+ // the final result. The wrapper exits when the child closes, so the session
2453
+ // command settles and the session shell (the subshell wrap around it) survives.
2454
+ function getProcessSessionRemoteStreamSource() {
2455
+ return `import { spawn } from "node:child_process";
2456
+ import { promises as fs, constants as fsConstants } from "node:fs";
2457
+ import path from "node:path";
2458
+
2459
+ const sessionDir = process.env.PAPERCLIP_PROCESS_SESSION_DIR;
2460
+ if (!sessionDir) throw new Error("Missing process session bridge env.");
2461
+
2462
+ const stdinDir = path.posix.join(sessionDir, "stdin");
2463
+ let seq = 0;
2464
+ let stdinClosed = false;
2465
+ let shuttingDown = false;
2466
+ let terminated = false;
2467
+ let killTimer = null;
2468
+
2469
+ await fs.mkdir(stdinDir, { recursive: true });
2470
+
2471
+ // One newline-delimited JSON frame per event. Node keeps process.stdout writes
2472
+ // ordered, and the base64 payload holds no newline, so each frame is one line.
2473
+ function writeEvent(event) {
2474
+ seq += 1;
2475
+ process.stdout.write(JSON.stringify({ seq, ...event }) + "\\n");
2476
+ }
2477
+
2478
+ // Hardening (I3): refuse a symbolic link on a control path before this
2479
+ // wrapper reads or writes through it. A symbolic link here could let another
2480
+ // sandbox process redirect the wrapper's file I/O outside the session tree.
2481
+ async function isSymbolicLink(candidatePath) {
2482
+ try {
2483
+ const stats = await fs.lstat(candidatePath);
2484
+ return stats.isSymbolicLink();
2485
+ } catch {
2486
+ return false;
2487
+ }
2488
+ }
2489
+
2490
+ if ((await isSymbolicLink(sessionDir)) || (await isSymbolicLink(stdinDir))) {
2491
+ await writeEvent({ type: "error", message: "Refusing a symbolic link on a process session control path." });
2492
+ process.exitCode = 1;
2493
+ process.exit(1);
2494
+ }
2495
+
2496
+ ${PROCESS_SESSION_READ_COMMAND}
2497
+
2498
+ // Hardening (I3, not containment): the wrapper's own launch env carries the
2499
+ // session dir and the command payload. Scrub both keys before they reach the
2500
+ // spawned child, so the child never inherits a path to its own control files.
2501
+ const childEnv = { ...process.env, ...(config.env || {}) };
2502
+ delete childEnv.PAPERCLIP_PROCESS_SESSION_DIR;
2503
+ delete childEnv.PAPERCLIP_PROCESS_SESSION_COMMAND_B64;
2504
+
2505
+ // I1: exactly one child process per emitted wrapper. Do not add a second
2506
+ // tracked child handle.
2507
+ const child = spawn(config.command, Array.isArray(config.args) ? config.args : [], {
2508
+ cwd: config.cwd || process.cwd(),
2509
+ env: childEnv,
2510
+ stdio: ["pipe", "pipe", "pipe"],
2511
+ });
2512
+
2513
+ child.stdout.on("data", (chunk) => writeEvent({ type: "data", stream: "stdout", data: Buffer.from(chunk).toString("base64") }));
2514
+ child.stderr.on("data", (chunk) => writeEvent({ type: "data", stream: "stderr", data: Buffer.from(chunk).toString("base64") }));
2515
+ child.on("error", (error) => writeEvent({ type: "error", message: error.message }));
2516
+ // "close" (not "exit") so stdout/stderr fully drain before the exit frame.
2517
+ // Queue the exit frame first, then run terminate(), so the exit frame always
2518
+ // lands even when the child closes on its own, with no stdinEnd and no
2519
+ // shutdown message ever received. writeEvent() only queues an asynchronous
2520
+ // write. terminate()'s own synchronous work (ending the child's stdin and
2521
+ // sending SIGTERM) already runs in this same handler by the time the exit
2522
+ // frame becomes readable on disk. terminate() is idempotent and its
2523
+ // child.kill() call here is always a no-op (I2): the child's process handle
2524
+ // is already gone by the time "close" fires. An error frame carries no such
2525
+ // guarantee: child.on("error", ...) below does not call terminate(), and
2526
+ // neither does the poll loop's own error writes, so those fire while the
2527
+ // wrapper and its child are still fully alive.
2528
+ child.on("close", (code, signal) => {
2529
+ writeEvent({ type: "exit", code, signal });
2530
+ process.exitCode = typeof code === "number" ? code : 1;
2531
+ void terminate();
2532
+ });
2533
+
2534
+ ${PROCESS_SESSION_STDIN_POLL_TAIL}`;
2535
+ }
2536
+ function getProcessSessionRemoteEventFileSource() {
2537
+ return `import { spawn } from "node:child_process";
2538
+ import { promises as fs, constants as fsConstants } from "node:fs";
2539
+ import path from "node:path";
2540
+
2541
+ const sessionDir = process.env.PAPERCLIP_PROCESS_SESSION_DIR;
2542
+ if (!sessionDir) throw new Error("Missing process session bridge env.");
2543
+
2544
+ const stdinDir = path.posix.join(sessionDir, "stdin");
2545
+ const eventsDir = path.posix.join(sessionDir, "events");
2546
+ let seq = 0;
2547
+ let stdinClosed = false;
2548
+ let shuttingDown = false;
2549
+ let terminated = false;
2550
+ let killTimer = null;
2551
+
2552
+ await fs.mkdir(stdinDir, { recursive: true });
2553
+ await fs.mkdir(eventsDir, { recursive: true });
2554
+
2555
+ let writeChain = Promise.resolve();
2556
+
2557
+ function writeEvent(event) {
2558
+ seq += 1;
2559
+ const file = path.posix.join(eventsDir, String(seq).padStart(12, "0") + ".json");
2560
+ const write = writeChain.then(async () => {
2561
+ await fs.writeFile(file + ".tmp", JSON.stringify(event) + "\\n", "utf8");
2562
+ await fs.rename(file + ".tmp", file);
2563
+ });
2564
+ writeChain = write.catch(() => undefined);
2565
+ return write;
2566
+ }
2567
+
2568
+ // Hardening (I3): refuse a symbolic link on a control path before this
2569
+ // wrapper reads or writes through it. A symbolic link here could let another
2570
+ // sandbox process redirect the wrapper's file I/O outside the session tree.
2571
+ async function isSymbolicLink(candidatePath) {
2572
+ try {
2573
+ const stats = await fs.lstat(candidatePath);
2574
+ return stats.isSymbolicLink();
2575
+ } catch {
2576
+ return false;
2577
+ }
2578
+ }
2579
+
2580
+ if ((await isSymbolicLink(sessionDir)) || (await isSymbolicLink(stdinDir))) {
2581
+ await writeEvent({ type: "error", message: "Refusing a symbolic link on a process session control path." });
2582
+ process.exitCode = 1;
2583
+ process.exit(1);
2584
+ }
2585
+
2586
+ ${PROCESS_SESSION_READ_COMMAND}
2587
+
2588
+ // Hardening (I3, not containment): the wrapper's own launch env carries the
2589
+ // session dir and the command payload. Scrub both keys before they reach the
2590
+ // spawned child, so the child never inherits a path to its own control files.
2591
+ const childEnv = { ...process.env, ...(config.env || {}) };
2592
+ delete childEnv.PAPERCLIP_PROCESS_SESSION_DIR;
2593
+ delete childEnv.PAPERCLIP_PROCESS_SESSION_COMMAND_B64;
2594
+
2595
+ // I1: exactly one child process per emitted wrapper. Do not add a second
2596
+ // tracked child handle.
2597
+ const child = spawn(config.command, Array.isArray(config.args) ? config.args : [], {
2598
+ cwd: config.cwd || process.cwd(),
2599
+ env: childEnv,
2600
+ stdio: ["pipe", "pipe", "pipe"],
2601
+ });
2602
+
2603
+ child.stdout.on("data", (chunk) => void writeEvent({ type: "data", stream: "stdout", data: Buffer.from(chunk).toString("base64") }));
2604
+ child.stderr.on("data", (chunk) => void writeEvent({ type: "data", stream: "stderr", data: Buffer.from(chunk).toString("base64") }));
2605
+ child.on("error", (error) => void writeEvent({ type: "error", message: error.message }));
2606
+ // "close" (not "exit") so stdout/stderr fully drain before the exit event;
2607
+ // the write chain then guarantees the exit file lands after every data file.
2608
+ // Queue the exit event first, then run terminate(), so the poll loop ends
2609
+ // even when the child closes on its own, with no stdinEnd and no shutdown
2610
+ // message ever received. writeEvent() only queues an asynchronous write.
2611
+ // terminate()'s own synchronous work (ending the child's stdin and sending
2612
+ // SIGTERM) already runs in this same handler by the time the exit file
2613
+ // becomes readable on disk. terminate() is idempotent and its child.kill()
2614
+ // call here is always a no-op (I2): the child's process handle is already
2615
+ // gone by the time "close" fires. An error event carries no such guarantee:
2616
+ // child.on("error", ...) below does not call terminate(), and neither does
2617
+ // the poll loop's own error writes, so those fire while the wrapper and its
2618
+ // child are still fully alive.
2619
+ child.on("close", (code, signal) => {
2620
+ void writeEvent({ type: "exit", code, signal });
2621
+ process.exitCode = typeof code === "number" ? code : 1;
2622
+ void terminate();
2623
+ });
2624
+
2625
+ ${PROCESS_SESSION_STDIN_POLL_TAIL}`;
2626
+ }
2627
+ /** The default deadline for the duplex readiness handshake, in milliseconds. */
2628
+ const DEFAULT_DUPLEX_READINESS_TIMEOUT_MS = 10_000;
2629
+ /** The default bounded budget to close a partial duplex channel, in milliseconds. */
2630
+ const DEFAULT_DUPLEX_CLEANUP_BUDGET_MS = 2_000;
2631
+ /**
2632
+ * Reserve a loopback port the host assigns to the duplex gateway. The host binds
2633
+ * an ephemeral listener on `127.0.0.1`, reads the port the operating system
2634
+ * chose, then closes the listener. The number is very likely free when the
2635
+ * gateway binds it a moment later. The gateway binds exactly this port or exits
2636
+ * nonzero, so a taken port fails closed to the file bridge and never steers the
2637
+ * endpoint.
2638
+ */
2639
+ async function reserveHostAssignedLoopbackPort() {
2640
+ return new Promise((resolve, reject) => {
2641
+ const probe = net.createServer();
2642
+ probe.once("error", reject);
2643
+ probe.listen(0, "127.0.0.1", () => {
2644
+ const address = probe.address();
2645
+ if (!address || typeof address === "string") {
2646
+ probe.close(() => reject(new Error("Could not reserve a loopback port for the duplex gateway.")));
2647
+ return;
2648
+ }
2649
+ const reserved = address.port;
2650
+ probe.close(() => resolve(reserved));
2651
+ });
2652
+ });
2653
+ }
2654
+ /**
2655
+ * Build the argument vector that launches the duplex gateway in the sandbox. The
2656
+ * host passes the assigned port and the per-open nonce only through the launch
2657
+ * environment, so the argument vector sets them as environment assignments in
2658
+ * front of the node command. No addressing data comes from the channel.
2659
+ *
2660
+ * The script uses `exec env NAME=value ... command`. A POSIX shell accepts an
2661
+ * environment-assignment prefix only on a plain command, never on `exec`. The
2662
+ * form `exec NAME=value command` exits with status 127. The `env` utility carries
2663
+ * the assignments, and `exec` still replaces the shell with the gateway process,
2664
+ * so the gateway keeps the process slot and the assigned environment.
2665
+ */
2666
+ export function buildDuplexGatewayLaunchArgv(input) {
2667
+ const assignments = Object.entries(input.env)
2668
+ .map(([key, value]) => `${key}=${shellQuote(value)}`)
2669
+ .join(" ");
2670
+ const nodeCommand = input.nodeCommand?.trim() || "node";
2671
+ const script = `exec env ${assignments} ${shellQuote(nodeCommand)} ${shellQuote(input.remoteEntrypoint)}`;
2672
+ return [input.shellCommand, ...shellCommandArgs(script)];
2673
+ }
2674
+ /**
2675
+ * Map a readiness failure to the fixed fallback reason. Each readiness failure
2676
+ * maps to exactly one reason from the closed telemetry set, so the fallback
2677
+ * counter and the transport event carry only an approved value.
2678
+ */
2679
+ function duplexReadinessFallbackReason(reason) {
2680
+ switch (reason) {
2681
+ case "protocol_contamination":
2682
+ return "contaminated";
2683
+ case "nonce_mismatch":
2684
+ return "ready_nonce_mismatch";
2685
+ case "timeout":
2686
+ return "ready_timeout";
2687
+ case "channel_exit":
2688
+ return "ready_invalid";
2689
+ }
2690
+ }
2691
+ /**
2692
+ * The fixed marker the worker manager puts in a route-busy rejection. The manager
2693
+ * defines the constant; this module matches the fixed string, because the two
2694
+ * layers ship in separate packages and share no import. The marker names the
2695
+ * process-scoped route ceiling, so it carries no route, query, body, or token.
2696
+ */
2697
+ const DUPLEX_ROUTE_BUSY_ERROR_MARKER = "DUPLEX_CHANNEL_ROUTE_BUSY";
2698
+ /**
2699
+ * Report whether the caught open error is a route-busy rejection. The host maps it
2700
+ * to the `route_busy` fallback stage, so a full process-scoped route ceiling never
2701
+ * folds into a generic open failure.
2702
+ */
2703
+ function isDuplexRouteBusyError(error) {
2704
+ return error instanceof Error && error.message.includes(DUPLEX_ROUTE_BUSY_ERROR_MARKER);
2705
+ }
2706
+ /**
2707
+ * The cap on the pre-READY readiness buffer, in bytes. The gate reads untrusted
2708
+ * bytes before the READY line arrives, so it bounds the buffer. The cap is the
2709
+ * codec frame-size bound plus one line of margin, so a legitimate maximum-size
2710
+ * READY frame still fits. Past the cap with no newline, the stream cannot be a
2711
+ * valid READY frame, so the gate finishes with protocol contamination.
2712
+ */
2713
+ const DUPLEX_READINESS_BUFFER_CAP_BYTES = DEFAULT_MAX_DUPLEX_FRAME_BYTES + 4_096;
2714
+ // ---------------------------------------------------------------------------
2715
+ // http2_v1: the client connection preface scan and the run disposition latch.
2716
+ // ---------------------------------------------------------------------------
2717
+ /**
2718
+ * The HTTP/2 client connection preface: 24 octets, `PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n`
2719
+ * (RFC 9113, Section 3.4). A Node `http2.performServerHandshake` call needs a
2720
+ * `Duplex` whose readable side starts at this exact sequence; one extra
2721
+ * leading byte makes the preface invalid, and the server reports a
2722
+ * `PROTOCOL_ERROR`. The server does not skip a leading byte and does not
2723
+ * search for the sequence, so the host finds the offset itself before it
2724
+ * hands the channel to the server.
2725
+ */
2726
+ const HTTP2_CLIENT_CONNECTION_PREFACE = Buffer.from("505249202a20485454502f322e300d0a0d0a534d0d0a0d0a", "hex");
2727
+ /** The one shared empty buffer. The preface scan starts and resets its two
2728
+ * retained buffers to it. */
2729
+ const HTTP2_PREFACE_EMPTY_BUFFER = Buffer.alloc(0);
2730
+ // The count of bytes the preface scan's substring search examines, in bytes.
2731
+ // A search that always starts from the beginning of the retained buffer
2732
+ // re-examines the whole buffer on every fragment, so this count grows
2733
+ // quadratically in the number of fragments. `findPrefaceFrom` instead
2734
+ // resumes from where the prior search left off, so this count stays linear
2735
+ // in the bytes received. A test reads this count to prove the search work
2736
+ // does not regress to the quadratic shape. Production code never reads this
2737
+ // count.
2738
+ let http2PrefaceScanSearchUnits = 0;
2739
+ // The count of bytes the pre-preface scan buffer copies while it grows its
2740
+ // backing storage. A one-copy-per-fragment append copies the whole retained
2741
+ // buffer on every fragment, so this count grows quadratically in the number
2742
+ // of fragments. The doubling-growth approach copies only on a reallocation,
2743
+ // so this count stays linear in the bytes received. A test reads this count
2744
+ // to prove the growth work does not regress to the quadratic shape.
2745
+ // Production code never reads this count.
2746
+ let http2PrefaceScanBufferGrowthCopyUnits = 0;
2747
+ // The same count as `http2PrefaceScanBufferGrowthCopyUnits`, for the
2748
+ // post-preface replay buffer instead of the pre-preface scan buffer.
2749
+ let http2PrefaceReplayBufferGrowthCopyUnits = 0;
2750
+ /**
2751
+ * A byte buffer that grows its backing storage by doubling its capacity,
2752
+ * instead of copying the whole retained buffer on every appended fragment. A
2753
+ * sender that trickles input in many small fragments would otherwise force
2754
+ * one full copy of the whole retained buffer per fragment: with the buffer
2755
+ * growing toward its cap, that is quadratic work in the number of fragments.
2756
+ * Doubling the backing storage's capacity only when the current capacity
2757
+ * runs out reallocates and copies a logarithmic number of times, so the
2758
+ * total copy work stays linear in the bytes received. `countGrowthCopy`
2759
+ * receives the number of bytes each reallocation copies, so a test can add
2760
+ * these up and prove the growth work stays linear.
2761
+ */
2762
+ function createGrowableByteBuffer(countGrowthCopy) {
2763
+ let used = HTTP2_PREFACE_EMPTY_BUFFER;
2764
+ let storage = HTTP2_PREFACE_EMPTY_BUFFER;
2765
+ return {
2766
+ view: () => used,
2767
+ length: () => used.length,
2768
+ append: (chunk) => {
2769
+ const usedLength = used.length;
2770
+ const neededLength = usedLength + chunk.byteLength;
2771
+ if (neededLength > storage.length) {
2772
+ let nextCapacity = storage.length === 0 ? chunk.byteLength : storage.length * 2;
2773
+ while (nextCapacity < neededLength) {
2774
+ nextCapacity *= 2;
2775
+ }
2776
+ const grown = Buffer.allocUnsafe(nextCapacity);
2777
+ storage.copy(grown, 0, 0, usedLength);
2778
+ countGrowthCopy(usedLength);
2779
+ storage = grown;
2780
+ }
2781
+ storage.set(chunk, usedLength);
2782
+ used = storage.subarray(0, neededLength);
2783
+ },
2784
+ reset: () => {
2785
+ used = HTTP2_PREFACE_EMPTY_BUFFER;
2786
+ storage = HTTP2_PREFACE_EMPTY_BUFFER;
2787
+ },
2788
+ };
2789
+ }
2790
+ /**
2791
+ * Find the client connection preface in `buffer` at or after index `from`
2792
+ * and return its offset, or -1. This counts the real scan distance for a
2793
+ * test: from `from` up to the found preface's end, or to the end of the
2794
+ * buffer when it finds none. The count stays linear in the bytes received
2795
+ * when the caller advances `from` to just short of the buffer's end on every
2796
+ * miss, instead of always searching from the start of the buffer.
2797
+ */
2798
+ function findPrefaceFrom(buffer, from) {
2799
+ const offset = buffer.indexOf(HTTP2_CLIENT_CONNECTION_PREFACE, from);
2800
+ const scannedTo = offset === -1 ? buffer.length : offset + HTTP2_CLIENT_CONNECTION_PREFACE.length;
2801
+ http2PrefaceScanSearchUnits += Math.max(scannedTo - from, 0);
2802
+ return offset;
2803
+ }
2804
+ /**
2805
+ * Wrap the readiness gate's broker channel so its `onData` delivers no byte
2806
+ * until the client connection preface appears, then delivers every byte from
2807
+ * the preface onward.
2808
+ *
2809
+ * The wrapped channel opens its scan window only on the bytes the readiness
2810
+ * gate already retained after it accepted the READY line (constraint: the
2811
+ * scan window opens only after the gate accepts the nonce). Nothing before
2812
+ * that line ever reaches this scan, because the gate itself discards the
2813
+ * whole pre-READY buffer on acceptance. The scan buffers at most
2814
+ * {@link DUPLEX_READINESS_BUFFER_CAP_BYTES}; past that bound with no preface
2815
+ * found, it calls `onMissing` exactly one time and stops buffering, so the
2816
+ * caller can abort the open and fall back to `queue_v1`. The function holds
2817
+ * no prologue byte count: it always scans for the fixed 24-octet sequence,
2818
+ * never a length.
2819
+ *
2820
+ * The bytes that follow the found preface, before the HTTP/2 server binds a
2821
+ * downstream listener, land in `pendingAfterPreface`. This buffer holds
2822
+ * untrusted bytes on the same footing as the scan buffer, so it carries the
2823
+ * same {@link DUPLEX_READINESS_BUFFER_CAP_BYTES} cap. A chunk that would pass
2824
+ * the cap fails closed: the function drops the buffer and stops the channel.
2825
+ * The caller reads {@link replayOverflowed} after the preface settles and, on
2826
+ * `true`, treats the open the same as a missing preface.
2827
+ */
2828
+ function createHttp2PrefaceScanningChannel(channel, options) {
2829
+ // The pre-preface scan buffer. `scanBuf.append` grows its backing storage
2830
+ // by doubling, instead of copying the whole retained buffer on every
2831
+ // fragment — see {@link createGrowableByteBuffer}. `scanSearchFrom` is the
2832
+ // first index the next search must examine: `findPrefaceFrom` advances it
2833
+ // to just short of the buffer's end on every miss, so a fragmented preface
2834
+ // is found without a full rescan of the retained buffer on every fragment.
2835
+ const scanBuf = createGrowableByteBuffer((copiedBytes) => {
2836
+ http2PrefaceScanBufferGrowthCopyUnits += copiedBytes;
2837
+ });
2838
+ let scanSearchFrom = 0;
2839
+ let sawPreface = false;
2840
+ let failed = false;
2841
+ let downstream = null;
2842
+ // Bytes found after the preface before a downstream listener attaches. The
2843
+ // wrapped channel replays them on attach, the same pattern the readiness
2844
+ // gate itself uses for its own post-READY replay buffer. This also grows
2845
+ // by doubling, for the same reason as `scanBuf`: fragmented post-preface
2846
+ // input must not force a full copy of the retained buffer per fragment.
2847
+ const pendingAfterPreface = createGrowableByteBuffer((copiedBytes) => {
2848
+ http2PrefaceReplayBufferGrowthCopyUnits += copiedBytes;
2849
+ });
2850
+ let replayOverflow = false;
2851
+ // Drop the pending buffer and stop the channel. The caller reads
2852
+ // `replayOverflowed()` after the preface settles and falls back the same
2853
+ // way it does for a missing preface.
2854
+ function overflowAndStop() {
2855
+ replayOverflow = true;
2856
+ pendingAfterPreface.reset();
2857
+ channel.stop();
2858
+ }
2859
+ function deliver(chunk) {
2860
+ if (downstream) {
2861
+ downstream(chunk);
2862
+ return;
2863
+ }
2864
+ if (replayOverflow)
2865
+ return;
2866
+ if (pendingAfterPreface.length() + chunk.byteLength > options.capBytes) {
2867
+ overflowAndStop();
2868
+ return;
2869
+ }
2870
+ pendingAfterPreface.append(chunk);
2871
+ }
2872
+ channel.onData((chunk) => {
2873
+ if (failed || replayOverflow)
2874
+ return;
2875
+ if (sawPreface) {
2876
+ deliver(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
2877
+ return;
2878
+ }
2879
+ const rawChunk = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
2880
+ // Reject the chunk on its prospective length before it grows the scan
2881
+ // buffer, the same way `deliver` bounds `pendingAfterPreface`. A single
2882
+ // oversized chunk — or a chunk that tips an already-large buffer past
2883
+ // the cap — must fail closed here, before `scanBuf.append` performs the
2884
+ // allocation. Checking the cap only after the append still bounds the
2885
+ // retained buffer, but it lets one untrusted chunk force an allocation
2886
+ // as large as the chunk itself, unbounded by `capBytes`.
2887
+ if (scanBuf.length() + rawChunk.byteLength > options.capBytes) {
2888
+ failed = true;
2889
+ scanBuf.reset();
2890
+ scanSearchFrom = 0;
2891
+ options.onMissing();
2892
+ return;
2893
+ }
2894
+ scanBuf.append(rawChunk);
2895
+ const scanBuffer = scanBuf.view();
2896
+ const offset = findPrefaceFrom(scanBuffer, scanSearchFrom);
2897
+ if (offset === -1) {
2898
+ // No match yet. Resume the next search just short of the buffer's
2899
+ // end, keeping back an overlap of one octet less than the preface
2900
+ // length, so a preface split across this fragment and the next one is
2901
+ // still found. Each byte enters that overlap window a bounded number
2902
+ // of times, so the total search work stays linear in the bytes
2903
+ // received, not quadratic in the number of fragments.
2904
+ scanSearchFrom = Math.max(0, scanBuffer.length - (HTTP2_CLIENT_CONNECTION_PREFACE.length - 1));
2905
+ return;
2906
+ }
2907
+ sawPreface = true;
2908
+ options.onFound();
2909
+ const fromPreface = Buffer.from(scanBuffer.subarray(offset));
2910
+ scanBuf.reset();
2911
+ scanSearchFrom = 0;
2912
+ deliver(fromPreface);
2913
+ });
2914
+ return {
2915
+ channel: {
2916
+ write: (data) => channel.write(data),
2917
+ onData: (listener) => {
2918
+ downstream = listener;
2919
+ if (pendingAfterPreface.length() > 0) {
2920
+ // Copy the exact retained bytes instead of handing the listener
2921
+ // the growable buffer's backing view. That backing storage can
2922
+ // run ahead of the bytes in use (the doubling growth in
2923
+ // `pendingAfterPreface.append` over-provisions it), so a raw view
2924
+ // would keep the whole over-provisioned allocation alive for as
2925
+ // long as the listener holds its reference.
2926
+ const replay = Buffer.from(pendingAfterPreface.view());
2927
+ pendingAfterPreface.reset();
2928
+ listener(replay);
2929
+ }
2930
+ },
2931
+ onExit: (listener) => channel.onExit(listener),
2932
+ stop: () => channel.stop(),
2933
+ close: () => channel.close(),
2934
+ },
2935
+ replayOverflowed: () => replayOverflow,
2936
+ /**
2937
+ * Drop the scan buffer, for a caller-side terminal path this function
2938
+ * itself never reaches — the bound readiness timeout elapsing while the
2939
+ * scan is still searching, with no preface found and no cap refusal of
2940
+ * its own. A call after the preface already matched, or after the cap
2941
+ * already failed the scan closed, is a no-op: both paths already reset
2942
+ * the scan buffer themselves.
2943
+ */
2944
+ disposeScanBuffer: () => {
2945
+ if (sawPreface || failed)
2946
+ return;
2947
+ failed = true;
2948
+ scanBuf.reset();
2949
+ scanSearchFrom = 0;
2950
+ },
2951
+ };
2952
+ }
2953
+ /**
2954
+ * Wait for {@link createHttp2PrefaceScanningChannel} to settle: either the
2955
+ * preface appears, or the scan passes the bound with no match, or the bound
2956
+ * readiness timeout elapses first. Reapplying the readiness timeout here
2957
+ * keeps one configured value for both the READY-line wait and this
2958
+ * immediately-following preface wait; the task adds no new timeout setting.
2959
+ * Returns the scanning channel alongside the settled result, so the caller
2960
+ * binds the HTTP/2 server to it only on a `found` result. On a `found`
2961
+ * result, the caller must still read `replayOverflowed()`: the post-preface
2962
+ * buffer can overflow its cap after the preface settles as `found` and
2963
+ * before the caller binds a downstream listener.
2964
+ */
2965
+ function scanForHttp2ClientPreface(channel, options) {
2966
+ let resolveSettled;
2967
+ let settledOnce = false;
2968
+ const settled = new Promise((resolve) => {
2969
+ resolveSettled = resolve;
2970
+ });
2971
+ // Reassigned to the real function once `createHttp2PrefaceScanningChannel`
2972
+ // returns, below. `settle` can only actually run after that point (the
2973
+ // timer fires later, and `onMissing`/`onFound` fire from inside the
2974
+ // channel's own `onData`, which registers after this call), so the
2975
+ // placeholder never runs for real.
2976
+ let disposeScanBuffer = () => { };
2977
+ const settle = (result) => {
2978
+ if (settledOnce)
2979
+ return;
2980
+ settledOnce = true;
2981
+ clearTimeout(timer);
2982
+ // The bound readiness timeout can elapse while the scan still searches,
2983
+ // with no preface found and no cap refusal of its own. That path holds
2984
+ // no other cleanup, so drop the scan buffer here. A `found` result, or a
2985
+ // `missing` result the scan itself already failed closed, is a no-op
2986
+ // inside `disposeScanBuffer`.
2987
+ if (result === "missing")
2988
+ disposeScanBuffer();
2989
+ resolveSettled(result);
2990
+ };
2991
+ const timer = setTimeout(() => settle("missing"), options.timeoutMs);
2992
+ timer.unref?.();
2993
+ const scan = createHttp2PrefaceScanningChannel(channel, {
2994
+ capBytes: options.capBytes,
2995
+ onFound: () => settle("found"),
2996
+ onMissing: () => settle("missing"),
2997
+ });
2998
+ disposeScanBuffer = scan.disposeScanBuffer;
2999
+ return { scanned: scan.channel, settled, replayOverflowed: scan.replayOverflowed };
3000
+ }
3001
+ /**
3002
+ * Test-only surface for {@link scanForHttp2ClientPreface}. A test drives the
3003
+ * post-preface replay cap across every terminal path without the whole
3004
+ * bridge. Production code never reads this export.
3005
+ */
3006
+ export const __http2PrefaceScanTesting = {
3007
+ scanForHttp2ClientPreface: (channel, options) => scanForHttp2ClientPreface(channel, options),
3008
+ readScanSearchUnits: () => http2PrefaceScanSearchUnits,
3009
+ resetScanSearchUnits: () => {
3010
+ http2PrefaceScanSearchUnits = 0;
3011
+ },
3012
+ readScanBufferGrowthCopyUnits: () => http2PrefaceScanBufferGrowthCopyUnits,
3013
+ resetScanBufferGrowthCopyUnits: () => {
3014
+ http2PrefaceScanBufferGrowthCopyUnits = 0;
3015
+ },
3016
+ readReplayBufferGrowthCopyUnits: () => http2PrefaceReplayBufferGrowthCopyUnits,
3017
+ resetReplayBufferGrowthCopyUnits: () => {
3018
+ http2PrefaceReplayBufferGrowthCopyUnits = 0;
3019
+ },
3020
+ };
3021
+ function createHttp2RunDispositionLatch() {
3022
+ let lossOrdered = false;
3023
+ let lossReason = null;
3024
+ let completionOrdered = false;
3025
+ let lossListener = null;
3026
+ const markOrderlyCompletion = () => {
3027
+ if (completionOrdered || lossOrdered)
3028
+ return;
3029
+ completionOrdered = true;
3030
+ };
3031
+ return {
3032
+ get disposition() {
3033
+ return { failed: lossOrdered, lossReason };
3034
+ },
3035
+ recordLoss(reason) {
3036
+ if (lossOrdered || completionOrdered)
3037
+ return false;
3038
+ lossOrdered = true;
3039
+ lossReason = reason;
3040
+ lossListener?.(reason);
3041
+ return true;
3042
+ },
3043
+ markOrderlyCompletion,
3044
+ settleRunDisposition() {
3045
+ markOrderlyCompletion();
3046
+ return { failed: lossOrdered, lossReason };
3047
+ },
3048
+ onLoss(listener) {
3049
+ lossListener = listener;
3050
+ return () => {
3051
+ if (lossListener === listener)
3052
+ lossListener = null;
3053
+ };
3054
+ },
3055
+ };
3056
+ }
3057
+ /**
3058
+ * Create the run-log directory on the sandbox before the tail starts. The file
3059
+ * bridge worker creates this directory on the file path. The duplex path starts
3060
+ * no worker, so the host creates the directory here. The tail then reads a real
3061
+ * directory from its first tick.
3062
+ *
3063
+ * This step is best effort. The broker already serves the duplex transport when
3064
+ * the host reaches it, and the tail wrap command runs its own `mkdir -p` as a
3065
+ * backstop. So a create failure must not tear down a working duplex transport;
3066
+ * the host swallows it and still builds the tail. The log line names no raw
3067
+ * error, so no raw error rides a log line here.
3068
+ */
3069
+ async function ensureSandboxRunLogDirectory(input) {
3070
+ try {
3071
+ await input.runner.execute({
3072
+ command: input.shellCommand,
3073
+ args: shellCommandArgs(`mkdir -p ${shellQuote(input.logsDir)}`),
3074
+ cwd: input.remoteCwd,
3075
+ timeoutMs: input.timeoutMs ?? undefined,
3076
+ });
3077
+ }
3078
+ catch {
3079
+ // Best effort: the tail wrap command creates the directory before it writes.
3080
+ }
3081
+ }
3082
+ /**
3083
+ * The duplex readiness gate. The gate owns the single data listener and the
3084
+ * single exit listener of the channel while the host waits for a valid READY
3085
+ * frame. It resolves the handshake, then hands the channel to the broker.
3086
+ *
3087
+ * The gate authenticates readiness with the nonce and the strict READY schema,
3088
+ * not with the line position. A PTY channel echoes the launch wrapper line before
3089
+ * it sets raw mode, so the first line is often not the READY frame. The gate skips
3090
+ * each pre-READY line that does not decode as a READY frame, then accepts the first
3091
+ * line that decodes as a READY frame with the matching nonce. A line that decodes
3092
+ * as a READY frame with a wrong nonce fails the handshake with a nonce mismatch. An
3093
+ * early exit or a timeout also fails the handshake. The gate never dispatches a
3094
+ * request; the broker does that after readiness passes.
3095
+ *
3096
+ * The skipped bytes stay in the capped buffer, so the O(1) cap and the readiness
3097
+ * timeout still bound the wait. The gate enforces the cap on every pre-READY path
3098
+ * and before it decodes a candidate line, so an over-cap prefix never reaches READY
3099
+ * acceptance. The cap check has priority over READY acceptance on every path.
3100
+ */
3101
+ // The count of the pre-READY newline-scan work, in bytes. Each search adds the
3102
+ // number of bytes it can read. A test reads this count to prove the scan work
3103
+ // stays linear in the bytes received. Production code never reads this count.
3104
+ let duplexReadinessNewlineScanUnits = 0;
3105
+ // The count of bytes `appendReadinessBytes` copies while it grows the pre-READY
3106
+ // buffer's backing storage. A one-copy-per-fragment approach copies the whole
3107
+ // retained buffer on every fragment, so this count grows quadratically in the
3108
+ // number of fragments. The doubling-growth approach copies only on a
3109
+ // reallocation, so this count stays linear in the bytes received. A test reads
3110
+ // this count to prove the growth work does not regress to the quadratic shape.
3111
+ // Production code never reads this count.
3112
+ let duplexReadinessBufferGrowthCopyUnits = 0;
3113
+ /** The newline byte. The readiness buffer is a byte buffer, not a string. */
3114
+ const READINESS_NEWLINE_BYTE = 0x0a;
3115
+ /** The opening-brace byte. The bracketed-paste retry scans for it, not a string. */
3116
+ const READINESS_OPEN_BRACE_BYTE = 0x7b;
3117
+ /** The one shared empty buffer. The gate starts and resets `buffer` to it. */
3118
+ const READINESS_EMPTY_BUFFER = Buffer.alloc(0);
3119
+ /**
3120
+ * Find the first newline in `buffer` at or after index `from` and return its
3121
+ * index, or -1. `Buffer#indexOf` reads the bytes from `from` up to the newline
3122
+ * it finds, or to the end of the buffer when it finds none. This helper counts
3123
+ * that real scan distance for a test. The count stays linear in the bytes
3124
+ * received when the caller advances `from` past each newline it consumes.
3125
+ */
3126
+ function findNewlineFrom(buffer, from) {
3127
+ const newlineIndex = buffer.indexOf(READINESS_NEWLINE_BYTE, from);
3128
+ const scanned = newlineIndex === -1 ? buffer.length - from : newlineIndex - from + 1;
3129
+ duplexReadinessNewlineScanUnits += scanned;
3130
+ return newlineIndex;
3131
+ }
3132
+ /**
3133
+ * Test-only surface for the pre-READY readiness gate. A test reads the scan
3134
+ * count to prove the newline search work stays linear in the bytes received.
3135
+ * Production code does not use this object.
3136
+ */
3137
+ export const __duplexReadinessTesting = {
3138
+ readNewlineScanUnits: () => duplexReadinessNewlineScanUnits,
3139
+ resetNewlineScanUnits: () => {
3140
+ duplexReadinessNewlineScanUnits = 0;
3141
+ },
3142
+ readBufferGrowthCopyUnits: () => duplexReadinessBufferGrowthCopyUnits,
3143
+ resetBufferGrowthCopyUnits: () => {
3144
+ duplexReadinessBufferGrowthCopyUnits = 0;
3145
+ },
3146
+ // Build one readiness gate over a supplied channel, so a test can drive the
3147
+ // readiness-replay cap lifecycle across every terminal path without the whole
3148
+ // bridge. Production code never reads this factory.
3149
+ createReadinessGate: (channel, options) => createDuplexReadinessGate(channel, options),
3150
+ };
3151
+ function createDuplexReadinessGate(channel, options) {
3152
+ let settled = false;
3153
+ let readyOk = false;
3154
+ // The gate sets this when a post-READY pre-bind chunk tips the pending replay
3155
+ // buffer past the cap. On that overflow the gate drops the pending buffer and
3156
+ // stops the channel. The caller reads it through `replayOverflowed` and selects
3157
+ // the file bridge.
3158
+ let replayOverflow = false;
3159
+ // The raw bytes the host reads before the READY frame completes. `buffer` is
3160
+ // append-only and always a zero-copy view over the used prefix of `storage`,
3161
+ // so the O(1) cap check on `buffer.length` stays valid.
3162
+ let buffer = READINESS_EMPTY_BUFFER;
3163
+ // The backing storage for `buffer`. `appendReadinessBytes` grows this by
3164
+ // doubling its capacity, instead of copying the whole retained buffer on
3165
+ // every fragment. See `appendReadinessBytes` for why this bounds the total
3166
+ // copy work.
3167
+ let storage = READINESS_EMPTY_BUFFER;
3168
+ // The start index of the current line in `buffer`. A leading blank line
3169
+ // advances this cursor past its newline without a buffer copy.
3170
+ let lineStart = 0;
3171
+ // The next index to search for a newline. The gate scans from here, so each
3172
+ // byte is read at most one time for the newline search.
3173
+ let scanFrom = 0;
3174
+ /**
3175
+ * Append `chunk` to the pre-READY buffer without copying the bytes already
3176
+ * retained. A sender that trickles the handshake in many small fragments
3177
+ * (a slow socket, a byte-at-a-time PTY echo) would otherwise force one full
3178
+ * copy of the whole retained buffer per fragment: with `buffer` growing
3179
+ * toward the {@link DUPLEX_READINESS_BUFFER_CAP_BYTES} cap, that is
3180
+ * quadratic work in the number of fragments. This instead grows `storage`
3181
+ * by doubling its capacity only when the current capacity runs out, so the
3182
+ * backing store reallocates and copies a logarithmic number of times, and
3183
+ * each append copies only the incoming chunk. The used length still reads
3184
+ * in O(1) through `buffer.length`, so every cap check and slice below stays
3185
+ * unchanged.
3186
+ */
3187
+ function appendReadinessBytes(chunk) {
3188
+ const usedLength = buffer.length;
3189
+ const neededLength = usedLength + chunk.byteLength;
3190
+ if (neededLength > storage.length) {
3191
+ let nextCapacity = storage.length === 0 ? chunk.byteLength : storage.length * 2;
3192
+ while (nextCapacity < neededLength) {
3193
+ nextCapacity *= 2;
3194
+ }
3195
+ const grown = Buffer.allocUnsafe(nextCapacity);
3196
+ storage.copy(grown, 0, 0, usedLength);
3197
+ duplexReadinessBufferGrowthCopyUnits += usedLength;
3198
+ storage = grown;
3199
+ }
3200
+ storage.set(chunk, usedLength);
3201
+ buffer = storage.subarray(0, neededLength);
3202
+ }
3203
+ // The bytes that followed the READY frame, held until the broker binds.
3204
+ let pending = READINESS_EMPTY_BUFFER;
3205
+ // The exit that arrived after READY but before the broker bound, if any.
3206
+ let pendingExit = null;
3207
+ let dataSink = null;
3208
+ let exitSink = null;
3209
+ let resolveReady;
3210
+ const ready = new Promise((resolve) => {
3211
+ resolveReady = resolve;
3212
+ });
3213
+ const timer = setTimeout(() => finish({ ok: false, reason: "timeout" }), options.timeoutMs);
3214
+ timer.unref?.();
3215
+ function finish(result) {
3216
+ if (settled)
3217
+ return;
3218
+ settled = true;
3219
+ clearTimeout(timer);
3220
+ if (result.ok)
3221
+ readyOk = true;
3222
+ resolveReady(result);
3223
+ }
3224
+ channel.onData((chunk) => {
3225
+ if (dataSink) {
3226
+ dataSink(chunk);
3227
+ return;
3228
+ }
3229
+ if (readyOk) {
3230
+ // READY already passed; hold the bytes until the broker binds. Bound this
3231
+ // buffer directly against {@link DUPLEX_READINESS_BUFFER_CAP_BYTES}, the
3232
+ // same way the preface-scan gate's own post-preface replay buffer bounds
3233
+ // itself: a worker that keeps sending bytes after READY, faster than the
3234
+ // broker can bind, cannot grow this buffer past the cap. A chunk that
3235
+ // would pass the cap fails closed: the gate drops the pending buffer,
3236
+ // stops the channel, and sets the overflow flag. The caller reads the
3237
+ // flag and selects the file bridge, because `ready` already resolved
3238
+ // before this synchronous post-READY chunk arrived.
3239
+ if (pending.length + chunk.byteLength > DUPLEX_READINESS_BUFFER_CAP_BYTES) {
3240
+ replayOverflow = true;
3241
+ pending = READINESS_EMPTY_BUFFER;
3242
+ channel.stop();
3243
+ return;
3244
+ }
3245
+ // Copy a first chunk instead of aliasing the caller's `Uint8Array`, so a
3246
+ // channel that reuses its delivered buffer across calls cannot corrupt the
3247
+ // bytes this gate holds for the broker replay.
3248
+ pending = pending.length === 0 ? Buffer.from(chunk) : Buffer.concat([pending, chunk]);
3249
+ return;
3250
+ }
3251
+ if (settled) {
3252
+ // The handshake already failed. The channel is untrusted and can keep
3253
+ // sending bytes until the host closes it. Drop them, so a failed handshake
3254
+ // never grows the buffer after the gate settles.
3255
+ return;
3256
+ }
3257
+ // Append the new bytes and continue the newline search from `scanFrom`, the
3258
+ // first index not yet examined. Each byte is read at most one time for the
3259
+ // search, and `appendReadinessBytes` copies at most the incoming chunk, so
3260
+ // the total work stays linear in the bytes received, not in the number of
3261
+ // fragments they arrive in.
3262
+ appendReadinessBytes(chunk);
3263
+ for (;;) {
3264
+ const newlineIndex = findNewlineFrom(buffer, scanFrom);
3265
+ if (newlineIndex === -1) {
3266
+ // No complete line yet. The whole buffer up to the end is now scanned.
3267
+ scanFrom = buffer.length;
3268
+ // The gate reads untrusted bytes, so bound the pre-READY buffer. Past
3269
+ // the cap with no complete READY line, the stream cannot be a valid
3270
+ // READY frame, so finish with protocol contamination. The retained
3271
+ // skipped lines count against the cap; that is acceptable and fail-closed.
3272
+ //
3273
+ // `buffer` is a byte buffer, so `buffer.length` is the exact byte count,
3274
+ // read in O(1).
3275
+ if (buffer.length > DUPLEX_READINESS_BUFFER_CAP_BYTES) {
3276
+ finish({ ok: false, reason: "protocol_contamination" });
3277
+ }
3278
+ return;
3279
+ }
3280
+ if (newlineIndex === lineStart) {
3281
+ // Skip a blank line, the same as the frame decoder. Advance the line-start
3282
+ // cursor past the newline without a buffer copy, then search the next line
3283
+ // from the position after the newline. Enforce the cap after the advance,
3284
+ // so a blank-line flood past the cap fails closed before READY acceptance.
3285
+ lineStart = newlineIndex + 1;
3286
+ scanFrom = newlineIndex + 1;
3287
+ if (lineStart > DUPLEX_READINESS_BUFFER_CAP_BYTES) {
3288
+ finish({ ok: false, reason: "protocol_contamination" });
3289
+ return;
3290
+ }
3291
+ continue;
3292
+ }
3293
+ // A complete non-blank candidate line spans `[lineStart, newlineIndex)`.
3294
+ // Enforce the cap on the line's end offset before the decode, so an over-cap
3295
+ // prefix never reaches READY acceptance on a completed line.
3296
+ if (newlineIndex + 1 > DUPLEX_READINESS_BUFFER_CAP_BYTES) {
3297
+ finish({ ok: false, reason: "protocol_contamination" });
3298
+ return;
3299
+ }
3300
+ // Slice only the single candidate line for the decode.
3301
+ const line = buffer.slice(lineStart, newlineIndex);
3302
+ let decoded = decodeDuplexLine(line);
3303
+ if (!decoded.ok) {
3304
+ // The whole line did not decode. A terminal can put bytes in front of the
3305
+ // gateway's first frame on the same line, with no newline between them: a
3306
+ // shell with bracketed paste enabled writes its disable sequence and a
3307
+ // bare carriage return (`ESC [ ? 2 0 0 4 l CR`) immediately before the
3308
+ // child's first output. So retry the decode from the first `{` in the
3309
+ // line, which is where a frame can start.
3310
+ //
3311
+ // This does not weaken the handshake. The retry still runs the same
3312
+ // strict decode over the remainder of the line, and readiness still
3313
+ // authenticates on the nonce below, so a prefix cannot forge a frame or
3314
+ // smuggle a second one — it can only be discarded.
3315
+ const braceIndex = line.indexOf(READINESS_OPEN_BRACE_BYTE);
3316
+ if (braceIndex > 0) {
3317
+ decoded = decodeDuplexLine(line.slice(braceIndex));
3318
+ }
3319
+ }
3320
+ if (decoded.ok && decoded.frame.type === "ready") {
3321
+ // A line that decodes as a READY frame authenticates by the nonce. A wrong
3322
+ // nonce fails the handshake; the matching nonce passes it.
3323
+ if (decoded.frame.nonce !== options.nonce) {
3324
+ finish({ ok: false, reason: "nonce_mismatch" });
3325
+ return;
3326
+ }
3327
+ // The bytes that follow the READY line become the replay buffer for the
3328
+ // broker.
3329
+ //
3330
+ // Copy the suffix instead of slicing it off `buffer`. `buffer` is a view
3331
+ // over `storage`, and `storage`'s capacity can run ahead of the bytes in
3332
+ // use (the doubling growth in `appendReadinessBytes` over-provisions it).
3333
+ // A slice would keep that whole over-provisioned allocation alive for as
3334
+ // long as the broker replay holds its reference. The copy is exactly
3335
+ // `suffix.length` bytes, one time, not a per-fragment cost.
3336
+ const suffix = Buffer.from(buffer.subarray(newlineIndex + 1));
3337
+ // Drop the original pre-READY buffer and its backing storage now. The
3338
+ // gate keeps only the retained suffix as `pending`. This clear also
3339
+ // covers the broker handoff and the replay disposal. Both run later and
3340
+ // read no buffer bytes.
3341
+ buffer = READINESS_EMPTY_BUFFER;
3342
+ storage = READINESS_EMPTY_BUFFER;
3343
+ pending = suffix;
3344
+ finish({ ok: true });
3345
+ return;
3346
+ }
3347
+ // The line does not decode as a READY frame. A PTY echo line or any other
3348
+ // pre-READY noise reaches here. Skip it and keep scanning; the nonce and the
3349
+ // strict schema, not the line position, authenticate readiness. Enforce the
3350
+ // cap after the advance, so a noise-line flood past the cap fails closed.
3351
+ lineStart = newlineIndex + 1;
3352
+ scanFrom = newlineIndex + 1;
3353
+ if (lineStart > DUPLEX_READINESS_BUFFER_CAP_BYTES) {
3354
+ finish({ ok: false, reason: "protocol_contamination" });
3355
+ return;
3356
+ }
3357
+ }
3358
+ });
3359
+ channel.onExit((exit) => {
3360
+ if (exitSink) {
3361
+ exitSink(exit);
3362
+ return;
3363
+ }
3364
+ if (readyOk) {
3365
+ // The channel exited after READY but before the broker bound. Hold the
3366
+ // exit so the broker still learns of the loss.
3367
+ pendingExit = exit;
3368
+ return;
3369
+ }
3370
+ finish({ ok: false, reason: "channel_exit" });
3371
+ });
3372
+ const brokerChannel = {
3373
+ write: (data) => channel.write(data),
3374
+ onData: (listener) => {
3375
+ dataSink = listener;
3376
+ if (pending.length > 0) {
3377
+ const replay = pending;
3378
+ pending = READINESS_EMPTY_BUFFER;
3379
+ listener(replay);
3380
+ return;
3381
+ }
3382
+ },
3383
+ onExit: (listener) => {
3384
+ exitSink = listener;
3385
+ if (pendingExit) {
3386
+ const exit = pendingExit;
3387
+ pendingExit = null;
3388
+ listener(exit);
3389
+ }
3390
+ },
3391
+ stop: () => channel.stop(),
3392
+ close: () => channel.close(),
3393
+ };
3394
+ return {
3395
+ ready,
3396
+ brokerChannel,
3397
+ replayOverflowed: () => replayOverflow,
3398
+ disposePendingReplay: () => {
3399
+ pending = READINESS_EMPTY_BUFFER;
3400
+ },
3401
+ retainedReadinessBufferLength: () => buffer.length,
3402
+ };
3403
+ }
3404
+ /**
3405
+ * Close a partial duplex channel inside a bounded budget, then stop the child.
3406
+ * The host runs this on any readiness failure, so a failed duplex attempt leaves
3407
+ * no live provider session before the fallback to the file bridge.
3408
+ */
3409
+ async function closeDuplexChannelWithinBudget(channel, budgetMs) {
3410
+ try {
3411
+ let timer;
3412
+ const budget = new Promise((resolve) => {
3413
+ timer = setTimeout(resolve, budgetMs);
3414
+ timer.unref?.();
3415
+ });
3416
+ await Promise.race([channel.close().catch(() => undefined), budget]);
3417
+ if (timer !== undefined)
3418
+ clearTimeout(timer);
3419
+ }
3420
+ catch {
3421
+ // Best effort: the stop below still removes the child.
3422
+ }
3423
+ finally {
3424
+ try {
3425
+ channel.stop();
3426
+ }
3427
+ catch {
3428
+ // The channel is already gone; nothing more to do.
3429
+ }
3430
+ }
3431
+ }
3432
+ let attachmentMaxBytesSource = null;
3433
+ /** Lets the host supply its live attachment size limit so the bridge body cap follows Instance Settings. */
3434
+ export function setPaperclipBridgeAttachmentMaxBytesSource(source) {
3435
+ attachmentMaxBytesSource = source;
3436
+ }
3437
+ export async function startAdapterExecutionTargetPaperclipBridge(input) {
3438
+ if (!adapterExecutionTargetUsesPaperclipBridge(input.target)) {
3439
+ return null;
3440
+ }
3441
+ if (!input.target || input.target.kind !== "remote") {
3442
+ return null;
3443
+ }
3444
+ const target = input.target;
3445
+ const onLog = input.onLog ?? (async () => { });
3446
+ const hostApiToken = input.hostApiToken?.trim() ?? "";
3447
+ if (hostApiToken.length === 0) {
3448
+ throw new Error("Sandbox bridge mode requires a host-side Paperclip API token.");
3449
+ }
3450
+ // The forward budget for one relayed request. It stays at the broker's default
3451
+ // forward budget (30 s) when the caller sets no option, so current behavior
3452
+ // does not change.
3453
+ const forwardTimeoutMs = input.forwardTimeoutMs ?? DEFAULT_DUPLEX_BROKER_BUDGETS.forwardTimeoutMs;
3454
+ const runtimeRootDir = input.runtimeRootDir?.trim().length
3455
+ ? input.runtimeRootDir.trim()
3456
+ : path.posix.join(target.remoteCwd, ".paperclip-runtime", input.adapterKey);
3457
+ const bridgeRuntimeDir = path.posix.join(runtimeRootDir, "paperclip-bridge");
3458
+ const queueDir = path.posix.join(bridgeRuntimeDir, "queue");
3459
+ const assetRemoteDir = path.posix.join(bridgeRuntimeDir, "server");
3460
+ const bridgeToken = createSandboxCallbackBridgeToken();
3461
+ const configuredAttachmentBytes = attachmentMaxBytesSource?.() ?? Number(process.env.PAPERCLIP_ATTACHMENT_MAX_BYTES);
3462
+ // A larger upload limit needs multipart headroom. A smaller attachment limit
3463
+ // remains enforced by the API and must not shrink unrelated JSON responses.
3464
+ const defaultBodyBytes = Number.isSafeInteger(configuredAttachmentBytes) && configuredAttachmentBytes > 0
3465
+ ? Math.max(DEFAULT_SANDBOX_CALLBACK_BRIDGE_MAX_BODY_BYTES, configuredAttachmentBytes + 64 * 1024)
3466
+ : DEFAULT_SANDBOX_CALLBACK_BRIDGE_MAX_BODY_BYTES;
3467
+ const maxBodyBytes = typeof input.maxBodyBytes === "number" && Number.isFinite(input.maxBodyBytes) && input.maxBodyBytes > 0
3468
+ ? Math.trunc(input.maxBodyBytes)
3469
+ : defaultBodyBytes;
3470
+ // The bridge worker runs inside the same process that serves the Paperclip
3471
+ // API, so forwarded sandbox calls must target the LOCAL listen origin. The
3472
+ // PAPERCLIP_RUNTIME_API_URL / PAPERCLIP_API_URL exports now prefer a
3473
+ // configured public base URL, which is the origin browsers and external
3474
+ // agents use; routing this in-process loopback hop through the network edge
3475
+ // breaks deployments whose public origin sits behind a session-gated proxy
3476
+ // (every forwarded agent API call is rejected at the edge). Server boot
3477
+ // exports PAPERCLIP_LISTEN_HOST / PAPERCLIP_LISTEN_PORT before any run
3478
+ // executes, and resolveDefaultPaperclipApiUrl() maps wildcard listen hosts
3479
+ // to the loopback address of the same family (0.0.0.0 -> 127.0.0.1,
3480
+ // :: -> [::1]), so the fallback is always loopback-reachable.
3481
+ // input.hostApiUrl stays available as an explicit override seam.
3482
+ const hostApiUrl = input.hostApiUrl?.trim() || resolveDefaultPaperclipApiUrl();
3483
+ const shellCommand = adapterExecutionTargetShellCommand(target);
3484
+ const runner = adapterExecutionTargetCommandRunner(target);
3485
+ const bridgeTimeoutMs = typeof input.timeoutSec === "number" && Number.isFinite(input.timeoutSec) && input.timeoutSec > 0
3486
+ ? Math.trunc(input.timeoutSec * 1000)
3487
+ : adapterExecutionTargetTimeoutMs(target);
3488
+ await onLog("stdout", `[paperclip] Starting sandbox callback bridge for ${input.adapterKey} in ${bridgeRuntimeDir}.\n`);
3489
+ const bridgeAsset = await createSandboxCallbackBridgeAsset();
3490
+ // The provider-scoped telemetry facade for the fixed duplex observability
3491
+ // surface. It maps the raw provider key through the allowlist one time, so no
3492
+ // raw plugin key reaches a span, a counter, or the event. The default recorder
3493
+ // is a no-op, so the facade is inert until the host injects a real recorder.
3494
+ const duplexProviderKey = "providerKey" in target ? target.providerKey ?? undefined : undefined;
3495
+ const duplexObservability = createDuplexObservability({
3496
+ recorder: input.duplexObservabilityRecorder ?? undefined,
3497
+ providerKey: duplexProviderKey,
3498
+ // http2_v1 is the one active non-file transport now; every non-file
3499
+ // record this facade produces stamps the `http2` transport value.
3500
+ transport: "http2",
3501
+ });
3502
+ // PAPERCLIP_BRIDGE_DEBUG opts into verbose stdout logs of every bridge proxy
3503
+ // request/response. The query string is logged verbatim, so callers who pass
3504
+ // auth tokens or other sensitive values as query parameters should be aware
3505
+ // those values appear in the host process's stdout when this flag is enabled.
3506
+ // Only intended for active debugging in trusted environments.
3507
+ const bridgeDebugEnabled = isBridgeDebugEnabled(process.env);
3508
+ // One forward of a relayed sandbox request onto the existing Paperclip API
3509
+ // path. The forward applies the real host token and the signed run id, so the
3510
+ // token replacement and the run attribution stay in one place for both the
3511
+ // file bridge and the duplex broker. The sandbox request carries only the
3512
+ // bridge token; the real agent token never leaves the host.
3513
+ const forwardBridgeRequest = async (request, signal, options) => {
3514
+ const method = request.method.trim().toUpperCase() || "GET";
3515
+ // The per-request debug log prints the method, the path, and the query. The
3516
+ // duplex path suppresses it, so no route or query rides a log line there. The
3517
+ // file path keeps the existing behavior.
3518
+ const emitDebugLog = bridgeDebugEnabled && options?.suppressDebugLog !== true;
3519
+ if (emitDebugLog) {
3520
+ await onLog("stdout", `[paperclip] Bridge proxy ${method} ${request.path}${request.query ? `?${request.query}` : ""}\n`);
3521
+ }
3522
+ const headers = new Headers();
3523
+ for (const [key, value] of Object.entries(request.headers)) {
3524
+ if (value.trim().length === 0)
3525
+ continue;
3526
+ headers.set(key, value);
3527
+ }
3528
+ headers.set("authorization", `Bearer ${hostApiToken}`);
3529
+ headers.set("x-paperclip-run-id", input.runId);
3530
+ // Abort the forward when the caller aborts the request (its per-iteration
3531
+ // timeout or watchdog fired, or the broker's forward budget ended), or after
3532
+ // the forward budget here, whichever comes first.
3533
+ const timeoutSignal = AbortSignal.timeout(forwardTimeoutMs);
3534
+ const forwardSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
3535
+ // Build the request-body init. A GET or a HEAD carries no body. The file
3536
+ // bridge passes legacy JSON as a string and binary data as a `Buffer`;
3537
+ // HTTP/2 passes raw `Buffer` bodies. Undici accepts a `Buffer` request body directly (a
3538
+ // `Buffer` is an `ArrayBufferView`), so neither shape needs a conversion.
3539
+ // The cast below only bridges a `BodyInit` typing gap: the DOM library
3540
+ // type this project's ambient `RequestInit` resolves to excludes a
3541
+ // `Buffer`, though Undici accepts one at runtime.
3542
+ const forwardInit = {
3543
+ method,
3544
+ headers,
3545
+ signal: forwardSignal,
3546
+ };
3547
+ if (method !== "GET" && method !== "HEAD" && request.body !== undefined) {
3548
+ forwardInit.body = request.body;
3549
+ }
3550
+ const response = await fetch(buildBridgeForwardUrl(hostApiUrl, request), forwardInit);
3551
+ if (emitDebugLog) {
3552
+ await onLog("stdout", `[paperclip] Bridge proxy response ${response.status} for ${method} ${request.path}${request.query ? `?${request.query}` : ""}\n`);
3553
+ }
3554
+ // The host delivered response headers, so the response-body read starts after
3555
+ // the host processed the request. A later response-body read failure (a body
3556
+ // over the size limit, or a stream read error) needs a classification by
3557
+ // method safety. A safe method (GET, HEAD, OPTIONS, TRACE) never changes host
3558
+ // state, so a retry cannot double-apply a mutation and the failure stays
3559
+ // retryable. A mutating or otherwise unsafe method may have committed on the
3560
+ // host, so a retryable status is unsafe: it makes the caller repeat the
3561
+ // request with a new request id outside the broker deduplication set, and the
3562
+ // host applies the mutation twice. For an unsafe method the code returns a
3563
+ // non-retryable 504 and marks the outcome indeterminate, exactly like an
3564
+ // aborted in-flight forward. The in-sandbox server maps the indeterminate 504
3565
+ // to a non-retryable 409 for both the file bridge and the duplex broker.
3566
+ let responseBody;
3567
+ try {
3568
+ responseBody = await readBridgeForwardResponseBody(response, maxBodyBytes, options?.reservation);
3569
+ }
3570
+ catch (error) {
3571
+ // A denied reservation is retryable capacity pressure for a safe
3572
+ // method, not a body-read fault: rethrow it before the method-safety
3573
+ // classification below runs, so it reaches the HTTP/2 bridge's own
3574
+ // capacity-denial catch (which answers the retryable 503 and settles
3575
+ // the stream) instead of this function turning it into a 502. For an
3576
+ // unsafe (mutating) method, the host has already delivered response
3577
+ // headers by this point, so it may already have committed the
3578
+ // mutation. Rethrowing there too would let the retryable 503 reach a
3579
+ // caller that repeats the request, applying the mutation twice. An
3580
+ // unsafe method's capacity denial falls through to the same
3581
+ // non-retryable indeterminate 504 any other response-body read fault
3582
+ // gets below.
3583
+ if (error instanceof BridgeProcessCapacityError && isSafeBridgeMethod(method))
3584
+ throw error;
3585
+ if (isSafeBridgeMethod(method)) {
3586
+ // The method is safe, so a retry cannot double-apply a mutation. Return a
3587
+ // retryable 502 with no indeterminate marker, so the gateway passes it
3588
+ // through as a retryable status.
3589
+ return {
3590
+ status: 502,
3591
+ headers: { "content-type": "application/json" },
3592
+ body: Buffer.from(JSON.stringify({
3593
+ error: error instanceof Error ? error.message : String(error),
3594
+ }), "utf8"),
3595
+ };
3596
+ }
3597
+ return {
3598
+ status: 504,
3599
+ headers: {
3600
+ "content-type": "application/json",
3601
+ "x-paperclip-bridge-outcome": "indeterminate",
3602
+ },
3603
+ body: Buffer.from(JSON.stringify({
3604
+ error: error instanceof Error ? error.message : String(error),
3605
+ outcome: "indeterminate",
3606
+ retryable: false,
3607
+ }), "utf8"),
3608
+ };
3609
+ }
3610
+ const commentMarker = postedIssueCommentLogMarker(method, request.path, response.status, responseBody);
3611
+ if (commentMarker)
3612
+ await onLog("stdout", commentMarker);
3613
+ return {
3614
+ status: response.status,
3615
+ headers: buildBridgeResponseHeaders(response),
3616
+ body: responseBody,
3617
+ };
3618
+ };
3619
+ // Two strict gates guard the duplex transport. Select duplex only when the
3620
+ // experimental setting is exactly `true`, the resolved capability
3621
+ // `duplexCommandStream` is exactly `true`, and the runner exposes the duplex
3622
+ // channel. Any other value of either gate selects the file bridge below.
3623
+ // HTTP/2 is the preferred transport. `queue_v1` is the soft-deprecated fallback.
3624
+ const duplexRequested = input.enableSandboxDuplexBridge === true;
3625
+ const capabilityGranted = "effectiveCapabilities" in target &&
3626
+ target.effectiveCapabilities?.duplexCommandStream === true;
3627
+ const openDuplexChannel = runner.openDuplexChannel?.bind(runner);
3628
+ // Record the pre-attempt fallback for a file-bridge selection that opens no
3629
+ // channel. `gate_off` marks the kill switch off; `capability_absent` marks the
3630
+ // capability or the runner method absent. A later channel-open failure records
3631
+ // its own fallback through the channel-open attempt below.
3632
+ if (!duplexRequested) {
3633
+ duplexObservability.recordFallback("gate_off");
3634
+ }
3635
+ else if (!capabilityGranted || typeof openDuplexChannel !== "function") {
3636
+ duplexObservability.recordFallback("capability_absent");
3637
+ }
3638
+ if (duplexRequested && capabilityGranted && typeof openDuplexChannel === "function") {
3639
+ // Begin the channel-open attempt. The block reports exactly one terminal:
3640
+ // `ready` on success, or `fallback(reason)` on an open or a readiness failure.
3641
+ const duplexChannelOpen = duplexObservability.startChannelOpen();
3642
+ const readinessTimeoutMs = typeof input.duplexReadinessTimeoutMs === "number" &&
3643
+ Number.isFinite(input.duplexReadinessTimeoutMs) &&
3644
+ input.duplexReadinessTimeoutMs > 0
3645
+ ? Math.trunc(input.duplexReadinessTimeoutMs)
3646
+ : DEFAULT_DUPLEX_READINESS_TIMEOUT_MS;
3647
+ // The host assigns the loopback port before it opens the channel. It passes
3648
+ // the port and one random per-open nonce to the gateway only through the
3649
+ // launch environment. It builds the sandbox-facing origin from its own
3650
+ // stored port. No field of any channel frame contributes to the endpoint.
3651
+ //
3652
+ // Provider-boundary rationale (a security-review condition): the Daytona SDK
3653
+ // surface the plugin uses (`sandbox.process` sessions, PTY, and exec;
3654
+ // `sandbox.fs`) exposes no listener identity that the provider control plane
3655
+ // binds to a launched process. No channel-supplied address can be attested,
3656
+ // so this design uses zero channel-supplied addressing data. The only actor
3657
+ // that can pre-bind the host-assigned loopback port before the agent starts
3658
+ // is the provider itself, which already delivers the agent launch
3659
+ // environment. The gateway bind-or-exit contract fails closed. This is an
3660
+ // accepted provider-untrusted residual, not endpoint authentication: the
3661
+ // nonce is a liveness signal, because a compromised channel can read the
3662
+ // launch environment; the endpoint stays safe because it never derives from
3663
+ // the channel.
3664
+ const assignedPort = await reserveHostAssignedLoopbackPort();
3665
+ const nonce = randomBytes(16).toString("hex");
3666
+ const sandboxOrigin = `http://127.0.0.1:${assignedPort}`;
3667
+ let channel = null;
3668
+ // The open runs two stages under one try: the entrypoint sync, then the
3669
+ // channel open. The stage names the exact open-failure outcome in the catch.
3670
+ let openStage = "entrypoint_sync";
3671
+ try {
3672
+ const assetSync = await syncSandboxCallbackBridgeEntrypoint({
3673
+ runner,
3674
+ remoteCwd: target.remoteCwd,
3675
+ assetRemoteDir,
3676
+ bridgeAsset,
3677
+ timeoutMs: bridgeTimeoutMs,
3678
+ shellCommand,
3679
+ });
3680
+ const gatewayEnv = {
3681
+ PAPERCLIP_API_BRIDGE_MODE: SANDBOX_CALLBACK_BRIDGE_HTTP2_MODE,
3682
+ PAPERCLIP_BRIDGE_TOKEN: bridgeToken,
3683
+ PAPERCLIP_BRIDGE_HOST: "127.0.0.1",
3684
+ PAPERCLIP_BRIDGE_PORT: String(assignedPort),
3685
+ PAPERCLIP_BRIDGE_NONCE: nonce,
3686
+ PAPERCLIP_BRIDGE_MAX_BODY_BYTES: String(maxBodyBytes),
3687
+ };
3688
+ const command = buildDuplexGatewayLaunchArgv({
3689
+ shellCommand,
3690
+ remoteEntrypoint: assetSync.remoteEntrypoint,
3691
+ env: gatewayEnv,
3692
+ });
3693
+ openStage = "channel_open";
3694
+ channel = await openDuplexChannel({ command });
3695
+ }
3696
+ catch (error) {
3697
+ // The channel never opened, so no request could carry the bridge token.
3698
+ // The open call is the last statement of the try, so `channel` is still
3699
+ // null here; there is nothing to close. Fall through to the file bridge
3700
+ // below. Bind and keep the caught error, so the fallback names the exact
3701
+ // open-failure stage: a full process-scoped route ceiling is `route_busy`;
3702
+ // otherwise the stage is the entrypoint sync or the channel open. The log
3703
+ // line names only the fixed stage enum, so no raw provider error rides a log
3704
+ // line on the duplex path.
3705
+ const reason = isDuplexRouteBusyError(error)
3706
+ ? "route_busy"
3707
+ : openStage === "entrypoint_sync"
3708
+ ? "entrypoint_sync_failed"
3709
+ : "channel_open_failed";
3710
+ duplexChannelOpen.fallback(reason);
3711
+ await onLog("stderr", `[paperclip] Could not open the sandbox duplex channel (${reason}). Using the file bridge.\n`);
3712
+ channel = null;
3713
+ }
3714
+ if (channel) {
3715
+ const gate = createDuplexReadinessGate(channel, {
3716
+ nonce,
3717
+ timeoutMs: readinessTimeoutMs,
3718
+ });
3719
+ const readiness = await gate.ready;
3720
+ if (!readiness.ok) {
3721
+ // Fail closed. Close the partial channel inside a bounded budget, then
3722
+ // select the file bridge. The broker never started, so no request that
3723
+ // carries the bridge token reached the channel or any endpoint. The reason
3724
+ // is a fixed enum, so it rides the log line and the fallback telemetry
3725
+ // with no raw value.
3726
+ gate.disposePendingReplay();
3727
+ await closeDuplexChannelWithinBudget(channel, DEFAULT_DUPLEX_CLEANUP_BUDGET_MS);
3728
+ duplexChannelOpen.fallback(duplexReadinessFallbackReason(readiness.reason));
3729
+ await onLog("stderr", `[paperclip] Sandbox duplex readiness failed (${readiness.reason}). Using the file bridge.\n`);
3730
+ }
3731
+ else {
3732
+ // Readiness passed. The gate retained every byte that followed the
3733
+ // accepted READY line. Scan those retained bytes for the HTTP/2
3734
+ // client connection preface — the scan window opens only now, after
3735
+ // the gate accepted the nonce — and start the HTTP/2 session at that
3736
+ // offset, inclusive. A missing preface inside the bounded readiness
3737
+ // buffer aborts the open; the run falls back to `queue_v1` exactly
3738
+ // one time (accepted security fix 6).
3739
+ const openedChannel = channel;
3740
+ const prefaceScan = scanForHttp2ClientPreface(gate.brokerChannel, {
3741
+ capBytes: DUPLEX_READINESS_BUFFER_CAP_BYTES,
3742
+ timeoutMs: readinessTimeoutMs,
3743
+ });
3744
+ const prefaceResult = await prefaceScan.settled;
3745
+ if (prefaceResult === "missing") {
3746
+ // Fail closed, the same shape as a readiness failure: close the
3747
+ // partial channel inside the cleanup budget, then select the file
3748
+ // bridge. No HTTP/2 server ever bound to this channel, so no
3749
+ // request reached it or any endpoint.
3750
+ gate.disposePendingReplay();
3751
+ await closeDuplexChannelWithinBudget(openedChannel, DEFAULT_DUPLEX_CLEANUP_BUDGET_MS);
3752
+ duplexChannelOpen.fallback("preface_missing");
3753
+ await onLog("stderr", "[paperclip] Sandbox HTTP/2 client preface did not appear inside the bounded readiness buffer (preface_missing). Using the file bridge.\n");
3754
+ }
3755
+ else {
3756
+ // The run disposition latch for the http2_v1 path, in the same
3757
+ // shape the retired duplex_v1 broker exposed. A loss ordered before
3758
+ // an orderly completion reports a failure with the typed loss
3759
+ // reason; every other state reports a success.
3760
+ const dispositionLatch = createHttp2RunDispositionLatch();
3761
+ // Set before the first await inside the forward handler, so a loss
3762
+ // that lands mid-request still classifies as `post_dispatch`.
3763
+ let anyStreamDispatched = false;
3764
+ const recordHttp2Loss = (event) => {
3765
+ const reason = mapHttp2EventToDuplexLossReason(event);
3766
+ const disposedNow = dispositionLatch.recordLoss(reason);
3767
+ if (!disposedNow && (reason === "provider_exit" || reason === "transport_closed")) {
3768
+ // A clean channel end that orders after a host-observed orderly
3769
+ // completion is a normal teardown, not a loss: the run already
3770
+ // completed. Emit no loss telemetry and no log line for it, the
3771
+ // same policy the retired duplex_v1 broker applied.
3772
+ return;
3773
+ }
3774
+ const lossClass = anyStreamDispatched ? "post_dispatch" : "pre_dispatch";
3775
+ duplexObservability.recordLoss(lossClass, reason);
3776
+ void onLog("stderr", `[paperclip] Sandbox HTTP/2 channel lost (${reason}). The run fails.\n`);
3777
+ };
3778
+ // The forward handler applies the real host token and the run id
3779
+ // through the existing `forwardBridgeRequest` — the same function
3780
+ // the file bridge uses. The route allowlist, the header allowlist,
3781
+ // and the per-request debug-log suppression already ran inside
3782
+ // `createHttp2BridgeServer`'s own stream handler before this call.
3783
+ // It records the request span with the same latency-and-outcome
3784
+ // shape the retired duplex_v1 broker recorded: `ok` for any
3785
+ // delivered host response (any status), `error` only when the
3786
+ // forward call itself throws.
3787
+ const http2ForwardRequest = async (request) => {
3788
+ anyStreamDispatched = true;
3789
+ const dispatchStartMs = Date.now();
3790
+ try {
3791
+ const result = await forwardBridgeRequest({
3792
+ method: request.method,
3793
+ path: request.pathname,
3794
+ query: request.query,
3795
+ headers: request.headers,
3796
+ body: request.body,
3797
+ }, request.signal, { suppressDebugLog: true, reservation: request.reservation });
3798
+ duplexObservability.recordRequest({ latencyMs: Date.now() - dispatchStartMs, outcome: "ok" });
3799
+ return { status: result.status, headers: result.headers, body: result.body };
3800
+ }
3801
+ catch (error) {
3802
+ duplexObservability.recordRequest({ latencyMs: Date.now() - dispatchStartMs, outcome: "error" });
3803
+ throw error;
3804
+ }
3805
+ };
3806
+ const http2Server = createHttp2BridgeServer({
3807
+ bridgeToken,
3808
+ forwardRequest: http2ForwardRequest,
3809
+ routes: HTTP2_SANDBOX_CALLBACK_BRIDGE_ROUTE_ALLOWLIST,
3810
+ // The same resolved limit the launch environment hands the
3811
+ // sandbox-side gateway (`PAPERCLIP_BRIDGE_MAX_BODY_BYTES`,
3812
+ // below), so the host check and the gateway check enforce one
3813
+ // value instead of the host silently falling back to the
3814
+ // package default.
3815
+ maxBodyBytes,
3816
+ onGoaway: () => recordHttp2Loss("session_goaway"),
3817
+ onSessionError: () => recordHttp2Loss("session_error"),
3818
+ });
3819
+ // Combine the loss hook with the forward-to-Duplex handoff inside
3820
+ // one `onExit` registration: the channel primitive holds exactly
3821
+ // one listener slot, and `bindChannel` below registers the one that
3822
+ // ends the wrapped `Duplex`.
3823
+ //
3824
+ // This object's `stop()` is also the real sandbox-side effect of
3825
+ // the post-bind read backpressure bound `bindChannel` applies
3826
+ // (`wrapDuplexChannelAsNodeDuplex` in `http2-bridge-server.ts`):
3827
+ // this raw provider channel exposes no pause, so once the bounded
3828
+ // read queue there overflows, it calls `stop()` through this exact
3829
+ // chain, down to `prefaceScan.scanned.stop()` and on to the real
3830
+ // channel, instead of letting sandbox-controlled bytes grow host
3831
+ // memory with no bound.
3832
+ const channelForHttp2Server = {
3833
+ write: (data) => prefaceScan.scanned.write(data),
3834
+ onData: (listener) => prefaceScan.scanned.onData(listener),
3835
+ onExit: (listener) => {
3836
+ prefaceScan.scanned.onExit((exit) => {
3837
+ recordHttp2Loss("channel_exit");
3838
+ listener(exit);
3839
+ });
3840
+ },
3841
+ stop: () => prefaceScan.scanned.stop(),
3842
+ close: () => prefaceScan.scanned.close(),
3843
+ };
3844
+ const boundDuplex = http2Server.bindChannel(channelForHttp2Server);
3845
+ // Also catches the `Duplex` this wrapper destroys when the bounded
3846
+ // read backpressure queue overflows post-bind, so that loss still
3847
+ // reaches `recordHttp2Loss` the same way any other write fault does.
3848
+ boundDuplex.on("error", () => recordHttp2Loss("write_error"));
3849
+ duplexChannelOpen.ready();
3850
+ await onLog("stdout", "[paperclip] Sandbox HTTP/2 transport ready; serving the host-assigned origin.\n");
3851
+ // Stream run logs on the http2 path with the same gate and the same
3852
+ // log line as the file path. The http2 path starts no file-bridge
3853
+ // worker, so create the log directory before the tail starts.
3854
+ let duplexRunLogTail = null;
3855
+ if (target.transport === "sandbox" && target.streamRunLogs !== false) {
3856
+ const duplexLogsDir = sandboxCallbackBridgeDirectories(queueDir).logsDir;
3857
+ await ensureSandboxRunLogDirectory({
3858
+ runner,
3859
+ remoteCwd: target.remoteCwd,
3860
+ logsDir: duplexLogsDir,
3861
+ shellCommand,
3862
+ timeoutMs: bridgeTimeoutMs,
3863
+ });
3864
+ duplexRunLogTail = createSandboxRunLogTailFactory({
3865
+ runner,
3866
+ remoteCwd: target.remoteCwd,
3867
+ logsDir: duplexLogsDir,
3868
+ shellCommand,
3869
+ });
3870
+ await onLog("stdout", "[paperclip] Sandbox run log streaming enabled for this run.\n");
3871
+ }
3872
+ return {
3873
+ env: {
3874
+ PAPERCLIP_API_URL: sandboxOrigin,
3875
+ PAPERCLIP_API_KEY: bridgeToken,
3876
+ PAPERCLIP_API_BRIDGE_MODE: SANDBOX_CALLBACK_BRIDGE_HTTP2_MODE,
3877
+ },
3878
+ runLogTail: duplexRunLogTail,
3879
+ readRunDisposition: () => dispositionLatch.disposition,
3880
+ // Atomically read the latch and mark the orderly completion for the
3881
+ // ACP success-eligible terminal, so no await separates the read from
3882
+ // the mark and a teardown loss cannot slip in between.
3883
+ settleRunDisposition: () => dispositionLatch.settleRunDisposition(),
3884
+ markOrderlyCompletion: () => dispositionLatch.markOrderlyCompletion(),
3885
+ onLoss: (listener) => dispositionLatch.onLoss(listener),
3886
+ stop: async () => {
3887
+ // Close the HTTP/2 server's sessions, then the channel, before
3888
+ // lease release, so no live provider session remains when the
3889
+ // caller releases the lease.
3890
+ await http2Server.close();
3891
+ await closeDuplexChannelWithinBudget(openedChannel, DEFAULT_DUPLEX_CLEANUP_BUDGET_MS);
3892
+ await bridgeAsset.cleanup();
3893
+ },
3894
+ };
3895
+ }
3896
+ }
3897
+ }
3898
+ }
3899
+ let server = null;
3900
+ let worker = null;
3901
+ try {
3902
+ const client = createCommandManagedSandboxCallbackBridgeQueueClient({
3903
+ runner,
3904
+ remoteCwd: target.remoteCwd,
3905
+ timeoutMs: bridgeTimeoutMs,
3906
+ shellCommand,
3907
+ });
3908
+ // `startSandboxCallbackBridgeWorker` keeps its awaited queue-directory
3909
+ // setup on the active `bridge.paperclip` step, and runs each request under
3910
+ // the run parent context (see `runWithRuntimeParent` inside that function).
3911
+ // So the startup `mkdir` execs stay parented to the step, and every later
3912
+ // request `sandbox.exec` span parents to the live run span.
3913
+ worker = await startSandboxCallbackBridgeWorker({
3914
+ client,
3915
+ queueDir,
3916
+ maxBodyBytes,
3917
+ getRuntimeParentContext: input.getRuntimeParentContext,
3918
+ runtimeSpan: input.runtimeSpan,
3919
+ // The worker encodes binary bodies only at the queue boundary.
3920
+ handleRequest: (request, options) => forwardBridgeRequest(request, options?.signal, {
3921
+ reservation: options?.reservation,
3922
+ }),
3923
+ });
3924
+ server = await startSandboxCallbackBridgeServer({
3925
+ runner,
3926
+ remoteCwd: target.remoteCwd,
3927
+ assetRemoteDir,
3928
+ queueDir,
3929
+ bridgeToken,
3930
+ bridgeAsset,
3931
+ timeoutMs: bridgeTimeoutMs,
3932
+ maxBodyBytes,
3933
+ shellCommand,
3934
+ });
3935
+ }
3936
+ catch (error) {
3937
+ await Promise.allSettled([
3938
+ server?.stop(),
3939
+ worker?.stop(),
3940
+ bridgeAsset.cleanup(),
3941
+ ]);
3942
+ throw error;
3943
+ }
3944
+ let runLogTail = null;
3945
+ if (target.transport === "sandbox" && target.streamRunLogs !== false) {
3946
+ runLogTail = createSandboxRunLogTailFactory({
3947
+ runner,
3948
+ remoteCwd: target.remoteCwd,
3949
+ logsDir: sandboxCallbackBridgeDirectories(queueDir).logsDir,
3950
+ shellCommand,
3951
+ });
3952
+ await onLog("stdout", "[paperclip] Sandbox run log streaming enabled for this run.\n");
3953
+ }
3954
+ return {
3955
+ env: {
3956
+ PAPERCLIP_API_URL: server.baseUrl,
3957
+ PAPERCLIP_API_KEY: bridgeToken,
3958
+ PAPERCLIP_API_BRIDGE_MODE: "queue_v1",
3959
+ PAPERCLIP_BRIDGE_QUEUE_DIR: queueDir,
3960
+ },
3961
+ runLogTail,
3962
+ stop: async () => {
3963
+ await Promise.allSettled([
3964
+ server?.stop(),
3965
+ ]);
3966
+ await Promise.allSettled([
3967
+ worker?.stop(),
3968
+ bridgeAsset.cleanup(),
3969
+ ]);
3970
+ },
3971
+ };
3972
+ }
3973
+ //# sourceMappingURL=execution-target.js.map