@graftland/plugin-remote 0.0.0-stage → 0.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +76 -2
  3. package/README.zh-CN.md +71 -0
  4. package/README.zh-TW.md +71 -0
  5. package/dist/Auth-BElTC9_X.js +6 -0
  6. package/dist/Auth.d.ts +49 -0
  7. package/dist/Auth.d.ts.map +1 -0
  8. package/dist/Auth.js +8 -0
  9. package/dist/Auth.js.map +1 -0
  10. package/dist/Bootstrap-MCwivGN1.js +9 -0
  11. package/dist/ConfigDirectory-BCC6q2R4.js +5 -0
  12. package/dist/Contract-CcpSIJm4.js +121 -0
  13. package/dist/Contract.d.ts +71 -0
  14. package/dist/Contract.d.ts.map +1 -0
  15. package/dist/Contract.js +1 -0
  16. package/dist/Contract.js.map +1 -0
  17. package/dist/Errors-oPsTLY7l.js +45 -0
  18. package/dist/Errors.d.ts +67 -0
  19. package/dist/Errors.d.ts.map +1 -0
  20. package/dist/Errors.js +47 -0
  21. package/dist/Errors.js.map +1 -0
  22. package/dist/FailureGroup-BcH0XOBi.js +53 -0
  23. package/dist/Framing-zaYdOJnT.js +61 -0
  24. package/dist/Graft-BsYq3F-J.js +985 -0
  25. package/dist/Instance.d.ts +7 -0
  26. package/dist/Instance.d.ts.map +1 -0
  27. package/dist/Instance.js +14 -0
  28. package/dist/Instance.js.map +1 -0
  29. package/dist/Packages-B1TPk8pa.js +111 -0
  30. package/dist/Peer-IJgFK6mD.js +342 -0
  31. package/dist/ProcessObservation-DEGrEMfP.js +38 -0
  32. package/dist/ServeLifecycle-CJM0gG5B.js +24 -0
  33. package/dist/Testing.d.ts +26 -0
  34. package/dist/Testing.d.ts.map +1 -0
  35. package/dist/Testing.js +69 -0
  36. package/dist/Testing.js.map +1 -0
  37. package/dist/Transport-DULzpsgR.js +6 -0
  38. package/dist/Transport.d.ts +39 -0
  39. package/dist/Transport.d.ts.map +1 -0
  40. package/dist/Transport.js +8 -0
  41. package/dist/Transport.js.map +1 -0
  42. package/dist/WatchdogProtocol-BZmVxrBP.js +17 -0
  43. package/dist/_virtual/_rolldown/runtime.js +12 -0
  44. package/dist/bin.d.ts +1 -0
  45. package/dist/bin.js +28275 -0
  46. package/dist/bin.js.map +1 -0
  47. package/dist/childRuntime-DSqtFN9o.js +188 -0
  48. package/dist/cleanup-BPWr-5U9.js +13 -0
  49. package/dist/command-9zrHdbwT.js +7 -0
  50. package/dist/connectionEnded-DUgcobEd.js +9 -0
  51. package/dist/directTransport-DrexuPSm.js +5 -0
  52. package/dist/entry-SYsx9VNb.js +708 -0
  53. package/dist/host/auth/bearer.d.ts +5 -0
  54. package/dist/host/auth/bearer.d.ts.map +1 -0
  55. package/dist/host/auth/bearer.js +4 -0
  56. package/dist/host/auth/bearer.js.map +1 -0
  57. package/dist/host/auth/jwt.d.ts +5 -0
  58. package/dist/host/auth/jwt.d.ts.map +1 -0
  59. package/dist/host/auth/jwt.js +4 -0
  60. package/dist/host/auth/jwt.js.map +1 -0
  61. package/dist/host/auth/mtls.d.ts +8 -0
  62. package/dist/host/auth/mtls.d.ts.map +1 -0
  63. package/dist/host/auth/mtls.js +34 -0
  64. package/dist/host/auth/mtls.js.map +1 -0
  65. package/dist/host/auth/none.d.ts +3 -0
  66. package/dist/host/auth/none.d.ts.map +1 -0
  67. package/dist/host/auth/none.js +13 -0
  68. package/dist/host/auth/none.js.map +1 -0
  69. package/dist/host/command.d.ts +22 -0
  70. package/dist/host/command.d.ts.map +1 -0
  71. package/dist/host/command.js +61 -0
  72. package/dist/host/command.js.map +1 -0
  73. package/dist/host/local.d.ts +4 -0
  74. package/dist/host/local.d.ts.map +1 -0
  75. package/dist/host/local.js +52 -0
  76. package/dist/host/local.js.map +1 -0
  77. package/dist/host/unix.d.ts +11 -0
  78. package/dist/host/unix.d.ts.map +1 -0
  79. package/dist/host/unix.js +39 -0
  80. package/dist/host/unix.js.map +1 -0
  81. package/dist/host/websocket.d.ts +13 -0
  82. package/dist/host/websocket.d.ts.map +1 -0
  83. package/dist/host/websocket.js +36 -0
  84. package/dist/host/websocket.js.map +1 -0
  85. package/dist/host/worker.d.ts +4 -0
  86. package/dist/host/worker.d.ts.map +1 -0
  87. package/dist/host/worker.js +52 -0
  88. package/dist/host/worker.js.map +1 -0
  89. package/dist/importer-D7zSgqxq.js +347 -0
  90. package/dist/index.d.ts +29 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +86 -0
  93. package/dist/index.js.map +1 -0
  94. package/dist/internal/Certificates.js +182 -0
  95. package/dist/internal/Certificates.js.map +1 -0
  96. package/dist/internal/FailureGroup.js +55 -0
  97. package/dist/internal/FailureGroup.js.map +1 -0
  98. package/dist/internal/Limits.d.ts +1 -0
  99. package/dist/internal/Limits.js +17 -0
  100. package/dist/internal/Limits.js.map +1 -0
  101. package/dist/internal/Peer.js +6 -0
  102. package/dist/internal/Peer.js.map +1 -0
  103. package/dist/internal/ServeLifecycle.js +26 -0
  104. package/dist/internal/ServeLifecycle.js.map +1 -0
  105. package/dist/internal/Supervisor.js +7 -0
  106. package/dist/internal/Supervisor.js.map +1 -0
  107. package/dist/internal/assembly.d.ts +5 -0
  108. package/dist/internal/assembly.js +138 -0
  109. package/dist/internal/assembly.js.map +1 -0
  110. package/dist/internal/auth/mtls.js +23 -0
  111. package/dist/internal/auth/mtls.js.map +1 -0
  112. package/dist/internal/auth/token.js +19 -0
  113. package/dist/internal/auth/token.js.map +1 -0
  114. package/dist/internal/auth/tokenCredentials.d.ts +8 -0
  115. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -0
  116. package/dist/internal/auth/tokenCredentials.js +33 -0
  117. package/dist/internal/auth/tokenCredentials.js.map +1 -0
  118. package/dist/internal/child.js +125 -0
  119. package/dist/internal/child.js.map +1 -0
  120. package/dist/internal/childErrors.d.ts +33 -0
  121. package/dist/internal/childErrors.d.ts.map +1 -0
  122. package/dist/internal/childErrors.js +29 -0
  123. package/dist/internal/childErrors.js.map +1 -0
  124. package/dist/internal/childRuntime.js +59 -0
  125. package/dist/internal/childRuntime.js.map +1 -0
  126. package/dist/internal/cleanup.js +15 -0
  127. package/dist/internal/cleanup.js.map +1 -0
  128. package/dist/internal/config.js +6 -0
  129. package/dist/internal/config.js.map +1 -0
  130. package/dist/internal/control.js +42 -0
  131. package/dist/internal/control.js.map +1 -0
  132. package/dist/internal/credentials.d.ts +44 -0
  133. package/dist/internal/credentials.d.ts.map +1 -0
  134. package/dist/internal/credentials.js +54 -0
  135. package/dist/internal/credentials.js.map +1 -0
  136. package/dist/internal/directTransport.d.ts +3 -0
  137. package/dist/internal/directTransport.js +7 -0
  138. package/dist/internal/directTransport.js.map +1 -0
  139. package/dist/internal/entry.d.ts +9 -0
  140. package/dist/internal/entry.d.ts.map +1 -0
  141. package/dist/internal/entry.js +144 -0
  142. package/dist/internal/entry.js.map +1 -0
  143. package/dist/internal/entryConfig.d.ts +202 -0
  144. package/dist/internal/entryConfig.d.ts.map +1 -0
  145. package/dist/internal/entryConfig.js +176 -0
  146. package/dist/internal/entryConfig.js.map +1 -0
  147. package/dist/internal/execution.d.ts +5 -0
  148. package/dist/internal/execution.js +43 -0
  149. package/dist/internal/execution.js.map +1 -0
  150. package/dist/internal/follow.js +11 -0
  151. package/dist/internal/follow.js.map +1 -0
  152. package/dist/internal/forkTree.js +7 -0
  153. package/dist/internal/forkTree.js.map +1 -0
  154. package/dist/internal/host/local.js +28 -0
  155. package/dist/internal/host/local.js.map +1 -0
  156. package/dist/internal/host/runner.js +100 -0
  157. package/dist/internal/host/runner.js.map +1 -0
  158. package/dist/internal/host.js +71 -0
  159. package/dist/internal/host.js.map +1 -0
  160. package/dist/internal/importer.js +18 -0
  161. package/dist/internal/importer.js.map +1 -0
  162. package/dist/internal/listenerStartup.js +17 -0
  163. package/dist/internal/listenerStartup.js.map +1 -0
  164. package/dist/internal/loadModule.js +20 -0
  165. package/dist/internal/loadModule.js.map +1 -0
  166. package/dist/internal/platform.js +9 -0
  167. package/dist/internal/platform.js.map +1 -0
  168. package/dist/internal/port.d.ts +13 -0
  169. package/dist/internal/port.d.ts.map +1 -0
  170. package/dist/internal/port.js +275 -0
  171. package/dist/internal/port.js.map +1 -0
  172. package/dist/internal/release.js +25 -0
  173. package/dist/internal/release.js.map +1 -0
  174. package/dist/internal/runner/Bootstrap.js +11 -0
  175. package/dist/internal/runner/Bootstrap.js.map +1 -0
  176. package/dist/internal/runner/Connection.d.ts +11 -0
  177. package/dist/internal/runner/Connection.js +56 -0
  178. package/dist/internal/runner/Connection.js.map +1 -0
  179. package/dist/internal/runner/Execution.js +115 -0
  180. package/dist/internal/runner/Execution.js.map +1 -0
  181. package/dist/internal/runner/Framing.d.ts +11 -0
  182. package/dist/internal/runner/Framing.d.ts.map +1 -0
  183. package/dist/internal/runner/Framing.js +63 -0
  184. package/dist/internal/runner/Framing.js.map +1 -0
  185. package/dist/internal/runner/Local.js +46 -0
  186. package/dist/internal/runner/Local.js.map +1 -0
  187. package/dist/internal/runner/Lock.js +25 -0
  188. package/dist/internal/runner/Lock.js.map +1 -0
  189. package/dist/internal/runner/Multiplex.d.ts +5 -0
  190. package/dist/internal/runner/Multiplex.js +49 -0
  191. package/dist/internal/runner/Multiplex.js.map +1 -0
  192. package/dist/internal/runner/Packages.d.ts +3 -0
  193. package/dist/internal/runner/Packages.js +108 -0
  194. package/dist/internal/runner/Packages.js.map +1 -0
  195. package/dist/internal/runner/ProcessObservation.js +40 -0
  196. package/dist/internal/runner/ProcessObservation.js.map +1 -0
  197. package/dist/internal/runner/Processes.js +83 -0
  198. package/dist/internal/runner/Processes.js.map +1 -0
  199. package/dist/internal/runner/Retention.js +13 -0
  200. package/dist/internal/runner/Retention.js.map +1 -0
  201. package/dist/internal/runner/Store.js +78 -0
  202. package/dist/internal/runner/Store.js.map +1 -0
  203. package/dist/internal/runner/Supervisor.js +375 -0
  204. package/dist/internal/runner/Supervisor.js.map +1 -0
  205. package/dist/internal/runner/Watchdog.js +47 -0
  206. package/dist/internal/runner/Watchdog.js.map +1 -0
  207. package/dist/internal/runner/WatchdogProtocol.js +19 -0
  208. package/dist/internal/runner/WatchdogProtocol.js.map +1 -0
  209. package/dist/internal/runner/Wire.d.ts +5 -0
  210. package/dist/internal/runner/Wire.js +64 -0
  211. package/dist/internal/runner/Wire.js.map +1 -0
  212. package/dist/internal/runner/accept.js +57 -0
  213. package/dist/internal/runner/accept.js.map +1 -0
  214. package/dist/internal/runner/command.js +9 -0
  215. package/dist/internal/runner/command.js.map +1 -0
  216. package/dist/internal/runner/connectionEnded.js +11 -0
  217. package/dist/internal/runner/connectionEnded.js.map +1 -0
  218. package/dist/internal/runner/model.d.ts +17 -0
  219. package/dist/internal/runner/model.d.ts.map +1 -0
  220. package/dist/internal/runner/model.js +231 -0
  221. package/dist/internal/runner/model.js.map +1 -0
  222. package/dist/internal/serve.js +60 -0
  223. package/dist/internal/serve.js.map +1 -0
  224. package/dist/internal/services.d.ts +18 -0
  225. package/dist/internal/services.d.ts.map +1 -0
  226. package/dist/internal/services.js +22 -0
  227. package/dist/internal/services.js.map +1 -0
  228. package/dist/internal/socketChannel.js +24 -0
  229. package/dist/internal/socketChannel.js.map +1 -0
  230. package/dist/internal/stdioChannel.js +23 -0
  231. package/dist/internal/stdioChannel.js.map +1 -0
  232. package/dist/internal/supervisorPlugin.js +1 -0
  233. package/dist/internal/supervisorPlugin.js.map +1 -0
  234. package/dist/internal/transportOptions.d.ts +18 -0
  235. package/dist/internal/transportOptions.d.ts.map +1 -0
  236. package/dist/internal/watchdogMain.d.ts +1 -0
  237. package/dist/internal/watchdogMain.js +55 -0
  238. package/dist/internal/watchdogMain.js.map +1 -0
  239. package/dist/internal/websocket.js +46 -0
  240. package/dist/internal/websocket.js.map +1 -0
  241. package/dist/internal/websocketServer.js +61 -0
  242. package/dist/internal/websocketServer.js.map +1 -0
  243. package/dist/internal/workerBootstrap.js +9 -0
  244. package/dist/internal/workerBootstrap.js.map +1 -0
  245. package/dist/internal/workerChannel.js +24 -0
  246. package/dist/internal/workerChannel.js.map +1 -0
  247. package/dist/internal/workerMain.d.ts +1 -0
  248. package/dist/internal/workerMain.js +18 -0
  249. package/dist/internal/workerMain.js.map +1 -0
  250. package/dist/port-Blbh8tms.js +285 -0
  251. package/dist/release-BY4Mlluy.js +23 -0
  252. package/dist/rolldown-runtime-DYf_mQCB.js +34 -0
  253. package/dist/runner/auth/bearer.d.ts +7 -0
  254. package/dist/runner/auth/bearer.d.ts.map +1 -0
  255. package/dist/runner/auth/bearer.js +42 -0
  256. package/dist/runner/auth/bearer.js.map +1 -0
  257. package/dist/runner/auth/jwt.d.ts +19 -0
  258. package/dist/runner/auth/jwt.d.ts.map +1 -0
  259. package/dist/runner/auth/jwt.js +65 -0
  260. package/dist/runner/auth/jwt.js.map +1 -0
  261. package/dist/runner/auth/mtls.d.ts +11 -0
  262. package/dist/runner/auth/mtls.d.ts.map +1 -0
  263. package/dist/runner/auth/mtls.js +48 -0
  264. package/dist/runner/auth/mtls.js.map +1 -0
  265. package/dist/runner/auth/none.d.ts +3 -0
  266. package/dist/runner/auth/none.d.ts.map +1 -0
  267. package/dist/runner/auth/none.js +13 -0
  268. package/dist/runner/auth/none.js.map +1 -0
  269. package/dist/runner/index.d.ts +3 -0
  270. package/dist/runner/index.d.ts.map +1 -0
  271. package/dist/runner/index.js +71 -0
  272. package/dist/runner/index.js.map +1 -0
  273. package/dist/runner/stdio.d.ts +7 -0
  274. package/dist/runner/stdio.d.ts.map +1 -0
  275. package/dist/runner/stdio.js +39 -0
  276. package/dist/runner/stdio.js.map +1 -0
  277. package/dist/runner/unix.d.ts +7 -0
  278. package/dist/runner/unix.d.ts.map +1 -0
  279. package/dist/runner/unix.js +42 -0
  280. package/dist/runner/unix.js.map +1 -0
  281. package/dist/runner/websocket.d.ts +28 -0
  282. package/dist/runner/websocket.d.ts.map +1 -0
  283. package/dist/runner/websocket.js +77 -0
  284. package/dist/runner/websocket.js.map +1 -0
  285. package/dist/socketChannel-KmtzF-9G.js +3658 -0
  286. package/dist/supervisorPlugin-Inb1S5IV.js +737 -0
  287. package/dist/token-v5ne2I0-.js +17 -0
  288. package/dist/tokenCredentials-WUJm2AKm.js +31 -0
  289. package/dist/websocketServer-MXcCJx0v.js +58 -0
  290. package/dist/workerChannel-P82YdNjh.js +27 -0
  291. package/package.json +69 -3
  292. package/src/Auth.ts +62 -0
  293. package/src/Contract.ts +100 -0
  294. package/src/Errors.ts +82 -0
  295. package/src/Instance.ts +12 -0
  296. package/src/Testing.ts +135 -0
  297. package/src/Transport.ts +52 -0
  298. package/src/bin.ts +145 -0
  299. package/src/host/auth/bearer.ts +10 -0
  300. package/src/host/auth/jwt.ts +10 -0
  301. package/src/host/auth/mtls.ts +48 -0
  302. package/src/host/auth/none.ts +13 -0
  303. package/src/host/command.ts +131 -0
  304. package/src/host/local.ts +41 -0
  305. package/src/host/unix.ts +65 -0
  306. package/src/host/websocket.ts +66 -0
  307. package/src/host/worker.ts +90 -0
  308. package/src/index.ts +115 -0
  309. package/src/internal/Certificates.ts +330 -0
  310. package/src/internal/FailureGroup.ts +176 -0
  311. package/src/internal/Limits.ts +12 -0
  312. package/src/internal/Peer.ts +4 -0
  313. package/src/internal/ServeLifecycle.ts +53 -0
  314. package/src/internal/Supervisor.ts +14 -0
  315. package/src/internal/assembly.ts +337 -0
  316. package/src/internal/auth/mtls.ts +40 -0
  317. package/src/internal/auth/token.ts +26 -0
  318. package/src/internal/auth/tokenCredentials.ts +65 -0
  319. package/src/internal/child.ts +323 -0
  320. package/src/internal/childErrors.ts +44 -0
  321. package/src/internal/childRuntime.ts +111 -0
  322. package/src/internal/cleanup.ts +34 -0
  323. package/src/internal/config.ts +8 -0
  324. package/src/internal/control.ts +49 -0
  325. package/src/internal/credentials.ts +112 -0
  326. package/src/internal/directTransport.ts +38 -0
  327. package/src/internal/entry.ts +288 -0
  328. package/src/internal/entryConfig.ts +190 -0
  329. package/src/internal/execution.ts +121 -0
  330. package/src/internal/follow.ts +17 -0
  331. package/src/internal/forkTree.ts +13 -0
  332. package/src/internal/host/local.ts +53 -0
  333. package/src/internal/host/runner.ts +187 -0
  334. package/src/internal/host.ts +209 -0
  335. package/src/internal/importer.ts +27 -0
  336. package/src/internal/listenerStartup.ts +55 -0
  337. package/src/internal/loadModule.ts +23 -0
  338. package/src/internal/platform.ts +12 -0
  339. package/src/internal/port.ts +623 -0
  340. package/src/internal/release.ts +71 -0
  341. package/src/internal/runner/Bootstrap.ts +9 -0
  342. package/src/internal/runner/Connection.ts +184 -0
  343. package/src/internal/runner/Execution.ts +244 -0
  344. package/src/internal/runner/Framing.ts +122 -0
  345. package/src/internal/runner/Local.ts +73 -0
  346. package/src/internal/runner/Lock.ts +29 -0
  347. package/src/internal/runner/Multiplex.ts +120 -0
  348. package/src/internal/runner/Packages.ts +178 -0
  349. package/src/internal/runner/ProcessObservation.ts +63 -0
  350. package/src/internal/runner/Processes.ts +109 -0
  351. package/src/internal/runner/Retention.ts +49 -0
  352. package/src/internal/runner/Store.ts +160 -0
  353. package/src/internal/runner/Supervisor.ts +901 -0
  354. package/src/internal/runner/Watchdog.ts +83 -0
  355. package/src/internal/runner/WatchdogProtocol.ts +12 -0
  356. package/src/internal/runner/Wire.ts +99 -0
  357. package/src/internal/runner/accept.ts +103 -0
  358. package/src/internal/runner/command.ts +15 -0
  359. package/src/internal/runner/connectionEnded.ts +28 -0
  360. package/src/internal/runner/model.ts +364 -0
  361. package/src/internal/serve.ts +117 -0
  362. package/src/internal/services.ts +74 -0
  363. package/src/internal/socketChannel.ts +64 -0
  364. package/src/internal/stdioChannel.ts +25 -0
  365. package/src/internal/supervisorPlugin.ts +67 -0
  366. package/src/internal/transportOptions.ts +17 -0
  367. package/src/internal/watchdogMain.ts +72 -0
  368. package/src/internal/websocket.ts +81 -0
  369. package/src/internal/websocketServer.ts +152 -0
  370. package/src/internal/workerBootstrap.ts +6 -0
  371. package/src/internal/workerChannel.ts +54 -0
  372. package/src/internal/workerMain.ts +23 -0
  373. package/src/runner/auth/bearer.ts +66 -0
  374. package/src/runner/auth/jwt.ts +114 -0
  375. package/src/runner/auth/mtls.ts +37 -0
  376. package/src/runner/auth/none.ts +13 -0
  377. package/src/runner/index.ts +97 -0
  378. package/src/runner/stdio.ts +76 -0
  379. package/src/runner/unix.ts +53 -0
  380. package/src/runner/websocket.ts +143 -0
@@ -0,0 +1,708 @@
1
+ import { c as isPlugin, i as plugin, l as make, o as fork, t as forks, u as optional } from "./Graft-BsYq3F-J.js";
2
+ import { t as ConfigDirectory } from "./ConfigDirectory-BCC6q2R4.js";
3
+ import { i as make$2, m as isSubtreeActive, n as ModuleInvalid, o as CurrentId, p as findSubtree, r as ModuleResolver, t as make$1 } from "./importer-D7zSgqxq.js";
4
+ import { c as endpoint, n as UndeclaredFailure, o as endpoints, r as fromModule } from "./Contract-CcpSIJm4.js";
5
+ import { a as ProcessExited, c as TransportError, i as MissingInstance, o as RemoteError, r as LocalTerminationTimeout, s as RemoteWithdrawn, t as AuthenticationFailed } from "./Errors-oPsTLY7l.js";
6
+ import { n as WorkerTransport, t as LocalTransport } from "./directTransport-DrexuPSm.js";
7
+ import { a as PositiveDuration, i as Supervisor, n as resolveEntry, r as verify } from "./Packages-B1TPk8pa.js";
8
+ import { E as make$3, b as awaitTermination, n as Session, r as channel, t as Peer, x as childOf } from "./Peer-IJgFK6mD.js";
9
+ import { n as Credentials, t as Authenticator } from "./Auth-BElTC9_X.js";
10
+ import { n as Listener, t as Connector } from "./Transport-DULzpsgR.js";
11
+ import { n as connectionEnded, t as closedNormally } from "./connectionEnded-DUgcobEd.js";
12
+ import { t as ServeLifecycle } from "./ServeLifecycle-CJM0gG5B.js";
13
+ import { t as make$4 } from "./FailureGroup-BcH0XOBi.js";
14
+ import { n as cleanupCause, t as children } from "./cleanup-BPWr-5U9.js";
15
+ import { n as make$5, o as defaults } from "./port-Blbh8tms.js";
16
+ import { n as close } from "./release-BY4Mlluy.js";
17
+ import { n as stdinExitTimeout } from "./ProcessObservation-DEGrEMfP.js";
18
+ import { Array, Cause, Context, Deferred, Duration, Effect, Exit, Fiber, Option, Path, Ref, References, Schema, Scope, Stream, String } from "effect";
19
+ import { SecureRandom } from "effect/crypto";
20
+ import { RpcClient } from "effect/rpc";
21
+ import { ChildProcessSpawner } from "effect/process";
22
+ // packages/remote/src/internal/entryConfig.ts
23
+ const Reference = Schema.Struct({
24
+ name: Schema.String,
25
+ config: Schema.optionalKey(Schema.Unknown)
26
+ });
27
+ const absent = Schema.optionalKey(Schema.Never);
28
+ const authFields = {
29
+ name: absent,
30
+ config: absent,
31
+ mtls: absent,
32
+ bearer: absent,
33
+ jwt: absent,
34
+ none: absent
35
+ };
36
+ const Authentication = Schema.Union([
37
+ Schema.Struct({
38
+ ...authFields,
39
+ name: Schema.String,
40
+ config: Schema.optionalKey(Schema.Unknown)
41
+ }),
42
+ Schema.Struct({
43
+ ...authFields,
44
+ mtls: Schema.Unknown
45
+ }),
46
+ Schema.Struct({
47
+ ...authFields,
48
+ bearer: Schema.Unknown
49
+ }),
50
+ Schema.Struct({
51
+ ...authFields,
52
+ jwt: Schema.Unknown
53
+ }),
54
+ Schema.Struct({
55
+ ...authFields,
56
+ none: Schema.Unknown
57
+ })
58
+ ]);
59
+ const transportFields = {
60
+ url: absent,
61
+ unix: absent,
62
+ command: absent,
63
+ stdio: absent,
64
+ local: absent,
65
+ worker: absent,
66
+ transport: absent
67
+ };
68
+ const auth = Schema.optionalKey(Authentication);
69
+ const common = {
70
+ instance: Schema.optionalKey(Schema.String),
71
+ lease: Schema.optionalKey(PositiveDuration),
72
+ margin: Schema.optionalKey(PositiveDuration),
73
+ expect: Schema.optionalKey(Schema.Struct({
74
+ version: Schema.optionalKey(Schema.String),
75
+ digest: Schema.optionalKey(Schema.String)
76
+ }))
77
+ };
78
+ const network = {
79
+ ...transportFields,
80
+ ...common,
81
+ auth,
82
+ url: Schema.String,
83
+ ca: Schema.optionalKey(Schema.String),
84
+ servername: Schema.optionalKey(Schema.String)
85
+ };
86
+ const Connect = Schema.Union([
87
+ Schema.Struct(network),
88
+ Schema.Struct({
89
+ ...transportFields,
90
+ ...common,
91
+ auth,
92
+ unix: Schema.String
93
+ }),
94
+ Schema.Struct({
95
+ ...transportFields,
96
+ ...common,
97
+ command: Schema.NonEmptyArray(Schema.String),
98
+ auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
99
+ cwd: Schema.optionalKey(Schema.String),
100
+ env: Schema.optionalKey(Schema.Record(Schema.String, Schema.String))
101
+ }),
102
+ Schema.Struct({
103
+ ...transportFields,
104
+ auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
105
+ local: Schema.Struct({ command: Schema.optionalKey(Schema.NonEmptyArray(Schema.String)) })
106
+ }),
107
+ Schema.Struct({
108
+ ...transportFields,
109
+ auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
110
+ worker: Schema.Struct({ execArgv: Schema.optionalKey(Schema.Array(Schema.String)) })
111
+ }),
112
+ Schema.Struct({
113
+ ...transportFields,
114
+ ...common,
115
+ auth,
116
+ transport: Reference
117
+ })
118
+ ]);
119
+ const Listen = Schema.Union([
120
+ Schema.Struct({
121
+ ...transportFields,
122
+ auth,
123
+ url: Schema.String,
124
+ cert: Schema.optionalKey(Schema.String),
125
+ key: Schema.optionalKey(Schema.String)
126
+ }),
127
+ Schema.Struct({
128
+ ...transportFields,
129
+ auth,
130
+ unix: Schema.String
131
+ }),
132
+ Schema.Struct({
133
+ ...transportFields,
134
+ stdio: Schema.Literal(true),
135
+ auth: Schema.optionalKey(Schema.Never.annotate({ message: "Direct and stdio transports do not accept auth" })),
136
+ identity: Schema.optionalKey(Schema.String)
137
+ }),
138
+ Schema.Struct({
139
+ ...transportFields,
140
+ auth,
141
+ transport: Reference
142
+ })
143
+ ]);
144
+ const capability = (side, name, config) => ({
145
+ name: `@graftland/plugin-remote/${side}/${name}`,
146
+ config
147
+ });
148
+ const authentication = (side, input) => {
149
+ if (input === void 0) return capability(side, "auth/none", {});
150
+ if (input.name !== void 0) return input;
151
+ if (input.mtls !== void 0) return capability(side, "auth/mtls", input.mtls);
152
+ if (input.bearer !== void 0) return capability(side, "auth/bearer", input.bearer);
153
+ if (input.jwt !== void 0) return capability(side, "auth/jwt", input.jwt);
154
+ return capability(side, "auth/none", input.none);
155
+ };
156
+ const hostTransport = (input) => {
157
+ if (input.transport !== void 0) return input.transport;
158
+ if (input.url !== void 0) return capability("host", "websocket", {
159
+ url: input.url,
160
+ ...input.ca === void 0 ? {} : { ca: input.ca },
161
+ ...input.servername === void 0 ? {} : { servername: input.servername }
162
+ });
163
+ if (input.unix !== void 0) return capability("host", "unix", { path: input.unix });
164
+ return capability("host", "command", {
165
+ argv: input.command,
166
+ ..."cwd" in input && input.cwd !== void 0 ? { cwd: input.cwd } : {},
167
+ ..."env" in input && input.env !== void 0 ? { env: input.env } : {}
168
+ });
169
+ };
170
+ const runnerTransport = (input) => {
171
+ if (input.transport !== void 0) return input.transport;
172
+ if (input.url !== void 0) return capability("runner", "websocket", {
173
+ url: input.url,
174
+ ...input.cert === void 0 ? {} : { cert: input.cert },
175
+ ...input.key === void 0 ? {} : { key: input.key }
176
+ });
177
+ if (input.unix !== void 0) return capability("runner", "unix", { path: input.unix });
178
+ return capability("runner", "stdio", {});
179
+ };
180
+ const Host = Schema.Struct({
181
+ contract: Schema.String,
182
+ connect: Connect,
183
+ config: Schema.Json.pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
184
+ });
185
+ const Runner = Schema.Struct({
186
+ root: Schema.String,
187
+ state: Schema.String,
188
+ lease: Schema.optionalKey(PositiveDuration),
189
+ grace: Schema.optionalKey(PositiveDuration),
190
+ listen: Schema.Array(Listen)
191
+ });
192
+ const runnerAuthentication = (input) => input.stdio !== void 0 ? capability("runner", "auth/none", { identity: input.identity ?? "anonymous" }) : authentication("runner", input.auth);
193
+ // packages/remote/src/internal/follow.ts
194
+ /** Follow startup and later failures without changing the caller's error boundary. */
195
+ const follow = Effect.fnUntraced(function* (fork$1, fail) {
196
+ yield* fork$1.await.pipe(Effect.catchCause(fail));
197
+ yield* fork(fork$1.state.pipe(Stream.runForEach((state) => state._tag === "Failed" ? fail(state.cause) : Effect.void)));
198
+ });
199
+ // packages/remote/src/internal/assembly.ts
200
+ var ListenerConfigError = class extends Schema.TaggedError()("ListenerConfigError", { detail: Schema.String }) {
201
+ get message() {
202
+ return this.detail;
203
+ }
204
+ };
205
+ var CapabilityContractError = class extends Schema.TaggedError()("CapabilityContractError", {
206
+ plugin: Schema.String,
207
+ key: Schema.String
208
+ }) {
209
+ get message() {
210
+ return `Capability ${this.plugin} became active without providing ${this.key}`;
211
+ }
212
+ };
213
+ var CapabilityCombinationError = class extends Schema.TaggedError()("CapabilityCombinationError", { detail: Schema.String }) {
214
+ get message() {
215
+ return this.detail;
216
+ }
217
+ };
218
+ var CapabilityFailed = class extends Schema.TaggedError()("CapabilityFailed", { cause: Schema.Cause(Schema.Unknown, Schema.Unknown) }) {};
219
+ const definition = Schema.declare(isPlugin);
220
+ /** Entries resolve capability modules before assembling their private providers. */
221
+ const Invocation = Schema.Struct({
222
+ plugin: definition,
223
+ config: Schema.Unknown
224
+ });
225
+ const Input = Schema.Struct({
226
+ transport: Invocation,
227
+ auth: Invocation,
228
+ consumer: definition,
229
+ input: Schema.optionalKey(Schema.Unknown)
230
+ });
231
+ const failure = (tree) => tree.state._tag === "Failed" ? Effect.fail(CapabilityFailed.make({ cause: tree.state.cause })) : Effect.forEach(tree.children, failure, { discard: true });
232
+ const probe = (name, key) => make({
233
+ name: "remote-capability-contract",
234
+ inject: [optional(key)],
235
+ apply: Effect.fnUntraced(function* () {
236
+ const value = yield* Effect.serviceOption(key);
237
+ if (Option.isNone(value)) return yield* CapabilityContractError.make({
238
+ plugin: name,
239
+ key: key.key
240
+ });
241
+ })
242
+ });
243
+ /** Resolve the key in a fresh consumer after the provider subtree settles.
244
+ * An optional consumer started earlier could still hold a pre-publication snapshot.
245
+ */
246
+ const watch = (provider, key) => fork(forks.pipe(Stream.map((trees) => findSubtree(trees, provider.id)), Stream.filter(Option.isSome), Stream.map((tree) => tree.value), Stream.tap(failure), Stream.map((tree) => ({
247
+ name: tree.name,
248
+ active: isSubtreeActive(tree)
249
+ })), Stream.changesWith((left, right) => left.active === right.active), Stream.filter((tree) => tree.active), Stream.runForEach((tree) => Effect.scoped(plugin(probe(tree.name, key)).pipe(Effect.flatMap((fork) => fork.await))))));
250
+ const assembly = (keys) => make({
251
+ name: "remote-assembly",
252
+ config: Input,
253
+ apply: Effect.fnUntraced(function* (input) {
254
+ yield* Effect.forEach([{
255
+ invocation: input.transport,
256
+ key: keys[0]
257
+ }, {
258
+ invocation: input.auth,
259
+ key: keys[1]
260
+ }], Effect.fnUntraced(function* ({ invocation, key }) {
261
+ const provider = yield* plugin(invocation.plugin, invocation.config);
262
+ yield* watch(provider, key);
263
+ }));
264
+ const consumer = yield* plugin(input.consumer, input.input);
265
+ yield* consumer.state.pipe(Stream.filter((state) => state._tag !== "Loading" && (state._tag !== "Pending" || !Array.some(keys, (key) => Array.contains(state.missing, key.key)))), Stream.runHead);
266
+ yield* follow(consumer, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
267
+ })
268
+ });
269
+ const hostAssembly = assembly([Connector, Credentials]);
270
+ const runnerAssembly = assembly([Listener, Authenticator]);
271
+ const host$1 = (input) => plugin(hostAssembly, input, { isolate: [Connector, Credentials] });
272
+ const runner = (input, consumer = listenerConsumer) => plugin(runnerAssembly, {
273
+ ...input,
274
+ consumer
275
+ }, { isolate: [Listener, Authenticator] });
276
+ const compatible = (properties, kind) => {
277
+ if (kind === "Certificate" && (properties.protocol !== "wss" || !properties.encrypted || !Array.contains(properties.carries, "certificate"))) return Effect.fail(CapabilityCombinationError.make({ detail: "Mutual TLS requires encrypted wss with certificate evidence" }));
278
+ if (kind === "Authorization" && !Array.contains(properties.carries, "header")) return Effect.fail(CapabilityCombinationError.make({ detail: "This transport cannot carry Authorization headers" }));
279
+ return Effect.void;
280
+ };
281
+ const kind = (auth) => auth._tag === "Mtls" ? "Certificate" : auth._tag === "Header" ? "Authorization" : "None";
282
+ const warn = (properties, credentials, side) => Effect.all([properties.network && !properties.encrypted ? Effect.logWarning(credentials === "Authorization" ? `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted; credentials are transmitted in plaintext` : `${properties.protocol}:// ${side === "host" ? "connection" : "listener"} is unencrypted`) : Effect.void, side === "runner" && properties.network && credentials === "None" ? Effect.logWarning("WebSocket listener has no authentication") : Effect.void], { discard: true });
283
+ const directAuth = (properties, explicit) => explicit && (properties.protocol === "stdio" || properties.protocol === "command") ? Effect.fail(CapabilityCombinationError.make({ detail: `${properties.protocol} transports do not accept auth` })) : Effect.void;
284
+ const connectWith = (explicitAuth = false) => Effect.gen(function* () {
285
+ const connector = yield* Connector;
286
+ const credentials = yield* Credentials;
287
+ yield* directAuth(connector.properties, explicitAuth);
288
+ yield* compatible(connector.properties, credentials.kind);
289
+ yield* warn(connector.properties, credentials.kind, "host");
290
+ const prepared = yield* credentials.read;
291
+ return yield* connector.connect(prepared);
292
+ });
293
+ const accept = (auth, properties, session) => (handshake) => {
294
+ return (auth._tag === "Header" ? auth.authenticate(handshake.authorization) : auth._tag === "Mtls" ? Option.match(handshake.certificate, {
295
+ onNone: () => Effect.fail(AuthenticationFailed.make({ reason: "missing" })),
296
+ onSome: auth.authenticate
297
+ }) : (properties.network ? Effect.logWarning("WebSocket connection has no authentication") : Effect.void).pipe(Effect.as(auth.identity))).pipe(Effect.map(session));
298
+ };
299
+ const makeListenerConsumer = (prepare = () => Effect.void, ready = Effect.void) => make({
300
+ name: "remote-listener-consumer",
301
+ inject: [
302
+ Listener,
303
+ Authenticator,
304
+ Supervisor,
305
+ optional(ServeLifecycle)
306
+ ],
307
+ apply: Effect.fnUntraced(function* () {
308
+ const listener = yield* Listener;
309
+ const auth = yield* Authenticator;
310
+ const supervisor = yield* Supervisor;
311
+ const lifecycle = yield* Effect.serviceOption(ServeLifecycle);
312
+ yield* prepare(listener.properties, auth);
313
+ yield* compatible(listener.properties, kind(auth)).pipe(Effect.mapError((error) => ListenerConfigError.make({ detail: error.detail })));
314
+ yield* warn(listener.properties, kind(auth), "runner");
315
+ const serving = yield* listener.bind(auth._tag === "Mtls" ? Option.some(auth.tls) : Option.none());
316
+ const running = yield* fork(serving.serve(accept(auth, listener.properties, (identity) => (channel) => supervisor.accept(channel).pipe(Effect.catchCause((cause) => listener.properties.protocol === "stdio" ? closedNormally(cause) ? Effect.void : Effect.failCause(cause) : connectionEnded(cause)), Effect.provideService(Peer, identity)))).pipe(Effect.onExit((exit) => listener.properties.protocol === "stdio" && Option.isSome(lifecycle) ? Deferred.done(lifecycle.value.ended, exit) : Effect.void)));
317
+ yield* serving.ready.pipe(Effect.raceFirst(Fiber.join(running)));
318
+ yield* ready;
319
+ })
320
+ });
321
+ const listenerConsumer = makeListenerConsumer();
322
+ connectWith();
323
+ // packages/remote/src/internal/host/runner.ts
324
+ const connect$1 = (target, contractModule, options, resources, processScope) => Effect.gen(function* () {
325
+ const instance = target.instance;
326
+ const margin = Duration.toMillis(target.margin ?? "5 seconds");
327
+ const channel$1 = yield* connectWith(target.explicitAuth).pipe(Scope.provide(processScope));
328
+ const mux = yield* make$3(channel$1).pipe(Scope.provide(resources));
329
+ const control = yield* make$5(channel(mux, 0), {
330
+ session: "session-v1",
331
+ serve: {},
332
+ call: { session: Session }
333
+ }).pipe(Scope.provide(resources));
334
+ const session = yield* RpcClient.make(Session).pipe(Effect.provideService(RpcClient.Protocol, control.clientProtocol("session")), Scope.provide(resources));
335
+ const expectedGeneration = yield* session.HighWater({ instance });
336
+ const record = yield* session.Open({
337
+ instance,
338
+ expectedGeneration,
339
+ requestId: options.session,
340
+ limits: defaults,
341
+ ...target.lease === void 0 ? {} : { leaseMillis: Duration.toMillis(target.lease) }
342
+ });
343
+ const failures = yield* make$4().pipe(Scope.provide(resources));
344
+ const finishStarted = yield* Ref.make(false);
345
+ const terminate = yield* Effect.cached(Effect.gen(function* () {
346
+ yield* Ref.set(finishStarted, true);
347
+ yield* failures.close;
348
+ const result = yield* awaitTermination(record.handle, session.Dispose(record.handle), record.leaseMillis, margin);
349
+ const { code, signal, stderr, cause } = result.exit;
350
+ yield* Effect.logInfo("Remote execution terminated", {
351
+ code,
352
+ ...signal === null ? {} : { signal },
353
+ ...stderr === void 0 || stderr === "" ? {} : { stderr },
354
+ ...cause === void 0 || cause.reasons.length === 0 ? {} : { cause }
355
+ }).pipe(Effect.annotateLogs({
356
+ "remote.instance": record.handle.key.instance,
357
+ "remote.generation": record.handle.generation,
358
+ "remote.termination": result.kind
359
+ }));
360
+ if (result.cause.reasons.length > 0) return yield* Effect.failCause(cleanupCause(result.cause));
361
+ }));
362
+ yield* Scope.addFinalizer(processScope, Effect.gen(function* () {
363
+ if (!(yield* Ref.get(finishStarted))) yield* terminate.pipe(Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))));
364
+ }));
365
+ const renewed = yield* Effect.forever(Effect.sleep(record.leaseMillis / 3).pipe(Effect.andThen(session.Renew(record.handle)))).pipe(Effect.forkIn(resources));
366
+ const code = yield* session.Load({
367
+ handle: record.handle,
368
+ specifier: contractModule,
369
+ digest: target.expect?.digest !== void 0
370
+ });
371
+ yield* verify(code, target.expect);
372
+ const loaded = yield* session.Status(record.handle);
373
+ const peer = yield* make$5(channel(mux, 1), {
374
+ ...options,
375
+ session: record.handle.token,
376
+ limits: record.limits
377
+ }).pipe(Scope.provide(resources));
378
+ const report = (cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : failures.failCause(Cause.map(cause, (error) => TransportError.make({ cause: Cause.fail(error) })));
379
+ yield* failures.await.pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : peer.fail(TransportError.make({ cause }))), Effect.forkIn(resources));
380
+ yield* failures.run(Fiber.join(renewed).pipe(Effect.catchCause((cause) => Effect.gen(function* () {
381
+ if (Cause.hasInterruptsOnly(cause)) return;
382
+ const status = yield* Effect.exit(session.Status(record.handle).pipe(Effect.timeout("5 seconds")));
383
+ if (Exit.isSuccess(status) && status.value.phase === "Stopped") {
384
+ const exit = status.value.termination.exit;
385
+ yield* report(Cause.combine(cause, Cause.fail(ProcessExited.make({
386
+ pid: Option.map(childOf(loaded), (child) => child.pid),
387
+ exitCode: exit.code,
388
+ stderr: exit.stderr ?? "",
389
+ statusCause: exit.cause ?? Cause.empty
390
+ }))));
391
+ } else yield* report(Exit.isFailure(status) ? Cause.combine(cause, status.cause) : cause);
392
+ }))));
393
+ return {
394
+ resources,
395
+ pid: Option.map(childOf(loaded), (child) => child.pid),
396
+ diagnostics: failures.cause,
397
+ terminate: () => Effect.gen(function* () {
398
+ yield* Fiber.interrupt(renewed);
399
+ yield* terminate;
400
+ }),
401
+ transport: {
402
+ ...peer,
403
+ failure: peer.await,
404
+ report
405
+ }
406
+ };
407
+ });
408
+ // packages/remote/src/internal/runner/Local.ts
409
+ /** Direct execution observers stay alive until exit, including forced cleanup. */
410
+ const connect = Effect.fnUntraced(function* (execution, options) {
411
+ const failures = yield* make$4();
412
+ const exited = yield* execution.exited.pipe(Effect.forkScoped);
413
+ const peer = yield* make$5(execution.channel, options);
414
+ yield* failures.run(Effect.raceFirst(peer.await, Fiber.join(exited).pipe(Effect.flatMap(Effect.fail))));
415
+ const report = (cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : failures.fail(TransportError.make({ cause })).pipe(Effect.andThen(peer.fail(TransportError.make({ cause }))));
416
+ yield* failures.run(execution.failure);
417
+ return {
418
+ ...peer,
419
+ pid: execution.pid,
420
+ ...execution.threadId === void 0 ? {} : { threadId: execution.threadId },
421
+ exited,
422
+ resources: yield* Effect.scope,
423
+ transport: {
424
+ ...peer,
425
+ failure: failures.await,
426
+ report
427
+ },
428
+ diagnostics: Fiber.await(exited).pipe(Effect.andThen(failures.cause)),
429
+ terminate: (graceful) => Effect.gen(function* () {
430
+ yield* failures.close;
431
+ if (!graceful) return;
432
+ const status = yield* peer.end.pipe(Effect.catchCauseIf(Cause.hasInterruptsOnly, () => Effect.void), Effect.andThen(Fiber.join(exited)), Effect.interruptible, Effect.timeoutOrElse({
433
+ duration: stdinExitTimeout,
434
+ orElse: () => LocalTerminationTimeout.make({
435
+ ...Option.match(execution.pid, {
436
+ onNone: () => ({}),
437
+ onSome: (pid) => ({ pid })
438
+ }),
439
+ ...execution.threadId === void 0 ? {} : { threadId: execution.threadId }
440
+ })
441
+ }));
442
+ if (status.exitCode !== 0 || status.statusCause.reasons.length > 0) return yield* status;
443
+ })
444
+ };
445
+ });
446
+ // packages/remote/src/internal/runner/Connection.ts
447
+ var Connection = class extends Context.Service()("@graftland/plugin-remote/internal/runner/Connection") {};
448
+ const connected = Connection.of;
449
+ const Local = Effect.fnUntraced(function* (target, contractModule, options, resources, processScope) {
450
+ const execution = yield* (yield* target._tag === "Local" ? LocalTransport : WorkerTransport).start({
451
+ ...target,
452
+ contractModule,
453
+ session: options.session
454
+ }).pipe(Scope.provide(processScope));
455
+ return yield* connect(execution, options).pipe(Scope.provide(resources));
456
+ });
457
+ const reason = (exit) => Exit.isFailure(exit) ? exit.cause : Cause.empty;
458
+ const finish = (causes) => {
459
+ const cause = Array.reduce(causes, Cause.empty, Cause.combine);
460
+ return cause.reasons.length === 0 ? Effect.void : Effect.failCause(cleanupCause(cause));
461
+ };
462
+ /** Close partially acquired resources too; the normal release observes exit before stopping readers. */
463
+ const scopes = Effect.acquireRelease(Effect.all({
464
+ resources: Scope.make(),
465
+ process: Scope.make()
466
+ }), (scopes, exit) => Effect.gen(function* () {
467
+ const process = yield* Effect.exit(close(scopes.process, exit));
468
+ const resources = yield* Effect.exit(close(scopes.resources, exit));
469
+ yield* finish([reason(process), reason(resources)]);
470
+ }));
471
+ /** Setup supplies a concrete control lifecycle; release never reads a later-installed effect. */
472
+ const acquire = (target, contractModule, options, setup, dispose, timeout) => Effect.gen(function* () {
473
+ const owned = yield* scopes;
474
+ const connection = yield* Effect.acquireRelease(Effect.gen(function* () {
475
+ return target._tag === "Local" || target._tag === "Worker" ? yield* Local(target, contractModule, options, owned.resources, owned.process).pipe(Effect.map(connected)) : yield* connect$1(target, contractModule, options, owned.resources, owned.process);
476
+ }).pipe(Effect.interruptible), (connection, exit) => Effect.gen(function* () {
477
+ const process = yield* Effect.exit(close(owned.process, exit));
478
+ yield* connection.diagnostics;
479
+ const resources = yield* Effect.exit(close(owned.resources, exit));
480
+ const diagnostics = yield* connection.diagnostics;
481
+ yield* finish([
482
+ reason(process),
483
+ reason(resources),
484
+ diagnostics
485
+ ]);
486
+ }));
487
+ return yield* Effect.acquireRelease(setup.pipe(Effect.provideService(Connection, connection)), (value) => Effect.gen(function* () {
488
+ const graceful = yield* dispose(value).pipe(Effect.interruptible, Effect.timeout(timeout), Effect.exit);
489
+ const terminated = yield* Effect.exit(connection.terminate(Exit.isSuccess(graceful)));
490
+ yield* finish([Exit.isSuccess(graceful) ? graceful.value : graceful.cause, reason(terminated)]);
491
+ }));
492
+ });
493
+ // packages/remote/src/internal/host.ts
494
+ const race = (connection, effect) => Effect.raceFirst(effect, connection.transport.failure);
495
+ const forwardEvents = (contract, client, connection) => Effect.gen(function* () {
496
+ const stopped = yield* Deferred.make();
497
+ const remoteFailure = yield* make$4();
498
+ return {
499
+ stopped,
500
+ remoteFailure,
501
+ events: yield* race(connection, client.Events().pipe(Stream.runForEach((event) => {
502
+ switch (event._tag) {
503
+ case "Stopped": return Deferred.succeed(stopped, void 0);
504
+ case "Withdrawing": return remoteFailure.fail(RemoteWithdrawn.make({}));
505
+ case "Failed": return contract.decodeCause(event.cause).pipe(Effect.flatMap((cause) => remoteFailure.failCause(cause)));
506
+ }
507
+ }))).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources))
508
+ };
509
+ });
510
+ const forwardLogs = (contract, client, connection) => Effect.gen(function* () {
511
+ const logsEnded = yield* Deferred.make();
512
+ const reportedDrops = yield* Ref.make(0);
513
+ yield* race(connection, client.Logs().pipe(Stream.runForEach((event) => Effect.gen(function* () {
514
+ const previous = yield* Ref.getAndSet(reportedDrops, event.dropped);
515
+ if (event.dropped > previous) yield* Effect.logWarning("Remote logs were dropped").pipe(Effect.annotateLogs({
516
+ ...Option.isSome(connection.pid) ? { "remote.pid": connection.pid.value } : {},
517
+ "remote.logs.dropped": event.dropped - previous,
518
+ "remote.logs.droppedTotal": event.dropped
519
+ }));
520
+ if (event._tag === "LogsEnded") {
521
+ yield* Deferred.succeed(logsEnded, void 0);
522
+ return;
523
+ }
524
+ const entry = event.entry;
525
+ const cause = yield* contract.decodeCause(entry.cause);
526
+ yield* Effect.logWithLevel(entry.level === "All" || entry.level === "None" ? "Info" : entry.level)(...Array.isArray(entry.message) ? entry.message : [entry.message], cause).pipe(Effect.annotateLogs({
527
+ ...Option.isSome(connection.pid) ? { "remote.pid": connection.pid.value } : {},
528
+ ...connection.threadId === void 0 ? {} : { "remote.threadId": connection.threadId },
529
+ "remote.annotations": entry.annotations
530
+ }));
531
+ })))).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources));
532
+ return logsEnded;
533
+ });
534
+ const initialize = (contract) => Effect.gen(function* () {
535
+ const connection = yield* Connection;
536
+ const client = yield* RpcClient.make(contract.control).pipe(Effect.provideService(RpcClient.Protocol, connection.transport.clientProtocol(endpoint)), Scope.provide(connection.resources));
537
+ for (const service of contract.inject) yield* service.serve(connection.transport).pipe(Effect.tapCause(connection.transport.report), Effect.forkIn(connection.resources));
538
+ const events = yield* forwardEvents(contract, client, connection);
539
+ const logsEnded = yield* forwardLogs(contract, client, connection);
540
+ return {
541
+ connection,
542
+ client,
543
+ ...events,
544
+ logsEnded
545
+ };
546
+ });
547
+ const load$1 = (active, input) => race(active.connection, Effect.raceFirst(active.client.Load({ input }).pipe(Effect.catchIf((cause) => Cause.isCause(cause), Effect.failCause)), active.remoteFailure.await));
548
+ const dispose = (active) => Effect.gen(function* () {
549
+ const result = yield* race(active.connection, active.client.Dispose().pipe(Effect.catchIf(Cause.isCause, Effect.succeed)));
550
+ const cause = Cause.isCause(result) ? result : Cause.empty;
551
+ yield* race(active.connection, Deferred.await(active.stopped).pipe(Effect.andThen(Deferred.await(active.logsEnded)))).pipe(Effect.onError(() => Effect.failCause(cleanupCause(cause))));
552
+ return cause;
553
+ });
554
+ // packages/remote/src/internal/execution.ts
555
+ const dependencies = (target) => target._tag === "Connector" ? [Connector, Credentials] : target._tag === "Local" ? [LocalTransport] : [WorkerTransport];
556
+ /** One owned execution per activation, with explicitly mapped services. */
557
+ const executionPlugin = (contract, options, configured, annotations = {}) => make({
558
+ name: contract.name,
559
+ inject: [
560
+ SecureRandom.SecureRandom,
561
+ ...dependencies(configured),
562
+ ...Array.map(contract.inject, (service) => service.key)
563
+ ],
564
+ config: Schema.toEncoded(contract.config),
565
+ apply: (input) => Effect.gen(function* () {
566
+ const session = yield* (yield* SecureRandom.SecureRandom).uuidV4();
567
+ const active = yield* acquire(configured, options.contractModule, {
568
+ session,
569
+ serve: endpoints(contract.inject),
570
+ call: {
571
+ ...endpoints(contract.provides),
572
+ [endpoint]: contract.control
573
+ }
574
+ }, initialize(contract), dispose, options.shutdownTimeout ?? "5 seconds");
575
+ yield* load$1(active, input);
576
+ for (const service of contract.provides) yield* service.publish(active.connection.transport).pipe(Scope.provide(active.connection.resources));
577
+ yield* fork(Effect.raceFirst(Fiber.join(active.events), active.remoteFailure.await).pipe(Effect.mapError((error) => publicError(contract.error, error))));
578
+ return () => Effect.succeed(false);
579
+ }).pipe(Effect.annotateLogs(annotations), Effect.mapError((error) => publicError(contract.error, error)))
580
+ });
581
+ const publicError = (declared, error) => Schema.is(declared)(error) ? error : Schema.is(UndeclaredFailure)(error) || Schema.is(RemoteWithdrawn)(error) || Schema.is(RemoteError)(error) || Schema.is(MissingInstance)(error) ? error : RemoteError.make({ cause: Cause.fail(error) });
582
+ // packages/remote/src/internal/entry.ts
583
+ var EntryError = class extends Schema.TaggedError()("RemoteEntryError", {
584
+ entry: Schema.Option(Schema.String),
585
+ directory: Schema.Option(Schema.String),
586
+ field: Schema.String,
587
+ cause: Schema.Cause(Schema.Unknown, Schema.Unknown)
588
+ }) {
589
+ get message() {
590
+ return `Remote entry ${Option.getOrElse(this.entry, () => "<programmatic>")} failed at ${this.field}`;
591
+ }
592
+ };
593
+ const boundary = Effect.fnUntraced(function* (field) {
594
+ const entry = yield* CurrentId;
595
+ const directory = yield* ConfigDirectory;
596
+ return (cause) => Effect.fail(EntryError.make({
597
+ entry,
598
+ directory,
599
+ field,
600
+ cause
601
+ }));
602
+ });
603
+ const resolve = Effect.fnUntraced(function* (reference, field) {
604
+ const existing = yield* Effect.serviceOption(ModuleResolver);
605
+ const path = yield* Path.Path;
606
+ const source = yield* ConfigDirectory;
607
+ const directory = path.resolve(Option.getOrElse(source, () => "."));
608
+ const resolver = yield* Option.match(existing, {
609
+ onSome: Effect.succeed,
610
+ onNone: () => Effect.gen(function* () {
611
+ const importer = yield* make$1(directory);
612
+ return yield* make$2({
613
+ base: directory,
614
+ importer: (specifier) => String.startsWith("@graftland/plugin-remote/")(specifier) ? import(specifier) : importer(specifier)
615
+ });
616
+ })
617
+ });
618
+ const fail = yield* boundary(field);
619
+ return {
620
+ plugin: yield* resolver.resolve(reference.name).pipe(Effect.catchCause(fail)),
621
+ config: reference.config
622
+ };
623
+ });
624
+ const loadContract = Effect.fnUntraced(function* (specifier) {
625
+ const resolver = yield* ModuleResolver;
626
+ const fail = yield* boundary("contract");
627
+ return yield* resolver.importModule(specifier).pipe(Effect.flatMap((module) => Effect.fromOption(fromModule(module), () => ModuleInvalid.make({
628
+ specifier,
629
+ cause: "Expected a default or named remote contract"
630
+ }))), Effect.catchCause(fail));
631
+ });
632
+ /** Direct execution installs only its execution capability in a private realm. */
633
+ const direct = (provider, consumer, input, key) => plugin(make({
634
+ name: "remote-direct",
635
+ apply: Effect.fnUntraced(function* () {
636
+ const capability = yield* plugin(provider);
637
+ yield* follow(capability, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
638
+ const execution = yield* plugin(consumer, input);
639
+ yield* follow(execution, (cause) => Effect.fail(CapabilityFailed.make({ cause })));
640
+ })
641
+ }), void 0, { isolate: [key] });
642
+ const directTarget = Effect.fnUntraced(function* (contract, input, selected, annotations, options) {
643
+ const path = yield* Path.Path;
644
+ const source = yield* ConfigDirectory;
645
+ const directory = path.resolve(Option.getOrElse(source, () => "."));
646
+ const module = String.startsWith("file:")(input.contract) ? input.contract : yield* resolveEntry(directory, input.contract);
647
+ const capability = yield* resolve({ name: selected._tag === "Local" ? "@graftland/plugin-remote/host/local" : "@graftland/plugin-remote/host/worker" }, "connect");
648
+ return yield* direct(capability.plugin, executionPlugin(contract, {
649
+ ...options,
650
+ contractModule: module
651
+ }, selected, annotations), input.config, selected._tag === "Local" ? LocalTransport : WorkerTransport);
652
+ });
653
+ const runnerTarget = Effect.fnUntraced(function* (contract, input, target, annotations, options, authOverride) {
654
+ const instance = target.instance === void 0 ? yield* CurrentId : Option.some(target.instance);
655
+ if (Option.isNone(instance)) return yield* MissingInstance.make({});
656
+ const transport = yield* resolve(hostTransport(target), "connect.transport");
657
+ const auth = authOverride ?? (yield* resolve(authentication("host", target.auth), "connect.auth"));
658
+ const consumer = executionPlugin(contract, options, {
659
+ _tag: "Connector",
660
+ explicitAuth: target.auth !== void 0,
661
+ instance: instance.value,
662
+ ...target.lease === void 0 ? {} : { lease: target.lease },
663
+ ...target.margin === void 0 ? {} : { margin: target.margin },
664
+ ...target.expect === void 0 ? {} : { expect: target.expect }
665
+ }, annotations);
666
+ return yield* host$1({
667
+ transport,
668
+ auth,
669
+ consumer,
670
+ input: input.config
671
+ });
672
+ });
673
+ const launch = Effect.fnUntraced(function* (contract, input, options, authOverride) {
674
+ const annotations = yield* References.CurrentLogAnnotations;
675
+ const connect = input.connect;
676
+ const scope = yield* children;
677
+ return yield* Effect.gen(function* () {
678
+ if (connect.local !== void 0) return yield* directTarget(contract, input, {
679
+ _tag: "Local",
680
+ ...connect.local
681
+ }, annotations, options);
682
+ if (connect.worker !== void 0) return yield* directTarget(contract, input, {
683
+ _tag: "Worker",
684
+ ...connect.worker
685
+ }, annotations, options);
686
+ return yield* runnerTarget(contract, input, connect, annotations, options, authOverride);
687
+ }).pipe(Scope.provide(scope));
688
+ });
689
+ const load = Effect.fnUntraced(function* (input) {
690
+ const contract = yield* loadContract(input.contract);
691
+ const failConfig = yield* boundary("config");
692
+ yield* Schema.decodeEffect(contract.config)(input.config).pipe(Effect.catchCause(failConfig));
693
+ const failConnect = yield* boundary("connect");
694
+ const fork = yield* launch(contract, input, { contractModule: input.contract }).pipe(Effect.catchCause(failConnect));
695
+ yield* follow(fork, failConnect);
696
+ });
697
+ const host = make({
698
+ name: "remote",
699
+ config: Host,
700
+ inject: [
701
+ SecureRandom.SecureRandom,
702
+ ModuleResolver,
703
+ Path.Path,
704
+ ChildProcessSpawner.ChildProcessSpawner
705
+ ],
706
+ apply: load
707
+ });
708
+ export { publicError as a, directAuth as c, follow as d, Host as f, runnerTransport as h, resolve as i, makeListenerConsumer as l, runnerAuthentication as m, host as n, CapabilityCombinationError as o, Runner as p, launch as r, CapabilityFailed as s, boundary as t, runner as u };