feat: branch-scoped memory with git ancestry filtering#1246
Open
thedotmack wants to merge 11 commits intomainfrom
Open
feat: branch-scoped memory with git ancestry filtering#1246thedotmack wants to merge 11 commits intomainfrom
thedotmack wants to merge 11 commits intomainfrom
Conversation
…hase 01) Add branch and commit_sha columns to observations table via migration 24, create git branch detection utility, and thread branch metadata through the entire observation pipeline from hook layer through worker to database storage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ry (Phase 02) Add git-ancestry.ts with getCurrentHead, resolveAncestorCommits, and resolveVisibleCommitShas functions that power branch isolation by determining which commits are ancestors of HEAD. Add getUniqueCommitShasForProject query helper in observations/get.ts. All 10 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…(Phase 03) Wire branch visibility resolution into the context injection pipeline so observations from sibling branches are excluded while merged branch work and pre-migration observations remain visible. The real cwd now flows from the SessionStart hook through the worker API to the ContextBuilder for accurate git ancestry resolution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ry (Phase 04) Extends branch awareness to MCP search tools (search, timeline, get_observations). When users search memory, results are filtered to only show observations from ancestor branches, completing the branch isolation story across all memory access points. Supports both explicit commit_sha filtering and auto-detection via cwd. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…allow clones, and worktrees (Phase 05) Adds comprehensive edge case tests for branch memory git utilities: - isGitRepository: validates git repo detection for real repos, /tmp, and nonexistent paths - detectCurrentBranch: tests detached HEAD returns null branch but valid commitSha - Shallow clone: creates temp shallow clone and verifies ancestry checks don't throw - Worktree: creates temp worktree and verifies isGitRepository and detectCurrentBranch work - Additional ancestry edge cases: truncated SHAs, non-git cwd Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ance tests (Phase 05) When resolveViaGitLog fails (e.g. shallow clone), the caller now properly falls back to batched merge-base checks instead of returning an empty array that would hide all observations. Added tests verifying correct behavior across batch boundaries with >100 candidates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ckward compat, dedup, and filtering (Phase 05) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All 1157 tests pass with 0 failures across 68 files. Build succeeds and marketplace synced. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ork queue (Phase 05) End-to-end verification revealed that PendingMessageStore.enqueue() was not persisting branch and commit_sha to the pending_messages table, causing these values to be lost during the database work queue round-trip. This resulted in all observations having NULL branch/commit_sha despite the hook correctly detecting and sending the values. - Add branch/commit_sha columns to pending_messages table (migration 25) - Update PendingMessageStore.enqueue() to persist branch/commit_sha - Update PersistentPendingMessage interface with branch/commit_sha fields - Update toPendingMessage() to read branch/commit_sha back from DB - Add migration to both SessionStore.ts and migrations/runner.ts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR implements branch memory - a git-aware observation filtering system that creates visibility semantics similar to how git works. Observations are now tagged with the current branch and commit SHA when captured, and context generation filters observations to only show those from commits that are ancestors of the current HEAD. Key changes:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start([User works in git repo]) --> Detect[detectCurrentBranch<br/>reads branch + commit SHA]
Detect --> Hook[Hook captures observation]
Hook --> Queue[PendingMessageStore<br/>persists branch/commit_sha]
Queue --> Worker[Worker processes message]
Worker --> Store[storeObservation<br/>saves to DB with branch/commit_sha]
Store --> DB[(observations table<br/>with branch + commit_sha columns)]
Request([Context generation request]) --> GetShas[getUniqueCommitShasForProject<br/>fetches all candidate SHAs]
GetShas --> Resolve{resolveVisibleCommitShas}
Resolve -->|Not in git repo| ShowAll[Return null<br/>show all observations]
Resolve -->|In git repo| Ancestry[resolveAncestorCommits<br/>git merge-base checks]
Ancestry -->|Small set| Concurrent[Concurrent checks]
Ancestry -->|100-500| Batched[Batched processing]
Ancestry -->|500+| GitLog[git log optimization<br/>with fallback]
Concurrent --> Filter
Batched --> Filter
GitLog --> Filter
Filter[Filter observations:<br/>commit_sha IN visible SHAs<br/>OR commit_sha IS NULL] --> Context[Render context]
ShowAll --> Context
style DB fill:#e1f5ff
style Filter fill:#fff4e1
style Context fill:#e8f5e9
Last reviewed commit: a371e2c |
…glue code (Phase 06) Close testing gaps in PendingMessageStore lifecycle, SearchManager branch filtering, ContextBuilder branch resolution, SDKAgent metadata capture, and hook layer branch detection. 27 new tests, 76 assertions, zero regressions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 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.
Summary
branchandcommit_shaat write time viadetectCurrentBranchin the hook layerImplementation (6 phases)
branch/commit_shacolumns),detectCurrentBranch, write path throughstoreObservationresolveVisibleCommitShasgit ancestry utility withgit merge-base --is-ancestorbatchingContextBuilder.generateContext()filters observations by branch ancestrySearchManager.resolveBranchFilter()filters search/timeline results by ancestryresolveViaGitLogfallbackTest plan
resolveBranchFilterwith direct SHAs, auto-resolution, error fallback, comma parsingdetectCurrentBranchintegration (normal, detached HEAD, non-git)🤖 Generated with Claude Code