cartog
npx skills add https://github.com/jrollin/cartog --skill cartog
Agent 安装分布
Skill 文档
cartog â Code Graph Navigation Skill
When to Use
Use cartog before reaching for grep, cat, or file reads when you need to:
- Discover symbols by partial name â
cartog search <query> - Find code by concept or behavior â
cartog rag search "description" - Understand the structure of a file â
cartog outline <file> - Find who references a symbol â
cartog refs <name>(or--kind callsfor just callers) - See what a function calls â
cartog callees <name> - Assess refactoring impact â
cartog impact <name> --depth 3 - Understand class hierarchies â
cartog hierarchy <class> - See file dependencies â
cartog deps <file>
Why cartog Over grep/glob
cartog pre-computes a code graph (symbols + edges) with tree-sitter and stores it in SQLite. Compared to grep/glob:
- Fewer tool calls: 1 command vs 3-6 grep/read cycles
- Transitive analysis:
impact --depth 3traces callers-of-callers â grep can’t do this - Structured results: symbols with types, signatures, and line ranges â not raw text matches
Workflow Rules
-
Before you grep or read a file to understand structure, query cartog first.
-
Search routing â pick the right strategy based on the query:
A. Direct keyword search (
cartog search <name>) â when the query is clearly a symbol identifier: single token, camelCase/snake_case, partial name. Sub-millisecond, prefix + substring matching.cartog search validate_token cartog search AuthService cartog search parse --kind functionB. Semantic search (
cartog rag search "<query>") â when the query is natural language describing behavior or a concept, and you don’t know the symbol name.cartog rag search "authentication token validation" cartog rag search "database connection pooling" cartog rag search "error handling in HTTP requests"C. Both in parallel â when the query is a broad keyword that could be a symbol name AND a concept (e.g.,
auth,config,cache). Run both in parallel to combine exact name matches with semantically related code.# run in parallel cartog search auth cartog rag search "authentication and authorization"Narrowing pattern: when
cartog searchreturns too many results, userag searchwith a more descriptive query to narrow down. Example:search parsereturns 30 hits ârag search "parse JSON response body"pinpoints the right ones.Routing rules:
- Single identifier-like token â A (direct)
- Multi-word natural language â B (semantic)
- Broad keyword / unsure â C (parallel)
- Too many results from A â narrow with B
-
When using
cartog searchto locate a symbol beforerefs/callees/impact:- Exactly one result â use that symbol name and file, proceed.
- Multiple results, same name, different files â add
--file <path>to disambiguate. - Multiple results, different names â add
--kind <kind>to filter, then re-evaluate. - Never pass an ambiguous name to
refs/callees/impactâ the result will be wrong.
-
Use
cartog outline <file>instead ofcat <file>when you need structure, not content. -
Before refactoring, run
cartog impact <symbol>to see the blast radius. -
Only fall back to grep/read when cartog doesn’t have what you need (e.g., reading actual implementation logic, string literals, config values).
-
After making code changes, run
cartog index .to update the graph.
Setup
Before first use, ensure cartog is installed and indexed:
# Install if missing
command -v cartog || bash scripts/install.sh
# Index (incremental â safe to re-run)
cartog index .
# Enable semantic search (required for rag search routing)
cartog rag setup # download embedding + re-ranker models (one-time)
cartog rag index . # embed all symbols for vector search
Without rag setup, the rag search strategy is unavailable and the agent should use search + grep as fallback.
Commands Reference
Index (build/rebuild)
cartog index . # Index current directory
cartog index src/ # Index specific directory
cartog index . --force # Re-index all files (ignore cache)
Search (find symbols by partial name)
cartog search parse # prefix + substring match
cartog search parse --kind function # filter by symbol kind
cartog search config --file src/db.rs # filter to one file
cartog search parse --limit 10 # cap results
Returns symbols ranked: exact match â prefix â substring. Case-insensitive. Max 100 results.
Valid --kind values: function, class, method, variable, import.
RAG Semantic Search (natural language queries)
cartog rag search "authentication token validation"
cartog rag search "error handling" --kind function
cartog rag search "database schema setup" --limit 20
Uses hybrid retrieval: FTS5 keyword matching + vector KNN, merged via Reciprocal Rank Fusion. When the cross-encoder model is available, results are re-ranked for better precision.
Outline (file structure)
cartog outline src/auth/tokens.py
Output shows symbols with types, signatures, and line ranges â no need to read the file.
Refs (who references this?)
cartog refs validate_token # all reference types
cartog refs validate_token --kind calls # only call sites
Available --kind values: calls, imports, inherits, references, raises.
Callees (what does this call?)
cartog callees authenticate
Impact (transitive blast radius)
cartog impact SessionManager --depth 3
Shows everything that transitively depends on a symbol up to N hops.
Hierarchy (inheritance tree)
cartog hierarchy BaseService
Deps (file imports)
cartog deps src/routes/auth.py
Stats (index summary)
cartog stats
Watch (auto re-index on file changes)
cartog watch . # watch current directory
cartog watch . --rag # also re-embed symbols (deferred)
cartog watch . --debounce 3 --rag-delay 30 # custom timings
Serve (MCP server)
cartog serve # MCP server over stdio
cartog serve --watch # with background file watcher
cartog serve --watch --rag # watcher + deferred RAG embedding
JSON Output
All commands support --json for structured output:
cartog --json refs validate_token
cartog --json outline src/auth/tokens.py
cartog --json rag search "authentication"
Refactoring Workflow
Before changing any symbol (rename, extract, move, delete):
- Identify â
cartog search <name>to confirm the exact symbol name and file - Map references â
cartog refs <name>to find every usage - Assess blast radius â
cartog impact <name> --depth 3for transitive dependents - Check hierarchy â
cartog hierarchy <name>if it’s a class (subclasses need updating too) - Plan change order â update leaf dependents first, work inward toward the source
- Apply changes â modify files
- Re-index â
cartog index .to update the graph - Verify â re-run
cartog refs <name>to confirm no stale references remain
Decision Heuristics
| I need to… | Use |
|---|---|
| Find a symbol by exact/partial name | cartog search <name> |
| Find code by concept or behavior | cartog rag search "description" |
| Broad keyword, unsure which to use | Both search + rag search in parallel |
Too many results from search |
Narrow with rag search "more specific description" |
| Know what’s in a file | cartog outline <file> |
| Find usages of a function | cartog refs <name> (--kind calls for just callers) |
| See what a function calls | cartog callees <name> |
| Check if a change is safe | cartog impact <name> --depth 3 |
| Understand class hierarchy | cartog hierarchy <class> |
| See file dependencies | cartog deps <file> |
| Read actual implementation logic | cat <file> (cartog indexes structure, not content) |
| Search for string literals / config | grep (cartog doesn’t index these) |
| Nothing from search or rag | Fall back to grep |
Limitations
- Structural/heuristic resolution, not full semantic. ~90% accuracy for cross-file references.
- Currently supports: Python, TypeScript/JavaScript, Rust, Go, Ruby. Java planned.
- Does not index string literals, comments (except docstrings), or config values.
- Method resolution is name-based â
foo.bar()resolvesbar, notFoo.barspecifically.
RAG search limitations
- No substring matching:
"valid"does NOT matchvalidate_token. FTS5 is token-based. Usecartog searchfor substring matches (this is why parallel routing is valuable). - Requires setup: if
cartog rag setupwas not run,rag searchis unavailable. - Scores are relative:
rrf_scoreandrerank_scorevalues are only meaningful for ranking within a single query â don’t compare scores across different queries. - Re-ranking latency: cross-encoder scores all candidates in a single batch ONNX call (up to 50 candidates). Expect ~150-500ms total overhead depending on candidate count.