Fix compaction status reset

This commit is contained in:
Federico Jaramillo Martinez
2026-05-08 22:22:08 +02:00
parent 8a5910ff10
commit a59268dbfd
2 changed files with 17 additions and 0 deletions
+10
View File
@@ -72,6 +72,16 @@ export class PiSessionService {
(sessionId) => this.getActive(sessionId),
(sessionId, text) => this.prompt(sessionId, text),
events,
{
onCompactionStart: (session) => {
this.publishActivity(session, "compacting", "active");
this.publishStatus(session);
},
onCompactionEnd: (session, result, detail) => {
this.publishActivity(session, result === "success" ? "compaction complete" : "compaction failed", result === "success" ? "idle" : "error", detail);
this.publishStatus(session);
},
},
);
}
@@ -17,6 +17,10 @@ export class SessionCommandService {
private readonly getActive: GetActiveSession,
private readonly prompt: (sessionId: string, text: string) => Promise<void>,
private readonly events: SessionEventHub,
private readonly lifecycle: {
onCompactionStart?: (session: AgentSession) => void;
onCompactionEnd?: (session: AgentSession, result: "success" | "error", detail?: string) => void;
} = {},
) {}
async run(sessionId: string, text: string): Promise<ClientCommandResult> {
@@ -60,6 +64,7 @@ export class SessionCommandService {
}
private compact(session: AgentSession, instructions: string): ClientCommandResult {
this.lifecycle.onCompactionStart?.(session);
void session.compact(instructions === "" ? undefined : instructions)
.then((result) => {
this.events.publish(session.sessionId, {
@@ -67,11 +72,13 @@ export class SessionCommandService {
level: "success",
message: formatCompactionResult(result),
});
this.lifecycle.onCompactionEnd?.(session, "success");
})
.catch((error: unknown) => {
const message = error instanceof Error ? error.message : String(error);
this.events.publish(session.sessionId, { type: "command.output", level: "error", message: `Compaction failed: ${message}` });
this.events.publish(session.sessionId, { type: "session.error", message });
this.lifecycle.onCompactionEnd?.(session, "error", message);
});
return { type: "done", message: "Compaction started…" };
}