Skip to content

Build your personal knowledge base with Trilium Notes

feat(llm): ship the Codex ACP adapter and run it against the user's Codex

Elian Doran97a71630cfc0
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e234ff907e..563bf382fa 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4066,7 +4066,7 @@
"claude_agent_description": "Uses your Claude Pro/Max subscription through Claude Code, so no API key is needed. Claude Code must be installed on the machine running Trilium (the server when self-hosting, or this computer on desktop); sign in once by running \"claude /login\" there.",
"copilot_agent_description": "Uses your GitHub Copilot subscription through the GitHub Copilot CLI, so no API key is needed. The Copilot CLI must be installed on the machine running Trilium (the server when self-hosting, or this computer on desktop); sign in once by running \"copilot login\" there — an existing Copilot login from another editor is reused automatically.",
"antigravity_agent_description": "Uses the Gemini quota of your Google account (free, Google AI Pro or Ultra) through Google Antigravity, so no API key is needed.\n\nGoogle's Antigravity ACP server must be downloaded to the device running Trilium: the server when self-hosting, or this computer on desktop. If it isn't installed yet, the next step shows how to install it.\n\nThe first time the models are listed, the Google sign-in page opens in a browser on that device.",
- "codex_agent_description": "Uses the Codex usage of your ChatGPT plan (Free, Go, Plus, Pro or Business) through OpenAI Codex, so no API key is needed.\n\nThe Codex ACP adapter must be installed on the device running Trilium: the server when self-hosting, or this computer on desktop. Install it by running \"npm install -g @agentclientprotocol/codex-acp\" there.\n\nThe first time the models are listed, the ChatGPT sign-in page opens in a browser on that device.",
+ "codex_agent_description": "Uses the Codex usage of your ChatGPT plan (Free, Go, Plus, Pro or Business) through OpenAI Codex, so no API key is needed.\n\nThe Codex CLI must be installed on the device running Trilium: the server when self-hosting, or this computer on desktop, for example by running \"npm install -g @openai/codex\" there.\n\nThe first time the models are listed, the ChatGPT sign-in page opens in a browser on that device.",
"antigravity_setup_download": "On the device running Trilium, download the archive for your platform from Google's <Link>ACP registry entry</Link> and unzip it into a folder it can stay in.",
"antigravity_setup_archive": "Download <Link>the archive for the device running Trilium</Link> and unzip it there, into a folder it can stay in.",
"antigravity_setup_path": "Add that folder to <Code>PATH</Code>, or set the <Code>TRILIUM_ANTIGRAVITY_ACP_PATH</Code> environment variable to <Code>agy_acp_server.par</Code> in it (<Code>agy_acp_server.exe</Code> on Windows), then restart Trilium.",
diff --git a/apps/desktop/scripts/build.ts b/apps/desktop/scripts/build.ts
index 6d259fc0b4..e51f2c2c8d 100644
--- a/apps/desktop/scripts/build.ts
+++ b/apps/desktop/scripts/build.ts
@@ -28,6 +28,9 @@ async function main() {
// The LLM skill sheets moved to core with the rest of the stack, but the
// Node hosts still read them from RESOURCE_DIR. See server core_assets.ts.
build.copy("/packages/trilium-core/src/assets/llm/skills", "assets/llm/skills/");
+ // The Codex ACP adapter runs as a script of its own in a worker thread. See the server's
+ // codex_binary.ts.
+ build.copy("/node_modules/@agentclientprotocol/codex-acp/dist/index.js", "assets/codex-acp.mjs");
build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/", "dist");
build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
diff --git a/apps/server/package.json b/apps/server/package.json
index df7d2e02b2..3bd9bd7bd9 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -32,6 +32,7 @@
"proxy-nginx-subdir": "docker run --name trilium-nginx-subdir --rm -p 8095:8095 --add-host=host.docker.internal:host-gateway -v ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro nginx:latest"
},
"dependencies": {
+ "@agentclientprotocol/codex-acp": "1.13.1",
"@ai-sdk/anthropic": "4.0.60",
"@ai-sdk/google": "4.0.77",
"@ai-sdk/openai": "4.0.72",
diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.ts
index dd9cddb3b5..19b081ad20 100644
--- a/apps/server/scripts/build.ts
+++ b/apps/server/scripts/build.ts
@@ -27,6 +27,8 @@ async function main() {
// `import.meta.url`, which in a split bundle is a hash-named file under chunks/, so the bytes
// are handed to it explicitly from here instead. See pdf_renderer.ts.
build.copy("/node_modules/@hyzyla/pdfium/dist/pdfium.wasm", "assets/pdfium.wasm");
+ // The Codex ACP adapter runs as a script of its own in a worker thread. See codex_binary.ts.
+ build.copy("/node_modules/@agentclientprotocol/codex-acp/dist/index.js", "assets/codex-acp.mjs");
build.triggerBuildAndCopyTo("packages/share-theme", "share-theme/assets/", "dist");
build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers.html
index 49cdcdd20b..c96218492a 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers.html
@@ -31,7 +31,7 @@
<li>Claude Code by reusing your CLI.</li>
<li>GitHub Copilot by reusing your CLI's ACP.</li>
<li>Google Antigravity by downloading and setting up an ACP for Trilium.</li>
- <li>OpenAI Codex by installing the Codex ACP adapter for Trilium.</li>
+ <li>OpenAI Codex by reusing your CLI through an ACP adapter shipped with Trilium.</li>
</ul>
<h2>Local/self-hosted providers</h2>
<p>Local or self-hosted providers are a free alternative which respects your
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers/Subscription-based providers.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers/Subscription-based providers.html
index 01265bb9c2..46e8d2b877 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers/Subscription-based providers.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Providers/Subscription-based providers.html
@@ -1,9 +1,9 @@
<p>Some cloud providers offer a subscription, which has a fixed monthly fee
instead of pay-per-use (unlike the API keys).</p>
<p>In a nutshell, subscription-based providers work by either reusing your
- existing CLI tools (e.g. Claude Code, GitHub Copilot via ACP) whereas some
- require installing the ACP server manually (e.g. Google Antigravity, OpenAI
- Codex). Because they require something to be installed on your device,
+ existing CLI tools (e.g. Claude Code, GitHub Copilot and OpenAI Codex via
+ ACP) whereas some require installing the ACP server manually (e.g. Google
+ Antigravity). Because they require something to be installed on your device,
these providers are not available on Mobile (Android or iOS) or standalone
mode.</p>
<p>See also the dedicated&nbsp;<a class="reference-link" href="#root/_help_cRRrdZjgyhNc">Privacy</a>&nbsp;section
@@ -142,10 +142,10 @@ trilium</code></pre>
Go, Plus, Pro or Business), without an API key. Usage counts against your
plan's Codex limits, which are small on the Free plan.</p>
<ol>
- <li>Install the Codex ACP adapter on the machine that runs Trilium with <code>npm install -g @agentclientprotocol/codex-acp</code>.
- It brings its own copy of the Codex CLI, so Codex doesn't need to be installed
- separately. For a <a class="reference-link" href="#root/_help_WOcw2SLH6tbX">Server Installation</a> it
- needs to be installed on the server.</li>
+ <li>Install the Codex CLI on the machine that runs Trilium, for example with <code>npm install -g @openai/codex</code>.
+ As with Claude Code, for a <a class="reference-link" href="#root/_help_WOcw2SLH6tbX">Server Installation</a> it
+ needs to be installed on the server. Trilium ships the ACP adapter that
+ connects to it, so nothing else is needed.</li>
<li>Go to <a class="reference-link" href="#root/_help_4TIF1oA4VQRO">Options</a> → <em>AI / LLM</em> and
add the OpenAI Codex provider. When the list of models is loaded for the
first time, the ChatGPT sign-in page opens in a browser on the machine
@@ -154,11 +154,11 @@ trilium</code></pre>
<p>Trilium keeps its own Codex sign-in and settings, separate from any Codex
CLI you use in a terminal, so an existing <code>codex login</code> is not
reused.</p>
-<p>Trilium will identify the Codex ACP adapter in this order:</p>
+<p>Trilium will identify your Codex CLI in this order:</p>
<ul>
- <li>By looking for a <code>TRILIUM_CODEX_ACP_PATH</code> environment variable
- pointing to the <code>codex-acp</code> binary.</li>
- <li>By looking for <code>codex-acp</code> in your PATH.</li>
+ <li>By looking for a <code>TRILIUM_CODEX_PATH</code> environment variable pointing
+ to the Codex binary.</li>
+ <li>By looking for <code>codex</code> in your PATH.</li>
<li>By asking your login shell for its <code>PATH</code>, the same as for Claude
Code.</li>
</ul>
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index ae5844cbc1..b1c0058fb2 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -40,6 +40,8 @@ export interface AcpLaunchSpec {
args: string[];
/** Launch through a shell (npm `.cmd` shims on Windows). */
shell?: boolean;
+ /** `binary` is a Node script to run in a worker thread (see {@link AcpClient.startWorker}). */
+ worker?: boolean;
/** Variables set on top of the server's own environment. */
env?: Record<string, string>;
}
@@ -688,7 +690,7 @@ ${firstMessage.substring(0, 500)}`
} = {}
): Promise<AcpClient> {
const launch = await this.launchSpec();
- const client = AcpClient.start(launch.binary, {
+ const client = (launch.worker ? AcpClient.startWorker : AcpClient.start)(launch.binary, {
cwd: this.agentCwd(),
shell: launch.shell,
args: launch.args,
diff --git a/apps/server/src/services/llm/providers/acp_client.spec.ts b/apps/server/src/services/llm/providers/acp_client.spec.ts
index d94c48add8..ab6972f0bb 100644
--- a/apps/server/src/services/llm/providers/acp_client.spec.ts
+++ b/apps/server/src/services/llm/providers/acp_client.spec.ts
@@ -1,4 +1,7 @@
import { EventEmitter } from "events";
+import fs from "fs";
+import os from "os";
+import path from "path";
import { PassThrough } from "stream";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -354,3 +357,48 @@ describe("AcpClient", () => {
expect(() => proc.stdin.emit("error", new Error("write EPIPE"))).not.toThrow();
});
});
+
+describe("AcpClient.startWorker", () => {
+ /** An agent that answers every request with what it sees of its environment, and exits when stdin closes. */
+ const ECHO_AGENT = `
+ import { createInterface } from "node:readline";
+ createInterface({ input: process.stdin }).on("line", line => {
+ const { id, method } = JSON.parse(line);
+ if (method === "crash") throw new Error("agent crashed");
+ process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, result: { mark: process.env.MARK, argv: process.argv.slice(2) } }) + "\\n");
+ });
+ process.stdin.on("close", async () => {
+ (await import("node:fs")).writeFileSync(process.env.CLOSED_MARKER, "");
+ process.exit(0);
+ });
+ `;
+ let script: string;
+
+ beforeEach(() => {
+ script = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "trilium-acp-worker-")), "agent.mjs");
+ fs.writeFileSync(script, ECHO_AGENT);
+ });
+
+ it("speaks to a script in a worker thread over its stdio, with the given args and environment", async () => {
+ const onExit = vi.fn();
+ const marker = `${script}.closed`;
+ const client = AcpClient.startWorker(script, { cwd: "/unused", args: ["--flag"], env: { MARK: "worker", CLOSED_MARKER: marker }, onExit });
+
+ await expect(client.request("ping", {})).resolves.toEqual({ mark: "worker", argv: ["--flag"] });
+
+ // Closing stdin lets the agent exit on its own; a deliberate dispose is no failure.
+ client.dispose();
+ await vi.waitFor(() => expect(fs.existsSync(marker)).toBe(true));
+ await new Promise(resolve => setTimeout(resolve, 50));
+ expect(onExit).not.toHaveBeenCalled();
+ });
+
+ it("fails in-flight requests and reports the death when the worker throws", async () => {
+ const onExit = vi.fn();
+ const client = AcpClient.startWorker(script, { cwd: "/unused", onExit });
+
+ await expect(client.request("crash", {})).rejects.toThrow(/agent crashed/);
+ expect(onExit).toHaveBeenCalledOnce();
+ expect(client.alive).toBe(false);
+ });
+});
diff --git a/apps/server/src/services/llm/providers/acp_client.ts b/apps/server/src/services/llm/providers/acp_client.ts
index 6837df7c2c..bbfc761304 100644
--- a/apps/server/src/services/llm/providers/acp_client.ts
+++ b/apps/server/src/services/llm/providers/acp_client.ts
@@ -6,12 +6,15 @@
* Deliberately dependency-free and transport-only: protocol semantics
* (initialize, session/new, session/prompt, permission policy) live in the
* provider. The client handles framing, request/response correlation,
- * agent→client requests, and subprocess lifecycle.
+ * agent→client requests, and the agent's lifecycle, whether it runs as a
+ * subprocess or as a Node script in a worker thread.
*/
import { getLog } from "@triliumnext/core";
import { type ChildProcessWithoutNullStreams, spawn } from "child_process";
import { createInterface } from "readline";
+import type { Readable, Writable } from "stream";
+import { Worker } from "worker_threads";
/** How long a disposed agent has to exit on its own before it is killed. */
const DISPOSE_GRACE_MS = 5_000;
@@ -68,6 +71,18 @@ export interface AcpClientOptions {
onExit?: (error: Error) => void;
}
+/** Where the agent runs: a subprocess, or a script in a worker thread of this process. */
+interface AgentHost {
+ stdin: Writable;
+ stdout: Readable;
+ stderr: Readable;
+ /** Called when the agent cannot start, or its worker throws. */
+ onError(listener: (err: Error) => void): void;
+ /** Called when the agent ends, with how it ended (`SIGTERM`, `code 1`). */
+ onExit(listener: (how: string) => void): void;
+ kill(): void;
+}
+
export class AcpClient {
private nextId = 1;
private readonly pending = new Map<number, { resolve: (msg: JsonRpcMessage) => void; reject: (err: Error) => void }>();
@@ -76,7 +91,7 @@ export class AcpClient {
private exited = false;
private constructor(
- private readonly proc: ChildProcessWithoutNullStreams,
+ private readonly proc: AgentHost,
private readonly options: AcpClientOptions
) {
const rl = createInterface({ input: proc.stdout });
@@ -96,13 +111,13 @@ export class AcpClient {
// left to report.
proc.stdin.on("error", () => {});
- proc.on("error", err => this.die(new Error(`Failed to start the ACP agent: ${err.message}`)));
- proc.on("exit", (code, sig) => {
+ proc.onError(err => this.die(new Error(`Failed to start the ACP agent: ${err.message}`)));
+ proc.onExit(how => {
this.exited = true;
// A deliberate dispose() ends the subprocess — that exit is expected
// and must not surface as an error for in-flight (cancelled) requests.
if (!this.disposed) {
- this.die(new Error(`The ACP agent exited unexpectedly (${sig ?? `code ${code}`}).`));
+ this.die(new Error(`The ACP agent exited unexpectedly (${how}).`));
}
});
}
@@ -118,7 +133,43 @@ export class AcpClient {
env: options.env ? { ...process.env, ...options.env } : process.env
}
);
- return new AcpClient(proc, options);
+ return new AcpClient({
+ stdin: proc.stdin,
+ stdout: proc.stdout,
+ stderr: proc.stderr,
+ onError: listener => proc.on("error", listener),
+ onExit: listener => proc.on("exit", (code, sig) => listener(sig ?? `code ${code}`)),
+ kill: () => killProcessTree(proc)
+ }, options);
+ }
+
+ /**
+ * Run an agent that ships as a Node script in a worker thread of this
+ * process, speaking ACP over the worker's stdio. It needs no Node binary on
+ * the host, which a packaged desktop build cannot provide: its `RunAsNode`
+ * fuse is off. The worker shares this process's working directory, so
+ * `cwd` and `shell` do not apply.
+ */
+ static startWorker(script: string, options: AcpClientOptions): AcpClient {
+ const worker = new Worker(script, {
+ argv: options.args ?? [],
+ env: { ...process.env, ...options.env },
+ stdin: true,
+ stdout: true,
+ stderr: true
+ });
+ const stdin = worker.stdin;
+ if (!stdin) {
+ throw new Error("The ACP agent's worker has no stdin.");
+ }
+ return new AcpClient({
+ stdin,
+ stdout: worker.stdout,
+ stderr: worker.stderr,
+ onError: listener => worker.on("error", listener),
+ onExit: listener => worker.on("exit", code => listener(`code ${code}`)),
+ kill: () => void worker.terminate()
+ }, options);
}
/** Send a request and await its response result (rejects with {@link AcpError} on error responses). */
@@ -178,27 +229,12 @@ export class AcpClient {
this.proc.stdin.end();
const killTimer = setTimeout(() => {
if (!this.exited) {
- this.kill();
+ this.proc.kill();
}
}, DISPOSE_GRACE_MS);
killTimer.unref();
}
- /**
- * End the agent and every process it started. On Windows `proc.kill()`
- * ends only the spawned process, while the agent can run in a child of it:
- * the PyInstaller build of `agy_acp_server` starts its server that way, and
- * a `.cmd` shim runs the CLI under `cmd.exe`. `taskkill /T` ends the tree.
- */
- private kill(): void {
- if (process.platform === "win32" && this.proc.pid !== undefined) {
- const taskkill = spawn("taskkill", [ "/pid", String(this.proc.pid), "/T", "/F" ], { stdio: "ignore", windowsHide: true });
- taskkill.on("error", err => getLog().error(`Failed to end the ACP agent's process tree: ${err.message}`));
- return;
- }
- this.proc.kill();
- }
-
private send(message: JsonRpcMessage): void {
this.proc.stdin.write(`${JSON.stringify(message)}\n`);
}
@@ -275,3 +311,18 @@ export class AcpClient {
this.pending.clear();
}
}
+
+/**
+ * End the agent and every process it started. On Windows `proc.kill()`
+ * ends only the spawned process, while the agent can run in a child of it:
+ * the PyInstaller build of `agy_acp_server` starts its server that way, and
+ * a `.cmd` shim runs the CLI under `cmd.exe`. `taskkill /T` ends the tree.
+ */
+function killProcessTree(proc: ChildProcessWithoutNullStreams): void {
+ if (process.platform === "win32" && proc.pid !== undefined) {
+ const taskkill = spawn("taskkill", [ "/pid", String(proc.pid), "/T", "/F" ], { stdio: "ignore", windowsHide: true });
+ taskkill.on("error", err => getLog().error(`Failed to end the ACP agent's process tree: ${err.message}`));
+ return;
+ }
+ proc.kill();
+}
diff --git a/apps/server/src/services/llm/providers/codex_agent.live.spec.ts b/apps/server/src/services/llm/providers/codex_agent.live.spec.ts
index 74aca0da6e..0709a137cd 100644
--- a/apps/server/src/services/llm/providers/codex_agent.live.spec.ts
+++ b/apps/server/src/services/llm/providers/codex_agent.live.spec.ts
@@ -1,11 +1,12 @@
/**
- * Live integration test for the Codex Agent provider: drives the user's real
- * `codex-acp` and asserts that a chat turn gets an answer.
+ * Live integration test for the Codex Agent provider: runs the installed
+ * `@agentclientprotocol/codex-acp` in a worker against the user's real `codex`
+ * (TRILIUM_CODEX_PATH or PATH) and asserts that a chat turn gets an answer.
*
- * Opt-in — it starts the adapter, needs a saved ChatGPT sign-in, and spends the
+ * Opt-in — it starts Codex, needs a saved ChatGPT sign-in, and spends the
* plan's Codex usage, so it never runs in CI:
*
- * TRILIUM_CODEX_LIVE_TEST=1 pnpm --filter server test codex_agent.live
+ * TRILIUM_CODEX_LIVE_TEST=1 TRILIUM_RESOURCE_DIR=src pnpm --filter server test codex_agent.live
*
* The sign-in (`auth.json`) is copied from TRILIUM_CODEX_LIVE_HOME (default: the
* dev server's `data/codex-agent/home`) into a temporary data directory.
diff --git a/apps/server/src/services/llm/providers/codex_agent.spec.ts b/apps/server/src/services/llm/providers/codex_agent.spec.ts
index 285ed8fff1..08f139d518 100644
--- a/apps/server/src/services/llm/providers/codex_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/codex_agent.spec.ts
@@ -16,7 +16,10 @@ vi.mock("../../data_dir.js", async () => {
return { default: { TRILIUM_DATA_DIR: path.join(os.tmpdir(), "trilium-codex-agent-spec") } };
});
-vi.mock("./codex_binary.js", () => ({ resolveCodexBinaryPath: async () => "/usr/bin/codex-acp" }));
+vi.mock("./codex_binary.js", () => ({
+ resolveCodexBinaryPath: async () => "/usr/bin/codex",
+ resolveCodexAcpScript: () => "/opt/trilium/assets/codex-acp.mjs"
+}));
vi.mock("./acp_mcp_endpoint.js", () => ({ getAcpMcpEndpointUrl: async () => "http://127.0.0.1:12345/mcp-secret" }));
vi.mock("@triliumnext/core/src/services/llm/note_hint.js", () => ({ buildNoteHint: () => null }));
vi.mock("@triliumnext/core/src/services/llm/attachment_content.js", () => ({ resolveAttachmentPart: vi.fn() }));
@@ -27,10 +30,12 @@ class FakeAcpError extends Error {
}
}
+type StartOptions = { args?: string[]; env?: Record<string, string>; cwd: string; onAgentRequest?: (m: string, p: unknown) => unknown };
+
/** Answers like `codex-acp`: `session/new` fails until `authenticate` has run, when `signedIn` is false. */
class FakeAcpClient {
static current: FakeAcpClient | undefined;
- static lastStart: { binary: string; opts: { args?: string[]; env?: Record<string, string>; cwd: string } } | undefined;
+ static lastStart: { worker: boolean; binary: string; opts: { args?: string[]; env?: Record<string, string>; cwd: string } } | undefined;
static signedIn = true;
/** An error `session/new` fails with, when set. */
static sessionFailure: Error | undefined;
@@ -38,8 +43,16 @@ class FakeAcpClient {
requests: { method: string; params: unknown }[] = [];
onAgentRequest?: (method: string, params: unknown) => unknown;
- static start(binary: string, opts: { args?: string[]; env?: Record<string, string>; cwd: string; onAgentRequest?: (m: string, p: unknown) => unknown }) {
- FakeAcpClient.lastStart = { binary, opts };
+ static start(binary: string, opts: StartOptions) {
+ return FakeAcpClient.launch(false, binary, opts);
+ }
+
+ static startWorker(script: string, opts: StartOptions) {
+ return FakeAcpClient.launch(true, script, opts);
+ }
+
+ private static launch(worker: boolean, binary: string, opts: StartOptions) {
+ FakeAcpClient.lastStart = { worker, binary, opts };
FakeAcpClient.current = new FakeAcpClient();
FakeAcpClient.current.onAgentRequest = opts.onAgentRequest;
return FakeAcpClient.current;
@@ -113,12 +126,17 @@ beforeEach(() => {
});
describe("CodexAgentProvider", () => {
- it("launches the adapter read-only, with a home of Trilium's own, and denies what it asks permission for", async () => {
+ it("runs the bundled adapter in a worker against the user's Codex, read-only, with a home of Trilium's own, and denies what it asks permission for", async () => {
await collect(new CodexAgentProvider().chatChunks([{ role: "user", content: "hi" }], {}));
const start = FakeAcpClient.lastStart;
- expect(start?.binary).toBe("/usr/bin/codex-acp");
- expect(start?.opts.env).toEqual({ CODEX_HOME: path.join(DATA_DIR, "codex-agent", "home"), INITIAL_AGENT_MODE: "read-only" });
+ expect(start?.worker).toBe(true);
+ expect(start?.binary).toBe("/opt/trilium/assets/codex-acp.mjs");
+ expect(start?.opts.env).toEqual({
+ CODEX_PATH: "/usr/bin/codex",
+ CODEX_HOME: path.join(DATA_DIR, "codex-agent", "home"),
+ INITIAL_AGENT_MODE: "read-only"
+ });
expect(start?.opts.cwd).toBe(path.join(DATA_DIR, "codex-agent", "workspace"));
expect(FakeAcpClient.current?.onAgentRequest?.("session/request_permission", {
toolCall: { kind: "execute", title: "rm -rf /" },
@@ -144,7 +162,7 @@ describe("CodexAgentProvider", () => {
return new CodexAgentProvider().listModels().then(() => "resolved", (err: Error) => err.message);
};
expect(await failureOf(new Error("ACP request \"authenticate\" timed out after 300000ms"))).toMatch(/sign-in was not completed in time/);
- expect(await failureOf(new Error("spawn /usr/bin/codex-acp ENOENT"))).toBe("Failed to start the Codex ACP adapter: spawn /usr/bin/codex-acp ENOENT");
+ expect(await failureOf(new Error("spawn /usr/bin/codex ENOENT"))).toBe("Failed to start Codex: spawn /usr/bin/codex ENOENT");
expect(await failureOf(new Error("Something else"))).toBe("Something else");
});
diff --git a/apps/server/src/services/llm/providers/codex_agent.ts b/apps/server/src/services/llm/providers/codex_agent.ts
index 6ecda285a3..178ae2c131 100644
--- a/apps/server/src/services/llm/providers/codex_agent.ts
+++ b/apps/server/src/services/llm/providers/codex_agent.ts
@@ -1,11 +1,12 @@
/**
- * Codex Agent provider — drives OpenAI Codex through its ACP adapter
- * (`codex-acp`, the Agent Client Protocol) as a subprocess. This lets users
- * with a ChatGPT account — Free, Go, Plus, Pro or Business — use the in-app
- * chat without an API key: the adapter signs in with the ChatGPT account and
+ * Codex Agent provider — drives the user's own Codex CLI through the ACP
+ * adapter Trilium ships (`codex-acp`, the Agent Client Protocol), which runs in
+ * a worker thread and starts `codex app-server` (see codex_binary.ts). This
+ * lets users with a ChatGPT account — Free, Go, Plus, Pro or Business — use the
+ * in-app chat without an API key: Codex signs in with the ChatGPT account and
* bills the plan's Codex usage.
*
- * `CODEX_HOME` points the adapter at a directory of Trilium's own, so its
+ * `CODEX_HOME` points Codex at a directory of Trilium's own, so its
* sign-in, sessions, MCP servers and skills are Trilium's rather than those of
* the user's own Codex setup. The session starts in the `read-only` mode, where
* Codex asks before anything that writes or reaches the network, and the
@@ -20,8 +21,7 @@ import path from "path";
import dataDirs from "../../data_dir.js";
import { AcpAgentProvider, type AcpLaunchSpec, type AcpModel, type AcpNewSessionParams, type AcpSessionModelState, describeError } from "./acp_agent.js";
import { type AcpClient, AcpError } from "./acp_client.js";
-import { resolveCodexBinaryPath } from "./codex_binary.js";
-import { needsShell } from "./copilot_binary.js";
+import { resolveCodexAcpScript, resolveCodexBinaryPath } from "./codex_binary.js";
/** The model id that leaves the session on the model Codex picks. */
const DEFAULT_MODEL_ID = "default";
@@ -75,14 +75,14 @@ export class CodexAgentProvider extends AcpAgentProvider {
}
protected async launchSpec(): Promise<AcpLaunchSpec> {
- const binary = await resolveCodexBinaryPath();
+ const codex = await resolveCodexBinaryPath();
const home = agentHome();
fs.mkdirSync(home, { recursive: true });
return {
- binary,
+ binary: resolveCodexAcpScript(),
args: [],
- shell: needsShell(binary),
- env: { CODEX_HOME: home, INITIAL_AGENT_MODE: "read-only" }
+ worker: true,
+ env: { CODEX_PATH: codex, CODEX_HOME: home, INITIAL_AGENT_MODE: "read-only" }
};
}
@@ -124,7 +124,7 @@ export class CodexAgentProvider extends AcpAgentProvider {
return "The ChatGPT sign-in was not completed in time. Try again, and finish signing in in the browser window that opens on the device running Trilium.";
}
if (/ENOENT|spawn/i.test(text)) {
- return `Failed to start the Codex ACP adapter: ${text}`;
+ return `Failed to start Codex: ${text}`;
}
return text;
}
diff --git a/apps/server/src/services/llm/providers/codex_binary.ts b/apps/server/src/services/llm/providers/codex_binary.ts
index 058b63cf4b..9b1c235b9e 100644
--- a/apps/server/src/services/llm/providers/codex_binary.ts
+++ b/apps/server/src/services/llm/providers/codex_binary.ts
@@ -1,23 +1,26 @@
/**
- * Resolves the Codex ACP adapter (`codex-acp`), which the Codex Agent provider
- * drives.
+ * Resolves what the Codex Agent provider runs: the Codex ACP adapter, which
+ * Trilium ships, and the user's own Codex CLI, which the adapter drives.
*
- * Bring-your-own-binary like the other agent providers: nothing is bundled. The
- * adapter is the npm package `@agentclientprotocol/codex-acp`, which depends on
- * `@openai/codex` and starts that Codex CLI itself, so it is the only thing the
- * user installs.
+ * The adapter (`@agentclientprotocol/codex-acp`) is one bundled script that
+ * translates ACP into Codex's `codex app-server` protocol. It runs in a worker
+ * thread (see `AcpClient.startWorker`), so no Node is needed on the host. The
+ * Codex CLI stays bring-your-own like the other agent CLIs: its native build is
+ * 300-400 MB per platform, and it must update as fast as OpenAI ships models.
*
- * Resolution order: the TRILIUM_CODEX_ACP_PATH override, then `codex-acp` on
- * PATH (see `findOnPath`, which also asks the login shell). The resolved binary
- * is probed with `--version` once so a broken install surfaces as a clear error
- * instead of an opaque spawn failure mid-chat.
+ * The CLI is resolved from the TRILIUM_CODEX_PATH override, then `codex` on
+ * PATH (see `findOnPath`, which also asks the login shell), and probed with
+ * `--version` once so a broken install surfaces as a clear error instead of an
+ * opaque failure mid-chat.
*/
import { getLog } from "@triliumnext/core";
import { execFile } from "child_process";
import { existsSync } from "fs";
+import path from "path";
import { promisify } from "util";
+import { RESOURCE_DIR } from "../../resource_dir.js";
import { findOnPath } from "./binary_lookup.js";
import { needsShell } from "./copilot_binary.js";
@@ -25,7 +28,7 @@ const execFileAsync = promisify(execFile);
const PROBE_TIMEOUT_MS = 15000;
-const INSTALL_HINT = "Install it with `npm install -g @agentclientprotocol/codex-acp` on the machine running the Trilium server, or set the TRILIUM_CODEX_ACP_PATH environment variable to its location.";
+const INSTALL_HINT = "Install it (for example with `npm install -g @openai/codex`) on the machine running the Trilium server, or set the TRILIUM_CODEX_PATH environment variable to its location.";
/**
* The in-flight/successful resolution. Caching the promise lets concurrent
@@ -49,40 +52,54 @@ export function resetCodexBinaryCache(): void {
cachedResolution = undefined;
}
+/**
+ * The adapter script: the copy the build places under RESOURCE_DIR, or the
+ * installed package when running from source.
+ */
+export function resolveCodexAcpScript(): string {
+ const bundled = path.join(RESOURCE_DIR, "codex-acp.mjs");
+ return existsSync(bundled) ? bundled : require.resolve("@agentclientprotocol/codex-acp");
+}
+
async function probeBinary(): Promise<string> {
const binary = await locateBinary();
// Async on purpose — this runs on the first chat request, and a sync probe
// would freeze the whole server for up to the timeout.
- let version: string;
+ let output: string;
try {
// `shell` is required for the .cmd shim npm creates on Windows, and
// then the path is not quoted for us.
const shell = needsShell(binary);
const { stdout } = await execFileAsync(shell ? `"${binary}"` : binary, ["--version"], { timeout: PROBE_TIMEOUT_MS, encoding: "utf8", shell });
- version = stdout.trim() || "version not reported";
+ output = stdout.trim();
} catch (err) {
const detail = err instanceof Error ? err.message : String(err);
- throw new Error(`Found the Codex ACP adapter at "${binary}" but it failed to run (${detail}). ${INSTALL_HINT}`);
+ throw new Error(`Found the Codex CLI at "${binary}" but it failed to run (${detail}). ${INSTALL_HINT}`);
+ }
+
+ const version = /\d+\.\d+\.\d+\S*/.exec(output)?.[0];
+ if (!version) {
+ throw new Error(`Found the Codex CLI at "${binary}" but it did not report a version${output ? ` (it printed: ${output})` : ""}. ${INSTALL_HINT}`);
}
- getLog().info(`Codex Agent provider: using the Codex ACP adapter at ${binary} (${version})`);
+ getLog().info(`Codex Agent provider: using the Codex CLI at ${binary} (${version})`);
return binary;
}
async function locateBinary(): Promise<string> {
- const override = process.env.TRILIUM_CODEX_ACP_PATH?.trim();
+ const override = process.env.TRILIUM_CODEX_PATH?.trim();
if (override) {
if (!existsSync(override)) {
- throw new Error(`TRILIUM_CODEX_ACP_PATH is set to "${override}", but no file exists there.`);
+ throw new Error(`TRILIUM_CODEX_PATH is set to "${override}", but no file exists there.`);
}
return override;
}
- const onPath = await findOnPath("codex-acp");
+ const onPath = await findOnPath("codex");
if (onPath) {
return onPath;
}
- throw new Error(`The Codex ACP adapter (codex-acp) was not found. ${INSTALL_HINT}`);
+ throw new Error(`The Codex CLI (codex) was not found. ${INSTALL_HINT}`);
}
diff --git a/docs/User Guide/User Guide/AI/Providers.md b/docs/User Guide/User Guide/AI/Providers.md
index f59b53698b..97b7bd38e2 100644
--- a/docs/User Guide/User Guide/AI/Providers.md
+++ b/docs/User Guide/User Guide/AI/Providers.md
@@ -27,7 +27,7 @@ Trilium integrates multiple <a class="reference-link" href="Providers/Subscript
* Claude Code by reusing your CLI.
* GitHub Copilot by reusing your CLI's ACP.
* Google Antigravity by downloading and setting up an ACP for Trilium.
-* OpenAI Codex by installing the Codex ACP adapter for Trilium.
+* OpenAI Codex by reusing your CLI through an ACP adapter shipped with Trilium.
## Local/self-hosted providers
diff --git a/docs/User Guide/User Guide/AI/Providers/Subscription-based providers.md b/docs/User Guide/User Guide/AI/Providers/Subscription-based providers.md
index 8f36d122ba..270d67e135 100644
--- a/docs/User Guide/User Guide/AI/Providers/Subscription-based providers.md
+++ b/docs/User Guide/User Guide/AI/Providers/Subscription-based providers.md
@@ -1,7 +1,7 @@
# Subscription-based providers
Some cloud providers offer a subscription, which has a fixed monthly fee instead of pay-per-use (unlike the API keys).
-In a nutshell, subscription-based providers work by either reusing your existing CLI tools (e.g. Claude Code, GitHub Copilot via ACP) whereas some require installing the ACP server manually (e.g. Google Antigravity, OpenAI Codex). Because they require something to be installed on your device, these providers are not available on Mobile (Android or iOS) or standalone mode.
+In a nutshell, subscription-based providers work by either reusing your existing CLI tools (e.g. Claude Code, GitHub Copilot and OpenAI Codex via ACP) whereas some require installing the ACP server manually (e.g. Google Antigravity). Because they require something to be installed on your device, these providers are not available on Mobile (Android or iOS) or standalone mode.
See also the dedicated <a class="reference-link" href="../Privacy.md">Privacy</a> section to better understand what data is being sent to a cloud provider.
@@ -87,15 +87,15 @@ trilium
OpenAI Codex gives access to the Codex models of your ChatGPT plan (Free, Go, Plus, Pro or Business), without an API key. Usage counts against your plan's Codex limits, which are small on the Free plan.
-1. Install the Codex ACP adapter on the machine that runs Trilium with `npm install -g @agentclientprotocol/codex-acp`. It brings its own copy of the Codex CLI, so Codex doesn't need to be installed separately. For a <a class="reference-link" href="../../Installation%20%26%20Setup/Server%20Installation.md">Server Installation</a> it needs to be installed on the server.
+1. Install the Codex CLI on the machine that runs Trilium, for example with `npm install -g @openai/codex`. As with Claude Code, for a <a class="reference-link" href="../../Installation%20%26%20Setup/Server%20Installation.md">Server Installation</a> it needs to be installed on the server. Trilium ships the ACP adapter that connects to it, so nothing else is needed.
2. Go to <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Options.md">Options</a> → _AI / LLM_ and add the OpenAI Codex provider. When the list of models is loaded for the first time, the ChatGPT sign-in page opens in a browser on the machine running Trilium; finish signing in there.
Trilium keeps its own Codex sign-in and settings, separate from any Codex CLI you use in a terminal, so an existing `codex login` is not reused.
-Trilium will identify the Codex ACP adapter in this order:
+Trilium will identify your Codex CLI in this order:
-* By looking for a `TRILIUM_CODEX_ACP_PATH` environment variable pointing to the `codex-acp` binary.
-* By looking for `codex-acp` in your PATH.
+* By looking for a `TRILIUM_CODEX_PATH` environment variable pointing to the Codex binary.
+* By looking for `codex` in your PATH.
* By asking your login shell for its `PATH`, the same as for Claude Code.
### Known limitations
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 323ce0774b..00b2f83f46 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -17,6 +17,7 @@ overrides:
'@lezer/highlight': 1.2.3
'@lezer/lr': 1.4.10
'@ai-sdk/provider-utils': 5.0.45
+ '@agentclientprotocol/codex-acp>@openai/codex': '-'
zod: 4.6.5
mermaid: 12.0.0
preact: 10.29.8
@@ -633,6 +634,9 @@ importers:
apps/server:
dependencies:
+ '@agentclientprotocol/codex-acp':
+ specifier: 1.13.1
+ version: 1.13.1
'@ai-sdk/anthropic':
specifier: 4.0.60
version: 4.0.60([email protected])
@@ -1558,6 +1562,15 @@ packages:
resolution: {integrity: sha512-6OzddxPio9UiWTCemp4N8cYLV2ZN1ncRnV1cVGtve7dhPOtRkleRyx32GQCYSwDYgaHU3USMm84tNsvKzRCa1Q==}
+ '@agentclientprotocol/[email protected]':
+ resolution: {integrity: sha512-NAbXTb6GRReox7B+8RN9VRB+sKUqFJh5Vg7Ex7RskYCO8EsYPJKN1WJvN7mOqjCKKK9lVDrNxtP7Bp/OUKPyAg==}
+ hasBin: true
+
+ '@agentclientprotocol/[email protected]':
+ resolution: {integrity: sha512-524jwbB2iYWA+kWWyv9fhKbhU89dH/lu9u5EXwVNmfYzopV8BujCDxByBDZhxRUkB7RWIJzISCnwivdDk+bdVg==}
+ peerDependencies:
+ zod: 4.6.5
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-7Hb10pUnPRLYQxrWC5OtcYEmrOIGmAez6+meKBePxCO09Jjle5Ke+L2mTOonAVkY/7MEafpY7c55F7DJ9yGeNg==}
engines: {node: '>=22'}
@@ -6240,6 +6253,10 @@ packages:
resolution: {integrity: sha512-azX778/2VQ9K2uiYprSUKLgK2K6lR1KtJycJDsMg7u0+Cc994A9HyGaUKb01e/T+M8jse057429iKXurCaT35g==}
engines: {node: '>=20.11.1'}
+ resolution: {integrity: sha512-DdH81/zPLVS11EUgWq3tEu/xn+EzljlMYooDNdzWEnFha3R3NBMpMV1UqYIpjYHV/SgpFKMIX1Oh7o06SjM/oA==}
+ engines: {node: '>=18'}
+
resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}
engines: {node: '>=10.16.0'}
@@ -6963,6 +6980,14 @@ packages:
resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==}
engines: {node: '>=0.10.0'}
+ resolution: {integrity: sha512-x1VCxdX4t+8wVfd1so/9w+vQ4vx7lKd2Qp5tDRutErwmR85OgmfX7RlLRMWafRMY7hbEiXIbudNrjOAPa/hL8Q==}
+ engines: {node: '>=18'}
+
+ resolution: {integrity: sha512-m1pAzaJgZ/gssEqlOhJkPJp8Xly7QyW6xcrkUa2KKcDeDSEMP7X8xipU3snUcfisTQx0w1AGae+9UtJSfVnXGw==}
+ engines: {node: '>=18'}
+
resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==}
@@ -6978,6 +7003,10 @@ packages:
resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==}
engines: {node: '>=8'}
+ resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==}
+ engines: {node: '>=12'}
+
resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==}
engines: {node: '>= 0.4'}
@@ -8308,6 +8337,11 @@ packages:
engines: {node: '>=8'}
hasBin: true
+ resolution: {integrity: sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ hasBin: true
+
resolution: {integrity: sha512-+XSoyS05OdBbhFuELhgTCpFNHkpBOJqtsZfUFFpe5QTw+9Sjbh8zitxhQkYAo6wV7e1Vb8cAPvpCk9jGam/82g==}
engines: {node: '>= 0.4'}
@@ -8336,6 +8370,15 @@ packages:
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
engines: {node: '>=0.10.0'}
+ resolution: {integrity: sha512-jYa6Q9rH90kR1vKB6NM7qqd1mge3Fx4Dhw5TVlK1MUBqhEOuCagrEHMevNuCcbECmXZ0ThXkRm+Ymr51HwEPAw==}
+ engines: {node: '>=20'}
+
+ resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==}
+ engines: {node: '>=14.16'}
+ hasBin: true
+
resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==}
engines: {node: '>=8'}
@@ -8458,6 +8501,10 @@ packages:
resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==}
engines: {node: '>=8'}
+ resolution: {integrity: sha512-e6rvdUCiQCAuumZslxRJWR/Doq4VpPR82kqclvcS0efgt430SlGIk05vdCN58+VrzgtIcfNODjozVielycD4Sw==}
+ engines: {node: '>=16'}
+
resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==}
@@ -9616,6 +9663,10 @@ packages:
resolution: {integrity: sha512-vCseG/EQ6/RcvxhUcGJiHViOgrtz4x0XbZepXvKik66TMGkvbmjeJrKFyBEx6daG5rNyyd14zYXhz0hZVwQFOw==}
+ resolution: {integrity: sha512-++Zlftm0kVLPmzC06t6epuWmcRMDbI4z5P3NNX979WA/k23+NtSOynEGzsVfZwguKw2mi5umVgnBlJQMwRz4Pg==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==}
engines: {node: '>=12'}
@@ -9952,6 +10003,14 @@ packages:
resolution: {integrity: sha512-pcaShQc1Shq0y+E7GqJqvZj8DTthWV1KeHGdi0Z6IAin2Oi3JnLCOfwnCo84qc+HAp52wT9nK9H7FAJp5a44GQ==}
+ resolution: {integrity: sha512-dM0jVuXJPsDN6DvRpea484tCUaMiXWjuCn++HGTqUWzGDjv5tZkEZldAJ/UMlqRYGFrD/etByo4/xOuC/snX2A==}
+ engines: {node: '>=20'}
+
+ resolution: {integrity: sha512-C+y9x90UElAddDZmV4qOx9W53B61PO7cIqWz2dQsWlwswuq4mr8NEwytdGKboYbQlGZ3awrkTeNvcZiZNHnQ8A==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-qit+qSMiZ41K0EQkLNa3MSxnWVCm5yXvy9m3CcGf/zF1QhVJzSwVCbpiz52VSbWpg8v8nYNIYDrXJZPNFpM1uw==}
peerDependencies:
@@ -10425,6 +10484,10 @@ packages:
resolution: {integrity: sha512-hM3dHSBMeaJ0Ktp7W38BJZ7O1zOgaFEsn41PDk+yHoEtfLV+PoJt9E9xAlZiWgf/iqEqionN0ebHFZIDAp+iGw==}
+ resolution: {integrity: sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q==}
+ engines: {node: '>=18'}
+
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
@@ -11601,6 +11664,10 @@ packages:
resolution: {integrity: sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==}
engines: {node: '>=14.0.0'}
+ resolution: {integrity: sha512-qETYf9PCl1lVfwR+oBmMfc4vP2nqLNA35ABxorw3j06+xlKRgDVxbLgKm4Y/xPL0YWdeDjLoI4ImICIT3nB0zQ==}
+ engines: {node: '>=14.0.0'}
+
resolution: {integrity: sha512-mb1bvRJN8SVznADSGWM9u/b07H7Ecg0I3OgXDuLdn307rl/J3A9YD6/eYOssqhecL27hK1IPZAsaqh00i/Jljg==}
@@ -11777,6 +11844,10 @@ packages:
utf-8-validate:
optional: true
+ resolution: {integrity: sha512-Hl0ZOAs672vg+06kfujwRhoS6/jehvULrlFkuF2dRu6pHgA8U06h3xqNIqNNU1LTXPcedxByAR4GS6pwQK0mgA==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-iyVMTXb37BQAbsPHCuPzrK3ZxnO9pZmvbKl7VJWIHe3RG40On2NyP2FOjArtOITO96plEYnh3o+iUlRp9qE90w==}
engines: {bun: '>=1.2.0', node: '>=22'}
@@ -11982,6 +12053,18 @@ snapshots:
'@adobe/[email protected]': {}
+ '@agentclientprotocol/[email protected]':
+ dependencies:
+ '@agentclientprotocol/sdk': 1.5.0([email protected])
+ diff: 9.0.0
+ open: 11.0.4
+ vscode-jsonrpc: 9.0.3
+ zod: 4.6.5
+
+ '@agentclientprotocol/[email protected]([email protected])':
+ dependencies:
+ zod: 4.6.5
+
dependencies:
'@ai-sdk/provider': 4.0.17
@@ -18497,6 +18580,10 @@ snapshots:
readable-stream: 3.6.2
yerror: 8.0.0
+ dependencies:
+ run-applescript: 7.1.0
+
dependencies:
streamsearch: 1.1.0
@@ -19322,6 +19409,13 @@ snapshots:
+
+ dependencies:
+ bundle-name: 4.1.1
+ default-browser-id: 5.0.1
+
dependencies:
clone: 1.0.4
@@ -19336,6 +19430,8 @@ snapshots:
+
dependencies:
define-data-property: 1.1.4
@@ -21043,6 +21139,8 @@ snapshots:
+
dependencies:
call-bound: 1.0.4
@@ -21069,6 +21167,12 @@ snapshots:
dependencies:
is-extglob: 2.1.1
+
+ dependencies:
+ is-docker: 3.0.0
+
@@ -21170,6 +21274,10 @@ snapshots:
dependencies:
is-docker: 2.2.1
+ dependencies:
+ is-inside-container: 1.0.0
+
@@ -22505,6 +22613,15 @@ snapshots:
+ dependencies:
+ default-browser: 5.5.1
+ define-lazy-prop: 3.0.0
+ is-in-ssh: 1.0.0
+ is-inside-container: 1.0.0
+ powershell-utils: 0.2.1
+ wsl-utils: 1.0.0
+
dependencies:
define-lazy-prop: 2.0.0
@@ -22822,6 +22939,10 @@ snapshots:
+
+
dependencies:
preact: 10.29.8([email protected])
@@ -23372,6 +23493,8 @@ snapshots:
dependencies:
tslib: 2.8.1
+
dependencies:
queue-microtask: 1.2.3
@@ -24720,6 +24843,8 @@ snapshots:
+
dependencies:
vscode-jsonrpc: 8.2.0
@@ -24938,6 +25063,11 @@ snapshots:
+ dependencies:
+ is-wsl: 3.1.1
+ powershell-utils: 0.1.0
+
dependencies:
'@1natsu/wait-element': 4.2.0
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 28c912468d..b40e22cf74 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -39,6 +39,9 @@ overrides:
# built by one provider stops being assignable to the ToolSet `ai` expects (TS2322 on the Anthropic
# web-search tool). Pin the version `ai` itself is built against, and raise it with the next bump.
"@ai-sdk/provider-utils": "5.0.45"
+ # The Codex provider runs the adapter against the user's own `codex` (CODEX_PATH), so the
+ # 300-400 MB native Codex build the adapter depends on is never used.
+ "@agentclientprotocol/codex-acp>@openai/codex": "-"
"zod": "4.6.5"
"mermaid": "12.0.0"
"preact": "10.29.8"
diff --git a/scripts/build-utils.ts b/scripts/build-utils.ts
index e14cce3044..f3389b3d7a 100644
--- a/scripts/build-utils.ts
+++ b/scripts/build-utils.ts
@@ -85,7 +85,11 @@ export default class BuildHelper {
// the require.resolve branch is unreachable, but esbuild
// still sees the static string and warns. External marker
// suppresses the warning without changing runtime behavior.
- "@triliumnext/core/src/assets/*"
+ "@triliumnext/core/src/assets/*",
+ // The Codex ACP adapter is copied to RESOURCE_DIR/codex-acp.mjs by the
+ // build; codex_binary.ts only require.resolve()s the package when running
+ // from source.
+ "@agentclientprotocol/codex-acp"
],
metafile: true,
loader: {