Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ import {
} from "./commands"
import { type HostPermissionSnapshot } from "./host-permissions"
import { compressPermission, syncCompressPermissionState } from "./compress-permission"
import { checkSession, ensureSessionInitialized, saveSessionState, syncToolCache } from "./state"
import {
checkSession,
deleteSessionState,
ensureSessionInitialized,
saveSessionState,
syncToolCache,
} from "./state"
import { cacheSystemPromptTokens } from "./ui/utils"

const INTERNAL_AGENT_SIGNATURES = [
Expand Down Expand Up @@ -293,6 +299,14 @@ export function createEventHandler(state: SessionState, logger: Logger) {
? input.event.properties.time
: undefined

if (input.event.type === "session.deleted") {
const sessionId = input.event.properties.info?.id
if (sessionId) {
await deleteSessionState(sessionId).catch(() => {})
}
return
}

if (input.event.type !== "message.part.updated") {
return
}
Expand Down
5 changes: 5 additions & 0 deletions lib/state/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ export async function loadSessionState(
}
}

export async function deleteSessionState(sessionId: string): Promise<void> {
const filePath = getSessionFilePath(sessionId)
await fs.unlink(filePath)
}

export interface AggregatedStats {
totalTokens: number
totalTools: number
Expand Down