CodeSearch — Multi-Repo Code Intelligence
Role
Own multi-repo code discovery as evidence-driven hybrid search, not grep across local files.
Working Mode
Map → Separate evidence from hypothesis → Smallest intervention → Validate with actual query results.
Architecture
Stolen from TabbyML/tabby (33K stars): tree-sitter chunking + pgvector hybrid search.
Adapted to: Python + Supabase pgvector + Gemini Flash (free tier, $0 cost).
Focus Areas
- Hybrid search — 70% vector similarity (Gemini Flash 768d) + 30% trigram text match (pg_trgm)
- Tree-sitter chunking — function/class boundaries, not arbitrary line counts; max 512 tokens/chunk
- Git-aware incremental indexing — track last_indexed_commit, skip unchanged files
- Multi-repo unified index — code_repos + code_chunks tables in Supabase pgvector
- Language support — Python, TypeScript, JavaScript, Shell, SQL, HTML (tree-sitter); fallback: 256-line blocks
- Skip rules — files >100KB, binary files, node_modules/, .git/, dist/, build/, pycache/
- Free tier only — Gemini Flash text-embedding-004, 1500 RPM, 768 dimensions, $0 cost
- CLI interface — search, index, stats subcommands via cli_anything.codesearch
Quality Gates
- verify: CLI
codesearch stats returns row counts from DB (not estimated)
- confirm:
code_repos table shows last_indexed_commit matches HEAD for indexed repos
- check: Search results include repo_name, filepath, start_line, symbol_name, score
- ensure: Embedding dimension is exactly 768 (Gemini Flash text-embedding-004)
- call_out: Report if any repo has chunk_count=0 after indexing (silent failure)
Output Format
{
"query": "Smart Router LLM routing",
"results": [
{
"repo_name": "cli-anything-biddeed",
"filepath": "shared/cli_anything/shared/llm.py",
"language": "python",
"chunk_body": "def route_llm(prompt, model_hint=None):\n ...",
"start_line": 42,
"symbol_name": "route_llm",
"score": 0.89
}
],
"total": 10,
"search_ms": 145
}
CLI Usage
# Search across all repos
python -m skills.codesearch.codesearch search "Smart Router LLM routing"
# Search specific repo
python -m skills.codesearch.codesearch search "max bid formula" --repo cli-anything-biddeed
# Search by language
python -m skills.codesearch.codesearch search "Supabase RLS policy" --language sql
# Index incrementally (all Tier 1 repos)
python -m skills.codesearch.codesearch index
# Force full reindex of one repo
python -m skills.codesearch.codesearch index --repo cli-anything-biddeed --full
# Stats
python -m skills.codesearch.codesearch stats
Constraints
- NEVER report chunk counts or index stats without querying
SELECT COUNT(*) FROM code_chunks first
- NEVER declare a repo "indexed" without verifying
last_indexed_commit in DB matches git HEAD
- All embeddings MUST use Gemini Flash text-embedding-004 (768 dimensions) — no other model
- Indexing server: /opt/biddeed/codesearch-repos/ on Hetzner (87.99.129.125)
- Cost: $0 — Gemini Flash free tier only. Reject any approach requiring paid embeddings
Guard Rail
Do not declare indexing complete without verifying chunk_count > 0 in code_repos and SELECT COUNT(*) FROM code_chunks > 1000 for Tier 1 repos combined.
1---2name: codesearch3description: CodeSearch — Multi-Repo Code Intelligence4---56# CodeSearch — Multi-Repo Code Intelligence78## Role9Own multi-repo code discovery as evidence-driven hybrid search, not grep across local files.1011## Working Mode12Map → Separate evidence from hypothesis → Smallest intervention → Validate with actual query results.1314## Architecture15Stolen from TabbyML/tabby (33K stars): tree-sitter chunking + pgvector hybrid search.16Adapted to: Python + Supabase pgvector + Gemini Flash (free tier, $0 cost).1718## Focus Areas191. Hybrid search — 70% vector similarity (Gemini Flash 768d) + 30% trigram text match (pg_trgm)202. Tree-sitter chunking — function/class boundaries, not arbitrary line counts; max 512 tokens/chunk213. Git-aware incremental indexing — track last_indexed_commit, skip unchanged files224. Multi-repo unified index — code_repos + code_chunks tables in Supabase pgvector235. Language support — Python, TypeScript, JavaScript, Shell, SQL, HTML (tree-sitter); fallback: 256-line blocks246. Skip rules — files >100KB, binary files, node_modules/, .git/, dist/, build/, __pycache__/257. Free tier only — Gemini Flash text-embedding-004, 1500 RPM, 768 dimensions, $0 cost268. CLI interface — search, index, stats subcommands via cli_anything.codesearch2728## Quality Gates29- verify: CLI `codesearch stats` returns row counts from DB (not estimated)30- confirm: `code_repos` table shows last_indexed_commit matches HEAD for indexed repos31- check: Search results include repo_name, filepath, start_line, symbol_name, score32- ensure: Embedding dimension is exactly 768 (Gemini Flash text-embedding-004)33- call_out: Report if any repo has chunk_count=0 after indexing (silent failure)3435## Output Format36```json37{38 "query": "Smart Router LLM routing",39 "results": [40 {41 "repo_name": "cli-anything-biddeed",42 "filepath": "shared/cli_anything/shared/llm.py",43 "language": "python",44 "chunk_body": "def route_llm(prompt, model_hint=None):\n ...",45 "start_line": 42,46 "symbol_name": "route_llm",47 "score": 0.8948 }49 ],50 "total": 10,51 "search_ms": 14552}53```5455## CLI Usage56```bash57# Search across all repos58python -m skills.codesearch.codesearch search "Smart Router LLM routing"5960# Search specific repo61python -m skills.codesearch.codesearch search "max bid formula" --repo cli-anything-biddeed6263# Search by language64python -m skills.codesearch.codesearch search "Supabase RLS policy" --language sql6566# Index incrementally (all Tier 1 repos)67python -m skills.codesearch.codesearch index6869# Force full reindex of one repo70python -m skills.codesearch.codesearch index --repo cli-anything-biddeed --full7172# Stats73python -m skills.codesearch.codesearch stats74```7576## Constraints77- NEVER report chunk counts or index stats without querying `SELECT COUNT(*) FROM code_chunks` first78- NEVER declare a repo "indexed" without verifying `last_indexed_commit` in DB matches git HEAD79- All embeddings MUST use Gemini Flash text-embedding-004 (768 dimensions) — no other model80- Indexing server: /opt/biddeed/codesearch-repos/ on Hetzner (87.99.129.125)81- Cost: $0 — Gemini Flash free tier only. Reject any approach requiring paid embeddings8283## Guard Rail84Do not declare indexing complete without verifying chunk_count > 0 in code_repos and SELECT COUNT(*) FROM code_chunks > 1000 for Tier 1 repos combined.