@devries-cameron20 / t3code-1 / commits / 88f31d2f65
Fork 0

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

Pass runtime env through terminal open and disable zsh prompt spacer

- add optional `env` to terminal open contract and validate env keys/limits - propagate runtime env from web terminal/script launches to server PTY spawn - start `zsh` with `-o nopromptsp` to avoid trailing `%` markers and add coverage

Julius Marminge committed Feb 17, 2026 at 23:01 UTC 88f31d2f65b1db7a557320d99f70b8c707cfdf4f
11 files changed +200 -84
apps/server/src/ptyAdapter.ts
+2 -1
@@ -20,6 +20,7 @@ export interface PtyProcess {
20
21 export interface PtySpawnInput {
22 shell: string;
23 + args?: string[];
24 cwd: string;
25 cols: number;
26 rows: number;
@@ -118,7 +119,7 @@ class NodePtyProcess implements PtyProcess {
119 export class NodePtyAdapter implements PtyAdapter {
120 spawn(input: PtySpawnInput): PtyProcess {
121 ensureNodePtySpawnHelperExecutable();
121 - const ptyProcess = nodePty.spawn(input.shell, [], {
122 + const ptyProcess = nodePty.spawn(input.shell, input.args ?? [], {
123 cwd: input.cwd,
124 cols: input.cols,
125 rows: input.rows,
apps/server/src/terminalManager.test.ts
+38
@@ -466,4 +466,42 @@ describe("TerminalManager", () => {
466 restoreEnv();
467 }
468 });
469 +
470 + it("injects runtime env overrides into spawned terminals", async () => {
471 + const { manager, ptyAdapter } = makeManager();
472 + await manager.open(
473 + openInput({
474 + env: {
475 + T3CODE_PROJECT_ROOT: "/repo",
476 + T3CODE_WORKTREE_PATH: "/repo/worktree-a",
477 + CUSTOM_FLAG: "1",
478 + },
479 + }),
480 + );
481 + const spawnInput = ptyAdapter.spawnInputs[0];
482 + expect(spawnInput).toBeDefined();
483 + if (!spawnInput) return;
484 +
485 + expect(spawnInput.env.T3CODE_PROJECT_ROOT).toBe("/repo");
486 + expect(spawnInput.env.T3CODE_WORKTREE_PATH).toBe("/repo/worktree-a");
487 + expect(spawnInput.env.CUSTOM_FLAG).toBe("1");
488 +
489 + manager.dispose();
490 + });
491 +
492 + it("starts zsh with prompt spacer disabled to avoid `%` end markers", async () => {
493 + if (process.platform === "win32") return;
494 + const { manager, ptyAdapter } = makeManager(5, {
495 + shellResolver: () => "/bin/zsh",
496 + });
497 + await manager.open(openInput());
498 + const spawnInput = ptyAdapter.spawnInputs[0];
499 + expect(spawnInput).toBeDefined();
500 + if (!spawnInput) return;
501 +
502 + expect(spawnInput.shell).toBe("/bin/zsh");
503 + expect(spawnInput.args).toEqual(["-o", "nopromptsp"]);
504 +
505 + manager.dispose();
506 + });
507 });
apps/server/src/terminalManager.ts
+83 -25
@@ -59,6 +59,12 @@ interface TerminalSessionState {
59 unsubscribeData: (() => void) | null;
60 unsubscribeExit: (() => void) | null;
61 hasRunningSubprocess: boolean;
62 + runtimeEnv: Record<string, string> | null;
63 +}
64 +
65 +interface ShellCandidate {
66 + shell: string;
67 + args?: string[];
68 }
69
70 function defaultShellResolver(): string {
@@ -82,34 +88,54 @@ function normalizeShellCommand(value: string | undefined): string | null {
88 return firstToken.replace(/^['"]|['"]$/g, "");
89 }
90
85 -function uniqueShells(shells: Array<string | null>): string[] {
91 +function shellCandidateFromCommand(command: string | null): ShellCandidate | null {
92 + if (!command || command.length === 0) return null;
93 + const shellName = path.basename(command).toLowerCase();
94 + if (process.platform !== "win32" && shellName === "zsh") {
95 + return { shell: command, args: ["-o", "nopromptsp"] };
96 + }
97 + return { shell: command };
98 +}
99 +
100 +function formatShellCandidate(candidate: ShellCandidate): string {
101 + if (!candidate.args || candidate.args.length === 0) return candidate.shell;
102 + return `${candidate.shell} ${candidate.args.join(" ")}`;
103 +}
104 +
105 +function uniqueShellCandidates(candidates: Array<ShellCandidate | null>): ShellCandidate[] {
106 const seen = new Set<string>();
87 - const ordered: string[] = [];
88 - for (const shell of shells) {
89 - if (!shell || shell.length === 0) continue;
90 - if (seen.has(shell)) continue;
91 - seen.add(shell);
92 - ordered.push(shell);
107 + const ordered: ShellCandidate[] = [];
108 + for (const candidate of candidates) {
109 + if (!candidate) continue;
110 + const key = formatShellCandidate(candidate);
111 + if (seen.has(key)) continue;
112 + seen.add(key);
113 + ordered.push(candidate);
114 }
115 return ordered;
116 }
117
97 -function resolveShellCandidates(shellResolver: () => string): string[] {
98 - const requested = normalizeShellCommand(shellResolver());
118 +function resolveShellCandidates(shellResolver: () => string): ShellCandidate[] {
119 + const requested = shellCandidateFromCommand(normalizeShellCommand(shellResolver()));
120
121 if (process.platform === "win32") {
101 - return uniqueShells([requested, process.env.ComSpec ?? null, "powershell.exe", "cmd.exe"]);
122 + return uniqueShellCandidates([
123 + requested,
124 + shellCandidateFromCommand(process.env.ComSpec ?? null),
125 + shellCandidateFromCommand("powershell.exe"),
126 + shellCandidateFromCommand("cmd.exe"),
127 + ]);
128 }
129
104 - return uniqueShells([
130 + return uniqueShellCandidates([
131 requested,
106 - normalizeShellCommand(process.env.SHELL),
107 - "/bin/zsh",
108 - "/bin/bash",
109 - "/bin/sh",
110 - "zsh",
111 - "bash",
112 - "sh",
132 + shellCandidateFromCommand(normalizeShellCommand(process.env.SHELL)),
133 + shellCandidateFromCommand("/bin/zsh"),
134 + shellCandidateFromCommand("/bin/bash"),
135 + shellCandidateFromCommand("/bin/sh"),
136 + shellCandidateFromCommand("zsh"),
137 + shellCandidateFromCommand("bash"),
138 + shellCandidateFromCommand("sh"),
139 ]);
140 }
141
@@ -241,16 +267,33 @@ function shouldExcludeTerminalEnvKey(key: string): boolean {
267 return TERMINAL_ENV_BLOCKLIST.has(normalizedKey);
268 }
269
244 -function createTerminalSpawnEnv(baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
270 +function createTerminalSpawnEnv(
271 + baseEnv: NodeJS.ProcessEnv,
272 + runtimeEnv?: Record<string, string> | null,
273 +): NodeJS.ProcessEnv {
274 const spawnEnv: NodeJS.ProcessEnv = {};
275 for (const [key, value] of Object.entries(baseEnv)) {
276 if (value === undefined) continue;
277 if (shouldExcludeTerminalEnvKey(key)) continue;
278 spawnEnv[key] = value;
279 }
280 + if (runtimeEnv) {
281 + for (const [key, value] of Object.entries(runtimeEnv)) {
282 + spawnEnv[key] = value;
283 + }
284 + }
285 return spawnEnv;
286 }
287
288 +function normalizedRuntimeEnv(
289 + env: Record<string, string> | undefined,
290 +): Record<string, string> | null {
291 + if (!env) return null;
292 + const entries = Object.entries(env);
293 + if (entries.length === 0) return null;
294 + return Object.fromEntries(entries.sort(([left], [right]) => left.localeCompare(right)));
295 +}
296 +
297 export class TerminalManager extends EventEmitter<TerminalManagerEvents> {
298 private readonly sessions = new Map<string, TerminalSessionState>();
299 private readonly logsDir: string;
@@ -307,20 +350,30 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {
350 unsubscribeData: null,
351 unsubscribeExit: null,
352 hasRunningSubprocess: false,
353 + runtimeEnv: normalizedRuntimeEnv(input.env),
354 };
355 this.sessions.set(sessionKey, session);
356 this.startSession(session, input, "started");
357 return this.snapshot(session);
358 }
359
316 - if (existing.cwd !== input.cwd) {
360 + const nextRuntimeEnv = normalizedRuntimeEnv(input.env);
361 + const currentRuntimeEnv = existing.runtimeEnv;
362 + const runtimeEnvChanged =
363 + JSON.stringify(currentRuntimeEnv) !== JSON.stringify(nextRuntimeEnv);
364 +
365 + if (existing.cwd !== input.cwd || runtimeEnvChanged) {
366 this.stopProcess(existing);
367 existing.cwd = input.cwd;
368 + existing.runtimeEnv = nextRuntimeEnv;
369 existing.history = "";
370 await this.persistHistory(existing.threadId, existing.terminalId, existing.history);
371 } else if (existing.status === "exited" || existing.status === "error") {
372 + existing.runtimeEnv = nextRuntimeEnv;
373 existing.history = "";
374 await this.persistHistory(existing.threadId, existing.terminalId, existing.history);
375 + } else if (currentRuntimeEnv !== nextRuntimeEnv) {
376 + existing.runtimeEnv = nextRuntimeEnv;
377 }
378
379 if (!existing.process) {
@@ -404,11 +457,13 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {
457 unsubscribeData: null,
458 unsubscribeExit: null,
459 hasRunningSubprocess: false,
460 + runtimeEnv: normalizedRuntimeEnv(input.env),
461 };
462 this.sessions.set(sessionKey, session);
463 } else {
464 this.stopProcess(session);
465 session.cwd = input.cwd;
466 + session.runtimeEnv = normalizedRuntimeEnv(input.env);
467 }
468
469 session.history = "";
@@ -480,19 +535,20 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {
535 let startedShell: string | null = null;
536 try {
537 const shellCandidates = resolveShellCandidates(this.shellResolver);
483 - const terminalEnv = createTerminalSpawnEnv(process.env);
538 + const terminalEnv = createTerminalSpawnEnv(process.env, session.runtimeEnv);
539 let lastSpawnError: unknown = null;
540
486 - for (const shell of shellCandidates) {
541 + for (const candidate of shellCandidates) {
542 try {
543 ptyProcess = this.ptyAdapter.spawn({
489 - shell,
544 + shell: candidate.shell,
545 + ...(candidate.args ? { args: candidate.args } : {}),
546 cwd: session.cwd,
547 cols: session.cols,
548 rows: session.rows,
549 env: terminalEnv,
550 });
495 - startedShell = shell;
551 + startedShell = formatShellCandidate(candidate);
552 break;
553 } catch (error) {
554 lastSpawnError = error;
@@ -506,7 +562,9 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {
562 const detail =
563 lastSpawnError instanceof Error ? lastSpawnError.message : "Terminal start failed";
564 const tried =
509 - shellCandidates.length > 0 ? ` Tried shells: ${shellCandidates.join(", ")}.` : "";
565 + shellCandidates.length > 0
566 + ? ` Tried shells: ${shellCandidates.map((candidate) => formatShellCandidate(candidate)).join(", ")}.`
567 + : "";
568 throw new Error(`${detail}.${tried}`.trim());
569 }
570
apps/server/src/wsServer.test.ts
+2
@@ -323,6 +323,8 @@ describe("WebSocket Server", () => {
323 });
324
325 it("responds to server.getConfig", async () => {
326 + const fakeHome = makeTempDir("t3code-home-");
327 + vi.spyOn(os, "homedir").mockReturnValue(fakeHome);
328 server = createTestServer({ cwd: "/my/workspace" });
329 await server.start();
330 const addr = server.httpServer.address();
apps/web/src/components/ChatView.tsx
+27 -20
@@ -102,7 +102,6 @@ import { Command, CommandInput, CommandItem, CommandList } from "./ui/command";
102 import ProjectScriptsControl, { type NewProjectScriptInput } from "./ProjectScriptsControl";
103 import {
104 commandForProjectScript,
105 - injectEnvIntoShellCommand,
105 nextProjectScriptId,
106 projectScriptRuntimeEnv,
107 projectScriptIdFromCommand,
@@ -545,6 +544,15 @@ export default function ChatView() {
544 [composerHighlightedItemId, composerMenuItems],
545 );
546 const keybindings = keybindingsQuery.data ?? EMPTY_KEYBINDINGS;
547 + const threadTerminalRuntimeEnv = useMemo(() => {
548 + if (!activeProject) return {};
549 + return projectScriptRuntimeEnv({
550 + project: {
551 + cwd: activeProject.cwd,
552 + },
553 + worktreePath: activeThread?.worktreePath ?? null,
554 + });
555 + }, [activeProject, activeThread?.worktreePath]);
556 // Default true while loading to avoid toolbar flicker.
557 const isGitRepo = branchesQuery.data?.isRepo ?? true;
558 const splitTerminalShortcutLabel = useMemo(
@@ -661,13 +669,16 @@ export default function ChatView() {
669 env?: Record<string, string>;
670 worktreePath?: string | null;
671 preferNewTerminal?: boolean;
672 + rememberAsLastInvoked?: boolean;
673 },
674 ) => {
675 if (!api || !activeThreadId || !activeProject || !activeThread) return;
667 - setLastInvokedScriptByProjectId((current) => {
668 - if (current[activeProject.id] === script.id) return current;
669 - return { ...current, [activeProject.id]: script.id };
670 - });
676 + if (options?.rememberAsLastInvoked !== false) {
677 + setLastInvokedScriptByProjectId((current) => {
678 + if (current[activeProject.id] === script.id) return current;
679 + return { ...current, [activeProject.id]: script.id };
680 + });
681 + }
682 const targetCwd = options?.cwd ?? gitCwd ?? activeProject.cwd;
683 const baseTerminalId =
684 activeThread.activeTerminalId ||
@@ -701,20 +712,13 @@ export default function ChatView() {
712 }
713 setTerminalFocusRequestId((value) => value + 1);
714
704 - const resolvedCommand = injectEnvIntoShellCommand(
705 - script.command,
706 - projectScriptRuntimeEnv({
707 - project: {
708 - id: activeProject.id,
709 - name: activeProject.name,
710 - cwd: activeProject.cwd,
711 - },
712 - script,
713 - threadId: activeThreadId,
714 - worktreePath: options?.worktreePath ?? activeThread.worktreePath ?? null,
715 - ...(options?.env ? { extraEnv: options.env } : {}),
716 - }),
717 - );
715 + const runtimeEnv = projectScriptRuntimeEnv({
716 + project: {
717 + cwd: activeProject.cwd,
718 + },
719 + worktreePath: options?.worktreePath ?? activeThread.worktreePath ?? null,
720 + ...(options?.env ? { extraEnv: options.env } : {}),
721 + });
722
723 try {
724 await api.terminal.open({
@@ -723,11 +727,12 @@ export default function ChatView() {
727 cwd: targetCwd,
728 cols: SCRIPT_TERMINAL_COLS,
729 rows: SCRIPT_TERMINAL_ROWS,
730 + env: runtimeEnv,
731 });
732 await api.terminal.write({
733 threadId: activeThreadId,
734 terminalId: targetTerminalId,
730 - data: `${resolvedCommand}\n`,
735 + data: `${script.command}\r`,
736 });
737 } catch (error) {
738 dispatch({
@@ -1337,6 +1342,7 @@ export default function ChatView() {
1342 void runProjectScript(setupScript, {
1343 cwd: result.worktree.path,
1344 worktreePath: result.worktree.path,
1345 + rememberAsLastInvoked: false,
1346 });
1347 }
1348 } catch (err) {
@@ -1889,6 +1895,7 @@ export default function ChatView() {
1895 api={api}
1896 threadId={activeThread.id}
1897 cwd={gitCwd ?? activeProject.cwd}
1898 + runtimeEnv={threadTerminalRuntimeEnv}
1899 height={activeThread.terminalHeight}
1900 terminalIds={activeThread.terminalIds}
1901 activeTerminalId={activeThread.activeTerminalId}
apps/web/src/components/ProjectScriptsControl.tsx
+2 -2
@@ -6,12 +6,12 @@ import type {
6 import {
7 BugIcon,
8 ChevronDownIcon,
9 - CogIcon,
9 FlaskConicalIcon,
10 HammerIcon,
11 ListChecksIcon,
12 PlayIcon,
13 PlusIcon,
14 + SettingsIcon,
15 WrenchIcon,
16 } from "lucide-react";
17 import React, { type FormEvent, type KeyboardEvent, useMemo, useState } from "react";
@@ -319,7 +319,7 @@ export default function ProjectScriptsControl({
319 openEditDialog(script);
320 }}
321 >
322 - <CogIcon className="size-3.5" />
322 + <SettingsIcon className="size-3.5" />
323 </Button>
324 </span>
325 </MenuItem>
apps/web/src/components/ThreadTerminalDrawer.tsx
+8 -1
@@ -111,6 +111,7 @@ interface TerminalViewportProps {
111 threadId: string;
112 terminalId: string;
113 cwd: string;
114 + runtimeEnv?: Record<string, string>;
115 focusRequestId: number;
116 autoFocus: boolean;
117 resizeEpoch: number;
@@ -122,6 +123,7 @@ function TerminalViewport({
123 threadId,
124 terminalId,
125 cwd,
126 + runtimeEnv,
127 focusRequestId,
128 autoFocus,
129 resizeEpoch,
@@ -274,6 +276,7 @@ function TerminalViewport({
276 cwd,
277 cols: activeTerminal.cols,
278 rows: activeTerminal.rows,
279 + ...(runtimeEnv ? { env: runtimeEnv } : {}),
280 });
281 if (disposed) return;
282 activeTerminal.write("\u001bc");
@@ -369,7 +372,7 @@ function TerminalViewport({
372 fitAddonRef.current = null;
373 terminal.dispose();
374 };
372 - }, [api, cwd, terminalId, threadId]);
375 + }, [api, autoFocus, cwd, runtimeEnv, terminalId, threadId]);
376
377 useEffect(() => {
378 if (!autoFocus) return;
@@ -414,6 +417,7 @@ interface ThreadTerminalDrawerProps {
417 api: NativeApi;
418 threadId: string;
419 cwd: string;
420 + runtimeEnv?: Record<string, string>;
421 height: number;
422 terminalIds: string[];
423 activeTerminalId: string;
@@ -463,6 +467,7 @@ export default function ThreadTerminalDrawer({
467 api,
468 threadId,
469 cwd,
470 + runtimeEnv,
471 height,
472 terminalIds,
473 activeTerminalId,
@@ -778,6 +783,7 @@ export default function ThreadTerminalDrawer({
783 threadId={threadId}
784 terminalId={terminalId}
785 cwd={cwd}
786 + {...(runtimeEnv ? { runtimeEnv } : {})}
787 focusRequestId={focusRequestId}
788 autoFocus={terminalId === resolvedActiveTerminalId}
789 resizeEpoch={resizeEpoch}
@@ -795,6 +801,7 @@ export default function ThreadTerminalDrawer({
801 threadId={threadId}
802 terminalId={resolvedActiveTerminalId}
803 cwd={cwd}
804 + {...(runtimeEnv ? { runtimeEnv } : {})}
805 focusRequestId={focusRequestId}
806 autoFocus
807 resizeEpoch={resizeEpoch}
apps/web/src/projectScripts.test.ts
+2 -24
@@ -67,40 +67,19 @@ describe("projectScripts helpers", () => {
67
68 it("builds default runtime env for scripts", () => {
69 const env = projectScriptRuntimeEnv({
70 - project: { id: "project-1", name: "acme-web", cwd: "/repo" },
71 - script: {
72 - id: "test",
73 - name: "Test",
74 - icon: "test",
75 - runOnWorktreeCreate: false,
76 - },
77 - threadId: "thread-1",
70 + project: { cwd: "/repo" },
71 worktreePath: "/repo/worktree-a",
72 });
73
74 expect(env).toMatchObject({
75 T3CODE_PROJECT_ROOT: "/repo",
83 - T3CODE_PROJECT_ID: "project-1",
84 - T3CODE_PROJECT_NAME: "acme-web",
85 - T3CODE_THREAD_ID: "thread-1",
86 - T3CODE_SCRIPT_ID: "test",
87 - T3CODE_SCRIPT_NAME: "Test",
88 - T3CODE_SCRIPT_ICON: "test",
89 - T3CODE_SCRIPT_IS_SETUP: "0",
76 T3CODE_WORKTREE_PATH: "/repo/worktree-a",
77 });
78 });
79
80 it("allows overriding runtime env values", () => {
81 const env = projectScriptRuntimeEnv({
96 - project: { id: "project-1", name: "acme-web", cwd: "/repo" },
97 - script: {
98 - id: "setup",
99 - name: "Setup",
100 - icon: "configure",
101 - runOnWorktreeCreate: true,
102 - },
103 - threadId: "thread-1",
82 + project: { cwd: "/repo" },
83 extraEnv: {
84 T3CODE_PROJECT_ROOT: "/custom-root",
85 CUSTOM_FLAG: "1",
@@ -108,7 +87,6 @@ describe("projectScripts helpers", () => {
87 });
88
89 expect(env.T3CODE_PROJECT_ROOT).toBe("/custom-root");
111 - expect(env.T3CODE_SCRIPT_IS_SETUP).toBe("1");
90 expect(env.CUSTOM_FLAG).toBe("1");
91 expect(env.T3CODE_WORKTREE_PATH).toBeUndefined();
92 });
apps/web/src/projectScripts.ts
-11
@@ -85,12 +85,8 @@ export function injectEnvIntoShellCommand(
85
86 interface ProjectScriptRuntimeEnvInput {
87 project: {
88 - id: string;
89 - name: string;
88 cwd: string;
89 };
92 - script: Pick<ProjectScript, "id" | "name" | "icon" | "runOnWorktreeCreate">;
93 - threadId: string;
90 worktreePath?: string | null;
91 extraEnv?: Record<string, string>;
92 }
@@ -98,13 +94,6 @@ interface ProjectScriptRuntimeEnvInput {
94 export function projectScriptRuntimeEnv(input: ProjectScriptRuntimeEnvInput): Record<string, string> {
95 const env: Record<string, string> = {
96 T3CODE_PROJECT_ROOT: input.project.cwd,
101 - T3CODE_PROJECT_ID: input.project.id,
102 - T3CODE_PROJECT_NAME: input.project.name,
103 - T3CODE_THREAD_ID: input.threadId,
104 - T3CODE_SCRIPT_ID: input.script.id,
105 - T3CODE_SCRIPT_NAME: input.script.name,
106 - T3CODE_SCRIPT_ICON: input.script.icon,
107 - T3CODE_SCRIPT_IS_SETUP: input.script.runOnWorktreeCreate ? "1" : "0",
97 };
98 if (input.worktreePath) {
99 env.T3CODE_WORKTREE_PATH = input.worktreePath;
packages/contracts/src/terminal.test.ts
+30
@@ -42,6 +42,36 @@ describe("terminalOpenInputSchema", () => {
42 });
43 expect(parsed.terminalId).toBe(DEFAULT_TERMINAL_ID);
44 });
45 +
46 + it("accepts optional env overrides", () => {
47 + const parsed = terminalOpenInputSchema.parse({
48 + threadId: "thread-1",
49 + cwd: "/tmp/project",
50 + cols: 100,
51 + rows: 24,
52 + env: {
53 + T3CODE_PROJECT_ROOT: "/tmp/project",
54 + CUSTOM_FLAG: "1",
55 + },
56 + });
57 + expect(parsed.env).toMatchObject({
58 + T3CODE_PROJECT_ROOT: "/tmp/project",
59 + CUSTOM_FLAG: "1",
60 + });
61 + });
62 +
63 + it("rejects invalid env keys", () => {
64 + const result = terminalOpenInputSchema.safeParse({
65 + threadId: "thread-1",
66 + cwd: "/tmp/project",
67 + cols: 100,
68 + rows: 24,
69 + env: {
70 + "bad-key": "1",
71 + },
72 + });
73 + expect(result.success).toBe(false);
74 + });
75 });
76
77 describe("terminalWriteInputSchema", () => {
packages/contracts/src/terminal.ts
+6
@@ -5,6 +5,11 @@ export const DEFAULT_TERMINAL_ID = "default";
5 const terminalColsSchema = z.number().int().min(20).max(400);
6 const terminalRowsSchema = z.number().int().min(5).max(200);
7 const terminalIdSchema = z.string().trim().min(1).max(128);
8 +const terminalEnvKeySchema = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).max(128);
9 +const terminalEnvValueSchema = z.string().max(8_192);
10 +const terminalEnvSchema = z
11 + .record(terminalEnvKeySchema, terminalEnvValueSchema)
12 + .refine((env) => Object.keys(env).length <= 128, "Too many terminal env vars");
13
14 export const terminalThreadInputSchema = z.object({
15 threadId: z.string().trim().min(1),
@@ -18,6 +23,7 @@ export const terminalOpenInputSchema = terminalSessionInputSchema.extend({
23 cwd: z.string().trim().min(1),
24 cols: terminalColsSchema,
25 rows: terminalRowsSchema,
26 + env: terminalEnvSchema.optional(),
27 });
28
29 export const terminalWriteInputSchema = terminalSessionInputSchema.extend({