Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions plugins/codex/scripts/codex-companion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function printUsage() {
" node scripts/codex-companion.mjs setup [--enable-review-gate|--disable-review-gate] [--json]",
" node scripts/codex-companion.mjs review [--wait|--background] [--base <ref>] [--scope <auto|working-tree|branch>]",
" node scripts/codex-companion.mjs adversarial-review [--wait|--background] [--base <ref>] [--scope <auto|working-tree|branch>] [focus text]",
" node scripts/codex-companion.mjs task [--background] [--write] [--resume-last|--resume|--fresh] [--model <model|spark>] [--effort <none|minimal|low|medium|high|xhigh>] [prompt]",
" node scripts/codex-companion.mjs task [--background] [--write] [--resume-last|--resume|--fresh] [--model <model|spark>] [--effort <none|minimal|low|medium|high|xhigh>] [--prompt-file <path> [--prompt-file-consume]] [prompt]",
" node scripts/codex-companion.mjs transfer [--source <claude-jsonl>] [--json]",
" node scripts/codex-companion.mjs status [job-id] [--all] [--json]",
" node scripts/codex-companion.mjs result [job-id] [--json]",
Expand Down Expand Up @@ -641,8 +641,18 @@ async function executeTransfer(cwd, options = {}) {
}

function readTaskPrompt(cwd, options, positionals) {
const consumePromptFile = Boolean(options["prompt-file-consume"]);
if (consumePromptFile && !options["prompt-file"]) {
throw new Error("--prompt-file-consume requires --prompt-file.");
}

if (options["prompt-file"]) {
return fs.readFileSync(path.resolve(cwd, options["prompt-file"]), "utf8");
const promptPath = path.resolve(cwd, options["prompt-file"]);
const prompt = fs.readFileSync(promptPath, "utf8");
if (consumePromptFile) {
fs.unlinkSync(promptPath);
}
return prompt;
}

const positionalPrompt = positionals.join(" ");
Expand Down Expand Up @@ -762,7 +772,15 @@ async function handleReview(argv) {
async function handleTask(argv) {
const { options, positionals } = parseCommandInput(argv, {
valueOptions: ["model", "effort", "cwd", "prompt-file"],
booleanOptions: ["json", "write", "resume-last", "resume", "fresh", "background"],
booleanOptions: [
"json",
"write",
"resume-last",
"resume",
"fresh",
"background",
"prompt-file-consume"
],
aliasMap: {
m: "model"
}
Expand Down
53 changes: 53 additions & 0 deletions tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,59 @@ test("write task output focuses on the Codex result without generic follow-up hi
assert.equal(result.stdout, "Handled the requested task.\nTask prompt accepted.\n");
});

test("task --prompt-file-consume removes the prompt file after a successful read", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
const statePath = path.join(binDir, "fake-codex-state.json");
installFakeCodex(binDir);
initGitRepo(repo);
const promptPath = path.join(repo, "prompt.txt");
fs.writeFileSync(promptPath, "inspect the failing test", "utf8");

const result = run(
"node",
[SCRIPT, "task", "--prompt-file", promptPath, "--prompt-file-consume"],
{ cwd: repo, env: buildEnv(binDir) }
);

assert.equal(result.status, 0, result.stderr);
assert.equal(fs.existsSync(promptPath), false);
const fakeState = JSON.parse(fs.readFileSync(statePath, "utf8"));
assert.equal(fakeState.lastTurnStart.prompt, "inspect the failing test");
});

test("task --prompt-file preserves the prompt file without consume", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir);
initGitRepo(repo);
const promptPath = path.join(repo, "prompt.txt");
fs.writeFileSync(promptPath, "inspect the failing test", "utf8");

const result = run("node", [SCRIPT, "task", "--prompt-file", promptPath], {
cwd: repo,
env: buildEnv(binDir)
});

assert.equal(result.status, 0, result.stderr);
assert.equal(fs.existsSync(promptPath), true);
});

test("task --prompt-file-consume requires --prompt-file", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir);
initGitRepo(repo);

const result = run("node", [SCRIPT, "task", "--prompt-file-consume", "hello"], {
cwd: repo,
env: buildEnv(binDir)
});

assert.equal(result.status, 1);
assert.match(result.stderr, /--prompt-file-consume requires --prompt-file\./);
});

test("task --resume acts like --resume-last without leaking the flag into the prompt", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
Expand Down