From 35c34ea06b380cd065b25490116c472ded518b74 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 4 Apr 2026 01:13:02 +0900 Subject: [PATCH] fix(hooks): preserve transcript cache history across rebuilds Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/hooks/claude-code-hooks/transcript.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hooks/claude-code-hooks/transcript.ts b/src/hooks/claude-code-hooks/transcript.ts index 2c1c56723..ce1f9c98e 100644 --- a/src/hooks/claude-code-hooks/transcript.ts +++ b/src/hooks/claude-code-hooks/transcript.ts @@ -165,10 +165,12 @@ export async function buildTranscriptFromSession( ): Promise { try { let baseEntries: string[] + let previousTempPath: string | null = null const cached = transcriptCache.get(sessionId) if (cached && isCacheValid(cached)) { baseEntries = cached.baseEntries + previousTempPath = cached.tempPath } else { // Fetch full session messages (only on first call or cache expiry) const response = await client.session.messages({ @@ -199,6 +201,10 @@ export async function buildTranscriptFromSession( // Append current tool call const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)] + if (previousTempPath) { + try { unlinkSync(previousTempPath) } catch { /* ignore */ } + } + const tempPath = join( tmpdir(), `opencode-transcript-${sessionId}-${randomUUID()}.jsonl` @@ -208,7 +214,9 @@ export async function buildTranscriptFromSession( // Update cache temp path for cleanup tracking const cacheEntry = transcriptCache.get(sessionId) if (cacheEntry) { + cacheEntry.baseEntries = allEntries cacheEntry.tempPath = tempPath + cacheEntry.createdAt = Date.now() } return tempPath