Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

codexLaunchArgs.ts

53 lines1.9 KB

1import { tokenizeCliArgs } from "@t3tools/shared/cliArgs";
2​
3export const T3CODE_CODEX_LAUNCH_ARGS_ENV = "T3CODE_CODEX_LAUNCH_ARGS";
4export const T3CODE_CODEX_APPEND_LAUNCH_ARGS_ENV = "T3CODE_CODEX_APPEND_LAUNCH_ARGS";
5​
6export const resolveCodexLaunchArgs = (
7 launchArgs?: string,
8 environment: NodeJS.ProcessEnv = process.env,
9) => {
10 const configured = environment[T3CODE_CODEX_LAUNCH_ARGS_ENV]?.trim() || launchArgs?.trim() || "";
11 const appended = environment[T3CODE_CODEX_APPEND_LAUNCH_ARGS_ENV]?.trim() || "";
12 return [configured, appended].filter((value) => value.length > 0).join(" ");
13};
14​
15export const codexLaunchArgv = (launchArgs?: string): ReadonlyArray<string> =>
16 tokenizeCliArgs(launchArgs);
17​
18export const codexAppServerArgs = (launchArgs?: string) => [
19 "app-server",
20 ...codexLaunchArgv(launchArgs),
21];
22​
23export const codexExecLaunchArgs = (launchArgs?: string) => {
24 const args = codexLaunchArgv(launchArgs);
25 const execArgs: Array<string> = [];
26​
27 for (let index = 0; index < args.length; index++) {
28 const arg = args[index];
29 if (arg === undefined) continue;
30​
31 if (arg === "--strict-config" || arg.startsWith("--config=") || arg.startsWith("-c=")) {
32 execArgs.push(arg);
33 } else if (arg === "--config" || arg === "-c" || arg === "--enable" || arg === "--disable") {
34 const value = args[index + 1];
35 if (value !== undefined && !value.startsWith("-")) {
36 execArgs.push(arg, value);
37 index++;
38 }
39 } else if (arg.startsWith("--enable=") || arg.startsWith("--disable=")) {
40 execArgs.push(arg);
41 }
42 }
43​
44 return execArgs;
45};
46​
47export const codexSessionAppServerArgs = (
48 appServerArgs: ReadonlyArray<string> | undefined,
49 launchArgs: string | undefined,
50) => {
51 const launchAppServerArgs = codexAppServerArgs(launchArgs);
52 return appServerArgs ? [...launchAppServerArgs, ...appServerArgs] : launchAppServerArgs;
53};