Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 40c0ab0

Browse files
jamesx0416juliusmarmingeroot
authored
Add Codex launch arguments setting (pingdotgg#2892)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: root <[email protected]>
1 parent 33f1cb4 commit 40c0ab0

17 files changed

Lines changed: 414 additions & 16 deletions

‎apps/server/src/provider/Layers/CodexAdapter.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ validationLayer("CodexAdapterLive validation", (it) => {
279279
NodeAssert.deepStrictEqual(validationRuntimeFactory.factory.mock.calls[0]?.[0], {
280280
binaryPath: "codex",
281281
cwd: process.cwd(),
282+
launchArgs: "",
282283
model: "gpt-5.3-codex",
283284
providerInstanceId: ProviderInstanceId.make("codex"),
284285
serviceTier: "priority",
@@ -359,6 +360,69 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
359360
}),
360361
);
361362

363+
it.effect("passes configured launch args into the session runtime", () => {
364+
const runtimeFactory = makeRuntimeFactory();
365+
const layer = Layer.effect(
366+
CodexAdapter,
367+
Effect.gen(function* () {
368+
const codexConfig = decodeCodexSettings({ launchArgs: "--strict-config --enable foo" });
369+
return yield* makeCodexAdapter(codexConfig, {
370+
makeRuntime: runtimeFactory.factory,
371+
});
372+
}),
373+
).pipe(
374+
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), process.cwd())),
375+
Layer.provideMerge(ServerSettingsService.layerTest()),
376+
Layer.provideMerge(providerSessionDirectoryTestLayer),
377+
Layer.provideMerge(NodeServices.layer),
378+
);
379+
380+
return Effect.gen(function* () {
381+
const adapter = yield* CodexAdapter;
382+
yield* adapter.startSession({
383+
provider: ProviderDriverKind.make("codex"),
384+
threadId: asThreadId("sess-launch-args"),
385+
runtimeMode: "full-access",
386+
});
387+
388+
const runtime = runtimeFactory.lastRuntime;
389+
NodeAssert.ok(runtime);
390+
NodeAssert.equal(runtime.options.launchArgs, "--strict-config --enable foo");
391+
}).pipe(Effect.provide(layer));
392+
});
393+
394+
it.effect("uses T3CODE_CODEX_LAUNCH_ARGS for the session runtime", () => {
395+
const runtimeFactory = makeRuntimeFactory();
396+
const layer = Layer.effect(
397+
CodexAdapter,
398+
Effect.gen(function* () {
399+
const codexConfig = decodeCodexSettings({ launchArgs: "--enable settings-feature" });
400+
return yield* makeCodexAdapter(codexConfig, {
401+
environment: { T3CODE_CODEX_LAUNCH_ARGS: " --strict-config --enable env-feature " },
402+
makeRuntime: runtimeFactory.factory,
403+
});
404+
}),
405+
).pipe(
406+
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), process.cwd())),
407+
Layer.provideMerge(ServerSettingsService.layerTest()),
408+
Layer.provideMerge(providerSessionDirectoryTestLayer),
409+
Layer.provideMerge(NodeServices.layer),
410+
);
411+
412+
return Effect.gen(function* () {
413+
const adapter = yield* CodexAdapter;
414+
yield* adapter.startSession({
415+
provider: ProviderDriverKind.make("codex"),
416+
threadId: asThreadId("sess-launch-args-env"),
417+
runtimeMode: "full-access",
418+
});
419+
420+
const runtime = runtimeFactory.lastRuntime;
421+
NodeAssert.ok(runtime);
422+
NodeAssert.equal(runtime.options.launchArgs, "--strict-config --enable env-feature");
423+
}).pipe(Effect.provide(layer));
424+
});
425+
362426
it.effect("maps codex model options for the adapter's bound custom instance id", () => {
363427
const customInstanceId = ProviderInstanceId.make("codex_personal");
364428
const customRuntimeFactory = makeRuntimeFactory();

‎apps/server/src/provider/Layers/CodexAdapter.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
type CodexSessionRuntimeShape,
6262
} from "./CodexSessionRuntime.ts";
6363
import { type EventNdjsonLogger, makeEventNdjsonLogger } from "./EventNdjsonLogger.ts";
64+
import { resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
6465
const isCodexAppServerProcessExitedError = Schema.is(CodexErrors.CodexAppServerProcessExitedError);
6566
const isCodexAppServerTransportError = Schema.is(CodexErrors.CodexAppServerTransportError);
6667
const isCodexSessionRuntimeThreadIdMissingError = Schema.is(
@@ -1399,6 +1400,7 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
13991400
providerInstanceId: boundInstanceId,
14001401
cwd: input.cwd ?? process.cwd(),
14011402
binaryPath: codexConfig.binaryPath,
1403+
launchArgs: resolveCodexLaunchArgs(codexConfig.launchArgs, options?.environment),
14021404
...(options?.environment ? { environment: options.environment } : {}),
14031405
...(codexConfig.homePath ? { homePath: codexConfig.homePath } : {}),
14041406
...(isCodexResumeCursorSchema(input.resumeCursor)

‎apps/server/src/provider/Layers/CodexProvider.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ServerSettingsError } from "@t3tools/contracts";
2626

2727
import { createModelCapabilities } from "@t3tools/shared/model";
2828
import { resolveSpawnCommand } from "@t3tools/shared/shell";
29+
import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
2930
import {
3031
AUTH_PROBE_TIMEOUT_MS,
3132
buildServerProvider,
@@ -289,6 +290,7 @@ export function buildCodexInitializeParams(): CodexSchema.V1InitializeParams {
289290
const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(function* (input: {
290291
readonly binaryPath: string;
291292
readonly homePath?: string;
293+
readonly launchArgs?: string;
292294
readonly cwd: string;
293295
readonly customModels?: ReadonlyArray<string>;
294296
readonly environment?: NodeJS.ProcessEnv;
@@ -303,10 +305,14 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
303305
...input.environment,
304306
...(resolvedHomePath ? { CODEX_HOME: resolvedHomePath } : {}),
305307
};
306-
const spawnCommand = yield* resolveSpawnCommand(input.binaryPath, ["app-server"], {
307-
env: environment,
308-
extendEnv: true,
309-
});
308+
const spawnCommand = yield* resolveSpawnCommand(
309+
input.binaryPath,
310+
codexAppServerArgs(input.launchArgs),
311+
{
312+
env: environment,
313+
extendEnv: true,
314+
},
315+
);
310316
const child = yield* spawner
311317
.spawn(
312318
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
@@ -465,6 +471,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
465471
probe: (input: {
466472
readonly binaryPath: string;
467473
readonly homePath?: string;
474+
readonly launchArgs?: string;
468475
readonly cwd: string;
469476
readonly customModels: ReadonlyArray<string>;
470477
readonly environment?: NodeJS.ProcessEnv;
@@ -503,6 +510,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
503510
const probeResult = yield* probe({
504511
binaryPath: codexSettings.binaryPath,
505512
homePath: codexSettings.homePath,
513+
launchArgs: resolveCodexLaunchArgs(codexSettings.launchArgs, resolvedEnvironment),
506514
cwd: process.cwd(),
507515
customModels: codexSettings.customModels,
508516
environment: resolvedEnvironment,

‎apps/server/src/provider/Layers/CodexSessionRuntime.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS,
1414
CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS,
1515
} from "../CodexDeveloperInstructions.ts";
16+
import { codexSessionAppServerArgs } from "./codexLaunchArgs.ts";
1617
import {
1718
buildTurnStartParams,
1819
hasConfiguredMcpServer,
@@ -289,6 +290,33 @@ describe("hasConfiguredMcpServer", () => {
289290
});
290291
});
291292

293+
describe("codexSessionAppServerArgs", () => {
294+
it("keeps the app-server subcommand when explicit args are provided", () => {
295+
NodeAssert.deepStrictEqual(codexSessionAppServerArgs(["-c", "model=gpt-5"], undefined), [
296+
"app-server",
297+
"-c",
298+
"model=gpt-5",
299+
]);
300+
});
301+
302+
it("keeps launch args when explicit app-server args are provided", () => {
303+
NodeAssert.deepStrictEqual(
304+
codexSessionAppServerArgs(
305+
["-c", "mcp_servers.t3-code.url=http://127.0.0.1/mcp"],
306+
"--strict-config --enable foo",
307+
),
308+
[
309+
"app-server",
310+
"--strict-config",
311+
"--enable",
312+
"foo",
313+
"-c",
314+
"mcp_servers.t3-code.url=http://127.0.0.1/mcp",
315+
],
316+
);
317+
});
318+
});
319+
292320
describe("isRecoverableThreadResumeError", () => {
293321
it("matches missing thread errors", () => {
294322
NodeAssert.equal(

‎apps/server/src/provider/Layers/CodexSessionRuntime.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as CodexRpc from "effect-codex-app-server/rpc";
3636
import * as EffectCodexSchema from "effect-codex-app-server/schema";
3737

3838
import { buildCodexInitializeParams } from "./CodexProvider.ts";
39+
import { codexSessionAppServerArgs } from "./codexLaunchArgs.ts";
3940
import { expandHomePath } from "../../pathExpansion.ts";
4041
import { buildCodexDeveloperInstructions } from "../CodexDeveloperInstructions.ts";
4142
const decodeV2TurnStartResponse = Schema.decodeUnknownEffect(EffectCodexSchema.V2TurnStartResponse);
@@ -97,6 +98,7 @@ export interface CodexSessionRuntimeOptions {
9798
readonly providerInstanceId?: ProviderInstanceId;
9899
readonly binaryPath: string;
99100
readonly homePath?: string;
101+
readonly launchArgs?: string;
100102
readonly environment?: NodeJS.ProcessEnv;
101103
readonly cwd: string;
102104
readonly runtimeMode: RuntimeMode;
@@ -717,11 +719,11 @@ export const makeCodexSessionRuntime = (
717719
...(resolvedHomePath ? { CODEX_HOME: resolvedHomePath } : {}),
718720
};
719721
const extendEnv = options.environment === undefined;
720-
const spawnCommand = yield* resolveSpawnCommand(
721-
options.binaryPath,
722-
["app-server", ...(options.appServerArgs ?? [])],
723-
{ env, extendEnv },
724-
);
722+
const appServerArgs = codexSessionAppServerArgs(options.appServerArgs, options.launchArgs);
723+
const spawnCommand = yield* resolveSpawnCommand(options.binaryPath, appServerArgs, {
724+
env,
725+
extendEnv,
726+
});
725727
const child = yield* spawner
726728
.spawn(
727729
ChildProcess.make(spawnCommand.command, spawnCommand.args, {

‎apps/server/src/provider/Layers/ProviderInstanceRegistryLive.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const makeCodexConfig = (overrides: Partial<CodexSettings>): CodexSettings => ({
6161
binaryPath: "codex",
6262
homePath: "",
6363
shadowHomePath: "",
64+
launchArgs: "",
6465
customModels: [],
6566
...overrides,
6667
});

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const encodedDefaultServerSettings = encodeServerSettings(DEFAULT_SERVER_SETTING
5555

5656
const defaultClaudeSettings: ClaudeSettings = Schema.decodeSync(ClaudeSettings)({});
5757
const defaultCodexSettings: CodexSettings = Schema.decodeSync(CodexSettings)({});
58+
const decodeCodexSettings = Schema.decodeSync(CodexSettings);
5859
const disabledCodexSettings: CodexSettings = Schema.decodeSync(CodexSettings)({
5960
enabled: false,
6061
});
@@ -348,6 +349,21 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
348349
}),
349350
);
350351

352+
it.effect("passes configured launch args to the Codex provider probe", () =>
353+
Effect.gen(function* () {
354+
let observedLaunchArgs: string | undefined;
355+
const settings = decodeCodexSettings({ launchArgs: "--strict-config --enable foo" });
356+
357+
const status = yield* checkCodexProviderStatus(settings, (input) => {
358+
observedLaunchArgs = input.launchArgs;
359+
return Effect.succeed(makeCodexProbeSnapshot());
360+
});
361+
362+
assert.strictEqual(status.status, "ready");
363+
assert.strictEqual(observedLaunchArgs, "--strict-config --enable foo");
364+
}),
365+
);
366+
351367
it.effect("returns unauthenticated when app-server requires OpenAI auth", () =>
352368
Effect.gen(function* () {
353369
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as NodeAssert from "node:assert/strict";
2+
3+
import { describe, it } from "vite-plus/test";
4+
5+
import {
6+
codexAppServerArgs,
7+
codexExecLaunchArgs,
8+
resolveCodexLaunchArgs,
9+
} from "./codexLaunchArgs.ts";
10+
11+
describe("resolveCodexLaunchArgs", () => {
12+
it("uses T3CODE_CODEX_LAUNCH_ARGS before configured settings", () => {
13+
NodeAssert.equal(
14+
resolveCodexLaunchArgs(" --strict-config ", { T3CODE_CODEX_LAUNCH_ARGS: "--enable foo" }),
15+
"--enable foo",
16+
);
17+
});
18+
19+
it("uses configured settings when T3CODE_CODEX_LAUNCH_ARGS is empty", () => {
20+
NodeAssert.equal(
21+
resolveCodexLaunchArgs(" --strict-config ", { T3CODE_CODEX_LAUNCH_ARGS: " " }),
22+
"--strict-config",
23+
);
24+
});
25+
26+
it("ignores whitespace-only environment values", () => {
27+
NodeAssert.equal(resolveCodexLaunchArgs("", { T3CODE_CODEX_LAUNCH_ARGS: " " }), "");
28+
});
29+
});
30+
31+
describe("codexAppServerArgs", () => {
32+
it("returns the app-server command for empty launch args", () => {
33+
NodeAssert.deepStrictEqual(codexAppServerArgs(""), ["app-server"]);
34+
});
35+
36+
it("appends parsed launch args after app-server", () => {
37+
NodeAssert.deepStrictEqual(codexAppServerArgs("--strict-config --enable foo"), [
38+
"app-server",
39+
"--strict-config",
40+
"--enable",
41+
"foo",
42+
]);
43+
});
44+
});
45+
46+
describe("codexExecLaunchArgs", () => {
47+
it("keeps shared codex flags and omits app-server-only flags", () => {
48+
NodeAssert.deepStrictEqual(
49+
codexExecLaunchArgs('--strict-config --enable foo --listen off --config model="gpt 5"'),
50+
["--strict-config", "--enable", "foo", "--config", "model=gpt 5"],
51+
);
52+
});
53+
54+
it("does not pair value-taking flags with adjacent flags", () => {
55+
NodeAssert.deepStrictEqual(codexExecLaunchArgs("--config --strict-config --enable --disable"), [
56+
"--strict-config",
57+
]);
58+
});
59+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { tokenizeCliArgs } from "@t3tools/shared/cliArgs";
2+
3+
export const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS";
4+
5+
export const resolveCodexLaunchArgs = (
6+
launchArgs?: string,
7+
environment: NodeJS.ProcessEnv = process.env,
8+
) => environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";
9+
10+
export const codexLaunchArgv = (launchArgs?: string): ReadonlyArray<string> =>
11+
tokenizeCliArgs(launchArgs);
12+
13+
export const codexAppServerArgs = (launchArgs?: string) => [
14+
"app-server",
15+
...codexLaunchArgv(launchArgs),
16+
];
17+
18+
export const codexExecLaunchArgs = (launchArgs?: string) => {
19+
const args = codexLaunchArgv(launchArgs);
20+
const execArgs: Array<string> = [];
21+
22+
for (let index = 0; index < args.length; index++) {
23+
const arg = args[index];
24+
if (arg === undefined) continue;
25+
26+
if (arg === "--strict-config" || arg.startsWith("--config=") || arg.startsWith("-c=")) {
27+
execArgs.push(arg);
28+
} else if (arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable") {
29+
const value = args[index + 1];
30+
if (value !== undefined && !value.startsWith("-")) {
31+
execArgs.push(arg, value);
32+
index++;
33+
}
34+
} else if (arg.startsWith("--enable=") || arg.startsWith("--disable=")) {
35+
execArgs.push(arg);
36+
}
37+
}
38+
39+
return execArgs;
40+
};
41+
42+
export const codexSessionAppServerArgs = (
43+
appServerArgs: ReadonlyArray<string> | undefined,
44+
launchArgs: string | undefined,
45+
) => {
46+
const launchAppServerArgs = codexAppServerArgs(launchArgs);
47+
return appServerArgs ? [...launchAppServerArgs, ...appServerArgs] : launchAppServerArgs;
48+
};

‎apps/server/src/serverSettings.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ it.layer(NodeServices.layer)("server settings", (it) => {
179179
binaryPath: "/opt/homebrew/bin/codex",
180180
homePath: "/Users/julius/.codex",
181181
shadowHomePath: "",
182+
launchArgs: "",
182183
customModels: [],
183184
});
184185
assert.deepEqual(next.providers.claudeAgent, {
@@ -420,6 +421,7 @@ it.layer(NodeServices.layer)("server settings", (it) => {
420421
binaryPath: "/opt/homebrew/bin/codex",
421422
homePath: "",
422423
shadowHomePath: "",
424+
launchArgs: "",
423425
customModels: [],
424426
});
425427
assert.deepEqual(next.providers.claudeAgent, {

0 commit comments

Comments
 (0)