Skip to content

feat: link exchanges to git branches with --branch filter#11

Merged
senna-lang merged 3 commits into
mainfrom
feature/branch-linking
Jun 11, 2026
Merged

feat: link exchanges to git branches with --branch filter#11
senna-lang merged 3 commits into
mainfrom
feature/branch-linking

Conversation

@senna-lang

@senna-lang senna-lang commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

Links conversation history (exchanges) to git branches so that questions like "do you remember the work on this branch?" can be answered via loci. Implements openspec change add-branch-linking (G1–G5).

Claude Code session logs (.jsonl) already record a gitBranch field on every entry, so this requires no extra hooks and no git command execution. Since a single session can span multiple branches (observed in real data), linking is done at exchange granularity.

Changes

ID Description
G1 The indexer captures gitBranch from the exchange-boundary user entry into the new exchanges.git_branch column (missing / empty string → NULL)
G2 Migration v8: adds the column and backfills existing exchanges by re-parsing session jsonl files (ply coordinates count successfully-parsed lines only, missing jsonl stays NULL, idempotent)
G3 loci context --branch NAME: partial-match reverse lookup in chronological order. Uses LEFT JOIN on palace_objects so undistilled exchanges are included. AND-combinable with --symbol; exits 1 when neither is given
G4 loci search "query" --branch NAME: filters BM25 / HNSW candidates before RRF fusion
G5 Adds a git_branch field to search / context JSON output; updates prime instructions, CLAUDE.md, and AGENTS.md (new)

Compatibility

  • JSON output changes are additive only (existing fields unchanged)
  • loci context --symbol standalone behavior is unchanged (--symbol goes from required to either-one-required)
  • Backfill is pure JSON parsing — no LLM calls, no embedding computation (zero API cost)

Testing

  • 19 new tests (G1 capture / branch switching / missing field, G2 backfill / ply coordinates / idempotency, G3 reverse lookup / combination / validation, G4 filtering / partial match / binding order, G5 JSON / prime)
  • Full pytest suite passes (246 tests), ruff / pyright clean
  • Verified against real data: applied v8 to this repo's memory.db and confirmed loci context --branch "1.0-hardening" and loci search --branch return actual past conversations

Out of scope

  • PR linking (skipped to avoid a gh CLI dependency; can be added later as a thin PR → headRefName → --branch translation layer)
  • --since / --until time filters; distinguishing reused branch names

🤖 Generated with Claude Code

senna-lang and others added 2 commits June 11, 2026 21:17
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implements openspec change add-branch-linking:
- G1: indexer captures gitBranch from the exchange-boundary user
  entry into the new exchanges.git_branch column (NULL when absent)
- G2: migration v8 adds the column and backfills existing exchanges
  by re-parsing session jsonl files (success-parsed-lines ply
  coordinates, silent skip on missing jsonl, idempotent)
- G3: loci context --branch reverse lookup (LEFT JOIN palace_objects
  so undistilled exchanges are included, chronological order,
  AND-combinable with --symbol, exit 1 when neither given)
- G4: loci search --branch filters BM25/HNSW candidates before RRF
- G5: git_branch field in search/context JSON output, prime
  instructions and CLAUDE.md/AGENTS.md document the new options

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@senna-lang senna-lang changed the base branch from release/1.0-hardening to main June 11, 2026 12:37
Adopt main's rewritten agent-action-trigger PRIME_TEXT structure and
re-apply the --branch additions in its style: a 'work on a specific
branch' trigger bullet and a loci context --branch example in the
Context section. CLAUDE.md keeps both --branch command lines with
main's shortened --symbol comment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@claude

claude Bot commented Jun 11, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@senna-lang senna-lang merged commit 9f432fb into main Jun 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant