Krusch-Git (Codebase & Git AST Memory Engine)
A persistent Git DAG indexer, AST chunker, and semantic codebase retrieval engine for AI coding agents. Stores the entire Directed Acyclic Graph (DAG) natively in PostgreSQL with pgvector, extracting code symbols, call edges, and chunked semantic vector embeddings.
📖 Read the Systems Deep Dive: Check out the published architecture essay krusch-git: Git DAG Indexing, Relational AST Symbols, and Hybrid Recency Search for AI Coding Agents on krusch.dev, or the local companion guide in docs/WHAT_MAKES_IT_SPECIAL.md.
🧠 Why Krusch-Git?
In the standard AI coding agent ecosystem, searching codebases relies on rigid grep searches or expensive ad-hoc AST parsing. Krusch-Git fundamentally changes this by bridging Git directly with persistent semantic graphs:
- Semantic Code Search: Find code based on what it does, not just exact token syntax.
- AST Symbol & Edge Graph: Walks call graphs, definitions, and symbol dependencies across your repository.
- Exponential Temporal Decay: Mathematically decays older vectors. Your agent prioritizes code written recently over stale or dead code.
- Decoupled Architecture: Sits as an independent MCP server alongside krusch-context-mcp.
⚠️ Not a Replacement for Git
It is critical to understand that Krusch-Git does not replace Git or services like GitHub/GitLab. It does not handle branch merging, rebasing, or pull requests.
Instead, Krusch-Git is an agentic augmentation layer. You continue to use standard Git for your human-facing source control and team collaboration. Krusch-Git sits alongside it in your workflow, automatically ingesting your standard Git history to provide your AI agents with a mathematically optimized, semantically searchable clone of your codebase.
🔒 Reliability Audit & Pointer Resolution
To guarantee production-grade stability and complete continuity across complex monorepos, Krusch-Git underwent a thorough architectural audit and reliability overhaul:
- Deterministic Pointer Resolution: In standard
'pointer' storage mode (used to keep the database lightweight), file content is stored as NULL in PostgreSQL. I introduced a dynamic resolver inside server/git-engine.js that maps relative blob paths to the local filesystem monorepo root. This automatically streams raw file contents from disk on demand, resolving previous null value crashes on the Express /api/blobs/:id route and krusch_git_read_blob MCP tool.
- Safe Semantic Search Previews: Standard semantic search tool calls throw TypeErrors if they attempt to stringify nullable database columns. Krusch-Git now safely extracts the pre-compiled
summary column (generated using qwen2.5-coder:7b inline summaries) to serve as the context preview.
- Starvation-Proof Queue Management: The fleet priority queue (
PriorityQueue.process) inside lib/llm-queue.js is secured using a strict try ... finally block. This guarantees that concurrent slots are cleanly released (this.active--) under all task outcomes, preventing memory and slot leaks that would otherwise block multi-agent swarm operations.
- Fidelity-Preserved Embedding Backfills: Upgraded
backfill_embeddings.js to automatically resolve local disk paths when processing pointer-mode blobs. This enables the embedding backfill process to compute full-fidelity, chunked centroid embeddings from the original code rather than falling back to lossy, shortened summary snippets.
- Pointer-Slimmed Symbol Indexing & On-Demand Snippet Hydration (
v1.2.2): Instead of duplicating up to 3,000 characters of raw code inside code_symbols.content, sync_to_pg.js stores a compact [POINTER_TOKENS] identifier stream so PostgreSQL's generated tsv full-text index remains 100% lossless while cutting symbol storage overhead by >85%. When krusch_git_search_symbols returns top hits, resolveSymbolSnippet() dynamically slices start_line..end_line directly from disk via resolveBlobContent().
- Per-Symbol SHA-256 Hash (
symbol_hash) & Markdown Heading Spine (symbol_type = 'section'): Every extracted symbol and Markdown heading section (#, ##, ###) computes a normalized SHA-256 symbol_hash (lib/ast-chunker.js) and extracts relative Markdown link edges (edgeType = 'references'), enabling structural section retrieval across README.md, AGENTS.md, and docs/*.md alongside code AST symbols.
- Polyglot Java AST & Live Cursor Import Activity (
v1.2.3): lib/ast-chunker.js extracts Java class, interface, @interface, enum, record, constructor/method bodies, ;-terminated interface signatures, and static imports (parseJava), paired with analyzeImportSymbolActivity() to classify imported bindings (immediate_cursor, unused_staged, earlier_only) with 1-hop typed/constructed local and field receiver tracking.
📊 Empirical Benchmark: RepoBench-R (n = 47,998 Cross-File Queries)
Evaluated hermetically across 100% of the official tianyang/repobench-r v1.1 test suite (47,998 Python & Java cross-file retrieval queries across all 8 cff/cfr × easy/hard splits; zero LLM judge, runtime Proxy oracle traps, and SHA-256 provenance audit) with snowflake-arctic-embed2 (1,024d):
| Scope / Split |
Import Order |
Identifier BM25 |
Pure Dense (snowflake-arctic-embed2) |
krusch-git v1.2.3 (Hybrid RRF + AST + Import Activity) |
Lift vs. Pure Dense |
Official 8-Split Macro (Acc@1 / Acc@5 / MRR) |
11.84% / 57.01% / 0.3109 |
15.98% / 63.95% / 0.3598 |
15.69% / 64.14% / 0.3586 |
19.12% / 68.58% / 0.3957 |
+21.8% Acc@1 (+61.5% vs. Import Order) |
Python 4-Split Macro (n = 23,998) |
12.33% / 56.78% / 0.3133 |
18.53% / 66.03% / 0.3836 |
17.82% / 66.41% / 0.3790 |
21.67% / 70.07% / 0.4179 |
+21.6% Acc@1 |
Java 4-Split Macro (n = 24,000) |
11.35% / 57.23% / 0.3084 |
13.44% / 61.88% / 0.3359 |
13.57% / 61.88% / 0.3381 |
16.57% / 67.09% / 0.3735 |
+22.1% Acc@1 |
Cross-File Random (cfr) Easy Acc@1 (Py / Java) |
12.71% / 11.67% |
25.83% / 19.65% |
21.75% / 19.85% |
31.33% / 27.45% |
Surpasses published CodeBERT (~20.6%/~19.3%) & UniXcoder (~28.8%/~26.9%) on both Py & Java |
📊 Empirical Benchmark: ACL 2025 CoIR (10 / 10 Tasks: 2,389,123 Docs & 162,216 Queries)
Evaluated hermetically across 100% of all 10 / 10 official ACL 2025 CoIR code retrieval tasks (20 / 20 unshrunk sub-corpora: cosqa, codetrans-dl, codetrans-contest, apps, stackoverflow-qa, synthetic-text2sql, codefeedback-st, codefeedback-mt, 6-language codesearchnet, and 6-language codesearchnet-ccr; 0 LLM judges, runtime Proxy oracle traps, and SHA-256 provenance audit archived at krush420/sovereign-g4-benchmarks) with local-weights snowflake-arctic-embed2:latest (568M params, 1,024d, 8,192 ctx):
| Aggregation / Highlight Task |
Porter FTS5 BM25 (NDCG@10 / R@10) |
Pure Dense (snowflake-arctic-embed2) |
krusch-git (Hybrid RRF + AST Spine + Subtoken FTS5) |
Comparison vs. ACL 2025 CoIR Table 3 (Li et al.) |
Official 10-Task Macro Average (NDCG@10 / MRR@10 / R@10) |
48.98% / 44.06% / 64.85% |
55.65% / 50.64% / 71.71% |
56.40% / 50.94% / 73.88% |
#1 Overall (+0.75 pp NDCG@10 & +2.17 pp R@10 vs. Dense): exceeds all 10 Table 3 models incl. Voyage-Code-002 (56.26%) & E5-Mistral 7B (55.18%)* |
CodeSearchNet (6 Langs, 1,003,765 Docs / 52,561 Qs) |
41.81% / 52.77% |
57.72% / 70.07% |
59.76% / 72.80% |
+5.51 pp over E5-Mistral 7B (54.25%); Python AST Spine hits 81.45% NDCG@10 |
CodeFeedback-MT (66,383 Docs / 13,277 Multi-Turn Qs) |
54.53% / 63.27% |
52.23% / 64.86% |
60.23% / 70.81% |
+8.00 pp over Pure Dense & +18.24 pp over Table 3 best (41.99%; 51.32% GTE 4k Table 5) |
CodeFeedback-ST (156,526 Docs / 31,306 Qs) |
62.58% / 76.45% |
72.81% / 89.11% |
74.76% / 90.26% |
#1 vs. Table 3 best (E5-base 74.52%, E5-Mistral 7B 72.71%) |
Synthetic-Text2SQL (105,851 Docs / 5,851 Qs) |
40.74% / 70.91% |
44.49% / 77.75% |
48.71% / 84.19% |
+4.22 pp NDCG@10 & +6.44 pp Recall@10 over Pure Dense via identifier/SQL hybrid fusion |
*Scope Note: ACL 2025 CoIR Table 3 truncated inputs at 512 tokens, whereas snowflake-arctic-embed2:latest operates at its native 8,192-token context window.
🤝 Sibling Synergy with Krusch Context MCP
Krusch-Git and krusch-context-mcp form a complementary two-server architecture for AI coding agents:
| Server |
Responsibility |
Verbs / Tools |
| krusch-context-mcp |
Project memory, episodic decisions, steering invariants |
5 core verbs (retrieve, remember, revise, nudge, health) |
| krusch-git |
Codebase AST, symbol search, Git DAG indexing |
7 tools (krusch_git_search_symbols, krusch_git_semantic_search, ...) |
Separation of Concerns: Memory and codebase indexing are decoupled. Your agent uses krusch-context-mcp to know why architectural decisions were made and what rules to follow, and queries krusch-git to find where code lives, how symbols connect, and what the Git history looks like.
⚡ Quick Start
Agent-Assisted Setup
Ask your coding agent (Claude Code, Codex, Cursor, Windsurf, or Antigravity):
Read https://raw.githubusercontent.com/kruschdev/krusch-git/main/INSTALL.md and set up krusch-git on this machine.
You must