feat: --config/-c flag to open global instructions in nvim (#158)
I promised I'd never write JavaScript code, but I never said anything about using AI to write it for me...entirely authored with `codex`. No idea how good the code is, didn't read it (sorta joking but I really don't know js/ts) closes #154 https://github.com/user-attachments/assets/94cf2276-bfcf-4ba1-ad2f-aaefebbf8f06
This commit is contained in:
@@ -17,7 +17,11 @@ import { AgentLoop } from "./utils/agent/agent-loop";
|
|||||||
import { initLogger } from "./utils/agent/log";
|
import { initLogger } from "./utils/agent/log";
|
||||||
import { ReviewDecision } from "./utils/agent/review";
|
import { ReviewDecision } from "./utils/agent/review";
|
||||||
import { AutoApprovalMode } from "./utils/auto-approval-mode";
|
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 { createInputItem } from "./utils/input-utils";
|
||||||
import {
|
import {
|
||||||
isModelSupportedForResponses,
|
isModelSupportedForResponses,
|
||||||
@@ -26,6 +30,7 @@ import {
|
|||||||
import { parseToolCall } from "./utils/parsers";
|
import { parseToolCall } from "./utils/parsers";
|
||||||
import { onExit, setInkRenderer } from "./utils/terminal";
|
import { onExit, setInkRenderer } from "./utils/terminal";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import { spawnSync } from "child_process";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { render } from "ink";
|
import { render } from "ink";
|
||||||
import meow from "meow";
|
import meow from "meow";
|
||||||
@@ -53,6 +58,7 @@ const cli = meow(
|
|||||||
-i, --image <path> Path(s) to image files to include as input
|
-i, --image <path> Path(s) to image files to include as input
|
||||||
-v, --view <rollout> Inspect a previously saved rollout instead of starting a session
|
-v, --view <rollout> Inspect a previously saved rollout instead of starting a session
|
||||||
-q, --quiet Non-interactive mode that only prints the assistant's final output
|
-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 <mode> Override the approval policy: 'suggest', 'auto-edit', or 'full-auto'
|
-a, --approval-mode <mode> Override the approval policy: 'suggest', 'auto-edit', or 'full-auto'
|
||||||
|
|
||||||
--auto-edit Automatically approve file edits; still prompt for commands
|
--auto-edit Automatically approve file edits; still prompt for commands
|
||||||
@@ -91,6 +97,11 @@ const cli = meow(
|
|||||||
aliases: ["q"],
|
aliases: ["q"],
|
||||||
description: "Non-interactive quiet mode",
|
description: "Non-interactive quiet mode",
|
||||||
},
|
},
|
||||||
|
config: {
|
||||||
|
type: "boolean",
|
||||||
|
aliases: ["c"],
|
||||||
|
description: "Open the instructions file in your editor",
|
||||||
|
},
|
||||||
dangerouslyAutoApproveEverything: {
|
dangerouslyAutoApproveEverything: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
description:
|
description:
|
||||||
@@ -139,9 +150,9 @@ const cli = meow(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Handle 'completion' subcommand before any prompting or API calls
|
// Handle 'completion' subcommand before any prompting or API calls
|
||||||
if (cli.input[0] === 'completion') {
|
if (cli.input[0] === "completion") {
|
||||||
const shell = cli.input[1] || 'bash';
|
const shell = cli.input[1] || "bash";
|
||||||
const scripts: Record<string,string> = {
|
const scripts: Record<string, string> = {
|
||||||
bash: `# bash completion for codex
|
bash: `# bash completion for codex
|
||||||
_codex_completion() {
|
_codex_completion() {
|
||||||
local cur
|
local cur
|
||||||
@@ -174,6 +185,21 @@ if (cli.flags.help) {
|
|||||||
cli.showHelp();
|
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
|
// API key handling
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user