Skip to content
Merged
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
18 changes: 12 additions & 6 deletions src/supervisor/agents/codex/acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ export class CodexStructuredSession implements StructuredSessionHandle {
): Promise<void> {
switch (command.kind) {
case "set":
if (this.ensureMapperState().goalItemId) {
await this.rpc.request("thread/goal/clear", { threadId });
}
await this.rpc.request("thread/goal/set", {
threadId,
objective: command.objective,
Expand All @@ -369,12 +372,15 @@ export class CodexStructuredSession implements StructuredSessionHandle {

async controlGoal(control: ThreadGoalControl): Promise<void> {
const threadId = await this.waitForRemoteThreadId();
await this.dispatchCodexGoalCommand(
threadId,
control.action === "edit"
? { kind: "set", objective: control.objective }
: { kind: control.action },
);
if (control.action === "edit") {
await this.rpc.request("thread/goal/set", {
threadId,
objective: control.objective,
status: "active",
});
return;
}
await this.dispatchCodexGoalCommand(threadId, { kind: control.action });
}

private updateSlashCommands(commands: AgentSlashCommand[]): void {
Expand Down
40 changes: 40 additions & 0 deletions src/supervisor/agents/codex/codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,46 @@ describe("CodexStructuredSession", () => {
expect(updates).not.toContainEqual({ status: "idle", attention: "none" });
});

it("clears an existing goal before /goal replaces it", async () => {
const requests: Array<{ method: string; params: Record<string, unknown> }> = [];
const structuredSession = makeStructuredSession(requests);
dispatchNotification(structuredSession, {
jsonrpc: "2.0",
method: "thread/goal/updated",
params: {
threadId: "provider-thread",
turnId: null,
goal: {
threadId: "provider-thread",
objective: "previous goal",
status: "active",
tokenBudget: null,
tokensUsed: 7_900_000,
timeUsedSeconds: 29_580,
createdAt: 1778570000,
updatedAt: 1778599580,
},
},
});

await structuredSession.startTurn("/goal start fresh", { model: "gpt-5.4" });

expect(requests).toEqual([
{
method: "thread/goal/clear",
params: { threadId: "provider-thread" },
},
{
method: "thread/goal/set",
params: {
threadId: "provider-thread",
objective: "start fresh",
status: "active",
},
},
]);
});

it("settles /goal <objective> when Codex does not start a model turn", async () => {
const requests: Array<{ method: string; params: Record<string, unknown> }> = [];
const structuredSession = makeStructuredSession(requests);
Expand Down