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.

fix(server): advertise 256-color TERM on Windows terminals (#5693)

yassiEmpc14bcca10358
diff --git a/apps/server/src/terminal/NodePtyAdapter.test.ts b/apps/server/src/terminal/NodePtyAdapter.test.ts
index ed87440d4..7cf6a167e 100644
--- a/apps/server/src/terminal/NodePtyAdapter.test.ts
+++ b/apps/server/src/terminal/NodePtyAdapter.test.ts
@@ -33,6 +33,7 @@ const testLayer = NodePtyAdapter.layer.pipe(
it.effect("spawns through the public adapter with the provided host references", () =>
Effect.gen(function* () {
+ spawn.mockClear();
const adapter = yield* PtyAdapter.PtyAdapter;
const process = yield* adapter.spawn({
shell: "powershell.exe",
@@ -52,8 +53,35 @@ it.effect("spawns through the public adapter with the provided host references",
cwd: "C:\\workspace",
cols: 120,
rows: 40,
- env: {},
- name: "xterm-color",
+ env: { TERM: "xterm-256color" },
+ name: "xterm-256color",
+ },
+ ]);
+ }).pipe(Effect.provide(testLayer)),
+);
+
+it.effect("preserves a caller-provided TERM in the spawn env on win32", () =>
+ Effect.gen(function* () {
+ spawn.mockClear();
+ const adapter = yield* PtyAdapter.PtyAdapter;
+ yield* adapter.spawn({
+ shell: "powershell.exe",
+ cwd: "C:\\workspace",
+ cols: 80,
+ rows: 24,
+ env: { TERM: "xterm-direct" },
+ });
+
+ assert.equal(spawn.mock.calls.length, 1);
+ assert.deepEqual(spawn.mock.calls[0], [
+ "powershell.exe",
+ [],
+ {
+ cwd: "C:\\workspace",
+ cols: 80,
+ rows: 24,
+ env: { TERM: "xterm-direct" },
+ name: "xterm-256color",
},
]);
}).pipe(Effect.provide(testLayer)),
diff --git a/apps/server/src/terminal/NodePtyAdapter.ts b/apps/server/src/terminal/NodePtyAdapter.ts
index ac06e1edf..e9c462ab2 100644
--- a/apps/server/src/terminal/NodePtyAdapter.ts
+++ b/apps/server/src/terminal/NodePtyAdapter.ts
@@ -141,14 +141,21 @@ export const make = Effect.fn("NodePtyAdapter.make")(function* (
return PtyAdapter.PtyAdapter.of({
spawn: Effect.fn("NodePtyAdapter.spawn")(function* (input) {
yield* ensureNodePtySpawnHelperExecutableCached;
+ // node-pty only writes `name` into the child's TERM on the Unix path;
+ // the ConPTY path leaves the environment untouched, so Windows children
+ // inherit a missing or 16-color TERM unless it is set here.
+ const env =
+ platform === "win32" && input.env["TERM"] === undefined
+ ? { ...input.env, TERM: "xterm-256color" }
+ : input.env;
const ptyProcess = yield* Effect.try({
try: () =>
nodePty.spawn(input.shell, input.args ?? [], {
cwd: input.cwd,
cols: input.cols,
rows: input.rows,
- env: input.env,
- name: platform === "win32" ? "xterm-color" : "xterm-256color",
+ env,
+ name: "xterm-256color",
}),
catch: (cause) =>
new PtyAdapter.PtySpawnError({