# Tools Reference — Pi Extension Complete reference for every tool registered by `@octocodeai/pi-extension`. The 15 Octocode research tools are reached through the built-in `octocode` MCP server; the Pi-specific tools are implemented directly in `src/tools/`. Run `npx octocode tools --scheme` before calling a research tool—the live schema is authoritative. The branded launcher suppresses all native Pi built-ins before session creation. The extension supplies its guarded same-name `bash`; for direct extension installs it also removes native `read`/`edit`/`write`/`grep`/`find`/`ls` on load and session start. `file` consolidates file mutations. See **[OVERRIDES.md](./OVERRIDES.md)** for the user contract and developer code map. --- ## Tool inventory The direct palette contains 17 extension-owned tools: 16 support tools and the guarded `bash` override. GitHub, local, LSP, and npm research tools are provided indirectly through the built-in `octocode` MCP server. | Family | Direct tools | |---|---| | Core | `file`, `bash` | | Browser and workers | `chromeDebug`, `agent` | | Media and web | `readMedia`, `media`, `runFfmpeg`, `web` | | MCP | `MCPTool` | | Dynamic capabilities | `callTool`, `skill` | | Planning and interaction | `plan`, `askUser`, `localServer` | | Awareness | `memory`, `lock`, `message` | Every direct tool exposes only one top-level field, `queries`. Each query requires a non-empty `reasoning` string of at most 240 characters. A call accepts at most 100 queries, validates the full batch before side effects, executes in source order, stops on the first runtime failure, and keeps prior successful effects. Successful batches return a compact receipt index followed by every child content block—including images—in source order; the receipt never replaces model-visible results. One-query calls preserve the underlying result details and rendering contract. ### Tool transcript UI contract Tool request and result rows use one compositional view shape: **state glyph → tool identity → tool-specific semantic segments → optional evidence body → optional disclosure hint**. Each tool still chooses the useful segments for its domain—for example paths and byte counts for file operations, URLs and pagination for web, exit codes and line counts for Bash, or action/target for Awareness—but the reading order and state language stay stable. Colors convey meaning rather than decoration: - brand/accent: a request or operation currently running; - green: completed successfully; - red: failed and needs correction; - gold: warning, blocked state, or user action needed; - sky/path: filesystem target; - lavender/link: URL or parallel-policy signal; - normal/count: totals and numeric evidence; - bright/title: tool identity, action, or current focal value; - muted/dim: metadata, previews, reasoning, and disclosure hints. Renderer limits are view-only. The tool result delivered to the model remains unchanged. Bash is the sole direct tool that pages model-visible text, losslessly, into content blocks of at most 20,000 characters; its collapsed/expanded terminal preview is independently bounded and never edits stdout or stderr. The Awareness CLI remains the canonical backend diagnostics and recovery surface; it does not expand the Pi palette. Session-scoped maintenance jobs are controlled by `/octocode-cron`; see [CRON.md](./CRON.md). `OCTOCODE_SUPPORT_TOOL_NAMES` in `src/constants.ts` is the direct support-tool source of truth. --- ## Routing Guide | Task | Tool | |------|------| | Run shell commands, git, builds | `bash` | | Edit existing file (exact replacement) | `file` with `type:"edit"` | | Create / overwrite a file | `file` with `type:"write"` | | Delete a file or symbolic link | `file` with `type:"delete"` | | Search code across GitHub | `ghSearchCode` | | Read a file from GitHub | `ghGetFileContent` | | Browse a GitHub repo tree | `ghViewRepoStructure` | | Discover GitHub repos | `ghSearchRepos` | | Search pull requests | `ghSearchPullRequests` | | Search issues | `ghSearchIssues` | | Search commits | `ghSearchCommits` | | Clone repo for local reads | `ghCloneRepo` | | Search local files (text / AST) | `localSearchCode` | | Browse local directory tree | `localViewStructure` | | Find files by name/size/time | `localFindFiles` | | Read a local file or range | `localGetFileContent` | | Find dead-code candidates | `localFindDeadCode` | | Symbol identity, refs, callers, types | `lspGetSemantics` | | Resolve npm package to source | `npmSearch` | | See a local image / screenshot | `readMedia` with `type:"image"` | | Inspect video/audio metadata | `readMedia` with `type:"video"` / `"audio"`, `view:"metadata"` | | See a video frame/contact sheet or audio visualization | `readMedia` with the matching `view` | | Author an image or PDF | `media` with `type:"image"` / `"pdf"` | | Convert / clip / resize / gif / extract audio | `media` with `type:"convert"` / `"trim"` / `"gif"` / `"audio"` | | Single-shot Chrome DevTools call | `chromeDebug` | | Browser analysis routing | `agent` with `profile:"browser"` | | Multi-turn browser session | `agent` spawn, then wait/message/steer/abort/kill queries | | Spawn background Pi worker | `agent` with `type:"spawn"` | | Coordinate spawned workers | `agent` lifecycle queries | | Fetch a URL / web search | `web` | | List / call an external MCP server tool | `MCPTool` | | Add / remove / restart an MCP server (no agent restart) | `MCPTool` (action: add/remove/restart) | > **Built-in `octocode` server.** The gateway resolves the pinned local `octocode-mcp` > package first and falls back to `npx -y octocode-mcp@latest`. You can't remove the > built-in entry, but you can override it with `action:"add"`. Active config directories > are watched for external edits; a change drops stale connections and catalogs before the > next call. `RUN_MCP_LIVE=1` enables the > [built-in connection test](../tests/mcp-tool.test.ts), and the > [external Node MCP integration test](../tests/mcp-external.test.ts) runs by default. | Reuse/create/maintain a verified dynamic capability | `callTool` | | Load or manage a reusable multi-step workflow | `skill` with `type:"load"|"call"` | | Compact or reset context | Pi's user `/compact` or `/new`; automatic compaction remains active | | Recall prior lessons that may change the approach | `memory` | | Record a verified reusable root cause / decision | `memory` | | Inspect deeper shared-state diagnostics | Awareness skill / `$OCTOCODE_AWARENESS_CLI` | | Send / read needed peer messages | `message` | | Protect sensitive/non-mergeable files exceptionally | `lock` | | Diagnose task, handoff, verification, or presence state | `$OCTOCODE_AWARENESS_CLI` (recovery only) | --- ## Core Tools ### `bash` Execute shell commands in the current working directory. Octocode override of Pi’s built-in bash: same shell execution, plus path-guard on redirect/`tee`/`cp`/`mv` write targets and a small blocklist of catastrophic commands. Every call requires a non-empty `reasoning` field explaining why the command is necessary. Bash is the only direct tool that pages model-visible text: stdout + stderr is split losslessly into content blocks of at most 20,000 characters, with full stdout/stderr retained in renderer details. Collapsed UI shows the latest lines; expanded UI uses a bounded head/tail preview. Prefer `file` for ordinary mutations; use bash for builds, tests, package commands, and genuinely mechanical changes. Details: [OVERRIDES.md](./OVERRIDES.md). ### `file` One guarded mutation boundary with `type:"edit" | "write" | "delete"`: - `edit`: targeted exact/normalized/lineRange replacements with stale/lost-update checks, BOM/CRLF preservation, and Myers diff/patch details. - `write`: atomic create or full overwrite with parent-directory creation and post-write read-state recording. - `delete`: files and symbolic links only; directories are rejected, and metadata is rechecked under the mutation queue before unlinking. Every query requires one concise `reasoning`. Mixed batches reject duplicate paths and fully preflight every operation before the first mutation. All paths use the shared cwd/home/temp/`ALLOWED_PATHS` guard. Use `delete` only when removal is explicitly in scope. Details: [OVERRIDES.md](./OVERRIDES.md). --- ## GitHub Tools All use the live `queries` schema reported by `npx octocode tools --scheme`. Do not reuse remembered fields across catalog versions. | Tool | Key params | Notes | |------|-----------|-------| | `ghSearchCode` | `keywords`, `owner`, `repo`, `match`, `extension`, `path`, `page` | `match:"path"` for filenames; `match:"file"` for snippets | | `ghSearchRepos` | `keywords`, `language`, `stars`, `sort`, `concise` | Start `concise:true`; follow into `ghViewRepoStructure` | | `ghSearchPullRequests` | `keywordsToSearch`, `prNumber`, `owner`, `repo`, `state` | Search PRs or fetch one PR by number | | `ghSearchIssues` | `keywordsToSearch`, `issueNumber`, `owner`, `repo`, `state` | Search issues or fetch one issue by number | | `ghSearchCommits` | `owner`, `repo`, `path`, `since`, `until`, `base`, `head`, `includeDiff` | Search commit history or inspect a bounded comparison | | `ghGetFileContent` | `owner`, `repo`, `path`, `startLine`/`endLine`, `matchString`, `minify`, `branch` | `symbols` → anchor → `none` for edits | | `ghViewRepoStructure` | `owner`, `repo`, `path`, `maxDepth`, `branch` | Orient before fetching files | | `ghCloneRepo` | `owner`, `repo`, `branch`, `sparsePath` | Needs `ENABLE_CLONE`; use `sparsePath` to bound checkout | --- ## Local Tools All accept absolute paths. Strip leading `@` if copied from a Pi file reference. | Tool | Key params | Notes | |------|-----------|-------| | `localViewStructure` | `path`, `maxDepth`, `page`, `limit` | Cheapest orientation step; use before any file read | | `localSearchCode` | `path`, `searchText`, `mode` plus mode-specific fields | Modes: `discovery` · `paginated` · `detailed` · `structural` (AST) | | `localFindFiles` | `path`, `names`, `pathPattern` plus metadata filters | Name/metadata filters; use when content doesn't matter | | `localGetFileContent` | `path`, `startLine`/`endLine`, `matchString`, `minify`, `fullContent` | `symbols` first for large files; `none` for edits/citations | | `localFindDeadCode` | `path`, `entrypoints`, `includeTests`, `excludeDir`, `maxFiles` | Candidate generator only; prove reachability with `lspGetSemantics` before deleting | **`localSearchCode` modes:** | Mode | Use | |------|-----| | `discovery` | Paths only — cheapest; find candidates before reading | | `paginated` | Snippets with surrounding context | | `detailed` | Full context window | | `structural` | AST pattern (`pattern`) or rule (`rule`); captures feed `lspGetSemantics` | --- ## LSP Tool ### `lspGetSemantics` Symbol-level code intelligence. `lineHint` **must** come from a prior search result, `matchRanges`, or `documentSymbols` — never guessed. | Operation | When to use | |-----------|------------| | `definition` | Jump to declaration | | `references` | All usages of a symbol | | `callers` / `callees` | Call hierarchy one level | | `callHierarchy` | Full call graph (use `depth`) | | `hover` | Type info + docs at a location | | `documentSymbols` | All symbols in a file (no `lineHint` needed) | | `workspaceSymbol` | Fuzzy project-wide symbol search | | `typeDefinition` | Follow to type declaration | | `implementation` | Find interface implementations | | `supertypes` / `subtypes` | Type hierarchy | | `diagnostic` | File-level errors/warnings (no `lineHint` needed) | --- ## Package Tool ### `npmSearch` Resolve npm package names → GitHub repo. Exact package name returns rich single result with `repository`. Keyword query returns paginated candidates. Follow `repository` into GitHub tools. --- ## Browser and agent tools See [`BROWSER_AGENT.md`](https://github.com/bgauryy/octocode-mcp/blob/main/packages/octocode-pi-extension/subagents/browser-agent/BROWSER_AGENT.md) for the Chrome DevTools scheme reference. ### `chromeDebug` Runs one direct Chrome DevTools operation. Use it for bounded observations or interactions. A query can select a named scheme or `raw` with a CDP `Domain.method`. ### `agent` Spawns typed, browser, or custom workers and controls their lifecycle. The `type` discriminator supports `spawn`, `inspect`, `wait`, `message`, `steer`, `abort`, and `kill`. Worker assistant output and stderr are retained and returned without a transport cap. Collapsed and expanded TUI renderers create bounded previews only at display time; they never mutate the result delivered to the parent agent. Spawn profiles: | Profile | Use | |---|---| | `researcher` | Evidence gathering across web, GitHub, npm, local files, binaries, and LSP. | | `planner` | Dependency-ordered implementation plans, risks, verification strategy, and RFC handoffs. | | `architect` | Root-cause and architecture analysis with local tools and targeted shell checks. | | `browser` | Routed multi-turn Chrome DevTools work. | | `custom` | A clean worker with explicit tools, system prompt, and resource mode. | ```text agent({queries:[{ reasoning:"Delegate an independent browser audit.", type:"spawn", profile:"browser", task:"Audit cookie security on https://example.com", url:"https://example.com", launch:true }]}) → agentId: "abc123" agent({queries:[{reasoning:"Collect the browser turn.",type:"wait",agentId:"abc123",timeoutMs:60000}]}) agent({queries:[{reasoning:"Free the completed worker.",type:"kill",agentId:"abc123",remove:true}]}) ``` Spawn policy is warning-first: task packets should name goal, context, scope, ownership, acceptance, and return shape. Capacity limits block before process creation. Workers never receive the `agent` facade, so recursive spawning is unavailable. Spawn first and use the returned ID in a later call; generated IDs can't be referenced by another item in the same preflighted batch. ### `/octocode-agents` This user command manages the in-session worker ledger and below-editor widget. It lists, inspects, kills, prunes, or hides worker records. The model uses `agent` lifecycle queries; users can use `/octocode-agents` directly. See [`AGENT_ORCHESTRATOR.md`](./AGENT_ORCHESTRATOR.md) and [`SUBAGENTS.md`](./SUBAGENTS.md). ## Media and web tools ### `readMedia` The read-only perception boundary for local media. Each query chooses `type:"image"`, `"video"`, or `"audio"` and provides `path`. Images are returned directly. Video supports `view:"metadata"`, `"frame"`, or `"contactSheet"`; audio supports `view:"metadata"`, `"waveform"`, or `"spectrogram"`. Visual results are sent to the model as image content as well as rendered in capable terminals. Defaults favor useful perception: `contactSheet` for video and `waveform` for audio. ### `media` The only public creation/transformation boundary. Each query chooses `type:"image"`, `"pdf"`, `"gif"`, `"trim"`, `"audio"`, or `"convert"`. - `image`: exactly one of `svg` or `html`; an optional `dest` saves the PNG. - `pdf`: exactly one of `html`, `markdown`, or `images`; `dest` is required. - `gif`, `trim`, `audio`, `convert`: require `source` and `dest` and use hardened argv-only ffmpeg execution. Writes are workspace path-guarded and refuse to clobber unless `overwrite:true`. Timestamps accept `"12"`, `"1:05"`, or `"00:01:05.5"`; ffmpeg jobs honor `timeoutSec` (default 120). Chrome is required for HTML/PDF authoring and ffmpeg for transformations. See [MEDIA_TOOL.md](./MEDIA_TOOL.md) for the decision record and exact split. ### `web` Fetches a public URL as clean text or runs a web search. Query fields select `url` or search `query`, result/page limits, engine, recency, and domain filters. ## Context controls The extension doesn't register a model-callable context tool. Automatic compaction and continuation hooks remain active. Users can invoke Pi's `/compact` and `/new` commands directly. A model-runtime `maximum output token limit` stop is different from context pressure: shorten or chunk the response, or write long output to a file and return a concise summary and path. --- ## Session artifact routing Every tool output that lands on disk is now routed into the **session artifact tree** under `/.octocode/agent//` and registered in a session manifest (`manifest.json`). The `session-key` is derived from `sessionManager.getSessionId()` (falls back to the session-file basename, then `process-`). | Producer slot | Path inside session tree | Notes | |---|---|---| | `plan` | `plan/plan.html`, `plan/plan.md`, `plan/state.json`, `plan/branches/*.json` | Primary plan artifacts and branch snapshots | | `browser` | `browser/port-/session.json`, `browser/screenshots/*.png` | chromeDebug session metadata and screenshots | | `compaction` | `compaction/-