Add incremental file caching for multi-repo analysis in KV store
Problem
When analyzing multiple repositories sequentially (related to #6), RepoMind re-processes identical or overlapping files across repos. The current caching strategy in src/lib/cag/cache.ts stores compressed file data in KV, but there's no mechanism to:
- Detect when the same file exists across multiple repos (e.g., common utility files, shared dependencies)
- Skip re-fetching identical files by content hash
- Track which repos have already loaded a given file to avoid redundant AI processing
This causes:
- Duplicate API calls to GitHub for the same file content
- Redundant tokenization and AI processing when analyzing related codebases
- Slower org-level analysis (#6) due to repeated file fetches
Why it matters
Organizations analyzing multiple related repos (monorepos, service ecosystems, forked projects) will see 2-3x slower performance than necessary. With org-level analysis coming in #6, this becomes a critical path blocker.
What good looks like
When a user analyzes:
org/repo-a→ loadsshared/utils.tsorg/repo-b→ detects same file already cached → reuses without re-fetch- System stores:
{contentHash, fileKey, repos: [repo-a, repo-b]}
The KV cache entry for a file should track:
contentHash: SHA256 of file content (not path, since path varies by repo)lastAccessed: timestamp for LRU evictionrepoSources: array of{owner, repo, path}tuples where this file was found
Implementation notes
Looking at src/lib/cag/hierarchicalPruning.ts and how it calls fetchFileContent(), the cache key generation at line ~42 should include a content-based component:
// Current: cache key = `${owner}/${repo}/files/${path}`
// Proposed: cache key = `content-hash-${contentHash}` with metadata tracking sources
This requires:
- Computing file content hash during
fetchFileContent()(before compression) - Updating
src/lib/cag/cache.tsto support hash-based keys alongside path-based keys - Modifying the metadata structure to track
repoSourcesfor debugging/stats
For org-level analysis (#6), this becomes: "load unique files once, reuse across all repos in the org."
Acceptance criteria
- [ ] Identical files across different repos use single KV cache entry
- [ ] Cache metadata includes list of repos where file was found
- [ ] File is fetched only once even if referenced in 10 repos
- [ ] No changes to public API of
fetchFileContent() - [ ] Cache hit rate visible in debug logs (e.g., "10 files, 3 cache hits")
Contributed by Klement Gunndu
Withdrawing this issue. Apologies for any inconvenience.