feat(context): add intelligent context caching and diff tracking#26
Merged
foundatron merged 1 commit intomainfrom Mar 11, 2026
Merged
feat(context): add intelligent context caching and diff tracking#26foundatron merged 1 commit intomainfrom
foundatron merged 1 commit intomainfrom
Conversation
…fetching - Add ContextEntry model and context_cache table in SQLite store - Rewrite fetch_context() to return ContextResult with context string and changed_files list; writes fresh content to both DB and filesystem caches - Fallback chain: fresh fetch → DB cache → filesystem cache - Pass store to fetch_context in cli.py; log when context files change - Add comprehensive tests for context caching, fallbacks, and change detection Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
Changes
1.
tentacle/models.py— AddContextEntrydataclassContextEntrywith fields:filename: str,content: str,checksum: str,fetched_at: datetime,id: int | None = None2.
tentacle/db.py— Addcontext_cachetable and Store methodscontext_cachetable to_SCHEMA:(id INTEGER PRIMARY KEY AUTOINCREMENT, filename TEXT NOT NULL UNIQUE, content TEXT NOT NULL, checksum TEXT NOT NULL, fetched_at TEXT NOT NULL)Store.upsert_context(entry: ContextEntry) -> None— INSERT OR REPLACE by filenameStore.get_context(filename: str) -> ContextEntry | None— fetch cached entry by filename_row_to_context_entryconverter following existing patternget_all_context()— nothing uses it.3.
tentacle/context.py— Rewrite with caching and change detectionimport hashliband imports forStore,ContextEntryfrom the project_checksum(content: str) -> strhelper using SHA-256ContextResultdataclass:context: str,changed_files: list[str]diff_summaryfield — checksums are sufficient for change detection; diffs in LLM context add noise, not signal._read_fileto only handle fetching (local paths +ghCLI). Remove the filesystem cache fallback from_read_file— move it tofetch_context.fetch_context(repo_path: str | None = None, store: Store | None = None) -> ContextResult:_CONTEXT_FILES, call_read_file(filename, repo_path)to get fresh content.store.get_context(filename). If different (or no cached entry), add filename tochanged_files. Upsert new entry._CACHE_DIR / filenameas filesystem fallback (withmkdir(parents=True, exist_ok=True)for subdirectories likedocs/).store.get_context(filename)cached content. Log warning._CACHE_DIR / filename. Log warning.ContextResult.contextusing existing### filename\n\ncontentformat.store=None,changed_filesis always empty (no prior state to compare).4.
tentacle/cli.py— Pass store tofetch_contextcontext_result = fetch_context(store=store)(note:storeis created on line 115)contexttocontext_result.contextwhere passed toanalyze_articlecontext_result.changed_filesis non-emptyReview Findings
The main error is the double-patching in the test that leaves dead code and works by accident. The warnings around missing error handling on filesystem writes, no cache staleness tracking, and the encoding assumption should be addressed before merge.