The best way to control Claude Code, Codex and more from any computer or phone

main
ts 30 lines 1.3 KB
Raw
1 import * as NodeChildProcessSpawner from "@effect/platform-node-shared/NodeChildProcessSpawner"
2 import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem"
3 import * as NodePath from "@effect/platform-node-shared/NodePath"
4 import * as Effect from "effect/Effect"
5 import * as Layer from "effect/Layer"
6 import * as ChildProcess from "effect/process/ChildProcess"
7 import * as Stream from "effect/Stream"
8
9 const input = Stream.make(new Uint8Array(1024 * 1024))
10 const program = Effect.scoped(Effect.gen(function*() {
11 // Keep the child alive without reading either input pipe. The timer also
12 // bounds its lifetime if the host crashes before scoped cleanup completes.
13 const handle = yield* ChildProcess.make(
14 process.execPath,
15 ["-e", "setTimeout(() => {}, 5000)"],
16 process.argv[2] === "stdin"
17 ? { stdin: input }
18 : { stdin: "ignore", additionalFds: { fd3: { type: "input", stream: input } } }
19 )
20 return yield* handle.exitCode.pipe(Effect.timeout("100 millis"))
21 }))
22
23 const result = await Effect.runPromiseExit(program.pipe(
24 Effect.provide(NodeChildProcessSpawner.layer.pipe(
25 Layer.provide([NodeFileSystem.layer, NodePath.layer])
26 ))
27 ))
28 console.log("program finished:", result._tag)
29 await new Promise((resolve) => setTimeout(resolve, 500))
30 console.log("still alive after 500ms")