@maxmo74/pi-coding-agent 0.0.0-stage → 1.4.0-max.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6397 -0
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/dist/bun/cli.d.ts +5 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +5 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +17 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +36 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/bun/runtime-setup.d.ts +2 -0
- package/dist/bun/runtime-setup.d.ts.map +1 -0
- package/dist/bun/runtime-setup.js +12 -0
- package/dist/bun/runtime-setup.js.map +1 -0
- package/dist/bun/sandbox-env-setup.d.ts +2 -0
- package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
- package/dist/bun/sandbox-env-setup.js +4 -0
- package/dist/bun/sandbox-env-setup.js.map +1 -0
- package/dist/bundle/chunks/anthropic-messages-KRX3GRGV.js +6 -0
- package/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/bundle/chunks/azure-openai-responses-YWTDZRIJ.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
- package/dist/bundle/chunks/chunk-4UNN5OGR.js +4 -0
- package/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
- package/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
- package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/bundle/chunks/chunk-AFNTYPTW.js +65 -0
- package/dist/bundle/chunks/chunk-BPHHHEET.js +9 -0
- package/dist/bundle/chunks/chunk-BSS6T6KQ.js +2 -0
- package/dist/bundle/chunks/chunk-CF5GWZHW.js +31 -0
- package/dist/bundle/chunks/chunk-CPKYLLPC.js +2 -0
- package/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
- package/dist/bundle/chunks/chunk-G2WC5ETL.js +2 -0
- package/dist/bundle/chunks/chunk-HODJBMOY.js +9 -0
- package/dist/bundle/chunks/chunk-HQBQWHLD.js +7 -0
- package/dist/bundle/chunks/chunk-HQJBN2MC.js +2 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
- package/dist/bundle/chunks/chunk-KFM2CJ7Q.js +4 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/bundle/chunks/chunk-LAMEVJ4W.js +132 -0
- package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
- package/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
- package/dist/bundle/chunks/chunk-M3LEVT3X.js +2 -0
- package/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/bundle/chunks/chunk-QTM7S6TH.js +2 -0
- package/dist/bundle/chunks/chunk-QVAQV2RJ.js +1237 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
- package/dist/bundle/chunks/chunk-RFUP4YGP.js +82 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
- package/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
- package/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
- package/dist/bundle/chunks/chunk-V4LJ5IY6.js +44 -0
- package/dist/bundle/chunks/chunk-XPUTTZLN.js +16 -0
- package/dist/bundle/chunks/chunk-ZN2R65UF.js +2 -0
- package/dist/bundle/chunks/cli-QUXYJ5RR.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-QPZQRBK5.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +478 -0
- package/dist/bundle/chunks/easter-egg-3d-RD5RBYI2.js +2 -0
- package/dist/bundle/chunks/execute-XTJDRV75.js +505 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-J3K3YPN3.js +2 -0
- package/dist/bundle/chunks/google-vertex-VFXOTBVP.js +2 -0
- package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
- package/dist/bundle/chunks/llama-cpp-classify-4KFSGAMH.js +22 -0
- package/dist/bundle/chunks/meta.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-C2QQGYVC.js +5 -0
- package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
- package/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
- package/dist/bundle/chunks/node-KCMANYC2.js +16 -0
- package/dist/bundle/chunks/openai-chatgpt.js +75 -0
- package/dist/bundle/chunks/openai-codex-responses-H2UJSVV3.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/bundle/chunks/openai-completions-QPD4B26I.js +7 -0
- package/dist/bundle/chunks/openai-decisions-O6PHBSCB.js +5 -0
- package/dist/bundle/chunks/openai-responses-JOYMWKMB.js +4 -0
- package/dist/bundle/chunks/openrouter-images-4WG6OOLH.js +2 -0
- package/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/bundle/chunks/pi-messages-EZXKVRR6.js +8 -0
- package/dist/bundle/chunks/radius.js +75 -0
- package/dist/bundle/chunks/runtime-YKR6KZPS.js +2 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-X3JT6ECA.js +2 -0
- package/dist/bundle/chunks/virtual-modules-KVDFV7IC.js +2 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli-runtime.js +3 -0
- package/dist/bundle/cli.js +5 -0
- package/dist/bundle/index.js +2 -0
- package/dist/bundle/rpc-entry.js +3 -0
- package/dist/cli/args.d.ts +62 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +473 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts +16 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +32 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/credential-print.d.ts +13 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +76 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +71 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +98 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/project-trust.d.ts +10 -0
- package/dist/cli/project-trust.d.ts.map +1 -0
- package/dist/cli/project-trust.js +48 -0
- package/dist/cli/project-trust.js.map +1 -0
- package/dist/cli/session-picker.d.ts +10 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +36 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +12 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/startup-ui.d.ts +20 -0
- package/dist/cli/startup-ui.d.ts.map +1 -0
- package/dist/cli/startup-ui.js +193 -0
- package/dist/cli/startup-ui.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +126 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +534 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +120 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/core/agent-session-runtime.js +307 -0
- package/dist/core/agent-session-runtime.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +147 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +940 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +3654 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +72 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +433 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +32 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +101 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/bug-report-upload.d.ts +12 -0
- package/dist/core/bug-report-upload.d.ts.map +1 -0
- package/dist/core/bug-report-upload.js +22 -0
- package/dist/core/bug-report-upload.js.map +1 -0
- package/dist/core/bug-report.d.ts +184 -0
- package/dist/core/bug-report.d.ts.map +1 -0
- package/dist/core/bug-report.js +292 -0
- package/dist/core/bug-report.js.map +1 -0
- package/dist/core/cache-stats.d.ts +49 -0
- package/dist/core/cache-stats.d.ts.map +1 -0
- package/dist/core/cache-stats.js +112 -0
- package/dist/core/cache-stats.js.map +1 -0
- package/dist/core/cache-warmer.d.ts +103 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +356 -0
- package/dist/core/cache-warmer.js.map +1 -0
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +15 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +100 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +253 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +145 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +749 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +45 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +148 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/crash-log.d.ts +27 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +140 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/defaults.d.ts +4 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +11 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +37 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +119 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/experimental.d.ts +2 -0
- package/dist/core/experimental.d.ts.map +1 -0
- package/dist/core/experimental.js +4 -0
- package/dist/core/experimental.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +37 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +236 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1085 -0
- package/dist/core/export-html/template.html +56 -0
- package/dist/core/export-html/template.js +2044 -0
- package/dist/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +110 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +79 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/jiti-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-loader.js +4 -0
- package/dist/core/extensions/jiti-loader.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +4 -0
- package/dist/core/extensions/jiti-static-loader.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +23 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +704 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +215 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +1238 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1769 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +48 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/virtual-modules.d.ts +3 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +41 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +64 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +338 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/http-dispatcher.d.ts +22 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +98 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/key-id-schema.d.ts +6 -0
- package/dist/core/key-id-schema.d.ts.map +1 -0
- package/dist/core/key-id-schema.js +16 -0
- package/dist/core/key-id-schema.js.map +1 -0
- package/dist/core/keybindings-schema.d.ts +4 -0
- package/dist/core/keybindings-schema.d.ts.map +1 -0
- package/dist/core/keybindings-schema.js +16 -0
- package/dist/core/keybindings-schema.js.map +1 -0
- package/dist/core/keybindings.d.ts +568 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +328 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/mcp-servers.d.ts +139 -0
- package/dist/core/mcp-servers.d.ts.map +1 -0
- package/dist/core/mcp-servers.js +232 -0
- package/dist/core/mcp-servers.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +124 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-config.d.ts +2312 -0
- package/dist/core/model-config.d.ts.map +1 -0
- package/dist/core/model-config.js +168 -0
- package/dist/core/model-config.js.map +1 -0
- package/dist/core/model-registry.d.ts +63 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +144 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +137 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +491 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/model-runtime.d.ts +145 -0
- package/dist/core/model-runtime.d.ts.map +1 -0
- package/dist/core/model-runtime.js +767 -0
- package/dist/core/model-runtime.js.map +1 -0
- package/dist/core/models-store.d.ts +22 -0
- package/dist/core/models-store.d.ts.map +1 -0
- package/dist/core/models-store.js +115 -0
- package/dist/core/models-store.js.map +1 -0
- package/dist/core/nested-tool-calls.d.ts +103 -0
- package/dist/core/nested-tool-calls.d.ts.map +1 -0
- package/dist/core/nested-tool-calls.js +179 -0
- package/dist/core/nested-tool-calls.js.map +1 -0
- package/dist/core/output-guard.d.ts +7 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +89 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +226 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +2275 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/pi-manifest.d.ts +9 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +30 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/project-trust.d.ts +15 -0
- package/dist/core/project-trust.d.ts.map +1 -0
- package/dist/core/project-trust.js +60 -0
- package/dist/core/project-trust.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +59 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +267 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/provider-composer.d.ts +81 -0
- package/dist/core/provider-composer.d.ts.map +1 -0
- package/dist/core/provider-composer.js +492 -0
- package/dist/core/provider-composer.js.map +1 -0
- package/dist/core/radius.d.ts +7 -0
- package/dist/core/radius.d.ts.map +1 -0
- package/dist/core/radius.js +10 -0
- package/dist/core/radius.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +23 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -0
- package/dist/core/remote-catalog-provider.js +190 -0
- package/dist/core/remote-catalog-provider.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +30 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +247 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +232 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +1026 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/runtime-credentials.d.ts +15 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -0
- package/dist/core/runtime-credentials.js +39 -0
- package/dist/core/runtime-credentials.js.map +1 -0
- package/dist/core/sdk.d.ts +117 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +329 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-delete.d.ts +8 -0
- package/dist/core/session-delete.d.ts.map +1 -0
- package/dist/core/session-delete.js +37 -0
- package/dist/core/session-delete.js.map +1 -0
- package/dist/core/session-export.d.ts +8 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +33 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-manager.d.ts +422 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1568 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-move.d.ts +3 -0
- package/dist/core/session-move.d.ts.map +1 -0
- package/dist/core/session-move.js +133 -0
- package/dist/core/session-move.js.map +1 -0
- package/dist/core/session-ownership.d.ts +13 -0
- package/dist/core/session-ownership.d.ts.map +1 -0
- package/dist/core/session-ownership.js +205 -0
- package/dist/core/session-ownership.js.map +1 -0
- package/dist/core/settings-defaults.d.ts +66 -0
- package/dist/core/settings-defaults.d.ts.map +1 -0
- package/dist/core/settings-defaults.js +67 -0
- package/dist/core/settings-defaults.js.map +1 -0
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +253 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +1154 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/settings-schema.d.ts +231 -0
- package/dist/core/settings-schema.d.ts.map +1 -0
- package/dist/core/settings-schema.js +294 -0
- package/dist/core/settings-schema.js.map +1 -0
- package/dist/core/skills.d.ts +63 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +412 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +28 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/source-info.d.ts +33 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +43 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +77 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +152 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/timings.d.ts +10 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +41 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +100 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +333 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +101 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +421 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +44 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +147 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +52 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +42 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +251 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +41 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +254 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +43 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +41 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +126 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +63 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +214 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +10 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +99 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/read.d.ts +55 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +186 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +50 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +158 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/renderers/bash.d.ts +12 -0
- package/dist/core/tools/renderers/bash.d.ts.map +1 -0
- package/dist/core/tools/renderers/bash.js +89 -0
- package/dist/core/tools/renderers/bash.js.map +1 -0
- package/dist/core/tools/renderers/edit.d.ts +23 -0
- package/dist/core/tools/renderers/edit.d.ts.map +1 -0
- package/dist/core/tools/renderers/edit.js +168 -0
- package/dist/core/tools/renderers/edit.js.map +1 -0
- package/dist/core/tools/renderers/find.d.ts +10 -0
- package/dist/core/tools/renderers/find.d.ts.map +1 -0
- package/dist/core/tools/renderers/find.js +64 -0
- package/dist/core/tools/renderers/find.js.map +1 -0
- package/dist/core/tools/renderers/grep.d.ts +10 -0
- package/dist/core/tools/renderers/grep.d.ts.map +1 -0
- package/dist/core/tools/renderers/grep.js +69 -0
- package/dist/core/tools/renderers/grep.js.map +1 -0
- package/dist/core/tools/renderers/index.d.ts +28 -0
- package/dist/core/tools/renderers/index.d.ts.map +1 -0
- package/dist/core/tools/renderers/index.js +47 -0
- package/dist/core/tools/renderers/index.js.map +1 -0
- package/dist/core/tools/renderers/ls.d.ts +10 -0
- package/dist/core/tools/renderers/ls.d.ts.map +1 -0
- package/dist/core/tools/renderers/ls.js +58 -0
- package/dist/core/tools/renderers/ls.js.map +1 -0
- package/dist/core/tools/renderers/read.d.ts +11 -0
- package/dist/core/tools/renderers/read.d.ts.map +1 -0
- package/dist/core/tools/renderers/read.js +126 -0
- package/dist/core/tools/renderers/read.js.map +1 -0
- package/dist/core/tools/renderers/write.d.ts +10 -0
- package/dist/core/tools/renderers/write.d.ts.map +1 -0
- package/dist/core/tools/renderers/write.js +153 -0
- package/dist/core/tools/renderers/write.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +16 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +38 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +84 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +244 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +30 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +61 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/trust-manager.d.ts +36 -0
- package/dist/core/trust-manager.d.ts.map +1 -0
- package/dist/core/trust-manager.js +204 -0
- package/dist/core/trust-manager.js.map +1 -0
- package/dist/core/usage-totals.d.ts +21 -0
- package/dist/core/usage-totals.d.ts.map +1 -0
- package/dist/core/usage-totals.js +81 -0
- package/dist/core/usage-totals.js.map +1 -0
- package/dist/core/virtual-models.d.ts +117 -0
- package/dist/core/virtual-models.d.ts.map +1 -0
- package/dist/core/virtual-models.js +124 -0
- package/dist/core/virtual-models.js.map +1 -0
- package/dist/extensions/codemode/execute.d.ts +16 -0
- package/dist/extensions/codemode/execute.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.js +740 -0
- package/dist/extensions/codemode/execute.js.map +1 -0
- package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
- package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
- package/dist/extensions/codemode/execute.lazy.js +3 -0
- package/dist/extensions/codemode/execute.lazy.js.map +1 -0
- package/dist/extensions/codemode/index.d.ts +21 -0
- package/dist/extensions/codemode/index.d.ts.map +1 -0
- package/dist/extensions/codemode/index.js +33 -0
- package/dist/extensions/codemode/index.js.map +1 -0
- package/dist/extensions/codemode/renderer.d.ts +12 -0
- package/dist/extensions/codemode/renderer.d.ts.map +1 -0
- package/dist/extensions/codemode/renderer.js +143 -0
- package/dist/extensions/codemode/renderer.js.map +1 -0
- package/dist/extensions/codemode/tool.d.ts +124 -0
- package/dist/extensions/codemode/tool.d.ts.map +1 -0
- package/dist/extensions/codemode/tool.js +313 -0
- package/dist/extensions/codemode/tool.js.map +1 -0
- package/dist/extensions/codemode/worker.d.ts +7 -0
- package/dist/extensions/codemode/worker.d.ts.map +1 -0
- package/dist/extensions/codemode/worker.js +7 -0
- package/dist/extensions/codemode/worker.js.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +13 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/llama/client.d.ts +69 -0
- package/dist/extensions/llama/client.d.ts.map +1 -0
- package/dist/extensions/llama/client.js +313 -0
- package/dist/extensions/llama/client.js.map +1 -0
- package/dist/extensions/llama/huggingface.d.ts +23 -0
- package/dist/extensions/llama/huggingface.d.ts.map +1 -0
- package/dist/extensions/llama/huggingface.js +141 -0
- package/dist/extensions/llama/huggingface.js.map +1 -0
- package/dist/extensions/llama/index.d.ts +3 -0
- package/dist/extensions/llama/index.d.ts.map +1 -0
- package/dist/extensions/llama/index.js +219 -0
- package/dist/extensions/llama/index.js.map +1 -0
- package/dist/extensions/llama/provider.d.ts +12 -0
- package/dist/extensions/llama/provider.d.ts.map +1 -0
- package/dist/extensions/llama/provider.js +236 -0
- package/dist/extensions/llama/provider.js.map +1 -0
- package/dist/extensions/llama/ui.d.ts +42 -0
- package/dist/extensions/llama/ui.d.ts.map +1 -0
- package/dist/extensions/llama/ui.js +428 -0
- package/dist/extensions/llama/ui.js.map +1 -0
- package/dist/extensions/mcp/cli.d.ts +21 -0
- package/dist/extensions/mcp/cli.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.js +494 -0
- package/dist/extensions/mcp/cli.js.map +1 -0
- package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
- package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/cli.lazy.js +3 -0
- package/dist/extensions/mcp/cli.lazy.js.map +1 -0
- package/dist/extensions/mcp/config.d.ts +84 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -0
- package/dist/extensions/mcp/config.js +195 -0
- package/dist/extensions/mcp/config.js.map +1 -0
- package/dist/extensions/mcp/index.d.ts +79 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -0
- package/dist/extensions/mcp/index.js +1205 -0
- package/dist/extensions/mcp/index.js.map +1 -0
- package/dist/extensions/mcp/log.d.ts +16 -0
- package/dist/extensions/mcp/log.d.ts.map +1 -0
- package/dist/extensions/mcp/log.js +66 -0
- package/dist/extensions/mcp/log.js.map +1 -0
- package/dist/extensions/mcp/oauth.d.ts +102 -0
- package/dist/extensions/mcp/oauth.d.ts.map +1 -0
- package/dist/extensions/mcp/oauth.js +428 -0
- package/dist/extensions/mcp/oauth.js.map +1 -0
- package/dist/extensions/mcp/resources.d.ts +36 -0
- package/dist/extensions/mcp/resources.d.ts.map +1 -0
- package/dist/extensions/mcp/resources.js +261 -0
- package/dist/extensions/mcp/resources.js.map +1 -0
- package/dist/extensions/mcp/runtime.d.ts +98 -0
- package/dist/extensions/mcp/runtime.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.js +378 -0
- package/dist/extensions/mcp/runtime.js.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
- package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
- package/dist/extensions/mcp/runtime.lazy.js +3 -0
- package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
- package/dist/extensions/mcp/tools.d.ts +86 -0
- package/dist/extensions/mcp/tools.d.ts.map +1 -0
- package/dist/extensions/mcp/tools.js +309 -0
- package/dist/extensions/mcp/tools.js.map +1 -0
- package/dist/extensions/mcp/ui.d.ts +61 -0
- package/dist/extensions/mcp/ui.d.ts.map +1 -0
- package/dist/extensions/mcp/ui.js +195 -0
- package/dist/extensions/mcp/ui.js.map +1 -0
- package/dist/extensions/tool-search/index.d.ts +12 -0
- package/dist/extensions/tool-search/index.d.ts.map +1 -0
- package/dist/extensions/tool-search/index.js +15 -0
- package/dist/extensions/tool-search/index.js.map +1 -0
- package/dist/extensions/tool-search/tool.d.ts +75 -0
- package/dist/extensions/tool-search/tool.d.ts.map +1 -0
- package/dist/extensions/tool-search/tool.js +210 -0
- package/dist/extensions/tool-search/tool.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +16 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +836 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +282 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/bug-report.d.ts +16 -0
- package/dist/modes/interactive/bug-report.d.ts.map +1 -0
- package/dist/modes/interactive/bug-report.js +210 -0
- package/dist/modes/interactive/bug-report.js.map +1 -0
- package/dist/modes/interactive/chat-viewport.d.ts +20 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -0
- package/dist/modes/interactive/chat-viewport.js +28 -0
- package/dist/modes/interactive/chat-viewport.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +37 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +335 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +28 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +168 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/auth-url.d.ts +14 -0
- package/dist/modes/interactive/components/auth-url.d.ts.map +1 -0
- package/dist/modes/interactive/components/auth-url.js +37 -0
- package/dist/modes/interactive/components/auth-url.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +38 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +178 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +54 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +54 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +55 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +102 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +771 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +30 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +122 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts +21 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-entry.js +58 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +22 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +88 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.d.ts +104 -0
- package/dist/modes/interactive/components/easter-egg-3d.d.ts.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.js +1139 -0
- package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts +6 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts.map +1 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.js +23 -0
- package/dist/modes/interactive/components/easter-egg-3d.lazy.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +24 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +103 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +25 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +67 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +27 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +87 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/first-time-setup.d.ts +25 -0
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -0
- package/dist/modes/interactive/components/first-time-setup.js +109 -0
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +39 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +265 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +33 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +34 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +59 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +289 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +61 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +372 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +40 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +175 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/pi-logo.d.ts +19 -0
- package/dist/modes/interactive/components/pi-logo.d.ts.map +1 -0
- package/dist/modes/interactive/components/pi-logo.js +37 -0
- package/dist/modes/interactive/components/pi-logo.js.map +1 -0
- package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/radius-login-selector.js +85 -0
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +47 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +337 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +27 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +219 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +104 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +932 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +98 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +753 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +167 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +18 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +57 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/status-indicator.d.ts +30 -0
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -0
- package/dist/modes/interactive/components/status-indicator.js +67 -0
- package/dist/modes/interactive/components/status-indicator.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +50 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/themed-text.d.ts +17 -0
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/themed-text.js +29 -0
- package/dist/modes/interactive/components/themed-text.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +23 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +109 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +79 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +334 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +95 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1250 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/trust-selector.d.ts +23 -0
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/trust-selector.js +91 -0
- package/dist/modes/interactive/components/trust-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +31 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +122 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +18 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +54 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +48 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +66 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/external-editor.d.ts +12 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +38 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +491 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +6060 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
- package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
- package/dist/modes/interactive/model-catalog-refresh.js +34 -0
- package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
- package/dist/modes/interactive/model-search.d.ts +22 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -0
- package/dist/modes/interactive/model-search.js +36 -0
- package/dist/modes/interactive/model-search.js.map +1 -0
- package/dist/modes/interactive/program-status-reporter.d.ts +34 -0
- package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -0
- package/dist/modes/interactive/program-status-reporter.js +110 -0
- package/dist/modes/interactive/program-status-reporter.js.map +1 -0
- package/dist/modes/interactive/session-share.d.ts +18 -0
- package/dist/modes/interactive/session-share.d.ts.map +1 -0
- package/dist/modes/interactive/session-share.js +195 -0
- package/dist/modes/interactive/session-share.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +78 -0
- package/dist/modes/interactive/theme/light.json +78 -0
- package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
- package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/system-theme.js +546 -0
- package/dist/modes/interactive/theme/system-theme.js.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +81 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-controller.js +210 -0
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +105 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.js +94 -0
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +155 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +905 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/interactive/tui-renderer.d.ts +22 -0
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -0
- package/dist/modes/interactive/tui-renderer.js +67 -0
- package/dist/modes/interactive/tui-renderer.js.map +1 -0
- package/dist/modes/json-event.d.ts +34 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +29 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +146 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +254 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +499 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +655 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +478 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/package-manager-cli.d.ts +9 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +1015 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/rpc-entry.d.ts +3 -0
- package/dist/rpc-entry.d.ts.map +1 -0
- package/dist/rpc-entry.js +11 -0
- package/dist/rpc-entry.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/ansi.d.ts +10 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +74 -0
- package/dist/utils/ansi.js.map +1 -0
- package/dist/utils/changelog.d.ts +22 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +165 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +18 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +106 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-command.d.ts +7 -0
- package/dist/utils/clipboard-command.d.ts.map +1 -0
- package/dist/utils/clipboard-command.js +48 -0
- package/dist/utils/clipboard-command.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +214 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard.d.ts +6 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +162 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/deprecation.d.ts +4 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/deprecation.js +13 -0
- package/dist/utils/deprecation.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts +5 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +27 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.js.map +1 -0
- package/dist/utils/git.d.ts +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +195 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +40 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/image-convert.d.ts +22 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +84 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-process.d.ts +18 -0
- package/dist/utils/image-process.d.ts.map +1 -0
- package/dist/utils/image-process.js +83 -0
- package/dist/utils/image-process.js.map +1 -0
- package/dist/utils/image-resize-core.d.ts +42 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +129 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +32 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +16 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +96 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +7 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/management-http.d.ts +25 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +54 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +110 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/open-browser.d.ts +9 -0
- package/dist/utils/open-browser.d.ts.map +1 -0
- package/dist/utils/open-browser.js +22 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/output-files.d.ts +15 -0
- package/dist/utils/output-files.d.ts.map +1 -0
- package/dist/utils/output-files.js +30 -0
- package/dist/utils/output-files.js.map +1 -0
- package/dist/utils/paths.d.ts +34 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +115 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/pi-user-agent.d.ts +3 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +6 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/shell.d.ts +32 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +235 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts +13 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +184 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/tool-result-images.d.ts +21 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +48 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +13 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +339 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/dist/utils/version-check.d.ts +55 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +143 -0
- package/dist/utils/version-check.js.map +1 -0
- package/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/utils/windows-self-update.d.ts.map +1 -0
- package/dist/utils/windows-self-update.js +77 -0
- package/dist/utils/windows-self-update.js.map +1 -0
- package/dist/utils/wsl.d.ts +3 -0
- package/dist/utils/wsl.d.ts.map +1 -0
- package/dist/utils/wsl.js +15 -0
- package/dist/utils/wsl.js.map +1 -0
- package/dist/utils/zip.d.ts +7 -0
- package/dist/utils/zip.d.ts.map +1 -0
- package/dist/utils/zip.js +60 -0
- package/dist/utils/zip.js.map +1 -0
- package/docs/cli-integration.md +106 -0
- package/docs/cli.md +333 -0
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +463 -0
- package/docs/configuration.md +47 -0
- package/docs/containerization.md +183 -0
- package/docs/custom-provider.md +227 -0
- package/docs/docs.json +220 -0
- package/docs/environment-variables.md +102 -0
- package/docs/extensions.md +3333 -0
- package/docs/how-pi-works.md +49 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +39 -0
- package/docs/json.md +226 -0
- package/docs/keybindings.md +195 -0
- package/docs/llama-cpp.md +132 -0
- package/docs/mcp.md +272 -0
- package/docs/message-types.md +279 -0
- package/docs/models-configuration.md +196 -0
- package/docs/models.md +225 -0
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/packages.md +151 -0
- package/docs/prompt-templates.md +59 -0
- package/docs/providers.md +247 -0
- package/docs/quickstart.md +140 -0
- package/docs/rpc-commands.md +860 -0
- package/docs/rpc-extension-ui.md +200 -0
- package/docs/rpc.md +193 -0
- package/docs/sdk.md +147 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +293 -0
- package/docs/sessions.md +66 -0
- package/docs/settings.md +172 -0
- package/docs/shell-aliases.md +93 -0
- package/docs/skills.md +93 -0
- package/docs/slash-commands.md +61 -0
- package/docs/terminal-setup.md +233 -0
- package/docs/termux.md +117 -0
- package/docs/themes.md +138 -0
- package/docs/tmux.md +55 -0
- package/docs/tui.md +197 -0
- package/docs/usage.md +94 -0
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +81 -0
- package/examples/README.md +36 -0
- package/examples/extensions/README.md +214 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +117 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +613 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +81 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +175 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +353 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +394 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +438 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +49 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +286 -0
- package/examples/extensions/questionnaire.ts +448 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +49 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +177 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1036 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +304 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +148 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +661 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +75 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +99 -0
- package/examples/sdk/07-context-files.ts +47 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +141 -0
- package/package.json +94 -5
- package/schemas/keybindings.schema.json +397 -0
- package/schemas/models.schema.json +1211 -0
- package/schemas/settings.schema.json +792 -0
- package/schemas/theme.schema.json +365 -0
|
@@ -0,0 +1,3333 @@
|
|
|
1
|
+
> Pi can create extensions. Ask it to build one for your use case.
|
|
2
|
+
|
|
3
|
+
# Extensions
|
|
4
|
+
|
|
5
|
+
Extensions are TypeScript modules that extend Pi's behavior. They can subscribe to lifecycle events, register custom tools callable by the LLM, add commands, and more.
|
|
6
|
+
|
|
7
|
+
An extension runs inside the Pi process with the same operating-system permissions. It can inspect prompts, tool calls, files, credentials, and session history, so load extensions only from sources you trust.
|
|
8
|
+
|
|
9
|
+
> **Placement for /reload:** Put extensions in `~/.pi/agent/extensions/` (global) or `.pi/extensions/` (project-local) for auto-discovery. Use `pi -e ./path.ts` only for quick tests. Extensions in auto-discovered locations can be hot-reloaded with `/reload`.
|
|
10
|
+
|
|
11
|
+
**Key capabilities:**
|
|
12
|
+
- **Custom tools** - Register tools the LLM can call via `pi.registerTool()`
|
|
13
|
+
- **Event interception** - Block or modify tool calls, inject context, customize compaction
|
|
14
|
+
- **User interaction** - Prompt users via `ctx.ui` (select, confirm, input, notify)
|
|
15
|
+
- **Custom UI components** - Full TUI components with keyboard input via `ctx.ui.custom()` for complex interactions
|
|
16
|
+
- **Custom commands** - Register commands like `/mycommand` via `pi.registerCommand()`
|
|
17
|
+
- **Session persistence** - Store state that survives restarts via `pi.appendEntry()`
|
|
18
|
+
- **Custom rendering** - Control how tool calls/results and messages appear in TUI
|
|
19
|
+
- **Providers and MCP servers** - Register model providers, virtual models, and MCP servers
|
|
20
|
+
|
|
21
|
+
**Example use cases:**
|
|
22
|
+
- Permission gates (confirm before `rm -rf`, `sudo`, etc.)
|
|
23
|
+
- Git checkpointing (stash at each turn, restore on branch)
|
|
24
|
+
- Path protection (block writes to `.env`, `node_modules/`)
|
|
25
|
+
- Custom compaction (summarize conversation your way)
|
|
26
|
+
- Conversation summaries (see `summarize.ts` example)
|
|
27
|
+
- Interactive tools (questions, wizards, custom dialogs)
|
|
28
|
+
- Stateful tools (todo lists, connection pools)
|
|
29
|
+
- External integrations (file watchers, webhooks, CI triggers)
|
|
30
|
+
- Games while you wait (see `snake.ts` example)
|
|
31
|
+
|
|
32
|
+
See [examples/extensions/](../examples/extensions/) for working implementations.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
- [Quick Start](#quick-start)
|
|
37
|
+
- [Extension Locations](#extension-locations)
|
|
38
|
+
- [Available Imports](#available-imports)
|
|
39
|
+
- [Writing an Extension](#writing-an-extension)
|
|
40
|
+
- [Extension Styles](#extension-styles)
|
|
41
|
+
- [Events](#events)
|
|
42
|
+
- [Lifecycle Overview](#lifecycle-overview)
|
|
43
|
+
- [Handler Composition](#handler-composition)
|
|
44
|
+
- [Startup Events](#startup-events)
|
|
45
|
+
- [Resource Events](#resource-events)
|
|
46
|
+
- [Session Events](#session-events)
|
|
47
|
+
- [Agent Events](#agent-events)
|
|
48
|
+
- [Model Events](#model-events)
|
|
49
|
+
- [Tool Events](#tool-events)
|
|
50
|
+
- [User Bash Events](#user-bash-events)
|
|
51
|
+
- [Input Events](#input-events)
|
|
52
|
+
- [ExtensionContext](#extensioncontext)
|
|
53
|
+
- [ExtensionCommandContext](#extensioncommandcontext)
|
|
54
|
+
- [ExtensionAPI Methods](#extensionapi-methods)
|
|
55
|
+
- [State Management](#state-management)
|
|
56
|
+
- [Custom Tools](#custom-tools)
|
|
57
|
+
- [Tool Exposure](#tool-exposure)
|
|
58
|
+
- [Calling Other Tools](#calling-other-tools)
|
|
59
|
+
- [Dynamic Tool Loading](#dynamic-tool-loading)
|
|
60
|
+
- [MCP Servers](#mcp-servers)
|
|
61
|
+
- [Custom UI](#custom-ui)
|
|
62
|
+
- [Error Handling](#error-handling)
|
|
63
|
+
- [Mode Behavior](#mode-behavior)
|
|
64
|
+
- [Examples Reference](#examples-reference)
|
|
65
|
+
|
|
66
|
+
<a id="create-an-extension"></a>
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
Create `~/.pi/agent/extensions/my-extension.ts`:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { type ExtensionAPI, isToolCallEventType } from "@earendil-works/pi-coding-agent";
|
|
74
|
+
import { Type } from "typebox";
|
|
75
|
+
|
|
76
|
+
export default function (pi: ExtensionAPI) {
|
|
77
|
+
// React to events
|
|
78
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
79
|
+
ctx.ui.notify("Extension loaded!", "info");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
83
|
+
if (isToolCallEventType("bash", event) && event.input.command.includes("rm -rf")) {
|
|
84
|
+
const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
|
|
85
|
+
if (!ok) return { block: true, reason: "Blocked by user" };
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Register a custom tool
|
|
90
|
+
pi.registerTool({
|
|
91
|
+
name: "greet",
|
|
92
|
+
label: "Greet",
|
|
93
|
+
description: "Greet someone by name",
|
|
94
|
+
parameters: Type.Object({
|
|
95
|
+
name: Type.String({ description: "Name to greet" }),
|
|
96
|
+
}),
|
|
97
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
98
|
+
return {
|
|
99
|
+
content: [{ type: "text", text: `Hello, ${params.name}!` }],
|
|
100
|
+
details: {},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Register a command
|
|
106
|
+
pi.registerCommand("hello", {
|
|
107
|
+
description: "Say hello",
|
|
108
|
+
handler: async (args, ctx) => {
|
|
109
|
+
ctx.ui.notify(`Hello ${args || "world"}!`, "info");
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Test with `--extension` (or `-e`) flag:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pi -e ./my-extension.ts
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
<a id="choose-where-it-loads"></a>
|
|
122
|
+
|
|
123
|
+
## Extension Locations
|
|
124
|
+
|
|
125
|
+
> **Security:** Extensions run with your full system permissions and can execute arbitrary code. Only install from sources you trust.
|
|
126
|
+
|
|
127
|
+
Extensions are auto-discovered from trusted locations. Project-local `.pi/extensions` entries load only after the project is trusted.
|
|
128
|
+
|
|
129
|
+
| Location | Scope |
|
|
130
|
+
|----------|-------|
|
|
131
|
+
| `~/.pi/agent/extensions/*.ts` or `*.js` | Global (all projects) |
|
|
132
|
+
| `~/.pi/agent/extensions/*/index.ts` or `index.js` | Global (subdirectory) |
|
|
133
|
+
| `~/.pi/agent/extensions/*/package.json` with a `pi.extensions` field | Global (subdirectory with manifest) |
|
|
134
|
+
| `.pi/extensions/...` | Project-local, same layouts |
|
|
135
|
+
|
|
136
|
+
Discovery goes one level deep. Larger packages declare their entry points in a `package.json` manifest.
|
|
137
|
+
|
|
138
|
+
Additional paths via `settings.json`:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"packages": [
|
|
143
|
+
"npm:@foo/bar@1.0.0",
|
|
144
|
+
"git:github.com/user/repo@v1"
|
|
145
|
+
],
|
|
146
|
+
"extensions": [
|
|
147
|
+
"/path/to/local/extension.ts",
|
|
148
|
+
"/path/to/local/extension/dir"
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Settings also accept built-in extensions as `builtin:<name>` entries; see [Settings](settings.md#resources). To share extensions via npm or git as Pi packages, see [packages.md](packages.md).
|
|
154
|
+
|
|
155
|
+
## Available Imports
|
|
156
|
+
|
|
157
|
+
| Package | Purpose |
|
|
158
|
+
|---------|---------|
|
|
159
|
+
| `@earendil-works/pi-coding-agent` | Extension types (`ExtensionAPI`, `ExtensionContext`, events) and helpers |
|
|
160
|
+
| `@earendil-works/pi-agent-core` | Agent message and tool types |
|
|
161
|
+
| `typebox`, `typebox/compile`, `typebox/value` | Schema definitions for tool parameters |
|
|
162
|
+
| `@earendil-works/pi-ai` | AI utilities (`StringEnum` for string enums, transcript helpers, model types) |
|
|
163
|
+
| `@earendil-works/pi-ai/compat`, `/models`, `/oauth`, `/providers/all` | Provider construction, built-in APIs, and OAuth helpers |
|
|
164
|
+
| `@earendil-works/pi-tui` | TUI components for custom rendering |
|
|
165
|
+
|
|
166
|
+
Pi maps these imports to its own copies, so extensions share Pi's classes and registries. The legacy `@mariozechner/*` and `@sinclair/typebox` names map to the same modules.
|
|
167
|
+
|
|
168
|
+
npm dependencies work too. Add a `package.json` next to your extension (or in a parent directory), run `npm install`, and imports from `node_modules/` are resolved automatically.
|
|
169
|
+
|
|
170
|
+
For distributed Pi packages installed with `pi install` (npm or git), runtime deps must be in `dependencies`; `devDependencies` are not installed. Do not list the host-provided packages above in `dependencies`. See [Declare dependencies](packages.md#declare-dependencies).
|
|
171
|
+
|
|
172
|
+
Node.js built-ins (`node:fs`, `node:path`, etc.) are also available.
|
|
173
|
+
|
|
174
|
+
## Writing an Extension
|
|
175
|
+
|
|
176
|
+
An extension exports a default factory function that receives `ExtensionAPI`. The factory can be synchronous or asynchronous:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
180
|
+
|
|
181
|
+
export default function (pi: ExtensionAPI) {
|
|
182
|
+
// Subscribe to events
|
|
183
|
+
pi.on("event_name", async (event, ctx) => {
|
|
184
|
+
// ctx.ui for user interaction
|
|
185
|
+
const ok = await ctx.ui.confirm("Title", "Are you sure?");
|
|
186
|
+
ctx.ui.notify("Done!", "info");
|
|
187
|
+
ctx.ui.setStatus("my-ext", "Processing..."); // Footer status
|
|
188
|
+
ctx.ui.setWidget("my-ext", ["Line 1", "Line 2"]); // Widget above editor (default)
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Register tools, commands, shortcuts, flags
|
|
192
|
+
pi.registerTool({ ... });
|
|
193
|
+
pi.registerCommand("name", { ... });
|
|
194
|
+
pi.registerShortcut("ctrl+x", { ... });
|
|
195
|
+
pi.registerFlag("my-flag", { ... });
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Extensions are loaded via [jiti](https://github.com/unjs/jiti), so TypeScript works without compilation.
|
|
200
|
+
|
|
201
|
+
If the factory returns a `Promise`, Pi awaits it before continuing startup. That means async initialization completes before `session_start`, before `resources_discover`, and before provider registrations queued via `pi.registerProvider()` are flushed.
|
|
202
|
+
|
|
203
|
+
### Async factory functions
|
|
204
|
+
|
|
205
|
+
Use an async factory for one-time startup work such as fetching remote configuration or dynamically discovering available models.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
209
|
+
|
|
210
|
+
export default async function (pi: ExtensionAPI) {
|
|
211
|
+
const response = await fetch("http://localhost:1234/v1/models");
|
|
212
|
+
const payload = (await response.json()) as {
|
|
213
|
+
data: Array<{
|
|
214
|
+
id: string;
|
|
215
|
+
name?: string;
|
|
216
|
+
context_window?: number;
|
|
217
|
+
max_tokens?: number;
|
|
218
|
+
}>;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
pi.registerProvider("local-openai", {
|
|
222
|
+
baseUrl: "http://localhost:1234/v1",
|
|
223
|
+
apiKey: "$LOCAL_OPENAI_API_KEY",
|
|
224
|
+
api: "openai-completions",
|
|
225
|
+
models: payload.data.map((model) => ({
|
|
226
|
+
id: model.id,
|
|
227
|
+
name: model.name ?? model.id,
|
|
228
|
+
reasoning: false,
|
|
229
|
+
input: ["text"],
|
|
230
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
231
|
+
contextWindow: model.context_window ?? 128000,
|
|
232
|
+
maxTokens: model.max_tokens ?? 4096,
|
|
233
|
+
})),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
This pattern makes the fetched models available during normal startup and to `pi --list-models`. For model lists that change while Pi runs, implement `refreshModels` instead; see [pi.registerProvider()](#piregisterprovidername-config).
|
|
239
|
+
|
|
240
|
+
### Long-lived resources and shutdown
|
|
241
|
+
|
|
242
|
+
Extension factories may run in invocations that never start a session. Do not start background resources such as processes, sockets, file watchers, or timers from the factory.
|
|
243
|
+
|
|
244
|
+
Defer background resource startup until `session_start` or the command/tool/event that needs the resource. Register an idempotent `session_shutdown` handler to close any session-scoped resources you start.
|
|
245
|
+
|
|
246
|
+
### Extension Styles
|
|
247
|
+
|
|
248
|
+
**Single file** - simplest, for small extensions:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
~/.pi/agent/extensions/
|
|
252
|
+
└── my-extension.ts
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Directory with index.ts** - for multi-file extensions:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
~/.pi/agent/extensions/
|
|
259
|
+
└── my-extension/
|
|
260
|
+
├── index.ts # Entry point (exports default function)
|
|
261
|
+
├── tools.ts # Helper module
|
|
262
|
+
└── utils.ts # Helper module
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Package with dependencies** - for extensions that need npm packages:
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
~/.pi/agent/extensions/
|
|
269
|
+
└── my-extension/
|
|
270
|
+
├── package.json # Declares dependencies and entry points
|
|
271
|
+
├── package-lock.json
|
|
272
|
+
├── node_modules/ # After npm install
|
|
273
|
+
└── src/
|
|
274
|
+
└── index.ts
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
// package.json
|
|
279
|
+
{
|
|
280
|
+
"name": "my-extension",
|
|
281
|
+
"dependencies": {
|
|
282
|
+
"zod": "^3.0.0",
|
|
283
|
+
"chalk": "^5.0.0"
|
|
284
|
+
},
|
|
285
|
+
"pi": {
|
|
286
|
+
"extensions": ["./src/index.ts"]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Run `npm install` in the extension directory, then imports from `node_modules/` work automatically.
|
|
292
|
+
|
|
293
|
+
<a id="extension-events"></a>
|
|
294
|
+
|
|
295
|
+
## Events
|
|
296
|
+
|
|
297
|
+
<a id="understand-the-lifecycle"></a>
|
|
298
|
+
|
|
299
|
+
### Lifecycle Overview
|
|
300
|
+
|
|
301
|
+
A prompt starts a run. Input handling comes first:
|
|
302
|
+
|
|
303
|
+
1. Extension commands (`/name`) run their handler. The `input` event does not fire. Typed and RPC prompts always check for commands; `pi.sendUserMessage()` checks only with `expandPromptTemplates: true`.
|
|
304
|
+
2. `input` handlers can intercept, transform, or handle the text.
|
|
305
|
+
3. Skill commands (`/skill:name`) and prompt templates (`/template`) expand.
|
|
306
|
+
4. `before_agent_start` runs, then the agent loop starts.
|
|
307
|
+
|
|
308
|
+
The run repeats turns, then checks whether more work starts another low-level agent run:
|
|
309
|
+
|
|
310
|
+
```mermaid
|
|
311
|
+
flowchart TD
|
|
312
|
+
Input["input"] --> Before["before_agent_start"]
|
|
313
|
+
Before --> AgentStart["agent_start"]
|
|
314
|
+
AgentStart --> Turns[["turns"]]
|
|
315
|
+
Turns --> AgentEnd["agent_end"]
|
|
316
|
+
AgentEnd --> MoreRuns{"More work?"}
|
|
317
|
+
MoreRuns -->|yes| AgentStart
|
|
318
|
+
MoreRuns -->|no| BeforeSettle["agent_before_settle"]
|
|
319
|
+
BeforeSettle --> Continue{"Continuation requested?"}
|
|
320
|
+
Continue -->|yes| AgentStart
|
|
321
|
+
Continue -->|no| Settled["agent_settled"]
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
More work means a retry, final-attempt recovery, a compaction retry, or queued messages. `agent_end` is therefore not a final-idle signal; use `agent_settled` for that. An aborted run skips `agent_before_settle` and goes from `agent_end` to `agent_settled`. Pi counts as busy while a run starts, including the compaction check and `before_agent_start`, so messages sent meanwhile go into the starting run.
|
|
325
|
+
|
|
326
|
+
Each turn sends one model request and executes the tool calls in the assistant response:
|
|
327
|
+
|
|
328
|
+
```mermaid
|
|
329
|
+
flowchart TD
|
|
330
|
+
TurnStart["turn_start"] --> Request[["model request"]]
|
|
331
|
+
Request --> ToolDecision{"Tool calls?"}
|
|
332
|
+
ToolDecision -->|yes| Tools[["tool execution"]]
|
|
333
|
+
Tools --> TurnEnd["turn_end"]
|
|
334
|
+
ToolDecision -->|no| TurnEnd
|
|
335
|
+
TurnEnd --> MoreTurns{"Another turn?"}
|
|
336
|
+
MoreTurns -->|yes| TurnStart
|
|
337
|
+
MoreTurns -->|no| AgentEnd(["agent_end"])
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The model request runs these hooks in order:
|
|
341
|
+
|
|
342
|
+
1. `context` (can modify conversation messages)
|
|
343
|
+
2. `context_with_system` (can modify the full transcript)
|
|
344
|
+
3. `before_provider_headers` (can mutate headers)
|
|
345
|
+
4. `before_provider_request` (can inspect or replace the payload)
|
|
346
|
+
5. `after_provider_response` (status and headers, before the stream is consumed)
|
|
347
|
+
6. `provider_stream_event` (raw parsed stream events) and `message_start` / `message_update` / `message_end` for the assistant message
|
|
348
|
+
|
|
349
|
+
A tool call that executes runs these hooks in order:
|
|
350
|
+
|
|
351
|
+
1. `tool_execution_start`
|
|
352
|
+
2. `tool_call` (can block or mutate input)
|
|
353
|
+
3. `tool_execution_update` while the tool executes
|
|
354
|
+
4. `tool_result` (can modify the result)
|
|
355
|
+
5. `tool_execution_end`
|
|
356
|
+
|
|
357
|
+
Calls that do not execute end early. An unknown tool or invalid arguments skip `tool_call`; a blocked or aborted call skips execution and `tool_result`. Each of these still gets `tool_execution_end` with an error result, so use `tool_execution_end` to observe every finalized call.
|
|
358
|
+
|
|
359
|
+
`turn_end` can append entries and request a continuation. Threshold compaction runs before a naturally required next turn. Message events also fire for other messages, such as user, tool-result, and custom messages. Provider hooks run only when the transport exposes the corresponding stage.
|
|
360
|
+
|
|
361
|
+
Session startup and replacement follow a separate lifecycle:
|
|
362
|
+
|
|
363
|
+
```mermaid
|
|
364
|
+
flowchart TD
|
|
365
|
+
Startup["Process startup"] --> Trust["project_trust when needed"]
|
|
366
|
+
Trust --> SessionStart["session_start"]
|
|
367
|
+
Switch["/new or /resume"] --> BeforeSwitch["session_before_switch"]
|
|
368
|
+
Fork["/fork or /clone"] --> BeforeFork["session_before_fork"]
|
|
369
|
+
BeforeSwitch --> Shutdown["session_shutdown"]
|
|
370
|
+
BeforeFork --> Shutdown
|
|
371
|
+
Reload["/reload"] --> Shutdown
|
|
372
|
+
Exit["exit"] --> Shutdown
|
|
373
|
+
Shutdown --> Replacing{"Replacing the runtime?"}
|
|
374
|
+
Replacing -->|yes| ReplacementTrust["project_trust when the working directory is new"]
|
|
375
|
+
ReplacementTrust --> Replacement["load replacement extension runtime"]
|
|
376
|
+
Replacement --> SessionStart
|
|
377
|
+
Replacing -->|no| Stop["process exits"]
|
|
378
|
+
SessionStart --> Discover["resources_discover"]
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
`session_start` carries `reason: "startup" | "reload" | "new" | "resume" | "fork"`, and `session_shutdown` carries `reason: "quit" | "reload" | "new" | "resume" | "fork"`. `resources_discover` uses `reason: "reload"` after a reload and `"startup"` otherwise. Exit covers Ctrl+C, Ctrl+D, SIGHUP, and SIGTERM. `project_trust` runs before trusted project resources load and can run again when session replacement enters a new working directory.
|
|
382
|
+
|
|
383
|
+
Other operations change the current session without replacing the runtime:
|
|
384
|
+
|
|
385
|
+
| Operation | Events |
|
|
386
|
+
|---|---|
|
|
387
|
+
| `/compact` or automatic compaction | `session_before_compact` (can cancel or customize), then `session_compact` or `session_compact_failed` |
|
|
388
|
+
| `/tree` navigation | `session_before_tree` (can cancel or customize), then `session_tree` |
|
|
389
|
+
| `/name` or `pi.setSessionName()` | `session_info_changed` |
|
|
390
|
+
| `/model` or model cycling (`Ctrl+P`) | `thinking_level_select` if the level changes or is clamped, then `model_select` |
|
|
391
|
+
| Thinking-level change (settings, keybinding, `pi.setThinkingLevel()`) | `thinking_level_select` |
|
|
392
|
+
| `!` or `!!` command | `user_bash` (can intercept) |
|
|
393
|
+
| Extension dialog or custom screen waits for the user | `ui_prompt_start`, `ui_prompt_end` |
|
|
394
|
+
| Idle prompt-cache refresh | `cache_warming_decision` |
|
|
395
|
+
| Extension registers or removes an MCP server after startup | `mcp_servers_change` |
|
|
396
|
+
|
|
397
|
+
<a id="events-and-concurrency"></a>
|
|
398
|
+
<a id="work-with-events"></a>
|
|
399
|
+
|
|
400
|
+
### Handler Composition
|
|
401
|
+
|
|
402
|
+
Handlers run in extension load order, then registration order. Some events notify; others transform data, replace results, or cancel an operation:
|
|
403
|
+
|
|
404
|
+
| Pattern | Behavior |
|
|
405
|
+
|---|---|
|
|
406
|
+
| Notification | Return values are ignored. Use the event for observation only. |
|
|
407
|
+
| In-place mutation | Later handlers see changes to values such as `before_provider_headers.headers`, `before_agent_start.systemPromptOptions`, and `tool_call.input`. |
|
|
408
|
+
| Chained transformation | Later handlers receive the value returned by earlier `input`, `context`, `context_with_system`, `message_end`, `tool_result`, and `before_provider_request` handlers. |
|
|
409
|
+
| Gate | A handled input, blocked tool call, cancelled session operation, or handled `user_bash` command stops that operation's normal fallback path. |
|
|
410
|
+
| Actionable boundary | Each `turn_end` or `agent_before_settle` handler sees the entries and continuation decision proposed so far. |
|
|
411
|
+
| Last override | The last `cache_warming_decision` handler that returns an action wins. |
|
|
412
|
+
|
|
413
|
+
Notification handlers should not perform slow work on a streaming event. Transform handlers should preserve fields they do not intentionally own, and gate handlers should fail closed when their safety decision cannot be made.
|
|
414
|
+
|
|
415
|
+
### Startup Events
|
|
416
|
+
|
|
417
|
+
#### project_trust
|
|
418
|
+
|
|
419
|
+
Fired before Pi decides whether to trust a project with dynamic configs (`.pi` or `.agents/skills`). It runs during startup and when session replacement (for example `/resume`) enters a cwd whose trust has not been resolved in the current process. Only user/global extensions and CLI `-e` extensions participate; project-local extensions are not loaded until after trust is resolved.
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
pi.on("project_trust", async (event, ctx) => {
|
|
423
|
+
// event.cwd - current working directory
|
|
424
|
+
// ctx has a limited trust context: cwd, mode, hasUI, and select/confirm/input/notify UI helpers
|
|
425
|
+
if (await ctx.ui.confirm("Trust project?", event.cwd)) {
|
|
426
|
+
return { trusted: "yes", remember: true };
|
|
427
|
+
}
|
|
428
|
+
return { trusted: "undecided" };
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
A `project_trust` handler must return `{ trusted: "yes" | "no" | "undecided" }`. A user/global or CLI extension that returns `"yes"` or `"no"` owns the decision; the first yes/no decision wins and suppresses the built-in trust prompt. Use `remember: true` to persist a yes/no decision; otherwise it applies only to the current process. Return `"undecided"` to let later handlers or the built-in trust flow decide. Check `ctx.hasUI` before prompting. If no handler returns yes/no, normal trust resolution continues: saved `trust.json` decisions apply first, then `defaultProjectTrust` controls whether Pi asks, trusts, or declines by default.
|
|
433
|
+
|
|
434
|
+
### Resource Events
|
|
435
|
+
|
|
436
|
+
#### resources_discover
|
|
437
|
+
|
|
438
|
+
Fired after `session_start` so extensions can contribute additional skill, prompt, and theme paths.
|
|
439
|
+
The startup path uses `reason: "startup"`. Reload uses `reason: "reload"`.
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
pi.on("resources_discover", async (event, _ctx) => {
|
|
443
|
+
// event.cwd - current working directory
|
|
444
|
+
// event.reason - "startup" | "reload"
|
|
445
|
+
return {
|
|
446
|
+
skillPaths: ["/path/to/skills"],
|
|
447
|
+
promptPaths: ["/path/to/prompts"],
|
|
448
|
+
themePaths: ["/path/to/themes"],
|
|
449
|
+
};
|
|
450
|
+
});
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### mcp_servers_change
|
|
454
|
+
|
|
455
|
+
Fired when an extension registers or unregisters an MCP server after extensions are bound. `event.servers` lists every registered server after the change. Handling this event marks the extension as the one that connects registered servers; see [MCP Servers](#mcp-servers).
|
|
456
|
+
|
|
457
|
+
### Session Events
|
|
458
|
+
|
|
459
|
+
See [Session Format](session-format.md) for session storage internals and the SessionManager API.
|
|
460
|
+
|
|
461
|
+
#### session_start
|
|
462
|
+
|
|
463
|
+
Fired when a session is started, loaded, or reloaded.
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
pi.on("session_start", async (event, ctx) => {
|
|
467
|
+
// event.reason - "startup" | "reload" | "new" | "resume" | "fork"
|
|
468
|
+
// event.previousSessionFile - present for "new", "resume", and "fork"
|
|
469
|
+
ctx.ui.notify(`Session: ${ctx.sessionManager.getSessionFile() ?? "ephemeral"}`, "info");
|
|
470
|
+
});
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### session_info_changed
|
|
474
|
+
|
|
475
|
+
Fired when the current session display name is set via `/name`, RPC, or `pi.setSessionName()`.
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
pi.on("session_info_changed", async (event, ctx) => {
|
|
479
|
+
// event.name - current normalized name, or undefined if cleared
|
|
480
|
+
ctx.ui.notify(`Session renamed: ${event.name ?? "(none)"}`, "info");
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
#### session_before_switch
|
|
485
|
+
|
|
486
|
+
Fired before starting a new session (`/new`) or switching sessions (`/resume`).
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
pi.on("session_before_switch", async (event, ctx) => {
|
|
490
|
+
// event.reason - "new" or "resume"
|
|
491
|
+
// event.targetSessionFile - session we're switching to (only for "resume")
|
|
492
|
+
|
|
493
|
+
if (event.reason === "new") {
|
|
494
|
+
const ok = await ctx.ui.confirm("Clear?", "Delete all messages?");
|
|
495
|
+
if (!ok) return { cancel: true };
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
After a successful switch or new-session action, Pi emits `session_shutdown` for the old extension instance, reloads and rebinds extensions for the new session, then emits `session_start` with `reason: "new" | "resume"` and `previousSessionFile`.
|
|
501
|
+
Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
|
|
502
|
+
|
|
503
|
+
#### session_before_fork
|
|
504
|
+
|
|
505
|
+
Fired when forking via `/fork` or cloning via `/clone`.
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
pi.on("session_before_fork", async (event, ctx) => {
|
|
509
|
+
// event.entryId - ID of the selected entry
|
|
510
|
+
// event.position - "before" for /fork, "at" for /clone
|
|
511
|
+
return { cancel: true }; // Cancel fork/clone
|
|
512
|
+
// OR
|
|
513
|
+
return { skipConversationRestore: true }; // Reserved for future conversation restore control
|
|
514
|
+
});
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
After a successful fork or clone, Pi emits `session_shutdown` for the old extension instance, reloads and rebinds extensions for the new session, then emits `session_start` with `reason: "fork"` and `previousSessionFile`.
|
|
518
|
+
Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `session_start`.
|
|
519
|
+
|
|
520
|
+
<a id="session_before_compact--session_compact"></a>
|
|
521
|
+
|
|
522
|
+
#### session_before_compact / session_compact / session_compact_failed
|
|
523
|
+
|
|
524
|
+
Fired on compaction. See [compaction.md](compaction.md) for details.
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
pi.on("session_before_compact", async (event, ctx) => {
|
|
528
|
+
const { preparation, branchEntries, customInstructions, reason, willRetry, signal } = event;
|
|
529
|
+
|
|
530
|
+
// reason - "manual" (/compact), "threshold", or "overflow"
|
|
531
|
+
// willRetry - whether the aborted turn is retried after compaction (overflow recovery)
|
|
532
|
+
|
|
533
|
+
// Cancel:
|
|
534
|
+
return { cancel: true };
|
|
535
|
+
|
|
536
|
+
// Custom summary:
|
|
537
|
+
return {
|
|
538
|
+
compaction: {
|
|
539
|
+
summary: "...",
|
|
540
|
+
firstKeptEntryId: preparation.firstKeptEntryId,
|
|
541
|
+
tokensBefore: preparation.tokensBefore,
|
|
542
|
+
// usage: summaryResponse.usage, // Optional; included in session totals
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
pi.on("session_compact", async (event, ctx) => {
|
|
548
|
+
// event.compactionEntry - the saved compaction
|
|
549
|
+
// event.fromExtension - whether extension provided it
|
|
550
|
+
// event.reason - "manual" (/compact), "threshold", or "overflow"
|
|
551
|
+
// event.willRetry - whether the aborted turn is retried after compaction (overflow recovery)
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
pi.on("session_compact_failed", async (event, ctx) => {
|
|
555
|
+
// event.reason - "manual" (/compact), "threshold", or "overflow"
|
|
556
|
+
// event.errorMessage - present for non-abort failures
|
|
557
|
+
// event.aborted - true for cancelled/aborted compactions
|
|
558
|
+
// event.willRetry - whether the aborted turn would have retried after compaction
|
|
559
|
+
// event.fromExtension - whether extension-provided compaction content was being used
|
|
560
|
+
});
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
#### session_before_tree / session_tree
|
|
564
|
+
|
|
565
|
+
Fired on `/tree` navigation. See [Sessions](sessions.md) for tree navigation concepts.
|
|
566
|
+
|
|
567
|
+
```typescript
|
|
568
|
+
pi.on("session_before_tree", async (event, ctx) => {
|
|
569
|
+
const { preparation, signal } = event;
|
|
570
|
+
// preparation.targetId, oldLeafId, commonAncestorId, entriesToSummarize,
|
|
571
|
+
// userWantsSummary, customInstructions, replaceInstructions, label
|
|
572
|
+
return { cancel: true };
|
|
573
|
+
// OR provide custom summary (used only when preparation.userWantsSummary is true):
|
|
574
|
+
return {
|
|
575
|
+
summary: {
|
|
576
|
+
summary: "...",
|
|
577
|
+
// usage: summaryResponse.usage, // Optional; included in session totals
|
|
578
|
+
details: {},
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
// OR override summarization options: customInstructions, replaceInstructions, label
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
pi.on("session_tree", async (event, ctx) => {
|
|
585
|
+
// event.newLeafId, oldLeafId, summaryEntry, fromExtension
|
|
586
|
+
});
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
#### session_shutdown
|
|
590
|
+
|
|
591
|
+
Fired before a started session runtime is torn down. Use this to clean up resources opened from `session_start` or other session-scoped hooks.
|
|
592
|
+
|
|
593
|
+
```typescript
|
|
594
|
+
pi.on("session_shutdown", async (event, ctx) => {
|
|
595
|
+
// event.reason - "quit" | "reload" | "new" | "resume" | "fork"
|
|
596
|
+
// event.targetSessionFile - destination session for session replacement flows
|
|
597
|
+
// Cleanup, save state, etc.
|
|
598
|
+
});
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### Agent Events
|
|
602
|
+
|
|
603
|
+
#### before_agent_start
|
|
604
|
+
|
|
605
|
+
Fired before a run starts, after input handling and expansion. Can inject a message and/or modify the system prompt.
|
|
606
|
+
|
|
607
|
+
`event.messageType` says what started the run: `"user"` for a prompt or `pi.sendUserMessage()`, with `prompt` and `images`; `"custom"` for `pi.sendMessage(..., { triggerTurn: true })` while idle, with the starting `message` and no `prompt`.
|
|
608
|
+
|
|
609
|
+
```typescript
|
|
610
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
611
|
+
// event.messageType - "user" | "custom"
|
|
612
|
+
// event.prompt, event.images - user's prompt text and images (messageType "user")
|
|
613
|
+
// event.message - the custom message that starts the run (messageType "custom")
|
|
614
|
+
// event.systemPrompt - current chained system prompt for this handler
|
|
615
|
+
// (includes changes from earlier before_agent_start handlers)
|
|
616
|
+
// event.systemPromptOptions - structured options used to build the system prompt
|
|
617
|
+
// .customPrompt - exact prompt prefix from --system-prompt, SYSTEM.md, or custom templates
|
|
618
|
+
// .forceSystemPrompt - optional exact replacement for the complete prompt
|
|
619
|
+
// .selectedTools - tools currently active in the prompt
|
|
620
|
+
// .hiddenTools - selected tools whose declarations requests leave out
|
|
621
|
+
// .toolSnippets - one-line descriptions for each tool
|
|
622
|
+
// .toolGuidelines - rule bullets keyed by tool name
|
|
623
|
+
// .promptGuidelines - additional custom rule bullets
|
|
624
|
+
// .sections - custom XML-wrapped sections keyed by tag name
|
|
625
|
+
// .appendSystemPrompt - text from --append-system-prompt flags
|
|
626
|
+
// .cwd - working directory
|
|
627
|
+
// .contextFiles - AGENTS.md files and other loaded context files
|
|
628
|
+
// .skills - loaded skills
|
|
629
|
+
|
|
630
|
+
return {
|
|
631
|
+
// Inject a persistent message (stored in session, sent to LLM)
|
|
632
|
+
message: {
|
|
633
|
+
customType: "my-extension",
|
|
634
|
+
content: "Additional context for the LLM",
|
|
635
|
+
display: true,
|
|
636
|
+
},
|
|
637
|
+
// Replace the system prompt for this turn (chained across extensions)
|
|
638
|
+
systemPrompt: event.systemPrompt + "\n\nExtra instructions for this turn...",
|
|
639
|
+
};
|
|
640
|
+
});
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
A returned `message` is added to either kind of run; check `messageType` to skip runs started by custom messages.
|
|
644
|
+
|
|
645
|
+
The `systemPromptOptions` field gives extensions access to the same structured data Pi uses to build the system prompt. Collections are mutable. Prefer changing `sections`, `selectedTools`, or `promptGuidelines`: Pi diffs the resulting prompt sections against what the model already has and appends one system message patching only the changed sections. Returning `systemPrompt`, or setting `forceSystemPrompt`, replaces the whole prompt for the run: every provider receives the forced text as its leading system prompt (a cache miss when it changes), and the session transcript keeps recording the structured sections. Tool selection changes update both the prompt contributions and executable provider tools; calling `pi.setActiveTools()` inside the handler has the same effect as editing `selectedTools`. Models that accept system messages mid-conversation receive the patch in place and keep their cached prefix; other models get the replayed prompt as their system prompt, which is a cache miss once per change.
|
|
646
|
+
|
|
647
|
+
Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
|
|
648
|
+
|
|
649
|
+
<a id="agent_start--agent_end--agent_settled"></a>
|
|
650
|
+
|
|
651
|
+
#### agent_start / agent_end / agent_before_settle / agent_settled
|
|
652
|
+
|
|
653
|
+
`agent_start` fires when a low-level agent run begins. `agent_end` fires when that run ends, but Pi may still auto-retry, auto-compact and retry, or continue with queued follow-up messages. `agent_before_settle` is the final actionable boundary: it can append session entries and request one continuation. `agent_settled` is final and notification-only; use it for status integrations that need to know Pi will not continue running automatically.
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
pi.on("agent_start", async (_event, ctx) => {});
|
|
657
|
+
|
|
658
|
+
pi.on("agent_end", async (event, ctx) => {
|
|
659
|
+
// event.messages - messages from this low-level run
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
let addedReviewReminder = false;
|
|
663
|
+
pi.on("agent_before_settle", async (event, ctx) => {
|
|
664
|
+
if (addedReviewReminder) return;
|
|
665
|
+
addedReviewReminder = true;
|
|
666
|
+
return {
|
|
667
|
+
entries: [...event.entries, {
|
|
668
|
+
type: "custom_message",
|
|
669
|
+
customType: "review-reminder",
|
|
670
|
+
content: "Review the final diff before replying.",
|
|
671
|
+
display: false,
|
|
672
|
+
}],
|
|
673
|
+
continue: true,
|
|
674
|
+
};
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
pi.on("agent_settled", async (event, ctx) => {
|
|
678
|
+
// event.aborted - true when the run ended because it was aborted, for example with Escape
|
|
679
|
+
// ctx.isIdle() is true; runs requested here start after all settled handlers finish.
|
|
680
|
+
});
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
If the run is aborted while `agent_before_settle` handlers are running, valid returned entries are still committed, but requested continuation is suppressed. Work requested from `agent_settled` is deferred until every settled handler completes, so notification dispatch is non-reentrant.
|
|
684
|
+
|
|
685
|
+
#### ui_prompt_start / ui_prompt_end
|
|
686
|
+
|
|
687
|
+
Notification-only lifecycle events for blocking user-facing extension UI prompts. They fire around `ctx.ui.select()`, `ctx.ui.confirm()`, `ctx.ui.input()`, `ctx.ui.editor()`, and `ctx.ui.custom()` so host/status integrations can report "waiting for user" instead of just "running".
|
|
688
|
+
|
|
689
|
+
Nested or overlapping prompts are coalesced into one outer waiting span. Handlers are invoked best-effort and are not awaited before showing or closing the prompt.
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
pi.on("ui_prompt_start", async (event, ctx) => {
|
|
693
|
+
// event.reason === "ui_prompt"
|
|
694
|
+
// event.kind: "select" | "confirm" | "input" | "editor" | "custom"
|
|
695
|
+
// event.title: prompt title when available
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
pi.on("ui_prompt_end", async (event, ctx) => {
|
|
699
|
+
// Pi is no longer waiting on that UI prompt span.
|
|
700
|
+
});
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
#### turn_start / turn_end
|
|
704
|
+
|
|
705
|
+
Fired for each turn (one LLM response + tool calls).
|
|
706
|
+
|
|
707
|
+
```typescript
|
|
708
|
+
pi.on("turn_start", async (event, ctx) => {
|
|
709
|
+
// event.turnIndex, event.timestamp
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
let replacedResponse = false;
|
|
713
|
+
pi.on("turn_end", async (event, ctx) => {
|
|
714
|
+
// event.turnIndex, event.message, event.toolResults
|
|
715
|
+
// event.entries contains the structural entries proposed so far.
|
|
716
|
+
if (replacedResponse || event.outcome !== "completed" || event.toolResults.length > 0) return;
|
|
717
|
+
replacedResponse = true;
|
|
718
|
+
return {
|
|
719
|
+
entries: [
|
|
720
|
+
...event.entries,
|
|
721
|
+
{ type: "context_edit", targetId: event.messageEntryId, replacement: null },
|
|
722
|
+
{
|
|
723
|
+
type: "custom_message",
|
|
724
|
+
customType: "replacement-instruction",
|
|
725
|
+
content: "Answer again using the persisted user request.",
|
|
726
|
+
display: false,
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
continue: true,
|
|
730
|
+
};
|
|
731
|
+
});
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
`turn_end` runs after the assistant and tool-result messages have been persisted and before the low-level `turn_end` event. Retry backoff and final-attempt recovery still happen after `agent_end`, preserving their existing lifecycle and queue ordering; `agent_before_settle` sees the repaired projection after that work completes. Boundary handlers run in extension load and registration order. Each handler sees prior proposals in `event.entries` and sees `event.context` rebuilt from them. Returning `entries` or `continue` replaces only that field; omitted fields preserve the current proposal. Allowed draft entry types are `custom`, `custom_message`, `context_edit`, and `compaction`. The complete proposal is validated before it is appended in list order after all handlers finish; a handler error is reported and later handlers still run. Validation prevents partially applied semantic errors, but persistence is not transactional.
|
|
735
|
+
|
|
736
|
+
`continue: true` ensures one next provider request for that boundary invocation. If tool results, steering, or a follow-up already cause that request, they satisfy the decision and no additional request is made; otherwise Pi makes one context-only request. Error and aborted responses remain hard exits. `continue: false` never suppresses natural work. Guard continuation conditions: an unconditional `continue: true` is evaluated again after the next response and can create an endless loop. A `custom_message` draft contributes a user-role model message but is extension-authored: it does not run human input hooks, slash commands, skills, or prompt templates.
|
|
737
|
+
|
|
738
|
+
Host integrations that construct `TurnEndEvent` values must provide `messageEntryId`, `toolResultEntryIds`, `outcome`, `entries`, `continue`, and `context`. `ExtensionEvent` exhaustive switches must also handle `agent_before_settle`. `ExtensionRunner.emit()` excludes actionable turn boundaries; dispatch `turn_end` and `agent_before_settle` through `emitBoundary(baseEvent, buildContext)` so handlers receive chained previews. Other dedicated runner methods still return results for events such as `session_before_*`.
|
|
739
|
+
|
|
740
|
+
#### message_start / message_update / message_end
|
|
741
|
+
|
|
742
|
+
Fired for message lifecycle updates.
|
|
743
|
+
|
|
744
|
+
- `message_start` and `message_end` fire for every message, including user, assistant, tool-result, and custom messages.
|
|
745
|
+
- `message_update` fires for assistant streaming updates.
|
|
746
|
+
- `message_end` handlers can return `{ message }` to replace the finalized message. The replacement must keep the same `role`.
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
pi.on("message_start", async (event, ctx) => {
|
|
750
|
+
// event.message
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
pi.on("message_update", async (event, ctx) => {
|
|
754
|
+
// event.message
|
|
755
|
+
// event.assistantMessageEvent (token-by-token stream event)
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
pi.on("message_end", async (event, ctx) => {
|
|
759
|
+
if (event.message.role !== "assistant") return;
|
|
760
|
+
|
|
761
|
+
return {
|
|
762
|
+
message: {
|
|
763
|
+
...event.message,
|
|
764
|
+
usage: {
|
|
765
|
+
...event.message.usage,
|
|
766
|
+
cost: {
|
|
767
|
+
...event.message.usage.cost,
|
|
768
|
+
total: 0.123,
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
};
|
|
773
|
+
});
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
#### tool_execution_start / tool_execution_update / tool_execution_end
|
|
777
|
+
|
|
778
|
+
Fired for tool execution lifecycle updates.
|
|
779
|
+
|
|
780
|
+
In parallel tool mode:
|
|
781
|
+
- `tool_execution_start` is emitted in assistant source order during the preflight phase
|
|
782
|
+
- `tool_execution_update` events may interleave across tools
|
|
783
|
+
- `tool_execution_end` is emitted in tool completion order after each tool is finalized
|
|
784
|
+
- final `toolResult` message events are still emitted later in assistant source order
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
pi.on("tool_execution_start", async (event, ctx) => {
|
|
788
|
+
// event.toolCallId, event.toolName, event.args
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
pi.on("tool_execution_update", async (event, ctx) => {
|
|
792
|
+
// event.toolCallId, event.toolName, event.args, event.partialResult
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
pi.on("tool_execution_end", async (event, ctx) => {
|
|
796
|
+
// event.toolCallId, event.toolName, event.result, event.isError
|
|
797
|
+
// event.durationMs - milliseconds execute() took; absent when the tool did not run
|
|
798
|
+
});
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
All three events, `tool_call`, and `tool_result` carry `parentToolCallId` when another tool made the call; see [Calling Other Tools](#calling-other-tools).
|
|
802
|
+
|
|
803
|
+
#### context
|
|
804
|
+
|
|
805
|
+
Fired before each LLM call. Modify messages non-destructively. See [Session Format](session-format.md) for message types.
|
|
806
|
+
|
|
807
|
+
```typescript
|
|
808
|
+
pi.on("context", async (event, ctx) => {
|
|
809
|
+
// event.messages - deep copy without system messages, safe to modify
|
|
810
|
+
const filtered = event.messages.filter(m => !shouldPrune(m));
|
|
811
|
+
return { messages: filtered };
|
|
812
|
+
});
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
`event.messages` holds the conversation without system messages. The prompt and tool declarations belong to Pi and are not part of this hook: when the handler returns a changed list, Pi replays the current prompt sections and tool declarations into one leading system message ahead of the returned messages. Filtering, windowing, or slicing from a compaction summary therefore cannot drop the prompt or the tools. An unchanged list keeps mid-conversation system messages in place, so models that accept them retain their cached prefix. System messages a handler adds are kept after Pi's head. To change the prompt or the tool set durably, use [`before_agent_start`](#before_agent_start) or `pi.setActiveTools()`; to edit system messages for one request, use [`context_with_system`](#context_with_system).
|
|
816
|
+
|
|
817
|
+
#### context_with_system
|
|
818
|
+
|
|
819
|
+
Fired before each LLM call, after every `context` handler has run and Pi has restored the prompt and tool state. `event.messages` is the full transcript, including the leading system message and any mid-conversation prompt or tool patches (see [Session Format](session-format.md#sessionmessageentry)). The returned messages are sent as they are: this hook owns the prompt and tool declarations for the request.
|
|
820
|
+
|
|
821
|
+
```typescript
|
|
822
|
+
import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
823
|
+
|
|
824
|
+
pi.on("context_with_system", async (event, ctx) => {
|
|
825
|
+
const cut = findCutIndex(event.messages);
|
|
826
|
+
// Fold the dropped prefix so its prompt and tool state survives as the new head.
|
|
827
|
+
const head = getCurrentSystemMessage(event.messages.slice(0, cut));
|
|
828
|
+
return { messages: head ? [head, ...event.messages.slice(cut)] : event.messages.slice(cut) };
|
|
829
|
+
});
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
Rules: keep a system message at index 0 (providers read the prompt and initial tool declarations there; Pi reports an error if a handler drops it). Removing a system message removes the tool declarations and section patches it carries. Check your output with `getCurrentSystemPrompt()` and `getCurrentTools()` from `@earendil-works/pi-ai`. Handlers run in extension load order; a `systemPrompt` forced from `before_agent_start` is still projected onto the request afterwards.
|
|
833
|
+
|
|
834
|
+
#### before_provider_headers
|
|
835
|
+
|
|
836
|
+
Fired after the outgoing HTTP headers are assembled. Use it to add, override, or remove request headers.
|
|
837
|
+
|
|
838
|
+
Handlers mutate `event.headers` in place. Set a key to a string to add or override it, or to `null` to delete it.
|
|
839
|
+
|
|
840
|
+
```typescript
|
|
841
|
+
pi.on("before_provider_headers", (event, ctx) => {
|
|
842
|
+
// Add or override — e.g. a session id for gateway tracing/attribution
|
|
843
|
+
event.headers["x-session-id"] = ctx.sessionManager.getSessionId();
|
|
844
|
+
|
|
845
|
+
// Drop a tracking header pi adds for this call
|
|
846
|
+
event.headers["X-OpenRouter-Title"] = null;
|
|
847
|
+
});
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
Runs once per provider request; retries reuse the same headers rather than re-firing the hook.
|
|
851
|
+
|
|
852
|
+
#### before_provider_request
|
|
853
|
+
|
|
854
|
+
Fired after the provider-specific payload is built, right before the request is sent. Handlers run in extension load order. Returning `undefined` keeps the payload unchanged. Returning any other value replaces the payload for later handlers and for the actual request.
|
|
855
|
+
|
|
856
|
+
This hook can rewrite provider-level system instructions or remove them entirely. Those payload-level changes are not reflected by `ctx.getSystemPrompt()`, which reports Pi's system prompt string rather than the final serialized provider payload.
|
|
857
|
+
|
|
858
|
+
```typescript
|
|
859
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
860
|
+
console.log(JSON.stringify(event.payload, null, 2));
|
|
861
|
+
|
|
862
|
+
// Optional: replace payload
|
|
863
|
+
// return { ...event.payload, temperature: 0 };
|
|
864
|
+
});
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
This is mainly useful for debugging provider serialization and cache behavior.
|
|
868
|
+
|
|
869
|
+
#### after_provider_response
|
|
870
|
+
|
|
871
|
+
Fired after an HTTP response is received and before its stream body is consumed. Handlers run in extension load order.
|
|
872
|
+
|
|
873
|
+
```typescript
|
|
874
|
+
pi.on("after_provider_response", (event, ctx) => {
|
|
875
|
+
// event.status - HTTP status code
|
|
876
|
+
// event.headers - normalized response headers
|
|
877
|
+
if (event.status === 429) {
|
|
878
|
+
console.log("rate limited", event.headers["retry-after"]);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
Header availability depends on provider and transport. Providers that abstract HTTP responses may not expose headers.
|
|
884
|
+
|
|
885
|
+
#### provider_stream_event
|
|
886
|
+
|
|
887
|
+
Fired for each parsed provider stream event before Pi normalizes it. Notification-only and not persisted.
|
|
888
|
+
|
|
889
|
+
```typescript
|
|
890
|
+
pi.on("provider_stream_event", (event, ctx) => {
|
|
891
|
+
// event.provider, event.api, event.model
|
|
892
|
+
// event.data - earliest structured value available to Pi (read-only)
|
|
893
|
+
});
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
`event.data` is not necessarily the original HTTP bytes or SSE frame. Treat it as read-only because mutation can affect normalization. Handlers are awaited in stream order, so slow handlers delay stream consumption. Handler errors are reported without changing the provider response. See [`debug-provider.ts`](../examples/extensions/debug-provider.ts) for an opt-in viewer that groups raw events by assistant message.
|
|
897
|
+
|
|
898
|
+
#### cache_warming_decision
|
|
899
|
+
|
|
900
|
+
Fired before each prompt-cache refresh with Pi's decision filled in. The event carries only Pi's cost estimates; use `ctx.model`, `ctx.isIdle()`, and `ctx.getContextUsage()` for everything else.
|
|
901
|
+
|
|
902
|
+
```typescript
|
|
903
|
+
pi.on("cache_warming_decision", (event, ctx) => {
|
|
904
|
+
// event.warmCost: price of this refresh
|
|
905
|
+
// event.missCost: extra price of the next request if the entry is lost
|
|
906
|
+
// event.continuationProbability: pi's estimate that a request arrives in time
|
|
907
|
+
// event.action: "warm" | "stop", pi's decision
|
|
908
|
+
|
|
909
|
+
if (ctx.model?.provider === "my-provider") {
|
|
910
|
+
return { action: "stop" };
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
Return `{ action: "warm" }` or `{ action: "stop" }` to override; the last handler that returns an action wins. `"stop"` ends warming until the next real request.
|
|
916
|
+
|
|
917
|
+
### Model Events
|
|
918
|
+
|
|
919
|
+
#### model_select
|
|
920
|
+
|
|
921
|
+
Fired when the model changes via `/model` command, model cycling (`Ctrl+P`), or `pi.setModel()`. Restoring a session does not fire it; read `ctx.model` in `session_start` to initialize model-dependent state.
|
|
922
|
+
|
|
923
|
+
```typescript
|
|
924
|
+
pi.on("model_select", async (event, ctx) => {
|
|
925
|
+
// event.model - newly selected model
|
|
926
|
+
// event.previousModel - previous model (undefined if first selection)
|
|
927
|
+
// event.source - "set" | "cycle"
|
|
928
|
+
|
|
929
|
+
const prev = event.previousModel
|
|
930
|
+
? `${event.previousModel.provider}/${event.previousModel.id}`
|
|
931
|
+
: "none";
|
|
932
|
+
const next = `${event.model.provider}/${event.model.id}`;
|
|
933
|
+
|
|
934
|
+
ctx.ui.notify(`Model changed (${event.source}): ${prev} -> ${next}`, "info");
|
|
935
|
+
});
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
|
|
939
|
+
|
|
940
|
+
#### thinking_level_select
|
|
941
|
+
|
|
942
|
+
Fired when the thinking level changes. This is notification-only; handler return values are ignored.
|
|
943
|
+
|
|
944
|
+
```typescript
|
|
945
|
+
pi.on("thinking_level_select", async (event, ctx) => {
|
|
946
|
+
// event.level - newly selected thinking level
|
|
947
|
+
// event.previousLevel - previous thinking level
|
|
948
|
+
|
|
949
|
+
ctx.ui.setStatus("thinking", `thinking: ${event.level}`);
|
|
950
|
+
});
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
Use this to update extension UI when `pi.setThinkingLevel()`, model changes, or built-in thinking-level controls change the active thinking level.
|
|
954
|
+
|
|
955
|
+
<a id="tool-call-events"></a>
|
|
956
|
+
|
|
957
|
+
### Tool Events
|
|
958
|
+
|
|
959
|
+
#### tool_call
|
|
960
|
+
|
|
961
|
+
Fired after `tool_execution_start`, before the tool executes. **Can block.** Use `isToolCallEventType` to narrow and get typed inputs.
|
|
962
|
+
|
|
963
|
+
Before `tool_call` runs, Pi waits for previously emitted Agent events to finish draining through `AgentSession`. This means `ctx.sessionManager` is up to date through the current assistant tool-calling message.
|
|
964
|
+
|
|
965
|
+
In the default parallel tool execution mode, sibling tool calls from the same assistant message are preflighted sequentially, then executed concurrently. `tool_call` is not guaranteed to see sibling tool results from that same assistant message in `ctx.sessionManager`.
|
|
966
|
+
|
|
967
|
+
`event.input` is mutable. Mutate it in place to patch tool arguments before execution.
|
|
968
|
+
|
|
969
|
+
Behavior guarantees:
|
|
970
|
+
- Mutations to `event.input` affect the actual tool execution
|
|
971
|
+
- Later `tool_call` handlers see mutations made by earlier handlers
|
|
972
|
+
- No re-validation is performed after your mutation
|
|
973
|
+
- Return values from `tool_call` control blocking via `{ block: true, reason?: string, terminate?: boolean }`
|
|
974
|
+
- `terminate` only applies to a blocked call; the agent stops early only when every finalized result in the batch is terminating
|
|
975
|
+
|
|
976
|
+
```typescript
|
|
977
|
+
import { isToolCallEventType } from "@earendil-works/pi-coding-agent";
|
|
978
|
+
|
|
979
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
980
|
+
// event.toolName - "bash", "read", "write", "edit", etc.
|
|
981
|
+
// event.toolCallId
|
|
982
|
+
// event.input - tool parameters (mutable)
|
|
983
|
+
|
|
984
|
+
// Built-in tools: no type params needed
|
|
985
|
+
if (isToolCallEventType("bash", event)) {
|
|
986
|
+
// event.input is { command: string; timeout?: number }
|
|
987
|
+
event.input.command = `source ~/.profile\n${event.input.command}`;
|
|
988
|
+
|
|
989
|
+
if (event.input.command.includes("rm -rf")) {
|
|
990
|
+
return { block: true, reason: "Dangerous command", terminate: true };
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
if (isToolCallEventType("read", event)) {
|
|
995
|
+
// event.input is { path: string; offset?: number; limit?: number }
|
|
996
|
+
console.log(`Reading: ${event.input.path}`);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
```
|
|
1000
|
+
|
|
1001
|
+
#### Typing custom tool input
|
|
1002
|
+
|
|
1003
|
+
Custom tools should export their input type:
|
|
1004
|
+
|
|
1005
|
+
```typescript
|
|
1006
|
+
// my-tool.ts
|
|
1007
|
+
import { type Static, Type } from "typebox";
|
|
1008
|
+
|
|
1009
|
+
export const myToolSchema = Type.Object({ action: Type.String() });
|
|
1010
|
+
export type MyToolInput = Static<typeof myToolSchema>;
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
Use `isToolCallEventType` with explicit type parameters:
|
|
1014
|
+
|
|
1015
|
+
```typescript
|
|
1016
|
+
import { isToolCallEventType } from "@earendil-works/pi-coding-agent";
|
|
1017
|
+
import type { MyToolInput } from "./my-tool.ts";
|
|
1018
|
+
|
|
1019
|
+
pi.on("tool_call", (event) => {
|
|
1020
|
+
if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
|
|
1021
|
+
event.input.action; // typed
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
#### tool_result
|
|
1027
|
+
|
|
1028
|
+
Fired after tool execution finishes and before `tool_execution_end` plus the final tool result message events are emitted. **Can modify result.**
|
|
1029
|
+
|
|
1030
|
+
In parallel tool mode, `tool_result` and `tool_execution_end` may interleave in tool completion order, while final `toolResult` message events are still emitted later in assistant source order.
|
|
1031
|
+
|
|
1032
|
+
`tool_result` handlers chain like middleware:
|
|
1033
|
+
- Handlers run in extension load order
|
|
1034
|
+
- Each handler sees the latest result after previous handler changes
|
|
1035
|
+
- Handlers can return partial patches (`content`, `details`, `structuredContent`, `isError`, or `usage`); omitted fields keep their current values
|
|
1036
|
+
- Replacing `content` without returning `structuredContent` drops the structured content, because it may no longer match
|
|
1037
|
+
|
|
1038
|
+
Use `ctx.signal` for nested async work inside the handler. This lets Esc cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
|
|
1039
|
+
|
|
1040
|
+
```typescript
|
|
1041
|
+
import { isBashToolResult } from "@earendil-works/pi-coding-agent";
|
|
1042
|
+
|
|
1043
|
+
pi.on("tool_result", async (event, ctx) => {
|
|
1044
|
+
// event.toolName, event.toolCallId, event.input, event.parentToolCallId
|
|
1045
|
+
// event.content, event.details, event.structuredContent, event.isError, event.usage
|
|
1046
|
+
|
|
1047
|
+
if (isBashToolResult(event)) {
|
|
1048
|
+
// event.details is typed as BashToolDetails
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
const response = await fetch("https://example.com/summarize", {
|
|
1052
|
+
method: "POST",
|
|
1053
|
+
body: JSON.stringify({ content: event.content }),
|
|
1054
|
+
signal: ctx.signal,
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
// Modify result:
|
|
1058
|
+
return { content: [...], details: {...}, isError: false, usage: nestedModelUsage };
|
|
1059
|
+
});
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
### User Bash Events
|
|
1063
|
+
|
|
1064
|
+
#### user_bash
|
|
1065
|
+
|
|
1066
|
+
Fired when user executes `!` or `!!` commands. **Can intercept.**
|
|
1067
|
+
|
|
1068
|
+
```typescript
|
|
1069
|
+
import { createLocalBashOperations } from "@earendil-works/pi-coding-agent";
|
|
1070
|
+
|
|
1071
|
+
pi.on("user_bash", (event, ctx) => {
|
|
1072
|
+
// event.command - the bash command
|
|
1073
|
+
// event.excludeFromContext - true if !! prefix
|
|
1074
|
+
// event.cwd - working directory
|
|
1075
|
+
|
|
1076
|
+
// Option 1: Provide custom operations (e.g., SSH)
|
|
1077
|
+
return { operations: remoteBashOps };
|
|
1078
|
+
|
|
1079
|
+
// Option 2: Wrap pi's built-in local bash backend
|
|
1080
|
+
const local = createLocalBashOperations();
|
|
1081
|
+
return {
|
|
1082
|
+
operations: {
|
|
1083
|
+
exec(command, cwd, options) {
|
|
1084
|
+
return local.exec(`source ~/.profile\n${command}`, cwd, options);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
// Option 3: Full replacement - return result directly
|
|
1090
|
+
return { result: { output: "...", exitCode: 0, cancelled: false, truncated: false } };
|
|
1091
|
+
});
|
|
1092
|
+
```
|
|
1093
|
+
|
|
1094
|
+
Returning `undefined` continues to the next handler, then local execution if none handles the event. A valid result stops propagation: `operations` executes the command through the supplied backend, while `result` records the completed command without executing it.
|
|
1095
|
+
|
|
1096
|
+
### Input Events
|
|
1097
|
+
|
|
1098
|
+
#### input
|
|
1099
|
+
|
|
1100
|
+
Fired when user input is received, after extension commands are checked but before skill and template expansion. The event sees the raw input text, so `/skill:foo` and `/template` are not yet expanded.
|
|
1101
|
+
|
|
1102
|
+
**Processing order:**
|
|
1103
|
+
1. Extension commands (`/cmd`) checked first - if found, handler runs and input event is skipped. Messages from `pi.sendUserMessage()` are checked only with `expandPromptTemplates: true`.
|
|
1104
|
+
2. `input` event fires - can intercept, transform, or handle
|
|
1105
|
+
3. If not handled: skill commands (`/skill:name`) expanded to skill content
|
|
1106
|
+
4. If not handled: prompt templates (`/template`) expanded to template content
|
|
1107
|
+
5. Agent processing begins (`before_agent_start`, etc.)
|
|
1108
|
+
|
|
1109
|
+
```typescript
|
|
1110
|
+
pi.on("input", async (event, ctx) => {
|
|
1111
|
+
// event.text - raw input (before skill/template expansion)
|
|
1112
|
+
// event.images - attached images, if any
|
|
1113
|
+
// event.source - "interactive" (typed), "rpc" (API), or "extension" (via sendUserMessage)
|
|
1114
|
+
// event.streamingBehavior - "steer" | "followUp" | undefined
|
|
1115
|
+
// undefined when idle, "steer" for mid-stream interrupts,
|
|
1116
|
+
// "followUp" for messages queued until the agent finishes
|
|
1117
|
+
|
|
1118
|
+
// Transform: rewrite input before expansion
|
|
1119
|
+
if (event.text.startsWith("?quick "))
|
|
1120
|
+
return { action: "transform", text: `Respond briefly: ${event.text.slice(7)}` };
|
|
1121
|
+
|
|
1122
|
+
// Handle: respond without LLM (extension shows its own feedback)
|
|
1123
|
+
if (event.text === "ping") {
|
|
1124
|
+
ctx.ui.notify("pong", "info");
|
|
1125
|
+
return { action: "handled" };
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// Route by source: skip processing for extension-injected messages
|
|
1129
|
+
if (event.source === "extension") return { action: "continue" };
|
|
1130
|
+
|
|
1131
|
+
// Intercept skill commands before expansion
|
|
1132
|
+
if (event.text.startsWith("/skill:")) {
|
|
1133
|
+
// Could transform, block, or let pass through
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return { action: "continue" }; // Default: pass through to expansion
|
|
1137
|
+
});
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
**Results:**
|
|
1141
|
+
- `continue` - pass through unchanged (default if handler returns nothing)
|
|
1142
|
+
- `transform` - modify text/images, then continue to expansion
|
|
1143
|
+
- `handled` - skip agent entirely (first handler to return this wins)
|
|
1144
|
+
|
|
1145
|
+
Transforms chain across handlers. See [input-transform.ts](../examples/extensions/input-transform.ts) and [input-transform-streaming.ts](../examples/extensions/input-transform-streaming.ts) for `streamingBehavior`-aware routing.
|
|
1146
|
+
|
|
1147
|
+
<a id="use-extension-context"></a>
|
|
1148
|
+
|
|
1149
|
+
## ExtensionContext
|
|
1150
|
+
|
|
1151
|
+
All handlers receive `ctx: ExtensionContext`. Tool `execute()` receives `ExtensionToolContext`, which adds `ctx.tools` and `ctx.executeTool()` (see [Calling Other Tools](#calling-other-tools)). Command handlers receive [`ExtensionCommandContext`](#extensioncommandcontext).
|
|
1152
|
+
|
|
1153
|
+
### ctx.ui
|
|
1154
|
+
|
|
1155
|
+
UI methods for user interaction. See [Custom UI](#custom-ui) for full details.
|
|
1156
|
+
|
|
1157
|
+
### ctx.mode
|
|
1158
|
+
|
|
1159
|
+
Current run mode: `"tui"`, `"rpc"`, `"json"`, or `"print"`. Use `ctx.mode === "tui"` to guard terminal-only features such as `custom()`, component factories, terminal input, and direct TUI rendering.
|
|
1160
|
+
|
|
1161
|
+
### ctx.hasUI
|
|
1162
|
+
|
|
1163
|
+
`true` in TUI and RPC modes. `false` in print mode (`-p`) and JSON mode. Use this to guard dialog methods (`select`, `confirm`, `input`, `editor`) and fire-and-forget methods (`notify`, `setStatus`, `setWidget`, `setTitle`, `setEditorText`) that work in both TUI and RPC modes. In RPC mode, some TUI-specific methods are no-ops or return defaults (see [RPC Extension UI](rpc-extension-ui.md)).
|
|
1164
|
+
|
|
1165
|
+
### ctx.cwd
|
|
1166
|
+
|
|
1167
|
+
Current working directory.
|
|
1168
|
+
|
|
1169
|
+
Use `CONFIG_DIR_NAME` instead of hardcoding `.pi` when constructing project-local config paths. Rebranded distributions can use a different config directory name.
|
|
1170
|
+
|
|
1171
|
+
```typescript
|
|
1172
|
+
import { CONFIG_DIR_NAME, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
1173
|
+
import { join } from "node:path";
|
|
1174
|
+
|
|
1175
|
+
export default function (pi: ExtensionAPI) {
|
|
1176
|
+
pi.on("session_start", (_event, ctx) => {
|
|
1177
|
+
const projectConfigPath = join(ctx.cwd, CONFIG_DIR_NAME, "my-extension.json");
|
|
1178
|
+
// ...
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
### ctx.isProjectTrusted()
|
|
1184
|
+
|
|
1185
|
+
Returns whether project-local trust is active for the current session context. This includes temporary trust decisions and CLI trust overrides, not just saved decisions in the global trust store.
|
|
1186
|
+
|
|
1187
|
+
Use this before reading project-local extension configuration that should only be honored for trusted projects.
|
|
1188
|
+
|
|
1189
|
+
### ctx.sessionManager
|
|
1190
|
+
|
|
1191
|
+
Read-only access to session state: `getCwd()`, `getSessionDir()`, `getSessionId()`, `getSessionFile()`, `getSessionName()`, `getHeader()`, `getEntries()`, `getEntry()`, `getBranch()`, `getTree()`, `getLeafId()`, `getLeafEntry()`, `getLabel()`, `buildContextEntries()`, and `buildSessionProjection()`. See [Session Format](session-format.md) for entry types.
|
|
1192
|
+
|
|
1193
|
+
For `tool_call`, this state is synchronized through the current assistant message before handlers run. In parallel tool execution mode it is still not guaranteed to include sibling tool results from the same assistant message.
|
|
1194
|
+
|
|
1195
|
+
```typescript
|
|
1196
|
+
ctx.sessionManager.getEntries() // All entries
|
|
1197
|
+
ctx.sessionManager.getBranch() // Current branch
|
|
1198
|
+
ctx.sessionManager.buildContextEntries() // Active branch entries with compaction applied
|
|
1199
|
+
ctx.sessionManager.getLeafId() // Current leaf entry ID
|
|
1200
|
+
```
|
|
1201
|
+
|
|
1202
|
+
### ctx.modelRegistry / ctx.model / ctx.thinkingLevel / ctx.scopedModels
|
|
1203
|
+
|
|
1204
|
+
Access to models, providers, and resolved authentication. `ctx.modelRegistry.getProvider(id)` returns the effective pi-ai provider, while `getProviderAuth(id)` resolves its current API key, headers, base URL, and provider-scoped environment without requiring a loaded model. `ctx.model` is the active model, and `ctx.thinkingLevel` is its current effective thinking level.
|
|
1205
|
+
|
|
1206
|
+
`ctx.scopedModels` is the read-only list of models scoped to the current session — the same set the `/scoped-models` command shows. It is resolved at session start from the `--models` CLI flag and the `enabledModels` setting (matched against the available catalogue with minimatch on `provider/modelId` or a bare `modelId`). It is empty when no scoping is configured, meaning every available model is usable. Each entry is `{ model, thinkingLevel? }`, where `thinkingLevel` is set only when a pattern pinned it (e.g. `anthropic/*:high`). Use it to populate a model picker that mirrors the built-in one instead of enumerating the whole catalogue via `ctx.modelRegistry.getAvailable()`.
|
|
1207
|
+
|
|
1208
|
+
#### Streaming model calls
|
|
1209
|
+
|
|
1210
|
+
Use `ctx.modelRegistry.streamSimple(model, context, options)` for provider-neutral options such as `reasoning`, or `complete(model, context, options)` to await the final assistant message with API-specific options. Both use configured providers and resolve authentication, including for providers registered with `pi.registerProvider()`. Use these instead of `pi-ai/compat` streaming functions, which cannot see extension provider registrations.
|
|
1211
|
+
|
|
1212
|
+
`streamSimple()` returns an `AssistantMessageEventStream`. Iterate it for response events and await `.result()` for the final message. Setup failures produce error events and error results.
|
|
1213
|
+
|
|
1214
|
+
For non-chat models, `findOfType()`, `getModelsOfType()`, `getAvailableOfType()`, and `getModelOfType()` look up image and classifier models, and `classify()` and `generateImages()` call them. See [Use classifier models](models.md#use-classifier-models) and [Use image models](models.md#use-image-models).
|
|
1215
|
+
|
|
1216
|
+
### ctx.signal
|
|
1217
|
+
|
|
1218
|
+
The current agent abort signal, or `undefined` when no agent turn is active.
|
|
1219
|
+
|
|
1220
|
+
Use this for abort-aware nested work started by extension handlers, for example:
|
|
1221
|
+
- `fetch(..., { signal: ctx.signal })`
|
|
1222
|
+
- model calls that accept `signal`
|
|
1223
|
+
- file or process helpers that accept `AbortSignal`
|
|
1224
|
+
|
|
1225
|
+
`ctx.signal` is typically defined during active turn events such as `tool_call`, `tool_result`, `message_update`, and `turn_end`.
|
|
1226
|
+
It is usually `undefined` in idle or non-turn contexts such as session events, extension commands, and shortcuts fired while Pi is idle.
|
|
1227
|
+
|
|
1228
|
+
```typescript
|
|
1229
|
+
pi.on("tool_result", async (event, ctx) => {
|
|
1230
|
+
const response = await fetch("https://example.com/api", {
|
|
1231
|
+
method: "POST",
|
|
1232
|
+
body: JSON.stringify(event),
|
|
1233
|
+
signal: ctx.signal,
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
const data = await response.json();
|
|
1237
|
+
return { details: data };
|
|
1238
|
+
});
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
### ctx.isIdle() / ctx.abort() / ctx.hasPendingMessages()
|
|
1242
|
+
|
|
1243
|
+
Control flow helpers. `ctx.isIdle()` is false while Pi is processing an agent run, automatic retry, auto-compaction retry, or queued continuation.
|
|
1244
|
+
|
|
1245
|
+
### ctx.shutdown()
|
|
1246
|
+
|
|
1247
|
+
Request a graceful shutdown of pi.
|
|
1248
|
+
|
|
1249
|
+
- **Interactive mode:** Deferred until the agent becomes idle (after processing all queued steering and follow-up messages).
|
|
1250
|
+
- **RPC mode:** Deferred until the next idle state (after completing the current command response, when waiting for the next command).
|
|
1251
|
+
- **Print mode:** No-op. The process exits automatically when all prompts are processed.
|
|
1252
|
+
|
|
1253
|
+
Emits `session_shutdown` event to all extensions before exiting. Available in all contexts (event handlers, tools, commands, shortcuts).
|
|
1254
|
+
|
|
1255
|
+
```typescript
|
|
1256
|
+
pi.on("tool_call", (event, ctx) => {
|
|
1257
|
+
if (isFatal(event.input)) {
|
|
1258
|
+
ctx.shutdown();
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
```
|
|
1262
|
+
|
|
1263
|
+
### ctx.getContextUsage()
|
|
1264
|
+
|
|
1265
|
+
Returns current context usage for the active model. Uses last assistant usage when available, then estimates tokens for trailing messages.
|
|
1266
|
+
|
|
1267
|
+
```typescript
|
|
1268
|
+
const usage = ctx.getContextUsage();
|
|
1269
|
+
if (usage?.tokens != null && usage.tokens > 100_000) {
|
|
1270
|
+
// ...
|
|
1271
|
+
}
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1274
|
+
### ctx.compact()
|
|
1275
|
+
|
|
1276
|
+
Trigger compaction without awaiting completion. Use `onComplete` and `onError` for follow-up actions.
|
|
1277
|
+
|
|
1278
|
+
```typescript
|
|
1279
|
+
ctx.compact({
|
|
1280
|
+
customInstructions: "Focus on recent changes",
|
|
1281
|
+
onComplete: (result) => {
|
|
1282
|
+
ctx.ui.notify("Compaction completed", "info");
|
|
1283
|
+
},
|
|
1284
|
+
onError: (error) => {
|
|
1285
|
+
ctx.ui.notify(`Compaction failed: ${error.message}`, "error");
|
|
1286
|
+
},
|
|
1287
|
+
});
|
|
1288
|
+
```
|
|
1289
|
+
|
|
1290
|
+
### ctx.getSystemPrompt()
|
|
1291
|
+
|
|
1292
|
+
Returns Pi's current system prompt string.
|
|
1293
|
+
|
|
1294
|
+
- During `before_agent_start`, this reflects chained system-prompt changes made so far for the current turn.
|
|
1295
|
+
- It does not include later `context` message mutations.
|
|
1296
|
+
- It does not include `before_provider_request` payload rewrites.
|
|
1297
|
+
- If later-loaded extensions run after yours, they can still change what is ultimately sent.
|
|
1298
|
+
|
|
1299
|
+
```typescript
|
|
1300
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
1301
|
+
const prompt = ctx.getSystemPrompt();
|
|
1302
|
+
console.log(`System prompt length: ${prompt.length}`);
|
|
1303
|
+
});
|
|
1304
|
+
```
|
|
1305
|
+
|
|
1306
|
+
## ExtensionCommandContext
|
|
1307
|
+
|
|
1308
|
+
Command handlers receive `ExtensionCommandContext`, which extends `ExtensionContext` with session control methods. These are only available in commands because they can deadlock if called from event handlers.
|
|
1309
|
+
|
|
1310
|
+
### ctx.getSystemPromptOptions()
|
|
1311
|
+
|
|
1312
|
+
Returns the base inputs Pi currently uses to build the system prompt.
|
|
1313
|
+
|
|
1314
|
+
```typescript
|
|
1315
|
+
const options = ctx.getSystemPromptOptions();
|
|
1316
|
+
const contextPaths = options.contextFiles?.map((file) => file.path) ?? [];
|
|
1317
|
+
```
|
|
1318
|
+
|
|
1319
|
+
This has the same shape and mutability as `before_agent_start` `event.systemPromptOptions`: custom or forced prompt, active tools, tool snippets, per-tool and custom rules, custom sections, appended prompt text, cwd, loaded context files, and loaded skills. It may include full context file contents, so treat it as sensitive extension-local data and avoid exposing it through command lists, logs, or autocomplete metadata.
|
|
1320
|
+
|
|
1321
|
+
This reports the current base prompt inputs. It does not include per-turn `before_agent_start` chained system-prompt changes, later `context` event message mutations, or `before_provider_request` payload rewrites.
|
|
1322
|
+
|
|
1323
|
+
### ctx.waitForIdle()
|
|
1324
|
+
|
|
1325
|
+
Wait for the agent to fully settle, including automatic retries, auto-compaction retries, and queued continuations:
|
|
1326
|
+
|
|
1327
|
+
```typescript
|
|
1328
|
+
pi.registerCommand("my-cmd", {
|
|
1329
|
+
handler: async (args, ctx) => {
|
|
1330
|
+
await ctx.waitForIdle();
|
|
1331
|
+
// Agent is now idle, safe to modify session
|
|
1332
|
+
},
|
|
1333
|
+
});
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
### ctx.newSession(options?)
|
|
1337
|
+
|
|
1338
|
+
Create a new session:
|
|
1339
|
+
|
|
1340
|
+
```typescript
|
|
1341
|
+
const parentSession = ctx.sessionManager.getSessionFile();
|
|
1342
|
+
const kickoff = "Continue in the replacement session";
|
|
1343
|
+
|
|
1344
|
+
const result = await ctx.newSession({
|
|
1345
|
+
parentSession,
|
|
1346
|
+
setup: async (sm) => {
|
|
1347
|
+
sm.appendMessage({
|
|
1348
|
+
role: "user",
|
|
1349
|
+
content: [{ type: "text", text: "Context from previous session..." }],
|
|
1350
|
+
timestamp: Date.now(),
|
|
1351
|
+
});
|
|
1352
|
+
},
|
|
1353
|
+
withSession: async (ctx) => {
|
|
1354
|
+
// Use only the replacement-session ctx here.
|
|
1355
|
+
await ctx.sendUserMessage(kickoff);
|
|
1356
|
+
},
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
if (result.cancelled) {
|
|
1360
|
+
// An extension cancelled the new session
|
|
1361
|
+
}
|
|
1362
|
+
```
|
|
1363
|
+
|
|
1364
|
+
Options:
|
|
1365
|
+
- `parentSession`: parent session file to record in the new session header
|
|
1366
|
+
- `setup`: mutate the new session's `SessionManager` before `withSession` runs
|
|
1367
|
+
- `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
|
|
1368
|
+
|
|
1369
|
+
### ctx.fork(entryId, options?)
|
|
1370
|
+
|
|
1371
|
+
Fork from a specific entry, creating a new session file:
|
|
1372
|
+
|
|
1373
|
+
```typescript
|
|
1374
|
+
const result = await ctx.fork("entry-id-123", {
|
|
1375
|
+
withSession: async (ctx) => {
|
|
1376
|
+
// Use only the replacement-session ctx here.
|
|
1377
|
+
ctx.ui.notify("Now in the forked session", "info");
|
|
1378
|
+
},
|
|
1379
|
+
});
|
|
1380
|
+
if (result.cancelled) {
|
|
1381
|
+
// An extension cancelled the fork
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
const cloneResult = await ctx.fork("entry-id-456", { position: "at" });
|
|
1385
|
+
if (cloneResult.cancelled) {
|
|
1386
|
+
// An extension cancelled the clone
|
|
1387
|
+
}
|
|
1388
|
+
```
|
|
1389
|
+
|
|
1390
|
+
Options:
|
|
1391
|
+
- `position`: `"before"` (default) forks before the selected user message, restoring that prompt into the editor
|
|
1392
|
+
- `position`: `"at"` duplicates the active path through the selected entry without restoring editor text
|
|
1393
|
+
- `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
|
|
1394
|
+
|
|
1395
|
+
### ctx.navigateTree(targetId, options?)
|
|
1396
|
+
|
|
1397
|
+
Navigate to a different point in the session tree. Rejects while an agent response, manual or automatic compaction, or another tree navigation is active, even with `summarize: false`. These conflicts leave the active branch unchanged and reject the promise rather than returning `{ cancelled: true }`. Wait for the active operation to finish (for example, with `await ctx.waitForIdle()` in a command handler) and retry. It also rejects when `summarize` is set without an available model, or when the target entry does not exist:
|
|
1398
|
+
|
|
1399
|
+
```typescript
|
|
1400
|
+
const result = await ctx.navigateTree("entry-id-456", {
|
|
1401
|
+
summarize: true,
|
|
1402
|
+
customInstructions: "Focus on error handling changes",
|
|
1403
|
+
replaceInstructions: false, // true = replace default prompt entirely
|
|
1404
|
+
label: "review-checkpoint",
|
|
1405
|
+
});
|
|
1406
|
+
```
|
|
1407
|
+
|
|
1408
|
+
Options:
|
|
1409
|
+
- `summarize`: Whether to generate a summary of the abandoned branch
|
|
1410
|
+
- `customInstructions`: Custom instructions for the summarizer
|
|
1411
|
+
- `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
|
|
1412
|
+
- `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
|
|
1413
|
+
|
|
1414
|
+
### ctx.switchSession(sessionPath, options?)
|
|
1415
|
+
|
|
1416
|
+
Switch to a different session file:
|
|
1417
|
+
|
|
1418
|
+
```typescript
|
|
1419
|
+
const result = await ctx.switchSession("/path/to/session.jsonl", {
|
|
1420
|
+
withSession: async (ctx) => {
|
|
1421
|
+
await ctx.sendUserMessage("Resume work in the replacement session");
|
|
1422
|
+
},
|
|
1423
|
+
});
|
|
1424
|
+
if (result.cancelled) {
|
|
1425
|
+
// An extension cancelled the switch via session_before_switch
|
|
1426
|
+
}
|
|
1427
|
+
```
|
|
1428
|
+
|
|
1429
|
+
Options:
|
|
1430
|
+
- `withSession`: run post-switch work against a fresh replacement-session context. Do not use captured old `pi` / command `ctx`; see [Session replacement lifecycle and footguns](#session-replacement-lifecycle-and-footguns).
|
|
1431
|
+
|
|
1432
|
+
To discover available sessions, use the static `SessionManager.list()` or `SessionManager.listAll()` methods:
|
|
1433
|
+
|
|
1434
|
+
```typescript
|
|
1435
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
1436
|
+
|
|
1437
|
+
pi.registerCommand("switch", {
|
|
1438
|
+
description: "Switch to another session",
|
|
1439
|
+
handler: async (args, ctx) => {
|
|
1440
|
+
const sessions = await SessionManager.list(ctx.cwd);
|
|
1441
|
+
if (sessions.length === 0) return;
|
|
1442
|
+
const choice = await ctx.ui.select(
|
|
1443
|
+
"Pick session:",
|
|
1444
|
+
sessions.map((s) => s.path),
|
|
1445
|
+
);
|
|
1446
|
+
if (choice) {
|
|
1447
|
+
await ctx.switchSession(choice, {
|
|
1448
|
+
withSession: async (ctx) => {
|
|
1449
|
+
ctx.ui.notify("Switched session", "info");
|
|
1450
|
+
},
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
},
|
|
1454
|
+
});
|
|
1455
|
+
```
|
|
1456
|
+
|
|
1457
|
+
### Session replacement lifecycle and footguns
|
|
1458
|
+
|
|
1459
|
+
`withSession` receives a fresh `ReplacedSessionContext`, which extends `ExtensionCommandContext` with async `sendMessage()` and `sendUserMessage()` helpers bound to the replacement session.
|
|
1460
|
+
|
|
1461
|
+
Lifecycle and footguns:
|
|
1462
|
+
- `withSession` runs only after the old session has emitted `session_shutdown`, the old runtime has been torn down, the replacement session has been rebound, and the new extension instance has already received `session_start`.
|
|
1463
|
+
- The callback still executes in the original closure, not inside the new extension instance. That means your old extension instance may already have run its shutdown cleanup before `withSession` starts.
|
|
1464
|
+
- Captured old `pi` / old command `ctx` session-bound objects are stale after replacement and will throw if used. Use only the `ctx` passed to `withSession` for session-bound work.
|
|
1465
|
+
- Previously extracted raw objects are still your responsibility. For example, if you capture `const sm = ctx.sessionManager` before replacement, `sm` is still the old `SessionManager` object. Do not reuse it after replacement.
|
|
1466
|
+
- Code in `withSession` should assume any state invalidated by your `session_shutdown` handler is already gone. Only capture plain data that survives shutdown cleanly, such as strings, ids, and serialized config.
|
|
1467
|
+
|
|
1468
|
+
Safe pattern:
|
|
1469
|
+
|
|
1470
|
+
```typescript
|
|
1471
|
+
pi.registerCommand("handoff", {
|
|
1472
|
+
handler: async (_args, ctx) => {
|
|
1473
|
+
const kickoff = "Continue from the replacement session";
|
|
1474
|
+
await ctx.newSession({
|
|
1475
|
+
withSession: async (ctx) => {
|
|
1476
|
+
await ctx.sendUserMessage(kickoff);
|
|
1477
|
+
},
|
|
1478
|
+
});
|
|
1479
|
+
},
|
|
1480
|
+
});
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1483
|
+
Unsafe pattern:
|
|
1484
|
+
|
|
1485
|
+
```typescript
|
|
1486
|
+
pi.registerCommand("handoff", {
|
|
1487
|
+
handler: async (_args, ctx) => {
|
|
1488
|
+
const oldSessionManager = ctx.sessionManager;
|
|
1489
|
+
await ctx.newSession({
|
|
1490
|
+
withSession: async (_ctx) => {
|
|
1491
|
+
// stale old objects: do not do this
|
|
1492
|
+
oldSessionManager.getSessionFile();
|
|
1493
|
+
pi.sendUserMessage("wrong");
|
|
1494
|
+
},
|
|
1495
|
+
});
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
```
|
|
1499
|
+
|
|
1500
|
+
### ctx.reload()
|
|
1501
|
+
|
|
1502
|
+
Run the same reload flow as `/reload`.
|
|
1503
|
+
|
|
1504
|
+
```typescript
|
|
1505
|
+
pi.registerCommand("reload-runtime", {
|
|
1506
|
+
description: "Reload extensions, skills, prompts, themes, and context files",
|
|
1507
|
+
handler: async (_args, ctx) => {
|
|
1508
|
+
await ctx.reload();
|
|
1509
|
+
return;
|
|
1510
|
+
},
|
|
1511
|
+
});
|
|
1512
|
+
```
|
|
1513
|
+
|
|
1514
|
+
Important behavior:
|
|
1515
|
+
- `await ctx.reload()` emits `session_shutdown` for the current extension runtime
|
|
1516
|
+
- It then reloads resources and emits `session_start` with `reason: "reload"` and `resources_discover` with reason `"reload"`
|
|
1517
|
+
- The currently running command handler still continues in the old call frame
|
|
1518
|
+
- Code after `await ctx.reload()` still runs from the pre-reload version
|
|
1519
|
+
- Code after `await ctx.reload()` must not assume old in-memory extension state is still valid
|
|
1520
|
+
- After the handler returns, future commands/events/tool calls use the new extension version
|
|
1521
|
+
|
|
1522
|
+
For predictable behavior, treat reload as terminal for that handler (`await ctx.reload(); return;`).
|
|
1523
|
+
|
|
1524
|
+
Tools run with `ExtensionToolContext`, not `ExtensionCommandContext`, so they cannot call `ctx.reload()`, and Pi cannot reload while the agent is running. To let the LLM trigger a reload, have the tool record the request and run the command from `agent_settled`, where messages sent by handlers are processed after all settled handlers finish:
|
|
1525
|
+
|
|
1526
|
+
```typescript
|
|
1527
|
+
let reloadRequested = false;
|
|
1528
|
+
|
|
1529
|
+
pi.registerTool({
|
|
1530
|
+
name: "reload_runtime",
|
|
1531
|
+
label: "Reload Runtime",
|
|
1532
|
+
description: "Reload extensions, skills, prompts, themes, and context files",
|
|
1533
|
+
parameters: Type.Object({}),
|
|
1534
|
+
async execute() {
|
|
1535
|
+
reloadRequested = true;
|
|
1536
|
+
return {
|
|
1537
|
+
content: [{ type: "text", text: "Reload requested. Pi reloads after this response." }],
|
|
1538
|
+
details: {},
|
|
1539
|
+
terminate: true,
|
|
1540
|
+
};
|
|
1541
|
+
},
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
pi.on("agent_settled", () => {
|
|
1545
|
+
if (!reloadRequested) return;
|
|
1546
|
+
reloadRequested = false;
|
|
1547
|
+
pi.sendUserMessage("/reload-runtime", { expandPromptTemplates: true });
|
|
1548
|
+
});
|
|
1549
|
+
```
|
|
1550
|
+
|
|
1551
|
+
`expandPromptTemplates: true` dispatches the text as a command. Without it, or when queued with `deliverAs`, the text reaches the model as a plain user message. See [reload-runtime.ts](../examples/extensions/reload-runtime.ts).
|
|
1552
|
+
|
|
1553
|
+
## ExtensionAPI Methods
|
|
1554
|
+
|
|
1555
|
+
### pi.on(event, handler)
|
|
1556
|
+
|
|
1557
|
+
Subscribe to events. Returns an unsubscribe function that removes only that registration. See [Events](#events) for event types and return values.
|
|
1558
|
+
|
|
1559
|
+
```typescript
|
|
1560
|
+
const unsubscribe = pi.on("agent_end", async (event) => {
|
|
1561
|
+
unsubscribe();
|
|
1562
|
+
await updateIntegration(event.messages);
|
|
1563
|
+
});
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
Handlers run in extension load order, then registration order within each extension. Adding or removing a handler does not affect a dispatch already in progress.
|
|
1567
|
+
|
|
1568
|
+
### pi.registerTool(definition)
|
|
1569
|
+
|
|
1570
|
+
Register a custom tool callable by the LLM. See [Custom Tools](#custom-tools) for full details.
|
|
1571
|
+
|
|
1572
|
+
`pi.registerTool()` works both during extension load and after startup. You can call it inside `session_start`, command handlers, or other event handlers. New tools are refreshed immediately in the same session, so they appear in `pi.getAllTools()` without `/reload`. Registering a tool activates it unless it sets `defaultActive: false` or an [exposure](#tool-exposure) other than `direct` or `model-only`.
|
|
1573
|
+
|
|
1574
|
+
Use `pi.setActiveTools()` to enable or disable tools (including dynamically added tools) at runtime.
|
|
1575
|
+
|
|
1576
|
+
Use `promptSnippet` to opt a custom tool into a one-line entry in the `<tools>` section of the default system prompt, and `promptGuidelines` to append tool-specific bullets to its `<rules>` section when the tool is active.
|
|
1577
|
+
|
|
1578
|
+
**Important:** `promptGuidelines` bullets are appended flat to the `<rules>` section with no tool name prefix. Each guideline must name the tool it refers to — avoid "Use this tool when..." because the LLM cannot tell which tool "this" means. Write "Use my_tool when..." instead.
|
|
1579
|
+
|
|
1580
|
+
See [dynamic-tools.ts](../examples/extensions/dynamic-tools.ts) for a full example.
|
|
1581
|
+
|
|
1582
|
+
```typescript
|
|
1583
|
+
import { Type } from "typebox";
|
|
1584
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
1585
|
+
|
|
1586
|
+
pi.registerTool({
|
|
1587
|
+
name: "my_tool",
|
|
1588
|
+
label: "My Tool",
|
|
1589
|
+
description: "What this tool does",
|
|
1590
|
+
promptSnippet: "Summarize or transform text according to action",
|
|
1591
|
+
promptGuidelines: ["Use my_tool when the user asks to summarize previously generated text."],
|
|
1592
|
+
parameters: Type.Object({
|
|
1593
|
+
action: StringEnum(["list", "add"] as const),
|
|
1594
|
+
text: Type.Optional(Type.String()),
|
|
1595
|
+
}),
|
|
1596
|
+
|
|
1597
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
1598
|
+
// Stream progress; partial results also need details
|
|
1599
|
+
onUpdate?.({ content: [{ type: "text", text: "Working..." }], details: { result: "pending" } });
|
|
1600
|
+
|
|
1601
|
+
return {
|
|
1602
|
+
content: [{ type: "text", text: "Done" }],
|
|
1603
|
+
details: { result: "..." },
|
|
1604
|
+
};
|
|
1605
|
+
},
|
|
1606
|
+
|
|
1607
|
+
// Optional: Custom rendering
|
|
1608
|
+
renderCall(args, theme, context) { ... },
|
|
1609
|
+
renderResult(result, options, theme, context) { ... },
|
|
1610
|
+
});
|
|
1611
|
+
```
|
|
1612
|
+
|
|
1613
|
+
### pi.sendMessage(message, options?)
|
|
1614
|
+
|
|
1615
|
+
Inject a custom message into the session. Custom messages participate in LLM context. For durable TUI-only content that should not be sent to the LLM, use [`pi.appendEntry()`](#piappendentrycustomtype-data) with [`pi.registerEntryRenderer()`](#piregisterentryrenderercustomtype-renderer).
|
|
1616
|
+
|
|
1617
|
+
```typescript
|
|
1618
|
+
pi.sendMessage({
|
|
1619
|
+
customType: "my-extension",
|
|
1620
|
+
content: "Message text",
|
|
1621
|
+
display: true,
|
|
1622
|
+
details: { ... },
|
|
1623
|
+
}, {
|
|
1624
|
+
triggerTurn: true,
|
|
1625
|
+
deliverAs: "steer",
|
|
1626
|
+
});
|
|
1627
|
+
```
|
|
1628
|
+
|
|
1629
|
+
**Options:**
|
|
1630
|
+
- `deliverAs` - Delivery mode:
|
|
1631
|
+
- `"steer"` (default) - Queues the message while streaming. Delivered after the current assistant turn finishes executing its tool calls, before the next LLM call.
|
|
1632
|
+
- `"followUp"` - Waits for agent to finish. Delivered only when agent has no more tool calls.
|
|
1633
|
+
- `"nextTurn"` - Queued for next user prompt. Does not interrupt or trigger anything.
|
|
1634
|
+
- `triggerTurn: true` - If agent is idle, trigger an LLM response immediately. Only applies to `"steer"` and `"followUp"` modes (ignored for `"nextTurn"`). Without it, an idle session stores the message without starting a turn.
|
|
1635
|
+
- `triggerTurn: false` while streaming - The message is not steered or queued as a follow-up; it is appended after the current turn ends.
|
|
1636
|
+
|
|
1637
|
+
### pi.sendUserMessage(content, options?)
|
|
1638
|
+
|
|
1639
|
+
Send a user message to the agent. Unlike `sendMessage()` which sends custom messages, this sends an actual user message that appears as if typed by the user. It starts or queues a turn unless an `input` handler handles it or, with `expandPromptTemplates: true`, it runs an extension command.
|
|
1640
|
+
|
|
1641
|
+
```typescript
|
|
1642
|
+
// Simple text message
|
|
1643
|
+
pi.sendUserMessage("What is 2+2?");
|
|
1644
|
+
|
|
1645
|
+
// With content array (text + images)
|
|
1646
|
+
pi.sendUserMessage([
|
|
1647
|
+
{ type: "text", text: "Describe this image:" },
|
|
1648
|
+
{ type: "image", data: "...", mimeType: "image/png" },
|
|
1649
|
+
]);
|
|
1650
|
+
|
|
1651
|
+
// During streaming - must specify delivery mode
|
|
1652
|
+
pi.sendUserMessage("Focus on error handling", { deliverAs: "steer" });
|
|
1653
|
+
pi.sendUserMessage("And then summarize", { deliverAs: "followUp" });
|
|
1654
|
+
|
|
1655
|
+
// Opt in to extension command dispatch and skill/prompt template expansion
|
|
1656
|
+
pi.sendUserMessage("/review src/index.ts", { expandPromptTemplates: true });
|
|
1657
|
+
```
|
|
1658
|
+
|
|
1659
|
+
**Options:**
|
|
1660
|
+
- `deliverAs` - Required when agent is streaming:
|
|
1661
|
+
- `"steer"` - Queues the message for delivery after the current assistant turn finishes executing its tool calls
|
|
1662
|
+
- `"followUp"` - Waits for agent to finish all tools
|
|
1663
|
+
- `expandPromptTemplates` - Dispatch extension commands and expand skill commands and prompt templates. Defaults to `false`.
|
|
1664
|
+
|
|
1665
|
+
When not streaming, the message is sent immediately and triggers a new turn. When streaming without `deliverAs`, the message is rejected and Pi reports an extension error.
|
|
1666
|
+
|
|
1667
|
+
See [send-user-message.ts](../examples/extensions/send-user-message.ts) for a complete example.
|
|
1668
|
+
|
|
1669
|
+
### pi.appendEntry(customType, data?)
|
|
1670
|
+
|
|
1671
|
+
Persist extension data. Custom entries do NOT participate in LLM context. In interactive mode, they can also render inside the chat transcript when paired with `pi.registerEntryRenderer()`.
|
|
1672
|
+
|
|
1673
|
+
```typescript
|
|
1674
|
+
pi.appendEntry("my-state", { count: 42 });
|
|
1675
|
+
pi.appendEntry("status-card", { title: "Indexed files", count: 17 });
|
|
1676
|
+
|
|
1677
|
+
// Restore on reload
|
|
1678
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
1679
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
1680
|
+
if (entry.type === "custom" && entry.customType === "my-state") {
|
|
1681
|
+
// Reconstruct from entry.data
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
```
|
|
1686
|
+
|
|
1687
|
+
### pi.setSessionName(name)
|
|
1688
|
+
|
|
1689
|
+
Set the session display name (shown in session selector instead of first message).
|
|
1690
|
+
|
|
1691
|
+
```typescript
|
|
1692
|
+
pi.setSessionName("Refactor auth module");
|
|
1693
|
+
```
|
|
1694
|
+
|
|
1695
|
+
### pi.getSessionName()
|
|
1696
|
+
|
|
1697
|
+
Get the current session name, if set.
|
|
1698
|
+
|
|
1699
|
+
```typescript
|
|
1700
|
+
const name = pi.getSessionName();
|
|
1701
|
+
if (name) {
|
|
1702
|
+
console.log(`Session: ${name}`);
|
|
1703
|
+
}
|
|
1704
|
+
```
|
|
1705
|
+
|
|
1706
|
+
### pi.setLabel(entryId, label)
|
|
1707
|
+
|
|
1708
|
+
Set or clear a label on an entry. Labels are user-defined markers for bookmarking and navigation (shown in `/tree` selector).
|
|
1709
|
+
|
|
1710
|
+
```typescript
|
|
1711
|
+
// Set a label
|
|
1712
|
+
pi.setLabel(entryId, "checkpoint-before-refactor");
|
|
1713
|
+
|
|
1714
|
+
// Clear a label
|
|
1715
|
+
pi.setLabel(entryId, undefined);
|
|
1716
|
+
|
|
1717
|
+
// Read labels via sessionManager
|
|
1718
|
+
const label = ctx.sessionManager.getLabel(entryId);
|
|
1719
|
+
```
|
|
1720
|
+
|
|
1721
|
+
Labels persist in the session and survive restarts. Use them to mark important points (turns, checkpoints) in the conversation tree.
|
|
1722
|
+
|
|
1723
|
+
### pi.registerCommand(name, options)
|
|
1724
|
+
|
|
1725
|
+
Register a command.
|
|
1726
|
+
|
|
1727
|
+
If multiple extensions register the same command name, Pi keeps them all and assigns numeric invocation suffixes in load order, for example `/review:1` and `/review:2`.
|
|
1728
|
+
|
|
1729
|
+
```typescript
|
|
1730
|
+
pi.registerCommand("stats", {
|
|
1731
|
+
description: "Show session statistics",
|
|
1732
|
+
handler: async (args, ctx) => {
|
|
1733
|
+
const count = ctx.sessionManager.getEntries().length;
|
|
1734
|
+
ctx.ui.notify(`${count} entries`, "info");
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
```
|
|
1738
|
+
|
|
1739
|
+
Optional: add argument auto-completion for `/command ...`. `getArgumentCompletions` can also return a `Promise`:
|
|
1740
|
+
|
|
1741
|
+
```typescript
|
|
1742
|
+
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
1743
|
+
|
|
1744
|
+
pi.registerCommand("deploy", {
|
|
1745
|
+
description: "Deploy to an environment",
|
|
1746
|
+
getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
|
|
1747
|
+
const envs = ["dev", "staging", "prod"];
|
|
1748
|
+
const items = envs.map((e) => ({ value: e, label: e }));
|
|
1749
|
+
const filtered = items.filter((i) => i.value.startsWith(prefix));
|
|
1750
|
+
return filtered.length > 0 ? filtered : null;
|
|
1751
|
+
},
|
|
1752
|
+
handler: async (args, ctx) => {
|
|
1753
|
+
ctx.ui.notify(`Deploying: ${args}`, "info");
|
|
1754
|
+
},
|
|
1755
|
+
});
|
|
1756
|
+
```
|
|
1757
|
+
|
|
1758
|
+
### pi.getCommands()
|
|
1759
|
+
|
|
1760
|
+
Get the slash commands available for invocation via `prompt` in the current session. Includes extension commands, prompt templates, and skill commands.
|
|
1761
|
+
The list matches the RPC `get_commands` ordering: extensions first, then templates, then skills. Skill commands are named `skill:<name>`.
|
|
1762
|
+
|
|
1763
|
+
```typescript
|
|
1764
|
+
const commands = pi.getCommands();
|
|
1765
|
+
const bySource = commands.filter((command) => command.source === "extension");
|
|
1766
|
+
const userScoped = commands.filter((command) => command.sourceInfo.scope === "user");
|
|
1767
|
+
```
|
|
1768
|
+
|
|
1769
|
+
Each entry has this shape:
|
|
1770
|
+
|
|
1771
|
+
```typescript
|
|
1772
|
+
{
|
|
1773
|
+
name: string; // Invokable command name without the leading slash. May be suffixed like "review:1"
|
|
1774
|
+
description?: string;
|
|
1775
|
+
source: "extension" | "prompt" | "skill";
|
|
1776
|
+
sourceInfo: {
|
|
1777
|
+
path: string;
|
|
1778
|
+
source: string;
|
|
1779
|
+
scope: "user" | "project" | "temporary";
|
|
1780
|
+
origin: "package" | "top-level";
|
|
1781
|
+
baseDir?: string;
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
```
|
|
1785
|
+
|
|
1786
|
+
Use `sourceInfo` as the canonical provenance field. Do not infer ownership from command names or from ad hoc path parsing.
|
|
1787
|
+
|
|
1788
|
+
Built-in interactive commands (like `/model` and `/settings`) are not included here. They are handled only in interactive
|
|
1789
|
+
mode and would not execute if sent via `prompt`.
|
|
1790
|
+
|
|
1791
|
+
### pi.registerMessageRenderer(customType, renderer)
|
|
1792
|
+
|
|
1793
|
+
Register a custom TUI renderer for custom messages with your `customType`. Custom messages are created with `pi.sendMessage()` and participate in LLM context. See [Custom UI](#custom-ui).
|
|
1794
|
+
|
|
1795
|
+
### pi.registerMarkdownTransformer(transformer)
|
|
1796
|
+
|
|
1797
|
+
Register a transformer for the Markdown in normal user text, assistant text, and thinking blocks. Transformers run in extension load order, and each transformer receives the Markdown returned by the previous transformer. After the chain finishes, Pi renders the transformed content with its built-in renderer.
|
|
1798
|
+
|
|
1799
|
+
The transformer receives the Markdown string and a context with:
|
|
1800
|
+
|
|
1801
|
+
- `messageType` — `"user"`, `"assistant"`, or `"assistant-thinking"`
|
|
1802
|
+
- `isStreaming` — `true` for partial assistant updates; `false` for user, finalized assistant, and restored messages
|
|
1803
|
+
- `availableWidth` — exact terminal columns available for the transformed Markdown content
|
|
1804
|
+
- `messageId`, `timestamp` — session-entry ID and ISO timestamp when rendering from persisted session entries; `undefined` for live messages
|
|
1805
|
+
|
|
1806
|
+
Return the transformed Markdown:
|
|
1807
|
+
|
|
1808
|
+
```typescript
|
|
1809
|
+
pi.registerMarkdownTransformer((markdown, { messageType, isStreaming }) => {
|
|
1810
|
+
if (isStreaming || messageType === "assistant-thinking") return markdown;
|
|
1811
|
+
return markdown.replaceAll("-->", "→");
|
|
1812
|
+
});
|
|
1813
|
+
```
|
|
1814
|
+
|
|
1815
|
+
If a transformer throws, Pi keeps the Markdown produced so far and continues with the next transformer. The hook is display-only: the original message remains unchanged in the session and model context. It runs for new user messages, assistant streaming updates, restored session messages, and terminal width changes, so transformers should remain synchronous and inexpensive.
|
|
1816
|
+
|
|
1817
|
+
### pi.registerEntryRenderer(customType, renderer)
|
|
1818
|
+
|
|
1819
|
+
Register a custom TUI renderer for custom entries with your `customType`. Custom entries are created with `pi.appendEntry()` and do not participate in LLM context.
|
|
1820
|
+
|
|
1821
|
+
```typescript
|
|
1822
|
+
import { Box, Text } from "@earendil-works/pi-tui";
|
|
1823
|
+
|
|
1824
|
+
pi.registerEntryRenderer("status-card", (entry, { expanded }, theme) => {
|
|
1825
|
+
const data = entry.data as { title: string; count: number };
|
|
1826
|
+
const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text));
|
|
1827
|
+
box.addChild(new Text(`${theme.bold(data.title)}: ${data.count}`));
|
|
1828
|
+
if (expanded) {
|
|
1829
|
+
box.addChild(new Text(theme.fg("dim", JSON.stringify(data, null, 2))));
|
|
1830
|
+
}
|
|
1831
|
+
return box;
|
|
1832
|
+
});
|
|
1833
|
+
|
|
1834
|
+
pi.appendEntry("status-card", { title: "Indexed files", count: 17 });
|
|
1835
|
+
```
|
|
1836
|
+
|
|
1837
|
+
### pi.registerShortcut(shortcut, options)
|
|
1838
|
+
|
|
1839
|
+
Register a keyboard shortcut. See [keybindings.md](keybindings.md) for the shortcut format and built-in keybindings.
|
|
1840
|
+
|
|
1841
|
+
```typescript
|
|
1842
|
+
pi.registerShortcut("ctrl+shift+p", {
|
|
1843
|
+
description: "Toggle plan mode",
|
|
1844
|
+
handler: async (ctx) => {
|
|
1845
|
+
ctx.ui.notify("Toggled!");
|
|
1846
|
+
},
|
|
1847
|
+
});
|
|
1848
|
+
```
|
|
1849
|
+
|
|
1850
|
+
### pi.registerFlag(name, options)
|
|
1851
|
+
|
|
1852
|
+
Register a CLI flag.
|
|
1853
|
+
|
|
1854
|
+
```typescript
|
|
1855
|
+
pi.registerFlag("plan", {
|
|
1856
|
+
description: "Start in plan mode",
|
|
1857
|
+
type: "boolean",
|
|
1858
|
+
default: false,
|
|
1859
|
+
});
|
|
1860
|
+
|
|
1861
|
+
// Check the value after loading; in the factory, getFlag() returns the default
|
|
1862
|
+
pi.on("session_start", () => {
|
|
1863
|
+
if (pi.getFlag("plan")) {
|
|
1864
|
+
// Plan mode enabled
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
```
|
|
1868
|
+
|
|
1869
|
+
### pi.exec(command, args, options?)
|
|
1870
|
+
|
|
1871
|
+
Execute a command without a shell.
|
|
1872
|
+
|
|
1873
|
+
```typescript
|
|
1874
|
+
const result = await pi.exec("git", ["status"], { signal, timeout: 5000 });
|
|
1875
|
+
// result.stdout, result.stderr, result.code, result.killed, result.truncated
|
|
1876
|
+
```
|
|
1877
|
+
|
|
1878
|
+
Options: `signal` and `timeout` terminate the command, `cwd` sets the working directory, and `maxBuffer` limits stdout and stderr combined (default 256 MiB). When output exceeds `maxBuffer`, pi terminates the command and returns the output up to the limit with `truncated: true`, `killed: true`, and a nonzero `code`. `killed` is true whenever pi terminated the command: timeout, abort, or `maxBuffer`. A command that ignores SIGTERM gets SIGKILL after 5 seconds.
|
|
1879
|
+
|
|
1880
|
+
### pi.getActiveTools() / pi.getAllTools() / pi.setActiveTools(names)
|
|
1881
|
+
|
|
1882
|
+
Manage active tools. This works for both built-in tools and dynamically registered tools. `pi.getActiveTools()` returns the active tool names as `string[]`; `pi.getAllTools()` returns metadata for all configured tools.
|
|
1883
|
+
|
|
1884
|
+
```typescript
|
|
1885
|
+
const active = pi.getActiveTools(); // ["read", "bash", ...]
|
|
1886
|
+
const all = pi.getAllTools();
|
|
1887
|
+
// all = [{
|
|
1888
|
+
// name: "read",
|
|
1889
|
+
// description: "Read file contents...",
|
|
1890
|
+
// parameters: ...,
|
|
1891
|
+
// promptGuidelines: ["Use read to examine files instead of cat or sed."],
|
|
1892
|
+
// exposure: "direct",
|
|
1893
|
+
// sourceInfo: { path: "builtin:read", source: "builtin", scope: "temporary", origin: "top-level" }
|
|
1894
|
+
// }, ...]
|
|
1895
|
+
// Tools shipped with Pi: core tools and tools from built-in extensions such as builtin:mcp
|
|
1896
|
+
const shippedTools = all.filter((t) => t.sourceInfo.source === "builtin");
|
|
1897
|
+
// Tools from installed or local extensions
|
|
1898
|
+
const extensionTools = all.filter((t) => t.sourceInfo.source !== "builtin" && t.sourceInfo.source !== "sdk");
|
|
1899
|
+
pi.setActiveTools([...new Set([...active, "my_custom_tool"])]); // Keep current tools and enable my_custom_tool
|
|
1900
|
+
pi.setActiveTools(["read", "bash"]); // Only read and bash
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
`pi.getAllTools()` returns `name`, `description`, `parameters`, `promptGuidelines`, `exposure`, `sourceInfo`, and, when set, `namespace`, `annotations`, and `reachesTools`.
|
|
1904
|
+
|
|
1905
|
+
Typical `sourceInfo` values:
|
|
1906
|
+
- `source: "builtin"` for tools shipped with Pi: core tools (`path: "builtin:<tool>"`) and tools registered by built-in extensions such as `builtin:mcp` (`path: "builtin:<extension>"`)
|
|
1907
|
+
- `source: "sdk"` for tools passed via `createAgentSession({ customTools })`
|
|
1908
|
+
- extension source metadata for tools registered by extensions
|
|
1909
|
+
|
|
1910
|
+
`pi.setActiveTools()` ignores unknown and `hidden` tools. Tools with `codemode` or `deferred` exposure stay callable from codemode scripts whether active or not.
|
|
1911
|
+
|
|
1912
|
+
### pi.setModel(model)
|
|
1913
|
+
|
|
1914
|
+
Set the model for the current session. The change is recorded in session history and restored when that session is resumed, but it does not change the configured `defaultProvider` or `defaultModel` used by new sessions. Returns `false` if authentication is not configured for the model's provider. See [models.md](models.md) for configuring custom models.
|
|
1915
|
+
|
|
1916
|
+
```typescript
|
|
1917
|
+
const model = ctx.modelRegistry.find("anthropic", "claude-sonnet-4-5");
|
|
1918
|
+
if (model) {
|
|
1919
|
+
const success = await pi.setModel(model);
|
|
1920
|
+
if (!success) {
|
|
1921
|
+
ctx.ui.notify("No API key for this model", "error");
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
```
|
|
1925
|
+
|
|
1926
|
+
### pi.getThinkingLevel() / pi.setThinkingLevel(level)
|
|
1927
|
+
|
|
1928
|
+
Get the current thinking level. Level is clamped to model capabilities (non-reasoning models always use "off"). Changes emit `thinking_level_select`.
|
|
1929
|
+
|
|
1930
|
+
`pi.setThinkingLevel()` changes the thinking level for the current session. The change is recorded in session history and restored when that session is resumed, but it does not change the configured default used by new sessions.
|
|
1931
|
+
|
|
1932
|
+
```typescript
|
|
1933
|
+
const current = pi.getThinkingLevel(); // "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
|
|
1934
|
+
pi.setThinkingLevel("high");
|
|
1935
|
+
```
|
|
1936
|
+
|
|
1937
|
+
### pi.events
|
|
1938
|
+
|
|
1939
|
+
Shared event bus for communication between extensions:
|
|
1940
|
+
|
|
1941
|
+
```typescript
|
|
1942
|
+
pi.events.on("my:event", (data) => { ... });
|
|
1943
|
+
pi.events.emit("my:event", { ... });
|
|
1944
|
+
```
|
|
1945
|
+
|
|
1946
|
+
### pi.registerProvider(name, config)
|
|
1947
|
+
|
|
1948
|
+
Register or override a model provider dynamically. Useful for proxies, custom endpoints, or team-wide model configurations.
|
|
1949
|
+
|
|
1950
|
+
Calls made during the extension factory function are queued and applied once the runner initialises. Calls made after that — for example from a command handler following a user setup flow — take effect immediately without requiring a `/reload`.
|
|
1951
|
+
|
|
1952
|
+
Dynamic providers can implement `refreshModels`. Pi calls it during model refresh, publishes the returned list synchronously through the provider, and passes the canonical credential/stored-catalog/network/signal context. The extension decides whether to persist catalog metadata through generation-checked `context.publish({ persist: entry })`; live servers such as llama.cpp can return models without persisting them.
|
|
1953
|
+
|
|
1954
|
+
`context.signal` is always a concrete signal and provider callbacks must pass it to blocking I/O. Public `ModelRuntime.refresh()` and `ModelRegistry.refresh()` calls accept an optional signal and are unbounded when it is omitted; extensions and applications choose their own deadlines. Cancellation stops the caller waiting even if a provider ignores the signal, but cooperation is still required to stop the underlying work.
|
|
1955
|
+
|
|
1956
|
+
Extensions that need native provider auth, filtering, refresh, or stream behavior can register a complete `Provider` from `@earendil-works/pi-ai`. The provider becomes the composition base and `models.json` overrides still apply above it.
|
|
1957
|
+
|
|
1958
|
+
```typescript
|
|
1959
|
+
import { createProvider, openAICompletionsApi } from "@earendil-works/pi-ai/compat";
|
|
1960
|
+
|
|
1961
|
+
const provider = createProvider({
|
|
1962
|
+
id: "local-server",
|
|
1963
|
+
name: "Local Server",
|
|
1964
|
+
baseUrl: "http://localhost:8080/v1",
|
|
1965
|
+
auth: {
|
|
1966
|
+
apiKey: {
|
|
1967
|
+
name: "Local server setup",
|
|
1968
|
+
async login(interaction) {
|
|
1969
|
+
return {
|
|
1970
|
+
type: "api_key",
|
|
1971
|
+
key: await interaction.prompt({ type: "secret", message: "API key" }),
|
|
1972
|
+
};
|
|
1973
|
+
},
|
|
1974
|
+
async resolve({ credential }) {
|
|
1975
|
+
return credential?.key
|
|
1976
|
+
? { auth: { apiKey: credential.key }, source: "stored API key" }
|
|
1977
|
+
: undefined;
|
|
1978
|
+
},
|
|
1979
|
+
},
|
|
1980
|
+
},
|
|
1981
|
+
models: [],
|
|
1982
|
+
api: openAICompletionsApi(),
|
|
1983
|
+
});
|
|
1984
|
+
|
|
1985
|
+
pi.registerProvider(provider);
|
|
1986
|
+
|
|
1987
|
+
// Register a new provider with custom models
|
|
1988
|
+
pi.registerProvider("my-proxy", {
|
|
1989
|
+
name: "My Proxy",
|
|
1990
|
+
baseUrl: "https://proxy.example.com",
|
|
1991
|
+
apiKey: "$PROXY_API_KEY", // env var reference
|
|
1992
|
+
api: "anthropic-messages",
|
|
1993
|
+
models: [
|
|
1994
|
+
{
|
|
1995
|
+
id: "claude-sonnet-4-20250514",
|
|
1996
|
+
name: "Claude 4 Sonnet (proxy)",
|
|
1997
|
+
reasoning: false,
|
|
1998
|
+
input: ["text", "image"],
|
|
1999
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2000
|
+
contextWindow: 200000,
|
|
2001
|
+
maxTokens: 16384
|
|
2002
|
+
}
|
|
2003
|
+
]
|
|
2004
|
+
});
|
|
2005
|
+
|
|
2006
|
+
// Register a live llama.cpp catalog without persisting discovered models
|
|
2007
|
+
pi.registerProvider("llama.cpp", {
|
|
2008
|
+
baseUrl: "http://localhost:8080/v1",
|
|
2009
|
+
apiKey: "local",
|
|
2010
|
+
api: "openai-completions",
|
|
2011
|
+
async refreshModels({ signal }) {
|
|
2012
|
+
const response = await fetch("http://localhost:8080/v1/models", { signal });
|
|
2013
|
+
const { data } = (await response.json()) as { data: Array<{ id: string }> };
|
|
2014
|
+
return data.map(({ id }) => ({
|
|
2015
|
+
id,
|
|
2016
|
+
name: id,
|
|
2017
|
+
reasoning: false,
|
|
2018
|
+
input: ["text"],
|
|
2019
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
2020
|
+
contextWindow: 128000,
|
|
2021
|
+
maxTokens: 16384
|
|
2022
|
+
}));
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
|
|
2026
|
+
// Override baseUrl for an existing provider (keeps all models)
|
|
2027
|
+
pi.registerProvider("anthropic", {
|
|
2028
|
+
baseUrl: "https://proxy.example.com"
|
|
2029
|
+
});
|
|
2030
|
+
|
|
2031
|
+
// Register provider with OAuth support for /login
|
|
2032
|
+
pi.registerProvider("corporate-ai", {
|
|
2033
|
+
baseUrl: "https://ai.corp.com",
|
|
2034
|
+
api: "openai-responses",
|
|
2035
|
+
models: [...],
|
|
2036
|
+
oauth: {
|
|
2037
|
+
name: "Corporate AI (SSO)",
|
|
2038
|
+
async login(callbacks) {
|
|
2039
|
+
// Custom OAuth flow
|
|
2040
|
+
callbacks.onAuth({ url: "https://sso.corp.com/..." });
|
|
2041
|
+
const code = await callbacks.onPrompt({ message: "Enter code:" });
|
|
2042
|
+
return { refresh: code, access: code, expires: Date.now() + 3600000 };
|
|
2043
|
+
},
|
|
2044
|
+
async refreshToken(credentials, signal) {
|
|
2045
|
+
signal.throwIfAborted();
|
|
2046
|
+
// Refresh logic
|
|
2047
|
+
return credentials;
|
|
2048
|
+
},
|
|
2049
|
+
getApiKey(credentials) {
|
|
2050
|
+
return credentials.access;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
});
|
|
2054
|
+
```
|
|
2055
|
+
|
|
2056
|
+
The object form accepts a complete pi-ai `Provider`, including native `auth`, `getModels`, `refreshModels`, `filterModels`, `stream`, and `streamSimple` behavior.
|
|
2057
|
+
|
|
2058
|
+
**Legacy config options:**
|
|
2059
|
+
- `name` - Display name for the provider in UI such as `/login`.
|
|
2060
|
+
- `baseUrl` - API endpoint URL. Each defined model needs one, from the model definition or the provider.
|
|
2061
|
+
- `apiKey` - API key literal, environment interpolation (`$ENV_VAR` or `${ENV_VAR}`), or leading `!command`. Optional: without it, users store a key with `/login`. `$$` escapes `$`, and `$!` escapes a literal `!` without triggering command execution.
|
|
2062
|
+
- `api` - API type: `"anthropic-messages"`, `"openai-completions"`, `"openai-responses"`, etc.
|
|
2063
|
+
- `headers` - Custom headers to include in requests.
|
|
2064
|
+
- `authHeader` - If true, adds `Authorization: Bearer` header automatically.
|
|
2065
|
+
- `models` - Array of model definitions. If provided, replaces all existing models for this provider. Model definitions can set `baseUrl` to override the provider endpoint for that model.
|
|
2066
|
+
- `refreshModels` - Async dynamic discovery callback. Its returned models replace extension-provided models. `context.stored` contains the persisted provider snapshot; use generation-checked `context.publish({ persist: entry })` only when updated catalog data should persist. Use `persist: null` to delete that snapshot.
|
|
2067
|
+
- `oauth` - OAuth provider config for `/login` support. When provided, the provider appears in the login menu.
|
|
2068
|
+
- `streamSimple` - Custom streaming implementation for non-standard APIs.
|
|
2069
|
+
|
|
2070
|
+
See [custom-provider.md](custom-provider.md) for advanced topics: custom streaming APIs, OAuth details, model definition reference.
|
|
2071
|
+
|
|
2072
|
+
### pi.unregisterProvider(name)
|
|
2073
|
+
|
|
2074
|
+
Remove a previously registered provider and its models. Built-in models that were overridden by the provider are restored. Has no effect if the provider was not registered.
|
|
2075
|
+
|
|
2076
|
+
Like `registerProvider`, this takes effect immediately when called after the initial load phase, so a `/reload` is not required.
|
|
2077
|
+
|
|
2078
|
+
```typescript
|
|
2079
|
+
pi.registerCommand("my-setup-teardown", {
|
|
2080
|
+
description: "Remove the custom proxy provider",
|
|
2081
|
+
handler: async (_args, _ctx) => {
|
|
2082
|
+
pi.unregisterProvider("my-proxy");
|
|
2083
|
+
},
|
|
2084
|
+
});
|
|
2085
|
+
```
|
|
2086
|
+
|
|
2087
|
+
### pi.registerVirtualModel(model) / pi.unregisterVirtualModel(provider, id)
|
|
2088
|
+
|
|
2089
|
+
Register a selectable catalog entry that routes each request to a physical model. `ctx.model` and the session's model selection name the virtual model; assistant messages record the physical model and thinking level the router picked. Registering the same provider and ID again replaces the virtual model. See [Virtual Models](virtual-models.md).
|
|
2090
|
+
|
|
2091
|
+
### pi.registerMcpServer(name, config) / pi.unregisterMcpServer(name) / pi.getMcpServers()
|
|
2092
|
+
|
|
2093
|
+
Register an MCP server for the current session. See [MCP Servers](#mcp-servers).
|
|
2094
|
+
|
|
2095
|
+
### pi.registerToolRenderer(resolver)
|
|
2096
|
+
|
|
2097
|
+
Choose how calls to any tool are drawn, including tools that are not registered yet, such as MCP tools in a resumed session before their server connected. The resolver receives the tool name and `next()`, which returns what the remaining resolvers (in extension load order), then the registered tool, would use, so `next() ?? mine` only fills in.
|
|
2098
|
+
|
|
2099
|
+
```typescript
|
|
2100
|
+
pi.registerToolRenderer((toolName, next) => {
|
|
2101
|
+
if (!toolName.startsWith("mcp__")) return next();
|
|
2102
|
+
return next() ?? { renderCall: (args, theme) => new Text(theme.fg("toolTitle", toolName), 0, 0) };
|
|
2103
|
+
});
|
|
2104
|
+
```
|
|
2105
|
+
|
|
2106
|
+
### pi.getSettings()
|
|
2107
|
+
|
|
2108
|
+
Return a copy of the effective settings, with global and project settings merged and overrides applied.
|
|
2109
|
+
|
|
2110
|
+
<a id="persist-state"></a>
|
|
2111
|
+
|
|
2112
|
+
## State Management
|
|
2113
|
+
|
|
2114
|
+
Extensions with state should store it in tool result `details` for proper branching support:
|
|
2115
|
+
|
|
2116
|
+
```typescript
|
|
2117
|
+
export default function (pi: ExtensionAPI) {
|
|
2118
|
+
let items: string[] = [];
|
|
2119
|
+
|
|
2120
|
+
// Reconstruct state from the active branch
|
|
2121
|
+
const reconstruct = (ctx: ExtensionContext) => {
|
|
2122
|
+
items = [];
|
|
2123
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
2124
|
+
if (entry.type === "message" && entry.message.role === "toolResult") {
|
|
2125
|
+
if (entry.message.toolName === "my_tool") {
|
|
2126
|
+
items = (entry.message.details as { items?: string[] } | undefined)?.items ?? [];
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
pi.on("session_start", async (_event, ctx) => reconstruct(ctx));
|
|
2132
|
+
pi.on("session_tree", async (_event, ctx) => reconstruct(ctx)); // /tree changes the branch
|
|
2133
|
+
|
|
2134
|
+
pi.registerTool({
|
|
2135
|
+
name: "my_tool",
|
|
2136
|
+
// ...
|
|
2137
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
2138
|
+
items.push("new item");
|
|
2139
|
+
return {
|
|
2140
|
+
content: [{ type: "text", text: "Added" }],
|
|
2141
|
+
details: { items: [...items] }, // Store for reconstruction
|
|
2142
|
+
};
|
|
2143
|
+
},
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
```
|
|
2147
|
+
|
|
2148
|
+
Rebuild from `getBranch()`, not from every entry: abandoned branches represent alternative histories. Use [`pi.appendEntry()`](#piappendentrycustomtype-data) for durable data that should not reach the model.
|
|
2149
|
+
|
|
2150
|
+
<a id="register-tools"></a>
|
|
2151
|
+
|
|
2152
|
+
## Custom Tools
|
|
2153
|
+
|
|
2154
|
+
Register tools the LLM can call via `pi.registerTool()`. Tools appear in the system prompt and can have custom rendering.
|
|
2155
|
+
|
|
2156
|
+
Use `promptSnippet` for a short one-line entry in the `<tools>` section of the default system prompt. If omitted, custom tools are left out of that section.
|
|
2157
|
+
|
|
2158
|
+
Use `promptGuidelines` to add tool-specific bullets to the `<rules>` section of the default system prompt. These bullets are included only while the tool is active (for example, after `pi.setActiveTools([...])`).
|
|
2159
|
+
|
|
2160
|
+
**Important:** `promptGuidelines` bullets are appended flat to the `<rules>` section with no tool name prefix or grouping. Each guideline must name the tool it refers to — avoid "Use this tool when..." because the LLM cannot tell which tool "this" means. Write "Use my_tool when..." instead.
|
|
2161
|
+
|
|
2162
|
+
Note: Some models include the @ prefix in tool path arguments. Built-in tools strip a leading @ before resolving paths. If your custom tool accepts a path, normalize a leading @ as well.
|
|
2163
|
+
|
|
2164
|
+
If your custom tool mutates files, use `withFileMutationQueue()` so it participates in the same per-file queue as built-in `edit` and `write`. This matters because tool calls run in parallel by default. Without the queue, two tools can read the same old file contents, compute different updates, and then whichever write lands last overwrites the other.
|
|
2165
|
+
|
|
2166
|
+
Example failure case: your custom tool edits `foo.ts` while built-in `edit` also changes `foo.ts` in the same assistant turn. If your tool does not participate in the queue, both can read the original `foo.ts`, apply separate changes, and one of those changes is lost.
|
|
2167
|
+
|
|
2168
|
+
Pass the real target file path to `withFileMutationQueue()`, not the raw user argument. Resolve it to an absolute path first, relative to `ctx.cwd` or your tool's working directory. For existing files, the helper canonicalizes through `realpath()`, so symlink aliases for the same file share one queue. For new files, it falls back to the resolved absolute path because there is nothing to `realpath()` yet.
|
|
2169
|
+
|
|
2170
|
+
Queue the entire mutation window on that target path. That includes read-modify-write logic, not just the final write.
|
|
2171
|
+
|
|
2172
|
+
```typescript
|
|
2173
|
+
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
2174
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2175
|
+
import { dirname, resolve } from "node:path";
|
|
2176
|
+
|
|
2177
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
2178
|
+
const absolutePath = resolve(ctx.cwd, params.path);
|
|
2179
|
+
|
|
2180
|
+
return withFileMutationQueue(absolutePath, async () => {
|
|
2181
|
+
await mkdir(dirname(absolutePath), { recursive: true });
|
|
2182
|
+
const current = await readFile(absolutePath, "utf8");
|
|
2183
|
+
const next = current.replace(params.oldText, params.newText);
|
|
2184
|
+
await writeFile(absolutePath, next, "utf8");
|
|
2185
|
+
|
|
2186
|
+
return {
|
|
2187
|
+
content: [{ type: "text", text: `Updated ${params.path}` }],
|
|
2188
|
+
details: {},
|
|
2189
|
+
};
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
```
|
|
2193
|
+
|
|
2194
|
+
### Tool Definition
|
|
2195
|
+
|
|
2196
|
+
```typescript
|
|
2197
|
+
import { type Static, Type } from "typebox";
|
|
2198
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2199
|
+
|
|
2200
|
+
const myToolSchema = Type.Object({
|
|
2201
|
+
action: StringEnum(["list", "add"] as const),
|
|
2202
|
+
text: Type.Optional(Type.String()),
|
|
2203
|
+
});
|
|
2204
|
+
|
|
2205
|
+
pi.registerTool({
|
|
2206
|
+
name: "my_tool",
|
|
2207
|
+
label: "My Tool",
|
|
2208
|
+
description: "What this tool does (shown to LLM)",
|
|
2209
|
+
promptSnippet: "List or add items in the project todo list",
|
|
2210
|
+
promptGuidelines: [
|
|
2211
|
+
"Use my_tool for todo planning instead of direct file edits when the user asks for a task list."
|
|
2212
|
+
],
|
|
2213
|
+
parameters: myToolSchema,
|
|
2214
|
+
prepareArguments(args) {
|
|
2215
|
+
// Fold a legacy `oldAction` field into `action`. Schema validation still runs afterwards.
|
|
2216
|
+
const input = (args ?? {}) as { action?: unknown; oldAction?: unknown };
|
|
2217
|
+
if (input.action === undefined && input.oldAction !== undefined) {
|
|
2218
|
+
return { ...input, action: input.oldAction } as Static<typeof myToolSchema>;
|
|
2219
|
+
}
|
|
2220
|
+
return args as Static<typeof myToolSchema>;
|
|
2221
|
+
},
|
|
2222
|
+
|
|
2223
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
2224
|
+
// Check for cancellation
|
|
2225
|
+
if (signal?.aborted) {
|
|
2226
|
+
return { content: [{ type: "text", text: "Cancelled" }], details: {} };
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
// Stream progress updates; partial results also need details
|
|
2230
|
+
onUpdate?.({
|
|
2231
|
+
content: [{ type: "text", text: "Working..." }],
|
|
2232
|
+
details: {},
|
|
2233
|
+
});
|
|
2234
|
+
|
|
2235
|
+
// Run commands via pi.exec (captured from extension closure)
|
|
2236
|
+
const result = await pi.exec("some-command", [], { signal });
|
|
2237
|
+
|
|
2238
|
+
// Return result
|
|
2239
|
+
return {
|
|
2240
|
+
content: [{ type: "text", text: "Done" }], // Sent to LLM
|
|
2241
|
+
details: { data: result }, // For rendering & state
|
|
2242
|
+
// usage: nestedModelResponse.usage, // Optional nested LLM usage
|
|
2243
|
+
// Optional: stop after this tool batch when every finalized tool result
|
|
2244
|
+
// in the batch also returns terminate: true.
|
|
2245
|
+
terminate: true,
|
|
2246
|
+
};
|
|
2247
|
+
},
|
|
2248
|
+
|
|
2249
|
+
// Optional: Custom rendering
|
|
2250
|
+
renderCall(args, theme, context) { ... },
|
|
2251
|
+
renderResult(result, options, theme, context) { ... },
|
|
2252
|
+
});
|
|
2253
|
+
```
|
|
2254
|
+
|
|
2255
|
+
**Result fields:** Every result, including partial results passed to `onUpdate`, needs model-facing `content` and a `details` value. Use `details: undefined` when there is nothing to store; the type of `details` must match across all results of the tool.
|
|
2256
|
+
|
|
2257
|
+
**Usage accounting:** If a tool makes nested LLM calls, return their combined `Usage` as `usage`. Pi persists it on the tool result and includes it in footer, `/session`, and RPC session totals. `tool_result` handlers can inspect or replace this value.
|
|
2258
|
+
|
|
2259
|
+
**Signaling errors:** To mark a tool execution as failed, throw an error from `execute`, or return a result with `isError: true`. Both report an error result to the LLM; a returned result also keeps `details` and `structuredContent` for rendering and scripts. Other returned values never set the error flag.
|
|
2260
|
+
|
|
2261
|
+
**Early termination:** Return `terminate: true` from `execute()` to hint that the automatic follow-up LLM call should be skipped after the current tool batch. This only takes effect when every finalized tool result in that batch is terminating. See [examples/extensions/structured-output.ts](../examples/extensions/structured-output.ts) for a minimal example where the agent ends on a final structured-output tool call.
|
|
2262
|
+
|
|
2263
|
+
```typescript
|
|
2264
|
+
// Correct: throw to signal an error
|
|
2265
|
+
async execute(toolCallId, params) {
|
|
2266
|
+
if (!isValid(params.input)) {
|
|
2267
|
+
throw new Error(`Invalid input: ${params.input}`);
|
|
2268
|
+
}
|
|
2269
|
+
return { content: [{ type: "text", text: "OK" }], details: {} };
|
|
2270
|
+
}
|
|
2271
|
+
```
|
|
2272
|
+
|
|
2273
|
+
**String enums:** Prefer `StringEnum` from `@earendil-works/pi-ai`. It produces a plain `enum` schema that every provider accepts.
|
|
2274
|
+
|
|
2275
|
+
**Structured output:** Declare `outputSchema` and return a matching `structuredContent` when the result is data. The model still receives `content`; programmatic callers such as codemode scripts receive `structuredContent` instead of the text. Tools without `outputSchema` are passed to scripts as their text content. To report a failure that still carries data, return the result with `isError: true` instead of throwing: the model sees an error, and scripts still receive `structuredContent`.
|
|
2276
|
+
|
|
2277
|
+
**Execution mode:** Tool calls from one assistant message run in parallel by default. Set `executionMode: "sequential"` when a tool must not run concurrently with other calls, for example because it shares mutable in-memory state.
|
|
2278
|
+
|
|
2279
|
+
**Other definition fields:**
|
|
2280
|
+
|
|
2281
|
+
| Field | Purpose |
|
|
2282
|
+
|---|---|
|
|
2283
|
+
| `defaultActive` | Set `false` to register the tool inactive; `--tools`, the `defaultTools` setting, or `pi.setActiveTools()` activates it |
|
|
2284
|
+
| `exposure`, `namespace`, `annotations`, `reachesTools`, `prepareLoadout` | Control how the model and other tools reach the tool; see [Tool Exposure](#tool-exposure) |
|
|
2285
|
+
| `renderShell`, `renderCall`, `renderResult` | Custom rendering; see [Custom Rendering](#custom-rendering) |
|
|
2286
|
+
| `constrainedSampling` | Optional provider-side constrained sampling request for the tool's arguments |
|
|
2287
|
+
|
|
2288
|
+
Use `defineTool()` to keep parameter type inference when you assign a tool definition to a variable before registering it.
|
|
2289
|
+
|
|
2290
|
+
**Argument preparation:** `prepareArguments(args)` is optional. If defined, it runs before schema validation and before `execute()`. Use it to mimic an older accepted input shape when Pi resumes an older session whose stored tool call arguments no longer match the current schema. Return the object you want validated against `parameters`. Keep the public schema strict. Do not add deprecated compatibility fields to `parameters` just to keep old resumed sessions working.
|
|
2291
|
+
|
|
2292
|
+
Example: an older session may contain an `edit` tool call with top-level `oldText` and `newText`, while the current schema only accepts `edits: [{ oldText, newText }]`.
|
|
2293
|
+
|
|
2294
|
+
```typescript
|
|
2295
|
+
const editSchema = Type.Object({
|
|
2296
|
+
path: Type.String(),
|
|
2297
|
+
edits: Type.Array(
|
|
2298
|
+
Type.Object({
|
|
2299
|
+
oldText: Type.String(),
|
|
2300
|
+
newText: Type.String(),
|
|
2301
|
+
}),
|
|
2302
|
+
),
|
|
2303
|
+
});
|
|
2304
|
+
type EditInput = Static<typeof editSchema>;
|
|
2305
|
+
|
|
2306
|
+
pi.registerTool({
|
|
2307
|
+
name: "edit",
|
|
2308
|
+
label: "Edit",
|
|
2309
|
+
description: "Edit a single file using exact text replacement",
|
|
2310
|
+
parameters: editSchema,
|
|
2311
|
+
prepareArguments(args) {
|
|
2312
|
+
const input = (args ?? {}) as Partial<EditInput> & { oldText?: unknown; newText?: unknown };
|
|
2313
|
+
if (typeof input.oldText !== "string" || typeof input.newText !== "string") {
|
|
2314
|
+
return args as EditInput; // validation reports anything still invalid
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
const { oldText, newText, ...rest } = input;
|
|
2318
|
+
return { ...rest, edits: [...(input.edits ?? []), { oldText, newText }] } as EditInput;
|
|
2319
|
+
},
|
|
2320
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
2321
|
+
// params now matches the current schema
|
|
2322
|
+
return {
|
|
2323
|
+
content: [{ type: "text", text: `Applying ${params.edits.length} edit block(s)` }],
|
|
2324
|
+
details: {},
|
|
2325
|
+
};
|
|
2326
|
+
},
|
|
2327
|
+
});
|
|
2328
|
+
```
|
|
2329
|
+
|
|
2330
|
+
### Overriding Built-in Tools
|
|
2331
|
+
|
|
2332
|
+
Extensions can override built-in tools (`read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, `ls`) by registering a tool with the same name. The extension tool replaces the built-in without a warning.
|
|
2333
|
+
|
|
2334
|
+
```bash
|
|
2335
|
+
# Extension's read tool replaces built-in read
|
|
2336
|
+
pi -e ./tool-override.ts
|
|
2337
|
+
```
|
|
2338
|
+
|
|
2339
|
+
Alternatively, use `--no-builtin-tools` to start without any built-in tools while keeping extension tools enabled:
|
|
2340
|
+
```bash
|
|
2341
|
+
# No built-in tools, only extension tools
|
|
2342
|
+
pi --no-builtin-tools -e ./my-extension.ts
|
|
2343
|
+
```
|
|
2344
|
+
|
|
2345
|
+
See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.ts) for a complete example that overrides `read` with logging and access control.
|
|
2346
|
+
|
|
2347
|
+
**Rendering:** Built-in renderer inheritance is resolved per slot. Execution override and rendering override are independent. If your override omits `renderCall`, the built-in `renderCall` is used. If your override omits `renderResult`, the built-in `renderResult` is used. If your override omits both, the built-in renderer is used automatically (syntax highlighting, diffs, etc.). This lets you wrap built-in tools for logging or access control without reimplementing the UI.
|
|
2348
|
+
|
|
2349
|
+
**Prompt metadata:** `promptSnippet` and `promptGuidelines` are not inherited from the built-in tool. If your override should keep those prompt instructions, define them on the override explicitly.
|
|
2350
|
+
|
|
2351
|
+
**Your implementation must match the exact result shape**, including the `details` type. The UI and session logic depend on these shapes for rendering and state tracking.
|
|
2352
|
+
|
|
2353
|
+
Built-in tool implementations:
|
|
2354
|
+
- [read.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/read.ts) - `ReadToolDetails`
|
|
2355
|
+
- [bash.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/bash.ts) - `BashToolDetails`
|
|
2356
|
+
- [powershell.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/powershell.ts) - `PowerShellToolDetails`
|
|
2357
|
+
- [edit.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/edit.ts)
|
|
2358
|
+
- [write.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/write.ts)
|
|
2359
|
+
- [grep.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/grep.ts) - `GrepToolDetails`
|
|
2360
|
+
- [find.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/find.ts) - `FindToolDetails`
|
|
2361
|
+
- [ls.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/ls.ts) - `LsToolDetails`
|
|
2362
|
+
|
|
2363
|
+
### Remote Execution
|
|
2364
|
+
|
|
2365
|
+
Built-in tools support pluggable operations for delegating to remote systems (SSH, containers, etc.):
|
|
2366
|
+
|
|
2367
|
+
```typescript
|
|
2368
|
+
import { createReadTool, type ReadOperations } from "@earendil-works/pi-coding-agent";
|
|
2369
|
+
|
|
2370
|
+
const localRead = createReadTool(cwd);
|
|
2371
|
+
|
|
2372
|
+
// Register, checking the remote configuration at execution time
|
|
2373
|
+
pi.registerTool({
|
|
2374
|
+
...localRead,
|
|
2375
|
+
async execute(id, params, signal, onUpdate, _ctx) {
|
|
2376
|
+
const ssh = getSshConfig();
|
|
2377
|
+
if (ssh) {
|
|
2378
|
+
const operations: ReadOperations = {
|
|
2379
|
+
readFile: (path) => sshReadBuffer(ssh, path), // must resolve to a Buffer
|
|
2380
|
+
access: (path) => sshExec(ssh, `test -r ${path}`).then(() => {}),
|
|
2381
|
+
};
|
|
2382
|
+
return createReadTool(cwd, { operations }).execute(id, params, signal, onUpdate);
|
|
2383
|
+
}
|
|
2384
|
+
return localRead.execute(id, params, signal, onUpdate);
|
|
2385
|
+
},
|
|
2386
|
+
});
|
|
2387
|
+
```
|
|
2388
|
+
|
|
2389
|
+
The `create*ToolDefinition()` factories, such as `createReadToolDefinition()`, return complete tool definitions, including the built-in prompt snippet and guidelines, for the same purpose. Rendering does not need copying: a tool registered under a built-in name inherits the built-in renderer for each slot it leaves out (see [Overriding Built-in Tools](#overriding-built-in-tools)).
|
|
2390
|
+
|
|
2391
|
+
**Operations interfaces:** `ReadOperations`, `WriteOperations`, `EditOperations`, `BashOperations`, `PowerShellOperations`, `LsOperations`, `GrepOperations`, `FindOperations`
|
|
2392
|
+
|
|
2393
|
+
For `user_bash`, extensions can reuse Pi's local shell backend via `createLocalBashOperations()` (or `createLocalPowerShellOperations()`) instead of reimplementing local process spawning, shell resolution, and process-tree termination.
|
|
2394
|
+
|
|
2395
|
+
The `bash` and `powershell` tools also support a spawn hook to adjust the command, cwd, or env before execution:
|
|
2396
|
+
|
|
2397
|
+
```typescript
|
|
2398
|
+
import { createBashTool } from "@earendil-works/pi-coding-agent";
|
|
2399
|
+
|
|
2400
|
+
const bashTool = createBashTool(cwd, {
|
|
2401
|
+
spawnHook: ({ command, cwd, env }) => ({
|
|
2402
|
+
command: `source ~/.profile\n${command}`,
|
|
2403
|
+
cwd: `/mnt/sandbox${cwd}`,
|
|
2404
|
+
env: { ...env, CI: "1" },
|
|
2405
|
+
}),
|
|
2406
|
+
});
|
|
2407
|
+
```
|
|
2408
|
+
|
|
2409
|
+
`createBashTool()` and `createPowerShellTool()` expose the current session to commands through `PI_SESSION_ID`, `PI_SESSION_FILE`, `PI_PROVIDER`, `PI_MODEL`, and `PI_REASONING_LEVEL`. Injection happens before `spawnHook`, so hooks receive these values in `env` and preserve them when they spread the existing environment as above. Set `exposeSessionEnvironment: false` to disable them:
|
|
2410
|
+
|
|
2411
|
+
```typescript
|
|
2412
|
+
const bashTool = createBashTool(cwd, {
|
|
2413
|
+
exposeSessionEnvironment: false,
|
|
2414
|
+
});
|
|
2415
|
+
```
|
|
2416
|
+
|
|
2417
|
+
See [Shell tool session environment](environment-variables.md#shell-tool-session-environment) for variable semantics. See [examples/extensions/ssh.ts](../examples/extensions/ssh.ts) for a complete SSH example with `--ssh` flag.
|
|
2418
|
+
|
|
2419
|
+
### Output Truncation
|
|
2420
|
+
|
|
2421
|
+
**Tools MUST truncate their output** to avoid overwhelming the LLM context. Large outputs can cause:
|
|
2422
|
+
- Context overflow errors (prompt too long)
|
|
2423
|
+
- Compaction failures
|
|
2424
|
+
- Degraded model performance
|
|
2425
|
+
|
|
2426
|
+
The built-in limit is **50KB** (~10k tokens) and **2000 lines**, whichever is hit first. Use the exported truncation utilities:
|
|
2427
|
+
|
|
2428
|
+
```typescript
|
|
2429
|
+
import {
|
|
2430
|
+
truncateHead, // Keep first N lines/bytes (good for file reads, search results)
|
|
2431
|
+
truncateTail, // Keep last N lines/bytes (good for logs, command output)
|
|
2432
|
+
truncateLine, // Truncate a single line to a character count; returns { text, wasTruncated }
|
|
2433
|
+
formatSize, // Human-readable size (e.g., "50KB", "1.5MB")
|
|
2434
|
+
DEFAULT_MAX_BYTES, // 50KB
|
|
2435
|
+
DEFAULT_MAX_LINES, // 2000
|
|
2436
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2437
|
+
|
|
2438
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
2439
|
+
const output = await runCommand();
|
|
2440
|
+
|
|
2441
|
+
// Apply truncation
|
|
2442
|
+
const truncation = truncateHead(output, {
|
|
2443
|
+
maxLines: DEFAULT_MAX_LINES,
|
|
2444
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
2445
|
+
});
|
|
2446
|
+
|
|
2447
|
+
let result = truncation.content;
|
|
2448
|
+
|
|
2449
|
+
if (truncation.truncated) {
|
|
2450
|
+
// Write full output to temp file
|
|
2451
|
+
const tempFile = writeTempFile(output);
|
|
2452
|
+
|
|
2453
|
+
// Inform the LLM where to find complete output
|
|
2454
|
+
result += `\n\n[Output truncated: ${truncation.outputLines} of ${truncation.totalLines} lines`;
|
|
2455
|
+
result += ` (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}).`;
|
|
2456
|
+
result += ` Full output saved to: ${tempFile}]`;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
return { content: [{ type: "text", text: result }], details: { truncation } };
|
|
2460
|
+
}
|
|
2461
|
+
```
|
|
2462
|
+
|
|
2463
|
+
**Key points:**
|
|
2464
|
+
- Use `truncateHead` for content where the beginning matters (search results, file reads)
|
|
2465
|
+
- Use `truncateTail` for content where the end matters (logs, command output)
|
|
2466
|
+
- Always inform the LLM when output is truncated and where to find the full version
|
|
2467
|
+
- Document the truncation limits in your tool's description
|
|
2468
|
+
|
|
2469
|
+
See [examples/extensions/truncated-tool.ts](../examples/extensions/truncated-tool.ts) for a complete example wrapping `rg` (ripgrep) with proper truncation.
|
|
2470
|
+
|
|
2471
|
+
### Multiple Tools
|
|
2472
|
+
|
|
2473
|
+
One extension can register multiple tools with shared state:
|
|
2474
|
+
|
|
2475
|
+
```typescript
|
|
2476
|
+
export default function (pi: ExtensionAPI) {
|
|
2477
|
+
let connection = null;
|
|
2478
|
+
|
|
2479
|
+
pi.registerTool({ name: "db_connect", ... });
|
|
2480
|
+
pi.registerTool({ name: "db_query", ... });
|
|
2481
|
+
pi.registerTool({ name: "db_close", ... });
|
|
2482
|
+
|
|
2483
|
+
pi.on("session_shutdown", async () => {
|
|
2484
|
+
connection?.close();
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
```
|
|
2488
|
+
|
|
2489
|
+
<a id="tool-rendering"></a>
|
|
2490
|
+
|
|
2491
|
+
### Custom Rendering
|
|
2492
|
+
|
|
2493
|
+
Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
|
|
2494
|
+
|
|
2495
|
+
By default, tool output is wrapped in a `Box` that handles background and horizontal padding from the `outputPad` setting. Tool renderers are also used in HTML exports. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
|
|
2496
|
+
|
|
2497
|
+
Set `renderShell: "self"` when the tool should render its own shell instead of using the default `Box`. This is useful for tools that need complete control over framing or background behavior, for example large previews that must stay visually stable after the tool settles.
|
|
2498
|
+
|
|
2499
|
+
```typescript
|
|
2500
|
+
pi.registerTool({
|
|
2501
|
+
name: "my_tool",
|
|
2502
|
+
label: "My Tool",
|
|
2503
|
+
description: "Custom shell example",
|
|
2504
|
+
parameters: Type.Object({}),
|
|
2505
|
+
renderShell: "self",
|
|
2506
|
+
async execute() {
|
|
2507
|
+
return { content: [{ type: "text", text: "ok" }], details: undefined };
|
|
2508
|
+
},
|
|
2509
|
+
renderCall(args, theme, context) {
|
|
2510
|
+
return new Text(theme.fg("accent", "my custom shell"), 0, 0);
|
|
2511
|
+
},
|
|
2512
|
+
});
|
|
2513
|
+
```
|
|
2514
|
+
|
|
2515
|
+
`renderCall` and `renderResult` each receive a `context` object with:
|
|
2516
|
+
- `args` - the current tool call arguments
|
|
2517
|
+
- `state` - shared row-local state across `renderCall` and `renderResult`
|
|
2518
|
+
- `lastComponent` - the previously returned component for that slot, if any
|
|
2519
|
+
- `invalidate()` - request a rerender of this tool row
|
|
2520
|
+
- `toolCallId`, `cwd`, `executionStarted`, `argsComplete`, `isPartial`, `expanded`, `showImages`, `isError`
|
|
2521
|
+
- `durationMs` - how long execution took, from the final result; `undefined` while running
|
|
2522
|
+
- `outputPad` - horizontal padding from the `outputPad` setting; renderers with `renderShell: "self"` apply it themselves
|
|
2523
|
+
|
|
2524
|
+
Use `context.state` for cross-slot shared state. Keep slot-local caches on the returned component instance when you want to reuse and mutate the same component across renders.
|
|
2525
|
+
|
|
2526
|
+
#### renderCall
|
|
2527
|
+
|
|
2528
|
+
Renders the tool call or header:
|
|
2529
|
+
|
|
2530
|
+
```typescript
|
|
2531
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2532
|
+
|
|
2533
|
+
renderCall(args, theme, context) {
|
|
2534
|
+
const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
|
|
2535
|
+
let content = theme.fg("toolTitle", theme.bold("my_tool "));
|
|
2536
|
+
content += theme.fg("muted", args.action);
|
|
2537
|
+
if (args.text) {
|
|
2538
|
+
content += " " + theme.fg("dim", `"${args.text}"`);
|
|
2539
|
+
}
|
|
2540
|
+
text.setText(content);
|
|
2541
|
+
return text;
|
|
2542
|
+
}
|
|
2543
|
+
```
|
|
2544
|
+
|
|
2545
|
+
#### renderResult
|
|
2546
|
+
|
|
2547
|
+
Renders the tool result or output:
|
|
2548
|
+
|
|
2549
|
+
```typescript
|
|
2550
|
+
renderResult(result, { expanded, isPartial }, theme, context) {
|
|
2551
|
+
if (isPartial) {
|
|
2552
|
+
return new Text(theme.fg("warning", "Processing..."), 0, 0);
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
if (result.details?.error) {
|
|
2556
|
+
return new Text(theme.fg("error", `Error: ${result.details.error}`), 0, 0);
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
let text = theme.fg("success", "✓ Done");
|
|
2560
|
+
if (expanded && result.details?.items) {
|
|
2561
|
+
for (const item of result.details.items) {
|
|
2562
|
+
text += "\n " + theme.fg("dim", item);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return new Text(text, 0, 0);
|
|
2566
|
+
}
|
|
2567
|
+
```
|
|
2568
|
+
|
|
2569
|
+
If a slot intentionally has no visible content, return an empty `Component` such as an empty `Container`.
|
|
2570
|
+
|
|
2571
|
+
#### Keybinding Hints
|
|
2572
|
+
|
|
2573
|
+
Use `keyHint()` to display keybinding hints that respect the active keybinding configuration:
|
|
2574
|
+
|
|
2575
|
+
```typescript
|
|
2576
|
+
import { keyHint } from "@earendil-works/pi-coding-agent";
|
|
2577
|
+
|
|
2578
|
+
renderResult(result, { expanded }, theme, context) {
|
|
2579
|
+
let text = theme.fg("success", "✓ Done");
|
|
2580
|
+
if (!expanded) {
|
|
2581
|
+
text += ` (${keyHint("app.tools.expand", "to expand")})`;
|
|
2582
|
+
}
|
|
2583
|
+
return new Text(text, 0, 0);
|
|
2584
|
+
}
|
|
2585
|
+
```
|
|
2586
|
+
|
|
2587
|
+
Available functions:
|
|
2588
|
+
- `keyHint(keybinding, description)` - Formats a configured keybinding id such as `"app.tools.expand"` or `"tui.select.confirm"`
|
|
2589
|
+
- `keyText(keybinding)` - Returns the raw configured key text for a keybinding id
|
|
2590
|
+
- `rawKeyHint(key, description)` - Format a raw key string
|
|
2591
|
+
|
|
2592
|
+
Use namespaced keybinding ids:
|
|
2593
|
+
- Coding-agent ids use the `app.*` namespace, for example `app.tools.expand`, `app.editor.external`, `app.session.rename`
|
|
2594
|
+
- Shared TUI ids use the `tui.*` namespace, for example `tui.select.confirm`, `tui.select.cancel`, `tui.input.tab`
|
|
2595
|
+
|
|
2596
|
+
For the exhaustive list of keybinding ids and defaults, see [keybindings.md](keybindings.md). `keybindings.json` uses those same namespaced ids.
|
|
2597
|
+
|
|
2598
|
+
Custom editors and `ctx.ui.custom()` components receive `keybindings: KeybindingsManager` as an injected argument. They should use that injected manager directly instead of calling `getKeybindings()` or `setKeybindings()`.
|
|
2599
|
+
|
|
2600
|
+
#### Best Practices
|
|
2601
|
+
|
|
2602
|
+
- Use `Text` with padding `(0, 0)`. The default Box handles padding.
|
|
2603
|
+
- Use `\n` for multi-line content.
|
|
2604
|
+
- Handle `isPartial` for streaming progress.
|
|
2605
|
+
- Support `expanded` for detail on demand.
|
|
2606
|
+
- Keep default view compact.
|
|
2607
|
+
- Read `context.args` in `renderResult` instead of copying args into `context.state`.
|
|
2608
|
+
- Use `context.state` only for data that must be shared across call and result slots.
|
|
2609
|
+
- Reuse `context.lastComponent` when the same component instance can be updated in place.
|
|
2610
|
+
- Use `renderShell: "self"` only when the default boxed shell gets in the way. In self-shell mode the tool is responsible for its own framing, padding, and background.
|
|
2611
|
+
|
|
2612
|
+
#### Fallback
|
|
2613
|
+
|
|
2614
|
+
If a slot renderer is not defined or throws:
|
|
2615
|
+
- `renderCall`: Shows the tool name
|
|
2616
|
+
- `renderResult`: Shows raw text from `content`
|
|
2617
|
+
|
|
2618
|
+
### Dynamic Tool Loading
|
|
2619
|
+
|
|
2620
|
+
Extensions can register many tools while keeping only a small initial set active. A tool can then change the active set with `pi.setActiveTools()` during execution. Pi stores the initial prompt and tool loadout in the transcript's first system message, then appends tool and prompt deltas before the next model request. Providers that cannot represent a transition receive a complete transcript checkpoint, which may invalidate the cached prefix.
|
|
2621
|
+
|
|
2622
|
+
The lifecycle is:
|
|
2623
|
+
|
|
2624
|
+
1. Register every tool with `pi.registerTool()` so it appears in `pi.getAllTools()`. Register searchable tools with `defaultActive: false` so they start inactive.
|
|
2625
|
+
2. Keep loader tools, such as `search_tools`, active.
|
|
2626
|
+
3. During loader execution, call `pi.setActiveTools()` with the desired active tool names. Names must already be registered; unknown and `hidden` names are ignored.
|
|
2627
|
+
|
|
2628
|
+
Pi also ships a built-in `tool_search` tool. Register tools with `exposure: "deferred"` to make them findable by it instead of writing your own loader; see [Tool Exposure](#tool-exposure).
|
|
2629
|
+
|
|
2630
|
+
#### Search tool example
|
|
2631
|
+
|
|
2632
|
+
The following extension registers two inactive searchable tools and keeps `search_tools` active as their loader. The example uses simple keyword matching, but the search implementation could use BM25, embeddings, a remote catalog, or project-specific routing.
|
|
2633
|
+
|
|
2634
|
+
```typescript
|
|
2635
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2636
|
+
import { Type } from "typebox";
|
|
2637
|
+
|
|
2638
|
+
const SEARCHABLE_TOOL_NAMES = new Set(["lookup_weather", "search_issues"]);
|
|
2639
|
+
|
|
2640
|
+
export default function (pi: ExtensionAPI) {
|
|
2641
|
+
pi.registerTool({
|
|
2642
|
+
name: "lookup_weather",
|
|
2643
|
+
label: "Lookup Weather",
|
|
2644
|
+
defaultActive: false,
|
|
2645
|
+
description: "Look up the current weather for a city",
|
|
2646
|
+
parameters: Type.Object({ city: Type.String() }),
|
|
2647
|
+
async execute(_toolCallId, params) {
|
|
2648
|
+
return {
|
|
2649
|
+
content: [{ type: "text", text: `Weather for ${params.city}: sunny` }],
|
|
2650
|
+
details: {},
|
|
2651
|
+
};
|
|
2652
|
+
},
|
|
2653
|
+
});
|
|
2654
|
+
|
|
2655
|
+
pi.registerTool({
|
|
2656
|
+
name: "search_issues",
|
|
2657
|
+
label: "Search Issues",
|
|
2658
|
+
defaultActive: false,
|
|
2659
|
+
description: "Search project issues by keyword",
|
|
2660
|
+
parameters: Type.Object({ query: Type.String() }),
|
|
2661
|
+
async execute(_toolCallId, params) {
|
|
2662
|
+
return {
|
|
2663
|
+
content: [{ type: "text", text: `No open issues matching ${params.query}` }],
|
|
2664
|
+
details: {},
|
|
2665
|
+
};
|
|
2666
|
+
},
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
pi.registerTool({
|
|
2670
|
+
name: "search_tools",
|
|
2671
|
+
label: "Search Tools",
|
|
2672
|
+
description: "Search for and enable tools relevant to a task",
|
|
2673
|
+
promptSnippet: "Search for additional tools when the active tools cannot perform the task",
|
|
2674
|
+
promptGuidelines: [
|
|
2675
|
+
"Use search_tools when a task requires a capability that is not currently available.",
|
|
2676
|
+
],
|
|
2677
|
+
parameters: Type.Object({
|
|
2678
|
+
query: Type.String({ description: "Capability or task to search for" }),
|
|
2679
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 10 })),
|
|
2680
|
+
}),
|
|
2681
|
+
async execute(_toolCallId, params) {
|
|
2682
|
+
const terms = params.query.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
2683
|
+
const matches = pi.getAllTools()
|
|
2684
|
+
.filter((tool) => SEARCHABLE_TOOL_NAMES.has(tool.name))
|
|
2685
|
+
.map((tool) => ({
|
|
2686
|
+
tool,
|
|
2687
|
+
score: terms.reduce(
|
|
2688
|
+
(score, term) =>
|
|
2689
|
+
score + (`${tool.name} ${tool.description}`.toLowerCase().includes(term) ? 1 : 0),
|
|
2690
|
+
0,
|
|
2691
|
+
),
|
|
2692
|
+
}))
|
|
2693
|
+
.filter((match) => match.score > 0)
|
|
2694
|
+
.sort((a, b) => b.score - a.score)
|
|
2695
|
+
.slice(0, params.limit ?? 3)
|
|
2696
|
+
.map((match) => match.tool.name);
|
|
2697
|
+
|
|
2698
|
+
if (matches.length === 0) {
|
|
2699
|
+
return {
|
|
2700
|
+
content: [{ type: "text", text: `No tools found for: ${params.query}` }],
|
|
2701
|
+
details: { matches: [] as string[], added: [] as string[] },
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
const active = pi.getActiveTools();
|
|
2706
|
+
const added = matches.filter((name) => !active.includes(name));
|
|
2707
|
+
pi.setActiveTools([...new Set([...active, ...added])]);
|
|
2708
|
+
|
|
2709
|
+
return {
|
|
2710
|
+
content: [{
|
|
2711
|
+
type: "text",
|
|
2712
|
+
text: added.length > 0
|
|
2713
|
+
? `Loaded tools: ${added.join(", ")}`
|
|
2714
|
+
: `Matching tools already active: ${matches.join(", ")}`,
|
|
2715
|
+
}],
|
|
2716
|
+
details: { matches, added },
|
|
2717
|
+
};
|
|
2718
|
+
},
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2721
|
+
```
|
|
2722
|
+
|
|
2723
|
+
When `search_tools` adds a match, the model receives the complete updated tool list on the immediately following request.
|
|
2724
|
+
|
|
2725
|
+
### Tool Exposure
|
|
2726
|
+
|
|
2727
|
+
`exposure` controls how the model reaches a tool. "Callable" means callable from other tools through `ctx.executeTool()` (`ctx.tools`), as the `codemode` tool's scripts do:
|
|
2728
|
+
|
|
2729
|
+
- `direct` (default): declared to the model while active, and callable while active.
|
|
2730
|
+
- `model-only`: declared to the model while active, never callable. Use it for tools that orchestrate other tools or ask the user.
|
|
2731
|
+
- `codemode`: callable whenever registered, and listed by the `codemode` tool. Not declared to the model unless activated explicitly.
|
|
2732
|
+
- `deferred`: like `codemode`, but codemode tools do not list it; `tool_search` can find and activate it.
|
|
2733
|
+
- `hidden`: registered but unreachable. Re-register a tool with `exposure: "hidden"` to withdraw it, since tools cannot be unregistered.
|
|
2734
|
+
|
|
2735
|
+
`namespace: { name, aliases, description, instructions }` groups related tools, as MCP servers do. Codemode tools list a namespace under one heading with its `description`. `instructions` holds longer usage guidance; it is not listed, and codemode scripts read it with `describeNamespace(name)`. `aliases` are other names scripts may look the namespace up by, for example the server name `docs` for `mcp__docs`; a name and the same name as a script identifier (`my-docs`, `my_docs`) match alike.
|
|
2736
|
+
|
|
2737
|
+
Registering a `direct` or `model-only` tool activates it unless it sets `defaultActive: false`; the other exposures are not activated on registration. The active set (`pi.getActiveTools()`, `pi.setActiveTools()`) is the set of tools declared to the model, except active tools whose declarations `prepareLoadout` hides. `pi.getAllTools()` reports each tool's `exposure`, `namespace`, `annotations`, and `reachesTools`.
|
|
2738
|
+
|
|
2739
|
+
`annotations` are hints about what a tool does, with the meaning of MCP tool annotations: `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint`. MCP tools carry the hints their server declares. Missing hints take the MCP defaults: a tool is not read-only, and may be destructive and reach an open world. The hints are not verified, but a permission extension can use them to decide which calls to confirm. This confirms the calls Codex asks approval for:
|
|
2740
|
+
|
|
2741
|
+
```typescript
|
|
2742
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
2743
|
+
const hints = pi.getAllTools().find((tool) => tool.name === event.toolName)?.annotations;
|
|
2744
|
+
const needsApproval =
|
|
2745
|
+
hints?.destructiveHint === true ||
|
|
2746
|
+
(!hints?.readOnlyHint && ((hints?.destructiveHint ?? true) || (hints?.openWorldHint ?? true)));
|
|
2747
|
+
if (needsApproval && !(await ctx.ui.confirm("Allow tool call?", event.toolName))) {
|
|
2748
|
+
return { block: true, reason: `${event.toolName} was not approved` };
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
```
|
|
2752
|
+
|
|
2753
|
+
A tool that orchestrates other tools can adjust what the model sees while it is active with `prepareLoadout(loadout)`. It runs whenever the active tools change and receives the declared tools, the callable tools, and every registered tool with its exposure, namespace, and prompt guidelines. It returns replacement `descriptions` for declared tools (including its own) and `hiddenDeclarations`: active tools whose declarations requests leave out while they stay active and callable. The default system prompt leaves hidden tools out of its tool list and rules, and names no tool in the skills hint when the file reader is hidden, so the orchestrating tool should present their guidelines itself. `codemode` uses only this hook, `exposure`, `reachesTools`, and `ctx.executeTool()`, so another tool can implement the same behavior under a different name.
|
|
2754
|
+
|
|
2755
|
+
A tool that reaches other tools declares which ones a call may reach with `reachesTools(input)`: `"all"`, or the words of the input that may name them, where a word refers to every tool or namespace whose name it contains. `codemode` returns `"all"` for scripts that search or list tools and the words of the script otherwise; `tool_search` always returns `"all"`. Extensions that register tools late use it from their `tool_call` handler to finish registering the tools a call needs before it runs, as the MCP extension does for servers that are still connecting. The MCP extension also activates `codemode` or `tool_search` for MCP tools only when the tool of that name declares `reachesTools`.
|
|
2756
|
+
|
|
2757
|
+
### Calling Other Tools
|
|
2758
|
+
|
|
2759
|
+
A tool can run other tools with `ctx.executeTool(name, args, { signal, onUpdate })`. `ctx.tools` lists the tools it can call. The call never rejects for tool failures: unknown tools, validation errors, blocked calls, and thrown errors come back as results with `isError: true`.
|
|
2760
|
+
|
|
2761
|
+
Nested calls go through argument validation and the `tool_call` and `tool_result` handlers like model-issued calls, and emit `tool_execution_start`, `tool_execution_update`, and `tool_execution_end`. All of these events carry `parentToolCallId`, and their `toolCallId` is assigned by Pi as `<parent id>/<n>`. These IDs do not appear as tool calls or tool results in the transcript.
|
|
2762
|
+
|
|
2763
|
+
Nested calls do not add transcript entries: their results only reach the calling tool, which reports them itself, for example through `onUpdate` and `details`. The session keeps a bounded record of them (name, arguments, status, duration, error; never results) as `nestedCalls` on the calling tool's result message. It is used for compaction file lists and shown in HTML exports. Arguments over 8 KiB per call or 32 KiB per tool result are omitted, at most 256 calls are kept, and `complete: false` marks a record that lost anything.
|
|
2764
|
+
|
|
2765
|
+
The `usage` of nested results, at every depth, is added to the calling tool's result `usage`, so a tool reports only its own usage, not that of the tools it called.
|
|
2766
|
+
|
|
2767
|
+
## MCP Servers
|
|
2768
|
+
|
|
2769
|
+
`pi.registerMcpServer(name, config)` adds an MCP server for the current session. `config` has the shape of an `mcpServers` entry in [`mcp.json`](mcp.md): `command`, `args`, `env`, and `cwd` for stdio servers, `url`, `headers`, and `oauth` for HTTP servers, plus `exposure`, `toolExposure`, `description`, `enabled`, and `timeout`.
|
|
2770
|
+
|
|
2771
|
+
```typescript
|
|
2772
|
+
pi.registerMcpServer("jira", { url: "https://mcp.example.com/jira", exposure: "codemode" });
|
|
2773
|
+
pi.unregisterMcpServer("jira");
|
|
2774
|
+
```
|
|
2775
|
+
|
|
2776
|
+
Servers registered while the extension loads connect when the session starts, together with the `mcp.json` servers; servers registered later connect right away, and `pi.unregisterMcpServer()` closes the connection and makes the server's tools unreachable. Registrations are not saved: register again on every load, for example based on the extension's own settings. A server in `mcp.json` with the same name takes precedence, and `/mcp` shows the override. Registering the same name again replaces the extension's earlier registration; names registered by another extension, invalid names, and invalid configs throw.
|
|
2777
|
+
|
|
2778
|
+
The built-in MCP support connects registered servers. When nothing does, because another extension replaced it (see [MCP](mcp.md#replace-the-built-in-mcp-support)), each registration is reported as an extension error. Other MCP extensions can connect registered servers too: read them with `pi.getMcpServers()` on `session_start` and handle the `mcp_servers_change` event for later changes.
|
|
2779
|
+
|
|
2780
|
+
<a id="interact-with-the-user"></a>
|
|
2781
|
+
|
|
2782
|
+
## Custom UI
|
|
2783
|
+
|
|
2784
|
+
Extensions can interact with users via `ctx.ui` methods and customize how messages/tools render.
|
|
2785
|
+
|
|
2786
|
+
For custom components, focus, overlays, themes, and rendering performance, see [Terminal UI](tui.md). The examples it lists show selection lists, settings toggles, cancellable loaders, footers, and widgets.
|
|
2787
|
+
|
|
2788
|
+
### Dialogs
|
|
2789
|
+
|
|
2790
|
+
```typescript
|
|
2791
|
+
// Select from options
|
|
2792
|
+
const choice = await ctx.ui.select("Pick one:", ["A", "B", "C"]);
|
|
2793
|
+
|
|
2794
|
+
// Confirm dialog
|
|
2795
|
+
const ok = await ctx.ui.confirm("Delete?", "This cannot be undone");
|
|
2796
|
+
|
|
2797
|
+
// Text input
|
|
2798
|
+
const name = await ctx.ui.input("Name:", "placeholder");
|
|
2799
|
+
|
|
2800
|
+
// Multi-line editor
|
|
2801
|
+
const text = await ctx.ui.editor("Edit:", "prefilled text");
|
|
2802
|
+
|
|
2803
|
+
// Notification (non-blocking)
|
|
2804
|
+
ctx.ui.notify("Done!", "info"); // "info" | "warning" | "error"
|
|
2805
|
+
```
|
|
2806
|
+
|
|
2807
|
+
#### Timed Dialogs with Countdown
|
|
2808
|
+
|
|
2809
|
+
Dialogs support a `timeout` option that auto-dismisses with a live countdown display:
|
|
2810
|
+
|
|
2811
|
+
```typescript
|
|
2812
|
+
// Dialog shows "Title (5s)" → "Title (4s)" → ... → auto-dismisses at 0
|
|
2813
|
+
const confirmed = await ctx.ui.confirm(
|
|
2814
|
+
"Timed Confirmation",
|
|
2815
|
+
"This dialog will auto-cancel in 5 seconds. Confirm?",
|
|
2816
|
+
{ timeout: 5000 }
|
|
2817
|
+
);
|
|
2818
|
+
|
|
2819
|
+
if (confirmed) {
|
|
2820
|
+
// User confirmed
|
|
2821
|
+
} else {
|
|
2822
|
+
// User cancelled or timed out
|
|
2823
|
+
}
|
|
2824
|
+
```
|
|
2825
|
+
|
|
2826
|
+
**Return values on timeout:**
|
|
2827
|
+
- `select()` returns `undefined`
|
|
2828
|
+
- `confirm()` returns `false`
|
|
2829
|
+
- `input()` returns `undefined`
|
|
2830
|
+
|
|
2831
|
+
#### Manual Dismissal with AbortSignal
|
|
2832
|
+
|
|
2833
|
+
For more control (e.g., to distinguish timeout from user cancel), use `AbortSignal`:
|
|
2834
|
+
|
|
2835
|
+
```typescript
|
|
2836
|
+
const controller = new AbortController();
|
|
2837
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
2838
|
+
|
|
2839
|
+
const confirmed = await ctx.ui.confirm(
|
|
2840
|
+
"Timed Confirmation",
|
|
2841
|
+
"This dialog will auto-cancel in 5 seconds. Confirm?",
|
|
2842
|
+
{ signal: controller.signal }
|
|
2843
|
+
);
|
|
2844
|
+
|
|
2845
|
+
clearTimeout(timeoutId);
|
|
2846
|
+
|
|
2847
|
+
if (confirmed) {
|
|
2848
|
+
// User confirmed
|
|
2849
|
+
} else if (controller.signal.aborted) {
|
|
2850
|
+
// Dialog timed out
|
|
2851
|
+
} else {
|
|
2852
|
+
// User cancelled (pressed Escape or selected "No")
|
|
2853
|
+
}
|
|
2854
|
+
```
|
|
2855
|
+
|
|
2856
|
+
See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.ts) for complete examples.
|
|
2857
|
+
|
|
2858
|
+
### Widgets, Status, and Footer
|
|
2859
|
+
|
|
2860
|
+
```typescript
|
|
2861
|
+
// Status in footer (persistent until cleared)
|
|
2862
|
+
ctx.ui.setStatus("my-ext", "Processing...");
|
|
2863
|
+
ctx.ui.setStatus("my-ext", undefined); // Clear
|
|
2864
|
+
|
|
2865
|
+
// Working loader (shown during streaming)
|
|
2866
|
+
ctx.ui.setWorkingMessage("Thinking deeply...");
|
|
2867
|
+
ctx.ui.setWorkingMessage(); // Restore default
|
|
2868
|
+
ctx.ui.setWorkingVisible(false); // Hide the built-in working loader row entirely
|
|
2869
|
+
ctx.ui.setWorkingVisible(true); // Show the built-in working loader row
|
|
2870
|
+
|
|
2871
|
+
// Working indicator (shown during streaming)
|
|
2872
|
+
ctx.ui.setWorkingIndicator({ frames: [ctx.ui.theme.fg("accent", "●")] }); // Static dot
|
|
2873
|
+
ctx.ui.setWorkingIndicator({
|
|
2874
|
+
frames: [
|
|
2875
|
+
ctx.ui.theme.fg("dim", "·"),
|
|
2876
|
+
ctx.ui.theme.fg("muted", "•"),
|
|
2877
|
+
ctx.ui.theme.fg("accent", "●"),
|
|
2878
|
+
ctx.ui.theme.fg("muted", "•"),
|
|
2879
|
+
],
|
|
2880
|
+
intervalMs: 120,
|
|
2881
|
+
});
|
|
2882
|
+
ctx.ui.setWorkingIndicator({ frames: [] }); // Hide indicator
|
|
2883
|
+
ctx.ui.setWorkingIndicator(); // Restore default spinner
|
|
2884
|
+
|
|
2885
|
+
// Widget above editor (default)
|
|
2886
|
+
ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"]);
|
|
2887
|
+
// Widget below editor
|
|
2888
|
+
ctx.ui.setWidget("my-widget", ["Line 1", "Line 2"], { placement: "belowEditor" });
|
|
2889
|
+
ctx.ui.setWidget("my-widget", (tui, theme) => new Text(theme.fg("accent", "Custom"), 0, 0));
|
|
2890
|
+
ctx.ui.setWidget("my-widget", undefined); // Clear
|
|
2891
|
+
|
|
2892
|
+
// Custom footer (replaces built-in footer entirely)
|
|
2893
|
+
// footerData provides the git branch and extension statuses from setStatus()
|
|
2894
|
+
ctx.ui.setFooter((tui, theme, footerData) => ({
|
|
2895
|
+
render(width) { return [theme.fg("dim", "Custom footer")]; },
|
|
2896
|
+
invalidate() {},
|
|
2897
|
+
}));
|
|
2898
|
+
ctx.ui.setFooter(undefined); // Restore built-in footer
|
|
2899
|
+
|
|
2900
|
+
// Custom header shown at startup above the chat
|
|
2901
|
+
ctx.ui.setHeader((tui, theme) => new Text(theme.fg("accent", "my-project"), 0, 0));
|
|
2902
|
+
ctx.ui.setHeader(undefined); // Restore built-in header
|
|
2903
|
+
|
|
2904
|
+
// Label shown for hidden thinking blocks
|
|
2905
|
+
ctx.ui.setHiddenThinkingLabel("Reasoning...");
|
|
2906
|
+
ctx.ui.setHiddenThinkingLabel(); // Restore default
|
|
2907
|
+
|
|
2908
|
+
// Raw terminal input (interactive mode only); return { consume: true } to swallow it
|
|
2909
|
+
const unsubscribe = ctx.ui.onTerminalInput((data) => undefined);
|
|
2910
|
+
|
|
2911
|
+
// Terminal title
|
|
2912
|
+
ctx.ui.setTitle("pi - my-project");
|
|
2913
|
+
|
|
2914
|
+
// Editor text
|
|
2915
|
+
ctx.ui.setEditorText("Prefill text");
|
|
2916
|
+
const current = ctx.ui.getEditorText();
|
|
2917
|
+
|
|
2918
|
+
// Paste into editor (triggers paste handling, including collapse for large content)
|
|
2919
|
+
ctx.ui.pasteToEditor("pasted content");
|
|
2920
|
+
|
|
2921
|
+
// Stack custom autocomplete behavior on top of the built-in provider
|
|
2922
|
+
ctx.ui.addAutocompleteProvider((current) => ({
|
|
2923
|
+
triggerCharacters: ["#"],
|
|
2924
|
+
async getSuggestions(lines, line, col, options) {
|
|
2925
|
+
const beforeCursor = (lines[line] ?? "").slice(0, col);
|
|
2926
|
+
const match = beforeCursor.match(/(?:^|[ \t])#([^\s#]*)$/);
|
|
2927
|
+
if (!match) {
|
|
2928
|
+
return current.getSuggestions(lines, line, col, options);
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
return {
|
|
2932
|
+
prefix: `#${match[1] ?? ""}`,
|
|
2933
|
+
items: [{ value: "#2983", label: "#2983", description: "Extension API for autocomplete" }],
|
|
2934
|
+
};
|
|
2935
|
+
},
|
|
2936
|
+
applyCompletion(lines, line, col, item, prefix) {
|
|
2937
|
+
return current.applyCompletion(lines, line, col, item, prefix);
|
|
2938
|
+
},
|
|
2939
|
+
shouldTriggerFileCompletion(lines, line, col) {
|
|
2940
|
+
return current.shouldTriggerFileCompletion?.(lines, line, col) ?? true;
|
|
2941
|
+
},
|
|
2942
|
+
}));
|
|
2943
|
+
|
|
2944
|
+
// Tool output expansion
|
|
2945
|
+
const wasExpanded = ctx.ui.getToolsExpanded();
|
|
2946
|
+
ctx.ui.setToolsExpanded(true);
|
|
2947
|
+
ctx.ui.setToolsExpanded(wasExpanded);
|
|
2948
|
+
|
|
2949
|
+
// Custom editor (vim mode, emacs mode, etc.)
|
|
2950
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) => new VimEditor(tui, theme, keybindings));
|
|
2951
|
+
const currentEditor = ctx.ui.getEditorComponent();
|
|
2952
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) =>
|
|
2953
|
+
new WrappedEditor(tui, theme, keybindings, currentEditor?.(tui, theme, keybindings))
|
|
2954
|
+
);
|
|
2955
|
+
ctx.ui.setEditorComponent(undefined); // Restore default editor
|
|
2956
|
+
|
|
2957
|
+
// Theme management (see themes.md for creating themes)
|
|
2958
|
+
const themes = ctx.ui.getAllThemes(); // [{ name: "dark", path: "/..." | undefined }, ...]
|
|
2959
|
+
const lightTheme = ctx.ui.getTheme("light"); // Load without switching
|
|
2960
|
+
const result = ctx.ui.setTheme("light"); // Switch by name
|
|
2961
|
+
if (!result.success) {
|
|
2962
|
+
ctx.ui.notify(`Failed: ${result.error}`, "error");
|
|
2963
|
+
}
|
|
2964
|
+
ctx.ui.setTheme(lightTheme!); // Or switch by Theme object
|
|
2965
|
+
ctx.ui.theme.fg("accent", "styled text"); // Access current theme
|
|
2966
|
+
```
|
|
2967
|
+
|
|
2968
|
+
Custom working-indicator frames are rendered verbatim. If you want colors, add them to the frame strings yourself, for example with `ctx.ui.theme.fg(...)`.
|
|
2969
|
+
|
|
2970
|
+
### Autocomplete Providers
|
|
2971
|
+
|
|
2972
|
+
Use `ctx.ui.addAutocompleteProvider()` to stack custom autocomplete logic on top of the built-in slash-command and path provider. Set `triggerCharacters` for custom natural triggers such as `$`.
|
|
2973
|
+
|
|
2974
|
+
Typical pattern:
|
|
2975
|
+
|
|
2976
|
+
- inspect the text before the cursor
|
|
2977
|
+
- return your own suggestions when your extension-specific syntax matches
|
|
2978
|
+
- otherwise delegate to `current.getSuggestions(...)`
|
|
2979
|
+
- delegate `applyCompletion(...)` unless you need custom insertion behavior
|
|
2980
|
+
|
|
2981
|
+
```typescript
|
|
2982
|
+
pi.on("session_start", (_event, ctx) => {
|
|
2983
|
+
ctx.ui.addAutocompleteProvider((current) => ({
|
|
2984
|
+
triggerCharacters: ["#"],
|
|
2985
|
+
async getSuggestions(lines, cursorLine, cursorCol, options) {
|
|
2986
|
+
const line = lines[cursorLine] ?? "";
|
|
2987
|
+
const beforeCursor = line.slice(0, cursorCol);
|
|
2988
|
+
const match = beforeCursor.match(/(?:^|[ \t])#([^\s#]*)$/);
|
|
2989
|
+
if (!match) {
|
|
2990
|
+
return current.getSuggestions(lines, cursorLine, cursorCol, options);
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
return {
|
|
2994
|
+
prefix: `#${match[1] ?? ""}`,
|
|
2995
|
+
items: [
|
|
2996
|
+
{ value: "#2983", label: "#2983", description: "Extension API for registering custom @ autocomplete providers" },
|
|
2997
|
+
{ value: "#2753", label: "#2753", description: "Reload stale resource settings" },
|
|
2998
|
+
],
|
|
2999
|
+
};
|
|
3000
|
+
},
|
|
3001
|
+
|
|
3002
|
+
applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
|
|
3003
|
+
return current.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
|
|
3004
|
+
},
|
|
3005
|
+
|
|
3006
|
+
shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
|
|
3007
|
+
return current.shouldTriggerFileCompletion?.(lines, cursorLine, cursorCol) ?? true;
|
|
3008
|
+
},
|
|
3009
|
+
}));
|
|
3010
|
+
});
|
|
3011
|
+
```
|
|
3012
|
+
|
|
3013
|
+
See [github-issue-autocomplete.ts](../examples/extensions/github-issue-autocomplete.ts) for a complete example that preloads the latest open GitHub issues with `gh issue list` and filters them locally for fast `#...` completion. It requires GitHub CLI (`gh`) and a GitHub repository checkout.
|
|
3014
|
+
|
|
3015
|
+
### Custom Components
|
|
3016
|
+
|
|
3017
|
+
For complex UI, use `ctx.ui.custom()`. This temporarily replaces the editor with your component until `done()` is called:
|
|
3018
|
+
|
|
3019
|
+
```typescript
|
|
3020
|
+
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
3021
|
+
|
|
3022
|
+
const result = await ctx.ui.custom<boolean>((tui, theme, keybindings, done) => ({
|
|
3023
|
+
render(width: number): string[] {
|
|
3024
|
+
return [truncateToWidth(theme.fg("accent", "Press Enter to confirm, Escape to cancel"), width)];
|
|
3025
|
+
},
|
|
3026
|
+
handleInput(data: string): void {
|
|
3027
|
+
if (keybindings.matches(data, "tui.select.confirm")) done(true);
|
|
3028
|
+
else if (keybindings.matches(data, "tui.select.cancel")) done(false);
|
|
3029
|
+
},
|
|
3030
|
+
invalidate() {},
|
|
3031
|
+
}));
|
|
3032
|
+
|
|
3033
|
+
if (result) {
|
|
3034
|
+
// User pressed Enter
|
|
3035
|
+
}
|
|
3036
|
+
```
|
|
3037
|
+
|
|
3038
|
+
The callback receives:
|
|
3039
|
+
- `tui` - TUI instance (for screen dimensions, focus management)
|
|
3040
|
+
- `theme` - Current theme for styling
|
|
3041
|
+
- `keybindings` - App keybinding manager (for checking shortcuts)
|
|
3042
|
+
- `done(value)` - Call to close component and return value
|
|
3043
|
+
|
|
3044
|
+
The factory can also return a `Promise` of a component. See [Terminal UI](tui.md#build-a-minimal-custom-screen) for a complete custom screen with cached rendering.
|
|
3045
|
+
|
|
3046
|
+
#### Overlay Mode (Experimental)
|
|
3047
|
+
|
|
3048
|
+
Pass `{ overlay: true }` to render the component as a floating modal on top of existing content, without clearing the screen:
|
|
3049
|
+
|
|
3050
|
+
```typescript
|
|
3051
|
+
const result = await ctx.ui.custom<string | null>(
|
|
3052
|
+
(tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
|
|
3053
|
+
{ overlay: true }
|
|
3054
|
+
);
|
|
3055
|
+
```
|
|
3056
|
+
|
|
3057
|
+
For advanced positioning (anchors, margins, percentages, responsive visibility), pass `overlayOptions`. Use `onHandle` to control focus or visibility programmatically:
|
|
3058
|
+
|
|
3059
|
+
```typescript
|
|
3060
|
+
const result = await ctx.ui.custom<string | null>(
|
|
3061
|
+
(tui, theme, keybindings, done) => new MyOverlayComponent({ onClose: done }),
|
|
3062
|
+
{
|
|
3063
|
+
overlay: true,
|
|
3064
|
+
overlayOptions: { anchor: "top-right", width: "50%", margin: 2 },
|
|
3065
|
+
onHandle: (handle) => {
|
|
3066
|
+
handle.focus(); // focus this overlay and bring it to the visual front
|
|
3067
|
+
// handle.unfocus({ target: editorComponent }); // release input to a specific component
|
|
3068
|
+
// handle.setHidden(true/false); // toggle visibility
|
|
3069
|
+
// handle.isHidden(), handle.isFocused(), handle.getBounds()
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
);
|
|
3073
|
+
```
|
|
3074
|
+
|
|
3075
|
+
`overlayOptions` can also be a function, re-evaluated for dynamic positioning. Finish the interaction with `done()`; do not call `handle.hide()` on an overlay created by `ctx.ui.custom()`.
|
|
3076
|
+
|
|
3077
|
+
A focused visible overlay can reclaim input after temporary non-overlay custom UI closes. If you intentionally want another component to keep input while the overlay stays visible, call `handle.unfocus({ target })`. Passing `{ target: null }` releases the overlay without focusing another component.
|
|
3078
|
+
|
|
3079
|
+
See [`OverlayOptions` and `OverlayHandle`](https://github.com/earendil-works/pi/blob/main/packages/tui/src/tui.ts) for the full API and [overlay-qa-tests.ts](../examples/extensions/overlay-qa-tests.ts) for examples.
|
|
3080
|
+
|
|
3081
|
+
### Custom Editor
|
|
3082
|
+
|
|
3083
|
+
Replace the main input editor with a custom implementation (vim mode, emacs mode, etc.):
|
|
3084
|
+
|
|
3085
|
+
```typescript
|
|
3086
|
+
import { CustomEditor, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3087
|
+
import { matchesKey } from "@earendil-works/pi-tui";
|
|
3088
|
+
|
|
3089
|
+
class VimEditor extends CustomEditor {
|
|
3090
|
+
private mode: "normal" | "insert" = "insert";
|
|
3091
|
+
|
|
3092
|
+
handleInput(data: string): void {
|
|
3093
|
+
if (matchesKey(data, "escape") && this.mode === "insert") {
|
|
3094
|
+
this.mode = "normal";
|
|
3095
|
+
return;
|
|
3096
|
+
}
|
|
3097
|
+
if (this.mode === "normal" && data === "i") {
|
|
3098
|
+
this.mode = "insert";
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
super.handleInput(data); // App keybindings + text editing
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
|
|
3105
|
+
export default function (pi: ExtensionAPI) {
|
|
3106
|
+
pi.on("session_start", (_event, ctx) => {
|
|
3107
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) =>
|
|
3108
|
+
new VimEditor(tui, theme, keybindings)
|
|
3109
|
+
);
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
```
|
|
3113
|
+
|
|
3114
|
+
**Key points:**
|
|
3115
|
+
- Extend `CustomEditor` (not base `Editor`) to get app keybindings (escape to abort, ctrl+d, model switching)
|
|
3116
|
+
- Call `super.handleInput(data)` for keys you don't handle
|
|
3117
|
+
- Custom editors keep the standalone working row by default. Pass `{ embedWorkingStatus: true }` as the fourth `CustomEditor` constructor argument to use the built-in editor-border spinner instead.
|
|
3118
|
+
- Factory receives `tui`, `theme`, and `keybindings` from the app
|
|
3119
|
+
- Use `ctx.ui.getEditorComponent()` before `setEditorComponent()` to wrap the previously configured custom editor
|
|
3120
|
+
- Pass `undefined` to restore default: `ctx.ui.setEditorComponent(undefined)`
|
|
3121
|
+
|
|
3122
|
+
To compose with another extension that already replaced the editor, capture the previous factory before setting yours:
|
|
3123
|
+
|
|
3124
|
+
```typescript
|
|
3125
|
+
const previous = ctx.ui.getEditorComponent();
|
|
3126
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) =>
|
|
3127
|
+
new MyEditor(tui, theme, keybindings, { base: previous?.(tui, theme, keybindings) })
|
|
3128
|
+
);
|
|
3129
|
+
```
|
|
3130
|
+
|
|
3131
|
+
See [modal-editor.ts](../examples/extensions/modal-editor.ts) for a complete example with a mode indicator.
|
|
3132
|
+
|
|
3133
|
+
### Message and Entry Rendering
|
|
3134
|
+
|
|
3135
|
+
Register a custom renderer for messages with your `customType`. Use message renderers for content that should participate in LLM context:
|
|
3136
|
+
|
|
3137
|
+
```typescript
|
|
3138
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
3139
|
+
|
|
3140
|
+
pi.registerMessageRenderer("my-extension", (message, options, theme) => {
|
|
3141
|
+
const { expanded, outputPad } = options;
|
|
3142
|
+
let text = theme.fg("accent", `[${message.customType}] `);
|
|
3143
|
+
text += message.content;
|
|
3144
|
+
|
|
3145
|
+
if (expanded && message.details) {
|
|
3146
|
+
text += "\n" + theme.fg("dim", JSON.stringify(message.details, null, 2));
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
return new Text(text, outputPad, 0);
|
|
3150
|
+
});
|
|
3151
|
+
```
|
|
3152
|
+
|
|
3153
|
+
Messages are sent via `pi.sendMessage()`:
|
|
3154
|
+
|
|
3155
|
+
```typescript
|
|
3156
|
+
pi.sendMessage({
|
|
3157
|
+
customType: "my-extension", // Matches registerMessageRenderer
|
|
3158
|
+
content: "Status update",
|
|
3159
|
+
display: true, // Show in TUI
|
|
3160
|
+
details: { ... }, // Available in renderer
|
|
3161
|
+
});
|
|
3162
|
+
```
|
|
3163
|
+
|
|
3164
|
+
For TUI-only content that should not be sent to the LLM, render custom entries instead:
|
|
3165
|
+
|
|
3166
|
+
```typescript
|
|
3167
|
+
pi.registerEntryRenderer("my-card", (entry, options, theme) => {
|
|
3168
|
+
return new Text(theme.fg("accent", JSON.stringify(entry.data)));
|
|
3169
|
+
});
|
|
3170
|
+
|
|
3171
|
+
pi.appendEntry("my-card", { status: "done" });
|
|
3172
|
+
```
|
|
3173
|
+
|
|
3174
|
+
### Theme Colors
|
|
3175
|
+
|
|
3176
|
+
All render functions receive a `theme` object. See [themes.md](themes.md) for creating custom themes and the full color palette.
|
|
3177
|
+
|
|
3178
|
+
```typescript
|
|
3179
|
+
// Foreground colors
|
|
3180
|
+
theme.fg("toolTitle", text) // Tool names
|
|
3181
|
+
theme.fg("accent", text) // Highlights
|
|
3182
|
+
theme.fg("success", text) // Success (green)
|
|
3183
|
+
theme.fg("error", text) // Errors (red)
|
|
3184
|
+
theme.fg("warning", text) // Warnings (yellow)
|
|
3185
|
+
theme.fg("muted", text) // Secondary text
|
|
3186
|
+
theme.fg("dim", text) // Tertiary text
|
|
3187
|
+
|
|
3188
|
+
// Text styles
|
|
3189
|
+
theme.bold(text)
|
|
3190
|
+
theme.italic(text)
|
|
3191
|
+
theme.underline(text)
|
|
3192
|
+
theme.strikethrough(text)
|
|
3193
|
+
|
|
3194
|
+
// Combined foreground, background, and attributes
|
|
3195
|
+
theme.style(text, { fg: "success", bg: "toolSuccessBg", bold: true })
|
|
3196
|
+
```
|
|
3197
|
+
|
|
3198
|
+
`theme.colors` exposes concrete colors and `theme.appearance` is `"dark"` or `"light"`. See [Apply themes correctly](tui.md#apply-themes-correctly).
|
|
3199
|
+
|
|
3200
|
+
For syntax highlighting in custom tool renderers:
|
|
3201
|
+
|
|
3202
|
+
```typescript
|
|
3203
|
+
import { highlightCode, getLanguageFromPath } from "@earendil-works/pi-coding-agent";
|
|
3204
|
+
|
|
3205
|
+
// Highlight code with an explicit language; returns one string per line
|
|
3206
|
+
const lines = highlightCode("const x = 1;", "typescript");
|
|
3207
|
+
|
|
3208
|
+
// Auto-detect language from file path
|
|
3209
|
+
const lang = getLanguageFromPath("/path/to/file.rs"); // "rust", or undefined
|
|
3210
|
+
const highlighted = highlightCode(code, lang);
|
|
3211
|
+
```
|
|
3212
|
+
|
|
3213
|
+
<a id="handle-errors-and-shutdown"></a>
|
|
3214
|
+
|
|
3215
|
+
## Error Handling
|
|
3216
|
+
|
|
3217
|
+
- Extension errors are logged, agent continues
|
|
3218
|
+
- `tool_call` errors block the tool (fail-safe)
|
|
3219
|
+
- `user_bash` errors block the command instead of falling through to local execution
|
|
3220
|
+
- Tool `execute` errors are signaled by throwing or by returning `isError: true`; a thrown error is caught, reported to the LLM as an error result, and execution continues
|
|
3221
|
+
|
|
3222
|
+
<a id="ui-and-modes"></a>
|
|
3223
|
+
<a id="account-for-each-mode"></a>
|
|
3224
|
+
|
|
3225
|
+
## Mode Behavior
|
|
3226
|
+
|
|
3227
|
+
| Mode | `ctx.mode` | `ctx.hasUI` | Notes |
|
|
3228
|
+
|------|------------|-------------|-------|
|
|
3229
|
+
| Interactive | `"tui"` | `true` | Full TUI with terminal rendering |
|
|
3230
|
+
| RPC (`--mode rpc`) | `"rpc"` | `true` | Dialogs and notifications via JSON protocol; `custom()` returns `undefined`, component factories are ignored. See [RPC Extension UI](rpc-extension-ui.md) |
|
|
3231
|
+
| JSON (`--mode json`) | `"json"` | `false` | Event stream to stdout; UI methods are no-ops |
|
|
3232
|
+
| Print (`-p`) | `"print"` | `false` | Extensions run but can't prompt |
|
|
3233
|
+
|
|
3234
|
+
Use `ctx.mode === "tui"` before TUI-specific features (`custom()`, component factories, terminal input). Use `ctx.hasUI` before dialog and notification methods that work in both TUI and RPC modes.
|
|
3235
|
+
|
|
3236
|
+
<a id="use-examples-as-the-implementation-reference"></a>
|
|
3237
|
+
|
|
3238
|
+
## Examples Reference
|
|
3239
|
+
|
|
3240
|
+
All examples in [examples/extensions/](../examples/extensions/).
|
|
3241
|
+
|
|
3242
|
+
| Example | Description | Key APIs |
|
|
3243
|
+
|---------|-------------|----------|
|
|
3244
|
+
| **Tools** |||
|
|
3245
|
+
| `hello.ts` | Minimal tool registration | `registerTool` |
|
|
3246
|
+
| `question.ts` | Tool with user interaction | `registerTool`, `ui.custom`, `renderResult` |
|
|
3247
|
+
| `questionnaire.ts` | Multi-step wizard tool | `registerTool`, `ui.custom` |
|
|
3248
|
+
| `todo.ts` | Stateful tool with branch-aware state in `details` | `registerTool`, `renderResult`, `registerCommand`, `on("session_start")`, `on("session_tree")` |
|
|
3249
|
+
| `dynamic-tools.ts` | Register tools after startup and during commands | `registerTool`, `session_start`, `registerCommand` |
|
|
3250
|
+
| `structured-output.ts` | Final structured-output tool with `terminate: true` | `registerTool`, terminating tool results |
|
|
3251
|
+
| `truncated-tool.ts` | Output truncation example | `registerTool`, `truncateHead` |
|
|
3252
|
+
| `tic-tac-toe.ts` | Tool that must run sequentially | `registerTool`, `executionMode: "sequential"`, `ui.custom` |
|
|
3253
|
+
| `tool-override.ts` | Override built-in read tool | `registerTool` (same name as built-in) |
|
|
3254
|
+
| `built-in-tool-renderer.ts` | Custom rendering for built-in tools | `create*ToolDefinition`, `renderCall`, `renderResult`, `renderShell` |
|
|
3255
|
+
| `minimal-mode.ts` | Collapsed display for built-in tools | Built-in tool overrides, `renderResult` |
|
|
3256
|
+
| **Commands** |||
|
|
3257
|
+
| `pirate.ts` | Modify system prompt per-turn | `registerCommand`, `before_agent_start` |
|
|
3258
|
+
| `summarize.ts` | Conversation summary command | `registerCommand`, `ui.custom` |
|
|
3259
|
+
| `handoff.ts` | Cross-provider model handoff | `registerCommand`, `ui.editor`, `ui.custom` |
|
|
3260
|
+
| `qna.ts` | Q&A with custom UI | `registerCommand`, `ui.custom`, `setEditorText` |
|
|
3261
|
+
| `send-user-message.ts` | Inject user messages | `registerCommand`, `sendUserMessage` |
|
|
3262
|
+
| `reload-runtime.ts` | Reload command and LLM tool handoff | `registerCommand`, `ctx.reload()`, `on("agent_settled")`, `sendUserMessage` |
|
|
3263
|
+
| `shutdown-command.ts` | Graceful shutdown command | `registerCommand`, `shutdown()` |
|
|
3264
|
+
| **Events & Gates** |||
|
|
3265
|
+
| `permission-gate.ts` | Block dangerous commands | `on("tool_call")`, `ui.select` |
|
|
3266
|
+
| `project-trust.ts` | Decide or defer project trust from a user/global or CLI extension | `on("project_trust")`, trust UI, required trust result |
|
|
3267
|
+
| `protected-paths.ts` | Block writes to specific paths | `on("tool_call")` |
|
|
3268
|
+
| `confirm-destructive.ts` | Confirm session changes | `on("session_before_switch")`, `on("session_before_fork")` |
|
|
3269
|
+
| `dirty-repo-guard.ts` | Warn on dirty git repo | `on("session_before_*")`, `exec` |
|
|
3270
|
+
| `input-transform.ts` | Transform user input | `on("input")` |
|
|
3271
|
+
| `input-transform-streaming.ts` | Streaming-aware input transform | `on("input")`, `streamingBehavior` |
|
|
3272
|
+
| `model-status.ts` | React to model changes | `on("model_select")`, `setStatus` |
|
|
3273
|
+
| `provider-payload.ts` | Inspect payloads and provider response headers | `on("before_provider_request")`, `on("after_provider_response")` |
|
|
3274
|
+
| `debug-provider.ts` | View raw provider stream events | `on("provider_stream_event")`, `appendEntry`, `registerEntryRenderer` |
|
|
3275
|
+
| `system-prompt-header.ts` | Display system prompt info | `on("agent_start")`, `getSystemPrompt` |
|
|
3276
|
+
| `claude-rules.ts` | Load rules from files | `on("session_start")`, `on("before_agent_start")` |
|
|
3277
|
+
| `prompt-customizer.ts` | Add context-aware tool guidance using `systemPromptOptions` | `on("before_agent_start")`, `BuildSystemPromptOptions` |
|
|
3278
|
+
| `file-trigger.ts` | File watcher triggers messages | `sendMessage` |
|
|
3279
|
+
| **Compaction & Sessions** |||
|
|
3280
|
+
| `custom-compaction.ts` | Custom compaction summary | `on("session_before_compact")` |
|
|
3281
|
+
| `trigger-compact.ts` | Trigger compaction manually | `compact()` |
|
|
3282
|
+
| `git-checkpoint.ts` | Git stash on turns | `on("turn_start")`, `on("tool_result")`, `on("agent_settled")`, `on("session_before_fork")`, `exec` |
|
|
3283
|
+
| `git-merge-and-resolve.ts` | Fetch, merge, and resolve conflicts | `on("agent_end")`, `exec`, `sendUserMessage` |
|
|
3284
|
+
| `auto-commit-on-exit.ts` | Commit on shutdown | `on("session_shutdown")`, `exec` |
|
|
3285
|
+
| **UI Components** |||
|
|
3286
|
+
| `status-line.ts` | Footer status indicator | `setStatus`, session events |
|
|
3287
|
+
| `working-indicator.ts` | Customize the streaming working indicator | `setWorkingIndicator`, `registerCommand` |
|
|
3288
|
+
| `github-issue-autocomplete.ts` | Add `#1234` issue completions on top of built-in autocomplete by preloading recent open issues from `gh issue list` | `addAutocompleteProvider`, `on("session_start")`, `exec` |
|
|
3289
|
+
| `custom-footer.ts` | Replace footer entirely | `registerCommand`, `setFooter` |
|
|
3290
|
+
| `custom-header.ts` | Replace startup header | `on("session_start")`, `setHeader` |
|
|
3291
|
+
| `modal-editor.ts` | Vim-style modal editor | `setEditorComponent`, `CustomEditor` |
|
|
3292
|
+
| `rainbow-editor.ts` | Custom editor styling | `setEditorComponent` |
|
|
3293
|
+
| `widget-placement.ts` | Widget above/below editor | `setWidget` |
|
|
3294
|
+
| `overlay-test.ts` | Overlay components | `ui.custom` with overlay options |
|
|
3295
|
+
| `overlay-qa-tests.ts` | Comprehensive overlay tests | `ui.custom`, all overlay options |
|
|
3296
|
+
| `notify.ts` | Native terminal notification when the agent is done | `on("agent_settled")` |
|
|
3297
|
+
| `titlebar-spinner.ts` | Spinner in the terminal title while working | `setTitle` |
|
|
3298
|
+
| `hidden-thinking-label.ts` | Label for hidden thinking blocks | `setHiddenThinkingLabel` |
|
|
3299
|
+
| `border-status-editor.ts` | Status in the editor border | `setEditorComponent`, `CustomEditor` |
|
|
3300
|
+
| `rpc-demo.ts` | Every RPC-supported UI method | `ui.*` in RPC mode |
|
|
3301
|
+
| `timed-confirm.ts` | Dialogs with timeout | `ui.confirm` with timeout/signal |
|
|
3302
|
+
| `mac-system-theme.ts` | Auto-switch theme | `setTheme`, `exec` |
|
|
3303
|
+
| **Complex Extensions** |||
|
|
3304
|
+
| `plan-mode/` | Full plan mode implementation | All event types, `registerCommand`, `registerShortcut`, `registerFlag`, `setStatus`, `setWidget`, `sendMessage`, `setActiveTools` |
|
|
3305
|
+
| `preset.ts` | Saveable presets (model, tools, thinking) | `registerCommand`, `registerShortcut`, `registerFlag`, `setModel`, `setActiveTools`, `setThinkingLevel`, `appendEntry` |
|
|
3306
|
+
| `tools.ts` | Toggle tools on/off UI | `registerCommand`, `setActiveTools`, `SettingsList`, session events |
|
|
3307
|
+
| **Remote & Sandbox** |||
|
|
3308
|
+
| `ssh.ts` | SSH remote execution | `registerFlag`, `on("user_bash")`, `on("before_agent_start")`, tool operations |
|
|
3309
|
+
| `interactive-shell.ts` | Persistent shell session | `on("user_bash")` |
|
|
3310
|
+
| `sandbox/` | Sandboxed tool execution | Tool operations |
|
|
3311
|
+
| `gondolin/` | Route built-in tools and `!` commands into a Gondolin micro-VM | Tool operations, built-in tool overrides, `on("user_bash")` |
|
|
3312
|
+
| `subagent/` | Spawn sub-agents | `registerTool`, `exec` |
|
|
3313
|
+
| **Games** |||
|
|
3314
|
+
| `snake.ts` | Snake game | `registerCommand`, `ui.custom`, keyboard handling |
|
|
3315
|
+
| `space-invaders.ts` | Space Invaders game | `registerCommand`, `ui.custom` |
|
|
3316
|
+
| `doom-overlay/` | Doom in overlay | `ui.custom` with overlay |
|
|
3317
|
+
| **Providers** |||
|
|
3318
|
+
| `custom-provider-anthropic/` | Custom Anthropic proxy | `registerProvider` |
|
|
3319
|
+
| `custom-provider-gitlab-duo/` | GitLab Duo integration | `registerProvider` with OAuth |
|
|
3320
|
+
| `jev-router.ts` | Virtual model that routes planning and implementation to different models | `registerVirtualModel` |
|
|
3321
|
+
| **Messages & Communication** |||
|
|
3322
|
+
| `message-renderer.ts` | Custom message rendering | `registerMessageRenderer`, `sendMessage` |
|
|
3323
|
+
| `entry-renderer.ts` | TUI-only custom entry rendering | `registerEntryRenderer`, `appendEntry` |
|
|
3324
|
+
| `event-bus.ts` | Inter-extension events | `pi.events` |
|
|
3325
|
+
| **Session Metadata** |||
|
|
3326
|
+
| `session-name.ts` | Name sessions for selector | `setSessionName`, `getSessionName` |
|
|
3327
|
+
| `bookmark.ts` | Bookmark entries for /tree | `setLabel` |
|
|
3328
|
+
| **Misc** |||
|
|
3329
|
+
| `commands.ts` | List available slash commands | `getCommands` |
|
|
3330
|
+
| `dynamic-resources/` | Add skills, prompts, and themes at runtime | `on("resources_discover")` |
|
|
3331
|
+
| `inline-bash.ts` | Expand inline `!{command}` in user prompts | `on("input")`, `exec` |
|
|
3332
|
+
| `bash-spawn-hook.ts` | Adjust bash command, cwd, and env before execution | `createBashTool`, `spawnHook` |
|
|
3333
|
+
| `with-deps/` | Extension with npm dependencies | Package structure with `package.json` |
|