fix(coding-agent): preserve history in terminal hooks
This commit is contained in:
@@ -4403,8 +4403,9 @@ export class AgentSession {
|
||||
// Check auto-retry and auto-compaction after agent completes
|
||||
if (event.type === "agent_end") {
|
||||
const settledMessages = event.messages;
|
||||
const activeMessages = this.agent.state.messages;
|
||||
const emitAgentEndNotification = async (isTerminal = true) => {
|
||||
await this.#emitAgentEndNotification(settledMessages);
|
||||
await this.#emitAgentEndNotification(activeMessages);
|
||||
await this.#emitSessionEvent({ ...event, isTerminal });
|
||||
};
|
||||
const usage = this.getSessionStats().tokens;
|
||||
@@ -4654,7 +4655,7 @@ export class AgentSession {
|
||||
await emitAgentEndNotification(false);
|
||||
return;
|
||||
}
|
||||
await this.#emitSessionStopEvent(settledMessages, msg);
|
||||
await this.#emitSessionStopEvent(activeMessages, msg);
|
||||
await emitAgentEndNotification();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -344,6 +344,7 @@ describe("AgentSession concurrent prompt guard", () => {
|
||||
convertToLlm,
|
||||
});
|
||||
const stopEvents: Array<{
|
||||
messages: AgentMessage[];
|
||||
stop_hook_active: boolean;
|
||||
session_id: string;
|
||||
turn_id: number;
|
||||
@@ -399,6 +400,14 @@ describe("AgentSession concurrent prompt guard", () => {
|
||||
expect(stopEvents.map(event => event.turn_id)).toEqual([0, 0]);
|
||||
expect(stopEvents[0]?.session_id).toBe(session.sessionId);
|
||||
expect(stopEvents[0]?.last_assistant_message?.role).toBe("assistant");
|
||||
expect(
|
||||
stopEvents[1]?.messages.some(
|
||||
message =>
|
||||
message.role === "user" &&
|
||||
Array.isArray(message.content) &&
|
||||
message.content.some(block => block.type === "text" && block.text === "First message"),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("uses non-empty session_stop reason when additional context is empty", async () => {
|
||||
|
||||
Reference in New Issue
Block a user