| @@ -18,7 +18,6 @@ if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) { · 17 unmodified lines |
| 18 | 18 | setQuickJSModule(mod); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | | −import { spawn } from "node:child_process"; |
| 22 | 21 | import { resolve } from "node:path"; |
| 23 | 22 | import { Command, Options, Args } from "@effect/cli"; |
| 24 | 23 | import { BunRuntime } from "@effect/platform-bun"; |
| @@ -74,33 +73,16 @@ const script = process.argv[1]; · 49 unmodified lines |
| 74 | 73 | const isDevMode = script?.endsWith(".ts") || script?.endsWith(".js"); |
| 75 | 74 | const cliPrefix = isDevMode ? `bun run ${script}` : "executor"; |
| 76 | 75 | |
| 77 | | −const startBackgroundServer = (port: number): void => { |
| 78 | | − const args = isDevMode |
| 79 | | − ? ["run", script, "web", "--port", String(port)] |
| 80 | | − : ["web", "--port", String(port)]; |
| 81 | | − const child = spawn(process.execPath, args, { |
| 82 | | − detached: true, |
| 83 | | − stdio: "ignore", |
| 84 | | − }); |
| 85 | | − child.unref(); |
| 86 | | −}; |
| 87 | | − |
| 88 | 76 | const ensureServer = (baseUrl: string) => |
| 89 | 77 | Effect.gen(function* () { |
| 90 | 78 | if (yield* Effect.promise(() => isServerReachable(baseUrl))) return; |
| 91 | 79 | |
| 80 | + // Start server in-process instead of spawning a background child. |
| 81 | + // This is more reliable across environments (containers, sandboxes, etc.) |
| 92 | 82 | const url = new URL(baseUrl); |
| 93 | 83 | const port = Number(url.port) || DEFAULT_PORT; |
| 94 | | − console.error(`Starting background server on port ${port}...`); |
| 95 | | − startBackgroundServer(port); |
| 96 | | − |
| 97 | | − const deadline = Date.now() + 30_000; |
| 98 | | − while (Date.now() < deadline) { |
| 99 | | − yield* Effect.promise(() => new Promise((r) => setTimeout(r, 200))); |
| 100 | | − if (yield* Effect.promise(() => isServerReachable(baseUrl))) return; |
| 101 | | − } |
| 102 | | − |
| 103 | | − return yield* Effect.fail(new Error(`Server failed to start within 30s at ${baseUrl}`)); |
| 84 | + console.error(`Starting server on port ${port}...`); |
| 85 | + yield* Effect.promise(() => startServer({ port, embeddedWebUI })); |
| 104 | 86 | }); |
| 105 | 87 | |
| 106 | 88 | // --------------------------------------------------------------------------- |
| @@ -302,6 +284,11 @@ const runCli = Command.run(root, { · 195 unmodified lines |
| 302 | 284 | executable: CLI_NAME, |
| 303 | 285 | }); |
| 304 | 286 | |
| 287 | +if (process.argv.includes("-v")) { |
| 288 | + console.log(CLI_VERSION); |
| 289 | + process.exit(0); |
| 290 | +} |
| 291 | + |
| 305 | 292 | const program = runCli(process.argv).pipe( |
| 306 | 293 | Effect.catchAllCause((cause) => |
| 307 | 294 | Effect.sync(() => { |