How mateusdcc/pi-gpt-search works
Purpose and runtime
pi-gpt-search is a TypeScript extension for the Pi Coding Agent that gives the active Pi model web retrieval without invoking GPT inference. It runs on Node.js 18+ and is installed/loaded by Pi as an extension. Primary extension entry point: src/index.ts.
Extension registration and user surfaces
The extension exposes three Pi-facing interfaces:
• /gpt-search direct command, registered through src/commands.ts.
• codex-search, a focused single-query LLM tool.
• web, a stateful multi-step research tool supporting search, document open, find, and navigation.
Tool construction and registration are centered in src/tool.ts, src/web-tool.ts, and src/index.ts.
Retrieval provider boundary
The provider abstraction separates Pi tool behavior from the remote retrieval backend. src/provider.ts defines the provider-facing boundary, while src/codex-provider.ts implements OpenAI Codex standalone search access. Requests target Codex/OpenAI retrieval infrastructure rather than a chat/completions API, preserving the “zero GPT inference” design.
Credentials, context, and privacy boundary
Authentication is sourced from explicit environment values or an existing local Codex session, with optional values documented in .env.example. src/context.ts manages request/session context, including the state needed for multi-step web operations. The intended outbound boundary is query and retrieval state only: conversation history, project files, and Pi system prompts are not sent as search payloads by default.
Core execution flow
For a direct command or codex-search, the flow is:
1. Pi invokes command/tool handlers in src/commands.ts or src/tool.ts.
2. Input is validated/normalized in src/normalize.ts.
3. The Codex provider in src/codex-provider.ts sends the retrieval request.
4. Results are transformed into Pi-facing output by src/output.ts.
For web, src/web-tool.ts accepts one or more search queries, then uses retained context to resolve returned reference IDs for later open and find operations. This makes research iterative while keeping retrieval orchestration within the extension.
Output, errors, and operational behavior
src/output.ts formats structured search results—such as titles, URLs, snippets, views, and citations—for Pi’s display/tool response layer. src/errors.ts provides a dedicated failure boundary for authentication, endpoint, timeout, cancellation, and upstream-response conditions. Debug request telemetry is controlled through PI_WEB_SEARCH_DEBUG; endpoint/session failures depend on Codex authentication validity and remote OpenAI service availability.
External dependencies and infrastructure
Material external systems are:
• Pi Coding Agent runtime, which loads src/index.ts and invokes registered commands/tools.
• Local Codex authentication state (typically ~/.codex/auth.json) or CODEX_ACCESS_TOKEN.
• OpenAI Codex standalone search endpoint (/codex/alpha/search) for search and document retrieval.
The package is distributed through npm/GitHub and configured as a Node/TypeScript package via package.json.
Main entry points: codex-provider.ts Codex provider · web-tool.ts web tool · index.ts Extension entry · output.ts Pi-facing output
Components 13
Pi Integration
- Pi Coding Agent · Loads the extension and invokes its commands and tools.
- Extension entry
src/index.ts - /gpt-search
src/commands.ts - codex-search · Focused single-query retrieval tool.
src/tool.ts - web tool · Supports iterative search, open, find, and navigation.
src/web-tool.ts
Extension Core
- Input normalization
src/normalize.ts - Research context · Retains reference IDs for follow-up web operations.
src/context.ts - Provider boundary
src/provider.ts - Codex provider · Uses standalone retrieval rather than chat/completions inference.
src/codex-provider.ts - Pi-facing output · Formats titles, URLs, snippets, views, and citations.
src/output.ts - Failure boundary · Handles auth, endpoint, timeout, cancellation, and upstream failures.
src/errors.ts
Credentials & Retrieval
- Codex credentials · Uses CODEX_ACCESS_TOKEN or local Codex session state.
- Codex search endpoint · OpenAI /codex/alpha/search for search and document retrieval.
Connections 19
- Pi Coding Agent → Extension entry: loads
- Extension entry → /gpt-search: registers
- Extension entry → codex-search: registers
- Extension entry → web tool: registers
- /gpt-search → Input normalization: query
- codex-search → Input normalization: query
- web tool → Input normalization: search input
- web tool → Research context: stores references
- Research context → web tool: resolves open/find
- Input normalization → Provider boundary: normalized request
- Provider boundary → Codex provider: implemented by
- Codex provider → Codex credentials: authenticates with
- Codex provider → Codex search endpoint: retrieval request · Only query and retrieval state are sent by default.
- Codex search endpoint → Codex provider: results
- Codex provider → Pi-facing output: structured results
- Pi-facing output → /gpt-search: display response
- Pi-facing output → codex-search: tool response
- Pi-facing output → web tool: research response
- Codex provider → Failure boundary: operational failures