mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-05-21 15:52:37 +00:00
milestone-3: avoid caching partial transcript parses
This commit is contained in:
@@ -54,6 +54,8 @@ interface TranscriptCacheFile {
|
||||
data: SerializedTranscriptData;
|
||||
}
|
||||
|
||||
let createReadStreamImpl: typeof fs.createReadStream = fs.createReadStream;
|
||||
|
||||
function getTranscriptCachePath(transcriptPath: string, homeDir: string): string {
|
||||
const hash = createHash('sha256').update(path.resolve(transcriptPath)).digest('hex');
|
||||
return path.join(getHudPluginDir(homeDir), 'transcript-cache', `${hash}.json`);
|
||||
@@ -172,8 +174,10 @@ export async function parseTranscript(transcriptPath: string): Promise<Transcrip
|
||||
let latestSlug: string | undefined;
|
||||
let customTitle: string | undefined;
|
||||
|
||||
let parsedCleanly = false;
|
||||
|
||||
try {
|
||||
const fileStream = fs.createReadStream(transcriptPath);
|
||||
const fileStream = createReadStreamImpl(transcriptPath);
|
||||
const rl = readline.createInterface({
|
||||
input: fileStream,
|
||||
crlfDelay: Infinity,
|
||||
@@ -194,6 +198,8 @@ export async function parseTranscript(transcriptPath: string): Promise<Transcrip
|
||||
// Skip malformed lines
|
||||
}
|
||||
}
|
||||
|
||||
parsedCleanly = true;
|
||||
} catch {
|
||||
// Return partial results on error
|
||||
}
|
||||
@@ -202,11 +208,17 @@ export async function parseTranscript(transcriptPath: string): Promise<Transcrip
|
||||
result.agents = Array.from(agentMap.values()).slice(-10);
|
||||
result.todos = latestTodos;
|
||||
result.sessionName = customTitle ?? latestSlug;
|
||||
writeTranscriptCache(transcriptPath, transcriptState, result);
|
||||
if (parsedCleanly) {
|
||||
writeTranscriptCache(transcriptPath, transcriptState, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function _setCreateReadStreamForTests(impl: typeof fs.createReadStream | null): void {
|
||||
createReadStreamImpl = impl ?? fs.createReadStream;
|
||||
}
|
||||
|
||||
function processEntry(
|
||||
entry: TranscriptLine,
|
||||
toolMap: Map<string, ToolEntry>,
|
||||
|
||||
Reference in New Issue
Block a user