Bug
In cmd/precompact.go lines 127–135, the intent is to collect at most 10 file paths from the transcript. However the break only exits the inner strings.Fields word loop, not the outer loop over transcript lines:
for _, word := range strings.Fields(text) { // inner loop
if looksLikeFilePath(word) && !seenFiles[word] {
seenFiles[word] = true
filesInFocus = append(filesInFocus, word)
if len(filesInFocus) >= 10 {
break // only exits inner loop; outer loop continues
}
}
}
If the transcript has many lines (a long session), unique file paths from later messages continue to be appended after the 10-file threshold is crossed. The seenFiles deduplication prevents duplicates but does not enforce the intended cap.
Impact
The session snapshot's "files in focus" list injected into the context bomb grows unboundedly with long transcripts, potentially exceeding the intended limit and wasting tokens in the context window.
Fix
Add a guard at the top of the outer loop to stop processing once the cap is reached:
for _, msg := range recentMessages {
if len(filesInFocus) >= 10 {
break
}
// ... existing word scanning logic
}
@claude please implement this