Skip to content

Commit 2f3f2d5

Browse files
committed
Merge remote-tracking branch 'origin/main' into high-contrast
# Conflicts: # apps/web/src/appSettings.ts
2 parents 2f69bce + ff8d87d commit 2f3f2d5

119 files changed

Lines changed: 9264 additions & 3376 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
AGENTS.md
1+
AGENTS.md

‎REMOTE.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ Use this when you want to open T3 Code from another device (phone, tablet, anoth
66

77
The T3 Code CLI accepts the following configuration options, available either as CLI flags or environment variables:
88

9-
| CLI flag | Env var | Notes |
10-
| ----------------------- | --------------------- | ---------------------------------- |
11-
| `--mode <web\|desktop>` | `T3CODE_MODE` | Runtime mode. |
12-
| `--port <number>` | `T3CODE_PORT` | HTTP/WebSocket port. |
13-
| `--host <address>` | `T3CODE_HOST` | Bind interface/address. |
14-
| `--base-dir <path>` | `T3CODE_HOME` | Base directory. |
15-
| `--dev-url <url>` | `VITE_DEV_SERVER_URL` | Dev web URL redirect/proxy target. |
16-
| `--no-browser` | `T3CODE_NO_BROWSER` | Disable auto-open browser. |
17-
| `--auth-token <token>` | `T3CODE_AUTH_TOKEN` | WebSocket auth token. |
9+
| CLI flag | Env var | Notes |
10+
| ----------------------- | --------------------- | ------------------------------------------------------------------------------------ |
11+
| `--mode <web\|desktop>` | `T3CODE_MODE` | Runtime mode. |
12+
| `--port <number>` | `T3CODE_PORT` | HTTP/WebSocket port. |
13+
| `--host <address>` | `T3CODE_HOST` | Bind interface/address. |
14+
| `--base-dir <path>` | `T3CODE_HOME` | Base directory. |
15+
| `--dev-url <url>` | `VITE_DEV_SERVER_URL` | Dev web URL redirect/proxy target. |
16+
| `--no-browser` | `T3CODE_NO_BROWSER` | Disable auto-open browser. |
17+
| `--auth-token <token>` | `T3CODE_AUTH_TOKEN` | WebSocket auth token. Use this for standard CLI and remote-server flows. |
18+
| `--bootstrap-fd <fd>` | `T3CODE_BOOTSTRAP_FD` | Read a one-shot bootstrap envelope from an inherited file descriptor during startup. |
1819

1920
> TIP: Use the `--help` flag to see all available options and their descriptions.
2021
2122
## Security First
2223

2324
- Always set `--auth-token` before exposing the server outside localhost.
25+
- When you control the process launcher, prefer sending the auth token in a JSON envelope via `--bootstrap-fd <fd>`.
26+
With `--bootstrap-fd <fd>`, the launcher starts the server first, then sends a one-shot JSON envelope over the inherited file descriptor. This allows the auth token to be delivered without putting it in process environment or command line arguments.
2427
- Treat the token like a password.
2528
- Prefer binding to trusted interfaces (LAN IP or Tailnet IP) instead of opening all interfaces unless needed.
2629

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/desktop",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"private": true,
55
"main": "dist-electron/main.js",
66
"scripts": {

‎apps/desktop/src/main.ts‎

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const UPDATE_STATE_CHANNEL = "desktop:update-state";
5656
const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";
5757
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
5858
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
59+
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
5960
const BASE_DIR = process.env.T3CODE_HOME?.trim() || Path.join(OS.homedir(), ".t3");
6061
const STATE_DIR = Path.join(BASE_DIR, "userdata");
6162
const DESKTOP_SCHEME = "t3";
@@ -113,6 +114,17 @@ function sanitizeLogValue(value: string): string {
113114
return value.replace(/\s+/g, " ").trim();
114115
}
115116

117+
function backendChildEnv(): NodeJS.ProcessEnv {
118+
const env = { ...process.env };
119+
delete env.T3CODE_PORT;
120+
delete env.T3CODE_AUTH_TOKEN;
121+
delete env.T3CODE_MODE;
122+
delete env.T3CODE_NO_BROWSER;
123+
delete env.T3CODE_HOST;
124+
delete env.T3CODE_DESKTOP_WS_URL;
125+
return env;
126+
}
127+
116128
function writeDesktopLogHeader(message: string): void {
117129
if (!desktopLogSink) return;
118130
desktopLogSink.write(`[${logTimestamp()}] [${logScope("desktop")}] ${message}\n`);
@@ -918,17 +930,6 @@ function configureAutoUpdater(): void {
918930
}, AUTO_UPDATE_POLL_INTERVAL_MS);
919931
updatePollTimer.unref();
920932
}
921-
function backendEnv(): NodeJS.ProcessEnv {
922-
return {
923-
...process.env,
924-
T3CODE_MODE: "desktop",
925-
T3CODE_NO_BROWSER: "1",
926-
T3CODE_PORT: String(backendPort),
927-
T3CODE_HOME: BASE_DIR,
928-
T3CODE_AUTH_TOKEN: backendAuthToken,
929-
};
930-
}
931-
932933
function scheduleBackendRestart(reason: string): void {
933934
if (isQuitting || restartTimer) return;
934935

@@ -952,16 +953,35 @@ function startBackend(): void {
952953
}
953954

954955
const captureBackendLogs = app.isPackaged && backendLogSink !== null;
955-
const child = ChildProcess.spawn(process.execPath, [backendEntry], {
956+
const child = ChildProcess.spawn(process.execPath, [backendEntry, "--bootstrap-fd", "3"], {
956957
cwd: resolveBackendCwd(),
957958
// In Electron main, process.execPath points to the Electron binary.
958959
// Run the child in Node mode so this backend process does not become a GUI app instance.
959960
env: {
960-
...backendEnv(),
961+
...backendChildEnv(),
961962
ELECTRON_RUN_AS_NODE: "1",
962963
},
963-
stdio: captureBackendLogs ? ["ignore", "pipe", "pipe"] : "inherit",
964+
stdio: captureBackendLogs
965+
? ["ignore", "pipe", "pipe", "pipe"]
966+
: ["ignore", "inherit", "inherit", "pipe"],
964967
});
968+
const bootstrapStream = child.stdio[3];
969+
if (bootstrapStream && "write" in bootstrapStream) {
970+
bootstrapStream.write(
971+
`${JSON.stringify({
972+
mode: "desktop",
973+
noBrowser: true,
974+
port: backendPort,
975+
t3Home: BASE_DIR,
976+
authToken: backendAuthToken,
977+
})}\n`,
978+
);
979+
bootstrapStream.end();
980+
} else {
981+
child.kill("SIGTERM");
982+
scheduleBackendRestart("missing desktop bootstrap pipe");
983+
return;
984+
}
965985
backendProcess = child;
966986
let backendSessionClosed = false;
967987
const closeBackendSession = (details: string) => {
@@ -1072,6 +1092,11 @@ async function stopBackendAndWaitForExit(timeoutMs = 5_000): Promise<void> {
10721092
}
10731093

10741094
function registerIpcHandlers(): void {
1095+
ipcMain.removeAllListeners(GET_WS_URL_CHANNEL);
1096+
ipcMain.on(GET_WS_URL_CHANNEL, (event) => {
1097+
event.returnValue = backendWsUrl;
1098+
});
1099+
10751100
ipcMain.removeHandler(PICK_FOLDER_CHANNEL);
10761101
ipcMain.handle(PICK_FOLDER_CHANNEL, async () => {
10771102
const owner = BrowserWindow.getFocusedWindow() ?? mainWindow;
@@ -1320,9 +1345,9 @@ async function bootstrap(): Promise<void> {
13201345
);
13211346
writeDesktopLogHeader(`reserved backend port via NetService port=${backendPort}`);
13221347
backendAuthToken = Crypto.randomBytes(24).toString("hex");
1323-
backendWsUrl = `ws://127.0.0.1:${backendPort}/?token=${encodeURIComponent(backendAuthToken)}`;
1324-
process.env.T3CODE_DESKTOP_WS_URL = backendWsUrl;
1325-
writeDesktopLogHeader(`bootstrap resolved websocket url=${backendWsUrl}`);
1348+
const baseUrl = `ws://127.0.0.1:${backendPort}`;
1349+
backendWsUrl = `${baseUrl}/?token=${encodeURIComponent(backendAuthToken)}`;
1350+
writeDesktopLogHeader(`bootstrap resolved websocket endpoint baseUrl=${baseUrl}`);
13261351

13271352
registerIpcHandlers();
13281353
writeDesktopLogHeader("bootstrap ipc handlers registered");

‎apps/desktop/src/preload.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ const UPDATE_STATE_CHANNEL = "desktop:update-state";
1111
const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";
1212
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
1313
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
14-
const wsUrl = process.env.T3CODE_DESKTOP_WS_URL ?? null;
14+
const GET_WS_URL_CHANNEL = "desktop:get-ws-url";
1515

1616
contextBridge.exposeInMainWorld("desktopBridge", {
17-
getWsUrl: () => wsUrl,
17+
getWsUrl: () => {
18+
const result = ipcRenderer.sendSync(GET_WS_URL_CHANNEL);
19+
return typeof result === "string" ? result : null;
20+
},
1821
pickFolder: () => ipcRenderer.invoke(PICK_FOLDER_CHANNEL),
1922
confirm: (message) => ipcRenderer.invoke(CONFIRM_CHANNEL, message),
2023
setTheme: (theme) => ipcRenderer.invoke(SET_THEME_CHANNEL, theme),

‎apps/server/integration/orchestrationEngine.integration.test.ts‎

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ProjectId,
1212
ProviderKind,
1313
ThreadId,
14+
ModelSelection,
1415
} from "@t3tools/contracts";
1516
import { assert, it } from "@effect/vitest";
1617
import { Effect, Option, Schema } from "effect";
@@ -115,7 +116,10 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
115116
projectId: PROJECT_ID,
116117
title: "Integration Project",
117118
workspaceRoot: harness.workspaceDir,
118-
defaultModel,
119+
defaultModelSelection: {
120+
provider,
121+
model: defaultModel,
122+
},
119123
createdAt,
120124
});
121125

@@ -125,7 +129,10 @@ const seedProjectAndThread = (harness: OrchestrationIntegrationHarness) =>
125129
threadId: THREAD_ID,
126130
projectId: PROJECT_ID,
127131
title: "Integration Thread",
128-
model: defaultModel,
132+
modelSelection: {
133+
provider,
134+
model: defaultModel,
135+
},
129136
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
130137
runtimeMode: "approval-required",
131138
branch: null,
@@ -139,7 +146,7 @@ const startTurn = (input: {
139146
readonly commandId: string;
140147
readonly messageId: string;
141148
readonly text: string;
142-
readonly provider?: IntegrationProvider;
149+
readonly modelSelection?: ModelSelection;
143150
}) =>
144151
input.harness.engine.dispatch({
145152
type: "thread.turn.start",
@@ -151,7 +158,11 @@ const startTurn = (input: {
151158
text: input.text,
152159
attachments: [],
153160
},
154-
...(input.provider !== undefined ? { provider: input.provider } : {}),
161+
...(input.modelSelection !== undefined
162+
? {
163+
modelSelection: input.modelSelection,
164+
}
165+
: {}),
155166
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
156167
runtimeMode: "approval-required",
157168
createdAt: nowIso(),
@@ -254,7 +265,10 @@ it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
254265
projectId: PROJECT_ID,
255266
title: "Integration Project",
256267
workspaceRoot: harness.workspaceDir,
257-
defaultModel: "gpt-5.3-codex",
268+
defaultModelSelection: {
269+
provider: "codex",
270+
model: "gpt-5.3-codex",
271+
},
258272
createdAt,
259273
});
260274

@@ -264,7 +278,10 @@ it.live.skipIf(!process.env.CODEX_BINARY_PATH)(
264278
threadId: THREAD_ID,
265279
projectId: PROJECT_ID,
266280
title: "Integration Thread",
267-
model: "gpt-5.3-codex",
281+
modelSelection: {
282+
provider: "codex",
283+
model: "gpt-5.3-codex",
284+
},
268285
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
269286
runtimeMode: "full-access",
270287
branch: null,
@@ -922,7 +939,10 @@ it.live("starts a claudeAgent session on first turn when provider is requested",
922939
commandId: "cmd-turn-start-claude-initial",
923940
messageId: "msg-user-claude-initial",
924941
text: "Use Claude",
925-
provider: "claudeAgent",
942+
modelSelection: {
943+
provider: "claudeAgent",
944+
model: "claude-sonnet-4-6",
945+
},
926946
});
927947

928948
const thread = yield* harness.waitForThread(
@@ -976,7 +996,10 @@ it.live("recovers claudeAgent sessions after provider stopAll using persisted re
976996
commandId: "cmd-turn-start-claude-recover-1",
977997
messageId: "msg-user-claude-recover-1",
978998
text: "Before restart",
979-
provider: "claudeAgent",
999+
modelSelection: {
1000+
provider: "claudeAgent",
1001+
model: "claude-sonnet-4-6",
1002+
},
9801003
});
9811004

9821005
yield* harness.waitForThread(
@@ -1083,7 +1106,10 @@ it.live("forwards claudeAgent approval responses to the provider session", () =>
10831106
commandId: "cmd-turn-start-claude-approval",
10841107
messageId: "msg-user-claude-approval",
10851108
text: "Need approval",
1086-
provider: "claudeAgent",
1109+
modelSelection: {
1110+
provider: "claudeAgent",
1111+
model: "claude-sonnet-4-6",
1112+
},
10871113
});
10881114

10891115
const thread = yield* harness.waitForThread(THREAD_ID, (entry) =>
@@ -1152,7 +1178,10 @@ it.live("forwards thread.turn.interrupt to claudeAgent provider sessions", () =>
11521178
commandId: "cmd-turn-start-claude-interrupt",
11531179
messageId: "msg-user-claude-interrupt",
11541180
text: "Start long turn",
1155-
provider: "claudeAgent",
1181+
modelSelection: {
1182+
provider: "claudeAgent",
1183+
model: "claude-sonnet-4-6",
1184+
},
11561185
});
11571186

11581187
const thread = yield* harness.waitForThread(
@@ -1222,7 +1251,10 @@ it.live("reverts claudeAgent turns and rolls back provider conversation state",
12221251
commandId: "cmd-turn-start-claude-revert-1",
12231252
messageId: "msg-user-claude-revert-1",
12241253
text: "First Claude edit",
1225-
provider: "claudeAgent",
1254+
modelSelection: {
1255+
provider: "claudeAgent",
1256+
model: "claude-sonnet-4-6",
1257+
},
12261258
});
12271259

12281260
yield* harness.waitForThread(

‎apps/server/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "t3",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"license": "MIT",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)