@devries-cameron20 / t3code Mirror · read-only / commits / 0c4c027e92
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 17:15 UTC

small config change

Julius Marminge committed Feb 25, 2026 at 20:21 UTC 0c4c027e92bae27716d94d14e3531c390d9ecef1
5 files changed +99 -60
apps/server/src/config.ts
+2
@@ -16,6 +16,8 @@ export interface ServerConfigShape {
16 readonly devUrl: URL | undefined;
17 readonly noBrowser: boolean;
18 readonly authToken: string | undefined;
19 + readonly autoBootstrapProjectFromCwd: boolean;
20 + readonly logWebSocketEvents: boolean;
21 }
22
23 export class ServerConfig extends ServiceMap.Service<ServerConfig, ServerConfigShape>()(
apps/server/src/main.test.ts
+36 -33
@@ -10,20 +10,18 @@ import { beforeEach } from "vitest";
10 import { CliConfig, t3Cli, type CliConfigShape } from "./main";
11 import { NetService, ServerConfig, type ServerConfigShape } from "./config";
12 import { Open, type OpenShape } from "./open";
13 -import { Server, type ServerShape, type ServerOptions } from "./wsServer";
13 +import { Server, type ServerShape } from "./wsServer";
14
15 const start = vi.fn(() => undefined);
16 const stop = vi.fn(() => undefined);
17 let resolvedConfig: ServerConfigShape | null = null;
18 -const createServer = vi.fn((_: ServerOptions | undefined) =>
19 - Effect.acquireRelease(
20 - Effect.gen(function* () {
21 - resolvedConfig = yield* ServerConfig;
22 - start();
23 - return {} as unknown as Http.Server;
24 - }),
25 - () => Effect.sync(() => stop()),
26 - ),
18 +const serverStart = Effect.acquireRelease(
19 + Effect.gen(function* () {
20 + resolvedConfig = yield* ServerConfig;
21 + start();
22 + return {} as unknown as Http.Server;
23 + }),
24 + () => Effect.sync(() => stop()),
25 );
26 const findAvailablePort = vi.fn((preferred: number) => Effect.succeed(preferred));
27
@@ -37,7 +35,7 @@ const testLayer = Layer.mergeAll(
35 findAvailablePort,
36 }),
37 Layer.succeed(Server, {
40 - createServer,
38 + start: serverStart,
39 stopSignal: Effect.void,
40 } satisfies ServerShape),
41 Layer.succeed(Open, {
@@ -60,16 +58,6 @@ beforeEach(() => {
58 resolvedConfig = null;
59 start.mockImplementation(() => undefined);
60 stop.mockImplementation(() => undefined);
63 - createServer.mockImplementation((_: ServerOptions | undefined) =>
64 - Effect.acquireRelease(
65 - Effect.gen(function* () {
66 - resolvedConfig = yield* ServerConfig;
67 - start();
68 - return {} as unknown as Http.Server;
69 - }),
70 - () => Effect.sync(() => stop()),
71 - ),
72 - );
61 findAvailablePort.mockImplementation((preferred: number) => Effect.succeed(preferred));
62 });
63
@@ -92,7 +80,7 @@ it.layer(testLayer)("server cli", (it) => {
80 "auth-secret",
81 ]);
82
95 - assert.equal(createServer.mock.calls.length, 1);
83 + assert.equal(start.mock.calls.length, 1);
84 assert.equal(resolvedConfig?.mode, "desktop");
85 assert.equal(resolvedConfig?.port, 4010);
86 assert.equal(resolvedConfig?.host, "0.0.0.0");
@@ -100,7 +88,8 @@ it.layer(testLayer)("server cli", (it) => {
88 assert.equal(resolvedConfig?.devUrl?.toString(), "http://127.0.0.1:5173/");
89 assert.equal(resolvedConfig?.noBrowser, true);
90 assert.equal(resolvedConfig?.authToken, "auth-secret");
103 - assert.equal(start.mock.calls.length, 1);
91 + assert.equal(resolvedConfig?.autoBootstrapProjectFromCwd, false);
92 + assert.equal(resolvedConfig?.logWebSocketEvents, true);
93 assert.equal(stop.mock.calls.length, 1);
94 }),
95 );
@@ -109,7 +98,7 @@ it.layer(testLayer)("server cli", (it) => {
98 Effect.gen(function* () {
99 yield* runCli(["--token", "token-secret"]);
100
112 - assert.equal(createServer.mock.calls.length, 1);
101 + assert.equal(start.mock.calls.length, 1);
102 assert.equal(resolvedConfig?.authToken, "token-secret");
103 }),
104 );
@@ -126,7 +115,7 @@ it.layer(testLayer)("server cli", (it) => {
115 T3CODE_AUTH_TOKEN: "env-token",
116 });
117
129 - assert.equal(createServer.mock.calls.length, 1);
118 + assert.equal(start.mock.calls.length, 1);
119 assert.equal(resolvedConfig?.mode, "desktop");
120 assert.equal(resolvedConfig?.port, 4999);
121 assert.equal(resolvedConfig?.host, "100.88.10.4");
@@ -134,6 +123,8 @@ it.layer(testLayer)("server cli", (it) => {
123 assert.equal(resolvedConfig?.devUrl?.toString(), "http://localhost:5173/");
124 assert.equal(resolvedConfig?.noBrowser, true);
125 assert.equal(resolvedConfig?.authToken, "env-token");
126 + assert.equal(resolvedConfig?.autoBootstrapProjectFromCwd, false);
127 + assert.equal(resolvedConfig?.logWebSocketEvents, true);
128 assert.equal(findAvailablePort.mock.calls.length, 0);
129 }),
130 );
@@ -147,7 +138,7 @@ it.layer(testLayer)("server cli", (it) => {
138 });
139
140 assert.deepStrictEqual(findAvailablePort.mock.calls, [[3773]]);
150 - assert.equal(createServer.mock.calls.length, 1);
141 + assert.equal(start.mock.calls.length, 1);
142 assert.equal(resolvedConfig?.mode, "web");
143 assert.equal(resolvedConfig?.port, 4666);
144 assert.equal(resolvedConfig?.host, undefined);
@@ -160,7 +151,7 @@ it.layer(testLayer)("server cli", (it) => {
151 T3CODE_NO_BROWSER: "false",
152 });
153
163 - assert.equal(createServer.mock.calls.length, 1);
154 + assert.equal(start.mock.calls.length, 1);
155 assert.equal(resolvedConfig?.noBrowser, true);
156 }),
157 );
@@ -171,7 +162,7 @@ it.layer(testLayer)("server cli", (it) => {
162 yield* runCli([]);
163
164 assert.deepStrictEqual(findAvailablePort.mock.calls, [[3773]]);
174 - assert.equal(createServer.mock.calls.length, 1);
165 + assert.equal(start.mock.calls.length, 1);
166 assert.equal(resolvedConfig?.port, 5444);
167 assert.equal(resolvedConfig?.mode, "web");
168 }),
@@ -185,7 +176,7 @@ it.layer(testLayer)("server cli", (it) => {
176 });
177
178 assert.equal(findAvailablePort.mock.calls.length, 0);
188 - assert.equal(createServer.mock.calls.length, 1);
179 + assert.equal(start.mock.calls.length, 1);
180 assert.equal(resolvedConfig?.port, 3773);
181 assert.equal(resolvedConfig?.host, "127.0.0.1");
182 assert.equal(resolvedConfig?.mode, "desktop");
@@ -199,17 +190,31 @@ it.layer(testLayer)("server cli", (it) => {
190 T3CODE_NO_BROWSER: "true",
191 });
192
202 - assert.equal(createServer.mock.calls.length, 1);
193 + assert.equal(start.mock.calls.length, 1);
194 assert.equal(resolvedConfig?.mode, "desktop");
195 assert.equal(resolvedConfig?.host, "0.0.0.0");
196 }),
197 );
198
199 + it.effect("supports CLI and env for bootstrap/log websocket toggles", () =>
200 + Effect.gen(function* () {
201 + yield* runCli(["--auto-bootstrap-project-from-cwd"], {
202 + T3CODE_MODE: "desktop",
203 + T3CODE_LOG_WS_EVENTS: "false",
204 + T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "false",
205 + T3CODE_NO_BROWSER: "true",
206 + });
207 +
208 + assert.equal(start.mock.calls.length, 1);
209 + assert.equal(resolvedConfig?.autoBootstrapProjectFromCwd, true);
210 + assert.equal(resolvedConfig?.logWebSocketEvents, false);
211 + }),
212 + );
213 +
214 it.effect("does not start server for invalid --mode values", () =>
215 Effect.gen(function* () {
216 yield* runCli(["--mode", "invalid"]);
217
212 - assert.equal(createServer.mock.calls.length, 0);
218 assert.equal(start.mock.calls.length, 0);
219 assert.equal(stop.mock.calls.length, 0);
220 }),
@@ -219,7 +224,6 @@ it.layer(testLayer)("server cli", (it) => {
224 Effect.gen(function* () {
225 yield* runCli(["--dev-url", "not-a-url"]).pipe(Effect.catch(() => Effect.void));
226
222 - assert.equal(createServer.mock.calls.length, 0);
227 assert.equal(start.mock.calls.length, 0);
228 assert.equal(stop.mock.calls.length, 0);
229 }),
@@ -230,7 +234,6 @@ it.layer(testLayer)("server cli", (it) => {
234 yield* runCli(["--port", "70000"]);
235
236 // effect/unstable/cli renders help/errors for parse failures and returns success.
233 - assert.equal(createServer.mock.calls.length, 0);
237 assert.equal(start.mock.calls.length, 0);
238 assert.equal(stop.mock.calls.length, 0);
239 }),
apps/server/src/main.ts
+41 -2
@@ -28,6 +28,8 @@ interface CliInput {
28 readonly devUrl: Option.Option<URL>;
29 readonly noBrowser: Option.Option<boolean>;
30 readonly authToken: Option.Option<string>;
31 + readonly autoBootstrapProjectFromCwd: Option.Option<boolean>;
32 + readonly logWebSocketEvents: Option.Option<boolean>;
33 }
34
35 export interface CliConfigShape {
@@ -79,6 +81,14 @@ const CliEnvConfig = Config.all({
81 Config.option,
82 Config.map(Option.getOrUndefined),
83 ),
84 + autoBootstrapProjectFromCwd: Config.boolean("T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD").pipe(
85 + Config.option,
86 + Config.map(Option.getOrUndefined),
87 + ),
88 + logWebSocketEvents: Config.boolean("T3CODE_LOG_WS_EVENTS").pipe(
89 + Config.option,
90 + Config.map(Option.getOrUndefined),
91 + ),
92 });
93
94 const ServerConfigLive = (input: CliInput) =>
@@ -119,6 +129,18 @@ const ServerConfigLive = (input: CliInput) =>
129 onNone: () => env.noBrowser ?? mode === "desktop",
130 });
131 const authToken = Option.getOrUndefined(input.authToken) ?? env.authToken;
132 + const autoBootstrapProjectFromCwd = Option.match(input.autoBootstrapProjectFromCwd, {
133 + // effect/cli boolean flags parse to `false` when absent; in that case
134 + // we still want env/mode fallbacks to apply.
135 + onSome: (value) => (value ? true : (env.autoBootstrapProjectFromCwd ?? mode === "web")),
136 + onNone: () => env.autoBootstrapProjectFromCwd ?? mode === "web",
137 + });
138 + const logWebSocketEvents = Option.match(input.logWebSocketEvents, {
139 + // effect/cli boolean flags parse to `false` when absent; in that case
140 + // we still want env/dev fallbacks to apply.
141 + onSome: (value) => (value ? true : (env.logWebSocketEvents ?? Boolean(devUrl))),
142 + onNone: () => env.logWebSocketEvents ?? Boolean(devUrl),
143 + });
144 const staticDir = devUrl ? undefined : yield* cliConfig.resolveStaticDir;
145 const { join } = yield* Path.Path;
146 const keybindingsConfigPath = join(stateDir, "keybindings.json");
@@ -138,6 +160,8 @@ const ServerConfigLive = (input: CliInput) =>
160 devUrl,
161 noBrowser,
162 authToken,
163 + autoBootstrapProjectFromCwd,
164 + logWebSocketEvents,
165 } satisfies ServerConfigShape;
166 }),
167 );
@@ -159,7 +183,7 @@ const formatHostForUrl = (host: string): string =>
183 const makeServerProgram = (input: CliInput) =>
184 Effect.gen(function* () {
185 const cliConfig = yield* CliConfig;
162 - const { createServer, stopSignal } = yield* Server;
186 + const { start, stopSignal } = yield* Server;
187 const openDeps = yield* Open;
188 yield* cliConfig.fixPath;
189
@@ -174,7 +198,7 @@ const makeServerProgram = (input: CliInput) =>
198 );
199 }
200
177 - yield* createServer();
201 + yield* start;
202
203 const localUrl = `http://localhost:${config.port}`;
204 const bindUrl =
@@ -240,6 +264,19 @@ const authTokenFlag = Flag.string("auth-token").pipe(
264 Flag.withAlias("token"),
265 Flag.optional,
266 );
267 +const autoBootstrapProjectFromCwdFlag = Flag.boolean("auto-bootstrap-project-from-cwd").pipe(
268 + Flag.withDescription(
269 + "Create a project for the current working directory on startup when missing.",
270 + ),
271 + Flag.optional,
272 +);
273 +const logWebSocketEventsFlag = Flag.boolean("log-websocket-events").pipe(
274 + Flag.withDescription(
275 + "Emit server-side logs for outbound WebSocket push traffic (equivalent to T3CODE_LOG_WS_EVENTS).",
276 + ),
277 + Flag.withAlias("log-ws-events"),
278 + Flag.optional,
279 +);
280
281 export const t3Cli = Command.make("t3", {
282 mode: modeFlag,
@@ -249,6 +286,8 @@ export const t3Cli = Command.make("t3", {
286 devUrl: devUrlFlag,
287 noBrowser: noBrowserFlag,
288 authToken: authTokenFlag,
289 + autoBootstrapProjectFromCwd: autoBootstrapProjectFromCwdFlag,
290 + logWebSocketEvents: logWebSocketEventsFlag,
291 }).pipe(
292 Command.withDescription("Run the T3 Code server."),
293 Command.withHandler((input) => Effect.scoped(makeServerProgram(input))),
apps/server/src/wsServer.test.ts
+4 -3
@@ -338,6 +338,7 @@ describe("WebSocket Server", () => {
338 persistenceLayer?: Layer.Layer<SqlClient.SqlClient, any>;
339 cwd?: string;
340 autoBootstrapProjectFromCwd?: boolean;
341 + logWebSocketEvents?: boolean;
342 devUrl?: string;
343 authToken?: string;
344 stateDir?: string;
@@ -368,6 +369,8 @@ describe("WebSocket Server", () => {
369 devUrl: options.devUrl ? new URL(options.devUrl) : undefined,
370 noBrowser: true,
371 authToken: options.authToken,
372 + autoBootstrapProjectFromCwd: options.autoBootstrapProjectFromCwd ?? false,
373 + logWebSocketEvents: options.logWebSocketEvents ?? Boolean(options.devUrl),
374 } satisfies ServerConfigShape);
375 const infrastructureLayer = providerLayer.pipe(Layer.provideMerge(persistenceLayer));
376 const runtimeOverrides = Layer.mergeAll(
@@ -397,9 +400,7 @@ describe("WebSocket Server", () => {
400
401 try {
402 const runtime = await Effect.runPromise(
400 - createServer({
401 - autoBootstrapProjectFromCwd: options.autoBootstrapProjectFromCwd ?? false,
402 - }).pipe(Effect.provide(runtimeServices), Scope.provide(scope)),
403 + createServer().pipe(Effect.provide(runtimeServices), Scope.provide(scope)),
404 );
405 serverScope = scope;
406 return runtime;
apps/server/src/wsServer.ts
+16 -22
@@ -49,15 +49,12 @@ const MIME_TYPES: Record<string, string> = {
49 ".map": "application/json",
50 };
51
52 -export interface ServerOptions {
53 - autoBootstrapProjectFromCwd?: boolean | undefined;
54 - logWebSocketEvents?: boolean | undefined;
55 -}
56 -
52 export interface ServerShape {
58 - readonly createServer: (
59 - options?: ServerOptions,
60 - ) => Effect.Effect<http.Server, unknown, Scope.Scope | ServerRuntimeServices | ServerConfig>;
53 + readonly start: Effect.Effect<
54 + http.Server,
55 + unknown,
56 + Scope.Scope | ServerRuntimeServices | ServerConfig
57 + >;
58 readonly stopSignal: Effect.Effect<unknown, never>;
59 }
60
@@ -82,14 +79,6 @@ function rejectUpgrade(socket: Duplex, statusCode: number, message: string): voi
79 );
80 }
81
85 -function parseBooleanEnv(value: string | undefined): boolean | undefined {
86 - if (value === undefined) return undefined;
87 - const normalized = value.trim().toLowerCase();
88 - if (["1", "true", "yes", "on"].includes(normalized)) return true;
89 - if (["0", "false", "no", "off"].includes(normalized)) return false;
90 - return undefined;
91 -}
92 -
82 function websocketRawToString(raw: unknown): string | null {
83 if (typeof raw === "string") {
84 return raw;
@@ -153,17 +142,22 @@ class RouteRequestError extends Schema.TaggedErrorClass<RouteRequestError>()("Ro
142 message: Schema.String,
143 }) {}
144
156 -export const createServer = Effect.fn(function* (options: ServerOptions = {}): Effect.fn.Return<
145 +export const createServer = Effect.fn(function* (): Effect.fn.Return<
146 http.Server,
147 unknown, // TODO: This should not be unknown
148 Scope.Scope | ServerRuntimeServices | ServerConfig
149 > {
150 const serverConfig = yield* ServerConfig;
162 - const { port, cwd, staticDir, devUrl, authToken, mode, host } = serverConfig;
151 const {
164 - logWebSocketEvents = parseBooleanEnv(process.env.T3CODE_LOG_WS_EVENTS) ?? Boolean(devUrl),
165 - autoBootstrapProjectFromCwd = mode === "web",
166 - } = options;
152 + port,
153 + cwd,
154 + staticDir,
155 + devUrl,
156 + authToken,
157 + host,
158 + logWebSocketEvents,
159 + autoBootstrapProjectFromCwd,
160 + } = serverConfig;
161
162 const gitManager = yield* GitManager;
163 const terminalManager = yield* TerminalManager;
@@ -599,6 +593,6 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E
593 });
594
595 export const ServerLive = Layer.succeed(Server, {
602 - createServer,
596 + start: createServer(),
597 stopSignal: Effect.never,
598 } satisfies ServerShape);