Skip to content

Shared per-repo code index, injected into every dispatched prompt - #398

Merged
currentbits merged 11 commits into
mainfrom
coder/shared-code-intelligence-index-per-repo--73cf1e
Aug 17, 2026
Merged

currentbits merged 11 commits into
mainfrom
coder/shared-code-intelligence-index-per-repo--73cf1e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #377.

One symbol index per repo, keyed on the project's main checkout and read by every thread — including threads running in worktrees, which do not get their own. Today each thread re-derives the same orientation by grep; this replaces that with a ranked map injected straight into the prompt.

The research behind the issue (Sourcegraph CodeScaleBench, 1,281 runs) is what shapes the design: agents overwhelmingly reach for the simplest tool — 7,993 keyword searches vs 57 deep-search calls across 602 MCP runs. A powerful index nobody invokes is worthless, so the value is entirely in the injection, and there is deliberately no new tool here.

What changed

  • electron/codeindex.js — git ls-files scan, line-based top-level symbol extraction (JS/TS, Python, Go, Rust, JS-ish fallback), git-churn rank over the last 300 commits, atomic JSON write, and an incremental refresh that reuses a row whose mtimeMs and size both still match. readIndex is sync, defensive, and never scans; maybeRefreshIndex is debounced per repo, fire-and-forget, and off under CODER_CODEINDEX_DISABLE=1.
  • electron/services.js — codeIndexNoteFor(index), a pure formatter alongside the existing standing notes (planboardNoteFor / selfIdNoteFor / specNoteFor), following the same "return empty string when there is nothing to say" rule. Emits the ranked file→symbols map plus explicit steering: use the map to jump to the file that owns a symbol, grep for literal strings and call sites, read the file before editing.
  • electron/runner.js — wired into the single dispatch finalization point, reading the index for projectForGate.path (never the thread's worktree, which would defeat the whole issue) and kicking a background refresh. Both calls are guarded so a corrupt index can never break a dispatch.

Measured on this repo

398 indexed source files, 1,680 symbols, 134K LOC: full build 170ms, incremental refresh 40ms, readIndex on the dispatch path 1ms, index file 69KB, injected note 3.4KB. Electron suite: 1076 pass / 1 fail, the failure being the pre-existing web-integration reconnect flake that is baseline on main.

Two defects fixed during review

  • Churn rank was systematically wrong. git log --format=%h --name-only emits a hash and a blank line before each file list, and the parser's off-by-one read the first file of every commit as a hash — so alphabetically-first paths never scored. An empty --format= makes every non-blank line a path. Regression test added.
  • Symbol-less files ate the note's char budget, listing test fixtures and config files as bare paths that tell an agent nothing.

Deliberate simplifications (documented as ponytail: comments)

  • JSON, not SQLite — the index is read whole to build one note, so there is no query to optimise. Move to node:sqlite when find-references / blast radius needs per-symbol queries.
  • Line-based extractor, not tree-sitter — this app ships zero native dependencies, and tree-sitter bindings would be a packaging and signing cost for what is only top-level definition names.
  • Debounced refresh from the dispatch path, not a file watcher — staleness ceiling is one refresh interval.
  • Repo-size gating is the note's ~3.5KB cap plus a 20-file floor, not an LOC threshold: a 400K-LOC repo yields the same size note as a small one.

Built by two parallel grok workers against a contract commit landed on main first (051535d), with the review fixes applied on merge.

  • PR created by the Claude Code agent

Willem and others added 11 commits August 17, 2026 21:18
… Turn any finished thread into an automation (one-click recur
Signatures + on-disk shape only, so the indexer and the prompt-injection
side can be built in parallel against one agreed contract.

Co-Authored-By: Claude Opus 5 <[email protected]>
Agents reach for grep first, so the map is worthless unless the harness
injects it. Add codeIndexNoteFor (gated on repo size and the disable
flag, capped at 3500 chars) and wire it at the single dispatch
finalization point against the project's main checkout, never the
worktree. tryReadCodeIndex swallows a missing or stub index so dispatch
never breaks before the indexer lands.
…into coder/shared-code-intelligence-index-per-repo--73cf1e
Fill in electron/codeindex.js: git ls-files scan, line-based top-level
symbol extract, git-log rank, incremental JSON persist, and a debounced
fire-and-forget refresh. One index per main checkout, never per worktree.
…into coder/shared-code-intelligence-index-per-repo--73cf1e
…e note

git log --format=%h --name-only needs the header and its blank line counted
out, and the state machine was off by one line: the first file of every
commit was read as a hash and never counted. An empty --format makes every
non-blank line a path, so there is nothing to count out.

Files with no extracted symbols (test fixtures, config) told the agent
nothing and were spending the note's char budget.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 9f16a21 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/shared-code-intelligence-index-per-repo--73cf1e branch October 3, 2026 16:07
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.

Shared code-intelligence index per repo, injected into every thread

1 participant