@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
package/src/bin.ts ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ /** Runs local children and WebSocket supervisors, and issues their deployment certificates. */
3
+ import { Graft } from "@graftland/graft"
4
+ import { NodeRuntime } from "@effect/platform-node"
5
+ import { Console, Array, Effect, Layer, Logger, Option, Schema } from "effect"
6
+ import { Argument, CliError, Command, Flag } from "effect/cli"
7
+ import process from "node:process"
8
+ import { pathToFileURL } from "node:url"
9
+ import { platform } from "./internal/platform"
10
+ import { bytes } from "./internal/stdioChannel"
11
+ import { load, run } from "./internal/childRuntime"
12
+ import { Bootstrap } from "./internal/runner/Bootstrap"
13
+ import * as Watchdog from "./internal/runner/Watchdog"
14
+ import * as Serve from "./internal/serve"
15
+ import * as Certificates from "./internal/Certificates"
16
+
17
+ const serve = Command.make(
18
+ "serve",
19
+ { config: Flag.String("config") },
20
+ ({ config }) => Serve.run(config),
21
+ )
22
+ const certificates = Command.make(
23
+ "certificates",
24
+ {
25
+ out: Flag.String("out").pipe(
26
+ Flag.withDescription("Directory for the CA and issued certificates"),
27
+ ),
28
+ server: Flag.String("server").pipe(
29
+ Flag.atLeast(0),
30
+ Flag.withDescription(
31
+ "Runner DNS name or IP address; repeat for additional SANs",
32
+ ),
33
+ ),
34
+ identity: Flag.String("identity").pipe(
35
+ Flag.atLeast(0),
36
+ Flag.withDescription(
37
+ "Host identity; repeat to issue multiple client certificates",
38
+ ),
39
+ ),
40
+ days: Flag.Int("days").pipe(
41
+ Flag.withDefault(365),
42
+ Flag.filter(
43
+ (days) => days > 0,
44
+ () => "Days must be a positive integer",
45
+ ),
46
+ ),
47
+ force: Flag.Boolean("force").pipe(
48
+ Flag.withDefault(false),
49
+ Flag.withDescription(
50
+ "Replace requested leaf certificates, keeping the existing CA",
51
+ ),
52
+ ),
53
+ },
54
+ (options) =>
55
+ Certificates.generate(options).pipe(
56
+ Effect.andThen(Console.log(`Certificates written to ${options.out}`)),
57
+ Effect.catchTag("CertificateExists", (error) =>
58
+ CliError.UserError.make({ cause: error, userMessage: error.message }),
59
+ ),
60
+ ),
61
+ )
62
+ const child = Command.make(
63
+ "child",
64
+ {
65
+ contract: Argument.String("contract"),
66
+ session: Argument.String("session"),
67
+ bootstrap: Argument.String("bootstrap").pipe(
68
+ Argument.withSchema(Schema.fromJsonString(Bootstrap)),
69
+ ),
70
+ },
71
+ ({ contract, session, bootstrap }) =>
72
+ Effect.gen(function* () {
73
+ const watchdog = yield* Watchdog.start
74
+ // The executable owns stdin; it must not retain the process after a supervisor stop.
75
+ yield* Effect.addFinalizer(() =>
76
+ Effect.sync(() => {
77
+ process.stdin.destroy()
78
+ }),
79
+ )
80
+ const begin = yield* Effect.raceFirst(
81
+ watchdog.begin.pipe(Effect.as(true)),
82
+ watchdog.stop.pipe(Effect.as(false)),
83
+ )
84
+ if (!begin) return
85
+ const definition = yield* load(pathToFileURL(contract).href)
86
+ const channel = yield* bytes
87
+ return yield* run(definition, channel, session, bootstrap, watchdog.stop)
88
+ }),
89
+ )
90
+ const cli = Command.make(
91
+ "graft-remote",
92
+ {
93
+ contract: Argument.String("contract").pipe(Argument.optional),
94
+ session: Argument.String("session").pipe(Argument.withDefault("local")),
95
+ },
96
+ ({ contract, session }) =>
97
+ Effect.gen(function* () {
98
+ if (Option.isNone(contract))
99
+ return yield* CliError.UserError.make({
100
+ cause: "Missing contract module",
101
+ userMessage:
102
+ "A contract module or the child/serve/certificates subcommand is required",
103
+ })
104
+ const definition = yield* load(contract.value)
105
+ const channel = yield* bytes
106
+ return yield* run(definition, channel, session)
107
+ }),
108
+ ).pipe(Command.withSubcommands([child, serve, certificates]))
109
+
110
+ NodeRuntime.runMain(
111
+ Effect.scoped(
112
+ Effect.gen(function* () {
113
+ const context = yield* Layer.build(
114
+ Layer.provideMerge(Graft.layer, platform),
115
+ )
116
+ return yield* Command.run(cli, { version: "0.0.0" }).pipe(
117
+ Effect.provideContext(context),
118
+ )
119
+ }),
120
+ ).pipe(
121
+ (effect) =>
122
+ Effect.withFiber((main) =>
123
+ effect.pipe(
124
+ Effect.tapCause((cause) =>
125
+ // NodeRuntime uses this fiber's id; a self-interrupt here is indistinguishable, but worker cleanup is not.
126
+ Array.every(
127
+ cause.reasons,
128
+ (reason) =>
129
+ reason._tag === "Interrupt" && reason.fiberId === main.id,
130
+ ) ||
131
+ Array.every(
132
+ cause.reasons,
133
+ (reason) =>
134
+ reason._tag === "Fail" && CliError.isCliError(reason.error),
135
+ )
136
+ ? Effect.void
137
+ : Effect.logError(cause),
138
+ ),
139
+ ),
140
+ ),
141
+ Effect.provideService(Logger.LogToStderr, true),
142
+ ),
143
+ // Report inside the stderr context, including failures from resource cleanup.
144
+ { disableErrorReporting: true },
145
+ )
@@ -0,0 +1,10 @@
1
+ import type { Graft, Plugin } from "@graftland/graft"
2
+ import { Config, plugin } from "../../internal/auth/tokenCredentials"
3
+ export { Config }
4
+
5
+ const capability: Plugin.Plugin<
6
+ typeof Config.Type,
7
+ typeof Config.Encoded,
8
+ Graft.ServiceConflict
9
+ > = plugin("remote-bearer-credentials")
10
+ export default capability
@@ -0,0 +1,10 @@
1
+ import type { Graft, Plugin } from "@graftland/graft"
2
+ import { Config, plugin } from "../../internal/auth/tokenCredentials"
3
+ export { Config }
4
+
5
+ const capability: Plugin.Plugin<
6
+ typeof Config.Type,
7
+ typeof Config.Encoded,
8
+ Graft.ServiceConflict
9
+ > = plugin("remote-jwt-credentials")
10
+ export default capability
@@ -0,0 +1,48 @@
1
+ import { Plugin, Graft } from "@graftland/graft"
2
+ import {
3
+ Cause,
4
+ Effect,
5
+ FileSystem,
6
+ Option,
7
+ Path,
8
+ Redacted,
9
+ Schema,
10
+ } from "effect"
11
+ import { CredentialsError } from "../../Errors"
12
+ import { ConfigDirectory } from "@graftland/loader"
13
+ import { Credentials, type Prepared } from "../../Auth"
14
+
15
+ export const Config = Schema.Struct({ cert: Schema.String, key: Schema.String })
16
+ export default Plugin.make({
17
+ name: "remote-certificate-credentials",
18
+ config: Config,
19
+ inject: [FileSystem.FileSystem, Path.Path],
20
+ apply: Effect.fnUntraced(function* (config) {
21
+ const fs = yield* FileSystem.FileSystem
22
+ const path = yield* Path.Path
23
+ const directory = yield* ConfigDirectory.pipe(
24
+ Effect.map(Option.getOrElse(() => ".")),
25
+ )
26
+ yield* Graft.provide(Credentials, {
27
+ kind: "Certificate",
28
+ // File credentials are read for each connection, not cached on activation.
29
+ read: Effect.all({
30
+ cert: fs.readFileString(path.resolve(directory, config.cert)),
31
+ key: fs
32
+ .readFileString(path.resolve(directory, config.key))
33
+ .pipe(Effect.map(Redacted.make)),
34
+ }).pipe(
35
+ Effect.mapBoth({
36
+ onSuccess: (
37
+ value,
38
+ ): Extract<Prepared, { readonly _tag: "Certificate" }> => ({
39
+ _tag: "Certificate",
40
+ value,
41
+ }),
42
+ onFailure: (error) =>
43
+ CredentialsError.make({ cause: Cause.fail(error) }),
44
+ }),
45
+ ),
46
+ })
47
+ }),
48
+ })
@@ -0,0 +1,13 @@
1
+ import { Plugin, Graft } from "@graftland/graft"
2
+ import { Effect, Schema } from "effect"
3
+ import { Credentials } from "../../Auth"
4
+
5
+ export default Plugin.make({
6
+ name: "remote-none-credentials",
7
+ config: Schema.Struct({}),
8
+ apply: () =>
9
+ Graft.provide(Credentials, {
10
+ kind: "None",
11
+ read: Effect.succeed<{ readonly _tag: "None" }>({ _tag: "None" }),
12
+ }),
13
+ })
@@ -0,0 +1,131 @@
1
+ import type { CommandOptions } from "../internal/transportOptions"
2
+ import { Plugin, Graft } from "@graftland/graft"
3
+ import {
4
+ Array,
5
+ Cause,
6
+ Effect,
7
+ Option,
8
+ Path,
9
+ Schema,
10
+ Scope,
11
+ Sink,
12
+ Stream,
13
+ } from "effect"
14
+ import { ChildProcess, ChildProcessSpawner } from "effect/process"
15
+ import { Connector } from "../Transport"
16
+ import { ConfigDirectory } from "@graftland/loader"
17
+ import { TransportError } from "../Errors"
18
+ import { cleanupCause } from "../internal/cleanup"
19
+ import * as ProcessObservation from "../internal/runner/ProcessObservation"
20
+
21
+ export class CommandExited extends Schema.TaggedError<
22
+ CommandExited,
23
+ { readonly brand: unique symbol }
24
+ >()("CommandExited", {
25
+ code: Schema.NullOr(Schema.Int),
26
+ stderr: Schema.String,
27
+ cause: Schema.Cause(Schema.Unknown, Schema.Unknown),
28
+ }) {}
29
+
30
+ /** The launcher exit describes this channel, never the remote execution's termination. */
31
+ export const make = (options: CommandOptions) =>
32
+ Effect.map(ChildProcessSpawner.ChildProcessSpawner, (spawner) =>
33
+ Connector.of({
34
+ properties: {
35
+ protocol: "command",
36
+ encrypted: false,
37
+ network: false,
38
+ carries: [],
39
+ },
40
+ connect: Effect.fnUntraced(
41
+ function* () {
42
+ const scope = yield* Effect.scope
43
+ const readers = yield* Scope.fork(scope)
44
+ const child = yield* spawner.spawn(
45
+ ChildProcess.make(options.argv[0], Array.drop(options.argv, 1), {
46
+ ...options,
47
+ stdin: "pipe",
48
+ stdout: "pipe",
49
+ stderr: "pipe",
50
+ forceKillAfter: "1 second",
51
+ }),
52
+ )
53
+ const observation = yield* ProcessObservation.observe(child, {
54
+ drainStdout: false,
55
+ }).pipe(Scope.provide(readers))
56
+ const exited = observation.exited.pipe(
57
+ Effect.map((status) => CommandExited.make(status)),
58
+ )
59
+ yield* Effect.addFinalizer(() =>
60
+ Stream.empty.pipe(
61
+ Stream.run(child.stdin),
62
+ Effect.andThen(exited),
63
+ Effect.flatMap((status) =>
64
+ status.code === 0 && status.cause.reasons.length === 0
65
+ ? Effect.void
66
+ : Effect.fail(status),
67
+ ),
68
+ Effect.interruptible,
69
+ Effect.timeout(ProcessObservation.stdinExitTimeout),
70
+ Effect.catchCause((cause) =>
71
+ Effect.failCause(cleanupCause(cause)),
72
+ ),
73
+ ),
74
+ )
75
+ return {
76
+ input: child.stdout.pipe(
77
+ Stream.concat(
78
+ Stream.fromEffect(
79
+ exited.pipe(
80
+ Effect.flatMap((status) =>
81
+ status.code === 0 && status.cause.reasons.length === 0
82
+ ? Effect.void
83
+ : Effect.fail(status),
84
+ ),
85
+ ),
86
+ ).pipe(Stream.drain),
87
+ ),
88
+ Stream.interruptWhen(observation.failure),
89
+ Stream.mapError((error) =>
90
+ TransportError.make({ cause: Cause.fail(error) }),
91
+ ),
92
+ ),
93
+ output: child.stdin.pipe(
94
+ Sink.mapError((error) =>
95
+ TransportError.make({ cause: Cause.fail(error) }),
96
+ ),
97
+ ),
98
+ }
99
+ },
100
+ Effect.mapError((error) =>
101
+ TransportError.make({ cause: Cause.fail(error) }),
102
+ ),
103
+ ),
104
+ }),
105
+ )
106
+ export const Config = Schema.Struct({
107
+ argv: Schema.NonEmptyArray(Schema.String),
108
+ cwd: Schema.optionalKey(Schema.String),
109
+ env: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
110
+ })
111
+ export default Plugin.make({
112
+ name: "remote-command-connector",
113
+ config: Config,
114
+ inject: [ChildProcessSpawner.ChildProcessSpawner, Path.Path],
115
+ apply: Effect.fnUntraced(function* (config) {
116
+ const path = yield* Path.Path
117
+ const directory = yield* ConfigDirectory
118
+ const connector = yield* make({
119
+ ...config,
120
+ ...(config.cwd === undefined
121
+ ? {}
122
+ : {
123
+ cwd: path.resolve(
124
+ Option.getOrElse(directory, () => "."),
125
+ config.cwd,
126
+ ),
127
+ }),
128
+ })
129
+ yield* Graft.provide(Connector, connector)
130
+ }),
131
+ })
@@ -0,0 +1,41 @@
1
+ import { Plugin, type Graft } from "@graftland/graft"
2
+ import { Array, Effect, Scope } from "effect"
3
+ import { ChildProcess, ChildProcessSpawner } from "effect/process"
4
+ import { LocalTransport } from "../internal/directTransport"
5
+ import { command } from "../internal/runner/command"
6
+ import * as Local from "../internal/host/local"
7
+
8
+ const make = Effect.map(ChildProcessSpawner.ChildProcessSpawner, (spawner) =>
9
+ LocalTransport.of({
10
+ start: Effect.fnUntraced(function* (options) {
11
+ const scope = yield* Effect.scope
12
+ // Readers must outlive the process finalizer to capture its final diagnostics.
13
+ const readers = yield* Scope.fork(scope)
14
+ const argv = yield* command(options.command)
15
+ const child = yield* spawner.spawn(
16
+ ChildProcess.make(
17
+ argv[0],
18
+ [...Array.drop(argv, 1), options.contractModule, options.session],
19
+ {
20
+ stdin: "pipe",
21
+ stdout: "pipe",
22
+ stderr: "pipe",
23
+ additionalFds: { fd3: { type: "output" } },
24
+ forceKillAfter: "1 second",
25
+ },
26
+ ),
27
+ )
28
+ return yield* Local.observe(child).pipe(Scope.provide(readers))
29
+ }),
30
+ }),
31
+ )
32
+ const plugin: Plugin.Plugin<void, void, Graft.ServiceConflict> = Plugin.service(
33
+ LocalTransport,
34
+ make,
35
+ {
36
+ name: "remote-local-transport",
37
+ inject: [ChildProcessSpawner.ChildProcessSpawner],
38
+ },
39
+ )
40
+
41
+ export default plugin
@@ -0,0 +1,65 @@
1
+ import type { UnixOptions } from "../internal/transportOptions"
2
+ import { Plugin, Graft } from "@graftland/graft"
3
+ import { ConfigDirectory } from "@graftland/loader"
4
+ import { Cause, Effect, Layer, Option, Path, Redacted, Schema } from "effect"
5
+ import { Socket } from "effect/socket"
6
+ import WS from "ws"
7
+ import type { Prepared } from "../Auth"
8
+ import { Connector, type ConnectorApi } from "../Transport"
9
+ import { TransportError } from "../Errors"
10
+ import { path, protocol, payloadLimit } from "../internal/websocket"
11
+ import * as Channel from "../internal/socketChannel"
12
+
13
+ export const properties: ConnectorApi["properties"] = {
14
+ protocol: "unix",
15
+ encrypted: false,
16
+ network: false,
17
+ carries: ["header"],
18
+ }
19
+ const constructor = (credentials: Prepared) =>
20
+ Layer.succeed(
21
+ Socket.WebSocketConstructor,
22
+ (url) =>
23
+ new WS(url, protocol, {
24
+ headers:
25
+ credentials._tag === "Authorization"
26
+ ? { authorization: Redacted.value(credentials.value) }
27
+ : {},
28
+ perMessageDeflate: false,
29
+ maxPayload: payloadLimit,
30
+ }),
31
+ )
32
+ export const make = (options: UnixOptions): ConnectorApi => ({
33
+ properties,
34
+ connect: Effect.fnUntraced(
35
+ function* (credentials) {
36
+ const services = yield* Layer.build(constructor(credentials))
37
+ const socket = yield* Socket.makeWebSocket(
38
+ `ws+unix://${options.path}:${path}`,
39
+ ).pipe(Effect.provideContext(services))
40
+ return yield* Channel.fromSocket(socket)
41
+ },
42
+ Effect.mapError((error) =>
43
+ TransportError.make({ cause: Cause.fail(error) }),
44
+ ),
45
+ ),
46
+ })
47
+ export const Config = Schema.Struct({ path: Schema.String })
48
+ export default Plugin.make({
49
+ name: "remote-unix-connector",
50
+ config: Config,
51
+ inject: [Path.Path],
52
+ apply: Effect.fnUntraced(function* (config) {
53
+ const path = yield* Path.Path
54
+ const directory = yield* ConfigDirectory
55
+ yield* Graft.provide(
56
+ Connector,
57
+ make({
58
+ path: path.resolve(
59
+ Option.getOrElse(directory, () => "."),
60
+ config.path,
61
+ ),
62
+ }),
63
+ )
64
+ }),
65
+ })
@@ -0,0 +1,66 @@
1
+ import type { WebsocketOptions } from "../internal/transportOptions"
2
+ import { Plugin, Graft } from "@graftland/graft"
3
+ import { Cause, Effect, FileSystem, Option, Path, Schema } from "effect"
4
+ import { Connector, type ConnectorApi } from "../Transport"
5
+ import { TransportError } from "../Errors"
6
+ import { ConfigDirectory } from "@graftland/loader"
7
+ import * as Websocket from "../internal/websocket"
8
+ import * as Channel from "../internal/socketChannel"
9
+
10
+ /** Configured Connector; certificate paths belong to the enclosing configuration. */
11
+ export const Config = Schema.Struct({
12
+ url: Websocket.Url,
13
+ ca: Schema.optionalKey(Schema.String),
14
+ servername: Schema.optionalKey(Schema.String),
15
+ })
16
+ export const make = (
17
+ options: WebsocketOptions,
18
+ properties: ConnectorApi["properties"],
19
+ ): ConnectorApi => ({
20
+ properties,
21
+ connect: (prepared) =>
22
+ Websocket.open(
23
+ options,
24
+ prepared._tag === "Certificate"
25
+ ? { certificate: prepared.value }
26
+ : prepared._tag === "Authorization"
27
+ ? { authorization: prepared.value }
28
+ : {},
29
+ ).pipe(
30
+ Effect.flatMap(Channel.fromSocket),
31
+ Effect.mapError((error) =>
32
+ TransportError.make({ cause: Cause.fail(error) }),
33
+ ),
34
+ ),
35
+ })
36
+ export default Plugin.make({
37
+ name: "remote-websocket-connector",
38
+ config: Config,
39
+ inject: [FileSystem.FileSystem, Path.Path],
40
+ apply: Effect.fnUntraced(function* (config) {
41
+ const fs = yield* FileSystem.FileSystem
42
+ const path = yield* Path.Path
43
+ const directory = yield* ConfigDirectory.pipe(
44
+ Effect.map(Option.getOrElse(() => ".")),
45
+ )
46
+ const ca =
47
+ config.ca === undefined
48
+ ? undefined
49
+ : yield* fs.readFileString(path.resolve(directory, config.ca))
50
+ yield* Graft.provide(
51
+ Connector,
52
+ make(
53
+ {
54
+ url: config.url.href,
55
+ tls: {
56
+ ...(ca === undefined ? {} : { ca }),
57
+ ...(config.servername === undefined
58
+ ? {}
59
+ : { servername: config.servername }),
60
+ },
61
+ },
62
+ Websocket.properties(config.url),
63
+ ),
64
+ )
65
+ }),
66
+ })
@@ -0,0 +1,90 @@
1
+ import { Plugin, type Graft } from "@graftland/graft"
2
+ import { Cause, Deferred, Effect, FiberSet, Option, Schema } from "effect"
3
+ import { Worker } from "node:worker_threads"
4
+ import { WorkerTransport } from "../internal/directTransport"
5
+ import { ProcessExited, TransportError } from "../Errors"
6
+ import * as Channel from "../internal/workerChannel"
7
+ import * as FailureGroup from "../internal/FailureGroup"
8
+ import { Bootstrap } from "../internal/workerBootstrap"
9
+ import { cleanupCause } from "../internal/cleanup"
10
+
11
+ const start: typeof WorkerTransport.Service.start = Effect.fnUntraced(
12
+ function* (options) {
13
+ const data = yield* Schema.encodeEffect(Bootstrap)(options).pipe(
14
+ Effect.mapError((error) =>
15
+ TransportError.make({ cause: Cause.fail(error) }),
16
+ ),
17
+ )
18
+ const exited = yield* Deferred.make<number>()
19
+ const failures = yield* FailureGroup.make<TransportError>()
20
+ const callbacks = yield* FiberSet.make()
21
+ const run = yield* FiberSet.runtime(callbacks)()
22
+ const onExit = (code: number) => run(Deferred.succeed(exited, code))
23
+ const onError = (error: Error) =>
24
+ run(failures.fail(TransportError.make({ cause: Cause.die(error) })))
25
+ const worker = yield* Effect.acquireRelease(
26
+ Effect.try({
27
+ try: () => {
28
+ const worker = new Worker(
29
+ new URL(
30
+ import.meta.resolve("@graftland/plugin-remote/internal/worker"),
31
+ ),
32
+ {
33
+ workerData: data,
34
+ ...(options.execArgv === undefined
35
+ ? {}
36
+ : { execArgv: [...options.execArgv] }),
37
+ },
38
+ )
39
+ worker.on("exit", onExit)
40
+ worker.on("error", onError)
41
+ return worker
42
+ },
43
+ catch: (cause) => TransportError.make({ cause: Cause.die(cause) }),
44
+ }),
45
+ (worker) =>
46
+ Effect.tryPromise({
47
+ try: () => worker.terminate(),
48
+ catch: (cause) => TransportError.make({ cause: Cause.die(cause) }),
49
+ }).pipe(
50
+ Effect.andThen(Deferred.await(exited)),
51
+ Effect.ensuring(
52
+ Effect.sync(() => {
53
+ worker.off("exit", onExit)
54
+ worker.off("error", onError)
55
+ }),
56
+ ),
57
+ Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))),
58
+ ),
59
+ )
60
+ const threadId = worker.threadId
61
+ const channel = yield* Channel.make(worker)
62
+ return {
63
+ channel,
64
+ pid: Option.none(),
65
+ threadId,
66
+ failure: failures.await,
67
+ exited: Deferred.await(exited).pipe(
68
+ Effect.flatMap((exitCode) =>
69
+ failures.cause.pipe(
70
+ Effect.map((statusCause) =>
71
+ ProcessExited.make({
72
+ pid: Option.none(),
73
+ threadId,
74
+ exitCode,
75
+ stderr: "",
76
+ statusCause,
77
+ }),
78
+ ),
79
+ ),
80
+ ),
81
+ ),
82
+ }
83
+ },
84
+ )
85
+ const plugin: Plugin.Plugin<void, void, Graft.ServiceConflict> = Plugin.service(
86
+ WorkerTransport,
87
+ Effect.succeed({ start }),
88
+ { name: "remote-thread-transport" },
89
+ )
90
+ export default plugin