pi-cocoindex
Pi extension that exposes CocoIndex Code as a simple semantic search tool.
Package details
Install pi-cocoindex from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-cocoindex- Package
pi-cocoindex- Version
1.0.2- Published
- Apr 26, 2026
- Downloads
- 395/mo · 395/wk
- Author
- elpapi42
- License
- MIT
- Types
- extension
- Size
- 60.4 KB
- Dependencies
- 0 dependencies · 4 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-cocoindex
Pi extension that exposes CocoIndex Code semantic code search as one simple agent tool named search.
The product shape is intentionally small: agents get one semantic search tool, while CocoIndex lifecycle/debug controls stay as human slash commands.
Install
CocoIndex Code must be installed separately because this package is only the Pi extension wrapper:
pipx install 'cocoindex-code[full]'
Install the Pi extension from npm:
pi install npm:pi-cocoindex
Or install directly from GitHub:
pi install git:github.com/elpapi42/pi-cocoindex
For local development from this repository:
pi -e .
Quickstart
Install CocoIndex Code:
pipx install 'cocoindex-code[full]'Install or load this Pi extension:
pi install npm:pi-cocoindex # or, while developing locally: pi -e .Initialize CocoIndex for the project from inside Pi:
/cc-init --litellm-model openai/text-embedding-3-smallIf you already have CocoIndex global settings,
/cc-initwithout--litellm-modelis fine. If global settings do not exist yet, the extension requires--litellm-model MODELto avoid hanging Pi on CocoIndex's interactive first-run setup.Check configuration and indexing health:
/cc-doctor /cc-reindex /cc-statusAsk Pi to use semantic search. The agent sees only the
searchtool:search({ query: "where request authentication is validated", path: "src/api" })
Agent tool
The extension registers exactly one agent-facing tool:
search({
query: string,
limit?: number, // default 10, max 25
path?: string // optional project-relative file or glob; use `src/**` for recursive directory search
})
search runs ccc search --limit N [--path PATH] QUERY from the resolved project root. It does not run --refresh and does not request reindexing after a successful search; search stays a pure lookup so multiple sequential searches are not interrupted by automatic refreshes. Before searching, the tool performs a short shared ccc status preflight so it does not rely only on the extension's in-memory indexing state; concurrent searches for the same root and timeout reuse the same in-flight status check and a very recent result. If CocoIndex is actively indexing — or if status cannot confirm quickly that the index is idle — search returns immediately with a retry-later message so the agent can inspect files with other available tools while CocoIndex settles. Timeout messages mention that high parallel search/status load can also cause delayed status confirmation. If indexing is unhealthy but not actively running, results may include a stale-index note. Omit path unless the user names an area or broad results are noisy. Files like src/index.ts work directly; for recursive directory search, use glob form such as src/**, not plain src or src/.
In Pi's TUI, the tool call renders as search "<query>". The collapsed result body renders a compact bulleted summary with relative path, line range, language, and CocoIndex score; the expanded view keeps the same bulleted match format for all parsed matches and adds search metadata such as query, path filter, project root, background index state, and truncation status. If a search is deferred because indexing is active or status is unknown, the TUI shows the retry-later message instead of an empty result list. The model still receives the full CocoIndex snippets in the tool content when a search runs.
path is project-relative. Leading @ is stripped for agent convenience, while absolute paths and .. traversal are rejected. Directory-like filters are not normalized automatically in v1; pass an explicit glob such as src/** when you want everything under a directory.
Project root and indexing
The extension treats the git repository as the product boundary. It resolves the project root in this order:
git rev-parse --show-toplevel- nearest initialized CocoIndex ancestor between Pi's current directory and that git root, if one exists
- Pi's current working directory, or an initialized ancestor above it only when no git root exists
Automatic refresh is intentionally simple: session start and successful searches do not trigger indexing. When the agent finishes a run, the agent_end hook checks CocoIndex status and starts ccc index immediately in the background only when status is idle. If CocoIndex is already indexing or status is unknown, the auto-index is skipped with a notification. The extension does not auto-run ccc init from the search tool.
The extension is deliberately chatty while indexing: Pi notifications announce background index start, already-running/cooldown decisions, completion with elapsed time, failures with a short diagnostic hint, skipped agent-end auto-index attempts, and reset-time aborts. Agent-facing searches use a short status preflight for fast safety; /cc-status remains the longer diagnostic command when you need full CocoIndex status output. If notifications become too noisy in practice, this is the first behavior to tune down.
Human commands
Lifecycle/debug operations are slash commands for the human, not tools for the agent:
/cc-init [--force|-f] [--litellm-model MODEL]
/cc-status
/cc-reindex
/cc-doctor
/cc-reset [--yes]
/cc-initrunsccc init, then starts background indexing. If the project is already initialized, it first confirms CocoIndex status is idle; if CocoIndex is actively indexing or status is unknown, init is not started. If CocoIndex global settings do not exist yet, the command requires--litellm-model MODELfor noninteractive setup; otherwise runccc initonce in a terminal first./cc-statusshows dense extension state — initialized status, current index state, reason, start/finish times, last success/failure, retry cooldown, and last error — plus rawccc statusoutput./cc-reindexstarts/dedupes backgroundccc indexafter confirming CocoIndex status is idle; it is not started while external indexing is active or status is unknown./cc-doctorrunsccc doctor./cc-resetconfirms unless--yes, aborts extension-owned indexing, confirms CocoIndex status is idle, runsccc reset -f, then starts background indexing if the project remains initialized. It refuses to reset while external indexing is active or status is unknown.
Notes
- First-time CocoIndex setup may require embedding configuration. To avoid hanging Pi on an interactive prompt,
/cc-initwill not run before global settings exist unless you provide/cc-init --litellm-model <model>. - Background index failures are throttled for five minutes so automatic indexing does not repeatedly spawn a failing index process.
/cc-reindexbypasses that cooldown. Use/cc-statuswhenever chatty lifecycle notifications indicate a failed or stale index. - CocoIndex settings and index state live outside this npm package and should not be committed from projects that use it.
License
MIT © 2026 pi-cocoindex contributors.