@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 72 lines 2.18 KB
Raw
1 /**
2 * Shared Node.js implementation of the Effect `Stdio` service.
3 *
4 * `NodeStdio` provides {@link Stdio.Stdio} from the current Node process. The
5 * exported {@link layer} reads command-line arguments from `process.argv`,
6 * consumes input from `process.stdin`, and writes normal and error output to
7 * `process.stdout` and `process.stderr`. Standard input remains open, and
8 * standard output and error output are not ended unless requested.
9 *
10 * @stability unstable
11 * @since 4.0.0
12 */
13 import * as Effect from "effect/Effect"
14 import * as Layer from "effect/Layer"
15 import { systemError } from "effect/PlatformError"
16 import * as Stdio from "effect/Stdio"
17 import { fromWritable } from "./NodeSink.ts"
18 import { fromReadable } from "./NodeStream.ts"
19
20 /**
21 * Provides `Stdio` from `process.argv`, `process.stdin`, `process.stdout`,
22 * and `process.stderr`; stdin remains open and stdout/stderr are not ended by
23 * default.
24 *
25 * @stability unstable
26 * @category layers
27 * @since 4.0.0
28 */
29 export const layer: Layer.Layer<Stdio.Stdio> = Layer.succeed(
30 Stdio.Stdio,
31 Stdio.make({
32 args: Effect.sync(() => process.argv.slice(2)),
33 stdinIsTerminal: Effect.sync(() => process.stdin.isTTY === true),
34 stdoutIsTerminal: Effect.sync(() => process.stdout.isTTY === true),
35 stderrIsTerminal: Effect.sync(() => process.stderr.isTTY === true),
36 stdout: (options) =>
37 fromWritable({
38 evaluate: () => process.stdout,
39 onError: (cause) =>
40 systemError({
41 module: "Stdio",
42 method: "stdout",
43 _tag: "Unknown",
44 cause
45 }),
46 endOnDone: options?.endOnDone ?? false
47 }),
48 stderr: (options) =>
49 fromWritable({
50 evaluate: () => process.stderr,
51 onError: (cause) =>
52 systemError({
53 module: "Stdio",
54 method: "stderr",
55 _tag: "Unknown",
56 cause
57 }),
58 endOnDone: options?.endOnDone ?? false
59 }),
60 stdin: fromReadable({
61 evaluate: () => process.stdin,
62 onError: (cause) =>
63 systemError({
64 module: "Stdio",
65 method: "stdin",
66 _tag: "Unknown",
67 cause
68 }),
69 closeOnDone: false
70 })
71 })
72 )