Skip to content
Draft
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
9 changes: 6 additions & 3 deletions plugins/codex/scripts/codex-companion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ async function executeTaskRun(request) {
sandbox: request.write ? "workspace-write" : "read-only",
onProgress: request.onProgress,
persistThread: true,
threadName: resumeThreadId ? null : buildPersistentTaskThreadName(request.prompt || DEFAULT_CONTINUE_PROMPT)
threadName: resumeThreadId ? null : buildPersistentTaskThreadName(request.prompt || DEFAULT_CONTINUE_PROMPT),
threadSource: taskMetadata.threadSource
});

const rawOutput = typeof result.finalMessage === "string" ? result.finalMessage : "";
Expand Down Expand Up @@ -541,15 +542,17 @@ function buildTaskRunMetadata({ prompt, resumeLast = false }) {
if (!resumeLast && String(prompt ?? "").includes(STOP_REVIEW_TASK_MARKER)) {
return {
title: "Codex Stop Gate Review",
summary: "Stop-gate review of previous Claude turn"
summary: "Stop-gate review of previous Claude turn",
threadSource: null
};
}

const title = resumeLast ? "Codex Resume" : "Codex Task";
const fallbackSummary = resumeLast ? DEFAULT_CONTINUE_PROMPT : "Task";
return {
title,
summary: shorten(prompt || fallbackSummary)
summary: shorten(prompt || fallbackSummary),
threadSource: "user"
};
}

Expand Down
6 changes: 4 additions & 2 deletions plugins/codex/scripts/lib/codex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function buildThreadParams(cwd, options = {}) {
approvalPolicy: options.approvalPolicy ?? "never",
sandbox: options.sandbox ?? "read-only",
serviceName: SERVICE_NAME,
ephemeral: options.ephemeral ?? true
ephemeral: options.ephemeral ?? true,
...(options.threadSource ? { threadSource: options.threadSource } : {})
};
}

Expand Down Expand Up @@ -1115,7 +1116,8 @@ export async function runAppServerTurn(cwd, options = {}) {
model: options.model,
sandbox: options.sandbox,
ephemeral: options.persistThread ? false : true,
threadName: options.persistThread ? options.threadName : options.threadName ?? null
threadName: options.persistThread ? options.threadName : options.threadName ?? null,
threadSource: options.threadSource
});
threadId = response.thread.id;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/fake-codex-fixture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ function send(message) {
process.stdout.write(JSON.stringify(message) + "\\n");
}

function nextThread(state, cwd, ephemeral) {
function nextThread(state, cwd, ephemeral, threadSource = null) {
const thread = {
id: "thr_" + state.nextThreadId++,
cwd: cwd || process.cwd(),
name: null,
preview: "",
ephemeral: Boolean(ephemeral),
threadSource,
createdAt: now(),
updatedAt: now()
};
Expand Down Expand Up @@ -312,7 +313,7 @@ rl.on("line", (line) => {
if (requiresExperimental("persistExtendedHistory", message, state) || requiresExperimental("persistFullHistory", message, state)) {
throw new Error("thread/start.persistFullHistory requires experimentalApi capability");
}
const thread = nextThread(state, message.params.cwd, message.params.ephemeral);
const thread = nextThread(state, message.params.cwd, message.params.ephemeral, message.params.threadSource ?? null);
send({ id: message.id, result: { thread: buildThread(thread), model: message.params.model || "gpt-5.4", modelProvider: "openai", serviceTier: null, cwd: thread.cwd, approvalPolicy: "never", sandbox: { type: "readOnly", access: { type: "fullAccess" }, networkAccess: false }, reasoningEffort: null } });
send({ method: "thread/started", params: { thread: { id: thread.id } } });
break;
Expand Down
8 changes: 8 additions & 0 deletions tests/runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ test("review renders a no-findings result from app-server review/start", () => {
assert.equal(result.status, 0);
assert.match(result.stdout, /Reviewed uncommitted changes/);
assert.match(result.stdout, /No material issues found/);
const fakeState = JSON.parse(fs.readFileSync(path.join(binDir, "fake-codex-state.json"), "utf8"));
assert.equal(fakeState.threads[0].threadSource, null);
});

test("task runs when the active provider does not require OpenAI login", () => {
Expand All @@ -173,6 +175,8 @@ test("task runs when the active provider does not require OpenAI login", () => {

assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Handled the requested task/);
const fakeState = JSON.parse(fs.readFileSync(path.join(binDir, "fake-codex-state.json"), "utf8"));
assert.equal(fakeState.threads[0].threadSource, "user");
});

test("task runs without auth preflight so Codex can refresh an expired session", () => {
Expand Down Expand Up @@ -384,6 +388,8 @@ test("adversarial review renders structured findings over app-server turn/start"

assert.equal(result.status, 0);
assert.match(result.stdout, /Missing empty-state guard/);
const fakeState = JSON.parse(fs.readFileSync(path.join(binDir, "fake-codex-state.json"), "utf8"));
assert.equal(fakeState.threads[0].threadSource, null);
});

test("adversarial review accepts the same base-branch targeting as review", () => {
Expand Down Expand Up @@ -1967,6 +1973,8 @@ test("stop hook runs a stop-time review task and blocks on findings when the rev
assert.match(fakeState.lastTurnStart.prompt, /<compact_output_contract>/i);
assert.match(fakeState.lastTurnStart.prompt, /Only review the work from the previous Claude turn/i);
assert.match(fakeState.lastTurnStart.prompt, /I completed the refactor and updated the retry logic\./);
assert.equal(fakeState.threads[0].threadSource, null);
assert.equal(fakeState.threads[1].threadSource, "user");

const status = run("node", [SCRIPT, "status"], {
cwd: repo,
Expand Down