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:
@@ -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) => {
|
agent.subscribe((event) => {
|
||||||
// Save messages on completion
|
// Save messages on completion
|
||||||
if (event.type === "message_end") {
|
if (event.type === "message_end") {
|
||||||
sessionManager.saveMessage(event.message);
|
sessionManager.saveMessage(event.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log all events except message_update (too verbose)
|
|
||||||
if (event.type !== "message_update") {
|
|
||||||
sessionManager.saveEvent(event);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Route to appropriate mode
|
// Route to appropriate mode
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { AgentEvent, AgentState } from "@mariozechner/pi-agent";
|
import type { AgentState } from "@mariozechner/pi-agent";
|
||||||
import { randomBytes } from "crypto";
|
import { randomBytes } from "crypto";
|
||||||
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "fs";
|
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "fs";
|
||||||
import { homedir } from "os";
|
import { homedir } from "os";
|
||||||
@@ -27,12 +27,6 @@ export interface SessionMessageEntry {
|
|||||||
message: any; // AppMessage from agent state
|
message: any; // AppMessage from agent state
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SessionEventEntry {
|
|
||||||
type: "event";
|
|
||||||
timestamp: string;
|
|
||||||
event: AgentEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ThinkingLevelChangeEntry {
|
export interface ThinkingLevelChangeEntry {
|
||||||
type: "thinking_level_change";
|
type: "thinking_level_change";
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
@@ -152,16 +146,6 @@ export class SessionManager {
|
|||||||
appendFileSync(this.sessionFile, JSON.stringify(entry) + "\n");
|
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 {
|
saveThinkingLevelChange(thinkingLevel: string): void {
|
||||||
if (!this.enabled) return;
|
if (!this.enabled) return;
|
||||||
const entry: ThinkingLevelChangeEntry = {
|
const entry: ThinkingLevelChangeEntry = {
|
||||||
|
|||||||
Reference in New Issue
Block a user