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
21 changes: 18 additions & 3 deletions plugins/codex/scripts/codex-companion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function printUsage() {
"Usage:",
" 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 adversarial-review [--wait|--background] [--base <ref>] [--scope <auto|working-tree|branch>] [--model <model|spark>] [--effort <none|minimal|low|medium|high|xhigh>] [focus text]",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize the advertised spark alias before starting reviews

When a user follows this newly advertised --model spark form, handleReviewCommand forwards the raw options.model to the app-server instead of applying normalizeRequestedModel (unlike task). The app-server therefore receives the literal model name spark rather than gpt-5.3-codex-spark, so this documented invocation can fail model selection instead of running the adversarial review.

Useful? React with 👍 / 👎.

" 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 transfer [--source <claude-jsonl>] [--json]",
" node scripts/codex-companion.mjs status [job-id] [--all] [--json]",
Expand Down Expand Up @@ -139,13 +139,25 @@ function normalizeArgv(argv) {
}

function parseCommandInput(argv, config = {}) {
return parseArgs(normalizeArgv(argv), {
const parsed = parseArgs(normalizeArgv(argv), {
...config,
aliasMap: {
C: "cwd",
...(config.aliasMap ?? {})
}
});

// An unrecognised long option is still treated as a positional, because some
// commands take free-form text. Say so on stderr rather than swallowing it:
// a mistyped or unsupported flag would otherwise be silently folded into a
// prompt, and the run would look like it did what was asked.
for (const token of parsed.unknownOptions ?? []) {
console.warn(
`Warning: unrecognised option ${token}; treating it as text. It will be passed through verbatim, not interpreted as a flag.`
);
}

return parsed;
}

function resolveCommandCwd(options = {}) {
Expand Down Expand Up @@ -411,6 +423,7 @@ async function executeReviewRun(request) {
const result = await runAppServerTurn(context.repoRoot, {
prompt,
model: request.model,
effort: request.effort,
sandbox: "read-only",
outputSchema: readOutputSchema(REVIEW_SCHEMA),
onProgress: request.onProgress
Expand Down Expand Up @@ -711,7 +724,7 @@ function enqueueBackgroundTask(cwd, job, request) {

async function handleReviewCommand(argv, config) {
const { options, positionals } = parseCommandInput(argv, {
valueOptions: ["base", "scope", "model", "cwd"],
valueOptions: ["base", "scope", "model", "effort", "cwd"],
booleanOptions: ["json", "background", "wait"],
aliasMap: {
m: "model"
Expand All @@ -720,6 +733,7 @@ async function handleReviewCommand(argv, config) {

const cwd = resolveCommandCwd(options);
const workspaceRoot = resolveCommandWorkspace(options);
const effort = normalizeReasoningEffort(options.effort);
const focusText = positionals.join(" ").trim();
const target = resolveReviewTarget(cwd, {
base: options.base,
Expand All @@ -744,6 +758,7 @@ async function handleReviewCommand(argv, config) {
base: options.base,
scope: options.scope,
model: options.model,
effort,
focusText,
reviewName: config.reviewName,
onProgress: progress
Expand Down
4 changes: 3 additions & 1 deletion plugins/codex/scripts/lib/args.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function parseArgs(argv, config = {}) {
const aliasMap = config.aliasMap ?? {};
const options = {};
const positionals = [];
const unknownOptions = [];
let passthrough = false;

for (let index = 0; index < argv.length; index += 1) {
Expand Down Expand Up @@ -45,6 +46,7 @@ export function parseArgs(argv, config = {}) {
continue;
}

unknownOptions.push(token);
positionals.push(token);
continue;
}
Expand All @@ -70,7 +72,7 @@ export function parseArgs(argv, config = {}) {
positionals.push(token);
}

return { options, positionals };
return { options, positionals, unknownOptions };
}

export function splitRawArgumentString(raw) {
Expand Down
65 changes: 65 additions & 0 deletions tests/args.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import test from "node:test";
import assert from "node:assert/strict";

import { parseArgs, splitRawArgumentString } from "../plugins/codex/scripts/lib/args.mjs";

const REVIEW_CONFIG = {
valueOptions: ["base", "scope", "model", "effort", "cwd"],
booleanOptions: ["json", "background", "wait"],
aliasMap: { m: "model" }
};

test("parseArgs reports an unrecognised long option instead of silently demoting it", () => {
const { options, positionals, unknownOptions } = parseArgs(
["--model", "gpt-6-astra", "--nonsense", "value"],
{ valueOptions: ["model"], booleanOptions: [] }
);

assert.equal(options.model, "gpt-6-astra");
// Behaviour is unchanged: the token still reaches positionals, because some
// commands take free-form text after their flags.
assert.deepEqual(positionals, ["--nonsense", "value"]);
// But it is now reported, so a caller can warn rather than swallow it.
assert.deepEqual(unknownOptions, ["--nonsense"]);
});

test("parseArgs reports nothing when every option is recognised", () => {
const { unknownOptions } = parseArgs(["--model", "gpt-6-astra", "--json"], {
valueOptions: ["model"],
booleanOptions: ["json"]
});

assert.deepEqual(unknownOptions, []);
});

test("parseArgs does not treat text after -- as an unrecognised option", () => {
const { positionals, unknownOptions } = parseArgs(["--", "--not-a-flag"], {
valueOptions: [],
booleanOptions: []
});

assert.deepEqual(positionals, ["--not-a-flag"]);
assert.deepEqual(unknownOptions, []);
});

test("review commands accept --effort rather than folding it into the focus text", () => {
const { options, positionals, unknownOptions } = parseArgs(
["--model", "gpt-6-astra", "--effort", "xhigh", "focus", "on", "auth"],
REVIEW_CONFIG
);

assert.equal(options.model, "gpt-6-astra");
assert.equal(options.effort, "xhigh");
assert.deepEqual(unknownOptions, []);
// The regression this guards: --effort and xhigh used to land here and be
// joined into the prompt the reviewer was given.
assert.deepEqual(positionals, ["focus", "on", "auth"]);
assert.equal(positionals.join(" "), "focus on auth");
});

test("splitRawArgumentString keeps a quoted focus phrase together", () => {
assert.deepEqual(
splitRawArgumentString('--model gpt-6-astra --effort xhigh "the auth path"'),
["--model", "gpt-6-astra", "--effort", "xhigh", "the auth path"]
);
});