The session_entries supersede pipeline was a design that never shipped: `SqliteSessionStore.replaceMessages` / `appendCompaction`, `sessionEntries.replace` / `listAll` / `deleteForSession`, and the `"compaction" | "summary"` kind variants had zero live callers. Compaction wires through pi's `transformContext` and leaves the persisted transcript alone, so the shadow-row machinery was pure cruft with two tests propping it up. Rip it out: the store exposes only `loadMessages` and `appendMessage`, `sessionEntries` exposes only `append` and `listActive`, and `SessionEntryKind` narrows to `"message"` so new writers can't re-introduce a dead kind by accident. `is_superseded` stays on the table — the DB column is harmless with no writer, and dropping it is a separate schema migration concern. `listTopLevelAgentIds` loses its only caller in the previous commit (company channel now fans out through `listCompanyBroadcastAgentIds`), so it goes too. Three tests that validated the removed behaviour are deleted; the one remaining session-store test still covers the live `append + load` path.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
|
import type { AppDatabase } from "@main/database";
|
|
|
|
/**
|
|
* SQLite-backed pi `AgentMessage[]` store.
|
|
*
|
|
* One store instance per task_session. `appendMessage` runs exactly
|
|
* once per pi `message_end` event; `loadMessages` reads the live
|
|
* transcript back at `prepareRun`. Compaction happens at LLM-call
|
|
* time via pi's `transformContext` hook and does not rewrite the
|
|
* persisted transcript — the session shadow is the durable truth,
|
|
* the compacted payload is a per-call view.
|
|
*/
|
|
export class SqliteSessionStore {
|
|
constructor(
|
|
private readonly db: AppDatabase,
|
|
public readonly taskSessionId: string,
|
|
) {}
|
|
|
|
loadMessages(): AgentMessage[] {
|
|
const rows = this.db.sessionEntries.listActive(this.taskSessionId);
|
|
const result: AgentMessage[] = [];
|
|
for (const row of rows) {
|
|
if (row.kind === "message") {
|
|
result.push(JSON.parse(row.payloadJson) as AgentMessage);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
appendMessage(message: AgentMessage): void {
|
|
this.db.sessionEntries.append({
|
|
taskSessionId: this.taskSessionId,
|
|
kind: "message",
|
|
role: (message as { role?: string }).role ?? null,
|
|
payloadJson: JSON.stringify(message),
|
|
});
|
|
}
|
|
}
|