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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["oxc.oxc-vscode"]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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:bundledev: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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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