This commit is contained in:
Theo Browne committed 2026-02-09 22:19:49 -08:00
1 parent b5bab3eb13
commit 5120f7fec7
38 files changed
+56 -56

No files matched your search

+2 -2
View File
@@ -14,7 +14,7 @@ If a tradeoff is required, choose correctness and robustness over short-term con
## Package Roles
- `apps/server`: Node.js WebSocket server. Wraps Codex app-server (JSON-RPC over stdio), serves the React web app, and manages provider sessions.
- `apps/renderer`: React/Vite UI. Owns session UX, conversation/event rendering, and client-side state. Connects to the server via WebSocket.
- `apps/web`: React/Vite UI. Owns session UX, conversation/event rendering, and client-side state. Connects to the server via WebSocket.
- `packages/contracts`: Shared Zod schemas and TypeScript contracts for provider events, WebSocket protocol, and model/session types.
## Codex App Server (Important)
@@ -24,7 +24,7 @@ How we use it in this codebase:
- Session startup/resume and turn lifecycle are brokered in `apps/server/src/codexAppServerManager.ts`.
- Provider dispatch and thread event logging are coordinated in `apps/server/src/providerManager.ts`.
- WebSocket server routes NativeApi methods in `apps/server/src/wsServer.ts`.
- Renderer consumes provider event streams via WebSocket push on channel `providers.event`.
- Web app consumes provider event streams via WebSocket push on channel `providers.event`.
Docs:
- Codex App Server docs: https://developers.openai.com/codex/sdk/#app-server
+7 -7
View File
@@ -29,9 +29,9 @@ T3 Code runs as a **Node.js WebSocket server** that wraps `codex app-server` (JS
## Workspace layout
- `/apps/server`: Node.js WebSocket server. Wraps Codex app-server, serves the built renderer, and opens the browser on start.
- `/apps/renderer`: React + Vite UI. Session control, conversation, and provider event rendering. Connects to the server via WebSocket.
- `/apps/desktop`: Electron shell. Spawns a desktop-scoped `t3` backend process and loads the shared renderer.
- `/apps/server`: Node.js WebSocket server. Wraps Codex app-server, serves the built web app, and opens the browser on start.
- `/apps/web`: React + Vite UI. Session control, conversation, and provider event rendering. Connects to the server via WebSocket.
- `/apps/desktop`: Electron shell. Spawns a desktop-scoped `t3` backend process and loads the shared web app.
- `/packages/contracts`: Shared Zod schemas and TypeScript contracts for provider events, WebSocket protocol, and model/session types.
## Codex prerequisites
@@ -61,9 +61,9 @@ npx t3
- `bun run dev` — Starts contracts, server, and web dev tasks via Turborepo's parallel task runner.
- `bun run dev:server` — Starts just the WebSocket server (uses tsx for TS execution).
- `bun run dev:web` — Starts just the Vite dev server for the renderer.
- `bun run start` — Runs the production server (serves built renderer as static files).
- `bun run build` — Builds contracts, renderer, and server through Turbo.
- `bun run dev:web` — Starts just the Vite dev server for the web app.
- `bun run start` — Runs the production server (serves built web app as static files).
- `bun run build` — Builds contracts, web app, and server through Turbo.
- `bun run typecheck` — Strict TypeScript checks for all packages.
- `bun run test` — Runs workspace tests.
@@ -76,7 +76,7 @@ T3 Code has a global runtime mode switch in the chat toolbar:
## Provider architecture
The renderer communicates with the server via WebSocket using a simple JSON-RPC-style protocol:
The web app communicates with the server via WebSocket using a simple JSON-RPC-style protocol:
- **Request/Response**: `{ id, method, params }` → `{ id, result }` or `{ id, error }`
- **Push events**: `{ type: "push", channel, data }` for streaming provider events
+1 -1
View File
@@ -4,7 +4,7 @@
"private": true,
"main": "dist-electron/main.js",
"scripts": {
"dev": "bun run --cwd ../server build && concurrently -k -n BUNDLE,RENDERER,ELECTRON \"bun run dev:bundle\" \"bun run --cwd ../renderer dev\" \"bun run dev:electron\"",
"dev": "bun run --cwd ../server build && concurrently -k -n BUNDLE,WEB,ELECTRON \"bun run dev:bundle\" \"bun run --cwd ../web dev\" \"bun run dev:electron\"",
"dev:bundle": "tsup --watch",
"dev:electron": "bun run scripts/dev-electron.mjs",
"build": "tsup",
+1 -1
View File
@@ -8,7 +8,7 @@ const rootDir = resolve(__dirname, "../../..");
const electronBin = resolve(desktopDir, "node_modules/.bin/electron");
const mainJs = resolve(desktopDir, "dist-electron/main.js");
console.log("Building contracts + renderer + server + desktop...");
console.log("Building contracts + web + server + desktop...");
execSync("bun run build", { cwd: rootDir, stdio: "inherit" });
console.log("\nLaunching Electron smoke test...");
+4 -4
View File
@@ -14,7 +14,7 @@ fixPath();
const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
const ROOT_DIR = path.resolve(__dirname, "../../..");
const BACKEND_ENTRY = path.join(ROOT_DIR, "apps/server/dist/index.js");
const RENDERER_ENTRY = path.join(ROOT_DIR, "apps/renderer/dist/index.html");
const WEB_ENTRY = path.join(ROOT_DIR, "apps/web/dist/index.html");
const STATE_DIR = path.join(os.homedir(), ".t3", "userdata");
const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
@@ -167,10 +167,10 @@ function createWindow(): BrowserWindow {
if (isDevelopment) {
void window.loadURL(process.env.VITE_DEV_SERVER_URL as string);
} else {
if (!fs.existsSync(RENDERER_ENTRY)) {
throw new Error(`Renderer bundle missing at ${RENDERER_ENTRY}`);
if (!fs.existsSync(WEB_ENTRY)) {
throw new Error(`Web bundle missing at ${WEB_ENTRY}`);
}
void window.loadFile(RENDERER_ENTRY);
void window.loadFile(WEB_ENTRY);
}
window.on("closed", () => {
+1 -1
View File
@@ -24,7 +24,7 @@
},
"devDependencies": {
"@t3tools/contracts": "workspace:*",
"@t3tools/renderer": "workspace:*",
"@t3tools/web": "workspace:*",
"@types/node": "^22.10.2",
"@types/ws": "^8.5.13",
"tsup": "^8.3.5",
+6 -6
View File
@@ -1,5 +1,5 @@
/**
* Copies the built renderer into dist/client/ so the published npm package
* Copies the built web app into dist/client/ so the published npm package
* includes the web UI. This runs as a post-build step.
*/
import fs from "node:fs";
@@ -7,15 +7,15 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rendererDist = path.resolve(__dirname, "../../renderer/dist");
const webDist = path.resolve(__dirname, "../../web/dist");
const target = path.resolve(__dirname, "../dist/client");
if (!fs.existsSync(rendererDist)) {
if (!fs.existsSync(webDist)) {
console.log(
"⚠ Renderer dist not found — skipping client bundle. Run `bun run --cwd apps/renderer build` first.",
"⚠ Web dist not found — skipping client bundle. Run `bun run --cwd apps/web build` first.",
);
process.exit(0);
}
fs.cpSync(rendererDist, target, { recursive: true });
console.log("✓ Bundled renderer into dist/client");
fs.cpSync(webDist, target, { recursive: true });
console.log("✓ Bundled web app into dist/client");
+4 -4
View File
@@ -84,8 +84,8 @@ function resolveStaticDir(): string | undefined {
// Not bundled — check monorepo layout
}
// Monorepo layout: apps/server/dist/index.js → apps/renderer/dist/
const monorepoClient = path.resolve(__dirname, "../../renderer/dist");
// Monorepo layout: apps/server/dist/index.js → apps/web/dist/
const monorepoClient = path.resolve(__dirname, "../../web/dist");
try {
const stat = fs.statSync(path.join(monorepoClient, "index.html"));
if (stat.isFile()) return monorepoClient;
@@ -109,8 +109,8 @@ async function main() {
const staticDir = devUrl ? undefined : resolveStaticDir();
if (!devUrl && !staticDir) {
logger.warn("renderer bundle missing and no VITE_DEV_SERVER_URL; web UI unavailable", {
hint: "Run `bun run --cwd apps/renderer build` or set VITE_DEV_SERVER_URL for dev mode.",
logger.warn("web bundle missing and no VITE_DEV_SERVER_URL; web UI unavailable", {
hint: "Run `bun run --cwd apps/web build` or set VITE_DEV_SERVER_URL for dev mode.",
});
}
+1 -1
View File
@@ -109,7 +109,7 @@ export function createServer(options: ServerOptions) {
return;
}
// Serve static files from the renderer build
// Serve static files from the web app build
if (!staticDir) {
res.writeHead(503, { "Content-Type": "text/plain" });
res.end("No static directory configured and no dev URL set.");
File renamed without changes.
@@ -1,5 +1,5 @@
{
"name": "@t3tools/renderer",
"name": "@t3tools/web",
"version": "0.0.0",
"private": true,
"type": "module",
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
/**
* True when running inside the Electron preload bridge, false in a regular browser.
* The preload script sets window.nativeApi via contextBridge before any renderer
* The preload script sets window.nativeApi via contextBridge before any web-app
* code executes, so this is reliable at module load time.
*/
export const isElectron =
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -12,7 +12,7 @@ export default defineConfig({
tailwindcss(),
],
define: {
// In dev mode, tell the renderer where the WebSocket server lives
// In dev mode, tell the web app where the WebSocket server lives
"import.meta.env.VITE_WS_URL": JSON.stringify(
process.env.VITE_WS_URL ?? "",
),
+23 -23
View File
@@ -28,8 +28,28 @@
"wait-on": "^8.0.2",
},
},
"apps/renderer": {
"name": "@t3tools/renderer",
"apps/server": {
"name": "t3",
"version": "0.1.0",
"bin": {
"t3": "./dist/index.js",
},
"dependencies": {
"open": "^10.1.0",
"ws": "^8.18.0",
},
"devDependencies": {
"@t3tools/contracts": "workspace:*",
"@t3tools/web": "workspace:*",
"@types/node": "^22.10.2",
"@types/ws": "^8.5.13",
"tsup": "^8.3.5",
"tsx": "^4.19.0",
"typescript": "^5.7.3",
},
},
"apps/web": {
"name": "@t3tools/web",
"version": "0.0.0",
"dependencies": {
"@t3tools/contracts": "workspace:*",
@@ -53,26 +73,6 @@
"vite": "^6.0.5",
},
},
"apps/server": {
"name": "t3",
"version": "0.1.0",
"bin": {
"t3": "./dist/index.js",
},
"dependencies": {
"open": "^10.1.0",
"ws": "^8.18.0",
},
"devDependencies": {
"@t3tools/contracts": "workspace:*",
"@t3tools/renderer": "workspace:*",
"@types/node": "^22.10.2",
"@types/ws": "^8.5.13",
"tsup": "^8.3.5",
"tsx": "^4.19.0",
"typescript": "^5.7.3",
},
},
"packages/contracts": {
"name": "@t3tools/contracts",
"version": "0.0.0",
@@ -294,7 +294,7 @@
"@t3tools/desktop": ["@t3tools/desktop@workspace:apps/desktop"],
"@t3tools/renderer": ["@t3tools/renderer@workspace:apps/renderer"],
"@t3tools/web": ["@t3tools/web@workspace:apps/web"],
"@tailwindcss/node": ["@tailwindcss/[email protected]", "", { "dependencies": { "@jridgewell/remapping": "^2.3.4", "enhanced-resolve": "^5.18.3", "jiti": "^2.6.1", "lightningcss": "1.30.2", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.1.18" } }, "sha512-DoR7U1P7iYhw16qJ49fgXUlry1t4CpXeErJHnQ44JgTSKMaZUdf17cfn5mHchfJ4KRBZRFA/Coo+MUF5+gOaCQ=="],
+3 -3
View File
@@ -6,14 +6,14 @@
"packages/*"
],
"scripts": {
"dev": "T3CODE_LOG_WS_EVENTS=1 VITE_WS_URL=ws://localhost:3773 turbo run dev --ui=tui --filter=@t3tools/contracts --filter=@t3tools/renderer --filter=t3 --parallel",
"dev": "T3CODE_LOG_WS_EVENTS=1 VITE_WS_URL=ws://localhost:3773 turbo run dev --ui=tui --filter=@t3tools/contracts --filter=@t3tools/web --filter=t3 --parallel",
"dev:server": "bun run build:contracts && bun run --cwd apps/server dev",
"dev:web": "VITE_WS_URL=ws://localhost:3773 bun run --cwd apps/renderer dev",
"dev:web": "VITE_WS_URL=ws://localhost:3773 bun run --cwd apps/web dev",
"dev:desktop": "bun run --cwd apps/desktop dev",
"start": "node apps/server/dist/index.js",
"start:desktop": "bun run --cwd apps/desktop start",
"build": "turbo run build",
"build:desktop": "bun run build:contracts && bun run --cwd apps/renderer build && bun run --cwd apps/server build && bun run --cwd apps/desktop build",
"build:desktop": "bun run build:contracts && bun run --cwd apps/web build && bun run --cwd apps/server build && bun run --cwd apps/desktop build",
"typecheck": "turbo run typecheck",
"lint": "oxlint --report-unused-disable-directives",
"test": "turbo run test",