Skip to content

Commit f47129f

Browse files
committed
Separate goal status updates from prior text
1 parent 0101238 commit f47129f

5 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/CodexEventHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class CodexEventHandler {
281281
sessionUpdate: "agent_message_chunk",
282282
content: {
283283
type: "text",
284-
text: `${text}\n\n`,
284+
text: `\n\n${text}\n\n`,
285285
},
286286
};
287287
}
@@ -313,7 +313,7 @@ export class CodexEventHandler {
313313
sessionUpdate: "agent_message_chunk",
314314
content: {
315315
type: "text",
316-
text: "Goal cleared.\n\n",
316+
text: "\n\nGoal cleared.\n\n",
317317
},
318318
};
319319
}

src/__tests__/CodexACPAgent/data/thread-goal-cleared.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "agent_message_chunk",
88
"content": {
99
"type": "text",
10-
"text": "Goal cleared.\n\n"
10+
"text": "\n\nGoal cleared.\n\n"
1111
}
1212
}
1313
}

src/__tests__/CodexACPAgent/data/thread-goal-updated-multiline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "agent_message_chunk",
88
"content": {
99
"type": "text",
10-
"text": "Goal updated (budget limited):\nFirst task\nSecond task\n\n"
10+
"text": "\n\nGoal updated (budget limited):\nFirst task\nSecond task\n\n"
1111
}
1212
}
1313
}

src/__tests__/CodexACPAgent/data/thread-goal-updated.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "agent_message_chunk",
88
"content": {
99
"type": "text",
10-
"text": "Goal updated (active): Ship the goal update\n\n"
10+
"text": "\n\nGoal updated (active): Ship the goal update\n\n"
1111
}
1212
}
1313
}

src/__tests__/CodexACPAgent/thread-goal-events.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,44 @@ describe("CodexEventHandler - thread goal events", () => {
123123

124124
const events = mockFixture.getAcpConnectionEvents([]);
125125
expect(events).toHaveLength(1);
126-
expect(events[0]!.args[0].update.content.text).toBe("Goal updated (active): Ship the goal update\n\n");
126+
expect(events[0]!.args[0].update.content.text).toBe("\n\nGoal updated (active): Ship the goal update\n\n");
127+
});
128+
129+
it("should separate completed goal updates from preceding agent text", async () => {
130+
const goalCompletedNotification: ServerNotification = {
131+
method: "thread/goal/updated",
132+
params: {
133+
threadId: sessionId,
134+
turnId: "turn-1",
135+
goal: {
136+
threadId: sessionId,
137+
objective: "tell me a joke",
138+
status: "complete",
139+
tokenBudget: null,
140+
tokensUsed: 42,
141+
timeUsedSeconds: 12,
142+
createdAt: 1710000000,
143+
updatedAt: 1710000012,
144+
},
145+
},
146+
};
147+
148+
await setupPromptAndSendNotifications(mockFixture, sessionId, createSessionState(), [
149+
{
150+
method: "item/agentMessage/delta",
151+
params: {
152+
threadId: sessionId,
153+
turnId: "turn-1",
154+
itemId: "message-1",
155+
delta: "Because they kept losing interest in `any`.",
156+
},
157+
},
158+
goalCompletedNotification,
159+
]);
160+
161+
const events = mockFixture.getAcpConnectionEvents([]);
162+
expect(events).toHaveLength(2);
163+
expect(events[1]!.args[0].update.content.text).toBe("\n\nGoal updated (complete): tell me a joke\n\n");
127164
});
128165

129166
it("should suppress duplicate thread goal cleared notifications", async () => {
@@ -141,7 +178,7 @@ describe("CodexEventHandler - thread goal events", () => {
141178

142179
const events = mockFixture.getAcpConnectionEvents([]);
143180
expect(events).toHaveLength(1);
144-
expect(events[0]!.args[0].update.content.text).toBe("Goal cleared.\n\n");
181+
expect(events[0]!.args[0].update.content.text).toBe("\n\nGoal cleared.\n\n");
145182
});
146183

147184
function createSessionState(): SessionState {

0 commit comments

Comments
 (0)