The best way to control Claude Code, Codex and more from any computer or phone
Load PTY adapter at runtime (#1311)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
shivam committed
Mar 23, 2026 at 23:10 UTC
754cded24abe6eff74e18a7e741a25c20cfb981d
3 files changed
+25
-13
apps/server/src/serverLayers.ts
+20
-10
@@ -1,5 +1,5 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
-import { Effect, FileSystem, Layer } from "effect";
2
+import { Effect, FileSystem, Layer, Path } from "effect";
3
import * as SqlClient from "effect/unstable/sql/SqlClient";
4
5
import { CheckpointDiffQueryLive } from "./checkpointing/Layers/CheckpointDiffQuery";
@@ -32,10 +32,26 @@ import { GitCoreLive } from "./git/Layers/GitCore";
32
import { GitHubCliLive } from "./git/Layers/GitHubCli";
33
import { CodexTextGenerationLive } from "./git/Layers/CodexTextGeneration";
34
import { GitServiceLive } from "./git/Layers/GitService";
35
-import { BunPtyAdapterLive } from "./terminal/Layers/BunPTY";
36
-import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY";
35
+import { PtyAdapter } from "./terminal/Services/PTY";
36
import { AnalyticsService } from "./telemetry/Services/AnalyticsService";
37
38
+type RuntimePtyAdapterLoader = {
39
+ layer: Layer.Layer<PtyAdapter, never, FileSystem.FileSystem | Path.Path>;
40
+};
41
+
42
+const runtimePtyAdapterLoaders = {
43
+ bun: () => import("./terminal/Layers/BunPTY"),
44
+ node: () => import("./terminal/Layers/NodePTY"),
45
+} satisfies Record<string, () => Promise<RuntimePtyAdapterLoader>>;
46
+
47
+const makeRuntimePtyAdapterLayer = () =>
48
+ Effect.gen(function* () {
49
+ const runtime = process.versions.bun !== undefined ? "bun" : "node";
50
+ const loader = runtimePtyAdapterLoaders[runtime];
51
+ const ptyAdapterModule = yield* Effect.promise<RuntimePtyAdapterLoader>(loader);
52
+ return ptyAdapterModule.layer;
53
+ }).pipe(Layer.unwrap);
54
+
55
export function makeServerProviderLayer(): Layer.Layer<
56
ProviderService,
57
ProviderUnsupportedError,
@@ -108,13 +124,7 @@ export function makeServerRuntimeServicesLayer() {
124
Layer.provideMerge(checkpointReactorLayer),
125
);
126
111
- const terminalLayer = TerminalManagerLive.pipe(
112
- Layer.provide(
113
- typeof Bun !== "undefined" && process.platform !== "win32"
114
- ? BunPtyAdapterLive
115
- : NodePtyAdapterLive,
116
- ),
117
- );
127
+ const terminalLayer = TerminalManagerLive.pipe(Layer.provide(makeRuntimePtyAdapterLayer()));
128
129
const gitManagerLayer = GitManagerLive.pipe(
130
Layer.provideMerge(gitCoreLayer),
apps/server/src/terminal/Layers/BunPTY.ts
+4
-2
@@ -86,11 +86,13 @@ class BunPtyProcess implements PtyProcess {
86
}
87
}
88
89
-export const BunPtyAdapterLive = Layer.effect(
89
+export const layer = Layer.effect(
90
PtyAdapter,
91
Effect.gen(function* () {
92
if (process.platform === "win32") {
93
- return yield* Effect.die("Bun PTY terminal support is unavailable on Windows.");
93
+ return yield* Effect.die(
94
+ "Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.",
95
+ );
96
}
97
return {
98
spawn: (input) =>
apps/server/src/terminal/Layers/NodePTY.ts
+1
-1
@@ -84,7 +84,7 @@ class NodePtyProcess implements PtyProcess {
84
}
85
}
86
87
-export const NodePtyAdapterLive = Layer.effect(
87
+export const layer = Layer.effect(
88
PtyAdapter,
89
Effect.gen(function* () {
90
const fs = yield* FileSystem.FileSystem;