fix(hooks): preserve transcript cache history across rebuilds

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-04 01:13:02 +09:00
parent 58e85960a1
commit 35c34ea06b
@@ -165,10 +165,12 @@ export async function buildTranscriptFromSession(
): Promise<string | null> {
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