repomind icon indicating copy to clipboard operation
repomind copied to clipboard

Add incremental file caching for multi-repo analysis in KV store

Open KlementMultiverse opened this issue 8 months ago • 1 comments

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:

  1. Detect when the same file exists across multiple repos (e.g., common utility files, shared dependencies)
  2. Skip re-fetching identical files by content hash
  3. 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:

  1. org/repo-a → loads shared/utils.ts
  2. org/repo-b → detects same file already cached → reuses without re-fetch
  3. 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 eviction
  • repoSources: 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:

  1. Computing file content hash during fetchFileContent() (before compression)
  2. Updating src/lib/cag/cache.ts to support hash-based keys alongside path-based keys
  3. Modifying the metadata structure to track repoSources for 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

KlementMultiverse avatar Mar 08 '26 05:03 KlementMultiverse

Withdrawing this issue. Apologies for any inconvenience.

KlementMultiverse avatar Mar 09 '26 02:03 KlementMultiverse