@graftland/plugin-remote 0.3.0 → 0.3.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 (209) hide show
  1. package/dist/Auth.d.ts +2 -2
  2. package/dist/Auth.d.ts.map +1 -1
  3. package/dist/Auth.js.map +1 -1
  4. package/dist/{Bootstrap-MCwivGN1.js → Bootstrap-H9gDsgsC.js} +2 -2
  5. package/dist/{Contract-CcpSIJm4.js → Contract-DsJtisvL.js} +8 -46
  6. package/dist/Contract.d.ts +50 -53
  7. package/dist/Contract.d.ts.map +1 -1
  8. package/dist/Contract.js +1 -1
  9. package/dist/Contract.js.map +1 -1
  10. package/dist/{Errors-oPsTLY7l.js → Errors-DYhsGZcZ.js} +14 -1
  11. package/dist/Errors.d.ts +19 -0
  12. package/dist/Errors.d.ts.map +1 -1
  13. package/dist/Errors.js +14 -1
  14. package/dist/Errors.js.map +1 -1
  15. package/dist/{FailureGroup-BcH0XOBi.js → FailureGroup-BgT73AaR.js} +14 -4
  16. package/dist/{Framing-zaYdOJnT.js → Framing-G9eSaeLb.js} +1 -1
  17. package/dist/{Graft-BsYq3F-J.js → Graft-B71CPA2Y.js} +46 -35
  18. package/dist/{Packages-B1TPk8pa.js → Packages-AgoCGotL.js} +23 -26
  19. package/dist/{Peer-IJgFK6mD.js → Peer-DXeVrGBh.js} +5 -5
  20. package/dist/{ProcessObservation-DEGrEMfP.js → ProcessObservation-gLgGirYv.js} +1 -1
  21. package/dist/{ServeLifecycle-CJM0gG5B.js → ServeLifecycle-Bd1FPJ6e.js} +1 -1
  22. package/dist/Testing.d.ts +4 -4
  23. package/dist/Testing.d.ts.map +1 -1
  24. package/dist/Testing.js +10 -4
  25. package/dist/Testing.js.map +1 -1
  26. package/dist/Transport.d.ts +2 -2
  27. package/dist/Transport.d.ts.map +1 -1
  28. package/dist/Transport.js.map +1 -1
  29. package/dist/bin.js +48 -47
  30. package/dist/bin.js.map +1 -1
  31. package/dist/{childRuntime-DSqtFN9o.js → childRuntime-Bm3iSg_N.js} +30 -26
  32. package/dist/connectionEnded-BwcxQ7W8.js +54 -0
  33. package/dist/{entry-SYsx9VNb.js → entry-psOpX3Bj.js} +76 -48
  34. package/dist/host/auth/bearer.d.ts +1 -2
  35. package/dist/host/auth/bearer.d.ts.map +1 -1
  36. package/dist/host/auth/bearer.js +1 -1
  37. package/dist/host/auth/bearer.js.map +1 -1
  38. package/dist/host/auth/jwt.d.ts +1 -2
  39. package/dist/host/auth/jwt.d.ts.map +1 -1
  40. package/dist/host/auth/jwt.js +1 -1
  41. package/dist/host/auth/jwt.js.map +1 -1
  42. package/dist/host/auth/mtls.js +2 -2
  43. package/dist/host/auth/none.js +1 -1
  44. package/dist/host/command.d.ts +1 -1
  45. package/dist/host/command.d.ts.map +1 -1
  46. package/dist/host/command.js +4 -4
  47. package/dist/host/command.js.map +1 -1
  48. package/dist/host/local.d.ts +1 -2
  49. package/dist/host/local.d.ts.map +1 -1
  50. package/dist/host/local.js +3 -3
  51. package/dist/host/local.js.map +1 -1
  52. package/dist/host/unix.d.ts +1 -1
  53. package/dist/host/unix.d.ts.map +1 -1
  54. package/dist/host/unix.js +3 -3
  55. package/dist/host/unix.js.map +1 -1
  56. package/dist/host/websocket.d.ts +1 -1
  57. package/dist/host/websocket.d.ts.map +1 -1
  58. package/dist/host/websocket.js +3 -3
  59. package/dist/host/websocket.js.map +1 -1
  60. package/dist/host/worker.d.ts +1 -2
  61. package/dist/host/worker.d.ts.map +1 -1
  62. package/dist/host/worker.js +4 -5
  63. package/dist/host/worker.js.map +1 -1
  64. package/dist/{importer-D7zSgqxq.js → importer-Cvf88eAY.js} +5 -8
  65. package/dist/index.d.ts +2 -3
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +10 -10
  68. package/dist/index.js.map +1 -1
  69. package/dist/internal/Certificates.js +4 -4
  70. package/dist/internal/Certificates.js.map +1 -1
  71. package/dist/internal/FailureGroup.js +3 -2
  72. package/dist/internal/FailureGroup.js.map +1 -1
  73. package/dist/internal/assembly.js +9 -2
  74. package/dist/internal/assembly.js.map +1 -1
  75. package/dist/internal/auth/mtls.js +1 -1
  76. package/dist/internal/auth/mtls.js.map +1 -1
  77. package/dist/internal/auth/tokenCredentials.d.ts +0 -1
  78. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  79. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  80. package/dist/internal/child.js +20 -17
  81. package/dist/internal/child.js.map +1 -1
  82. package/dist/internal/childRuntime.js +6 -4
  83. package/dist/internal/childRuntime.js.map +1 -1
  84. package/dist/internal/contract.js +26 -0
  85. package/dist/internal/contract.js.map +1 -0
  86. package/dist/internal/credentials.d.ts +6 -6
  87. package/dist/internal/credentials.d.ts.map +1 -1
  88. package/dist/internal/credentials.js.map +1 -1
  89. package/dist/internal/directTransport.d.ts +1 -1
  90. package/dist/internal/entry.d.ts +1 -2
  91. package/dist/internal/entry.d.ts.map +1 -1
  92. package/dist/internal/entry.js +4 -14
  93. package/dist/internal/entry.js.map +1 -1
  94. package/dist/internal/execution.js +44 -7
  95. package/dist/internal/execution.js.map +1 -1
  96. package/dist/internal/host/runner.js +7 -6
  97. package/dist/internal/host/runner.js.map +1 -1
  98. package/dist/internal/host.js +5 -5
  99. package/dist/internal/host.js.map +1 -1
  100. package/dist/internal/port.d.ts +2 -10
  101. package/dist/internal/port.js +5 -5
  102. package/dist/internal/port.js.map +1 -1
  103. package/dist/internal/release.js +1 -1
  104. package/dist/internal/release.js.map +1 -1
  105. package/dist/internal/runner/Connection.d.ts +1 -1
  106. package/dist/internal/runner/Connection.js +4 -4
  107. package/dist/internal/runner/Connection.js.map +1 -1
  108. package/dist/internal/runner/Execution.js +3 -3
  109. package/dist/internal/runner/Execution.js.map +1 -1
  110. package/dist/internal/runner/Framing.d.ts +1 -11
  111. package/dist/internal/runner/Framing.js +1 -1
  112. package/dist/internal/runner/Framing.js.map +1 -1
  113. package/dist/internal/runner/Local.js +1 -1
  114. package/dist/internal/runner/Local.js.map +1 -1
  115. package/dist/internal/runner/Lock.js +1 -1
  116. package/dist/internal/runner/Lock.js.map +1 -1
  117. package/dist/internal/runner/Packages.d.ts +1 -1
  118. package/dist/internal/runner/Packages.js +22 -25
  119. package/dist/internal/runner/Packages.js.map +1 -1
  120. package/dist/internal/runner/Processes.js +7 -9
  121. package/dist/internal/runner/Processes.js.map +1 -1
  122. package/dist/internal/runner/Store.js +3 -3
  123. package/dist/internal/runner/Store.js.map +1 -1
  124. package/dist/internal/runner/Supervisor.js +46 -47
  125. package/dist/internal/runner/Supervisor.js.map +1 -1
  126. package/dist/internal/runner/accept.js +3 -3
  127. package/dist/internal/runner/accept.js.map +1 -1
  128. package/dist/internal/runner/model.js +1 -1
  129. package/dist/internal/runner/model.js.map +1 -1
  130. package/dist/internal/serve.js +1 -1
  131. package/dist/internal/serve.js.map +1 -1
  132. package/dist/internal/services.d.ts +2 -12
  133. package/dist/internal/services.d.ts.map +1 -1
  134. package/dist/internal/services.js.map +1 -1
  135. package/dist/internal/supervisorPlugin.js +1 -1
  136. package/dist/internal/watchdogMain.js +5 -5
  137. package/dist/internal/watchdogMain.js.map +1 -1
  138. package/dist/internal/websocketServer.js +3 -1
  139. package/dist/internal/websocketServer.js.map +1 -1
  140. package/dist/internal/workerMain.js +3 -3
  141. package/dist/{port-Blbh8tms.js → port--3x2zJ4D.js} +8 -8
  142. package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
  143. package/dist/runner/auth/bearer.js +2 -2
  144. package/dist/runner/auth/jwt.js +4 -4
  145. package/dist/runner/auth/jwt.js.map +1 -1
  146. package/dist/runner/auth/mtls.js +3 -3
  147. package/dist/runner/auth/none.js +1 -1
  148. package/dist/runner/index.js +5 -5
  149. package/dist/runner/stdio.js +3 -3
  150. package/dist/runner/unix.js +3 -3
  151. package/dist/runner/websocket.js +4 -4
  152. package/dist/{socketChannel-KmtzF-9G.js → socketChannel-CJvL2DiB.js} +2 -2
  153. package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
  154. package/dist/{token-v5ne2I0-.js → token-CYBNNlhS.js} +1 -1
  155. package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CbCuk-Rt.js} +3 -3
  156. package/dist/{websocketServer-MXcCJx0v.js → websocketServer-NQhODlEt.js} +5 -3
  157. package/dist/{workerChannel-P82YdNjh.js → workerChannel-C8hhBJzA.js} +1 -1
  158. package/package.json +3 -3
  159. package/src/Auth.ts +9 -2
  160. package/src/Contract.ts +67 -51
  161. package/src/Errors.ts +23 -0
  162. package/src/Testing.ts +16 -2
  163. package/src/Transport.ts +6 -2
  164. package/src/bin.ts +28 -30
  165. package/src/host/auth/bearer.ts +1 -6
  166. package/src/host/auth/jwt.ts +1 -6
  167. package/src/host/command.ts +2 -0
  168. package/src/host/local.ts +5 -9
  169. package/src/host/unix.ts +2 -0
  170. package/src/host/websocket.ts +2 -0
  171. package/src/host/worker.ts +4 -6
  172. package/src/index.ts +8 -4
  173. package/src/internal/Certificates.ts +10 -13
  174. package/src/internal/FailureGroup.ts +128 -121
  175. package/src/internal/assembly.ts +19 -10
  176. package/src/internal/auth/mtls.ts +19 -20
  177. package/src/internal/auth/tokenCredentials.ts +1 -7
  178. package/src/internal/child.ts +249 -240
  179. package/src/internal/childRuntime.ts +84 -81
  180. package/src/internal/contract.ts +47 -0
  181. package/src/internal/credentials.ts +12 -9
  182. package/src/internal/entry.ts +11 -25
  183. package/src/internal/execution.ts +73 -14
  184. package/src/internal/host/runner.ts +153 -153
  185. package/src/internal/host.ts +123 -130
  186. package/src/internal/port.ts +100 -103
  187. package/src/internal/release.ts +3 -2
  188. package/src/internal/runner/Connection.ts +52 -60
  189. package/src/internal/runner/Execution.ts +163 -164
  190. package/src/internal/runner/Framing.ts +9 -10
  191. package/src/internal/runner/Local.ts +26 -27
  192. package/src/internal/runner/Lock.ts +23 -25
  193. package/src/internal/runner/Packages.ts +67 -70
  194. package/src/internal/runner/Processes.ts +89 -92
  195. package/src/internal/runner/Store.ts +110 -114
  196. package/src/internal/runner/Supervisor.ts +392 -405
  197. package/src/internal/runner/accept.ts +76 -84
  198. package/src/internal/runner/model.ts +20 -21
  199. package/src/internal/serve.ts +15 -13
  200. package/src/internal/services.ts +1 -19
  201. package/src/internal/watchdogMain.ts +16 -11
  202. package/src/internal/websocketServer.ts +18 -3
  203. package/src/runner/auth/jwt.ts +10 -6
  204. package/dist/cleanup-BPWr-5U9.js +0 -13
  205. package/dist/connectionEnded-DUgcobEd.js +0 -9
  206. package/dist/internal/childErrors.d.ts +0 -33
  207. package/dist/internal/childErrors.d.ts.map +0 -1
  208. package/dist/internal/port.d.ts.map +0 -1
  209. package/dist/internal/runner/Framing.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Framing.js","names":[],"sources":["../../../src/internal/runner/Framing.ts"],"sourcesContent":["import { Array, Effect, MutableRef, Option, Result, Schema } from \"effect\"\n\nexport class FrameError extends Schema.TaggedError<\n\tFrameError,\n\t{ readonly brand: unique symbol }\n>()(\"FrameError\", { detail: Schema.String }) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\n/** A complete byte stream ended; malformed trailing bytes remain FrameError. */\nexport class EndOfStream extends Schema.TaggedError<\n\tEndOfStream,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerEndOfStream\", {}) {\n\toverride get message() {\n\t\treturn \"Runner byte channel ended\"\n\t}\n}\nexport type Channel = 0 | 1\nexport interface Frame {\n\treadonly channel: Channel\n\treadonly payload: Uint8Array\n}\nexport const headerSize = 8\nexport const maxPayload = 1024 * 1024\nconst invalid = (detail: string) => FrameError.make({ detail })\n\n/** Version 2 carries only channel and length; request admission belongs to port. */\nexport const encode = (frame: Frame) =>\n\tEffect.gen(function* () {\n\t\tif (frame.payload.byteLength > maxPayload)\n\t\t\treturn yield* invalid(\"Runner frame exceeds the payload limit\")\n\t\tconst bytes = new Uint8Array(headerSize + frame.payload.byteLength)\n\t\tbytes.set([2, frame.channel, 0, 0])\n\t\tnew DataView(bytes.buffer).setUint32(4, frame.payload.byteLength)\n\t\tbytes.set(frame.payload, headerSize)\n\t\treturn bytes\n\t})\n\n/** Check a message boundary; the decoder still validates the frame's contents. */\nexport const isCompleteFrame = (bytes: Uint8Array): boolean =>\n\tbytes.byteLength >= headerSize &&\n\tnew DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(\n\t\t4,\n\t) ===\n\t\tbytes.byteLength - headerSize\n\n/** The decoder owns its byte buffer. Results expose malformed frames without throwing through a generator. */\nexport const decoder = () => {\n\tconst pending = MutableRef.make<Result.Result<Uint8Array, FrameError>>(\n\t\tResult.succeed(new Uint8Array(0)),\n\t)\n\tconst decode = (\n\t\tchunk: Uint8Array,\n\t): Result.Result<ReadonlyArray<Frame>, FrameError> =>\n\t\tResult.flatMap(MutableRef.get(pending), (previous) => {\n\t\t\tconst bytes = new Uint8Array(previous.length + chunk.length)\n\t\t\tbytes.set(previous)\n\t\t\tbytes.set(chunk, previous.length)\n\t\t\tconst frames = Array.unfold(\n\t\t\t\t0,\n\t\t\t\t(\n\t\t\t\t\toffset,\n\t\t\t\t): Option.Option<\n\t\t\t\t\treadonly [Result.Result<Frame, FrameError>, number]\n\t\t\t\t> => {\n\t\t\t\t\tif (bytes.length - offset < headerSize) return Option.none()\n\t\t\t\t\tconst header = new DataView(bytes.buffer, offset, headerSize)\n\t\t\t\t\tconst channel = header.getUint8(1)\n\t\t\t\t\tconst length = header.getUint32(4)\n\t\t\t\t\tif (\n\t\t\t\t\t\theader.getUint8(0) !== 2 ||\n\t\t\t\t\t\t(channel !== 0 && channel !== 1) ||\n\t\t\t\t\t\theader.getUint16(2) !== 0 ||\n\t\t\t\t\t\tlength > maxPayload\n\t\t\t\t\t)\n\t\t\t\t\t\treturn Option.some([\n\t\t\t\t\t\t\tResult.fail(\n\t\t\t\t\t\t\t\tinvalid(\"Invalid runner frame header or payload length\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tbytes.length,\n\t\t\t\t\t\t])\n\t\t\t\t\tconst end = offset + headerSize + length\n\t\t\t\t\tif (end > bytes.length) return Option.none()\n\t\t\t\t\treturn Option.some([\n\t\t\t\t\t\tResult.succeed({\n\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\tpayload: bytes.subarray(offset + headerSize, end),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tend,\n\t\t\t\t\t])\n\t\t\t\t},\n\t\t\t)\n\t\t\tconst result = Result.all(frames)\n\t\t\tMutableRef.set(\n\t\t\t\tpending,\n\t\t\t\tResult.map(result, (frames) =>\n\t\t\t\t\tbytes.subarray(\n\t\t\t\t\t\tArray.reduce(\n\t\t\t\t\t\t\tframes,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t(used, frame) => used + headerSize + frame.payload.length,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\treturn result\n\t\t})\n\treturn {\n\t\tdecode,\n\t\tfinish: Effect.suspend(() =>\n\t\t\tEffect.fromResult(\n\t\t\t\tResult.flatMap(MutableRef.get(pending), (bytes) =>\n\t\t\t\t\tbytes.length === 0\n\t\t\t\t\t\t? Result.succeed(undefined)\n\t\t\t\t\t\t: Result.fail(invalid(\"Runner connection ended inside a frame\")),\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t}\n}\n"],"mappings":";;AAEA,IAAa,aAAb,cAAgC,OAAO,YAGrC,CAAC,CAAC,cAAc,EAAE,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC;CAC5C,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;;AAEA,IAAa,cAAb,cAAiC,OAAO,YAGtC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;CAC5B,IAAa,UAAU;EACtB,OAAO;CACR;AACD;AAOA,MAAa,aAAa;AAC1B,MAAM,WAAW,WAAmB,WAAW,KAAK,EAAE,OAAO,CAAC;;AAG9D,MA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MAAM,QAAQ,OAAO,OAAO,KAAK;GAC3C,OAAO,OAAO,KAAK,CAClB,OAAO,QAAQ;IACd;IACA,SAAS,MAAM,SAAS,SAAA,GAAqB,GAAG;GACjD,CAAC,GACD,GACD,CAAC;EACF,CACD;EACA,MAAM,SAAS,OAAO,IAAI,MAAM;EAChC,WAAW,IACV,SACA,OAAO,IAAI,SAAS,WACnB,MAAM,SACL,MAAM,OACL,QACA,IACC,MAAM,UAAU,OAAA,IAAoB,MAAM,QAAQ,MACpD,CACD,CACD,CACD;EACA,OAAO;CACR,CAAC;CACF,OAAO;EACN;EACA,QAAQ,OAAO,cACd,OAAO,WACN,OAAO,QAAQ,WAAW,IAAI,OAAO,IAAI,UACxC,MAAM,WAAW,IACd,OAAO,QAAQ,KAAA,CAAS,IACxB,OAAO,KAAK,QAAQ,wCAAwC,CAAC,CACjE,CACD,CACD;CACD;AACD"}
1
+ {"version":3,"file":"Framing.js","names":[],"sources":["../../../src/internal/runner/Framing.ts"],"sourcesContent":["import { Array, Effect, MutableRef, Option, Result, Schema } from \"effect\"\n\nexport class FrameError extends Schema.TaggedError<\n\tFrameError,\n\t{ readonly brand: unique symbol }\n>()(\"FrameError\", { detail: Schema.String }) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\n/** A complete byte stream ended; malformed trailing bytes remain FrameError. */\nexport class EndOfStream extends Schema.TaggedError<\n\tEndOfStream,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerEndOfStream\", {}) {\n\toverride get message() {\n\t\treturn \"Runner byte channel ended\"\n\t}\n}\nexport type Channel = 0 | 1\nexport interface Frame {\n\treadonly channel: Channel\n\treadonly payload: Uint8Array\n}\nexport const headerSize = 8\nexport const maxPayload = 1024 * 1024\nconst invalid = (detail: string) => FrameError.make({ detail })\n\n/** Version 2 carries only channel and length; request admission belongs to port. */\nexport const encode = Effect.fnUntraced(function* (frame: Frame) {\n\tif (frame.payload.byteLength > maxPayload)\n\t\treturn yield* invalid(\"Runner frame exceeds the payload limit\")\n\tconst bytes = new Uint8Array(headerSize + frame.payload.byteLength)\n\tbytes.set([2, frame.channel, 0, 0])\n\tnew DataView(bytes.buffer).setUint32(4, frame.payload.byteLength)\n\tbytes.set(frame.payload, headerSize)\n\treturn bytes\n})\n\n/** Check a message boundary; the decoder still validates the frame's contents. */\nexport const isCompleteFrame = (bytes: Uint8Array): boolean =>\n\tbytes.byteLength >= headerSize &&\n\tnew DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(\n\t\t4,\n\t) ===\n\t\tbytes.byteLength - headerSize\n\n/** The decoder owns its byte buffer. Results expose malformed frames without throwing through a generator. */\nexport const decoder = () => {\n\tconst pending = MutableRef.make<Result.Result<Uint8Array, FrameError>>(\n\t\tResult.succeed(new Uint8Array(0)),\n\t)\n\tconst decode = (\n\t\tchunk: Uint8Array,\n\t): Result.Result<ReadonlyArray<Frame>, FrameError> =>\n\t\tResult.flatMap(MutableRef.get(pending), (previous) => {\n\t\t\tconst bytes = new Uint8Array(previous.length + chunk.length)\n\t\t\tbytes.set(previous)\n\t\t\tbytes.set(chunk, previous.length)\n\t\t\tconst frames = Array.unfold(\n\t\t\t\t0,\n\t\t\t\t(\n\t\t\t\t\toffset,\n\t\t\t\t): Option.Option<\n\t\t\t\t\treadonly [Result.Result<Frame, FrameError>, number]\n\t\t\t\t> => {\n\t\t\t\t\tif (bytes.length - offset < headerSize) return Option.none()\n\t\t\t\t\tconst header = new DataView(bytes.buffer, offset, headerSize)\n\t\t\t\t\tconst channel = header.getUint8(1)\n\t\t\t\t\tconst length = header.getUint32(4)\n\t\t\t\t\tif (\n\t\t\t\t\t\theader.getUint8(0) !== 2 ||\n\t\t\t\t\t\t(channel !== 0 && channel !== 1) ||\n\t\t\t\t\t\theader.getUint16(2) !== 0 ||\n\t\t\t\t\t\tlength > maxPayload\n\t\t\t\t\t)\n\t\t\t\t\t\treturn Option.some([\n\t\t\t\t\t\t\tResult.fail(\n\t\t\t\t\t\t\t\tinvalid(\"Invalid runner frame header or payload length\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tbytes.length,\n\t\t\t\t\t\t])\n\t\t\t\t\tconst end = offset + headerSize + length\n\t\t\t\t\tif (end > bytes.length) return Option.none()\n\t\t\t\t\treturn Option.some([\n\t\t\t\t\t\tResult.succeed({\n\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\tpayload: bytes.subarray(offset + headerSize, end),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tend,\n\t\t\t\t\t])\n\t\t\t\t},\n\t\t\t)\n\t\t\tconst result = Result.all(frames)\n\t\t\tMutableRef.set(\n\t\t\t\tpending,\n\t\t\t\tResult.map(result, (frames) =>\n\t\t\t\t\tbytes.subarray(\n\t\t\t\t\t\tArray.reduce(\n\t\t\t\t\t\t\tframes,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t(used, frame) => used + headerSize + frame.payload.length,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\treturn result\n\t\t})\n\treturn {\n\t\tdecode,\n\t\tfinish: Effect.suspend(() =>\n\t\t\tEffect.fromResult(\n\t\t\t\tResult.flatMap(MutableRef.get(pending), (bytes) =>\n\t\t\t\t\tbytes.length === 0\n\t\t\t\t\t\t? Result.succeed(undefined)\n\t\t\t\t\t\t: Result.fail(invalid(\"Runner connection ended inside a frame\")),\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t}\n}\n"],"mappings":";;AAEA,IAAa,aAAb,cAAgC,OAAO,YAGrC,CAAC,CAAC,cAAc,EAAE,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC;CAC5C,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;;AAEA,IAAa,cAAb,cAAiC,OAAO,YAGtC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;CAC5B,IAAa,UAAU;EACtB,OAAO;CACR;AACD;AAOA,MAAa,aAAa;AAC1B,MAAM,WAAW,WAAmB,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AM,MAAM,SAAA,IAAsB;GAClC,IAAI,MAAM,MAAM,QAAQ,OAAO,OAAO,KAAK;GAC3C,OAAO,OAAO,KAAK,CAClB,OAAO,QAAQ;IACd;IACA,SAAS,MAAM,SAAS,SAAA,GAAqB,GAAG;GACjD,CAAC,GACD,GACD,CAAC;EACF,CACD;EACA,MAAM,SAAS,OAAO,IAAI,MAAM;EAChC,WAAW,IACV,SACA,OAAO,IAAI,SAAS,WACnB,MAAM,SACL,MAAM,OACL,QACA,IACC,MAAM,UAAU,OAAA,IAAoB,MAAM,QAAQ,MACpD,CACD,CACD,CACD;EACA,OAAO;CACR,CAAC;CACF,OAAO;EACN;EACA,QAAQ,OAAO,cACd,OAAO,WACN,OAAO,QAAQ,WAAW,IAAI,OAAO,IAAI,UACxC,MAAM,WAAW,IACd,OAAO,QAAQ,KAAA,CAAS,IACxB,OAAO,KAAK,QAAQ,wCAAwC,CAAC,CACjE,CACD,CACD;CACD;AACD"}
@@ -24,7 +24,7 @@ const connect = Effect.fnUntraced(function* (execution, options) {
24
24
  report
25
25
  },
26
26
  diagnostics: Fiber.await(exited).pipe(Effect.andThen(failures.cause)),
27
- terminate: (graceful) => Effect.gen(function* () {
27
+ terminate: Effect.fnUntraced(function* (graceful) {
28
28
  yield* failures.close;
29
29
  if (!graceful) return;
30
30
  const status = yield* peer.end.pipe(Effect.catchCauseIf(Cause.hasInterruptsOnly, () => Effect.void), Effect.andThen(Fiber.join(exited)), Effect.interruptible, Effect.timeoutOrElse({
@@ -1 +1 @@
1
- {"version":3,"file":"Local.js","names":["FailureGroup.make","Port.make"],"sources":["../../../src/internal/runner/Local.ts"],"sourcesContent":["import { Cause, Effect, Fiber, Option } from \"effect\"\nimport type { Execution } from \"../directTransport\"\nimport * as FailureGroup from \"../FailureGroup\"\nimport {\n\tLocalTerminationTimeout,\n\tProcessExited,\n\tTransportError,\n} from \"../../Errors\"\nimport * as Port from \"../port\"\nimport { stdinExitTimeout } from \"./ProcessObservation\"\n\n/** Direct execution observers stay alive until exit, including forced cleanup. */\nexport const connect = Effect.fnUntraced(function* (\n\texecution: Execution,\n\toptions: Port.Options,\n) {\n\tconst failures = yield* FailureGroup.make<ProcessExited | TransportError>()\n\tconst exited = yield* execution.exited.pipe(Effect.forkScoped)\n\tconst peer = yield* Port.make(execution.channel, options)\n\tyield* failures.run(\n\t\tEffect.raceFirst(\n\t\t\tpeer.await,\n\t\t\tFiber.join(exited).pipe(Effect.flatMap(Effect.fail)),\n\t\t),\n\t)\n\tconst report = (cause: Cause.Cause<unknown>) =>\n\t\tCause.hasInterruptsOnly(cause)\n\t\t\t? Effect.void\n\t\t\t: failures\n\t\t\t\t\t.fail(TransportError.make({ cause }))\n\t\t\t\t\t.pipe(Effect.andThen(peer.fail(TransportError.make({ cause }))))\n\tyield* failures.run(execution.failure)\n\n\treturn {\n\t\t...peer,\n\t\tpid: execution.pid,\n\t\t...(execution.threadId === undefined\n\t\t\t? {}\n\t\t\t: { threadId: execution.threadId }),\n\t\texited,\n\t\tresources: yield* Effect.scope,\n\t\ttransport: { ...peer, failure: failures.await, report },\n\t\tdiagnostics: Fiber.await(exited).pipe(Effect.andThen(failures.cause)),\n\t\tterminate: (graceful: boolean) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\t// Stop observation before intentionally ending stdin or killing the process.\n\t\t\t\tyield* failures.close\n\t\t\t\tif (!graceful) return\n\t\t\t\t// If this fails, the execution scope forces termination and waits for exit.\n\t\t\t\tconst status = yield* peer.end.pipe(\n\t\t\t\t\t// Peer EOF can interrupt the writer as its output ends. Still confirm the unit's exit.\n\t\t\t\t\tEffect.catchCauseIf(Cause.hasInterruptsOnly, () => Effect.void),\n\t\t\t\t\tEffect.andThen(Fiber.join(exited)),\n\t\t\t\t\tEffect.interruptible,\n\t\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\t\tduration: stdinExitTimeout,\n\t\t\t\t\t\torElse: () =>\n\t\t\t\t\t\t\tLocalTerminationTimeout.make({\n\t\t\t\t\t\t\t\t...Option.match(execution.pid, {\n\t\t\t\t\t\t\t\t\tonNone: () => ({}),\n\t\t\t\t\t\t\t\t\tonSome: (pid) => ({ pid }),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t...(execution.threadId === undefined\n\t\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t\t: { threadId: execution.threadId }),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (status.exitCode !== 0 || status.statusCause.reasons.length > 0)\n\t\t\t\t\treturn yield* status\n\t\t\t}),\n\t}\n})\n"],"mappings":";;;;;;;AAYA,MAAa,UAAU,OAAO,WAAW,WACxC,WACA,SACC;CACD,MAAM,WAAW,OAAOA,KAAkD;CAC1E,MAAM,SAAS,OAAO,UAAU,OAAO,KAAK,OAAO,UAAU;CAC7D,MAAM,OAAO,OAAOC,OAAU,UAAU,SAAS,OAAO;CACxD,OAAO,SAAS,IACf,OAAO,UACN,KAAK,OACL,MAAM,KAAK,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,OAAO,IAAI,CAAC,CACpD,CACD;CACA,MAAM,UAAU,UACf,MAAM,kBAAkB,KAAK,IAC1B,OAAO,OACP,SACC,KAAK,eAAe,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CACpC,KAAK,OAAO,QAAQ,KAAK,KAAK,eAAe,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CACnE,OAAO,SAAS,IAAI,UAAU,OAAO;CAErC,OAAO;EACN,GAAG;EACH,KAAK,UAAU;EACf,GAAI,UAAU,aAAa,KAAA,IACxB,CAAC,IACD,EAAE,UAAU,UAAU,SAAS;EAClC;EACA,WAAW,OAAO,OAAO;EACzB,WAAW;GAAE,GAAG;GAAM,SAAS,SAAS;GAAO;EAAO;EACtD,aAAa,MAAM,MAAM,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,SAAS,KAAK,CAAC;EACpE,YAAY,aACX,OAAO,IAAI,aAAa;GAEvB,OAAO,SAAS;GAChB,IAAI,CAAC,UAAU;GAEf,MAAM,SAAS,OAAO,KAAK,IAAI,KAE9B,OAAO,aAAa,MAAM,yBAAyB,OAAO,IAAI,GAC9D,OAAO,QAAQ,MAAM,KAAK,MAAM,CAAC,GACjC,OAAO,eACP,OAAO,cAAc;IACpB,UAAU;IACV,cACC,wBAAwB,KAAK;KAC5B,GAAG,OAAO,MAAM,UAAU,KAAK;MAC9B,eAAe,CAAC;MAChB,SAAS,SAAS,EAAE,IAAI;KACzB,CAAC;KACD,GAAI,UAAU,aAAa,KAAA,IACxB,CAAC,IACD,EAAE,UAAU,UAAU,SAAS;IACnC,CAAC;GACH,CAAC,CACF;GACA,IAAI,OAAO,aAAa,KAAK,OAAO,YAAY,QAAQ,SAAS,GAChE,OAAO,OAAO;EAChB,CAAC;CACH;AACD,CAAC"}
1
+ {"version":3,"file":"Local.js","names":["FailureGroup.make","Port.make"],"sources":["../../../src/internal/runner/Local.ts"],"sourcesContent":["import { Cause, Effect, Fiber, Option } from \"effect\"\nimport type { Execution } from \"../directTransport\"\nimport * as FailureGroup from \"../FailureGroup\"\nimport {\n\tLocalTerminationTimeout,\n\tProcessExited,\n\tTransportError,\n} from \"../../Errors\"\nimport * as Port from \"../port\"\nimport { stdinExitTimeout } from \"./ProcessObservation\"\n\n/** Direct execution observers stay alive until exit, including forced cleanup. */\nexport const connect = Effect.fnUntraced(function* (\n\texecution: Execution,\n\toptions: Port.Options,\n) {\n\tconst failures = yield* FailureGroup.make<ProcessExited | TransportError>()\n\tconst exited = yield* execution.exited.pipe(Effect.forkScoped)\n\tconst peer = yield* Port.make(execution.channel, options)\n\tyield* failures.run(\n\t\tEffect.raceFirst(\n\t\t\tpeer.await,\n\t\t\tFiber.join(exited).pipe(Effect.flatMap(Effect.fail)),\n\t\t),\n\t)\n\tconst report = (cause: Cause.Cause<unknown>) =>\n\t\tCause.hasInterruptsOnly(cause)\n\t\t\t? Effect.void\n\t\t\t: failures\n\t\t\t\t\t.fail(TransportError.make({ cause }))\n\t\t\t\t\t.pipe(Effect.andThen(peer.fail(TransportError.make({ cause }))))\n\tyield* failures.run(execution.failure)\n\n\treturn {\n\t\t...peer,\n\t\tpid: execution.pid,\n\t\t...(execution.threadId === undefined\n\t\t\t? {}\n\t\t\t: { threadId: execution.threadId }),\n\t\texited,\n\t\tresources: yield* Effect.scope,\n\t\ttransport: { ...peer, failure: failures.await, report },\n\t\tdiagnostics: Fiber.await(exited).pipe(Effect.andThen(failures.cause)),\n\t\tterminate: Effect.fnUntraced(function* (graceful: boolean) {\n\t\t\t// Stop observation before intentionally ending stdin or killing the process.\n\t\t\tyield* failures.close\n\t\t\tif (!graceful) return\n\t\t\t// If this fails, the execution scope forces termination and waits for exit.\n\t\t\tconst status = yield* peer.end.pipe(\n\t\t\t\t// Peer EOF can interrupt the writer as its output ends. Still confirm the unit's exit.\n\t\t\t\tEffect.catchCauseIf(Cause.hasInterruptsOnly, () => Effect.void),\n\t\t\t\tEffect.andThen(Fiber.join(exited)),\n\t\t\t\tEffect.interruptible,\n\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\tduration: stdinExitTimeout,\n\t\t\t\t\torElse: () =>\n\t\t\t\t\t\tLocalTerminationTimeout.make({\n\t\t\t\t\t\t\t...Option.match(execution.pid, {\n\t\t\t\t\t\t\t\tonNone: () => ({}),\n\t\t\t\t\t\t\t\tonSome: (pid) => ({ pid }),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...(execution.threadId === undefined\n\t\t\t\t\t\t\t\t? {}\n\t\t\t\t\t\t\t\t: { threadId: execution.threadId }),\n\t\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t)\n\t\t\tif (status.exitCode !== 0 || status.statusCause.reasons.length > 0)\n\t\t\t\treturn yield* status\n\t\t}),\n\t}\n})\n"],"mappings":";;;;;;;AAYA,MAAa,UAAU,OAAO,WAAW,WACxC,WACA,SACC;CACD,MAAM,WAAW,OAAOA,KAAkD;CAC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O,YAAY,QAAQ,SAAS,GAChE,OAAO,OAAO;EAChB,CAAC;CACF;AACD,CAAC"}
@@ -2,7 +2,7 @@ import { StateDirectoryLocked } from "./model.js";
2
2
  import { Cause, Effect, FileSystem, Path } from "effect";
3
3
  // src/internal/runner/Lock.ts
4
4
  /** SQLite owns the local directory lock for the enclosing scope, including failed startup. */
5
- const acquire = (directory) => Effect.gen(function* () {
5
+ const acquire = Effect.fnUntraced(function* (directory) {
6
6
  const fs = yield* FileSystem.FileSystem;
7
7
  const path = yield* Path.Path;
8
8
  yield* fs.makeDirectory(directory, { recursive: true }).pipe(Effect.uninterruptible);
@@ -1 +1 @@
1
- {"version":3,"file":"Lock.js","names":[],"sources":["../../../src/internal/runner/Lock.ts"],"sourcesContent":["import { Cause, Effect, FileSystem, Path } from \"effect\"\nimport { StateDirectoryLocked } from \"./model\"\n\n/** SQLite owns the local directory lock for the enclosing scope, including failed startup. */\nexport const acquire = (directory: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tyield* fs\n\t\t\t.makeDirectory(directory, { recursive: true })\n\t\t\t.pipe(Effect.uninterruptible)\n\t\tconst { DatabaseSync } = yield* Effect.promise(\n\t\t\t() => import(\"node:sqlite\"),\n\t\t).pipe(Effect.uninterruptible)\n\t\tconst locked = (cause: unknown) =>\n\t\t\tStateDirectoryLocked.make({\n\t\t\t\tdetail:\n\t\t\t\t\t\"The runner state directory is already owned or cannot be locked\",\n\t\t\t\tcause: Cause.die(cause),\n\t\t\t})\n\t\tconst db = yield* Effect.acquireRelease(\n\t\t\tEffect.try({\n\t\t\t\ttry: () => new DatabaseSync(path.join(directory, \"owner.sqlite\")),\n\t\t\t\tcatch: locked,\n\t\t\t}),\n\t\t\t(db) => Effect.sync(() => db.close()),\n\t\t)\n\t\tyield* Effect.try({ try: () => db.exec(\"BEGIN EXCLUSIVE\"), catch: locked })\n\t})\n"],"mappings":";;;;AAIA,MAAa,WAAW,cACvB,OAAO,IAAI,aAAa;CACvB,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,GACL,cAAc,WAAW,EAAE,WAAW,KAAK,CAAC,CAAC,CAC7C,KAAK,OAAO,eAAe;CAC7B,MAAM,EAAE,iBAAiB,OAAO,OAAO,cAChC,OAAO,cACd,CAAC,CAAC,KAAK,OAAO,eAAe;CAC7B,MAAM,UAAU,UACf,qBAAqB,KAAK;EACzB,QACC;EACD,OAAO,MAAM,IAAI,KAAK;CACvB,CAAC;CACF,MAAM,KAAK,OAAO,OAAO,eACxB,OAAO,IAAI;EACV,WAAW,IAAI,aAAa,KAAK,KAAK,WAAW,cAAc,CAAC;EAChE,OAAO;CACR,CAAC,IACA,OAAO,OAAO,WAAW,GAAG,MAAM,CAAC,CACrC;CACA,OAAO,OAAO,IAAI;EAAE,WAAW,GAAG,KAAK,iBAAiB;EAAG,OAAO;CAAO,CAAC;AAC3E,CAAC"}
1
+ {"version":3,"file":"Lock.js","names":[],"sources":["../../../src/internal/runner/Lock.ts"],"sourcesContent":["import { Cause, Effect, FileSystem, Path } from \"effect\"\nimport { StateDirectoryLocked } from \"./model\"\n\n/** SQLite owns the local directory lock for the enclosing scope, including failed startup. */\nexport const acquire = Effect.fnUntraced(function* (directory: string) {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tyield* fs\n\t\t.makeDirectory(directory, { recursive: true })\n\t\t.pipe(Effect.uninterruptible)\n\tconst { DatabaseSync } = yield* Effect.promise(\n\t\t() => import(\"node:sqlite\"),\n\t).pipe(Effect.uninterruptible)\n\tconst locked = (cause: unknown) =>\n\t\tStateDirectoryLocked.make({\n\t\t\tdetail: \"The runner state directory is already owned or cannot be locked\",\n\t\t\tcause: Cause.die(cause),\n\t\t})\n\tconst db = yield* Effect.acquireRelease(\n\t\tEffect.try({\n\t\t\ttry: () => new DatabaseSync(path.join(directory, \"owner.sqlite\")),\n\t\t\tcatch: locked,\n\t\t}),\n\t\t(db) => Effect.sync(() => db.close()),\n\t)\n\tyield* Effect.try({ try: () => db.exec(\"BEGIN EXCLUSIVE\"), catch: locked })\n})\n"],"mappings":";;;;AAIA,MAAa,UAAU,OAAO,WAAW,WAAW,WAAmB;CACtE,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,GACL,cAAc,WAAW,EAAE,WAAW,KAAK,CAAC,CAAC,CAC7C,KAAK,OAAO,eAAe;CAC7B,MAAM,EAAE,iBAAiB,OAAO,OAAO,cAChC,OAAO,cACd,CAAC,CAAC,KAAK,OAAO,eAAe;CAC7B,MAAM,UAAU,UACf,qBAAqB,KAAK;EACzB,QAAQ;EACR,OAAO,MAAM,IAAI,KAAK;CACvB,CAAC;CACF,MAAM,KAAK,OAAO,OAAO,eACxB,OAAO,IAAI;EACV,WAAW,IAAI,aAAa,KAAK,KAAK,WAAW,cAAc,CAAC;EAChE,OAAO;CACR,CAAC,IACA,OAAO,OAAO,WAAW,GAAG,MAAM,CAAC,CACrC;CACA,OAAO,OAAO,IAAI;EAAE,WAAW,GAAG,KAAK,iBAAiB;EAAG,OAAO;CAAO,CAAC;AAC3E,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import "./model.js";
2
- import { Effect, FileSystem, Path } from "effect";
2
+ import { Effect, FileSystem, Path, PlatformError } from "effect";
3
3
  import { ChildProcessSpawner } from "effect/process";
@@ -15,7 +15,7 @@ const digest = Effect.fnUntraced(function* (directory) {
15
15
  const fs = yield* FileSystem.FileSystem;
16
16
  const path = yield* Path.Path;
17
17
  const hash = yield* Effect.sync(() => createHash("sha256").update("graft-package-sha256-v1\0"));
18
- const visit = (relative) => Effect.gen(function* () {
18
+ const visit = Effect.fnUntraced(function* (relative) {
19
19
  const filename = path.join(directory, relative);
20
20
  const info = yield* fs.stat(filename);
21
21
  if (info.type !== "File" && info.type !== "Directory") return yield* PackageError.make({ detail: `Unsupported package entry: ${relative}` });
@@ -78,31 +78,28 @@ const resolve = Effect.fnUntraced(function* (root, specifier, includeDigest = fa
78
78
  cause: Cause.fail(error)
79
79
  }))
80
80
  }));
81
- const resolveEntry = (installation, specifier) => Effect.gen(function* () {
82
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
83
- return yield* Effect.scoped(Effect.gen(function* () {
84
- const child = yield* spawner.spawn(ChildProcess.make(process.execPath, [
85
- "--input-type=module",
86
- "--eval",
87
- "process.stdout.write(import.meta.resolve(process.argv[1]))",
88
- "--",
89
- specifier
90
- ], {
91
- cwd: installation,
92
- env: {},
93
- stdin: "ignore",
94
- stdout: "pipe",
95
- stderr: "pipe"
96
- }));
97
- const [code, stdout, stderr] = yield* Effect.all([
98
- child.exitCode,
99
- child.stdout.pipe(Stream.decodeText(), Stream.mkString),
100
- child.stderr.pipe(Stream.decodeText(), Stream.mkString)
101
- ], { concurrency: "unbounded" });
102
- if (code !== 0) return yield* PackageError.make({ detail: `Package resolution failed: ${stderr}` });
103
- return stdout;
81
+ const resolveEntry = Effect.fnUntraced(function* (installation, specifier) {
82
+ const child = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(ChildProcess.make(process.execPath, [
83
+ "--input-type=module",
84
+ "--eval",
85
+ "process.stdout.write(import.meta.resolve(process.argv[1]))",
86
+ "--",
87
+ specifier
88
+ ], {
89
+ cwd: installation,
90
+ env: {},
91
+ stdin: "ignore",
92
+ stdout: "pipe",
93
+ stderr: "pipe"
104
94
  }));
105
- });
95
+ const [code, stdout, stderr] = yield* Effect.all([
96
+ child.exitCode,
97
+ child.stdout.pipe(Stream.decodeText(), Stream.mkString),
98
+ child.stderr.pipe(Stream.decodeText(), Stream.mkString)
99
+ ], { concurrency: "unbounded" });
100
+ if (code !== 0) return yield* PackageError.make({ detail: `Package resolution failed: ${stderr}` });
101
+ return stdout;
102
+ }, Effect.scoped);
106
103
  export { digest, resolve, resolveEntry, verify };
107
104
 
108
105
  //# sourceMappingURL=Packages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Packages.js","names":[],"sources":["../../../src/internal/runner/Packages.ts"],"sourcesContent":["import {\n\tArray,\n\tCause,\n\tEffect,\n\tFileSystem,\n\tOrder,\n\tPath,\n\tSchema,\n\tStream,\n\tString,\n} from \"effect\"\nimport type { PlatformError } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\n// @effect-diagnostics-next-line nodeBuiltinImport:off -- WebCrypto has no incremental digest API; package files are hashed as streams without buffering the directory.\nimport { createHash } from \"node:crypto\"\nimport process from \"node:process\"\nimport { fileURLToPath } from \"node:url\"\nimport { PackageError, type CodeIdentity } from \"./model\"\n\nconst Manifest = Schema.Struct({ name: Schema.String, version: Schema.String })\nexport interface Expected {\n\treadonly version?: string\n\treadonly digest?: string\n}\nexport const verify = (actual: CodeIdentity, expected: Expected = {}) =>\n\texpected.version !== undefined && actual.version !== expected.version\n\t\t? Effect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: `Package version mismatch: expected ${expected.version}, received ${actual.version}`,\n\t\t\t\t}),\n\t\t\t)\n\t\t: expected.digest !== undefined && actual.digest !== expected.digest\n\t\t\t? Effect.fail(\n\t\t\t\t\tPackageError.make({\n\t\t\t\t\t\tdetail: `Package digest mismatch: expected ${expected.digest}, received ${actual.digest}`,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t: Effect.void\n\n/** A path-sensitive SHA-256 of sorted entries and bytes, excluding every node_modules subtree. */\nexport const digest = Effect.fnUntraced(function* (directory: string) {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst hash = yield* Effect.sync(() =>\n\t\tcreateHash(\"sha256\").update(\"graft-package-sha256-v1\\0\"),\n\t)\n\tconst visit = (\n\t\trelative: string,\n\t): Effect.Effect<void, PackageError | PlatformError.PlatformError> =>\n\t\tEffect.gen(function* () {\n\t\t\tconst filename = path.join(directory, relative)\n\t\t\tconst info = yield* fs.stat(filename)\n\t\t\tif (info.type !== \"File\" && info.type !== \"Directory\")\n\t\t\t\treturn yield* PackageError.make({\n\t\t\t\t\tdetail: `Unsupported package entry: ${relative}`,\n\t\t\t\t})\n\t\t\tconst name = new TextEncoder().encode(relative)\n\t\t\tyield* Effect.sync(() => {\n\t\t\t\thash.update(\n\t\t\t\t\t`${info.type}:${name.byteLength}:${info.type === \"File\" ? info.size : 0}:`,\n\t\t\t\t)\n\t\t\t\thash.update(name)\n\t\t\t})\n\t\t\tif (info.type === \"File\") {\n\t\t\t\tyield* fs.stream(filename).pipe(\n\t\t\t\t\tStream.runForEach((bytes) =>\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\thash.update(bytes)\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tconst entries = yield* fs.readDirectory(filename)\n\t\t\t\tfor (const entry of Array.sort(entries, Order.String)) {\n\t\t\t\t\tif (entry === \"node_modules\") continue\n\t\t\t\t\tyield* visit(relative === \"\" ? entry : `${relative}/${entry}`)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\tyield* visit(\"\")\n\treturn yield* Effect.sync(() => hash.digest(\"hex\"))\n})\n\n/**\n * Resolve using Node's import conditions without importing executable package code.\n * The helper's cwd is the installation root and it inherits no NODE_OPTIONS/loaders.\n * The installation directory and its package exports are trusted.\n */\nexport const resolve = Effect.fnUntraced(\n\tfunction* (root: string, specifier: string, includeDigest: boolean = false) {\n\t\tconst segments = String.split(specifier, \"/\")\n\t\tconst scoped = String.startsWith(\"@\")(specifier)\n\t\tconst name = Array.join(Array.take(segments, scoped ? 2 : 1), \"/\")\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst installation = yield* fs.realPath(root)\n\t\tconst directory = yield* fs.realPath(\n\t\t\tpath.join(installation, \"node_modules\", name),\n\t\t)\n\t\tconst manifest = yield* fs\n\t\t\t.readFileString(path.join(directory, \"package.json\"))\n\t\t\t.pipe(\n\t\t\t\tEffect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Manifest))),\n\t\t\t)\n\t\tconst resolved = yield* resolveEntry(installation, specifier)\n\t\tconst filename = yield* Effect.try({\n\t\t\ttry: () => fileURLToPath(resolved),\n\t\t\tcatch: (error) =>\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"The package export is not a file URL\",\n\t\t\t\t\tcause: Cause.die(error),\n\t\t\t\t}),\n\t\t})\n\t\tconst entry = yield* fs.realPath(filename)\n\t\tconst identity: CodeIdentity = {\n\t\t\t...manifest,\n\t\t\t...(includeDigest ? { digest: yield* digest(directory) } : {}),\n\t\t}\n\t\treturn { directory, entry, identity }\n\t},\n\tEffect.catchTags({\n\t\tPlatformError: (error) =>\n\t\t\tEffect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"Reading the installed package failed\",\n\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t}),\n\t\t\t),\n\t\tSchemaError: (error) =>\n\t\t\tEffect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"Reading the package manifest failed\",\n\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t}),\n\t\t\t),\n\t}),\n)\n\nexport const resolveEntry = (installation: string, specifier: string) =>\n\tEffect.gen(function* () {\n\t\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\t\treturn yield* Effect.scoped(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst child = yield* spawner.spawn(\n\t\t\t\t\tChildProcess.make(\n\t\t\t\t\t\tprocess.execPath,\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"--input-type=module\",\n\t\t\t\t\t\t\t\"--eval\",\n\t\t\t\t\t\t\t\"process.stdout.write(import.meta.resolve(process.argv[1]))\",\n\t\t\t\t\t\t\t\"--\",\n\t\t\t\t\t\t\tspecifier,\n\t\t\t\t\t\t],\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcwd: installation,\n\t\t\t\t\t\t\tenv: {},\n\t\t\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t\t\t\tstdout: \"pipe\",\n\t\t\t\t\t\t\tstderr: \"pipe\",\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tconst [code, stdout, stderr] = yield* Effect.all(\n\t\t\t\t\t[\n\t\t\t\t\t\tchild.exitCode,\n\t\t\t\t\t\tchild.stdout.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\t\t\tchild.stderr.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\t\t],\n\t\t\t\t\t{ concurrency: \"unbounded\" },\n\t\t\t\t)\n\t\t\t\tif (code !== 0)\n\t\t\t\t\treturn yield* PackageError.make({\n\t\t\t\t\t\tdetail: `Package resolution failed: ${stderr}`,\n\t\t\t\t\t})\n\t\t\t\treturn stdout\n\t\t\t}),\n\t\t)\n\t})\n"],"mappings":";;;;;;;AAmBA,MAAM,WAAW,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC;AAK9E,MAAa,UAAU,QAAsB,WAAqB,CAAC,MAClE,SAAS,YAAY,KAAA,KAAa,OAAO,YAAY,SAAS,UAC3D,OAAO,KACP,aAAa,KAAK,EACjB,QAAQ,sCAAsC,SAAS,QAAQ,aAAa,OAAO,UACpF,CAAC,CACF,IACC,SAAS,WAAW,KAAA,KAAa,OAAO,WAAW,SAAS,SAC3D,OAAO,KACP,aAAa,KAAK,EACjB,QAAQ,qCAAqC,SAAS,OAAO,aAAa,OAAO,SAClF,CAAC,CACF,IACC,OAAO;;AAGZ,MAAa,SAAS,OAAO,WAAW,WAAW,WAAmB;CACrE,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,OAAO,WAC1B,WAAW,QAAQ,CAAC,CAAC,OAAO,2BAA2B,CACxD;CACA,MAAM,SACL,aAEA,OAAO,IAAI,aAAa;EACvB,MAAM,WAAW,KA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,KAAK,OAAO,WAAW,GAAG,OAAO,QAAQ;EACvD,GACA,EAAE,aAAa,YAAY,CAC5B;EACA,IAAI,SAAS,GACZ,OAAO,OAAO,aAAa,KAAK,EAC/B,QAAQ,8BAA8B,SACvC,CAAC;EACF,OAAO;CACR,CAAC,CACF;AACD,CAAC"}
1
+ {"version":3,"file":"Packages.js","names":[],"sources":["../../../src/internal/runner/Packages.ts"],"sourcesContent":["import {\n\tArray,\n\tCause,\n\tEffect,\n\tFileSystem,\n\tOrder,\n\tPath,\n\tSchema,\n\tStream,\n\tString,\n} from \"effect\"\nimport type { PlatformError } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\n// @effect-diagnostics-next-line nodeBuiltinImport:off -- WebCrypto has no incremental digest API; package files are hashed as streams without buffering the directory.\nimport { createHash } from \"node:crypto\"\nimport process from \"node:process\"\nimport { fileURLToPath } from \"node:url\"\nimport { PackageError, type CodeIdentity } from \"./model\"\n\nconst Manifest = Schema.Struct({ name: Schema.String, version: Schema.String })\nexport interface Expected {\n\treadonly version?: string\n\treadonly digest?: string\n}\nexport const verify = (actual: CodeIdentity, expected: Expected = {}) =>\n\texpected.version !== undefined && actual.version !== expected.version\n\t\t? Effect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: `Package version mismatch: expected ${expected.version}, received ${actual.version}`,\n\t\t\t\t}),\n\t\t\t)\n\t\t: expected.digest !== undefined && actual.digest !== expected.digest\n\t\t\t? Effect.fail(\n\t\t\t\t\tPackageError.make({\n\t\t\t\t\t\tdetail: `Package digest mismatch: expected ${expected.digest}, received ${actual.digest}`,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t: Effect.void\n\n/** A path-sensitive SHA-256 of sorted entries and bytes, excluding every node_modules subtree. */\nexport const digest = Effect.fnUntraced(function* (directory: string) {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst hash = yield* Effect.sync(() =>\n\t\tcreateHash(\"sha256\").update(\"graft-package-sha256-v1\\0\"),\n\t)\n\tconst visit = Effect.fnUntraced(function* (\n\t\trelative: string,\n\t): Effect.fn.Return<void, PackageError | PlatformError.PlatformError> {\n\t\tconst filename = path.join(directory, relative)\n\t\tconst info = yield* fs.stat(filename)\n\t\tif (info.type !== \"File\" && info.type !== \"Directory\")\n\t\t\treturn yield* PackageError.make({\n\t\t\t\tdetail: `Unsupported package entry: ${relative}`,\n\t\t\t})\n\t\tconst name = new TextEncoder().encode(relative)\n\t\tyield* Effect.sync(() => {\n\t\t\thash.update(\n\t\t\t\t`${info.type}:${name.byteLength}:${info.type === \"File\" ? info.size : 0}:`,\n\t\t\t)\n\t\t\thash.update(name)\n\t\t})\n\t\tif (info.type === \"File\") {\n\t\t\tyield* fs.stream(filename).pipe(\n\t\t\t\tStream.runForEach((bytes) =>\n\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\thash.update(bytes)\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\t\t} else {\n\t\t\tconst entries = yield* fs.readDirectory(filename)\n\t\t\tfor (const entry of Array.sort(entries, Order.String)) {\n\t\t\t\tif (entry === \"node_modules\") continue\n\t\t\t\tyield* visit(relative === \"\" ? entry : `${relative}/${entry}`)\n\t\t\t}\n\t\t}\n\t})\n\tyield* visit(\"\")\n\treturn yield* Effect.sync(() => hash.digest(\"hex\"))\n})\n\n/**\n * Resolve using Node's import conditions without importing executable package code.\n * The helper's cwd is the installation root and it inherits no NODE_OPTIONS/loaders.\n * The installation directory and its package exports are trusted.\n */\nexport const resolve = Effect.fnUntraced(\n\tfunction* (root: string, specifier: string, includeDigest: boolean = false) {\n\t\tconst segments = String.split(specifier, \"/\")\n\t\tconst scoped = String.startsWith(\"@\")(specifier)\n\t\tconst name = Array.join(Array.take(segments, scoped ? 2 : 1), \"/\")\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst installation = yield* fs.realPath(root)\n\t\tconst directory = yield* fs.realPath(\n\t\t\tpath.join(installation, \"node_modules\", name),\n\t\t)\n\t\tconst manifest = yield* fs\n\t\t\t.readFileString(path.join(directory, \"package.json\"))\n\t\t\t.pipe(\n\t\t\t\tEffect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Manifest))),\n\t\t\t)\n\t\tconst resolved = yield* resolveEntry(installation, specifier)\n\t\tconst filename = yield* Effect.try({\n\t\t\ttry: () => fileURLToPath(resolved),\n\t\t\tcatch: (error) =>\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"The package export is not a file URL\",\n\t\t\t\t\tcause: Cause.die(error),\n\t\t\t\t}),\n\t\t})\n\t\tconst entry = yield* fs.realPath(filename)\n\t\tconst identity: CodeIdentity = {\n\t\t\t...manifest,\n\t\t\t...(includeDigest ? { digest: yield* digest(directory) } : {}),\n\t\t}\n\t\treturn { directory, entry, identity }\n\t},\n\tEffect.catchTags({\n\t\tPlatformError: (error) =>\n\t\t\tEffect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"Reading the installed package failed\",\n\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t}),\n\t\t\t),\n\t\tSchemaError: (error) =>\n\t\t\tEffect.fail(\n\t\t\t\tPackageError.make({\n\t\t\t\t\tdetail: \"Reading the package manifest failed\",\n\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t}),\n\t\t\t),\n\t}),\n)\n\nexport const resolveEntry = Effect.fnUntraced(function* (\n\tinstallation: string,\n\tspecifier: string,\n) {\n\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\tconst child = yield* spawner.spawn(\n\t\tChildProcess.make(\n\t\t\tprocess.execPath,\n\t\t\t[\n\t\t\t\t\"--input-type=module\",\n\t\t\t\t\"--eval\",\n\t\t\t\t\"process.stdout.write(import.meta.resolve(process.argv[1]))\",\n\t\t\t\t\"--\",\n\t\t\t\tspecifier,\n\t\t\t],\n\t\t\t{\n\t\t\t\tcwd: installation,\n\t\t\t\tenv: {},\n\t\t\t\tstdin: \"ignore\",\n\t\t\t\tstdout: \"pipe\",\n\t\t\t\tstderr: \"pipe\",\n\t\t\t},\n\t\t),\n\t)\n\tconst [code, stdout, stderr] = yield* Effect.all(\n\t\t[\n\t\t\tchild.exitCode,\n\t\t\tchild.stdout.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\tchild.stderr.pipe(Stream.decodeText(), Stream.mkString),\n\t\t],\n\t\t{ concurrency: \"unbounded\" },\n\t)\n\tif (code !== 0)\n\t\treturn yield* PackageError.make({\n\t\t\tdetail: `Package resolution failed: ${stderr}`,\n\t\t})\n\treturn stdout\n}, Effect.scoped)\n"],"mappings":";;;;;;;AAmBA,MAAM,WAAW,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC;AAK9E,MAAa,UAAU,QAAsB,WAAqB,CAAC,MAClE,SAAS,YAAY,KAAA,KAAa,OAAO,YAAY,SAAS,UAC3D,OAAO,KACP,aAAa,KAAK,EACjB,QAAQ,sCAAsC,SAAS,QAAQ,aAAa,OAAO,UACpF,CAAC,CACF,IACC,SAAS,WAAW,KAAA,KAAa,OAAO,WAAW,SAAS,SAC3D,OAAO,KACP,aAAa,KAAK,EACjB,QAAQ,qCAAqC,SAAS,OAAO,aAAa,OAAO,SAClF,CAAC,CACF,IACC,OAAO;;AAGZ,MAAa,SAAS,OAAO,WAAW,WAAW,WAAmB;CACrE,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,OAAO,WAC1B,WAAW,QAAQ,CAAC,CAAC,OAAO,2BAA2B,CACxD;CACA,MAAM,QAAQ,OAAO,WAAW,WAC/B,UACqE;EACrE,MAAM,WAAW,KAAK,KAAK,WAAW,QAAQ;EAC9C,MAAM,OAAO,OAAO,GAAG,KAAK,QAAQ;EACpC,IAAI,KAAK,SAAS,UAAU,KAAK,SAAS,aACzC,OAAO,OAAO,aAAa,KAAK,EAC/B,QAAQ,8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option, Schedule, Stream, String } from "effect";
3
3
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
4
4
  import process from "node:process";
5
5
  // src/internal/runner/Processes.ts
6
- const inspect = (pid) => Effect.scoped(Effect.gen(function* () {
6
+ const inspect = Effect.fnUntraced(function* (pid) {
7
7
  const child = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(ChildProcess.make("ps", [
8
8
  "-p",
9
9
  `${pid}`,
@@ -12,10 +12,8 @@ const inspect = (pid) => Effect.scoped(Effect.gen(function* () {
12
12
  "-o",
13
13
  "stat="
14
14
  ], {
15
- env: {
16
- ...process.env,
17
- LC_ALL: "C"
18
- },
15
+ env: { LC_ALL: "C" },
16
+ extendEnv: true,
19
17
  stdin: "ignore"
20
18
  }));
21
19
  const [code, output, stderr] = yield* Effect.all([
@@ -28,11 +26,11 @@ const inspect = (pid) => Effect.scoped(Effect.gen(function* () {
28
26
  if (code !== 0 || born === void 0 || status === void 0) return yield* ExecutionError.make({ detail: "Cannot inspect process identity: " + stderr });
29
27
  if (String.startsWith("Z")(status)) return Option.none();
30
28
  return Option.some({ born });
31
- })).pipe(Effect.mapError((error) => error._tag === "ExecutionError" ? error : ExecutionError.make({
29
+ }, Effect.scoped, Effect.mapError((error) => error._tag === "ExecutionError" ? error : ExecutionError.make({
32
30
  detail: "Inspecting process identity failed",
33
31
  cause: Cause.fail(error)
34
32
  })));
35
- const identity = (pid) => Effect.gen(function* () {
33
+ const identity = Effect.fnUntraced(function* (pid) {
36
34
  const current = yield* inspect(pid);
37
35
  if (Option.isNone(current)) return yield* ExecutionError.make({ detail: "The child exited before its identity could be recorded" });
38
36
  return {
@@ -40,12 +38,12 @@ const identity = (pid) => Effect.gen(function* () {
40
38
  start: current.value
41
39
  };
42
40
  });
43
- const matches = (child) => Effect.gen(function* () {
41
+ const matches = Effect.fnUntraced(function* (child) {
44
42
  const current = yield* inspect(child.pid);
45
43
  if (Option.isNone(current) || current.value.born !== child.start.born) return false;
46
44
  return true;
47
45
  });
48
- const recover = (child) => Effect.gen(function* () {
46
+ const recover = Effect.fnUntraced(function* (child) {
49
47
  if (!(yield* matches(child))) return {
50
48
  kind: "Exited",
51
49
  exit: {
@@ -1 +1 @@
1
- {"version":3,"file":"Processes.js","names":[],"sources":["../../../src/internal/runner/Processes.ts"],"sourcesContent":["import { Cause, Effect, Option, Schedule, Stream, String } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\nimport process from \"node:process\"\nimport {\n\tExecutionError,\n\tTerminationUnconfirmed,\n\ttype ProcessIdentity,\n\ttype Termination,\n} from \"./model\"\n\nconst inspect = (pid: number) =>\n\tEffect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\t\t\tconst child = yield* spawner.spawn(\n\t\t\t\tChildProcess.make(\n\t\t\t\t\t\"ps\",\n\t\t\t\t\t[\"-p\", `${pid}`, \"-o\", \"lstart=\", \"-o\", \"stat=\"],\n\t\t\t\t\t{\n\t\t\t\t\t\tenv: { ...process.env, LC_ALL: \"C\" },\n\t\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tconst [code, output, stderr] = yield* Effect.all(\n\t\t\t\t[\n\t\t\t\t\tchild.exitCode,\n\t\t\t\t\tchild.stdout.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\t\tchild.stderr.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\t],\n\t\t\t\t{ concurrency: \"unbounded\" },\n\t\t\t)\n\t\t\tif (code === 1 && String.trim(output) === \"\") return Option.none()\n\t\t\tconst [, born, status] =\n\t\t\t\t/^(.{24})\\s+(\\S+)$/m.exec(String.trim(output)) ?? []\n\t\t\tif (code !== 0 || born === undefined || status === undefined)\n\t\t\t\treturn yield* ExecutionError.make({\n\t\t\t\t\tdetail: \"Cannot inspect process identity: \" + stderr,\n\t\t\t\t})\n\t\t\tif (String.startsWith(\"Z\")(status)) return Option.none()\n\t\t\treturn Option.some({ born })\n\t\t}),\n\t).pipe(\n\t\tEffect.mapError((error) =>\n\t\t\terror._tag === \"ExecutionError\"\n\t\t\t\t? error\n\t\t\t\t: ExecutionError.make({\n\t\t\t\t\t\tdetail: \"Inspecting process identity failed\",\n\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t}),\n\t\t),\n\t)\n\nexport const identity = (pid: number) =>\n\tEffect.gen(function* () {\n\t\tconst current = yield* inspect(pid)\n\t\tif (Option.isNone(current))\n\t\t\treturn yield* ExecutionError.make({\n\t\t\t\tdetail: \"The child exited before its identity could be recorded\",\n\t\t\t})\n\t\treturn { pid, start: current.value }\n\t})\n\n// The OS may discard argv before reporting a zombie; PID and start time remain the identity.\nexport const matches = (child: ProcessIdentity) =>\n\tEffect.gen(function* () {\n\t\tconst current = yield* inspect(child.pid)\n\t\tif (Option.isNone(current) || current.value.born !== child.start.born)\n\t\t\treturn false\n\t\treturn true\n\t})\n\nexport const recover = (child: ProcessIdentity) =>\n\tEffect.gen(function* () {\n\t\tif (!(yield* matches(child)))\n\t\t\treturn {\n\t\t\t\tkind: \"Exited\",\n\t\t\t\texit: { code: null, signal: null },\n\t\t\t\tcause: Cause.empty,\n\t\t\t} satisfies Termination\n\t\t// The PID can still be reused between this final check and kill; an external supervisor covers descendants.\n\t\tconst sent = yield* Effect.exit(\n\t\t\tEffect.try({\n\t\t\t\ttry: () => process.kill(child.pid, \"SIGKILL\"),\n\t\t\t\tcatch: (cause) =>\n\t\t\t\t\tExecutionError.make({\n\t\t\t\t\t\tdetail: \"Signaling the orphan failed\",\n\t\t\t\t\t\tcause: Cause.die(cause),\n\t\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t\tconst confirmed = yield* matches(child).pipe(\n\t\t\tEffect.repeat({\n\t\t\t\tschedule: Schedule.spaced(\"50 millis\"),\n\t\t\t\twhile: (value) => value,\n\t\t\t}),\n\t\t\tEffect.timeoutOption(\"10 seconds\"),\n\t\t)\n\t\tif (Option.isNone(confirmed))\n\t\t\treturn yield* TerminationUnconfirmed.make({\n\t\t\t\tdetail: \"The orphan did not exit after recovery\",\n\t\t\t\tcause: sent._tag === \"Failure\" ? sent.cause : Cause.empty,\n\t\t\t})\n\t\treturn {\n\t\t\tkind: \"Killed\",\n\t\t\texit: { code: null, signal: \"SIGKILL\" },\n\t\t\tcause: sent._tag === \"Failure\" ? sent.cause : Cause.empty,\n\t\t} satisfies Termination\n\t})\n"],"mappings":";;;;;AAUA,MAAM,WAAW,QAChB,OAAO,OACN,OAAO,IAAI,aAAa;CAEvB,MAAM,QAAQ,QAAO,OADE,oBAAoB,oBAAA,CACd,MAC5B,aAAa,KACZ,MACA;EAAC;EAAM,GAAG;EAAO;EAAM;EAAW;EAAM;CAAO,GAC/C;EACC,KAAK;GAAE,GAAG,QAAQ;GAAK,QAAQ;EAAI;EACnC,OAAO;CACR,CACD,CACD;CACA,MAAM,CAAC,MAAM,QAAQ,UAAU,OAAO,OAAO,IAC5C;EACC,MAAM;EACN,MAAM,OAAO,KAAK,OAAO,WAAW,GAAG,OAAO,QAAQ;EACtD,MAAM,OAAO,KAAK,OAAO,WAAW,GAAG,OAAO,QAAQ;CACvD,GACA,EAAE,aAAa,YAAY,CAC5B;CACA,IAAI,SAAS,KAAK,OAAO,KAAK,MAAM,MAAM,IAAI,OAAO,OAAO,KAAK;CACjE,MAAM,GAAG,MAAM,UACd,qBAAqB,KAAK,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC;CACpD,IAAI,SAAS,KAAK,SAAS,KAAA,KAAa,WAAW,KAAA,GAClD,OAAO,OAAO,eAAe,KAAK,EACjC,QAAQ,sCAAsC,OAC/C,CAAC;CACF,IAAI,OAAO,WAAW,GAAG,CAAC,CAAC,MAAM,GAAG,OAAO,OAAO,KAAK;CACvD,OAAO,OAAO,KAAK,EAAE,KAAK,CAAC;AAC5B,CAAC,CACF,CAAC,CAAC,KACD,OAAO,UAAU,UAChB,MAAM,SAAS,mBACZ,Q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K,QAAQ,MAAM;CACrD;AACD,CAAC"}
1
+ {"version":3,"file":"Processes.js","names":[],"sources":["../../../src/internal/runner/Processes.ts"],"sourcesContent":["import { Cause, Effect, Option, Schedule, Stream, String } from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\nimport process from \"node:process\"\nimport {\n\tExecutionError,\n\tTerminationUnconfirmed,\n\ttype ProcessIdentity,\n\ttype Termination,\n} from \"./model\"\n\nconst inspect = Effect.fnUntraced(\n\tfunction* (pid: number) {\n\t\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\t\tconst child = yield* spawner.spawn(\n\t\t\tChildProcess.make(\n\t\t\t\t\"ps\",\n\t\t\t\t[\"-p\", `${pid}`, \"-o\", \"lstart=\", \"-o\", \"stat=\"],\n\t\t\t\t{\n\t\t\t\t\tenv: { LC_ALL: \"C\" },\n\t\t\t\t\textendEnv: true,\n\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t},\n\t\t\t),\n\t\t)\n\t\tconst [code, output, stderr] = yield* Effect.all(\n\t\t\t[\n\t\t\t\tchild.exitCode,\n\t\t\t\tchild.stdout.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t\tchild.stderr.pipe(Stream.decodeText(), Stream.mkString),\n\t\t\t],\n\t\t\t{ concurrency: \"unbounded\" },\n\t\t)\n\t\tif (code === 1 && String.trim(output) === \"\") return Option.none()\n\t\tconst [, born, status] =\n\t\t\t/^(.{24})\\s+(\\S+)$/m.exec(String.trim(output)) ?? []\n\t\tif (code !== 0 || born === undefined || status === undefined)\n\t\t\treturn yield* ExecutionError.make({\n\t\t\t\tdetail: \"Cannot inspect process identity: \" + stderr,\n\t\t\t})\n\t\tif (String.startsWith(\"Z\")(status)) return Option.none()\n\t\treturn Option.some({ born })\n\t},\n\tEffect.scoped,\n\tEffect.mapError((error) =>\n\t\terror._tag === \"ExecutionError\"\n\t\t\t? error\n\t\t\t: ExecutionError.make({\n\t\t\t\t\tdetail: \"Inspecting process identity failed\",\n\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t}),\n\t),\n)\n\nexport const identity = Effect.fnUntraced(function* (pid: number) {\n\tconst current = yield* inspect(pid)\n\tif (Option.isNone(current))\n\t\treturn yield* ExecutionError.make({\n\t\t\tdetail: \"The child exited before its identity could be recorded\",\n\t\t})\n\treturn { pid, start: current.value }\n})\n\n// The OS may discard argv before reporting a zombie; PID and start time remain the identity.\nexport const matches = Effect.fnUntraced(function* (child: ProcessIdentity) {\n\tconst current = yield* inspect(child.pid)\n\tif (Option.isNone(current) || current.value.born !== child.start.born)\n\t\treturn false\n\treturn true\n})\n\nexport const recover = Effect.fnUntraced(function* (child: ProcessIdentity) {\n\tif (!(yield* matches(child)))\n\t\treturn {\n\t\t\tkind: \"Exited\",\n\t\t\texit: { code: null, signal: null },\n\t\t\tcause: Cause.empty,\n\t\t} satisfies Termination\n\t// The PID can still be reused between this final check and kill; an external supervisor covers descendants.\n\tconst sent = yield* Effect.exit(\n\t\tEffect.try({\n\t\t\ttry: () => process.kill(child.pid, \"SIGKILL\"),\n\t\t\tcatch: (cause) =>\n\t\t\t\tExecutionError.make({\n\t\t\t\t\tdetail: \"Signaling the orphan failed\",\n\t\t\t\t\tcause: Cause.die(cause),\n\t\t\t\t}),\n\t\t}),\n\t)\n\tconst confirmed = yield* matches(child).pipe(\n\t\tEffect.repeat({\n\t\t\tschedule: Schedule.spaced(\"50 millis\"),\n\t\t\twhile: (value) => value,\n\t\t}),\n\t\tEffect.timeoutOption(\"10 seconds\"),\n\t)\n\tif (Option.isNone(confirmed))\n\t\treturn yield* TerminationUnconfirmed.make({\n\t\t\tdetail: \"The orphan did not exit after recovery\",\n\t\t\tcause: sent._tag === \"Failure\" ? sent.cause : Cause.empty,\n\t\t})\n\treturn {\n\t\tkind: \"Killed\",\n\t\texit: { code: null, signal: \"SIGKILL\" },\n\t\tcause: sent._tag === \"Failure\" ? sent.cause : Cause.empty,\n\t} satisfies Termination\n})\n"],"mappings":";;;;;A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AAwB;CAC3E,MAAM,UAAU,OAAO,QAAQ,MAAM,GAAG;CACxC,IAAI,OAAO,OAAO,OAAO,KAAK,QAAQ,MAAM,SAAS,MAAM,MAAM,MAChE,OAAO;CACR,OAAO;AACR,CAAC;AAED,MAAa,UAAU,OAAO,WAAW,WAAW,OAAwB;CAC3E,IAAI,EAAE,OAAO,QAAQ,KAAK,IACzB,OAAO;EACN,MAAM;EACN,MAAM;GAAE,MAAM;GAAM,QAAQ;EAAK;EACjC,OAAO,MAAM;CACd;CAED,MAAM,OAAO,OAAO,OAAO,KAC1B,OAAO,IAAI;EACV,WAAW,QAAQ,KAAK,MAAM,KAAK,SAAS;EAC5C,QAAQ,UACP,eAAe,KAAK;GACnB,QAAQ;GACR,OAAO,MAAM,IAAI,KAAK;EACvB,CAAC;CACH,CAAC,CACF;CACA,MAAM,YAAY,OAAO,QAAQ,KAAK,CAAC,CAAC,KACvC,OAAO,OAAO;EACb,UAAU,SAAS,OAAO,WAAW;EACrC,QAAQ,UAAU;CACnB,CAAC,GACD,OAAO,cAAc,YAAY,CAClC;CACA,IAAI,OAAO,OAAO,SAAS,GAC1B,OAAO,OAAO,uBAAuB,KAAK;EACzC,QAAQ;EACR,OAAO,KAAK,SAAS,YAAY,KAAK,QAAQ,MAAM;CACrD,CAAC;CACF,OAAO;EACN,MAAM;EACN,MAAM;GAAE,MAAM;GAAM,QAAQ;EAAU;EACtC,OAAO,KAAK,SAAS,YAAY,KAAK,QAAQ,MAAM;CACrD;AACD,CAAC"}
@@ -16,7 +16,7 @@ const memory = Effect.gen(function* () {
16
16
  * Older terminal request ids expire; Open fences their retries with expectedGeneration.
17
17
  * Requires exclusive directory ownership; it is not a multi-writer database.
18
18
  */
19
- const directory = (root) => Effect.gen(function* () {
19
+ const directory = Effect.fnUntraced(function* (root) {
20
20
  const fs = yield* FileSystem.FileSystem;
21
21
  const path = yield* Path.Path;
22
22
  const digest = yield* Digest.Digest;
@@ -46,7 +46,7 @@ const directory = (root) => Effect.gen(function* () {
46
46
  yield* storage(compact);
47
47
  return Store.of({
48
48
  list: storage(mutex.withPermit(read.pipe(Effect.map((rows) => Array.map(rows, (row) => row.record))))),
49
- save: (record) => storage(mutex.withPermit(Effect.scoped(Effect.gen(function* () {
49
+ save: Effect.fnUntraced(function* (record) {
50
50
  const encoded = yield* Schema.encodeEffect(json)(record);
51
51
  const address = yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Struct({
52
52
  key: Key,
@@ -68,7 +68,7 @@ const directory = (root) => Effect.gen(function* () {
68
68
  yield* (yield* fs.open(root, { flag: "r" })).sync.pipe(Effect.uninterruptible);
69
69
  }));
70
70
  yield* compact;
71
- }))))
71
+ }, Effect.scoped, mutex.withPermit, storage)
72
72
  });
73
73
  });
74
74
  Layer.effect(Store, memory);
@@ -1 +1 @@
1
- {"version":3,"file":"Store.js","names":["Retention.save","Retention.retain"],"sources":["../../../src/internal/runner/Store.ts"],"sourcesContent":["import {\n\tArray,\n\tCause,\n\tLayer,\n\tEffect,\n\tFileSystem,\n\tHashMap,\n\tHashSet,\n\tPath,\n\tRef,\n\tSchema,\n\tSemaphore,\n\tString,\n\ttype PlatformError,\n} from \"effect\"\nimport { Digest, SecureRandom } from \"effect/crypto\"\nimport { Key, SessionRecord, Store, StateStorageError } from \"./model\"\nimport * as Retention from \"./Retention\"\n\n/** Injectable store used by deterministic supervisor tests. */\nexport const memory = Effect.gen(function* () {\n\tconst records = yield* Ref.make(HashMap.empty<string, SessionRecord>())\n\treturn Store.of({\n\t\tlist: Ref.get(records).pipe(\n\t\t\tEffect.map((records) => Array.fromIterable(HashMap.values(records))),\n\t\t),\n\t\tsave: (record) => Ref.update(records, (all) => Retention.save(all, record)),\n\t})\n})\n\n/**\n * Atomically replaced records retain unfinished sessions and each key's high-water mark.\n * Older terminal request ids expire; Open fences their retries with expectedGeneration.\n * Requires exclusive directory ownership; it is not a multi-writer database.\n */\nexport const directory = (root: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst digest = yield* Digest.Digest\n\t\tconst json = Schema.fromJsonString(Schema.toCodecJson(SessionRecord))\n\t\tconst random = yield* SecureRandom.SecureRandom\n\t\tconst storage = <A, R>(\n\t\t\teffect: Effect.Effect<\n\t\t\t\tA,\n\t\t\t\tPlatformError.PlatformError | Schema.SchemaError | StateStorageError,\n\t\t\t\tR\n\t\t\t>,\n\t\t) =>\n\t\t\teffect.pipe(\n\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\terror._tag === \"StateStorageError\"\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: StateStorageError.make({\n\t\t\t\t\t\t\t\tdetail: \"Runner state storage failed\",\n\t\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\t\tyield* storage(\n\t\t\tfs.makeDirectory(root, { recursive: true }).pipe(Effect.uninterruptible),\n\t\t)\n\t\tconst mutex = yield* Semaphore.make(1)\n\t\tconst read = Effect.gen(function* () {\n\t\t\tconst files = yield* fs.readDirectory(root)\n\t\t\tconst rows = yield* Effect.forEach(\n\t\t\t\tArray.filter(files, String.endsWith(\".json\")),\n\t\t\t\t(file) =>\n\t\t\t\t\tfs.readFileString(path.join(root, file)).pipe(\n\t\t\t\t\t\tEffect.flatMap(Schema.decodeEffect(json)),\n\t\t\t\t\t\tEffect.map((record) => ({ file, record })),\n\t\t\t\t\t),\n\t\t\t)\n\t\t\treturn rows\n\t\t})\n\t\tconst compact = Effect.scoped(\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst rows = yield* read\n\t\t\t\tconst retained = Retention.retain(Array.map(rows, (row) => row.record))\n\t\t\t\tconst tokens = HashSet.fromIterable(\n\t\t\t\t\tArray.map(retained, (record) => record.handle.token),\n\t\t\t\t)\n\t\t\t\tconst obsolete = Array.filter(\n\t\t\t\t\trows,\n\t\t\t\t\t(row) => !HashSet.has(tokens, row.record.handle.token),\n\t\t\t\t)\n\t\t\t\tyield* Effect.forEach(\n\t\t\t\t\tobsolete,\n\t\t\t\t\t(row) =>\n\t\t\t\t\t\tfs.remove(path.join(root, row.file)).pipe(Effect.uninterruptible),\n\t\t\t\t\t{ discard: true },\n\t\t\t\t)\n\t\t\t\tif (obsolete.length > 0) {\n\t\t\t\t\tconst directory = yield* fs.open(root, { flag: \"r\" })\n\t\t\t\t\tyield* directory.sync.pipe(Effect.uninterruptible)\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t\tyield* storage(compact)\n\t\treturn Store.of({\n\t\t\tlist: storage(\n\t\t\t\tmutex.withPermit(\n\t\t\t\t\tread.pipe(Effect.map((rows) => Array.map(rows, (row) => row.record))),\n\t\t\t\t),\n\t\t\t),\n\t\t\tsave: (record) =>\n\t\t\t\tstorage(\n\t\t\t\t\tmutex.withPermit(\n\t\t\t\t\t\tEffect.scoped(\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tconst encoded = yield* Schema.encodeEffect(json)(record)\n\t\t\t\t\t\t\t\tconst address = yield* Schema.encodeEffect(\n\t\t\t\t\t\t\t\t\tSchema.fromJsonString(\n\t\t\t\t\t\t\t\t\t\tSchema.Struct({ key: Key, generation: Schema.Int }),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)({\n\t\t\t\t\t\t\t\t\tkey: record.handle.key,\n\t\t\t\t\t\t\t\t\tgeneration: record.handle.generation,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\tconst name = yield* digest.digestHex(\n\t\t\t\t\t\t\t\t\tDigest.sha256,\n\t\t\t\t\t\t\t\t\tnew TextEncoder().encode(address),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst nonce = yield* random.uuidV4()\n\t\t\t\t\t\t\t\tconst temporary = path.join(root, `.${name}.${nonce}.tmp`)\n\t\t\t\t\t\t\t\tconst destination = path.join(root, name + \".json\")\n\t\t\t\t\t\t\t\tyield* Effect.acquireRelease(\n\t\t\t\t\t\t\t\t\tfs.open(temporary, { flag: \"wx\", mode: 0o600 }),\n\t\t\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\t\t\tfs.remove(temporary, { force: true }).pipe(Effect.orDie),\n\t\t\t\t\t\t\t\t).pipe(\n\t\t\t\t\t\t\t\t\tEffect.flatMap((file) =>\n\t\t\t\t\t\t\t\t\t\tfile\n\t\t\t\t\t\t\t\t\t\t\t.writeAll(new TextEncoder().encode(encoded))\n\t\t\t\t\t\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tEffect.uninterruptible,\n\t\t\t\t\t\t\t\t\t\t\t\tEffect.andThen(file.sync.pipe(Effect.uninterruptible)),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t// Keep rename and directory synchronization together if the caller is canceled.\n\t\t\t\t\t\t\t\tyield* Effect.uninterruptible(\n\t\t\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\t\t\tyield* fs.rename(temporary, destination)\n\t\t\t\t\t\t\t\t\t\tconst directory = yield* fs.open(root, { flag: \"r\" })\n\t\t\t\t\t\t\t\t\t\tyield* directory.sync.pipe(Effect.uninterruptible)\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t// The new high-water file is durable before any old record is removed.\n\t\t\t\t\t\t\t\tyield* compact\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t})\n\t})\n\nexport const layerMemory = Layer.effect(Store, memory)\nexport const layerDirectory = (root: string) =>\n\tLayer.effect(Store, directory(root))\n"],"mappings":";;;;;;AAoBA,MAAa,SAAS,OAAO,IAAI,aAAa;CAC7C,MAAM,UAAU,OAAO,IAAI,KAAK,QAAQ,MAA6B,CAAC;CACtE,OAAO,MAAM,GAAG;EACf,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AO,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,CACzD,CAAC,CAAC,KACD,OAAO,SAAS,SACf,KACE,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,CAC3C,KACA,OAAO,iBACP,OAAO,QAAQ,KAAK,KAAK,KAAK,OAAO,eAAe,CAAC,CACtD,CACF,CACD;GAEA,OAAO,OAAO,gBACb,OAAO,IAAI,aAAa;IACvB,OAAO,GAAG,OAAO,WAAW,WAAW;IAEvC,QAAO,OADkB,GAAG,KAAK,MAAM,EAAE,MAAM,IAAI,CAAC,EAAA,CACnC,KAAK,KAAK,OAAO,eAAe;GAClD,CAAC,CACF;GAEA,OAAO;EACR,CAAC,CACF,CACD,CACD;CACF,CAAC;AACF,CAAC;AAEyB,MAAM,OAAO,OAAO,MAAM;AACrD,MAAa,kBAAkB,SAC9B,MAAM,OAAO,OAAO,UAAU,IAAI,CAAC"}
1
+ {"version":3,"file":"Store.js","names":["Retention.save","Retention.retain"],"sources":["../../../src/internal/runner/Store.ts"],"sourcesContent":["import {\n\tArray,\n\tCause,\n\tLayer,\n\tEffect,\n\tFileSystem,\n\tHashMap,\n\tHashSet,\n\tPath,\n\tRef,\n\tSchema,\n\tSemaphore,\n\tString,\n\ttype PlatformError,\n} from \"effect\"\nimport { Digest, SecureRandom } from \"effect/crypto\"\nimport { Key, SessionRecord, Store, StateStorageError } from \"./model\"\nimport * as Retention from \"./Retention\"\n\n/** Injectable store used by deterministic supervisor tests. */\nexport const memory = Effect.gen(function* () {\n\tconst records = yield* Ref.make(HashMap.empty<string, SessionRecord>())\n\treturn Store.of({\n\t\tlist: Ref.get(records).pipe(\n\t\t\tEffect.map((records) => Array.fromIterable(HashMap.values(records))),\n\t\t),\n\t\tsave: (record) => Ref.update(records, (all) => Retention.save(all, record)),\n\t})\n})\n\n/**\n * Atomically replaced records retain unfinished sessions and each key's high-water mark.\n * Older terminal request ids expire; Open fences their retries with expectedGeneration.\n * Requires exclusive directory ownership; it is not a multi-writer database.\n */\nexport const directory = Effect.fnUntraced(function* (root: string) {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst digest = yield* Digest.Digest\n\tconst json = Schema.fromJsonString(Schema.toCodecJson(SessionRecord))\n\tconst random = yield* SecureRandom.SecureRandom\n\tconst storage = <A, R>(\n\t\teffect: Effect.Effect<\n\t\t\tA,\n\t\t\tPlatformError.PlatformError | Schema.SchemaError | StateStorageError,\n\t\t\tR\n\t\t>,\n\t) =>\n\t\teffect.pipe(\n\t\t\tEffect.mapError((error) =>\n\t\t\t\terror._tag === \"StateStorageError\"\n\t\t\t\t\t? error\n\t\t\t\t\t: StateStorageError.make({\n\t\t\t\t\t\t\tdetail: \"Runner state storage failed\",\n\t\t\t\t\t\t\tcause: Cause.fail(error),\n\t\t\t\t\t\t}),\n\t\t\t),\n\t\t)\n\tyield* storage(\n\t\tfs.makeDirectory(root, { recursive: true }).pipe(Effect.uninterruptible),\n\t)\n\tconst mutex = yield* Semaphore.make(1)\n\tconst read = Effect.gen(function* () {\n\t\tconst files = yield* fs.readDirectory(root)\n\t\tconst rows = yield* Effect.forEach(\n\t\t\tArray.filter(files, String.endsWith(\".json\")),\n\t\t\t(file) =>\n\t\t\t\tfs.readFileString(path.join(root, file)).pipe(\n\t\t\t\t\tEffect.flatMap(Schema.decodeEffect(json)),\n\t\t\t\t\tEffect.map((record) => ({ file, record })),\n\t\t\t\t),\n\t\t)\n\t\treturn rows\n\t})\n\tconst compact = Effect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst rows = yield* read\n\t\t\tconst retained = Retention.retain(Array.map(rows, (row) => row.record))\n\t\t\tconst tokens = HashSet.fromIterable(\n\t\t\t\tArray.map(retained, (record) => record.handle.token),\n\t\t\t)\n\t\t\tconst obsolete = Array.filter(\n\t\t\t\trows,\n\t\t\t\t(row) => !HashSet.has(tokens, row.record.handle.token),\n\t\t\t)\n\t\t\tyield* Effect.forEach(\n\t\t\t\tobsolete,\n\t\t\t\t(row) =>\n\t\t\t\t\tfs.remove(path.join(root, row.file)).pipe(Effect.uninterruptible),\n\t\t\t\t{ discard: true },\n\t\t\t)\n\t\t\tif (obsolete.length > 0) {\n\t\t\t\tconst directory = yield* fs.open(root, { flag: \"r\" })\n\t\t\t\tyield* directory.sync.pipe(Effect.uninterruptible)\n\t\t\t}\n\t\t}),\n\t)\n\tyield* storage(compact)\n\treturn Store.of({\n\t\tlist: storage(\n\t\t\tmutex.withPermit(\n\t\t\t\tread.pipe(Effect.map((rows) => Array.map(rows, (row) => row.record))),\n\t\t\t),\n\t\t),\n\t\tsave: Effect.fnUntraced(\n\t\t\tfunction* (record: SessionRecord) {\n\t\t\t\tconst encoded = yield* Schema.encodeEffect(json)(record)\n\t\t\t\tconst address = yield* Schema.encodeEffect(\n\t\t\t\t\tSchema.fromJsonString(\n\t\t\t\t\t\tSchema.Struct({ key: Key, generation: Schema.Int }),\n\t\t\t\t\t),\n\t\t\t\t)({\n\t\t\t\t\tkey: record.handle.key,\n\t\t\t\t\tgeneration: record.handle.generation,\n\t\t\t\t})\n\t\t\t\tconst name = yield* digest.digestHex(\n\t\t\t\t\tDigest.sha256,\n\t\t\t\t\tnew TextEncoder().encode(address),\n\t\t\t\t)\n\t\t\t\tconst nonce = yield* random.uuidV4()\n\t\t\t\tconst temporary = path.join(root, `.${name}.${nonce}.tmp`)\n\t\t\t\tconst destination = path.join(root, name + \".json\")\n\t\t\t\tyield* Effect.acquireRelease(\n\t\t\t\t\tfs.open(temporary, { flag: \"wx\", mode: 0o600 }),\n\t\t\t\t\t() => fs.remove(temporary, { force: true }).pipe(Effect.orDie),\n\t\t\t\t).pipe(\n\t\t\t\t\tEffect.flatMap((file) =>\n\t\t\t\t\t\tfile\n\t\t\t\t\t\t\t.writeAll(new TextEncoder().encode(encoded))\n\t\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\t\tEffect.uninterruptible,\n\t\t\t\t\t\t\t\tEffect.andThen(file.sync.pipe(Effect.uninterruptible)),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t// Keep rename and directory synchronization together if the caller is canceled.\n\t\t\t\tyield* Effect.uninterruptible(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tyield* fs.rename(temporary, destination)\n\t\t\t\t\t\tconst directory = yield* fs.open(root, { flag: \"r\" })\n\t\t\t\t\t\tyield* directory.sync.pipe(Effect.uninterruptible)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t// The new high-water file is durable before any old record is removed.\n\t\t\t\tyield* compact\n\t\t\t},\n\t\t\tEffect.scoped,\n\t\t\tmutex.withPermit,\n\t\t\tstorage,\n\t\t),\n\t})\n})\n\nexport const layerMemory = Layer.effect(Store, memory)\nexport const layerDirectory = (root: string) =>\n\tLayer.effect(Store, directory(root))\n"],"mappings":";;;;;;AAoBA,MAAa,SAAS,OAAO,IAAI,aAAa;CAC7C,MAAM,UAAU,OAAO,IAAI,KAAK,QAAQ,MAA6B,CAAC;CACtE,OAAO,MAAM,GAAG;EACf,MAAM,IAAI,IAAI,OAAO,CAAC,CAAC,KACtB,OAAO,KAAK,YAAY,MAAM,aAAa,QAAQ,OAAO,OAAO,CAAC,CAAC,CACpE;EACA,OAAO,WAAW,IAAI,OAAO,UAAU,QAAQA,KAAe,KAAK,MAAM,CAAC;CAC3E,CAAC;AACF,CAAC;;;;;;AAOD,MAAa,YAAY,OAAO,WAAW,WAAW,MAAc;CACnE,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,SAAS,OAAO,OAAO;CAC7B,MAAM,OAAO,OAAO,eAAe,OAAO,YAAY,aAAa,CAAC;CACpE,MAAM,SAAS,OAAO,aAAa;CACnC,MAAM,WACL,WAMA,OAAO,KACN,OAAO,UAAU,UAChB,MAAM,SAAS,sBACZ,QACA,kBAAkB,KAAK;EACvB,QAAQ;EACR,OAAO,MAAM,KAAK,KAAK;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AI,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { make as make$1 } from "../FailureGroup.js";
2
2
  import { close } from "../release.js";
3
- import { defaults } from "../Limits.js";
4
3
  import { save } from "./Retention.js";
4
+ import { defaults } from "../Limits.js";
5
5
  import { cleanupCause } from "../cleanup.js";
6
6
  import { Execution, ExecutionError, LeaseExpired, RunnerClosing, SessionConflict, SessionStopped, StaleSession, Store, TerminationUnconfirmed, childOf, keyOf, negotiate, stoppedRecord, stoppingRecord } from "./model.js";
7
7
  import { Array, Cause, Clock, Context, Data, Deferred, Duration, Effect, Equal, Exit, FiberHandle, FiberSet, HashMap, Layer, Option, RcMap, Ref, Result, Scope, Semaphore, SynchronizedRef } from "effect";
@@ -83,34 +83,32 @@ const emptyTermination = {
83
83
  };
84
84
  const exitCause = (exit) => Exit.isFailure(exit) ? exit.cause : Cause.empty;
85
85
  /** A signal is a request; only the exited effect confirms that the execution has stopped. */
86
- const terminate = (execution, grace, confirmation) => {
87
- if (execution._tag === "Absent") return Effect.succeed(emptyTermination);
88
- if (execution._tag === "Exited") return Effect.succeed({
86
+ const terminate = Effect.fnUntraced(function* (execution, grace, confirmation) {
87
+ if (execution._tag === "Absent") return emptyTermination;
88
+ if (execution._tag === "Exited") return {
89
89
  ...emptyTermination,
90
90
  exit: execution.exit
91
- });
91
+ };
92
92
  const child = execution.unit;
93
- return Effect.gen(function* () {
94
- const graceful = yield* child.interrupt.pipe(Effect.andThen(child.exited), Effect.timeoutOption(grace), Effect.exit);
95
- if (Exit.isSuccess(graceful) && Option.isSome(graceful.value)) return {
96
- ...emptyTermination,
97
- exit: graceful.value.value
98
- };
99
- const killed = yield* Effect.exit(child.kill);
100
- const forced = yield* child.exited.pipe(Effect.timeoutOption(confirmation), Effect.exit);
101
- const cause = Cause.combine(Cause.combine(exitCause(graceful), exitCause(killed)), exitCause(forced));
102
- if (Exit.isFailure(forced) || Option.isNone(forced.value)) return yield* TerminationUnconfirmed.make({
103
- detail: "The child exit could not be confirmed",
104
- cause
105
- });
106
- return {
107
- kind: "Killed",
108
- exit: forced.value.value,
109
- cause
110
- };
93
+ const graceful = yield* child.interrupt.pipe(Effect.andThen(child.exited), Effect.timeoutOption(grace), Effect.exit);
94
+ if (Exit.isSuccess(graceful) && Option.isSome(graceful.value)) return {
95
+ ...emptyTermination,
96
+ exit: graceful.value.value
97
+ };
98
+ const killed = yield* Effect.exit(child.kill);
99
+ const forced = yield* child.exited.pipe(Effect.timeoutOption(confirmation), Effect.exit);
100
+ const cause = Cause.combine(Cause.combine(exitCause(graceful), exitCause(killed)), exitCause(forced));
101
+ if (Exit.isFailure(forced) || Option.isNone(forced.value)) return yield* TerminationUnconfirmed.make({
102
+ detail: "The child exit could not be confirmed",
103
+ cause
111
104
  });
112
- };
113
- const initialize = (options = {}) => Effect.gen(function* () {
105
+ return {
106
+ kind: "Killed",
107
+ exit: forced.value.value,
108
+ cause
109
+ };
110
+ });
111
+ const initialize = Effect.fnUntraced(function* (options = {}) {
114
112
  const store = yield* Store;
115
113
  const execution = yield* Execution;
116
114
  const random = yield* SecureRandom.SecureRandom;
@@ -146,19 +144,19 @@ const operations = (runtime) => {
146
144
  return Option.isSome(found) && Equal.equals(keyOf(found.value.handle.key), keyOf(handle.key)) && found.value.handle.generation === handle.generation ? Effect.succeed(found.value) : Effect.fail(StaleSession.make({ detail: "Unknown session or generation" }));
147
145
  }));
148
146
  const latest = (key) => Ref.get(records).pipe(Effect.map((all) => Array.reduce(Array.fromIterable(HashMap.values(all)), 0, (value, record) => Equal.equals(keyOf(record.handle.key), keyOf(key)) ? Math.max(value, record.handle.generation) : value)));
149
- const entryFor = (handle) => Effect.gen(function* () {
147
+ const entryFor = Effect.fnUntraced(function* (handle) {
150
148
  yield* status(handle);
151
149
  const all = yield* Ref.get(entries);
152
150
  const found = HashMap.get(all, handle.token);
153
151
  if (Option.isNone(found)) return yield* SessionStopped.make({ detail: "The session was retired during recovery" });
154
152
  return found.value;
155
153
  });
156
- const commit = (entry, transition) => SynchronizedRef.updateEffect(entry.state, (state) => Effect.gen(function* () {
154
+ const commit = (entry, transition) => SynchronizedRef.updateEffect(entry.state, Effect.fnUntraced(function* (state) {
157
155
  const next = yield* Effect.fromResult(transition(state));
158
156
  yield* persist(snapshot(next));
159
157
  return next;
160
158
  }));
161
- const finishStop = (entry, state, saved) => Effect.gen(function* () {
159
+ const finishStop = Effect.fnUntraced(function* (entry, state, saved) {
162
160
  yield* FiberHandle.clear(entry.loading);
163
161
  const result = yield* terminate(state.execution, grace, confirmation);
164
162
  const closed = yield* Effect.exit(close(entry.unitScope, Exit.void));
@@ -175,7 +173,7 @@ const operations = (runtime) => {
175
173
  return termination;
176
174
  });
177
175
  /** Called with the session ref locked; the worker starts after its transition is published. */
178
- const stopLocked = (entry, state, reason, exit) => Effect.gen(function* () {
176
+ const stopLocked = Effect.fnUntraced(function* (entry, state, reason, exit) {
179
177
  if (state._tag === "Stopping" || state._tag === "Stopped") return [state.reply, state];
180
178
  const reply = yield* Deferred.make();
181
179
  const next = beginStop(state, reason, reply, exit);
@@ -192,7 +190,7 @@ const operations = (runtime) => {
192
190
  return stopLocked(entry, state, { _tag: "Expired" }, Option.none()).pipe(Effect.map(([, next]) => next));
193
191
  });
194
192
  })), { startImmediately: false });
195
- const register = (entry, unit) => SynchronizedRef.updateEffect(entry.state, (state) => Effect.gen(function* () {
193
+ const register = (entry, unit) => SynchronizedRef.updateEffect(entry.state, Effect.fnUntraced(function* (state) {
196
194
  const now = yield* Clock.monotonicTimeNanos;
197
195
  const current = yield* Effect.fromResult(live(state, now));
198
196
  const next = yield* Effect.fromResult(registerUnit(current, unit));
@@ -201,7 +199,7 @@ const operations = (runtime) => {
201
199
  yield* FiberSet.run(workers, observe(unit.exited.pipe(Effect.flatMap((exit) => stop(entry, { _tag: "Exited" }, Option.some(exit))))));
202
200
  return next;
203
201
  })).pipe(Effect.uninterruptible);
204
- const runLoad = (entry, state) => execution.spawn(state.record.handle, state.request, state.record.limits).pipe(Scope.provide(entry.unitScope), Effect.flatMap((unit) => register(entry, unit).pipe(Effect.andThen(unit.start), Effect.as(unit.code))), Effect.tap((code) => commit(entry, (current) => loaded(current, code))), Effect.onExit((result) => Effect.gen(function* () {
202
+ const runLoad = (entry, state) => execution.spawn(state.record.handle, state.request, state.record.limits).pipe(Scope.provide(entry.unitScope), Effect.flatMap((unit) => register(entry, unit).pipe(Effect.andThen(unit.start), Effect.as(unit.code))), Effect.tap((code) => commit(entry, (current) => loaded(current, code))), Effect.onExit(Effect.fnUntraced(function* (result) {
205
203
  if (Exit.isSuccess(result)) {
206
204
  yield* Deferred.done(state.reply, result);
207
205
  return;
@@ -224,7 +222,7 @@ const operations = (runtime) => {
224
222
  healthy
225
223
  };
226
224
  };
227
- const recover = (runtime, actions) => Effect.gen(function* () {
225
+ const recover = Effect.fnUntraced(function* (runtime, actions) {
228
226
  const { store, execution, confirmation, records } = runtime;
229
227
  const { persist } = actions;
230
228
  const stored = yield* store.list;
@@ -245,10 +243,10 @@ const recover = (runtime, actions) => Effect.gen(function* () {
245
243
  yield* persist(stoppedRecord(record.phase === "Stopping" ? record.previous : record, { _tag: "Recovery" }, termination));
246
244
  }
247
245
  });
248
- const ownShutdown = (runtime, actions) => Effect.gen(function* () {
246
+ const ownShutdown = Effect.fnUntraced(function* (runtime, actions) {
249
247
  const { entries, health, closing } = runtime;
250
248
  const { stop } = actions;
251
- yield* Effect.addFinalizer(() => Effect.gen(function* () {
249
+ yield* Effect.addFinalizer(Effect.fnUntraced(function* () {
252
250
  yield* Ref.set(closing, true);
253
251
  const all = yield* Ref.get(entries);
254
252
  const exits = yield* Effect.forEach(HashMap.values(all), (entry) => stop(entry, { _tag: "Shutdown" }).pipe(Effect.flatMap(Deferred.await), Effect.exit));
@@ -257,18 +255,19 @@ const ownShutdown = (runtime, actions) => Effect.gen(function* () {
257
255
  if (cause.reasons.length > 0) return yield* Effect.failCause(cleanupCause(cause));
258
256
  }));
259
257
  });
260
- const protocol = (runtime, actions) => Effect.gen(function* () {
258
+ const protocol = Effect.fnUntraced(function* (runtime, actions) {
261
259
  const { random, owner, locks, lease, limits, records, entries, health } = runtime;
262
260
  const { persist, status, latest, entryFor, stop, scheduleLease, runLoad, healthy } = actions;
263
261
  return Supervisor.of({
264
262
  await: health.await,
265
263
  status,
266
264
  highWater: (key) => latest(key).pipe(Effect.map((value) => value === 0 ? null : value)),
267
- open: (request) => Effect.scoped(Effect.gen(function* () {
265
+ open: Effect.fnUntraced(function* (request) {
268
266
  yield* healthy;
269
267
  const leaseMillis = Duration.toMillis(request.lease ?? lease);
270
268
  const negotiated = negotiate(limits, request.limits ?? defaults);
271
- return yield* (yield* RcMap.get(locks, keyOf(request.key))).withPermit(Effect.gen(function* () {
269
+ const lock = yield* RcMap.get(locks, keyOf(request.key));
270
+ return yield* Effect.gen(function* () {
272
271
  yield* healthy;
273
272
  const allRecords = yield* Ref.get(records);
274
273
  const same = Array.filter(Array.fromIterable(HashMap.values(allRecords)), (row) => Equal.equals(keyOf(row.handle.key), keyOf(request.key)));
@@ -319,28 +318,28 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
319
318
  yield* scheduleLease(entry, deadline);
320
319
  return record;
321
320
  }));
322
- }));
323
- })),
324
- renew: (handle) => Effect.gen(function* () {
321
+ }).pipe(lock.withPermit);
322
+ }, Effect.scoped),
323
+ renew: Effect.fnUntraced(function* (handle) {
325
324
  yield* healthy;
326
325
  const entry = yield* entryFor(handle);
327
- return yield* SynchronizedRef.modifyEffect(entry.state, (state) => Effect.gen(function* () {
326
+ return yield* Effect.uninterruptibleMask((restore) => SynchronizedRef.modifyEffect(entry.state, Effect.fnUntraced(function* (state) {
328
327
  const now = yield* Clock.monotonicTimeNanos;
329
328
  const current = yield* Effect.fromResult(live(state, now));
330
329
  const running = executionOf(current);
331
- if (running._tag === "Running") yield* running.unit.renew(current.record.leaseMillis);
330
+ if (running._tag === "Running") yield* restore(running.unit.renew(current.record.leaseMillis));
332
331
  const deadline = now + nanos(current.record.leaseMillis);
333
332
  yield* scheduleLease(entry, deadline);
334
333
  return [current.record.leaseMillis, {
335
334
  ...current,
336
335
  deadline
337
336
  }];
338
- }));
337
+ })));
339
338
  }),
340
- load: (handle, request) => Effect.gen(function* () {
339
+ load: Effect.fnUntraced(function* (handle, request) {
341
340
  yield* healthy;
342
341
  const entry = yield* entryFor(handle);
343
- return yield* yield* SynchronizedRef.modifyEffect(entry.state, (state) => Effect.gen(function* () {
342
+ return yield* yield* SynchronizedRef.modifyEffect(entry.state, Effect.fnUntraced(function* (state) {
344
343
  const now = yield* Clock.monotonicTimeNanos;
345
344
  const current = yield* Effect.fromResult(live(state, now));
346
345
  if (current._tag !== "Open") {
@@ -354,7 +353,7 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
354
353
  return [Deferred.await(done), next];
355
354
  })).pipe(Effect.uninterruptible);
356
355
  }),
357
- dispose: (handle) => Effect.gen(function* () {
356
+ dispose: Effect.fnUntraced(function* (handle) {
358
357
  const record = yield* status(handle);
359
358
  if (record.phase === "Stopped") return record.termination;
360
359
  const entry = yield* entryFor(handle);
@@ -362,7 +361,7 @@ const protocol = (runtime, actions) => Effect.gen(function* () {
362
361
  })
363
362
  });
364
363
  });
365
- const make = (options = {}) => Effect.gen(function* () {
364
+ const make = Effect.fnUntraced(function* (options = {}) {
366
365
  const runtime = yield* initialize(options);
367
366
  const actions = operations(runtime);
368
367
  yield* recover(runtime, actions);