mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Fixes #4748. ## Problem Extensions that import `keyText`/`keyHint` from `@earendil-works/pi-coding-agent` can resolve their own copy of the package (their own `node_modules`, or the bundled `cli.js` vs `dist/index.js`). That copy's keybindings are never set by the host, so it falls back to a manager with only `tui.*` bindings, and `keyHint("app.tools.expand", "to expand")` renders as ` to expand`. ## Change The host passes its own `keyText` and `keyHint` to extension renderers, the same way it passes `theme`: - `ToolRenderContext` (`renderCall`/`renderResult` context): `context.keyHint(...)` - `MessageRenderOptions` and `EntryRenderOptions`: `options.keyHint(...)` All three extend a new exported `KeybindingHints` interface. The docs and the `debug-provider` example now use the injected functions and warn against importing them in renderers. Not done: - Moving the `pi-tui` keybindings singleton to `globalThis`. Per the discussion in #7011, extension-facing state should be host-owned and passed through the extension API instead of shared through process-wide module state. - `ctx.ui.keyText`/`keyHint`. No reported case needs them outside renderers, RPC and print modes never install app keybindings, and adding them to `ExtensionUIContext` would break SDK hosts that implement it. ## Tests - `test/extension-keybinding-hints.test.ts`: tool, message, and entry renderers format a user-overridden `app.tools.expand` binding. - `npm run check` passes. |
||
|---|---|---|
| .. | ||
| extensions | ||
| sdk | ||
| README.md | ||
| rpc-client.ts | ||
| rpc-extension-ui.ts | ||
Examples
Example code for the pi-coding-agent SDK, process integration, and extensions.
CLI integration
rpc-client.ts uses the typed RpcClient to run Pi in a child process, stream events, and wait for the run to settle.
Build the coding-agent package before running it from a repository checkout:
node examples/rpc-client.ts "Explain this repository"
Directories
sdk/
Programmatic usage via createAgentSession(). Shows how to customize models, prompts, tools, extensions, and session management.
extensions/
Example extensions demonstrating:
- Lifecycle event handlers (tool interception, safety gates, context modifications)
- Custom tools (todo lists, questions, subagents, output truncation)
- Commands and keyboard shortcuts
- Custom UI (footers, headers, editors, overlays)
- Git integration (checkpoints, auto-commit)
- System prompt modifications and custom compaction
- External integrations (SSH, file watchers, system theme sync)
- Custom providers (Anthropic with custom streaming, GitLab Duo)