@graftland/plugin-remote 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +18 -54
  2. package/README.zh-CN.md +17 -51
  3. package/README.zh-TW.md +17 -51
  4. package/dist/Auth.d.ts.map +1 -1
  5. package/dist/Auth.js.map +1 -1
  6. package/dist/Config.d.ts +1151 -0
  7. package/dist/Config.d.ts.map +1 -0
  8. package/dist/Config.js +183 -0
  9. package/dist/Config.js.map +1 -0
  10. package/dist/Contract.d.ts +1 -1
  11. package/dist/Contract.d.ts.map +1 -1
  12. package/dist/Contract.js +32 -1
  13. package/dist/Contract.js.map +1 -1
  14. package/dist/Instance.d.ts.map +1 -1
  15. package/dist/Instance.js.map +1 -1
  16. package/dist/Testing.d.ts +1 -1
  17. package/dist/Testing.d.ts.map +1 -1
  18. package/dist/Testing.js.map +1 -1
  19. package/dist/Transport.d.ts +1 -1
  20. package/dist/Transport.d.ts.map +1 -1
  21. package/dist/Transport.js.map +1 -1
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +25 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/host/auth/bearer.d.ts.map +1 -1
  27. package/dist/host/auth/bearer.js +4 -2
  28. package/dist/host/auth/bearer.js.map +1 -1
  29. package/dist/host/auth/jwt.d.ts.map +1 -1
  30. package/dist/host/auth/jwt.js +4 -2
  31. package/dist/host/auth/jwt.js.map +1 -1
  32. package/dist/host/auth/mtls.d.ts +3 -7
  33. package/dist/host/auth/mtls.d.ts.map +1 -1
  34. package/dist/host/auth/mtls.js +13 -14
  35. package/dist/host/auth/mtls.js.map +1 -1
  36. package/dist/host/auth/none.d.ts +1 -1
  37. package/dist/host/auth/none.js +7 -5
  38. package/dist/host/auth/none.js.map +1 -1
  39. package/dist/host/command.d.ts +1 -1
  40. package/dist/host/command.d.ts.map +1 -1
  41. package/dist/host/command.js +11 -9
  42. package/dist/host/command.js.map +1 -1
  43. package/dist/host/local.d.ts.map +1 -1
  44. package/dist/host/local.js +9 -30
  45. package/dist/host/local.js.map +1 -1
  46. package/dist/host/unix.d.ts +1 -1
  47. package/dist/host/unix.d.ts.map +1 -1
  48. package/dist/host/unix.js +13 -9
  49. package/dist/host/unix.js.map +1 -1
  50. package/dist/host/websocket.d.ts +1 -1
  51. package/dist/host/websocket.d.ts.map +1 -1
  52. package/dist/host/websocket.js +11 -8
  53. package/dist/host/websocket.js.map +1 -1
  54. package/dist/host/worker.d.ts +1 -1
  55. package/dist/host/worker.d.ts.map +1 -1
  56. package/dist/host/worker.js +13 -9
  57. package/dist/host/worker.js.map +1 -1
  58. package/dist/index.d.ts +6 -8
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +30 -64
  61. package/dist/index.js.map +1 -1
  62. package/dist/internal/Certificates.js.map +1 -1
  63. package/dist/internal/FailureGroup.js +6 -6
  64. package/dist/internal/FailureGroup.js.map +1 -1
  65. package/dist/internal/Peer.js.map +1 -1
  66. package/dist/internal/{ServeLifecycle.js → RunnerLifecycle.js} +6 -6
  67. package/dist/internal/RunnerLifecycle.js.map +1 -0
  68. package/dist/internal/Supervisor.js.map +1 -1
  69. package/dist/internal/assembly.d.ts +3 -3
  70. package/dist/internal/assembly.js +8 -8
  71. package/dist/internal/assembly.js.map +1 -1
  72. package/dist/internal/auth/config.d.ts +27 -0
  73. package/dist/internal/auth/config.d.ts.map +1 -0
  74. package/dist/internal/auth/config.js +29 -0
  75. package/dist/internal/auth/config.js.map +1 -0
  76. package/dist/internal/auth/mtls.js.map +1 -1
  77. package/dist/internal/auth/token.js.map +1 -1
  78. package/dist/internal/auth/tokenCredentials.d.ts +1 -1
  79. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  80. package/dist/internal/auth/tokenCredentials.js +1 -1
  81. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  82. package/dist/internal/child.js +3 -3
  83. package/dist/internal/child.js.map +1 -1
  84. package/dist/internal/childMain.js +47 -0
  85. package/dist/internal/childMain.js.map +1 -0
  86. package/dist/internal/childRuntime.js +8 -8
  87. package/dist/internal/childRuntime.js.map +1 -1
  88. package/dist/internal/cleanup.js +3 -3
  89. package/dist/internal/cleanup.js.map +1 -1
  90. package/dist/internal/contract.js.map +1 -1
  91. package/dist/internal/credentials.d.ts +3 -2
  92. package/dist/internal/credentials.d.ts.map +1 -1
  93. package/dist/internal/credentials.js +1 -1
  94. package/dist/internal/credentials.js.map +1 -1
  95. package/dist/internal/directTransport.js.map +1 -1
  96. package/dist/internal/entry.d.ts +104 -26
  97. package/dist/internal/entry.d.ts.map +1 -1
  98. package/dist/internal/entry.js +22 -9
  99. package/dist/internal/entry.js.map +1 -1
  100. package/dist/internal/entryConfig.d.ts +2 -202
  101. package/dist/internal/entryConfig.js +2 -136
  102. package/dist/internal/entryConfig.js.map +1 -1
  103. package/dist/internal/execution.d.ts +4 -4
  104. package/dist/internal/execution.js +11 -11
  105. package/dist/internal/execution.js.map +1 -1
  106. package/dist/internal/follow.js +1 -1
  107. package/dist/internal/follow.js.map +1 -1
  108. package/dist/internal/forkTree.js.map +1 -1
  109. package/dist/internal/host/local.js.map +1 -1
  110. package/dist/internal/host/runner.js +4 -4
  111. package/dist/internal/host/runner.js.map +1 -1
  112. package/dist/internal/host.js +2 -2
  113. package/dist/internal/host.js.map +1 -1
  114. package/dist/internal/importer.js +1 -1
  115. package/dist/internal/importer.js.map +1 -1
  116. package/dist/internal/listenerStartup.js +1 -1
  117. package/dist/internal/listenerStartup.js.map +1 -1
  118. package/dist/internal/loadModule.js.map +1 -1
  119. package/dist/internal/platform.js +1 -9
  120. package/dist/internal/port.d.ts +1 -1
  121. package/dist/internal/port.js +2 -2
  122. package/dist/internal/port.js.map +1 -1
  123. package/dist/internal/runner/Bootstrap.js.map +1 -1
  124. package/dist/internal/runner/Connection.d.ts +3 -2
  125. package/dist/internal/runner/Connection.js +6 -6
  126. package/dist/internal/runner/Connection.js.map +1 -1
  127. package/dist/internal/runner/Execution.js +6 -6
  128. package/dist/internal/runner/Execution.js.map +1 -1
  129. package/dist/internal/runner/Local.js +1 -1
  130. package/dist/internal/runner/Local.js.map +1 -1
  131. package/dist/internal/runner/Lock.js.map +1 -1
  132. package/dist/internal/runner/Multiplex.js.map +1 -1
  133. package/dist/internal/runner/Packages.js.map +1 -1
  134. package/dist/internal/runner/ProcessObservation.js.map +1 -1
  135. package/dist/internal/runner/Processes.js.map +1 -1
  136. package/dist/internal/runner/Retention.js.map +1 -1
  137. package/dist/internal/runner/Store.js.map +1 -1
  138. package/dist/internal/runner/Supervisor.js +5 -5
  139. package/dist/internal/runner/Supervisor.js.map +1 -1
  140. package/dist/internal/runner/Watchdog.js.map +1 -1
  141. package/dist/internal/runner/Wire.d.ts +1 -1
  142. package/dist/internal/runner/Wire.js.map +1 -1
  143. package/dist/internal/runner/accept.js +2 -2
  144. package/dist/internal/runner/accept.js.map +1 -1
  145. package/dist/internal/runner/command.js +1 -1
  146. package/dist/internal/runner/command.js.map +1 -1
  147. package/dist/internal/runner/connectionEnded.js +1 -1
  148. package/dist/internal/runner/connectionEnded.js.map +1 -1
  149. package/dist/internal/runner/model.d.ts.map +1 -1
  150. package/dist/internal/runner/model.js.map +1 -1
  151. package/dist/internal/services.d.ts.map +1 -1
  152. package/dist/internal/services.js +1 -1
  153. package/dist/internal/services.js.map +1 -1
  154. package/dist/internal/socketChannel.js.map +1 -1
  155. package/dist/internal/stdioChannel.js.map +1 -1
  156. package/dist/internal/supervisorPlugin.js +48 -1
  157. package/dist/internal/supervisorPlugin.js.map +1 -1
  158. package/dist/internal/transportOptions.d.ts.map +1 -1
  159. package/dist/internal/watchdogMain.js +5 -3
  160. package/dist/internal/watchdogMain.js.map +1 -1
  161. package/dist/internal/websocket.js.map +1 -1
  162. package/dist/internal/websocketServer.js +1 -1
  163. package/dist/internal/websocketServer.js.map +1 -1
  164. package/dist/internal/workerChannel.js.map +1 -1
  165. package/dist/internal/workerMain.js +13 -6
  166. package/dist/internal/workerMain.js.map +1 -1
  167. package/dist/runner/auth/bearer.d.ts +3 -5
  168. package/dist/runner/auth/bearer.d.ts.map +1 -1
  169. package/dist/runner/auth/bearer.js +13 -11
  170. package/dist/runner/auth/bearer.js.map +1 -1
  171. package/dist/runner/auth/jwt.d.ts +4 -18
  172. package/dist/runner/auth/jwt.d.ts.map +1 -1
  173. package/dist/runner/auth/jwt.js +16 -28
  174. package/dist/runner/auth/jwt.js.map +1 -1
  175. package/dist/runner/auth/mtls.d.ts +3 -6
  176. package/dist/runner/auth/mtls.d.ts.map +1 -1
  177. package/dist/runner/auth/mtls.js +13 -29
  178. package/dist/runner/auth/mtls.js.map +1 -1
  179. package/dist/runner/auth/none.d.ts +1 -1
  180. package/dist/runner/auth/none.js +7 -5
  181. package/dist/runner/auth/none.js.map +1 -1
  182. package/dist/runner/index.d.ts +3 -308
  183. package/dist/runner/index.d.ts.map +1 -1
  184. package/dist/runner/index.js +62 -30
  185. package/dist/runner/index.js.map +1 -1
  186. package/dist/runner/stdio.d.ts +1 -1
  187. package/dist/runner/stdio.d.ts.map +1 -1
  188. package/dist/runner/stdio.js +11 -9
  189. package/dist/runner/stdio.js.map +1 -1
  190. package/dist/runner/unix.d.ts +1 -1
  191. package/dist/runner/unix.d.ts.map +1 -1
  192. package/dist/runner/unix.js +10 -8
  193. package/dist/runner/unix.js.map +1 -1
  194. package/dist/runner/websocket.d.ts +1 -1
  195. package/dist/runner/websocket.d.ts.map +1 -1
  196. package/dist/runner/websocket.js +12 -10
  197. package/dist/runner/websocket.js.map +1 -1
  198. package/package.json +14 -12
  199. package/schema.json +2269 -0
  200. package/src/Auth.ts +8 -2
  201. package/src/Config.ts +196 -0
  202. package/src/Contract.ts +12 -3
  203. package/src/Instance.ts +1 -0
  204. package/src/Testing.ts +6 -4
  205. package/src/Transport.ts +12 -3
  206. package/src/cli.ts +60 -0
  207. package/src/host/auth/bearer.ts +1 -0
  208. package/src/host/auth/jwt.ts +1 -0
  209. package/src/host/auth/mtls.ts +7 -12
  210. package/src/host/auth/none.ts +3 -1
  211. package/src/host/command.ts +8 -5
  212. package/src/host/local.ts +4 -2
  213. package/src/host/unix.ts +11 -7
  214. package/src/host/websocket.ts +10 -7
  215. package/src/host/worker.ts +8 -5
  216. package/src/index.ts +36 -23
  217. package/src/internal/Certificates.ts +1 -0
  218. package/src/internal/FailureGroup.ts +5 -3
  219. package/src/internal/Peer.ts +1 -0
  220. package/src/internal/{ServeLifecycle.ts → RunnerLifecycle.ts} +7 -5
  221. package/src/internal/Supervisor.ts +5 -4
  222. package/src/internal/assembly.ts +11 -9
  223. package/src/internal/auth/config.ts +44 -0
  224. package/src/internal/auth/mtls.ts +1 -0
  225. package/src/internal/auth/token.ts +1 -0
  226. package/src/internal/auth/tokenCredentials.ts +4 -2
  227. package/src/internal/child.ts +8 -6
  228. package/src/{bin.ts → internal/childMain.ts} +16 -61
  229. package/src/internal/childRuntime.ts +12 -10
  230. package/src/internal/cleanup.ts +3 -2
  231. package/src/internal/contract.ts +1 -0
  232. package/src/internal/credentials.ts +3 -1
  233. package/src/internal/directTransport.ts +9 -2
  234. package/src/internal/entry.ts +53 -16
  235. package/src/internal/entryConfig.ts +10 -132
  236. package/src/internal/execution.ts +17 -15
  237. package/src/internal/follow.ts +2 -1
  238. package/src/internal/forkTree.ts +2 -1
  239. package/src/internal/host/local.ts +1 -0
  240. package/src/internal/host/runner.ts +7 -5
  241. package/src/internal/host.ts +9 -8
  242. package/src/internal/importer.ts +3 -2
  243. package/src/internal/listenerStartup.ts +4 -2
  244. package/src/internal/loadModule.ts +1 -0
  245. package/src/internal/platform.ts +1 -12
  246. package/src/internal/port.ts +11 -6
  247. package/src/internal/runner/Bootstrap.ts +1 -0
  248. package/src/internal/runner/Connection.ts +13 -11
  249. package/src/internal/runner/Execution.ts +14 -13
  250. package/src/internal/runner/Local.ts +3 -2
  251. package/src/internal/runner/Lock.ts +1 -0
  252. package/src/internal/runner/Multiplex.ts +2 -1
  253. package/src/internal/runner/Packages.ts +7 -5
  254. package/src/internal/runner/ProcessObservation.ts +2 -1
  255. package/src/internal/runner/Processes.ts +3 -1
  256. package/src/internal/runner/Retention.ts +1 -0
  257. package/src/internal/runner/Store.ts +3 -2
  258. package/src/internal/runner/Supervisor.ts +22 -20
  259. package/src/internal/runner/Watchdog.ts +3 -1
  260. package/src/internal/runner/Wire.ts +13 -12
  261. package/src/internal/runner/accept.ts +6 -5
  262. package/src/internal/runner/command.ts +3 -2
  263. package/src/internal/runner/connectionEnded.ts +2 -1
  264. package/src/internal/runner/model.ts +5 -3
  265. package/src/internal/services.ts +9 -2
  266. package/src/internal/socketChannel.ts +2 -1
  267. package/src/internal/stdioChannel.ts +4 -2
  268. package/src/internal/supervisorPlugin.ts +10 -8
  269. package/src/internal/transportOptions.ts +1 -0
  270. package/src/internal/watchdogMain.ts +5 -3
  271. package/src/internal/websocket.ts +5 -2
  272. package/src/internal/websocketServer.ts +6 -4
  273. package/src/internal/workerChannel.ts +1 -0
  274. package/src/internal/workerMain.ts +21 -5
  275. package/src/runner/auth/bearer.ts +10 -6
  276. package/src/runner/auth/jwt.ts +10 -41
  277. package/src/runner/auth/mtls.ts +6 -3
  278. package/src/runner/auth/none.ts +3 -1
  279. package/src/runner/index.ts +102 -11
  280. package/src/runner/stdio.ts +15 -10
  281. package/src/runner/unix.ts +7 -4
  282. package/src/runner/websocket.ts +9 -7
  283. package/dist/Auth-BElTC9_X.js +0 -6
  284. package/dist/Bootstrap-H9gDsgsC.js +0 -9
  285. package/dist/ConfigDirectory-BCC6q2R4.js +0 -5
  286. package/dist/Contract-DsJtisvL.js +0 -83
  287. package/dist/Errors-DYhsGZcZ.js +0 -58
  288. package/dist/FailureGroup-BgT73AaR.js +0 -63
  289. package/dist/Framing-G9eSaeLb.js +0 -61
  290. package/dist/Graft-B71CPA2Y.js +0 -996
  291. package/dist/Packages-AgoCGotL.js +0 -108
  292. package/dist/Peer-DXeVrGBh.js +0 -342
  293. package/dist/ProcessObservation-gLgGirYv.js +0 -38
  294. package/dist/ServeLifecycle-Bd1FPJ6e.js +0 -24
  295. package/dist/Transport-DULzpsgR.js +0 -6
  296. package/dist/WatchdogProtocol-BZmVxrBP.js +0 -17
  297. package/dist/bin.js +0 -28276
  298. package/dist/bin.js.map +0 -1
  299. package/dist/childRuntime-Bm3iSg_N.js +0 -192
  300. package/dist/command-9zrHdbwT.js +0 -7
  301. package/dist/connectionEnded-BwcxQ7W8.js +0 -54
  302. package/dist/directTransport-DrexuPSm.js +0 -5
  303. package/dist/entry-psOpX3Bj.js +0 -736
  304. package/dist/importer-Cvf88eAY.js +0 -344
  305. package/dist/internal/ServeLifecycle.js.map +0 -1
  306. package/dist/internal/entryConfig.d.ts.map +0 -1
  307. package/dist/internal/platform.js.map +0 -1
  308. package/dist/internal/release.js +0 -25
  309. package/dist/internal/release.js.map +0 -1
  310. package/dist/internal/serve.js +0 -60
  311. package/dist/internal/serve.js.map +0 -1
  312. package/dist/port--3x2zJ4D.js +0 -285
  313. package/dist/release-DfZPuIcK.js +0 -23
  314. package/dist/rolldown-runtime-DYf_mQCB.js +0 -34
  315. package/dist/socketChannel-CJvL2DiB.js +0 -3658
  316. package/dist/supervisorPlugin-t6Z6PrhD.js +0 -733
  317. package/dist/token-CYBNNlhS.js +0 -17
  318. package/dist/tokenCredentials-CbCuk-Rt.js +0 -31
  319. package/dist/websocketServer-NQhODlEt.js +0 -60
  320. package/dist/workerChannel-C8hhBJzA.js +0 -27
  321. package/src/internal/release.ts +0 -72
  322. package/src/internal/serve.ts +0 -119
  323. /package/dist/{bin.d.ts → internal/childMain.d.ts} +0 -0
@@ -1,7 +1,14 @@
1
1
  import { Array, Context, Effect, Record } from "effect"
2
+ import {
3
+ RpcClient,
4
+ RpcServer,
5
+ type Rpc,
6
+ type RpcClientError,
7
+ type RpcGroup,
8
+ } from "effect/rpc"
9
+
2
10
  import { Graft } from "@graftland/graft"
3
- import { RpcClient, RpcServer } from "effect/rpc"
4
- import type { Rpc, RpcClientError, RpcGroup } from "effect/rpc"
11
+
5
12
  import type { Service } from "../Contract"
6
13
 
7
14
  export const service = <
@@ -1,7 +1,8 @@
1
1
  import { Cause, Effect, Exit, Sink, Stream } from "effect"
2
2
  import { Socket } from "effect/socket"
3
+
3
4
  import { TransportError } from "../Errors"
4
- import { FrameError, isCompleteFrame, decoder, encode } from "./runner/Framing"
5
+ import { decoder, encode, FrameError, isCompleteFrame } from "./runner/Framing"
5
6
 
6
7
  /** WebSocket boundaries are a wire compatibility detail, not Channel chunk boundaries. */
7
8
  export const fromSocket = Effect.fnUntraced(function* (socket: Socket.Socket) {
@@ -1,7 +1,9 @@
1
- import { NodeSink } from "@effect/platform-node"
2
- import { Cause, Effect, Stdio, Stream } from "effect"
3
1
  // @effect-diagnostics-next-line nodeBuiltinImport:off -- Node's extra inherited descriptor carries protocol output separately from console output.
4
2
  import { createWriteStream } from "node:fs"
3
+
4
+ import { Cause, Effect, Stdio, Stream } from "effect"
5
+ import { NodeSink } from "@effect/platform-node"
6
+
5
7
  import { TransportError } from "../Errors"
6
8
  import type * as Port from "./port"
7
9
 
@@ -1,4 +1,3 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
1
  import {
3
2
  Context,
4
3
  Effect,
@@ -11,15 +10,18 @@ import {
11
10
  } from "effect"
12
11
  import { Digest, SecureRandom } from "effect/crypto"
13
12
  import { ChildProcessSpawner } from "effect/process"
14
- import { Supervisor } from "./Supervisor"
15
- import { PositiveDuration } from "./config"
13
+
14
+ import { Graft, Plugin } from "@graftland/graft"
16
15
  import { ConfigDirectory } from "@graftland/loader"
16
+
17
+ import { PositiveDuration } from "./config"
18
+ import { accept } from "./runner/accept"
19
+ import * as Execution from "./runner/Execution"
17
20
  import * as Lock from "./runner/Lock"
18
21
  import * as Stores from "./runner/Store"
19
- import * as Execution from "./runner/Execution"
20
22
  import * as Engine from "./runner/Supervisor"
21
- import { accept } from "./runner/accept"
22
- import * as Lifecycle from "./ServeLifecycle"
23
+ import * as Lifecycle from "./RunnerLifecycle"
24
+ import { Supervisor } from "./Supervisor"
23
25
 
24
26
  export const Config = Schema.Struct({
25
27
  root: Schema.String,
@@ -31,7 +33,7 @@ export default Plugin.make({
31
33
  name: "remote-supervisor",
32
34
  config: Config,
33
35
  inject: [
34
- Plugin.optional(Lifecycle.ServeLifecycle),
36
+ Plugin.optional(Lifecycle.RunnerLifecycle),
35
37
  FileSystem.FileSystem,
36
38
  Path.Path,
37
39
  ChildProcessSpawner.ChildProcessSpawner,
@@ -39,7 +41,7 @@ export default Plugin.make({
39
41
  Digest.Digest,
40
42
  ],
41
43
  apply: Effect.fnUntraced(function* (options) {
42
- const lifecycle = yield* Effect.serviceOption(Lifecycle.ServeLifecycle)
44
+ const lifecycle = yield* Effect.serviceOption(Lifecycle.RunnerLifecycle)
43
45
  const resources = yield* Lifecycle.resources(lifecycle)
44
46
  const path = yield* Path.Path
45
47
  const directory = yield* ConfigDirectory.pipe(
@@ -1,4 +1,5 @@
1
1
  import type { Duration } from "effect"
2
+
2
3
  export interface WebsocketOptions {
3
4
  readonly url: string
4
5
  readonly tls?: {
@@ -1,9 +1,11 @@
1
1
  /** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */
2
- import { NodeRuntime, NodeStream } from "@effect/platform-node"
3
- import { Clock, Effect, FiberHandle, Ref, Schema, Stream } from "effect"
4
2
  import { Socket } from "node:net"
5
- import { parentPort } from "node:worker_threads"
6
3
  import process from "node:process"
4
+ import { parentPort } from "node:worker_threads"
5
+
6
+ import { Clock, Effect, FiberHandle, Ref, Schema, Stream } from "effect"
7
+ import { NodeRuntime, NodeStream } from "@effect/platform-node"
8
+
7
9
  import { CommandJson, Notice } from "./runner/WatchdogProtocol"
8
10
 
9
11
  // The runner machine is trusted. A suspended machine cannot enforce a deadline until it resumes.
@@ -1,14 +1,17 @@
1
1
  import { Array, Effect, Layer, Redacted, Schema } from "effect"
2
2
  import { Socket } from "effect/socket"
3
+
3
4
  import WS from "ws"
5
+
4
6
  import type { ClientCertificate } from "../Auth"
5
7
  import type { Properties } from "../Transport"
8
+ import { headerSize, maxPayload } from "./runner/Framing"
9
+ import type { WebsocketOptions } from "./transportOptions"
10
+
6
11
  interface PreparedCredentials {
7
12
  readonly certificate?: ClientCertificate
8
13
  readonly authorization?: Redacted.Redacted<string>
9
14
  }
10
- import type { WebsocketOptions } from "./transportOptions"
11
- import { headerSize, maxPayload } from "./runner/Framing"
12
15
 
13
16
  export const protocol = "graft-remote.v1"
14
17
  export const path = "/graft"
@@ -1,4 +1,5 @@
1
- import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node"
1
+ import { TLSSocket } from "node:tls"
2
+
2
3
  import {
3
4
  Array,
4
5
  Cause,
@@ -11,15 +12,16 @@ import {
11
12
  } from "effect"
12
13
  import { HttpServerRequest, HttpServerResponse } from "effect/http"
13
14
  import type { Socket } from "effect/socket"
14
- import { TLSSocket } from "node:tls"
15
+ import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node"
16
+
15
17
  import {
18
+ TransportError,
16
19
  type AuthenticationFailed,
17
20
  type AuthenticatorUnavailable,
18
- TransportError,
19
21
  } from "../Errors"
20
22
  import type { Accept, Handshake, Serving } from "../Transport"
21
23
  import * as Channel from "./socketChannel"
22
- import { path, protocol, payloadLimit } from "./websocket"
24
+ import { path, payloadLimit, protocol } from "./websocket"
23
25
 
24
26
  const rejection = (error: AuthenticationFailed | AuthenticatorUnavailable) =>
25
27
  error._tag === "AuthenticatorUnavailable"
@@ -1,4 +1,5 @@
1
1
  import { Cause, Effect, FiberSet, Queue, Sink, Stream } from "effect"
2
+
2
3
  import { TransportError } from "../Errors"
3
4
  import type { Channel } from "./port"
4
5
 
@@ -1,12 +1,15 @@
1
1
  /** Executable entry for a direct worker; platform services belong to this thread. */
2
- import { Graft } from "@graftland/graft"
3
- import { NodeRuntime } from "@effect/platform-node"
4
- import { Effect, Layer, Schema } from "effect"
5
2
  import { parentPort, workerData } from "node:worker_threads"
3
+
4
+ import { Cause, Effect, Layer, Logger, Schema } from "effect"
5
+ import { NodeRuntime } from "@effect/platform-node"
6
+
7
+ import { Graft } from "@graftland/graft"
8
+
6
9
  import { load, run } from "./childRuntime"
10
+ import { platform } from "./platform"
7
11
  import { Bootstrap } from "./workerBootstrap"
8
12
  import * as Channel from "./workerChannel"
9
- import { platform } from "./platform"
10
13
 
11
14
  const main = Effect.scoped(
12
15
  Effect.gen(function* () {
@@ -19,5 +22,18 @@ const main = Effect.scoped(
19
22
  }),
20
23
  )
21
24
  NodeRuntime.runMain(
22
- main.pipe(Effect.provide(Graft.layer.pipe(Layer.provide(platform)))),
25
+ Effect.scoped(
26
+ Effect.gen(function* () {
27
+ const context = yield* Layer.build(
28
+ Graft.layer.pipe(Layer.provide(platform)),
29
+ )
30
+ return yield* main.pipe(Effect.provideContext(context))
31
+ }),
32
+ ).pipe(
33
+ Effect.tapCause((cause) =>
34
+ Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logError(cause),
35
+ ),
36
+ Effect.provideService(Logger.LogToStderr, true),
37
+ ),
38
+ { disableErrorReporting: true },
23
39
  )
@@ -1,9 +1,11 @@
1
- import { Option } from "effect"
2
- import { Graft, Plugin } from "@graftland/graft"
1
+ // @effect-diagnostics-next-line nodeBuiltinImport:off -- Token digests use Node's constant-time comparison
2
+ import { timingSafeEqual } from "node:crypto"
3
+
3
4
  import {
4
5
  Array,
5
6
  Effect,
6
7
  FileSystem,
8
+ Option,
7
9
  Path,
8
10
  Record,
9
11
  Redacted,
@@ -11,13 +13,15 @@ import {
11
13
  } from "effect"
12
14
  import { Digest } from "effect/crypto"
13
15
  import { Hex } from "effect/encoding"
14
- // @effect-diagnostics-next-line nodeBuiltinImport:off -- Token digests use Node's constant-time comparison
15
- import { timingSafeEqual } from "node:crypto"
16
- import { Authenticator } from "../../Auth"
16
+
17
+ import { Graft, Plugin } from "@graftland/graft"
17
18
  import { ConfigDirectory } from "@graftland/loader"
19
+
20
+ import { Authenticator } from "../../Auth"
21
+ import { Bearer as Config } from "../../internal/auth/config"
18
22
  import * as Token from "../../internal/auth/token"
19
23
 
20
- export const Config = Schema.Struct({ tokens: Schema.String })
24
+ export { Config }
21
25
  const Tokens = Schema.fromJsonString(
22
26
  Schema.Record(
23
27
  Schema.String.check(Schema.isPattern(/^[0-9a-fA-F]{64}$/)),
@@ -1,50 +1,19 @@
1
- import { Option } from "effect"
2
- import { Graft, Plugin } from "@graftland/graft"
3
- import {
4
- Cause,
5
- Duration,
6
- Effect,
7
- FileSystem,
8
- Layer,
9
- Path,
10
- Schema,
11
- } from "effect"
12
- import { Jwk, Jwks, Jwt } from "effect/jose"
1
+ import { Cause, Effect, FileSystem, Layer, Option, Path, Schema } from "effect"
13
2
  import { Signature } from "effect/crypto"
14
3
  import { HttpClient } from "effect/http"
15
- import { Authenticator } from "../../Auth"
4
+ import { Jwk, Jwks, Jwt } from "effect/jose"
5
+
6
+ import { Graft, Plugin } from "@graftland/graft"
16
7
  import { ConfigDirectory } from "@graftland/loader"
8
+
9
+ import { Authenticator } from "../../Auth"
17
10
  import { AuthenticationFailed, AuthenticatorUnavailable } from "../../Errors"
11
+ import { Jwt as Config } from "../../internal/auth/config"
18
12
  import * as Token from "../../internal/auth/token"
19
13
 
20
- export const ClockTolerance = Schema.DurationFromString.check(
21
- Schema.makeFilter(
22
- (duration) =>
23
- Duration.isFinite(duration) && Duration.toMillis(duration) >= 0,
24
- { expected: "a finite, non-negative duration" },
25
- ),
26
- )
27
- export const Config = Schema.Struct({
28
- issuer: Schema.NonEmptyString,
29
- audience: Schema.NonEmptyArray(Schema.NonEmptyString),
30
- algorithms: Schema.NonEmptyArray(Jwk.AsymmetricAlgorithm),
31
- identityClaim: Schema.NonEmptyString.pipe(
32
- Schema.withDecodingDefaultKey(Effect.succeed("sub")),
33
- ),
34
- clockTolerance: ClockTolerance.pipe(
35
- Schema.withDecodingDefaultKey(Effect.succeed("5 seconds")),
36
- ),
37
- keys: Schema.Union([
38
- Schema.Struct({
39
- jwksUrl: Schema.String,
40
- publicKey: Schema.optionalKey(Schema.Never),
41
- }),
42
- Schema.Struct({
43
- publicKey: Schema.String,
44
- jwksUrl: Schema.optionalKey(Schema.Never),
45
- }),
46
- ]),
47
- })
14
+ export { ClockTolerance } from "../../internal/auth/config"
15
+
16
+ export { Config }
48
17
  const keys = Effect.fnUntraced(function* (config: typeof Config.Type) {
49
18
  if (config.keys.jwksUrl !== undefined)
50
19
  return Jwks.layerRemote({ url: config.keys.jwksUrl })
@@ -1,10 +1,13 @@
1
+ import { Effect, FileSystem, Option, Path } from "effect"
2
+
1
3
  import { Graft, Plugin } from "@graftland/graft"
2
- import { Effect, FileSystem, Option, Path, Schema } from "effect"
3
- import { Authenticator, type AuthenticatorApi } from "../../Auth"
4
4
  import { ConfigDirectory } from "@graftland/loader"
5
+
6
+ import { Authenticator, type AuthenticatorApi } from "../../Auth"
7
+ import { Mtls as Config } from "../../internal/auth/config"
5
8
  import { identityFromSubjectAltName } from "../../internal/auth/mtls"
6
9
 
7
- export const Config = Schema.Struct({ ca: Schema.String })
10
+ export { Config }
8
11
  const read = Effect.fnUntraced(function* (ca: string) {
9
12
  const fs = yield* FileSystem.FileSystem
10
13
  const path = yield* Path.Path
@@ -1,5 +1,7 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
1
  import { Effect, Schema } from "effect"
2
+
3
+ import { Graft, Plugin } from "@graftland/graft"
4
+
3
5
  import { Authenticator } from "../../Auth"
4
6
 
5
7
  export default Plugin.make({
@@ -1,13 +1,27 @@
1
- import { Graft, Plugin } from "@graftland/graft"
1
+ import {
2
+ Array,
3
+ Cause,
4
+ Deferred,
5
+ Effect,
6
+ Exit,
7
+ Option,
8
+ Path,
9
+ Schema,
10
+ Stream,
11
+ } from "effect"
2
12
  import { SecureRandom } from "effect/crypto"
3
- import { Path } from "effect"
13
+
14
+ import { Application, ProtocolOutput } from "@graftland/cli/Application"
15
+ import { Graft, Plugin, type Fork } from "@graftland/graft"
4
16
  import { ModuleResolver } from "@graftland/loader"
5
- import { Deferred, Effect, Schema, Stream } from "effect"
6
- import * as Configuration from "../internal/entryConfig"
7
- import { boundary, resolve } from "../internal/entry"
17
+
8
18
  import * as Assembly from "../internal/assembly"
9
- import * as Startup from "../internal/listenerStartup"
19
+ import { cleanupCause } from "../internal/cleanup"
20
+ import { boundary, resolve } from "../internal/entry"
21
+ import * as Configuration from "../internal/entryConfig"
10
22
  import { follow } from "../internal/follow"
23
+ import * as Startup from "../internal/listenerStartup"
24
+ import * as Lifecycle from "../internal/RunnerLifecycle"
11
25
  import { Supervisor } from "../internal/Supervisor"
12
26
  import supervisor, {
13
27
  Config as SupervisorConfig,
@@ -45,7 +59,12 @@ const startListener = Effect.fnUntraced(function* (
45
59
  const owner = Plugin.make({
46
60
  name: "remote-supervised-runtime",
47
61
  config: Configuration.Runner,
48
- inject: [ModuleResolver.ModuleResolver, Path.Path, SecureRandom.SecureRandom],
62
+ inject: [
63
+ ModuleResolver.ModuleResolver,
64
+ Path.Path,
65
+ SecureRandom.SecureRandom,
66
+ Plugin.optional(Application),
67
+ ],
49
68
  apply: Effect.fnUntraced(function* (config) {
50
69
  const options = yield* Schema.encodeEffect(SupervisorConfig)(config)
51
70
  const engine = yield* Graft.plugin(supervisor, options)
@@ -61,6 +80,21 @@ const owner = Plugin.make({
61
80
  { concurrency: "unbounded" },
62
81
  )
63
82
  yield* Startup.validate(descriptions)
83
+ const protocol = yield* ProtocolOutput
84
+ if (
85
+ Array.some(
86
+ descriptions,
87
+ (description) => description.properties.protocol === "stdio",
88
+ ) !== protocol
89
+ )
90
+ return yield* Lifecycle.StartupError.make({
91
+ detail:
92
+ "A stdio runner requires graft start --stdio and exactly one stdio listener",
93
+ })
94
+ if (protocol) {
95
+ const application = yield* Effect.serviceOption(Application)
96
+ if (Option.isSome(application)) yield* application.value.claimProtocol
97
+ }
64
98
  yield* Deferred.succeed(begin, undefined)
65
99
  yield* Effect.forEach(
66
100
  listeners,
@@ -85,13 +119,70 @@ const owner = Plugin.make({
85
119
  )
86
120
  }),
87
121
  })
122
+ const shutdown = Effect.fnUntraced(function* (
123
+ fork: Fork.Fork,
124
+ lifecycle: typeof Lifecycle.RunnerLifecycle.Service,
125
+ ) {
126
+ const disposed = yield* Effect.exit(fork.dispose)
127
+ const result = yield* Deferred.poll(lifecycle.released)
128
+ const released = Option.isSome(result)
129
+ ? yield* Effect.exit(result.value)
130
+ : Exit.void
131
+ const cause = Cause.combine(
132
+ Exit.isFailure(disposed) ? disposed.cause : Cause.empty,
133
+ Exit.isFailure(released) ? released.cause : Cause.empty,
134
+ )
135
+ if (cause.reasons.length > 0)
136
+ return yield* Effect.failCause(cleanupCause(cause))
137
+ })
138
+
88
139
  export default Plugin.make({
89
140
  name: "remote-server",
90
- config: Configuration.Runner,
91
- apply: Effect.fnUntraced(function* (config) {
141
+ config: Schema.Unknown,
142
+ inject: [Plugin.optional(Application)],
143
+ apply: Effect.fnUntraced(function* (input) {
144
+ const application = yield* Effect.serviceOption(Application)
145
+ const config = yield* Schema.decodeUnknownEffect(Configuration.Runner)(
146
+ input,
147
+ ).pipe(
148
+ Effect.tapError((error) =>
149
+ Option.isSome(application)
150
+ ? application.value.finish(Exit.fail(error))
151
+ : Effect.void,
152
+ ),
153
+ )
154
+ const lifecycle = yield* Lifecycle.make
92
155
  const encoded = yield* Schema.encodeEffect(Configuration.Runner)(config)
93
- const fork = yield* Graft.plugin(owner, encoded, { isolate: [Supervisor] })
156
+ const assembly = Plugin.make({
157
+ name: "remote-runner-runtime",
158
+ apply: Effect.fnUntraced(function* () {
159
+ yield* Graft.provide(Lifecycle.RunnerLifecycle, lifecycle)
160
+ const fork = yield* Graft.plugin(owner, encoded)
161
+ const fail = yield* boundary("runner")
162
+ yield* follow(fork, fail)
163
+ }),
164
+ })
165
+ const fork = yield* Graft.plugin(assembly, undefined, {
166
+ isolate: [Supervisor, Lifecycle.RunnerLifecycle],
167
+ })
168
+ if (Option.isSome(application)) {
169
+ yield* application.value.onExit(shutdown(fork, lifecycle))
170
+ yield* Plugin.fork(
171
+ Deferred.await(lifecycle.ended).pipe(
172
+ Effect.matchCauseEffect({
173
+ onSuccess: () => application.value.finish(Exit.void),
174
+ onFailure: (cause) =>
175
+ application.value.finish(Exit.failCause(cause)),
176
+ }),
177
+ ),
178
+ )
179
+ }
94
180
  const fail = yield* boundary("runner")
95
- yield* follow(fork, fail)
181
+ yield* follow(fork, (cause) =>
182
+ (Option.isSome(application) && !Cause.hasInterruptsOnly(cause)
183
+ ? application.value.finish(Exit.failCause(cause))
184
+ : Effect.void
185
+ ).pipe(Effect.andThen(fail(cause))),
186
+ )
96
187
  }),
97
188
  })
@@ -1,4 +1,3 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
1
  import {
3
2
  Cause,
4
3
  Deferred,
@@ -10,9 +9,12 @@ import {
10
9
  Stdio,
11
10
  Stream,
12
11
  } from "effect"
13
- import { Listener, type Accept } from "../Transport"
12
+
13
+ import { Graft, Plugin } from "@graftland/graft"
14
+ import * as Release from "@graftland/graft/Release"
15
+
14
16
  import { TransportError } from "../Errors"
15
- import * as Release from "../internal/release"
17
+ import { Listener, type Accept } from "../Transport"
16
18
 
17
19
  export const Config = Schema.Struct({ auth: Schema.optionalKey(Schema.Never) })
18
20
  export default Plugin.make({
@@ -30,7 +32,7 @@ export default Plugin.make({
30
32
  },
31
33
  bind: Effect.fnUntraced(function* () {
32
34
  const ready = yield* Deferred.make<void>()
33
- const eof = yield* Deferred.make<void>()
35
+ const eof = yield* Deferred.make<void, TransportError>()
34
36
  const channel = {
35
37
  input: stdio.stdin.pipe(
36
38
  Stream.onExit((exit) =>
@@ -42,13 +44,16 @@ export default Plugin.make({
42
44
  TransportError.make({ cause: Cause.fail(error) }),
43
45
  ),
44
46
  ),
45
- output: stdio
46
- .stdout({ endOnDone: false })
47
- .pipe(
48
- Sink.mapError((error) =>
49
- TransportError.make({ cause: Cause.fail(error) }),
50
- ),
47
+ output: stdio.stdout({ endOnDone: false }).pipe(
48
+ Sink.mapError((error) =>
49
+ TransportError.make({ cause: Cause.fail(error) }),
51
50
  ),
51
+ Sink.onExit((exit) =>
52
+ Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)
53
+ ? Deferred.failCause(eof, exit.cause)
54
+ : Effect.void,
55
+ ),
56
+ ),
52
57
  }
53
58
  return {
54
59
  ready: Deferred.await(ready),
@@ -1,11 +1,14 @@
1
- import { Graft, Plugin } from "@graftland/graft"
2
- import { ConfigDirectory } from "@graftland/loader"
3
- import { Cause, Console, Effect, Option, Path, Schema } from "effect"
4
1
  // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer takes a factory for an HTTP/1.1 server on the Unix socket
5
2
  import { createServer } from "node:http"
6
- import { Listener } from "../Transport"
3
+
4
+ import { Cause, Console, Effect, Option, Path, Schema } from "effect"
5
+
6
+ import { Graft, Plugin } from "@graftland/graft"
7
+ import { ConfigDirectory } from "@graftland/loader"
8
+
7
9
  import { TransportError } from "../Errors"
8
10
  import * as Server from "../internal/websocketServer"
11
+ import { Listener } from "../Transport"
9
12
 
10
13
  export const Config = Schema.Struct({ path: Schema.String })
11
14
  const Listening = Schema.fromJsonString(
@@ -1,4 +1,7 @@
1
- import { Graft, Plugin } from "@graftland/graft"
1
+ // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer takes a factory for an HTTP/1.1 upgrade server
2
+ import { createServer } from "node:http"
3
+ import { createSecureServer } from "node:http2"
4
+
2
5
  import {
3
6
  Cause,
4
7
  Console,
@@ -9,16 +12,15 @@ import {
9
12
  Schema,
10
13
  String,
11
14
  } from "effect"
15
+
16
+ import { Graft, Plugin } from "@graftland/graft"
12
17
  import { ConfigDirectory } from "@graftland/loader"
13
- import { createSecureServer } from "node:http2"
14
- import { Url, path as upgradePath } from "../internal/websocket"
15
- import { Listener } from "../Transport"
18
+
16
19
  import type { TlsPolicy } from "../Auth"
17
20
  import { TransportError } from "../Errors"
21
+ import { properties, path as upgradePath, Url } from "../internal/websocket"
18
22
  import * as Server from "../internal/websocketServer"
19
- import { properties } from "../internal/websocket"
20
- // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer takes a factory for an HTTP/1.1 upgrade server
21
- import { createServer } from "node:http"
23
+ import { Listener } from "../Transport"
22
24
 
23
25
  const url = (protocol: "ws:" | "wss:") =>
24
26
  Url.check(
@@ -1,6 +0,0 @@
1
- import { Context } from "effect";
2
- // packages/remote/src/Auth.ts
3
- /** Credentials and authenticated identities shared by transport plugins. */
4
- var Credentials = class extends Context.Service()("@graftland/plugin-remote/Auth/Credentials") {};
5
- var Authenticator = class extends Context.Service()("@graftland/plugin-remote/Auth/Authenticator") {};
6
- export { Credentials as n, Authenticator as t };
@@ -1,9 +0,0 @@
1
- import { D as Identity } from "./Peer-DXeVrGBh.js";
2
- import { r as Limits } from "./port--3x2zJ4D.js";
3
- import { Schema } from "effect";
4
- // packages/remote/src/internal/runner/Bootstrap.ts
5
- const Bootstrap = Schema.Struct({
6
- identity: Identity,
7
- limits: Limits
8
- });
9
- export { Bootstrap as t };
@@ -1,5 +0,0 @@
1
- import { Context, Option } from "effect";
2
- // packages/loader/src/ConfigDirectory.ts
3
- /** Directory of the supplied configuration path, before following symbolic links. */
4
- const ConfigDirectory = Context.Reference("@graftland/loader/ConfigDirectory", { defaultValue: Option.none });
5
- export { ConfigDirectory as t };