Fix SessionEntry type to exclude SessionHeader

- SessionEntry now only contains conversation entries (messages, compaction, etc.)
- SessionHeader is separate, not part of SessionEntry
- FileEntry = SessionHeader | SessionEntry (for file storage)
- getEntries() filters out header, returns SessionEntry[]
- Added getHeader() for accessing session metadata
- Updated compaction and tests to not expect header in entries
- Updated mom package to use FileEntry for internal storage
This commit is contained in:
Mario Zechner 2025-12-26 00:31:53 +01:00
parent 251fea752c
commit 9478a3c1f5
6 changed files with 50 additions and 75 deletions

View file

@ -14,6 +14,7 @@ import type { AppMessage } from "@mariozechner/pi-agent-core";
import {
buildSessionContext,
type CompactionEntry,
type FileEntry,
type LoadedSession,
type MessageContent,
type ModelChangeContent,
@ -52,7 +53,7 @@ export class MomSessionManager {
private logFile: string;
private channelDir: string;
private flushed: boolean = false;
private inMemoryEntries: SessionEntry[] = [];
private inMemoryEntries: FileEntry[] = [];
private leafId: string | null = null;
constructor(channelDir: string) {
@ -259,17 +260,17 @@ export class MomSessionManager {
return null;
}
private loadEntriesFromFile(): SessionEntry[] {
private loadEntriesFromFile(): FileEntry[] {
if (!existsSync(this.contextFile)) return [];
const content = readFileSync(this.contextFile, "utf8");
const entries: SessionEntry[] = [];
const entries: FileEntry[] = [];
const lines = content.trim().split("\n");
for (const line of lines) {
if (!line.trim()) continue;
try {
const entry = JSON.parse(line) as SessionEntry;
const entry = JSON.parse(line) as FileEntry;
entries.push(entry);
} catch {
// Skip malformed lines
@ -313,10 +314,8 @@ export class MomSessionManager {
loadEntries(): SessionEntry[] {
// Re-read from file to get latest state
if (existsSync(this.contextFile)) {
return this.loadEntriesFromFile();
}
return [...this.inMemoryEntries];
const entries = existsSync(this.contextFile) ? this.loadEntriesFromFile() : this.inMemoryEntries;
return entries.filter((e): e is SessionEntry => e.type !== "session");
}
getSessionId(): string {