Remove event logging from session files - only save messages and state changes

Session reconstruction only needs:
- type: 'session' - session metadata
- type: 'message' - conversation history
- type: 'thinking_level_change' - thinking level changes
- type: 'model_change' - model changes

Events like agent_start/end, tool_execution_start/end are not needed for
session reconstruction and only added bloat. This reduces session file size
significantly and speeds up writes.
This commit is contained in:
Mario Zechner 2025-11-12 21:56:29 +01:00
parent 9e3e319f1a
commit 5e988b444b
2 changed files with 2 additions and 23 deletions

View file

@ -449,17 +449,12 @@ export async function main(args: string[]) {
}
}
// Subscribe to agent events to save messages and log events
// Subscribe to agent events to save messages
agent.subscribe((event) => {
// Save messages on completion
if (event.type === "message_end") {
sessionManager.saveMessage(event.message);
}
// Log all events except message_update (too verbose)
if (event.type !== "message_update") {
sessionManager.saveEvent(event);
}
});
// Route to appropriate mode

View file

@ -1,4 +1,4 @@
import type { AgentEvent, AgentState } from "@mariozechner/pi-agent";
import type { AgentState } from "@mariozechner/pi-agent";
import { randomBytes } from "crypto";
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "fs";
import { homedir } from "os";
@ -27,12 +27,6 @@ export interface SessionMessageEntry {
message: any; // AppMessage from agent state
}
export interface SessionEventEntry {
type: "event";
timestamp: string;
event: AgentEvent;
}
export interface ThinkingLevelChangeEntry {
type: "thinking_level_change";
timestamp: string;
@ -152,16 +146,6 @@ export class SessionManager {
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
}
saveEvent(event: AgentEvent): void {
if (!this.enabled) return;
const entry: SessionEventEntry = {
type: "event",
timestamp: new Date().toISOString(),
event,
};
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
}
saveThinkingLevelChange(thinkingLevel: string): void {
if (!this.enabled) return;
const entry: ThinkingLevelChangeEntry = {