@agentchatme/agent-core 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,545 @@
1
+ import {
2
+ VERSION,
3
+ hostedMcpUrl
4
+ } from "./chunk-XDWBTX5J.js";
5
+ import {
6
+ spawnRun
7
+ } from "./chunk-AE4XHKHQ.js";
8
+ import {
9
+ atomicWriteFile,
10
+ clientHeadersOf,
11
+ log,
12
+ spawnCommandSync
13
+ } from "./chunk-QDM4EFI7.js";
14
+
15
+ // src/presets/claude-code.ts
16
+ import * as fs from "fs";
17
+ import * as os from "os";
18
+ import * as path from "path";
19
+
20
+ // src/presets/semver.ts
21
+ function semverAtLeast(actual, minimum) {
22
+ const parse = (value) => {
23
+ const match = value.match(/(\d+)\.(\d+)\.(\d+)/);
24
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
25
+ };
26
+ const a = parse(actual);
27
+ const b = parse(minimum);
28
+ if (a === null || b === null) return false;
29
+ for (let index = 0; index < 3; index++) {
30
+ if (a[index] !== b[index]) return (a[index] ?? 0) > (b[index] ?? 0);
31
+ }
32
+ return true;
33
+ }
34
+
35
+ // src/presets/types.ts
36
+ function withoutInheritedKey(env) {
37
+ const copy = { ...env };
38
+ delete copy["AGENTCHAT_API_KEY"];
39
+ return copy;
40
+ }
41
+
42
+ // src/presets/claude-code.ts
43
+ var CLAUDE_CODE_PRESET = "claude-code";
44
+ var MIN_CLAUDE_CODE_VERSION = "2.1.274";
45
+ var CLAUDE_MCP_SERVER_NAME = "agentchat";
46
+ var AGENTCHAT_TOOL_ALLOW = `mcp__${CLAUDE_MCP_SERVER_NAME}__*`;
47
+ var ANSWER_TOOLS = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
48
+ var WORK_TOOLS = ["Bash", "Edit", "Write", "MultiEdit", "NotebookEdit"];
49
+ var PARENT_ENV_KEYS = [
50
+ "CLAUDECODE",
51
+ "CLAUDE_CODE_CHILD_SESSION",
52
+ "CLAUDE_CODE_SESSION_ID",
53
+ "CLAUDE_CODE_ENTRYPOINT",
54
+ "CLAUDE_CODE_EXECPATH",
55
+ "CLAUDE_CODE_EFFORT_LEVEL",
56
+ "CLAUDE_EFFORT",
57
+ "AI_AGENT"
58
+ ];
59
+ var MCP_STARTUP_WAIT_MS = "15000";
60
+ function claudeConfigDirFrom(env = process.env) {
61
+ const override = env["CLAUDE_CONFIG_DIR"];
62
+ return override !== void 0 && override.trim().length > 0 ? path.resolve(override) : void 0;
63
+ }
64
+ function claudeHomeFor(configDirOverride) {
65
+ return configDirOverride ?? path.join(os.homedir(), ".claude");
66
+ }
67
+ function claudeUserStatePathFor(configDirOverride) {
68
+ return configDirOverride !== void 0 ? path.join(configDirOverride, ".claude.json") : path.join(os.homedir(), ".claude.json");
69
+ }
70
+ function claudeProcessEnv(configDirOverride, source) {
71
+ const env = { ...source };
72
+ if (configDirOverride === void 0) delete env["CLAUDE_CONFIG_DIR"];
73
+ else env["CLAUDE_CONFIG_DIR"] = configDirOverride;
74
+ return env;
75
+ }
76
+ function buildClaudeEnv(configDirOverride, source = process.env) {
77
+ const env = claudeProcessEnv(configDirOverride, source);
78
+ for (const key of PARENT_ENV_KEYS) delete env[key];
79
+ env["DISABLE_AUTOUPDATER"] = "1";
80
+ const wait = Number(env["CLAUDE_CODE_MCP_STARTUP_WAIT_MS"]);
81
+ if (!Number.isFinite(wait) || wait < Number(MCP_STARTUP_WAIT_MS)) env["CLAUDE_CODE_MCP_STARTUP_WAIT_MS"] = MCP_STARTUP_WAIT_MS;
82
+ return env;
83
+ }
84
+ function claudeIsLoggedIn(configDirOverride, command = "claude") {
85
+ const status = spawnCommandSync(command, ["auth", "status"], {
86
+ encoding: "utf-8",
87
+ timeout: 1e4,
88
+ windowsHide: true,
89
+ env: claudeProcessEnv(configDirOverride, process.env)
90
+ });
91
+ if (!status.error) {
92
+ try {
93
+ const parsed = JSON.parse(String(status.stdout ?? "").trim());
94
+ if (typeof parsed?.loggedIn === "boolean") return parsed.loggedIn;
95
+ } catch {
96
+ }
97
+ if (status.status === 0) return true;
98
+ }
99
+ const configDir = claudeHomeFor(configDirOverride);
100
+ if (fs.existsSync(path.join(configDir, ".credentials.json"))) return true;
101
+ if (process.platform !== "darwin") return false;
102
+ const keychain = spawnCommandSync("security", ["find-generic-password", "-s", "Claude Code-credentials"], {
103
+ encoding: "utf-8",
104
+ timeout: 5e3
105
+ });
106
+ return !keychain.error && keychain.status === 0;
107
+ }
108
+ function inspectClaudeRuntime(configDirOverride, command = "claude") {
109
+ const version = spawnCommandSync(command, ["--version"], {
110
+ encoding: "utf-8",
111
+ timeout: 1e4,
112
+ windowsHide: true,
113
+ env: claudeProcessEnv(configDirOverride, process.env)
114
+ });
115
+ if (version.error) return { ok: false, detail: `claude CLI not found on PATH (${version.error.message})` };
116
+ const rendered = String(version.stdout || version.stderr).trim();
117
+ if (version.status !== 0) return { ok: false, detail: rendered || `claude --version exited ${version.status}` };
118
+ return semverAtLeast(rendered, MIN_CLAUDE_CODE_VERSION) ? { ok: true, detail: rendered } : {
119
+ ok: false,
120
+ detail: `${rendered || "unrecognized version"}; AgentChat requires Claude Code >= ${MIN_CLAUDE_CODE_VERSION} (for --permission-prompts none and CLAUDE_CODE_MCP_STARTUP_WAIT_MS)`
121
+ };
122
+ }
123
+ function deniedAncestorOf(dir, denied) {
124
+ const target = path.resolve(dir);
125
+ for (const raw of denied) {
126
+ const root = path.resolve(raw);
127
+ if (target === root || target.startsWith(root.endsWith(path.sep) ? root : root + path.sep)) return root;
128
+ }
129
+ return null;
130
+ }
131
+ function claudeProfileArgs(profile) {
132
+ switch (profile) {
133
+ case "answer":
134
+ return [
135
+ "--permission-mode",
136
+ "default",
137
+ "--permission-prompts",
138
+ "none",
139
+ "--tools",
140
+ ANSWER_TOOLS.join(","),
141
+ "--allowedTools",
142
+ [AGENTCHAT_TOOL_ALLOW, ...ANSWER_TOOLS].join(",")
143
+ ];
144
+ case "work":
145
+ return [
146
+ "--permission-mode",
147
+ "acceptEdits",
148
+ "--permission-prompts",
149
+ "none",
150
+ "--allowedTools",
151
+ [AGENTCHAT_TOOL_ALLOW, ...ANSWER_TOOLS, ...WORK_TOOLS].join(",")
152
+ ];
153
+ case "full":
154
+ return ["--dangerously-skip-permissions", "--permission-prompts", "none", "--allowedTools", AGENTCHAT_TOOL_ALLOW];
155
+ }
156
+ }
157
+ function expressible(raw) {
158
+ return raw.startsWith("/") && !/[,\s]/.test(raw);
159
+ }
160
+ function inexpressibleDenyPaths(paths) {
161
+ return process.platform === "win32" ? [...paths] : paths.filter((p) => !expressible(p));
162
+ }
163
+ function readDenyRules(paths) {
164
+ if (process.platform === "win32") return [];
165
+ const rules = [];
166
+ for (const raw of paths) {
167
+ if (!expressible(raw)) continue;
168
+ const clean = raw.replace(/\/+$/, "");
169
+ rules.push(`Read(/${clean})`, `Read(/${clean}/**)`);
170
+ }
171
+ return rules;
172
+ }
173
+ function claudeRunArgs(profile, options = {}) {
174
+ const budget = options.maxBudgetUsd?.trim();
175
+ const deny = readDenyRules(options.denyReadPaths ?? []);
176
+ return [
177
+ "-p",
178
+ "--output-format",
179
+ "text",
180
+ // A wake run is not a conversation to resume; keep it out of the user's
181
+ // session list and off the disk.
182
+ "--no-session-persistence",
183
+ ...budget !== void 0 && /^\d+(\.\d+)?$/.test(budget) ? ["--max-budget-usd", budget] : [],
184
+ // Variadic, so it is closed by the boolean flag right after it.
185
+ ...options.mcpConfigPath !== void 0 ? ["--mcp-config", options.mcpConfigPath, "--strict-mcp-config"] : [],
186
+ ...claudeProfileArgs(profile),
187
+ // Last: the option is variadic and the prompt arrives on stdin, so there
188
+ // is no positional for it to swallow.
189
+ ...deny.length > 0 ? ["--disallowedTools", deny.join(",")] : []
190
+ ];
191
+ }
192
+ function claudeMcpConfig(apiBase, apiKey, clientVersion = VERSION) {
193
+ const headers = { Authorization: `Bearer ${apiKey}`, ...clientHeadersOf({ runtime: "claude-code", version: clientVersion }) };
194
+ return `${JSON.stringify({ mcpServers: { [CLAUDE_MCP_SERVER_NAME]: { type: "http", url: hostedMcpUrl(apiBase), headers } } }, null, 2)}
195
+ `;
196
+ }
197
+ var ClaudeRunner = class {
198
+ constructor(options) {
199
+ this.options = options;
200
+ this.command = options.command ?? "claude";
201
+ }
202
+ options;
203
+ name = "claude";
204
+ command;
205
+ /** The workdir warning is one line per process, not one per preflight (preflight repeats every few minutes). */
206
+ warnedWorkdir = false;
207
+ warnedDeny = false;
208
+ /** The denied path the configured workdir sits in, or null when the run can read its own cwd. */
209
+ workdirDeniedBy() {
210
+ return deniedAncestorOf(this.options.workdir, this.options.denyReadPaths);
211
+ }
212
+ async preflight() {
213
+ const runtime = inspectClaudeRuntime(this.options.configDir, this.command);
214
+ if (!runtime.ok) return { ok: false, detail: runtime.detail };
215
+ if (!claudeIsLoggedIn(this.options.configDir, this.command)) {
216
+ return { ok: false, detail: "claude is not signed in (run `claude` once and sign in)" };
217
+ }
218
+ const denied = this.workdirDeniedBy();
219
+ if (denied !== null && !this.warnedWorkdir) {
220
+ this.warnedWorkdir = true;
221
+ log.warn(
222
+ `the run workdir ${this.options.workdir} is inside ${denied}, which every run's file tools are denied: runs cannot read their own working directory.${this.options.workdirAdvice ? ` ${this.options.workdirAdvice}` : ""}`
223
+ );
224
+ }
225
+ const uncovered = inexpressibleDenyPaths(this.options.denyReadPaths);
226
+ if (uncovered.length > 0) {
227
+ const why = process.platform === "win32" ? `Claude Code's rule syntax for Windows paths is undocumented, so no read-deny rule is given for ${uncovered.join(", ")}` : `no read-deny rule can carry ${uncovered.join(", ")} (a comma or whitespace in the path)`;
228
+ if (this.options.inexpressibleDeny === "refuse") return { ok: false, detail: `${why}: a run could read the key there. Use an identity home whose path has no comma or whitespace (--home).` };
229
+ if (!this.warnedDeny) {
230
+ this.warnedDeny = true;
231
+ log.warn(`${why}: runs can read those paths.`);
232
+ }
233
+ }
234
+ if (this.options.mcpConfigPath !== void 0 && !fs.existsSync(this.options.mcpConfigPath)) {
235
+ return { ok: false, detail: `the hosted tool config ${this.options.mcpConfigPath} is missing` };
236
+ }
237
+ fs.mkdirSync(this.options.workdir, { recursive: true, mode: 448 });
238
+ return { ok: true };
239
+ }
240
+ /** The exact argv one run uses — exported for tests to pin per profile. */
241
+ args() {
242
+ return claudeRunArgs(this.options.profile, {
243
+ maxBudgetUsd: (this.options.env ?? process.env)["AGENTCHAT_RUN_MAX_BUDGET_USD"],
244
+ denyReadPaths: this.options.denyReadPaths,
245
+ mcpConfigPath: this.options.mcpConfigPath
246
+ });
247
+ }
248
+ async start(request) {
249
+ const args = this.args();
250
+ log.debug(`claude ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId})`);
251
+ return spawnRun({
252
+ command: this.command,
253
+ args,
254
+ cwd: this.options.workdir,
255
+ env: buildClaudeEnv(this.options.configDir, this.options.env ?? process.env),
256
+ stdin: request.prompt,
257
+ budgetMs: request.budgetMs,
258
+ // Stopping SIGTERMs this run's process group instead of orphaning it.
259
+ ...request.signal ? { signal: request.signal } : {},
260
+ // The engine records a group invite as offered the moment the process
261
+ // has spawned, so a run cut short still counts as the one offer.
262
+ ...request.onStarted ? { onStarted: request.onStarted } : {}
263
+ });
264
+ }
265
+ };
266
+ function claudeMcpConfigPath(home) {
267
+ return path.join(home, "presets", `${CLAUDE_CODE_PRESET}.mcp.json`);
268
+ }
269
+ var claudeCodePreset = {
270
+ name: CLAUDE_CODE_PRESET,
271
+ describeMcp({ home, apiBase }) {
272
+ return [
273
+ `--mcp-config ${claudeMcpConfigPath(home)} (owner-only): ${CLAUDE_MCP_SERVER_NAME} \u2192 ${hostedMcpUrl(apiBase)}, Authorization: Bearer <this home's key>, X-AgentChat-Client: claude-code`,
274
+ "--strict-mcp-config: no other MCP server (user, project or plugin) is loaded in these runs"
275
+ ];
276
+ },
277
+ label: "Claude Code",
278
+ runtime: "claude-code",
279
+ // Every run's file tools are denied the identity home.
280
+ serviceEnv: ["CLAUDE_CONFIG_DIR"],
281
+ readsIdentityHome: false,
282
+ inspect(env = process.env, command = "claude") {
283
+ const configDir = claudeConfigDirFrom(env);
284
+ const runtime = inspectClaudeRuntime(configDir, command);
285
+ if (!runtime.ok) return runtime;
286
+ return claudeIsLoggedIn(configDir, command) ? { ok: true, detail: `${runtime.detail}, signed in` } : { ok: false, detail: `${runtime.detail}, not signed in (run \`claude\` once and sign in)` };
287
+ },
288
+ runner(ctx) {
289
+ const env = withoutInheritedKey(ctx.env ?? process.env);
290
+ const configDir = claudeConfigDirFrom(env);
291
+ const mcpConfigPath = claudeMcpConfigPath(ctx.home);
292
+ atomicWriteFile(mcpConfigPath, claudeMcpConfig(ctx.apiBase, ctx.apiKey, ctx.clientVersion ?? VERSION), 384);
293
+ return new ClaudeRunner({
294
+ configDir,
295
+ workdir: ctx.workdir,
296
+ profile: ctx.profile,
297
+ // The listener's home (its key and this file), the user-scope MCP state
298
+ // and an integration's identity home beside it: no run reads a key.
299
+ denyReadPaths: [ctx.home, claudeUserStatePathFor(configDir), path.join(claudeHomeFor(configDir), "agentchat")],
300
+ mcpConfigPath,
301
+ workdirAdvice: "Start the listener from a directory outside it, or pass --workdir.",
302
+ // On POSIX a listener's run must not start with its key readable; on
303
+ // Windows no rule exists at all (documented), so it warns.
304
+ inexpressibleDeny: process.platform === "win32" ? "warn" : "refuse",
305
+ ...ctx.command !== void 0 ? { command: ctx.command } : {},
306
+ env
307
+ });
308
+ }
309
+ };
310
+
311
+ // src/presets/codex.ts
312
+ import * as fs2 from "fs";
313
+ import * as os2 from "os";
314
+ import * as path2 from "path";
315
+ var CODEX_PRESET = "codex";
316
+ var MIN_CODEX_VERSION = "0.154.0";
317
+ var CODEX_MCP_SERVER_NAME = "agentchat";
318
+ var LISTENER_KEY_ENV = "AGENTCHAT_LISTENER_API_KEY";
319
+ var CODEX_PROMPT_FROM_STDIN = "-";
320
+ function codexHomeFrom(env = process.env) {
321
+ const override = env["CODEX_HOME"];
322
+ if (override !== void 0 && override.trim().length > 0) return path2.resolve(override);
323
+ return path2.join(os2.homedir(), ".codex");
324
+ }
325
+ function inspectCodexRuntime(codexHome, command = "codex") {
326
+ const result = spawnCommandSync(command, ["--version"], {
327
+ encoding: "utf-8",
328
+ timeout: 1e4,
329
+ windowsHide: true,
330
+ env: { ...process.env, CODEX_HOME: codexHome }
331
+ });
332
+ if (result.error) return { ok: false, detail: `codex CLI not found on PATH (${result.error.message})` };
333
+ const rendered = String(result.stdout || result.stderr).trim();
334
+ if (result.status !== 0) return { ok: false, detail: rendered || `codex --version exited ${result.status}` };
335
+ return semverAtLeast(rendered, MIN_CODEX_VERSION) ? { ok: true, detail: rendered } : { ok: false, detail: `${rendered || "unrecognized version"}; AgentChat requires Codex >= ${MIN_CODEX_VERSION}` };
336
+ }
337
+ function codexIsLoggedIn(codexHome, command = "codex") {
338
+ const status = spawnCommandSync(command, ["login", "status"], {
339
+ encoding: "utf-8",
340
+ timeout: 1e4,
341
+ windowsHide: true,
342
+ env: { ...process.env, CODEX_HOME: codexHome }
343
+ });
344
+ if (status.error) return { ok: false, detail: status.error.message };
345
+ const detail = `${status.stdout ?? ""}${status.stderr ?? ""}`.trim().slice(0, 200);
346
+ return status.status === 0 ? { ok: true, detail: detail || "signed in" } : { ok: false, detail: detail || "codex is not signed in (run `codex login`)" };
347
+ }
348
+ function codexProfileArgs(profile) {
349
+ switch (profile) {
350
+ case "answer":
351
+ return ["--sandbox", "read-only", "-c", 'approval_policy="never"'];
352
+ case "work":
353
+ return ["--sandbox", "workspace-write", "-c", 'approval_policy="never"'];
354
+ case "full":
355
+ return ["--dangerously-bypass-approvals-and-sandbox"];
356
+ }
357
+ }
358
+ function codexClientHeadersToml(clientVersion = VERSION) {
359
+ const pairs = Object.entries(clientHeadersOf({ runtime: "codex", version: clientVersion })).map(([name, value]) => `${JSON.stringify(name)} = ${JSON.stringify(value)}`);
360
+ return `{ ${pairs.join(", ")} }`;
361
+ }
362
+ function codexMcpOverrideArgs(override) {
363
+ const table = `mcp_servers.${CODEX_MCP_SERVER_NAME}`;
364
+ return [
365
+ "-c",
366
+ `${table}.url=${JSON.stringify(override.url)}`,
367
+ "-c",
368
+ `${table}.bearer_token_env_var=${JSON.stringify(override.keyEnv)}`,
369
+ "-c",
370
+ `${table}.default_tools_approval_mode="approve"`,
371
+ "-c",
372
+ `${table}.http_headers=${codexClientHeadersToml(override.clientVersion ?? VERSION)}`
373
+ ];
374
+ }
375
+ function codexRunArgs(profile, options) {
376
+ return [
377
+ "exec",
378
+ "--json",
379
+ "--skip-git-repo-check",
380
+ "--ephemeral",
381
+ "-C",
382
+ options.workdir,
383
+ ...codexProfileArgs(profile),
384
+ ...options.mcp !== void 0 ? codexMcpOverrideArgs(options.mcp) : [],
385
+ CODEX_PROMPT_FROM_STDIN
386
+ ];
387
+ }
388
+ var CodexRunner = class {
389
+ constructor(options) {
390
+ this.options = options;
391
+ this.command = options.command ?? "codex";
392
+ }
393
+ options;
394
+ name = "codex";
395
+ command;
396
+ async preflight() {
397
+ const runtime = inspectCodexRuntime(this.options.codexHome, this.command);
398
+ if (!runtime.ok) return { ok: false, detail: runtime.detail };
399
+ const auth = codexIsLoggedIn(this.options.codexHome, this.command);
400
+ if (!auth.ok) return { ok: false, detail: `codex login status failed: ${auth.detail}` };
401
+ fs2.mkdirSync(this.options.workdir, { recursive: true });
402
+ return { ok: true };
403
+ }
404
+ /** The exact argv one run uses — exported for tests to pin per profile. */
405
+ args() {
406
+ return codexRunArgs(this.options.profile, { workdir: this.options.workdir, ...this.options.mcp !== void 0 ? { mcp: this.options.mcp } : {} });
407
+ }
408
+ /** The child environment: Codex's home and the key the hosted server needs, under the configured name. */
409
+ env() {
410
+ const env = { ...this.options.env ?? process.env, CODEX_HOME: this.options.codexHome };
411
+ const key = this.options.apiKey();
412
+ if (key !== null) env[this.options.keyEnv] = key;
413
+ return env;
414
+ }
415
+ async start(request) {
416
+ const args = this.args();
417
+ log.debug(`codex ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId})`);
418
+ return spawnRun({
419
+ command: this.command,
420
+ args,
421
+ cwd: this.options.workdir,
422
+ env: this.env(),
423
+ // Written to stdin and then closed: `codex exec -` reads its
424
+ // instructions until EOF. Never as an argument (see codexRunArgs).
425
+ stdin: request.prompt,
426
+ budgetMs: request.budgetMs,
427
+ ...request.signal ? { signal: request.signal } : {},
428
+ ...request.onStarted ? { onStarted: request.onStarted } : {}
429
+ });
430
+ }
431
+ };
432
+ function agentchatTableKeys(configToml) {
433
+ const lines = configToml.split(/\r?\n/);
434
+ const header = new RegExp(`^\\s*\\[mcp_servers\\.${CODEX_MCP_SERVER_NAME}\\]\\s*(#.*)?$`);
435
+ const start = lines.findIndex((line) => header.test(line));
436
+ if (start < 0) return null;
437
+ const keys = [];
438
+ for (const line of lines.slice(start + 1)) {
439
+ if (/^\s*\[/.test(line)) break;
440
+ const match = /^\s*([A-Za-z0-9_.-]+)\s*=/.exec(line);
441
+ if (match?.[1] !== void 0) keys.push(match[1]);
442
+ }
443
+ return keys;
444
+ }
445
+ var codexPreset = {
446
+ name: CODEX_PRESET,
447
+ describeMcp({ apiBase, env = process.env }) {
448
+ const file = path2.join(codexHomeFrom(env), "config.toml");
449
+ let own = null;
450
+ try {
451
+ own = agentchatTableKeys(fs2.readFileSync(file, "utf-8"));
452
+ } catch {
453
+ own = null;
454
+ }
455
+ return [
456
+ `-c mcp_servers.${CODEX_MCP_SERVER_NAME}.url="${hostedMcpUrl(apiBase)}"`,
457
+ `-c mcp_servers.${CODEX_MCP_SERVER_NAME}.bearer_token_env_var="${LISTENER_KEY_ENV}" (the key set in the run's environment, never on argv)`,
458
+ `-c mcp_servers.${CODEX_MCP_SERVER_NAME}.default_tools_approval_mode="approve"`,
459
+ `-c mcp_servers.${CODEX_MCP_SERVER_NAME}.http_headers={ "X-AgentChat-Client" = "codex", "X-AgentChat-Client-Version" = <the listener's version> } (names the runtime to the hosted tools)`,
460
+ own === null ? `${file}: no [mcp_servers.${CODEX_MCP_SERVER_NAME}] of its own \u2014 the run sees only the overrides above` : `${file}: [mcp_servers.${CODEX_MCP_SERVER_NAME}] also sets ${own.length > 0 ? own.join(", ") : "nothing"}; the overrides above replace their keys, the others still apply (how codex merges -c over an existing table is not verified on a real codex)`
461
+ ];
462
+ },
463
+ label: "Codex",
464
+ runtime: "codex",
465
+ // A read-only sandbox reads the whole filesystem.
466
+ serviceEnv: ["CODEX_HOME"],
467
+ readsIdentityHome: true,
468
+ inspect(env = process.env, command = "codex") {
469
+ const home = codexHomeFrom(env);
470
+ const runtime = inspectCodexRuntime(home, command);
471
+ if (!runtime.ok) return runtime;
472
+ const auth = codexIsLoggedIn(home, command);
473
+ return auth.ok ? { ok: true, detail: `${runtime.detail}, signed in` } : { ok: false, detail: `${runtime.detail}, not signed in: ${auth.detail}` };
474
+ },
475
+ runner(ctx) {
476
+ const env = withoutInheritedKey(ctx.env ?? process.env);
477
+ const apiKey = ctx.apiKey;
478
+ return new CodexRunner({
479
+ codexHome: codexHomeFrom(env),
480
+ workdir: ctx.workdir,
481
+ profile: ctx.profile,
482
+ apiKey: () => apiKey,
483
+ keyEnv: LISTENER_KEY_ENV,
484
+ mcp: { url: hostedMcpUrl(ctx.apiBase), keyEnv: LISTENER_KEY_ENV, clientVersion: ctx.clientVersion ?? VERSION },
485
+ ...ctx.command !== void 0 ? { command: ctx.command } : {},
486
+ env
487
+ });
488
+ }
489
+ };
490
+
491
+ // src/presets/index.ts
492
+ var PRESETS = Object.freeze({
493
+ [claudeCodePreset.name]: claudeCodePreset,
494
+ [codexPreset.name]: codexPreset
495
+ });
496
+ function presetNamed(name) {
497
+ return Object.prototype.hasOwnProperty.call(PRESETS, name) ? PRESETS[name] ?? null : null;
498
+ }
499
+ function presetNames() {
500
+ return Object.keys(PRESETS);
501
+ }
502
+ export {
503
+ AGENTCHAT_TOOL_ALLOW,
504
+ ANSWER_TOOLS,
505
+ CLAUDE_CODE_PRESET,
506
+ CLAUDE_MCP_SERVER_NAME,
507
+ CODEX_MCP_SERVER_NAME,
508
+ CODEX_PRESET,
509
+ CODEX_PROMPT_FROM_STDIN,
510
+ ClaudeRunner,
511
+ CodexRunner,
512
+ LISTENER_KEY_ENV,
513
+ MIN_CLAUDE_CODE_VERSION,
514
+ MIN_CODEX_VERSION,
515
+ PARENT_ENV_KEYS,
516
+ PRESETS,
517
+ WORK_TOOLS,
518
+ agentchatTableKeys,
519
+ buildClaudeEnv,
520
+ claudeCodePreset,
521
+ claudeConfigDirFrom,
522
+ claudeHomeFor,
523
+ claudeIsLoggedIn,
524
+ claudeMcpConfig,
525
+ claudeMcpConfigPath,
526
+ claudeProfileArgs,
527
+ claudeRunArgs,
528
+ claudeUserStatePathFor,
529
+ codexClientHeadersToml,
530
+ codexHomeFrom,
531
+ codexIsLoggedIn,
532
+ codexMcpOverrideArgs,
533
+ codexPreset,
534
+ codexProfileArgs,
535
+ codexRunArgs,
536
+ deniedAncestorOf,
537
+ inexpressibleDenyPaths,
538
+ inspectClaudeRuntime,
539
+ inspectCodexRuntime,
540
+ presetNamed,
541
+ presetNames,
542
+ readDenyRules,
543
+ semverAtLeast
544
+ };
545
+ //# sourceMappingURL=presets.js.map