2.7 KiB
2.7 KiB
Codexis
Tree-sitter powered code indexer. Produces a SQLite database of symbols, files, and line numbers at .codexis/index.db.
Usage
codexis [flags] [root] # default root is current directory
codexis . # index cwd → .codexis/index.db
codexis -force . # full re-index (ignore file hashes)
codexis -o /tmp/out.db . # custom output path
Architecture
main.go— CLI entry, schema creation, orchestrationindexer/walker.go— Usesgit ls-filesto find files,grammars.DetectLanguage()to filterindexer/indexer.go— For each file: hash check → tree-sitter tag → store symbolsindexer/scope.go— Package extraction (language-specific AST queries with filepath fallback), export detectiondb/— sqlc-generated code fromschema.sqlandqueries.sqlextension/— Pi coding agent extension providingcodexistool for LLM SQL queries
Key Dependencies
github.com/odvcencio/gotreesitter— Pure-Go tree-sitter runtime (no CGo). 206 grammars.grammars.DetectLanguage(filename)→ language detectiongrammars.ResolveTagsQuery(entry)→ symbol extraction queries (inferred if not explicit)gotreesitter.NewTagger(lang, query).Tag(src)→ returns[]Tagwith kind, name, range
github.com/mattn/go-sqlite3— SQLite driver- sqlc — Generates Go from
db/schema.sql+db/queries.sql
Schema
Two tables: files and symbols. See db/schema.sql.
Symbol kinds (enforced via CHECK constraint): function, method, class, type, interface, constant, variable, constructor.
Parent-child relationships (e.g., method → class) are determined by range containment in the AST.
Pi Extension
extension/codexis.ts registers a single codexis tool. Install:
# Symlink into pi extensions directory
ln -s $(pwd)/codexis/extension ~/.pi/agent/extensions/codexis
The tool finds <git-root>/.codexis/index.db automatically and runs read-only SQL queries. Schema is embedded in the tool description so the LLM knows the tables and valid enum values.
Modifying
- Schema changes: edit
db/schema.sql+db/queries.sql, runsqlc generateindb/ - New language package queries: add to
packageQueriesmap inindexer/scope.go - Export detection heuristics:
IsExported()inindexer/scope.go
Principles
- KISS — Use the tagger as-is. Don't write custom per-language extractors unless the tagger is insufficient.
- YAGNI — No query CLI, no web UI, no call graph. Just produce the
.dbfile. - Incremental — Files are skipped if their sha256 hash hasn't changed. Use
-forceto bypass.