Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"ignorePatterns": [
".plans",
"dist",
"dist-electron",
"node_modules",
"bun.lock",
"*.tsbuildinfo"
],
"experimentalSortPackageJson": {}
}
13 changes: 13 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"ignorePatterns": ["dist", "dist-electron", "node_modules", "bun.lock", "*.tsbuildinfo"],
"plugins": ["eslint", "oxc", "react", "unicorn", "typescript"],
"categories": {
"correctness": "warn",
"suspicious": "warn",
"perf": "warn"
},
"rules": {
"react-in-jsx-scope": "off"
}
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "oxc.oxc-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.oxc": "always"
},
"oxc.unusedDisableDirectives": "warn"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Mode changes apply across all threads. Existing live sessions are restarted so o
- `.github/workflows/ci.yml` runs `bun run lint`, `bun run typecheck`, and `bun run test` on pull requests and pushes to `main`.

Optional:

- `ELECTRON_RENDERER_PORT=5180 bun run dev` if `5173` is already in use.

## Provider architecture
Expand Down
4 changes: 1 addition & 3 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
"private": true,
"main": "dist-electron/main.js",
"scripts": {
"dev": "concurrently -k -n BUNDLE,ELECTRON \"bun run dev:bundle\" \"bun run dev:electron\"",
"dev": "bun run --parallel dev:bundle dev:electron",
"dev:bundle": "tsup --watch",
"dev:electron": "bun run scripts/dev-electron.mjs",
"build": "tsup",
"start": "electron dist-electron/main.js",
"postinstall": "electron-rebuild",
"typecheck": "tsc --noEmit",
"lint": "biome check src/",
"test": "vitest run",
"smoke-test": "node scripts/smoke-test.mjs"
},
Expand All @@ -23,7 +22,6 @@
"devDependencies": {
"@electron/rebuild": "^3.7.0",
"@types/node": "^22.10.2",
"concurrently": "^9.1.2",
"electronmon": "^2.0.2",
"tsup": "^8.3.5",
"typescript": "^5.7.3",
Expand Down
9 changes: 2 additions & 7 deletions apps/desktop/scripts/dev-electron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ const port = Number(process.env.ELECTRON_RENDERER_PORT ?? 5173);
const devServerUrl = `http://localhost:${port}`;

await waitOn({
resources: [
`tcp:${port}`,
"file:dist-electron/main.js",
"file:dist-electron/preload.js",
],
resources: [`tcp:${port}`, "file:dist-electron/main.js", "file:dist-electron/preload.js"],
});

const command =
process.platform === "win32" ? "electronmon.cmd" : "electronmon";
const command = process.platform === "win32" ? "electronmon.cmd" : "electronmon";
const child = spawn(command, ["dist-electron/main.js"], {
stdio: "inherit",
env: {
Expand Down
12 changes: 3 additions & 9 deletions apps/desktop/src/codexAppServerManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { describe, expect, it } from "vitest";

import {
classifyCodexStderrLine,
normalizeCodexModelSlug,
} from "./codexAppServerManager";
import { classifyCodexStderrLine, normalizeCodexModelSlug } from "./codexAppServerManager";

describe("classifyCodexStderrLine", () => {
it("ignores empty lines", () => {
Expand All @@ -23,8 +20,7 @@ describe("classifyCodexStderrLine", () => {
});

it("keeps unknown structured errors", () => {
const line =
"2026-02-08T04:24:20.085687Z ERROR codex_core::runtime: unrecoverable failure";
const line = "2026-02-08T04:24:20.085687Z ERROR codex_core::runtime: unrecoverable failure";
expect(classifyCodexStderrLine(line)).toEqual({
message: line,
});
Expand All @@ -45,9 +41,7 @@ describe("normalizeCodexModelSlug", () => {
});

it("prefers codex id when model differs", () => {
expect(normalizeCodexModelSlug("gpt-5.3", "gpt-5.3-codex")).toBe(
"gpt-5.3-codex",
);
expect(normalizeCodexModelSlug("gpt-5.3", "gpt-5.3-codex")).toBe("gpt-5.3-codex");
});

it("keeps non-aliased models as-is", () => {
Expand Down
113 changes: 24 additions & 89 deletions apps/desktop/src/codexAppServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ export function normalizeCodexModelSlug(
return normalized;
}

export function classifyCodexStderrLine(
rawLine: string,
): { message: string } | null {
export function classifyCodexStderrLine(rawLine: string): { message: string } | null {
const line = rawLine.replaceAll(ANSI_ESCAPE_REGEX, "").trim();
if (!line) {
return null;
Expand All @@ -106,9 +104,7 @@ export function classifyCodexStderrLine(
return null;
}

const isBenignError = BENIGN_ERROR_LOG_SNIPPETS.some((snippet) =>
line.includes(snippet),
);
const isBenignError = BENIGN_ERROR_LOG_SNIPPETS.some((snippet) => line.includes(snippet));
if (isBenignError) {
return null;
}
Expand All @@ -124,9 +120,7 @@ export interface CodexAppServerManagerEvents {
export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEvents> {
private readonly sessions = new Map<string, CodexSessionContext>();

async startSession(
input: ProviderSessionStartInput,
): Promise<ProviderSession> {
async startSession(input: ProviderSessionStartInput): Promise<ProviderSession> {
const sessionId = randomUUID();
const now = new Date().toISOString();

Expand Down Expand Up @@ -160,11 +154,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
this.sessions.set(sessionId, context);
this.attachProcessListeners(context);

this.emitLifecycleEvent(
context,
"session/connecting",
"Starting codex app-server",
);
this.emitLifecycleEvent(context, "session/connecting", "Starting codex app-server");

try {
await this.sendRequest(context, "initialize", {
Expand All @@ -188,10 +178,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
experimentalRawEvents: false,
});

const threadId = this.readString(
this.readObject(threadStart)?.thread,
"id",
);
const threadId = this.readString(this.readObject(threadStart)?.thread, "id");
if (!threadId) {
throw new Error("thread/start response did not include a thread id.");
}
Expand All @@ -200,30 +187,21 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
status: "ready",
threadId,
});
this.emitLifecycleEvent(
context,
"session/ready",
`Connected to thread ${threadId}`,
);
this.emitLifecycleEvent(context, "session/ready", `Connected to thread ${threadId}`);
return { ...context.session };
} catch (error) {
const message =
error instanceof Error
? error.message
: "Failed to start Codex session.";
const message = error instanceof Error ? error.message : "Failed to start Codex session.";
this.updateSession(context, {
status: "error",
lastError: message,
});
this.emitErrorEvent(context, "session/startFailed", message);
this.stopSession(sessionId);
throw new Error(message);
throw new Error(message, { cause: error });
}
}

async sendTurn(
input: ProviderSendTurnInput,
): Promise<ProviderTurnStartResult> {
async sendTurn(input: ProviderSendTurnInput): Promise<ProviderTurnStartResult> {
const context = this.requireSession(input.sessionId);
if (!context.session.threadId) {
throw new Error("Session is missing a thread id.");
Expand Down Expand Up @@ -252,11 +230,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
turnStartParams.effort = input.effort;
}

const response = await this.sendRequest(
context,
"turn/start",
turnStartParams,
);
const response = await this.sendRequest(context, "turn/start", turnStartParams);

const turn = this.readObject(this.readObject(response), "turn");
const turnId = this.readString(turn, "id");
Expand Down Expand Up @@ -498,21 +472,15 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
});

if (notification.method === "thread/started") {
const threadId = this.readString(
this.readObject(notification.params)?.thread,
"id",
);
const threadId = this.readString(this.readObject(notification.params)?.thread, "id");
if (threadId) {
this.updateSession(context, { threadId });
}
return;
}

if (notification.method === "turn/started") {
const turnId = this.readString(
this.readObject(notification.params)?.turn,
"id",
);
const turnId = this.readString(this.readObject(notification.params)?.turn, "id");
this.updateSession(context, {
status: "running",
activeTurnId: turnId,
Expand All @@ -523,10 +491,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
if (notification.method === "turn/completed") {
const turn = this.readObject(notification.params, "turn");
const status = this.readString(turn, "status");
const errorMessage = this.readString(
this.readObject(turn, "error"),
"message",
);
const errorMessage = this.readString(this.readObject(turn, "error"), "message");
this.updateSession(context, {
status: status === "failed" ? "error" : "ready",
activeTurnId: undefined,
Expand All @@ -536,10 +501,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
}

if (notification.method === "error") {
const message = this.readString(
this.readObject(notification.params)?.error,
"message",
);
const message = this.readString(this.readObject(notification.params)?.error, "message");
const willRetry = this.readBoolean(notification.params, "willRetry");

this.updateSession(context, {
Expand All @@ -549,10 +511,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
}
}

private handleServerRequest(
context: CodexSessionContext,
request: JsonRpcRequest,
): void {
private handleServerRequest(context: CodexSessionContext, request: JsonRpcRequest): void {
const route = this.readRouteFields(request.params);
const requestKind = this.requestKindForMethod(request.method);
let requestId: string | undefined;
Expand Down Expand Up @@ -609,10 +568,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
});
}

private handleResponse(
context: CodexSessionContext,
response: JsonRpcResponse,
): void {
private handleResponse(context: CodexSessionContext, response: JsonRpcResponse): void {
const key = String(response.id);
const pending = context.pending.get(key);
if (!pending) {
Expand All @@ -623,11 +579,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
context.pending.delete(key);

if (response.error?.message) {
pending.reject(
new Error(
`${pending.method} failed: ${String(response.error.message)}`,
),
);
pending.reject(new Error(`${pending.method} failed: ${String(response.error.message)}`));
return;
}

Expand Down Expand Up @@ -674,11 +626,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
context.child.stdin.write(`${encoded}\n`);
}

private emitLifecycleEvent(
context: CodexSessionContext,
method: string,
message: string,
): void {
private emitLifecycleEvent(context: CodexSessionContext, method: string, message: string): void {
this.emitEvent({
id: randomUUID(),
kind: "session",
Expand All @@ -690,11 +638,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
});
}

private emitErrorEvent(
context: CodexSessionContext,
method: string,
message: string,
): void {
private emitErrorEvent(context: CodexSessionContext, method: string, message: string): void {
this.emitEvent({
id: randomUUID(),
kind: "error",
Expand All @@ -710,10 +654,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
this.emit("event", event);
}

private updateSession(
context: CodexSessionContext,
updates: Partial<ProviderSession>,
): void {
private updateSession(context: CodexSessionContext, updates: Partial<ProviderSession>): void {
context.session = {
...context.session,
...updates,
Expand Down Expand Up @@ -762,8 +703,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
}

const candidate = value as Record<string, unknown>;
const hasId =
typeof candidate.id === "string" || typeof candidate.id === "number";
const hasId = typeof candidate.id === "string" || typeof candidate.id === "number";
const hasMethod = typeof candidate.method === "string";
return hasId && !hasMethod;
}
Expand All @@ -783,11 +723,9 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
this.readString(params, "threadId") ??
this.readString(this.readObject(params, "thread"), "id");
const turnId =
this.readString(params, "turnId") ??
this.readString(this.readObject(params, "turn"), "id");
this.readString(params, "turnId") ?? this.readString(this.readObject(params, "turn"), "id");
const itemId =
this.readString(params, "itemId") ??
this.readString(this.readObject(params, "item"), "id");
this.readString(params, "itemId") ?? this.readString(this.readObject(params, "item"), "id");

if (threadId) {
route.threadId = threadId;
Expand All @@ -804,10 +742,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
return route;
}

private readObject(
value: unknown,
key?: string,
): Record<string, unknown> | undefined {
private readObject(value: unknown, key?: string): Record<string, unknown> | undefined {
const target =
key === undefined
? value
Expand Down
Loading