Compare commits

..

1 Commits

Author SHA1 Message Date
Dominik Kundel d0423ccd3f fix: respect SHELL on Windows for Git Bash 2026-04-07 19:53:21 -07:00
18 changed files with 116 additions and 1317 deletions
+2 -2
View File
@@ -5,13 +5,13 @@
},
"metadata": {
"description": "Codex plugins to use in Claude Code for delegation and code review.",
"version": "1.0.3"
"version": "1.0.2"
},
"plugins": [
{
"name": "codex",
"description": "Use Codex from Claude Code to review code or delegate tasks.",
"version": "1.0.3",
"version": "1.0.2",
"author": {
"name": "OpenAI"
},
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@openai/codex-plugin-cc",
"version": "1.0.3",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openai/codex-plugin-cc",
"version": "1.0.3",
"version": "1.0.2",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^25.5.0",
+1 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@openai/codex-plugin-cc",
"version": "1.0.3",
"version": "1.0.2",
"private": true,
"type": "module",
"description": "Use Codex from Claude Code to review code or delegate tasks.",
@@ -9,8 +9,6 @@
"node": ">=18.18.0"
},
"scripts": {
"bump-version": "node scripts/bump-version.mjs",
"check-version": "node scripts/bump-version.mjs --check",
"prebuild": "mkdir -p plugins/codex/.generated/app-server-types && codex app-server generate-ts --out plugins/codex/.generated/app-server-types",
"build": "tsc -p tsconfig.app-server.json",
"test": "node --test tests/*.test.mjs"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "codex",
"version": "1.0.3",
"version": "1.0.2",
"description": "Use Codex from Claude Code to review code or delegate tasks.",
"author": {
"name": "OpenAI"
@@ -32,7 +32,6 @@ Actively try to disprove the change.
Look for violated invariants, missing guards, unhandled failure paths, and assumptions that stop being true under stress.
Trace how bad inputs, retries, concurrent actions, or partially completed operations move through the code.
If the user supplied a focus area, weight it heavily, but still report any other material issue you can defend.
{{REVIEW_COLLECTION_GUIDANCE}}
</review_method>
<finding_bar>
+30 -50
View File
@@ -11,8 +11,8 @@ import {
buildPersistentTaskThreadName,
DEFAULT_CONTINUE_PROMPT,
findLatestTaskThread,
getCodexAuthStatus,
getCodexAvailability,
getCodexLoginStatus,
getSessionRuntimeStatus,
interruptAppServerTurn,
parseStructuredOutput,
@@ -176,19 +176,19 @@ function firstMeaningfulLine(text, fallback) {
return line ?? fallback;
}
async function buildSetupReport(cwd, actionsTaken = []) {
function buildSetupReport(cwd, actionsTaken = []) {
const workspaceRoot = resolveWorkspaceRoot(cwd);
const nodeStatus = binaryAvailable("node", ["--version"], { cwd });
const npmStatus = binaryAvailable("npm", ["--version"], { cwd });
const codexStatus = getCodexAvailability(cwd);
const authStatus = await getCodexAuthStatus(cwd);
const authStatus = getCodexLoginStatus(cwd);
const config = getConfig(workspaceRoot);
const nextSteps = [];
if (!codexStatus.available) {
nextSteps.push("Install Codex with `npm install -g @openai/codex`.");
}
if (codexStatus.available && !authStatus.loggedIn && authStatus.requiresOpenaiAuth) {
if (codexStatus.available && !authStatus.loggedIn) {
nextSteps.push("Run `!codex login`.");
nextSteps.push("If browser login is blocked, retry with `!codex login --device-auth` or `!codex login --with-api-key`.");
}
@@ -209,7 +209,7 @@ async function buildSetupReport(cwd, actionsTaken = []) {
};
}
async function handleSetup(argv) {
function handleSetup(argv) {
const { options } = parseCommandInput(argv, {
valueOptions: ["cwd"],
booleanOptions: ["json", "enable-review-gate", "disable-review-gate"]
@@ -231,7 +231,7 @@ async function handleSetup(argv) {
actionsTaken.push(`Disabled the stop-time review gate for ${workspaceRoot}.`);
}
const finalReport = await buildSetupReport(cwd, actionsTaken);
const finalReport = buildSetupReport(cwd, actionsTaken);
outputResult(options.json ? finalReport : renderSetupReport(finalReport), options.json);
}
@@ -241,16 +241,18 @@ function buildAdversarialReviewPrompt(context, focusText) {
REVIEW_KIND: "Adversarial Review",
TARGET_LABEL: context.target.label,
USER_FOCUS: focusText || "No extra focus provided.",
REVIEW_COLLECTION_GUIDANCE: context.collectionGuidance,
REVIEW_INPUT: context.content
});
}
function ensureCodexAvailable(cwd) {
const availability = getCodexAvailability(cwd);
if (!availability.available) {
function ensureCodexReady(cwd) {
const authStatus = getCodexLoginStatus(cwd);
if (!authStatus.available) {
throw new Error("Codex CLI is not installed or is missing required runtime support. Install it with `npm install -g @openai/codex`, then rerun `/codex:setup`.");
}
if (!authStatus.loggedIn) {
throw new Error("Codex CLI is not authenticated. Run `!codex login` and retry.");
}
}
function buildNativeReviewTarget(target) {
@@ -288,30 +290,6 @@ function isActiveJobStatus(status) {
return status === "queued" || status === "running";
}
function getCurrentClaudeSessionId() {
return process.env[SESSION_ID_ENV] ?? null;
}
function filterJobsForCurrentClaudeSession(jobs) {
const sessionId = getCurrentClaudeSessionId();
if (!sessionId) {
return jobs;
}
return jobs.filter((job) => job.sessionId === sessionId);
}
function findLatestResumableTaskJob(jobs) {
return (
jobs.find(
(job) =>
job.jobClass === "task" &&
job.threadId &&
job.status !== "queued" &&
job.status !== "running"
) ?? null
);
}
async function waitForSingleJobSnapshot(cwd, reference, options = {}) {
const timeoutMs = Math.max(0, Number(options.timeoutMs) || DEFAULT_STATUS_WAIT_TIMEOUT_MS);
const pollIntervalMs = Math.max(100, Number(options.pollIntervalMs) || DEFAULT_STATUS_POLL_INTERVAL_MS);
@@ -332,28 +310,22 @@ async function waitForSingleJobSnapshot(cwd, reference, options = {}) {
async function resolveLatestTrackedTaskThread(cwd, options = {}) {
const workspaceRoot = resolveWorkspaceRoot(cwd);
const sessionId = getCurrentClaudeSessionId();
const jobs = sortJobsNewestFirst(listJobs(workspaceRoot)).filter((job) => job.id !== options.excludeJobId);
const visibleJobs = filterJobsForCurrentClaudeSession(jobs);
const activeTask = visibleJobs.find((job) => job.jobClass === "task" && (job.status === "queued" || job.status === "running"));
const activeTask = jobs.find((job) => job.jobClass === "task" && (job.status === "queued" || job.status === "running"));
if (activeTask) {
throw new Error(`Task ${activeTask.id} is still running. Use /codex:status before continuing it.`);
}
const trackedTask = findLatestResumableTaskJob(visibleJobs);
const trackedTask = jobs.find((job) => job.jobClass === "task" && job.status === "completed" && job.threadId);
if (trackedTask) {
return { id: trackedTask.threadId };
}
if (sessionId) {
return null;
}
return findLatestTaskThread(workspaceRoot);
}
async function executeReviewRun(request) {
ensureCodexAvailable(request.cwd);
ensureCodexReady(request.cwd);
ensureGitRepository(request.cwd);
const target = resolveReviewTarget(request.cwd, {
@@ -457,7 +429,7 @@ async function executeReviewRun(request) {
async function executeTaskRun(request) {
const workspaceRoot = resolveWorkspaceRoot(request.cwd);
ensureCodexAvailable(request.cwd);
ensureCodexReady(request.cwd);
const taskMetadata = buildTaskRunMetadata({
prompt: request.prompt,
@@ -756,7 +728,7 @@ async function handleTask(argv) {
});
if (options.background) {
ensureCodexAvailable(cwd);
ensureCodexReady(cwd);
requireTaskRequest(prompt, resumeLast);
const job = buildTaskJob(workspaceRoot, taskMetadata, write);
@@ -890,9 +862,17 @@ function handleTaskResumeCandidate(argv) {
const cwd = resolveCommandCwd(options);
const workspaceRoot = resolveCommandWorkspace(options);
const sessionId = getCurrentClaudeSessionId();
const jobs = filterJobsForCurrentClaudeSession(sortJobsNewestFirst(listJobs(workspaceRoot)));
const candidate = findLatestResumableTaskJob(jobs);
const sessionId = process.env[SESSION_ID_ENV] ?? null;
const jobs = sortJobsNewestFirst(listJobs(workspaceRoot));
const candidate =
jobs.find(
(job) =>
job.jobClass === "task" &&
job.threadId &&
job.status !== "queued" &&
job.status !== "running" &&
(!sessionId || job.sessionId === sessionId)
) ?? null;
const payload = {
available: Boolean(candidate),
@@ -925,7 +905,7 @@ async function handleCancel(argv) {
const cwd = resolveCommandCwd(options);
const reference = positionals[0] ?? "";
const { workspaceRoot, job } = resolveCancelableJob(cwd, reference, { env: process.env });
const { workspaceRoot, job } = resolveCancelableJob(cwd, reference);
const existing = readStoredJob(workspaceRoot, job.id) ?? {};
const threadId = existing.threadId ?? job.threadId ?? null;
const turnId = existing.turnId ?? job.turnId ?? null;
@@ -987,7 +967,7 @@ async function main() {
switch (subcommand) {
case "setup":
await handleSetup(argv);
handleSetup(argv);
break;
case "review":
await handleReview(argv);
-1
View File
@@ -51,7 +51,6 @@ export interface CodexAppServerClientOptions {
capabilities?: InitializeCapabilities;
brokerEndpoint?: string;
disableBroker?: boolean;
reuseExistingBroker?: boolean;
}
export interface AppServerMethodMap {
+3 -6
View File
@@ -13,7 +13,7 @@ import process from "node:process";
import { spawn } from "node:child_process";
import readline from "node:readline";
import { parseBrokerEndpoint } from "./broker-endpoint.mjs";
import { ensureBrokerSession, loadBrokerSession } from "./broker-lifecycle.mjs";
import { ensureBrokerSession } from "./broker-lifecycle.mjs";
import { terminateProcessTree } from "./process.mjs";
const PLUGIN_MANIFEST_URL = new URL("../../.claude-plugin/plugin.json", import.meta.url);
@@ -188,7 +188,7 @@ class SpawnedCodexAppServerClient extends AppServerClientBase {
async initialize() {
this.proc = spawn("codex", ["app-server"], {
cwd: this.cwd,
env: this.options.env ?? process.env,
env: this.options.env,
stdio: ["pipe", "pipe", "pipe"],
shell: process.platform === "win32" ? (process.env.SHELL || true) : false,
windowsHide: true
@@ -333,10 +333,7 @@ export class CodexAppServerClient {
let brokerEndpoint = null;
if (!options.disableBroker) {
brokerEndpoint = options.brokerEndpoint ?? options.env?.[BROKER_ENDPOINT_ENV] ?? process.env[BROKER_ENDPOINT_ENV] ?? null;
if (!brokerEndpoint && options.reuseExistingBroker) {
brokerEndpoint = loadBrokerSession(cwd)?.endpoint ?? null;
}
if (!brokerEndpoint && !options.reuseExistingBroker) {
if (!brokerEndpoint) {
const brokerSession = await ensureBrokerSession(cwd, { env: options.env });
brokerEndpoint = brokerSession?.endpoint ?? null;
}
+28 -163
View File
@@ -37,7 +37,7 @@
import { readJsonFile } from "./fs.mjs";
import { BROKER_BUSY_RPC_CODE, BROKER_ENDPOINT_ENV, CodexAppServerClient } from "./app-server.mjs";
import { loadBrokerSession } from "./broker-lifecycle.mjs";
import { binaryAvailable } from "./process.mjs";
import { binaryAvailable, runCommand } from "./process.mjs";
const SERVICE_NAME = "claude_code_codex_plugin";
const TASK_THREAD_PREFIX = "Codex Companion Task";
@@ -639,16 +639,7 @@ async function startThread(client, cwd, options = {}) {
const response = await client.request("thread/start", buildThreadParams(cwd, options));
const threadId = response.thread.id;
if (options.threadName) {
try {
await client.request("thread/name/set", { threadId, name: options.threadName });
} catch (err) {
// Only suppress "unknown variant/method" errors from older CLI versions
// that don't support thread/name/set. Rethrow auth, network, or server errors.
const msg = String(err?.message ?? err ?? "");
if (!msg.includes("unknown variant") && !msg.includes("unknown method")) {
throw err;
}
}
await client.request("thread/name/set", { threadId, name: options.threadName });
}
return response;
}
@@ -661,134 +652,6 @@ function buildResultStatus(turnState) {
return turnState.finalTurn?.status === "completed" ? 0 : 1;
}
const BUILTIN_PROVIDER_LABELS = new Map([
["openai", "OpenAI"],
["ollama", "Ollama"],
["lmstudio", "LM Studio"]
]);
function normalizeProviderId(value) {
const providerId = typeof value === "string" ? value.trim() : "";
return providerId || null;
}
function formatProviderLabel(providerId, providerConfig = null) {
const configuredName = typeof providerConfig?.name === "string" ? providerConfig.name.trim() : "";
if (configuredName) {
return configuredName;
}
if (!providerId) {
return "The active provider";
}
return BUILTIN_PROVIDER_LABELS.get(providerId) ?? providerId;
}
function buildAuthStatus(fields = {}) {
return {
available: true,
loggedIn: false,
detail: "not authenticated",
source: "unknown",
authMethod: null,
verified: null,
requiresOpenaiAuth: null,
provider: null,
...fields
};
}
function resolveProviderConfig(configResponse) {
const config = configResponse?.config;
if (!config || typeof config !== "object") {
return {
providerId: null,
providerConfig: null
};
}
const providerId = normalizeProviderId(config.model_provider);
const providers =
config.model_providers && typeof config.model_providers === "object" && !Array.isArray(config.model_providers)
? config.model_providers
: null;
const providerConfig =
providerId && providers?.[providerId] && typeof providers[providerId] === "object" ? providers[providerId] : null;
return {
providerId,
providerConfig
};
}
function buildAppServerAuthStatus(accountResponse, configResponse) {
const account = accountResponse?.account ?? null;
const requiresOpenaiAuth =
typeof accountResponse?.requiresOpenaiAuth === "boolean" ? accountResponse.requiresOpenaiAuth : null;
const { providerId, providerConfig } = resolveProviderConfig(configResponse);
const providerLabel = formatProviderLabel(providerId, providerConfig);
if (account?.type === "chatgpt") {
const email = typeof account.email === "string" && account.email.trim() ? account.email.trim() : null;
return buildAuthStatus({
loggedIn: true,
detail: email ? `ChatGPT login active for ${email}` : "ChatGPT login active",
source: "app-server",
authMethod: "chatgpt",
verified: true,
requiresOpenaiAuth,
provider: providerId
});
}
if (account?.type === "apiKey") {
return buildAuthStatus({
loggedIn: true,
detail: "API key configured (unverified)",
source: "app-server",
authMethod: "apiKey",
verified: false,
requiresOpenaiAuth,
provider: providerId
});
}
if (requiresOpenaiAuth === false) {
return buildAuthStatus({
loggedIn: true,
detail: `${providerLabel} is configured and does not require OpenAI authentication`,
source: "app-server",
requiresOpenaiAuth,
provider: providerId
});
}
return buildAuthStatus({
loggedIn: false,
detail: `${providerLabel} requires OpenAI authentication`,
source: "app-server",
requiresOpenaiAuth,
provider: providerId
});
}
async function getCodexAuthStatusFromClient(client, cwd) {
try {
const accountResponse = await client.request("account/read", { refreshToken: false });
const configResponse = await client.request("config/read", {
includeLayers: false,
cwd
});
return buildAppServerAuthStatus(accountResponse, configResponse);
} catch (error) {
return buildAuthStatus({
loggedIn: false,
detail: error instanceof Error ? error.message : String(error),
source: "app-server"
});
}
}
export function getCodexAvailability(cwd) {
const versionStatus = binaryAvailable("codex", ["--version"], { cwd });
if (!versionStatus.available) {
@@ -828,39 +691,38 @@ export function getSessionRuntimeStatus(env = process.env, cwd = process.cwd())
};
}
export async function getCodexAuthStatus(cwd, options = {}) {
export function getCodexLoginStatus(cwd) {
const availability = getCodexAvailability(cwd);
if (!availability.available) {
return {
available: false,
loggedIn: false,
detail: availability.detail,
source: "availability",
authMethod: null,
verified: null,
requiresOpenaiAuth: null,
provider: null
detail: availability.detail
};
}
let client = null;
try {
client = await CodexAppServerClient.connect(cwd, {
env: options.env,
reuseExistingBroker: true
});
return await getCodexAuthStatusFromClient(client, cwd);
} catch (error) {
return buildAuthStatus({
const result = runCommand("codex", ["login", "status"], { cwd });
if (result.error) {
return {
available: true,
loggedIn: false,
detail: error instanceof Error ? error.message : String(error),
source: "app-server"
});
} finally {
if (client) {
await client.close().catch(() => {});
}
detail: result.error.message
};
}
if (result.status === 0) {
return {
available: true,
loggedIn: true,
detail: result.stdout.trim() || "authenticated"
};
}
return {
available: true,
loggedIn: false,
detail: result.stderr.trim() || result.stdout.trim() || "not authenticated"
};
}
export async function interruptAppServerTurn(cwd, { threadId, turnId }) {
@@ -883,9 +745,12 @@ export async function interruptAppServerTurn(cwd, { threadId, turnId }) {
};
}
const brokerEndpoint = process.env[BROKER_ENDPOINT_ENV] ?? loadBrokerSession(cwd)?.endpoint ?? null;
let client = null;
try {
client = await CodexAppServerClient.connect(cwd, { reuseExistingBroker: true });
client = brokerEndpoint
? await CodexAppServerClient.connect(cwd, { brokerEndpoint })
: await CodexAppServerClient.connect(cwd, { disableBroker: true });
await client.request("turn/interrupt", { threadId, turnId });
return {
attempted: true,
+32 -169
View File
@@ -2,11 +2,9 @@ import fs from "node:fs";
import path from "node:path";
import { isProbablyText } from "./fs.mjs";
import { formatCommandFailure, runCommand, runCommandChecked } from "./process.mjs";
import { runCommand, runCommandChecked } from "./process.mjs";
const MAX_UNTRACKED_BYTES = 24 * 1024;
const DEFAULT_INLINE_DIFF_MAX_FILES = 2;
const DEFAULT_INLINE_DIFF_MAX_BYTES = 256 * 1024;
function git(cwd, args, options = {}) {
return runCommand("git", args, { cwd, ...options });
@@ -16,64 +14,6 @@ function gitChecked(cwd, args, options = {}) {
return runCommandChecked("git", args, { cwd, ...options });
}
function listUniqueFiles(...groups) {
return [...new Set(groups.flat().filter(Boolean))].sort();
}
function normalizeMaxInlineFiles(value) {
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 0) {
return DEFAULT_INLINE_DIFF_MAX_FILES;
}
return Math.floor(parsed);
}
function normalizeMaxInlineDiffBytes(value) {
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 0) {
return DEFAULT_INLINE_DIFF_MAX_BYTES;
}
return Math.floor(parsed);
}
function measureGitOutputBytes(cwd, args, maxBytes) {
const result = git(cwd, args, { maxBuffer: maxBytes + 1 });
if (result.error && /** @type {NodeJS.ErrnoException} */ (result.error).code === "ENOBUFS") {
return maxBytes + 1;
}
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(formatCommandFailure(result));
}
return Buffer.byteLength(result.stdout, "utf8");
}
function measureCombinedGitOutputBytes(cwd, argSets, maxBytes) {
let totalBytes = 0;
for (const args of argSets) {
const remainingBytes = maxBytes - totalBytes;
if (remainingBytes < 0) {
return maxBytes + 1;
}
totalBytes += measureGitOutputBytes(cwd, args, remainingBytes);
if (totalBytes > maxBytes) {
return totalBytes;
}
}
return totalBytes;
}
function buildBranchComparison(cwd, baseRef) {
const mergeBase = gitChecked(cwd, ["merge-base", "HEAD", baseRef]).stdout.trim();
return {
mergeBase,
commitRange: `${mergeBase}..HEAD`,
reviewRange: `${baseRef}...HEAD`
};
}
export function ensureGitRepository(cwd) {
const result = git(cwd, ["rev-parse", "--show-toplevel"]);
const errorCode = result.error && "code" in result.error ? result.error.code : null;
@@ -195,25 +135,12 @@ function formatSection(title, body) {
function formatUntrackedFile(cwd, relativePath) {
const absolutePath = path.join(cwd, relativePath);
let stat;
try {
stat = fs.statSync(absolutePath);
} catch {
return `### ${relativePath}\n(skipped: broken symlink or unreadable file)`;
}
if (stat.isDirectory()) {
return `### ${relativePath}\n(skipped: directory)`;
}
const stat = fs.statSync(absolutePath);
if (stat.size > MAX_UNTRACKED_BYTES) {
return `### ${relativePath}\n(skipped: ${stat.size} bytes exceeds ${MAX_UNTRACKED_BYTES} byte limit)`;
}
let buffer;
try {
buffer = fs.readFileSync(absolutePath);
} catch {
return `### ${relativePath}\n(skipped: broken symlink or unreadable file)`;
}
const buffer = fs.readFileSync(absolutePath);
if (!isProbablyText(buffer)) {
return `### ${relativePath}\n(skipped: binary file)`;
}
@@ -221,115 +148,55 @@ function formatUntrackedFile(cwd, relativePath) {
return [`### ${relativePath}`, "```", buffer.toString("utf8").trimEnd(), "```"].join("\n");
}
function collectWorkingTreeContext(cwd, state, options = {}) {
const includeDiff = options.includeDiff !== false;
const status = gitChecked(cwd, ["status", "--short", "--untracked-files=all"]).stdout.trim();
const changedFiles = listUniqueFiles(state.staged, state.unstaged, state.untracked);
function collectWorkingTreeContext(cwd, state) {
const status = gitChecked(cwd, ["status", "--short"]).stdout.trim();
const stagedDiff = gitChecked(cwd, ["diff", "--cached", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
const unstagedDiff = gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
const untrackedBody = state.untracked.map((file) => formatUntrackedFile(cwd, file)).join("\n\n");
let parts;
if (includeDiff) {
const stagedDiff = gitChecked(cwd, ["diff", "--cached", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
const unstagedDiff = gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
const untrackedBody = state.untracked.map((file) => formatUntrackedFile(cwd, file)).join("\n\n");
parts = [
formatSection("Git Status", status),
formatSection("Staged Diff", stagedDiff),
formatSection("Unstaged Diff", unstagedDiff),
formatSection("Untracked Files", untrackedBody)
];
} else {
const stagedStat = gitChecked(cwd, ["diff", "--shortstat", "--cached"]).stdout.trim();
const unstagedStat = gitChecked(cwd, ["diff", "--shortstat"]).stdout.trim();
const untrackedBody = state.untracked.map((file) => formatUntrackedFile(cwd, file)).join("\n\n");
parts = [
formatSection("Git Status", status),
formatSection("Staged Diff Stat", stagedStat),
formatSection("Unstaged Diff Stat", unstagedStat),
formatSection("Changed Files", changedFiles.join("\n")),
formatSection("Untracked Files", untrackedBody)
];
}
const parts = [
formatSection("Git Status", status),
formatSection("Staged Diff", stagedDiff),
formatSection("Unstaged Diff", unstagedDiff),
formatSection("Untracked Files", untrackedBody)
];
return {
mode: "working-tree",
summary: `Reviewing ${state.staged.length} staged, ${state.unstaged.length} unstaged, and ${state.untracked.length} untracked file(s).`,
content: parts.join("\n"),
changedFiles
content: parts.join("\n")
};
}
function collectBranchContext(cwd, baseRef, options = {}) {
const includeDiff = options.includeDiff !== false;
const comparison = options.comparison ?? buildBranchComparison(cwd, baseRef);
function collectBranchContext(cwd, baseRef) {
const mergeBase = gitChecked(cwd, ["merge-base", "HEAD", baseRef]).stdout.trim();
const commitRange = `${mergeBase}..HEAD`;
const currentBranch = getCurrentBranch(cwd);
const changedFiles = gitChecked(cwd, ["diff", "--name-only", comparison.commitRange]).stdout.trim().split("\n").filter(Boolean);
const logOutput = gitChecked(cwd, ["log", "--oneline", "--decorate", comparison.commitRange]).stdout.trim();
const diffStat = gitChecked(cwd, ["diff", "--stat", comparison.commitRange]).stdout.trim();
const logOutput = gitChecked(cwd, ["log", "--oneline", "--decorate", commitRange]).stdout.trim();
const diffStat = gitChecked(cwd, ["diff", "--stat", commitRange]).stdout.trim();
const diff = gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff", commitRange]).stdout;
return {
mode: "branch",
summary: `Reviewing branch ${currentBranch} against ${baseRef} from merge-base ${comparison.mergeBase}.`,
content: includeDiff
? [
formatSection("Commit Log", logOutput),
formatSection("Diff Stat", diffStat),
formatSection(
"Branch Diff",
gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff", comparison.commitRange]).stdout
)
].join("\n")
: [
formatSection("Commit Log", logOutput),
formatSection("Diff Stat", diffStat),
formatSection("Changed Files", changedFiles.join("\n"))
].join("\n"),
changedFiles,
comparison
summary: `Reviewing branch ${currentBranch} against ${baseRef} from merge-base ${mergeBase}.`,
content: [
formatSection("Commit Log", logOutput),
formatSection("Diff Stat", diffStat),
formatSection("Branch Diff", diff)
].join("\n")
};
}
function buildAdversarialCollectionGuidance(options = {}) {
if (options.includeDiff !== false) {
return "Use the repository context below as primary evidence.";
}
return "The repository context below is a lightweight summary. Inspect the target diff yourself with read-only git commands before finalizing findings.";
}
export function collectReviewContext(cwd, target, options = {}) {
export function collectReviewContext(cwd, target) {
const repoRoot = getRepoRoot(cwd);
const currentBranch = getCurrentBranch(repoRoot);
const maxInlineFiles = normalizeMaxInlineFiles(options.maxInlineFiles);
const maxInlineDiffBytes = normalizeMaxInlineDiffBytes(options.maxInlineDiffBytes);
const state = getWorkingTreeState(cwd);
const currentBranch = getCurrentBranch(cwd);
let details;
let includeDiff;
let diffBytes;
if (target.mode === "working-tree") {
const state = getWorkingTreeState(repoRoot);
diffBytes = measureCombinedGitOutputBytes(
repoRoot,
[
["diff", "--cached", "--binary", "--no-ext-diff", "--submodule=diff"],
["diff", "--binary", "--no-ext-diff", "--submodule=diff"]
],
maxInlineDiffBytes
);
includeDiff =
options.includeDiff ??
(listUniqueFiles(state.staged, state.unstaged, state.untracked).length <= maxInlineFiles &&
diffBytes <= maxInlineDiffBytes);
details = collectWorkingTreeContext(repoRoot, state, { includeDiff });
details = collectWorkingTreeContext(repoRoot, state);
} else {
const comparison = buildBranchComparison(repoRoot, target.baseRef);
const fileCount = gitChecked(repoRoot, ["diff", "--name-only", comparison.commitRange]).stdout.trim().split("\n").filter(Boolean).length;
diffBytes = measureGitOutputBytes(
repoRoot,
["diff", "--binary", "--no-ext-diff", "--submodule=diff", comparison.commitRange],
maxInlineDiffBytes
);
includeDiff = options.includeDiff ?? (fileCount <= maxInlineFiles && diffBytes <= maxInlineDiffBytes);
details = collectBranchContext(repoRoot, target.baseRef, { includeDiff, comparison });
details = collectBranchContext(repoRoot, target.baseRef);
}
return {
@@ -337,10 +204,6 @@ export function collectReviewContext(cwd, target, options = {}) {
repoRoot,
branch: currentBranch,
target,
fileCount: details.changedFiles.length,
diffBytes,
inputMode: includeDiff ? "inline-diff" : "self-collect",
collectionGuidance: buildAdversarialCollectionGuidance({ includeDiff }),
...details
};
}
+4 -10
View File
@@ -278,7 +278,7 @@ export function resolveResultJob(cwd, reference) {
throw new Error("No finished Codex jobs found for this repository yet.");
}
export function resolveCancelableJob(cwd, reference, options = {}) {
export function resolveCancelableJob(cwd, reference) {
const workspaceRoot = resolveWorkspaceRoot(cwd);
const jobs = sortJobsNewestFirst(listJobs(workspaceRoot));
const activeJobs = jobs.filter((job) => job.status === "queued" || job.status === "running");
@@ -291,18 +291,12 @@ export function resolveCancelableJob(cwd, reference, options = {}) {
return { workspaceRoot, job: selected };
}
const sessionScopedActiveJobs = filterJobsForCurrentSession(activeJobs, options);
if (sessionScopedActiveJobs.length === 1) {
return { workspaceRoot, job: sessionScopedActiveJobs[0] };
if (activeJobs.length === 1) {
return { workspaceRoot, job: activeJobs[0] };
}
if (sessionScopedActiveJobs.length > 1) {
if (activeJobs.length > 1) {
throw new Error("Multiple Codex jobs are active. Pass a job id to /codex:cancel.");
}
if (getCurrentSessionId(options)) {
throw new Error("No active Codex jobs to cancel for this session.");
}
throw new Error("No active Codex jobs to cancel.");
}
-1
View File
@@ -7,7 +7,6 @@ export function runCommand(command, args = [], options = {}) {
env: options.env,
encoding: "utf8",
input: options.input,
maxBuffer: options.maxBuffer,
stdio: options.stdio ?? "pipe",
shell: process.platform === "win32" ? (process.env.SHELL || true) : false,
windowsHide: true
@@ -6,7 +6,7 @@ import path from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { getCodexAvailability } from "./lib/codex.mjs";
import { getCodexLoginStatus } from "./lib/codex.mjs";
import { loadPromptTemplate, interpolateTemplate } from "./lib/prompts.mjs";
import { getConfig, listJobs } from "./lib/state.mjs";
import { sortJobsNewestFirst } from "./lib/job-control.mjs";
@@ -57,13 +57,13 @@ function buildStopReviewPrompt(input = {}) {
}
function buildSetupNote(cwd) {
const availability = getCodexAvailability(cwd);
if (availability.available) {
const authStatus = getCodexLoginStatus(cwd);
if (authStatus.available && authStatus.loggedIn) {
return null;
}
const detail = availability.detail ? ` ${availability.detail}.` : "";
return `Codex is not set up for the review gate.${detail} Run /codex:setup.`;
const detail = authStatus.detail ? ` ${authStatus.detail}.` : "";
return `Codex is not set up for the review gate.${detail} Run /codex:setup and, if needed, !codex login.`;
}
function parseStopReviewOutput(rawOutput) {
@@ -175,10 +175,4 @@ function main() {
logNote(runningTaskNote);
}
try {
main();
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
process.stderr.write(`${message}\n`);
process.exitCode = 1;
}
main();
-227
View File
@@ -1,227 +0,0 @@
#!/usr/bin/env node
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
const VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
const TARGETS = [
{
file: "package.json",
values: [
{
label: "version",
get: (json) => json.version,
set: (json, version) => {
json.version = version;
}
}
]
},
{
file: "package-lock.json",
values: [
{
label: "version",
get: (json) => json.version,
set: (json, version) => {
json.version = version;
}
},
{
label: "packages[\"\"].version",
get: (json) => json.packages?.[""]?.version,
set: (json, version) => {
requireObject(json.packages?.[""], "package-lock.json packages[\"\"]");
json.packages[""].version = version;
}
}
]
},
{
file: "plugins/codex/.claude-plugin/plugin.json",
values: [
{
label: "version",
get: (json) => json.version,
set: (json, version) => {
json.version = version;
}
}
]
},
{
file: ".claude-plugin/marketplace.json",
values: [
{
label: "metadata.version",
get: (json) => json.metadata?.version,
set: (json, version) => {
requireObject(json.metadata, ".claude-plugin/marketplace.json metadata");
json.metadata.version = version;
}
},
{
label: "plugins[codex].version",
get: (json) => findMarketplacePlugin(json).version,
set: (json, version) => {
findMarketplacePlugin(json).version = version;
}
}
]
}
];
function usage() {
return [
"Usage:",
" node scripts/bump-version.mjs <version>",
" node scripts/bump-version.mjs --check [version]",
"",
"Options:",
" --check Verify manifest versions. Uses package.json when version is omitted.",
" --root <dir> Run against a different repository root.",
" --help Print this help."
].join("\n");
}
function parseArgs(argv) {
const options = {
check: false,
root: process.cwd(),
version: null
};
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
if (arg === "--check") {
options.check = true;
} else if (arg === "--root") {
const root = argv[i + 1];
if (!root) {
throw new Error("--root requires a directory.");
}
options.root = root;
i += 1;
} else if (arg === "--help" || arg === "-h") {
options.help = true;
} else if (arg.startsWith("-")) {
throw new Error(`Unknown option: ${arg}`);
} else if (options.version) {
throw new Error(`Unexpected extra argument: ${arg}`);
} else {
options.version = arg;
}
}
options.root = path.resolve(options.root);
return options;
}
function validateVersion(version) {
if (!VERSION_PATTERN.test(version)) {
throw new Error(`Expected a semver-like version such as 1.0.3, got: ${version}`);
}
}
function requireObject(value, label) {
if (!value || typeof value !== "object" || Array.isArray(value)) {
throw new Error(`Expected ${label} to be an object.`);
}
}
function findMarketplacePlugin(json) {
const plugin = json.plugins?.find((entry) => entry?.name === "codex");
requireObject(plugin, ".claude-plugin/marketplace.json plugins[codex]");
return plugin;
}
function readJson(root, file) {
const filePath = path.join(root, file);
return JSON.parse(fs.readFileSync(filePath, "utf8"));
}
function writeJson(root, file, json) {
const filePath = path.join(root, file);
fs.writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
}
function readPackageVersion(root) {
const packageJson = readJson(root, "package.json");
if (typeof packageJson.version !== "string") {
throw new Error("package.json version must be a string.");
}
validateVersion(packageJson.version);
return packageJson.version;
}
function checkVersions(root, expectedVersion) {
const mismatches = [];
for (const target of TARGETS) {
const json = readJson(root, target.file);
for (const value of target.values) {
const actual = value.get(json);
if (actual !== expectedVersion) {
mismatches.push(`${target.file} ${value.label}: expected ${expectedVersion}, found ${actual ?? "<missing>"}`);
}
}
}
return mismatches;
}
function bumpVersion(root, version) {
const changedFiles = [];
for (const target of TARGETS) {
const json = readJson(root, target.file);
const before = JSON.stringify(json);
for (const value of target.values) {
value.set(json, version);
}
if (JSON.stringify(json) !== before) {
writeJson(root, target.file, json);
changedFiles.push(target.file);
}
}
return changedFiles;
}
function main() {
const options = parseArgs(process.argv.slice(2));
if (options.help) {
console.log(usage());
return;
}
const version = options.version ?? (options.check ? readPackageVersion(options.root) : null);
if (!version) {
throw new Error(`Missing version.\n\n${usage()}`);
}
validateVersion(version);
if (options.check) {
const mismatches = checkVersions(options.root, version);
if (mismatches.length > 0) {
throw new Error(`Version metadata is out of sync:\n${mismatches.join("\n")}`);
}
console.log(`All version metadata matches ${version}.`);
return;
}
const changedFiles = bumpVersion(options.root, version);
const touched = changedFiles.length > 0 ? changedFiles.join(", ") : "no files changed";
console.log(`Set version metadata to ${version}: ${touched}.`);
}
try {
main();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
-88
View File
@@ -1,88 +0,0 @@
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { makeTempDir, run } from "./helpers.mjs";
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const SCRIPT = path.join(ROOT, "scripts", "bump-version.mjs");
function writeJson(filePath, json) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
}
function readJson(filePath) {
return JSON.parse(fs.readFileSync(filePath, "utf8"));
}
function makeVersionFixture() {
const root = makeTempDir();
writeJson(path.join(root, "package.json"), {
name: "@openai/codex-plugin-cc",
version: "1.0.2"
});
writeJson(path.join(root, "package-lock.json"), {
name: "@openai/codex-plugin-cc",
version: "1.0.2",
lockfileVersion: 3,
packages: {
"": {
name: "@openai/codex-plugin-cc",
version: "1.0.2"
}
}
});
writeJson(path.join(root, "plugins", "codex", ".claude-plugin", "plugin.json"), {
name: "codex",
version: "1.0.2"
});
writeJson(path.join(root, ".claude-plugin", "marketplace.json"), {
metadata: {
version: "1.0.2"
},
plugins: [
{
name: "codex",
version: "1.0.2"
}
]
});
return root;
}
test("bump-version updates every release manifest", () => {
const root = makeVersionFixture();
const result = run("node", [SCRIPT, "--root", root, "1.2.3"], {
cwd: ROOT
});
assert.equal(result.status, 0, result.stderr);
assert.equal(readJson(path.join(root, "package.json")).version, "1.2.3");
assert.equal(readJson(path.join(root, "package-lock.json")).version, "1.2.3");
assert.equal(readJson(path.join(root, "package-lock.json")).packages[""].version, "1.2.3");
assert.equal(readJson(path.join(root, "plugins", "codex", ".claude-plugin", "plugin.json")).version, "1.2.3");
assert.equal(readJson(path.join(root, ".claude-plugin", "marketplace.json")).metadata.version, "1.2.3");
assert.equal(readJson(path.join(root, ".claude-plugin", "marketplace.json")).plugins[0].version, "1.2.3");
});
test("bump-version check mode reports stale metadata", () => {
const root = makeVersionFixture();
writeJson(path.join(root, "package.json"), {
name: "@openai/codex-plugin-cc",
version: "1.0.3"
});
const result = run("node", [SCRIPT, "--root", root, "--check"], {
cwd: ROOT
});
assert.notEqual(result.status, 0);
assert.match(result.stderr, /plugins\/codex\/\.claude-plugin\/plugin\.json version/);
assert.match(result.stderr, /\.claude-plugin\/marketplace\.json metadata\.version/);
});
+1 -63
View File
@@ -63,54 +63,6 @@ function buildTurn(id, status = "inProgress", error = null) {
return { id, status, items: [], error };
}
function buildAccountReadResult() {
switch (BEHAVIOR) {
case "logged-out":
case "refreshable-auth":
case "auth-run-fails":
return { account: null, requiresOpenaiAuth: true };
case "provider-no-auth":
case "env-key-provider":
return { account: null, requiresOpenaiAuth: false };
case "api-key-account-only":
return { account: { type: "apiKey" }, requiresOpenaiAuth: true };
default:
return {
account: { type: "chatgpt", email: "test@example.com", planType: "plus" },
requiresOpenaiAuth: true
};
}
}
function buildConfigReadResult() {
switch (BEHAVIOR) {
case "provider-no-auth":
return {
config: { model_provider: "ollama" },
origins: {}
};
case "env-key-provider":
return {
config: {
model_provider: "openai-custom",
model_providers: {
"openai-custom": {
name: "OpenAI custom",
env_key: "OPENAI_API_KEY",
requires_openai_auth: false
}
}
},
origins: {}
};
default:
return {
config: { model_provider: "openai" },
origins: {}
};
}
}
function send(message) {
process.stdout.write(JSON.stringify(message) + "\\n");
}
@@ -241,7 +193,7 @@ if (args[0] === "app-server" && args[1] === "--help") {
process.exit(0);
}
if (args[0] === "login" && args[1] === "status") {
if (BEHAVIOR === "logged-out" || BEHAVIOR === "refreshable-auth" || BEHAVIOR === "auth-run-fails" || BEHAVIOR === "provider-no-auth" || BEHAVIOR === "env-key-provider" || BEHAVIOR === "api-key-account-only") {
if (BEHAVIOR === "logged-out") {
console.error("not authenticated");
process.exit(1);
}
@@ -278,21 +230,7 @@ rl.on("line", (line) => {
case "initialized":
break;
case "account/read":
send({ id: message.id, result: buildAccountReadResult() });
break;
case "config/read":
if (BEHAVIOR === "config-read-fails") {
throw new Error("config/read failed for cwd");
}
send({ id: message.id, result: buildConfigReadResult() });
break;
case "thread/start": {
if (BEHAVIOR === "auth-run-fails") {
throw new Error("authentication expired; run codex login");
}
if (requiresExperimental("persistExtendedHistory", message, state) || requiresExperimental("persistFullHistory", message, state)) {
throw new Error("thread/start.persistFullHistory requires experimentalApi capability");
}
-113
View File
@@ -68,116 +68,3 @@ test("resolveReviewTarget requires an explicit base when no default branch can b
/Unable to detect the repository default branch\. Pass --base <ref> or use --scope working-tree\./
);
});
test("collectReviewContext keeps inline diffs for tiny adversarial reviews", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
fs.writeFileSync(path.join(cwd, "app.js"), "console.log('v1');\n");
run("git", ["add", "app.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
fs.writeFileSync(path.join(cwd, "app.js"), "console.log('INLINE_MARKER');\n");
const target = resolveReviewTarget(cwd, {});
const context = collectReviewContext(cwd, target);
assert.equal(context.inputMode, "inline-diff");
assert.equal(context.fileCount, 1);
assert.match(context.collectionGuidance, /primary evidence/i);
assert.match(context.content, /INLINE_MARKER/);
});
test("collectReviewContext skips untracked directories in working tree review", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
fs.writeFileSync(path.join(cwd, "app.js"), "console.log('v1');\n");
run("git", ["add", "app.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
const nestedRepoDir = path.join(cwd, ".claude", "worktrees", "agent-test");
fs.mkdirSync(nestedRepoDir, { recursive: true });
initGitRepo(nestedRepoDir);
const target = resolveReviewTarget(cwd, { scope: "working-tree" });
const context = collectReviewContext(cwd, target);
assert.match(context.content, /### \.claude\/worktrees\/agent-test\/\n\(skipped: directory\)/);
});
test("collectReviewContext skips broken untracked symlinks instead of crashing", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
fs.writeFileSync(path.join(cwd, "app.js"), "console.log('v1');\n");
run("git", ["add", "app.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
fs.symlinkSync("missing-target", path.join(cwd, "broken-link"));
const target = resolveReviewTarget(cwd, {});
const context = collectReviewContext(cwd, target);
assert.equal(target.mode, "working-tree");
assert.match(context.content, /### broken-link/);
assert.match(context.content, /skipped: broken symlink or unreadable file/i);
});
test("collectReviewContext falls back to lightweight context for larger adversarial reviews", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
for (const name of ["a.js", "b.js", "c.js"]) {
fs.writeFileSync(path.join(cwd, name), `export const value = "${name}-v1";\n`);
}
run("git", ["add", "a.js", "b.js", "c.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
fs.writeFileSync(path.join(cwd, "a.js"), 'export const value = "SELF_COLLECT_MARKER_A";\n');
fs.writeFileSync(path.join(cwd, "b.js"), 'export const value = "SELF_COLLECT_MARKER_B";\n');
fs.writeFileSync(path.join(cwd, "c.js"), 'export const value = "SELF_COLLECT_MARKER_C";\n');
const target = resolveReviewTarget(cwd, {});
const context = collectReviewContext(cwd, target);
assert.equal(context.inputMode, "self-collect");
assert.equal(context.fileCount, 3);
assert.match(context.collectionGuidance, /lightweight summary/i);
assert.match(context.collectionGuidance, /read-only git commands/i);
assert.doesNotMatch(context.content, /SELF_COLLECT_MARKER_[ABC]/);
assert.match(context.content, /## Changed Files/);
});
test("collectReviewContext falls back to lightweight context for oversized single-file diffs", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
fs.writeFileSync(path.join(cwd, "app.js"), "export const value = 'v1';\n");
run("git", ["add", "app.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
fs.writeFileSync(path.join(cwd, "app.js"), `export const value = '${"x".repeat(512)}';\n`);
const target = resolveReviewTarget(cwd, {});
const context = collectReviewContext(cwd, target, { maxInlineDiffBytes: 128 });
assert.equal(context.fileCount, 1);
assert.equal(context.inputMode, "self-collect");
assert.ok(context.diffBytes > 128);
assert.doesNotMatch(context.content, /xxx/);
assert.match(context.content, /## Changed Files/);
});
test("collectReviewContext keeps untracked file content in lightweight working tree context", () => {
const cwd = makeTempDir();
initGitRepo(cwd);
for (const name of ["a.js", "b.js"]) {
fs.writeFileSync(path.join(cwd, name), `export const value = "${name}-v1";\n`);
}
run("git", ["add", "a.js", "b.js"], { cwd });
run("git", ["commit", "-m", "init"], { cwd });
fs.writeFileSync(path.join(cwd, "a.js"), 'export const value = "TRACKED_MARKER_A";\n');
fs.writeFileSync(path.join(cwd, "b.js"), 'export const value = "TRACKED_MARKER_B";\n');
fs.writeFileSync(path.join(cwd, "new-risk.js"), 'export const value = "UNTRACKED_RISK_MARKER";\n');
const target = resolveReviewTarget(cwd, {});
const context = collectReviewContext(cwd, target);
assert.equal(context.inputMode, "self-collect");
assert.equal(context.fileCount, 3);
assert.doesNotMatch(context.content, /TRACKED_MARKER_[AB]/);
assert.match(context.content, /## Untracked Files/);
assert.match(context.content, /UNTRACKED_RISK_MARKER/);
});
+6 -405
View File
@@ -65,77 +65,6 @@ test("setup is ready without npm when Codex is already installed and authenticat
assert.equal(payload.auth.loggedIn, true);
});
test("setup trusts app-server API key auth even when login status alone would fail", () => {
const binDir = makeTempDir();
installFakeCodex(binDir, "api-key-account-only");
const result = run("node", [SCRIPT, "setup", "--json"], {
cwd: ROOT,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout);
assert.equal(payload.ready, true);
assert.equal(payload.auth.loggedIn, true);
assert.equal(payload.auth.authMethod, "apiKey");
assert.equal(payload.auth.source, "app-server");
assert.match(payload.auth.detail, /API key configured \(unverified\)/);
});
test("setup is ready when the active provider does not require OpenAI login", () => {
const binDir = makeTempDir();
installFakeCodex(binDir, "provider-no-auth");
const result = run("node", [SCRIPT, "setup", "--json"], {
cwd: ROOT,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout);
assert.equal(payload.ready, true);
assert.equal(payload.auth.loggedIn, true);
assert.equal(payload.auth.authMethod, null);
assert.equal(payload.auth.source, "app-server");
assert.match(payload.auth.detail, /configured and does not require OpenAI authentication/i);
});
test("setup treats custom providers with app-server-ready config as ready", () => {
const binDir = makeTempDir();
installFakeCodex(binDir, "env-key-provider");
const result = run("node", [SCRIPT, "setup", "--json"], {
cwd: ROOT,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout);
assert.equal(payload.ready, true);
assert.equal(payload.auth.loggedIn, true);
assert.equal(payload.auth.authMethod, null);
assert.equal(payload.auth.source, "app-server");
assert.match(payload.auth.detail, /configured and does not require OpenAI authentication/i);
});
test("setup reports not ready when app-server config read fails", () => {
const binDir = makeTempDir();
installFakeCodex(binDir, "config-read-fails");
const result = run("node", [SCRIPT, "setup", "--json"], {
cwd: ROOT,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout);
assert.equal(payload.ready, false);
assert.equal(payload.auth.loggedIn, false);
assert.equal(payload.auth.source, "app-server");
assert.match(payload.auth.detail, /config\/read failed for cwd/);
});
test("review renders a no-findings result from app-server review/start", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
@@ -157,60 +86,6 @@ test("review renders a no-findings result from app-server review/start", () => {
assert.match(result.stdout, /No material issues found/);
});
test("task runs when the active provider does not require OpenAI login", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir, "provider-no-auth");
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
const result = run("node", [SCRIPT, "task", "check auth preflight"], {
cwd: repo,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Handled the requested task/);
});
test("task runs without auth preflight so Codex can refresh an expired session", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir, "refreshable-auth");
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
const result = run("node", [SCRIPT, "task", "check refreshable auth"], {
cwd: repo,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Handled the requested task/);
});
test("task reports the actual Codex auth error when the run is rejected", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir, "auth-run-fails");
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
const result = run("node", [SCRIPT, "task", "check failed auth"], {
cwd: repo,
env: buildEnv(binDir)
});
assert.notEqual(result.status, 0);
assert.match(result.stderr, /authentication expired; run codex login/);
});
test("review accepts the quoted raw argument style for built-in base-branch review", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
@@ -273,33 +148,6 @@ test("adversarial review accepts the same base-branch targeting as review", () =
assert.match(result.stdout, /Missing empty-state guard/);
});
test("adversarial review asks Codex to inspect larger diffs itself", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir);
initGitRepo(repo);
fs.mkdirSync(path.join(repo, "src"));
for (const name of ["a.js", "b.js", "c.js"]) {
fs.writeFileSync(path.join(repo, "src", name), `export const value = "${name}-v1";\n`);
}
run("git", ["add", "src/a.js", "src/b.js", "src/c.js"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
fs.writeFileSync(path.join(repo, "src", "a.js"), 'export const value = "PROMPT_SELF_COLLECT_A";\n');
fs.writeFileSync(path.join(repo, "src", "b.js"), 'export const value = "PROMPT_SELF_COLLECT_B";\n');
fs.writeFileSync(path.join(repo, "src", "c.js"), 'export const value = "PROMPT_SELF_COLLECT_C";\n');
const result = run("node", [SCRIPT, "adversarial-review"], {
cwd: repo,
env: buildEnv(binDir)
});
assert.equal(result.status, 0, result.stderr);
const state = JSON.parse(fs.readFileSync(path.join(binDir, "fake-codex-state.json"), "utf8"));
assert.match(state.lastTurnStart.prompt, /lightweight summary/i);
assert.match(state.lastTurnStart.prompt, /read-only git commands/i);
assert.doesNotMatch(state.lastTurnStart.prompt, /PROMPT_SELF_COLLECT_[ABC]/);
});
test("review includes reasoning output when the app server returns it", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
@@ -436,105 +284,6 @@ test("task-resume-candidate returns the latest rescue thread from the current se
assert.equal(payload.candidate.threadId, "thr_current");
});
test("task --resume-last does not resume a task from another Claude session", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
const statePath = path.join(binDir, "fake-codex-state.json");
installFakeCodex(binDir);
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
const otherEnv = {
...buildEnv(binDir),
CODEX_COMPANION_SESSION_ID: "sess-other"
};
const currentEnv = {
...buildEnv(binDir),
CODEX_COMPANION_SESSION_ID: "sess-current"
};
const firstRun = run("node", [SCRIPT, "task", "initial task"], {
cwd: repo,
env: otherEnv
});
assert.equal(firstRun.status, 0, firstRun.stderr);
const candidate = run("node", [SCRIPT, "task-resume-candidate", "--json"], {
cwd: repo,
env: currentEnv
});
assert.equal(candidate.status, 0, candidate.stderr);
assert.equal(JSON.parse(candidate.stdout).available, false);
const resume = run("node", [SCRIPT, "task", "--resume-last", "follow up"], {
cwd: repo,
env: currentEnv
});
assert.equal(resume.status, 1);
assert.match(resume.stderr, /No previous Codex task thread was found for this repository\./);
const fakeState = JSON.parse(fs.readFileSync(statePath, "utf8"));
assert.equal(fakeState.lastTurnStart.threadId, "thr_1");
assert.equal(fakeState.lastTurnStart.prompt, "initial task");
});
test("task --resume-last ignores running tasks from other Claude sessions", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir);
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
const stateDir = resolveStateDir(repo);
fs.mkdirSync(path.join(stateDir, "jobs"), { recursive: true });
fs.writeFileSync(
path.join(stateDir, "state.json"),
`${JSON.stringify(
{
version: 1,
config: { stopReviewGate: false },
jobs: [
{
id: "task-other-running",
status: "running",
title: "Codex Task",
jobClass: "task",
sessionId: "sess-other",
threadId: "thr_other",
summary: "Other session active task",
updatedAt: "2026-03-24T20:05:00.000Z"
}
]
},
null,
2
)}\n`,
"utf8"
);
const env = {
...buildEnv(binDir),
CODEX_COMPANION_SESSION_ID: "sess-current"
};
const status = run("node", [SCRIPT, "status", "--json"], {
cwd: repo,
env
});
assert.equal(status.status, 0, status.stderr);
assert.deepEqual(JSON.parse(status.stdout).running, []);
const resume = run("node", [SCRIPT, "task", "--resume-last", "follow up"], {
cwd: repo,
env
});
assert.equal(resume.status, 1);
assert.match(resume.stderr, /No previous Codex task thread was found for this repository\./);
});
test("session start hook exports the Claude session id and plugin data dir for later commands", () => {
const repo = makeTempDir();
const envFile = path.join(makeTempDir(), "claude-env.sh");
@@ -1498,109 +1247,6 @@ test("cancel stops an active background job and marks it cancelled", async (t) =
assert.match(fs.readFileSync(logFile, "utf8"), /Cancelled by user/);
});
test("cancel without a job id ignores active jobs from other Claude sessions", () => {
const workspace = makeTempDir();
const stateDir = resolveStateDir(workspace);
const jobsDir = path.join(stateDir, "jobs");
fs.mkdirSync(jobsDir, { recursive: true });
const logFile = path.join(jobsDir, "task-other.log");
fs.writeFileSync(logFile, "", "utf8");
fs.writeFileSync(
path.join(stateDir, "state.json"),
`${JSON.stringify(
{
version: 1,
config: { stopReviewGate: false },
jobs: [
{
id: "task-other",
status: "running",
title: "Codex Task",
jobClass: "task",
sessionId: "sess-other",
summary: "Other session run",
updatedAt: "2026-03-24T20:05:00.000Z",
logFile
}
]
},
null,
2
)}\n`,
"utf8"
);
const env = {
...process.env,
CODEX_COMPANION_SESSION_ID: "sess-current"
};
const status = run("node", [SCRIPT, "status", "--json"], {
cwd: workspace,
env
});
assert.equal(status.status, 0, status.stderr);
assert.deepEqual(JSON.parse(status.stdout).running, []);
const cancel = run("node", [SCRIPT, "cancel", "--json"], {
cwd: workspace,
env
});
assert.equal(cancel.status, 1);
assert.match(cancel.stderr, /No active Codex jobs to cancel for this session\./);
const state = JSON.parse(fs.readFileSync(path.join(stateDir, "state.json"), "utf8"));
assert.equal(state.jobs[0].status, "running");
});
test("cancel with a job id can still target an active job from another Claude session", () => {
const workspace = makeTempDir();
const stateDir = resolveStateDir(workspace);
const jobsDir = path.join(stateDir, "jobs");
fs.mkdirSync(jobsDir, { recursive: true });
const logFile = path.join(jobsDir, "task-other.log");
fs.writeFileSync(logFile, "", "utf8");
fs.writeFileSync(
path.join(stateDir, "state.json"),
`${JSON.stringify(
{
version: 1,
config: { stopReviewGate: false },
jobs: [
{
id: "task-other",
status: "running",
title: "Codex Task",
jobClass: "task",
sessionId: "sess-other",
summary: "Other session run",
updatedAt: "2026-03-24T20:05:00.000Z",
logFile
}
]
},
null,
2
)}\n`,
"utf8"
);
const env = {
...process.env,
CODEX_COMPANION_SESSION_ID: "sess-current"
};
const cancel = run("node", [SCRIPT, "cancel", "task-other", "--json"], {
cwd: workspace,
env
});
assert.equal(cancel.status, 0, cancel.stderr);
assert.equal(JSON.parse(cancel.stdout).jobId, "task-other");
const state = JSON.parse(fs.readFileSync(path.join(stateDir, "state.json"), "utf8"));
assert.equal(state.jobs[0].status, "cancelled");
});
test("cancel sends turn interrupt to the shared app-server before killing a brokered task", async () => {
const repo = makeTempDir();
const binDir = makeTempDir();
@@ -1952,10 +1598,10 @@ test("stop hook does not block when Codex is unavailable even if the review gate
assert.match(allowed.stderr, /Run \/codex:setup/i);
});
test("stop hook runs the actual task when auth status looks stale", () => {
test("stop hook does not block when Codex is not authenticated even if the review gate is enabled", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
installFakeCodex(binDir, "refreshable-auth");
installFakeCodex(binDir, "logged-out");
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
@@ -1974,10 +1620,10 @@ test("stop hook runs the actual task when auth status looks stale", () => {
});
assert.equal(allowed.status, 0, allowed.stderr);
assert.doesNotMatch(allowed.stderr, /Codex is not set up for the review gate/i);
const payload = JSON.parse(allowed.stdout);
assert.equal(payload.decision, "block");
assert.match(payload.reason, /Missing empty-state guard/i);
assert.equal(allowed.stdout.trim(), "");
assert.match(allowed.stderr, /Codex is not set up for the review gate/i);
assert.match(allowed.stderr, /not authenticated/i);
assert.match(allowed.stderr, /!codex login/i);
});
test("commands lazily start and reuse one shared app-server after first use", async () => {
@@ -2025,51 +1671,6 @@ test("commands lazily start and reuse one shared app-server after first use", as
assert.equal(cleanup.status, 0, cleanup.stderr);
});
test("setup reuses an existing shared app-server without starting another one", () => {
const repo = makeTempDir();
const binDir = makeTempDir();
const fakeStatePath = path.join(binDir, "fake-codex-state.json");
installFakeCodex(binDir);
initGitRepo(repo);
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
run("git", ["add", "README.md"], { cwd: repo });
run("git", ["commit", "-m", "init"], { cwd: repo });
fs.writeFileSync(path.join(repo, "README.md"), "hello again\n");
const env = buildEnv(binDir);
const review = run("node", [SCRIPT, "review"], {
cwd: repo,
env
});
assert.equal(review.status, 0, review.stderr);
const brokerSession = loadBrokerSession(repo);
if (!brokerSession) {
return;
}
const setup = run("node", [SCRIPT, "setup", "--json"], {
cwd: repo,
env
});
assert.equal(setup.status, 0, setup.stderr);
const fakeState = JSON.parse(fs.readFileSync(fakeStatePath, "utf8"));
assert.equal(fakeState.appServerStarts, 1);
const cleanup = run("node", [SESSION_HOOK, "SessionEnd"], {
cwd: repo,
env,
input: JSON.stringify({
hook_event_name: "SessionEnd",
cwd: repo
})
});
assert.equal(cleanup.status, 0, cleanup.stderr);
});
test("status reports shared session runtime when a lazy broker is active", () => {
const repo = makeTempDir();
const binDir = makeTempDir();