feat(init): seed a git worktree's index from a sibling worktree
Merged
BO
1mo ago+336+336+012345678901234567890123456789-7-7-0123456789
codegraph init in a git worktree now starts from a sibling worktree's index instead of indexing from nothing.
Worktrees share their commits, and the index stores only repo-relative paths plus the commit it was built at. So a copy of a sibling's index, brought current by a normal sync, is this worktree's index: the sync asks git what changed since the copied commit and re-parses only those files.
How it works:
- A sibling qualifies when its index is complete, was built by the running extraction version, and has a schema this build can open.
- Among those, init takes the one whose indexed commit is fewest changed files from this worktree's HEAD. Ties go to the main checkout.
- The copy is a
VACUUM INTOsnapshot taken from a read-only connection, so it stays consistent even while the sibling's daemon writes. - If the copy or the sync fails, the copy is removed and init falls back to a full index.
--no-seedskips seeding, andCodeGraph.initFromSiblingis the library entry point.- The unindexed-worktree notice agents see now says that init starts from the sibling's index.
Measured:
| Worktree | Seeded init | Full index | Graph |
|---|---|---|---|
| svelte (8,217 files), same commit | 0.8–0.9 s, 184 MB | 5.8–6.1 s, 1.6 GB | |
| svelte, 10 files edited + 1 added | 1.9 s, 388 MB | 5.8 s, 1.6 GB | 36,995 nodes / 70,748 edges, identical |
| codegraph (1,148 files), 115 files diverged | 9.8–10.3 s, 1.5 GB | 10.1–10.4 s, 3.7 GB |
Seeding surfaced two sync defects, which landed first: the kernel connection truncating node:sqlite's -shm (#145) and a doubled synthesis pass (#146).
Checks:
- New
worktree-seed.test.ts: a worktree with committed edits, an added file, a deleted file and an uncommitted edit, seeded and synced, produces the same nodes and edges as a from-scratch index of the same files. - The same test file covers the CLI (seeds by default;
--no-seeddoesn't), refusal of a sibling index built by another extraction version (nothing left behind), and a directory outside git. - Full suite: 313 files, 5226 passed, 12 skipped.
Not validated on Windows: the git and path handling reuses sync/worktree.ts, but I haven't run it there.
Ledger: docs/design/metrics-ledger.md §5.58.