@devries-cameron20 / t3code-1 / commits / 2c351726ae
Fork 0

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

fix(contracts): align terminal restart input type across IPC, WS, and server (#597)

0x1f99d committed Mar 11, 2026 at 03:46 UTC 2c351726ae21a73ac0549500783d5a4de6394214
5 files changed +22 -6
apps/server/src/terminal/Layers/Manager.test.ts
+12 -1
@@ -6,6 +6,7 @@ import {
6 DEFAULT_TERMINAL_ID,
7 type TerminalEvent,
8 type TerminalOpenInput,
9 + type TerminalRestartInput,
10 } from "@t3tools/contracts";
11 import { afterEach, describe, expect, it } from "vitest";
12
@@ -134,6 +135,16 @@ function openInput(overrides: Partial<TerminalOpenInput> = {}): TerminalOpenInpu
135 };
136 }
137
138 +function restartInput(overrides: Partial<TerminalRestartInput> = {}): TerminalRestartInput {
139 + return {
140 + threadId: "thread-1",
141 + cwd: process.cwd(),
142 + cols: 100,
143 + rows: 24,
144 + ...overrides,
145 + };
146 +}
147 +
148 function historyLogName(threadId: string): string {
149 return `terminal_${Encoding.encodeBase64Url(threadId)}.log`;
150 }
@@ -361,7 +372,7 @@ describe("TerminalManager", () => {
372 firstProcess.emitData("before restart\n");
373 await waitFor(() => fs.existsSync(historyLogPath(logsDir)));
374
364 - const snapshot = await manager.restart(openInput());
375 + const snapshot = await manager.restart(restartInput());
376 expect(snapshot.history).toBe("");
377 expect(snapshot.status).toBe("running");
378 expect(ptyAdapter.spawnInputs).toHaveLength(2);
apps/server/src/terminal/Layers/Manager.ts
+4 -2
@@ -8,6 +8,7 @@ import {
8 TerminalCloseInput,
9 TerminalOpenInput,
10 TerminalResizeInput,
11 + TerminalRestartInput,
12 TerminalWriteInput,
13 type TerminalEvent,
14 type TerminalSessionSnapshot,
@@ -37,6 +38,7 @@ const DEFAULT_OPEN_ROWS = 30;
38 const TERMINAL_ENV_BLOCKLIST = new Set(["PORT", "ELECTRON_RENDERER_PORT", "ELECTRON_RUN_AS_NODE"]);
39
40 const decodeTerminalOpenInput = Schema.decodeUnknownSync(TerminalOpenInput);
41 +const decodeTerminalRestartInput = Schema.decodeUnknownSync(TerminalRestartInput);
42 const decodeTerminalWriteInput = Schema.decodeUnknownSync(TerminalWriteInput);
43 const decodeTerminalResizeInput = Schema.decodeUnknownSync(TerminalResizeInput);
44 const decodeTerminalClearInput = Schema.decodeUnknownSync(TerminalClearInput);
@@ -478,8 +480,8 @@ export class TerminalManagerRuntime extends EventEmitter<TerminalManagerEvents>
480 });
481 }
482
481 - async restart(raw: TerminalOpenInput): Promise<TerminalSessionSnapshot> {
482 - const input = decodeTerminalOpenInput(raw);
483 + async restart(raw: TerminalRestartInput): Promise<TerminalSessionSnapshot> {
484 + const input = decodeTerminalRestartInput(raw);
485 return this.runWithThreadLock(input.threadId, async () => {
486 await this.assertValidCwd(input.cwd);
487
apps/server/src/terminal/Services/Manager.ts
+2 -1
@@ -12,6 +12,7 @@ import {
12 TerminalEvent,
13 TerminalOpenInput,
14 TerminalResizeInput,
15 + TerminalRestartInput,
16 TerminalSessionSnapshot,
17 TerminalSessionStatus,
18 TerminalWriteInput,
@@ -88,7 +89,7 @@ export interface TerminalManagerShape {
89 * Always resets history before spawning the new process.
90 */
91 readonly restart: (
91 - input: TerminalOpenInput,
92 + input: TerminalRestartInput,
93 ) => Effect.Effect<TerminalSessionSnapshot, TerminalError>;
94
95 /**
packages/contracts/src/ipc.ts
+2 -1
@@ -31,6 +31,7 @@ import type {
31 TerminalEvent,
32 TerminalOpenInput,
33 TerminalResizeInput,
34 + TerminalRestartInput,
35 TerminalSessionSnapshot,
36 TerminalWriteInput,
37 } from "./terminal";
@@ -118,7 +119,7 @@ export interface NativeApi {
119 write: (input: TerminalWriteInput) => Promise<void>;
120 resize: (input: TerminalResizeInput) => Promise<void>;
121 clear: (input: TerminalClearInput) => Promise<void>;
121 - restart: (input: TerminalOpenInput) => Promise<TerminalSessionSnapshot>;
122 + restart: (input: TerminalRestartInput) => Promise<TerminalSessionSnapshot>;
123 close: (input: TerminalCloseInput) => Promise<void>;
124 onEvent: (callback: (event: TerminalEvent) => void) => () => void;
125 };
packages/contracts/src/terminal.ts
+2 -1
@@ -60,12 +60,13 @@ export const TerminalClearInput = TerminalSessionInput;
60 export type TerminalClearInput = Schema.Codec.Encoded<typeof TerminalClearInput>;
61
62 export const TerminalRestartInput = Schema.Struct({
63 - ...TerminalThreadInput.fields,
63 + ...TerminalSessionInput.fields,
64 cwd: TrimmedNonEmptyStringSchema,
65 cols: TerminalColsSchema,
66 rows: TerminalRowsSchema,
67 env: Schema.optional(TerminalEnvSchema),
68 });
69 +export type TerminalRestartInput = Schema.Codec.Encoded<typeof TerminalRestartInput>;
70
71 export const TerminalCloseInput = Schema.Struct({
72 ...TerminalThreadInput.fields,