Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Load PTY adapter at runtime (#1311)

shivam754cded24abe
diff --git a/apps/server/src/serverLayers.ts b/apps/server/src/serverLayers.ts
index 7250f8566..b75444173 100644
--- a/apps/server/src/serverLayers.ts
+++ b/apps/server/src/serverLayers.ts
@@ -1,5 +1,5 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
-import { Effect, FileSystem, Layer } from "effect";
+import { Effect, FileSystem, Layer, Path } from "effect";
import * as SqlClient from "effect/unstable/sql/SqlClient";
import { CheckpointDiffQueryLive } from "./checkpointing/Layers/CheckpointDiffQuery";
@@ -32,10 +32,26 @@ import { GitCoreLive } from "./git/Layers/GitCore";
import { GitHubCliLive } from "./git/Layers/GitHubCli";
import { CodexTextGenerationLive } from "./git/Layers/CodexTextGeneration";
import { GitServiceLive } from "./git/Layers/GitService";
-import { BunPtyAdapterLive } from "./terminal/Layers/BunPTY";
-import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY";
+import { PtyAdapter } from "./terminal/Services/PTY";
import { AnalyticsService } from "./telemetry/Services/AnalyticsService";
+type RuntimePtyAdapterLoader = {
+ layer: Layer.Layer<PtyAdapter, never, FileSystem.FileSystem | Path.Path>;
+};
+
+const runtimePtyAdapterLoaders = {
+ bun: () => import("./terminal/Layers/BunPTY"),
+ node: () => import("./terminal/Layers/NodePTY"),
+} satisfies Record<string, () => Promise<RuntimePtyAdapterLoader>>;
+
+const makeRuntimePtyAdapterLayer = () =>
+ Effect.gen(function* () {
+ const runtime = process.versions.bun !== undefined ? "bun" : "node";
+ const loader = runtimePtyAdapterLoaders[runtime];
+ const ptyAdapterModule = yield* Effect.promise<RuntimePtyAdapterLoader>(loader);
+ return ptyAdapterModule.layer;
+ }).pipe(Layer.unwrap);
+
export function makeServerProviderLayer(): Layer.Layer<
ProviderService,
ProviderUnsupportedError,
@@ -108,13 +124,7 @@ export function makeServerRuntimeServicesLayer() {
Layer.provideMerge(checkpointReactorLayer),
);
- const terminalLayer = TerminalManagerLive.pipe(
- Layer.provide(
- typeof Bun !== "undefined" && process.platform !== "win32"
- ? BunPtyAdapterLive
- : NodePtyAdapterLive,
- ),
- );
+ const terminalLayer = TerminalManagerLive.pipe(Layer.provide(makeRuntimePtyAdapterLayer()));
const gitManagerLayer = GitManagerLive.pipe(
Layer.provideMerge(gitCoreLayer),
diff --git a/apps/server/src/terminal/Layers/BunPTY.ts b/apps/server/src/terminal/Layers/BunPTY.ts
index 48b6492b1..1fb4bdd63 100644
--- a/apps/server/src/terminal/Layers/BunPTY.ts
+++ b/apps/server/src/terminal/Layers/BunPTY.ts
@@ -86,11 +86,13 @@ class BunPtyProcess implements PtyProcess {
}
}
-export const BunPtyAdapterLive = Layer.effect(
+export const layer = Layer.effect(
PtyAdapter,
Effect.gen(function* () {
if (process.platform === "win32") {
- return yield* Effect.die("Bun PTY terminal support is unavailable on Windows.");
+ return yield* Effect.die(
+ "Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.",
+ );
}
return {
spawn: (input) =>
diff --git a/apps/server/src/terminal/Layers/NodePTY.ts b/apps/server/src/terminal/Layers/NodePTY.ts
index 60a7ab622..cf1fdd219 100644
--- a/apps/server/src/terminal/Layers/NodePTY.ts
+++ b/apps/server/src/terminal/Layers/NodePTY.ts
@@ -84,7 +84,7 @@ class NodePtyProcess implements PtyProcess {
}
}
-export const NodePtyAdapterLive = Layer.effect(
+export const layer = Layer.effect(
PtyAdapter,
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;