diff --git a/codex-cli/src/cli.tsx b/codex-cli/src/cli.tsx index 2f578980..da6a465a 100644 --- a/codex-cli/src/cli.tsx +++ b/codex-cli/src/cli.tsx @@ -17,7 +17,11 @@ import { AgentLoop } from "./utils/agent/agent-loop"; import { initLogger } from "./utils/agent/log"; import { ReviewDecision } from "./utils/agent/review"; import { AutoApprovalMode } from "./utils/auto-approval-mode"; -import { loadConfig, PRETTY_PRINT } from "./utils/config"; +import { + loadConfig, + PRETTY_PRINT, + INSTRUCTIONS_FILEPATH, +} from "./utils/config"; import { createInputItem } from "./utils/input-utils"; import { isModelSupportedForResponses, @@ -26,6 +30,7 @@ import { import { parseToolCall } from "./utils/parsers"; import { onExit, setInkRenderer } from "./utils/terminal"; import chalk from "chalk"; +import { spawnSync } from "child_process"; import fs from "fs"; import { render } from "ink"; import meow from "meow"; @@ -53,6 +58,7 @@ const cli = meow( -i, --image Path(s) to image files to include as input -v, --view Inspect a previously saved rollout instead of starting a session -q, --quiet Non-interactive mode that only prints the assistant's final output + -c, --config Open the instructions file in your editor -a, --approval-mode Override the approval policy: 'suggest', 'auto-edit', or 'full-auto' --auto-edit Automatically approve file edits; still prompt for commands @@ -91,6 +97,11 @@ const cli = meow( aliases: ["q"], description: "Non-interactive quiet mode", }, + config: { + type: "boolean", + aliases: ["c"], + description: "Open the instructions file in your editor", + }, dangerouslyAutoApproveEverything: { type: "boolean", description: @@ -139,9 +150,9 @@ const cli = meow( ); // Handle 'completion' subcommand before any prompting or API calls -if (cli.input[0] === 'completion') { - const shell = cli.input[1] || 'bash'; - const scripts: Record = { +if (cli.input[0] === "completion") { + const shell = cli.input[1] || "bash"; + const scripts: Record = { bash: `# bash completion for codex _codex_completion() { local cur @@ -174,6 +185,21 @@ if (cli.flags.help) { cli.showHelp(); } +// Handle config flag: open instructions file in editor and exit +if (cli.flags.config) { + // Ensure configuration and instructions file exist + try { + loadConfig(); + } catch { + // ignore errors + } + const filePath = INSTRUCTIONS_FILEPATH; + const editor = + process.env["EDITOR"] || (process.platform === "win32" ? "notepad" : "vi"); + spawnSync(editor, [filePath], { stdio: "inherit" }); + process.exit(0); +} + // --------------------------------------------------------------------------- // API key handling // ---------------------------------------------------------------------------