pi-cbm
v1.1.0
Published
Extension that exposes `codebase-memory-mcp` as native Pi tools, adds auto-indexing and deliberate obtimizations for agent-workflows and token saving.
Maintainers
Readme
pi-cbm
Pi extension that exposes codebase-memory-mcp as native Pi tools. `codebase-memory-mcp provides a fast local code graph. pi-cbm adds auto-indexing and adapts it for Pi agents in a way that is deliberately optimized for agent workflows and token saving.
This package does not implement an MCP client. It uses codebase-memory-mcp cli --json <tool> <args> and registers the core tools directly with Pi. When a Pi session starts, it automatically indexes the current git root, or a safe non-git working directory when enabled, in full mode in the background, then periodically refreshes it so graph tools stay current.
What makes this different
- Token-saving output by default. Several upstream tools return rich graph metadata, fingerprints, scores, and raw analysis fields.
pi-cbmstrips less-useful metadata by default and returns compact, location-first results. Useinclude_metadata: truewhen you need the full upstream payload. - Source compaction controls. Tools that may return code support
full_outputandmax_symbol_lines. Normal-sized symbols are returned directly; oversized code blocks are compacted and the full uncompacted JSON is saved to a temp file. - Symbol-first helpers. Upstream
get_code_snippetworks best when you already know the exactqualified_name.pi-cbmaddsresolve_symbolandread_symbolso the agent can start from a normal symbol name, disambiguate with file/class/route filters, and only read source when the match is unambiguous. - Safe-by-default symbol reading.
read_symbolfails closed on ambiguity: it returns candidate identities instead of guessing and reading the wrong source. When exactly one symbol matches, it calls upstreamget_code_snippetand can optionally include compact direct callers/callees. - Batch source-reading workflows.
get_code_snippets,read_symbols, andsearch_and_read_symbolslet agents inspect several relevant symbols in one tool call instead of looping through many single-symbol calls. These batch tools keep the same compact metadata defaults while preserving essential locations, per-item ambiguity/error results, and source compaction controls. - Current project stays indexed. On Pi session start, the extension indexes the current git root, or a safe non-git working directory when enabled, in full mode and refreshes it periodically in the background. Root, home, system, and common builtin OS directories are never auto-indexed.
- Project inference for cwd workflows. Most tools accept optional
project, but for normal current-repo work the extension infers the indexed project from Pi's current working directory. - Query tools only. The agent gets code-exploration tools, not administrative controls.
index_repositoryandlist_projectsare used internally for background indexing and project inference; destructive/admin MCP tools such as project deletion are not registered as Pi tools.
Security
Pi extensions run with your local user permissions. This extension also shells out to the codebase-memory-mcp binary installed on your machine, so install both this package and codebase-memory-mcp only from sources you trust.
Requirements: install codebase-memory-mcp
Install codebase-memory-mcp first. These are the upstream recommended install paths.
macOS / Linux
curl -fsSL https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh | bashWith the optional graph visualization UI:
curl -fsSL https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh | bash -s -- --uiWindows PowerShell
# 1. Download the installer
Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.ps1 -OutFile install.ps1
# 2. Optional but recommended: inspect the script
notepad install.ps1
# 3. Run it
.\install.ps1Useful installer options from upstream:
--ui— install the graph visualization variant.--skip-config— install the binary only, without configuring other agents.--dir=<path>— install to a custom location.
Arch Linux AUR
yay -S codebase-memory-mcp-binor:
paru -S codebase-memory-mcp-binManual release archive
Download the archive for your platform from the latest codebase-memory-mcp release:
codebase-memory-mcp-<platform>-<arch>.tar.gzfor macOS/Linux.codebase-memory-mcp-windows-amd64.zipfor Windows.codebase-memory-mcp-ui-...variants include the graph visualization UI.
Then extract and run the included installer:
tar xzf codebase-memory-mcp-*.tar.gz
./install.shWindows PowerShell:
Expand-Archive codebase-memory-mcp-windows-amd64.zip -DestinationPath .
.\install.ps1If the binary is not on PATH, set:
export CODEBASE_MEMORY_MCP_BIN="$HOME/.local/bin/codebase-memory-mcp"Install
pi install npm:pi-cbmOr test for one run:
pi -e npm:pi-cbmTools
Registers:
get_graph_schemaget_architecturesearch_graphresolve_symbolread_symbolread_symbolssearch_codeget_code_snippetget_code_snippetssearch_and_read_symbolstrace_pathquery_graphdetect_changes
Most tools accept optional project. When omitted, the extension infers it from indexed project roots matching Pi's current working directory. Agents should omit project for cwd/current-project work and provide it only when intentionally querying an external indexed project.
Commands
/cbm
Open the pi-cbm settings menu:
/cbm menu— show the interactive settings menu./cbm status— show auto-index settings./cbm enable-non-git— auto-index safe non-git working directories./cbm disable-non-git— only auto-index git repositories.
Non-git auto-indexing is enabled by default to preserve normal cwd workflows. The unsafe-path guard is always enabled: filesystem roots, home directories, system directories, and common macOS/Linux builtin directories are skipped with a status message explaining why.
Notes:
- Use
search_graphfirst for symbol/workflow/route/class/function discovery and “where is X implemented?” questions. Use a small limit for targeted lookup. - Use
search_and_read_symbolswhen you need to both discover implementation locations and inspect source for the top matches. Prefer it oversearch_graphfollowed by many individual snippet reads. Keepread_limitsmall, usually 3–8. - Use
resolve_symbolwhen you know a symbol name but need the exactqualified_nameor need to disambiguate candidates. - Use
read_symbolwhen you know a symbol name plus enough disambiguators, such asfile_path,parent_class,label,route_path, orroute_method, and want source only if the match is unambiguous. - Use
read_symbolswhen you know multiple concrete symbol names and need their source in one call. Each item fails closed on ambiguity likeread_symbol; retry only ambiguous items with stronger disambiguators. read_symbolfails closed on ambiguity; if it returns candidates, retry with more disambiguators or useget_code_snippetwith an exactqualified_name.read_symbolsupportsneighbors: "callers" | "callees" | "both"plusneighbor_limitfor direct, compact, source-free surrounding call context. Usetrace_pathfor multi-hop workflow or impact tracing.- Use
get_code_snippetwhen you already have an exactqualified_name; preferread_symbolwhen you have a concrete symbol name plus disambiguators but not the exactqualified_name. - Use
get_code_snippetswhen you already have multiple exactqualified_namevalues from search, trace, or query results. Prefer it over repeatedget_code_snippetcalls. - If the query is a symbol name, prefer
resolve_symbol/read_symbol; if it is an exact non-symbol string or you need all textual occurrences, usesearch_code. - Use
search_codefor exact literal text/regex searches such as env vars, config keys, route strings, error messages, constants, template text, comments, and docstrings. - Use
trace_pathafter identifying an anchor symbol when you need callers, callees, workflow, dependency, data-flow, or blast-radius context. Keep depth shallow by default. - Use
get_code_snippetonly aftersearch_graph/search_codeidentifies the exact symbol. Keep snippet retrieval targeted instead of bulk-reading many symbols. - Use
get_architecturefor broad orientation in unfamiliar repos, not targeted implementation lookup. Requested aspects may be absent if the index has no data for them. - Use
get_graph_schemabefore non-trivialquery_graphqueries, and keepquery_graphreturned columns narrow. - Use
detect_changesfor diff review or blast-radius analysis, not ordinary code lookup. - Read obvious README/package/deployment/config manifest paths directly instead of forcing graph tools into file-inspection work.
trace_pathauto-resolves short function/method names when there is a single unambiguous match; otherwise it returns candidatequalified_names. It also supports explicit plugin-sideexclude_pathsfilters.- Exploration tools such as
search_graph,get_code_snippet,trace_path,get_architecture,search_code, anddetect_changesdefault to compact, location-first output. Less-useful upstream graph metadata such as fingerprints, token fields, and raw metrics is hidden unlessinclude_metadata: trueis set. - Batch/source tools such as
get_code_snippets,read_symbols, andsearch_and_read_symbolsuse the same compact metadata defaults: they preserve essential identity such asfile_path,start_line,end_line,qualified_name, signatures, and route fields while stripping less-useful raw graph metadata unlessinclude_metadata: trueis set. - Compact output hides analysis metadata, not edit-critical location identity. Symbol-like outputs preserve
file_path,start_line, andend_linewhen available, and the plugin enriches missing locations for resolver, trace, and architecture outputs where possible. - Code/source-heavy tools support
full_outputandmax_symbol_lines. By default, normal-sized symbols are returned in full and only oversized function/method/class-sized blocks are compacted. search_codedefaults to compact output with small context to avoid flooding the agent context, and oversized per-symbol contexts are compacted unlessfull_output=trueormax_symbol_linesis increased. If a result is compacted/truncated, agents should retry the same codebase-memory tool with a highermax_symbol_linesorfull_output=truebefore falling back to file reads/grep.query_graphnormalizes common numeric metric columns in the returned rows for easier agent consumption, while still relying on upstream for query execution/order.
Typical workflow
Ask Pi:
Give me the architecture overview.The extension indexes and periodically refreshes the current repo in the background, so the agent should usually go straight to get_architecture, search_graph, get_code_snippet, trace_path, search_code, or query_graph for structural code exploration. Administrative index operations remain available through the codebase-memory-mcp CLI when needed.
