@korallis/k-pi 0.1.0
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 +5619 -0
- package/LICENSE +21 -0
- package/NOTICE +66 -0
- package/README.md +723 -0
- package/dist/bundle/chunks/anthropic-messages-IBCPCIJO.js +45 -0
- package/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/bundle/chunks/azure-openai-responses-GUUG57CZ.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +74 -0
- package/dist/bundle/chunks/chunk-4L3WN2XY.js +2 -0
- package/dist/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
- package/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
- package/dist/bundle/chunks/chunk-AXIIZGTV.js +2 -0
- package/dist/bundle/chunks/chunk-CO7LIZG5.js +2 -0
- package/dist/bundle/chunks/chunk-DRQDKNXA.js +2 -0
- package/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
- package/dist/bundle/chunks/chunk-HOFU6X66.js +50 -0
- package/dist/bundle/chunks/chunk-JUUC5AZY.js +2 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/bundle/chunks/chunk-MNAIPA3J.js +2 -0
- package/dist/bundle/chunks/chunk-NBBFIJUL.js +11 -0
- package/dist/bundle/chunks/chunk-NUHFSC37.js +25 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/bundle/chunks/chunk-TRDNDS6A.js +4 -0
- package/dist/bundle/chunks/chunk-UAQELI3K.js +2 -0
- package/dist/bundle/chunks/chunk-X5QHCKY4.js +1653 -0
- package/dist/bundle/chunks/chunk-XDUWOHPL.js +6 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-YRXF7C4I.js +2 -0
- package/dist/bundle/chunks/google-vertex-BVZ6VBRQ.js +2 -0
- package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/lib-HGQMNYVT.js +9 -0
- package/dist/bundle/chunks/mistral-conversations-Q3AWZJAZ.js +5 -0
- package/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
- package/dist/bundle/chunks/openai-codex-responses-GJVBJXLB.js +8 -0
- package/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/bundle/chunks/openai-completions-OICQQ5JB.js +7 -0
- package/dist/bundle/chunks/openai-responses-P5LIZTXX.js +2 -0
- package/dist/bundle/chunks/openrouter-images-XTKS2AS3.js +2 -0
- package/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/bundle/chunks/pi-messages-TPFH44NP.js +8 -0
- package/dist/bundle/chunks/radius.js +75 -0
- package/dist/bundle/chunks/src-UK77SYZE.js +4 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli.js +3 -0
- package/dist/bundle/client.js +2 -0
- package/dist/bundle/index.js +2 -0
- package/dist/bundle/rpc-entry.js +3 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1864 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/kpi/graphs/coding-loop.auto.json +377 -0
- package/dist/kpi/graphs/coding-loop.gated.json +417 -0
- package/dist/kpi/graphs/spec-first.json +40 -0
- package/dist/kpi/kstack/NOTICE +5 -0
- package/dist/kpi/kstack/UPSTREAM.md +23 -0
- package/dist/kpi/kstack/generated/LICENSE +21 -0
- package/dist/kpi/kstack/generated/skills/architect/SKILL.md +83 -0
- package/dist/kpi/kstack/generated/skills/architect/references/design-red-flags.md +33 -0
- package/dist/kpi/kstack/generated/skills/architect/references/rationale-template.md +35 -0
- package/dist/kpi/kstack/generated/skills/architect/references/runner-prompt.md +20 -0
- package/dist/kpi/kstack/generated/skills/arena/SKILL.md +29 -0
- package/dist/kpi/kstack/generated/skills/blast-radius/SKILL.md +50 -0
- package/dist/kpi/kstack/generated/skills/bro/SKILL.md +7 -0
- package/dist/kpi/kstack/generated/skills/create-verification-skill/SKILL.md +44 -0
- package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/dist/kpi/kstack/generated/skills/figure-it-out/SKILL.md +55 -0
- package/dist/kpi/kstack/generated/skills/how/SKILL.md +135 -0
- package/dist/kpi/kstack/generated/skills/how/references/critic-prompt.md +59 -0
- package/dist/kpi/kstack/generated/skills/how/references/critique-rubric.md +58 -0
- package/dist/kpi/kstack/generated/skills/how/references/explainer-prompt.md +55 -0
- package/dist/kpi/kstack/generated/skills/how/references/explorer-prompt.md +52 -0
- package/dist/kpi/kstack/generated/skills/interrogate/SKILL.md +113 -0
- package/dist/kpi/kstack/generated/skills/interrogate/references/code-quality-review.md +47 -0
- package/dist/kpi/kstack/generated/skills/interrogate/references/lead-judgment.md +58 -0
- package/dist/kpi/kstack/generated/skills/interrogate/references/reviewer-prompt.md +72 -0
- package/dist/kpi/kstack/generated/skills/interrogate/references/rubric.md +77 -0
- package/dist/kpi/kstack/generated/skills/k-agent/SKILL.md +17 -0
- package/dist/kpi/kstack/generated/skills/k-mode/SKILL.md +64 -0
- package/dist/kpi/kstack/generated/skills/k-stack-principles/SKILL.md +24 -0
- package/dist/kpi/kstack/generated/skills/maintain-verification-skill/SKILL.md +39 -0
- package/dist/kpi/kstack/generated/skills/no-comments/SKILL.md +24 -0
- package/dist/kpi/kstack/generated/skills/playbook-arena/SKILL.md +20 -0
- package/dist/kpi/kstack/generated/skills/playbook-autonomous-run/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/playbook-autopilot-full/SKILL.md +20 -0
- package/dist/kpi/kstack/generated/skills/playbook-autopilot-stack/SKILL.md +20 -0
- package/dist/kpi/kstack/generated/skills/playbook-bug-fix/SKILL.md +21 -0
- package/dist/kpi/kstack/generated/skills/playbook-feature/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/playbook-investigation/SKILL.md +21 -0
- package/dist/kpi/kstack/generated/skills/playbook-shipping/SKILL.md +18 -0
- package/dist/kpi/kstack/generated/skills/playbook-swarm/SKILL.md +20 -0
- package/dist/kpi/kstack/generated/skills/principle-boundary-discipline/SKILL.md +34 -0
- package/dist/kpi/kstack/generated/skills/principle-build-the-lever/SKILL.md +23 -0
- package/dist/kpi/kstack/generated/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
- package/dist/kpi/kstack/generated/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
- package/dist/kpi/kstack/generated/skills/principle-experience-first/SKILL.md +19 -0
- package/dist/kpi/kstack/generated/skills/principle-fix-root-causes/SKILL.md +23 -0
- package/dist/kpi/kstack/generated/skills/principle-foundational-thinking/SKILL.md +21 -0
- package/dist/kpi/kstack/generated/skills/principle-guard-the-context-window/SKILL.md +17 -0
- package/dist/kpi/kstack/generated/skills/principle-laziness-protocol/SKILL.md +18 -0
- package/dist/kpi/kstack/generated/skills/principle-make-operations-idempotent/SKILL.md +24 -0
- package/dist/kpi/kstack/generated/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/principle-minimize-reader-load/SKILL.md +23 -0
- package/dist/kpi/kstack/generated/skills/principle-model-the-domain/SKILL.md +26 -0
- package/dist/kpi/kstack/generated/skills/principle-never-block-on-the-human/SKILL.md +23 -0
- package/dist/kpi/kstack/generated/skills/principle-outcome-oriented-execution/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/principle-prove-it-works/SKILL.md +33 -0
- package/dist/kpi/kstack/generated/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
- package/dist/kpi/kstack/generated/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
- package/dist/kpi/kstack/generated/skills/principle-sequence-verifiable-units/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/principle-subtract-before-you-add/SKILL.md +22 -0
- package/dist/kpi/kstack/generated/skills/principle-type-system-discipline/SKILL.md +31 -0
- package/dist/kpi/kstack/generated/skills/recall/SKILL.md +35 -0
- package/dist/kpi/kstack/generated/skills/reflect/SKILL.md +77 -0
- package/dist/kpi/kstack/generated/skills/reflect/references/divergent-reviewer.md +43 -0
- package/dist/kpi/kstack/generated/skills/reflect/references/judgment-reviewer.md +42 -0
- package/dist/kpi/kstack/generated/skills/reflect/references/synthesizer.md +56 -0
- package/dist/kpi/kstack/generated/skills/reflect/references/tooling-reviewer.md +57 -0
- package/dist/kpi/kstack/generated/skills/setup-kstack/SKILL.md +48 -0
- package/dist/kpi/kstack/generated/skills/show-me-your-work/SKILL.md +82 -0
- package/dist/kpi/kstack/generated/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/dist/kpi/kstack/generated/skills/show-me-your-work/scripts/log.sh +40 -0
- package/dist/kpi/kstack/generated/skills/swarm/SKILL.md +27 -0
- package/dist/kpi/kstack/generated/skills/tdd/SKILL.md +44 -0
- package/dist/kpi/kstack/generated/skills/teach/SKILL.md +21 -0
- package/dist/kpi/kstack/generated/skills/technical-writing/SKILL.md +130 -0
- package/dist/kpi/kstack/generated/skills/typescript-best-practices/SKILL.md +30 -0
- package/dist/kpi/kstack/generated/skills/typescript-best-practices/references/patterns.md +313 -0
- package/dist/kpi/kstack/generated/skills/unslop/SKILL.md +81 -0
- package/dist/kpi/kstack/generated/skills/why/SKILL.md +230 -0
- package/dist/kpi/kstack/generated/skills/why/references/epistemics.md +144 -0
- package/dist/kpi/kstack/generated/skills/why/references/investigator-prompt.md +103 -0
- package/dist/kpi/kstack/generated/skills/why/references/source-playbook.md +17 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/code-archaeology.md +88 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/databricks.md +70 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/datadog.md +99 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/incident-postmortem.md +15 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/linear.md +48 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/notion.md +55 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/sentry.md +100 -0
- package/dist/kpi/kstack/generated/skills/why/references/sources/slack.md +54 -0
- package/dist/kpi/kstack/generated/skills/why/references/synthesizer-prompt.md +135 -0
- package/dist/kpi/kstack/model-ladder.md +50 -0
- package/dist/kpi/kstack/provenance.json +17 -0
- package/dist/kpi/prompts/implement.md +6 -0
- package/dist/kpi/prompts/plan.md +6 -0
- package/dist/kpi/prompts/review.md +6 -0
- package/dist/kpi/prompts/ship.md +6 -0
- package/dist/kpi/prompts/specify.md +6 -0
- package/dist/kpi/prompts/verify.md +6 -0
- package/dist/kpi/schemas/event.schema.json +1314 -0
- package/dist/kpi/schemas/evidence.schema.json +43 -0
- package/dist/kpi/schemas/stack.schema.json +102 -0
- package/dist/kpi/schemas/task.schema.json +165 -0
- package/dist/kpi/schemas/verdict.schema.json +44 -0
- package/dist/kpi/skills/concise-output/SKILL.md +10 -0
- package/dist/kpi/skills/context-pack/SKILL.md +10 -0
- package/dist/kpi/skills/conventional-commit/SKILL.md +12 -0
- package/dist/kpi/skills/isolated-review/SKILL.md +10 -0
- package/dist/kpi/skills/kg-claim/SKILL.md +26 -0
- package/dist/kpi/skills/minimalist/SKILL.md +24 -0
- package/dist/kpi/skills/quality-gates/SKILL.md +10 -0
- package/dist/kpi/skills/spec-first/SKILL.md +10 -0
- package/dist/kpi/skills/tdd-cycle/SKILL.md +10 -0
- package/dist/kpi/templates/AGENTS.md +31 -0
- package/dist/kpi/templates/APPEND_SYSTEM.md +13 -0
- package/dist/kpi/templates/context-pack/product.md +7 -0
- package/dist/kpi/templates/context-pack/structure.md +7 -0
- package/dist/kpi/templates/context-pack/tech.md +9 -0
- package/dist/kpi/templates/policy.json +17 -0
- package/dist/kpi/themes/loop-amber.json +82 -0
- package/dist/kpi/themes/protocol-blue.json +82 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/theme/dark.json +90 -0
- package/dist/modes/interactive/theme/light.json +89 -0
- package/dist/modes/interactive/theme/theme-schema.json +352 -0
- package/docs/compaction.md +418 -0
- package/docs/containerization.md +111 -0
- package/docs/custom-provider.md +777 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +156 -0
- package/docs/environment-variables.md +97 -0
- package/docs/extensions.md +3020 -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 +84 -0
- package/docs/json.md +98 -0
- package/docs/keybindings.md +236 -0
- package/docs/llama-cpp.md +101 -0
- package/docs/models.md +571 -0
- package/docs/packages.md +228 -0
- package/docs/prompt-templates.md +96 -0
- package/docs/providers.md +317 -0
- package/docs/quickstart.md +167 -0
- package/docs/rpc.md +1618 -0
- package/docs/sdk.md +1219 -0
- package/docs/security.md +59 -0
- package/docs/session-format.md +438 -0
- package/docs/sessions.md +145 -0
- package/docs/settings.md +369 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +232 -0
- package/docs/terminal-setup.md +177 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +320 -0
- package/docs/tmux.md +63 -0
- package/docs/tui.md +942 -0
- package/docs/usage.md +311 -0
- package/docs/windows.md +39 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +213 -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 +249 -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 +611 -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/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 +79 -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 +185 -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/kimi-deferred-tools.ts +61 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -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 +390 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +97 -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 +37 -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 +1038 -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 +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -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-extension-ui.ts +641 -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/README.md +140 -0
- package/package.json +55 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Extension - OS-level sandboxing for bash commands
|
|
3
|
+
*
|
|
4
|
+
* Uses @anthropic-ai/sandbox-runtime to enforce filesystem and network
|
|
5
|
+
* restrictions on bash commands at the OS level (sandbox-exec on macOS,
|
|
6
|
+
* bubblewrap on Linux).
|
|
7
|
+
*
|
|
8
|
+
* Note: this example intentionally overrides the built-in `bash` tool to show
|
|
9
|
+
* how built-in tools can be replaced. Alternatively, you could sandbox `bash`
|
|
10
|
+
* via `tool_call` input mutation without replacing the tool.
|
|
11
|
+
*
|
|
12
|
+
* Config files (merged, project takes precedence):
|
|
13
|
+
* - ~/.pi/agent/extensions/sandbox.json (global)
|
|
14
|
+
* - <cwd>/.pi/sandbox.json (project-local)
|
|
15
|
+
*
|
|
16
|
+
* Example .pi/sandbox.json:
|
|
17
|
+
* ```json
|
|
18
|
+
* {
|
|
19
|
+
* "enabled": true,
|
|
20
|
+
* "network": {
|
|
21
|
+
* "allowedDomains": ["github.com", "*.github.com"],
|
|
22
|
+
* "deniedDomains": []
|
|
23
|
+
* },
|
|
24
|
+
* "filesystem": {
|
|
25
|
+
* "denyRead": ["~/.ssh", "~/.aws"],
|
|
26
|
+
* "allowWrite": [".", "/tmp"],
|
|
27
|
+
* "denyWrite": [".env"]
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Usage:
|
|
33
|
+
* - `pi -e ./sandbox` - sandbox enabled with default/config settings
|
|
34
|
+
* - `pi -e ./sandbox --no-sandbox` - disable sandboxing
|
|
35
|
+
* - `/sandbox` - show current sandbox configuration
|
|
36
|
+
*
|
|
37
|
+
* Setup:
|
|
38
|
+
* 1. Copy sandbox/ directory to ~/.pi/agent/extensions/
|
|
39
|
+
* 2. Run `npm install` in ~/.pi/agent/extensions/sandbox/
|
|
40
|
+
*
|
|
41
|
+
* Linux also requires: bubblewrap, socat, ripgrep
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
import { spawn } from "node:child_process";
|
|
45
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
46
|
+
import { join } from "node:path";
|
|
47
|
+
import { SandboxManager, type SandboxRuntimeConfig } from "@anthropic-ai/sandbox-runtime";
|
|
48
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
49
|
+
import { type BashOperations, CONFIG_DIR_NAME, createBashTool, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
50
|
+
|
|
51
|
+
interface SandboxConfig extends SandboxRuntimeConfig {
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const DEFAULT_CONFIG: SandboxConfig = {
|
|
56
|
+
enabled: true,
|
|
57
|
+
network: {
|
|
58
|
+
allowedDomains: [
|
|
59
|
+
"npmjs.org",
|
|
60
|
+
"*.npmjs.org",
|
|
61
|
+
"registry.npmjs.org",
|
|
62
|
+
"registry.yarnpkg.com",
|
|
63
|
+
"pypi.org",
|
|
64
|
+
"*.pypi.org",
|
|
65
|
+
"github.com",
|
|
66
|
+
"*.github.com",
|
|
67
|
+
"api.github.com",
|
|
68
|
+
"raw.githubusercontent.com",
|
|
69
|
+
],
|
|
70
|
+
deniedDomains: [],
|
|
71
|
+
},
|
|
72
|
+
filesystem: {
|
|
73
|
+
denyRead: ["~/.ssh", "~/.aws", "~/.gnupg"],
|
|
74
|
+
allowWrite: [".", "/tmp"],
|
|
75
|
+
denyWrite: [".env", ".env.*", "*.pem", "*.key"],
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function loadConfig(cwd: string): SandboxConfig {
|
|
80
|
+
const projectConfigPath = join(cwd, CONFIG_DIR_NAME, "sandbox.json");
|
|
81
|
+
const globalConfigPath = join(getAgentDir(), "extensions", "sandbox.json");
|
|
82
|
+
|
|
83
|
+
let globalConfig: Partial<SandboxConfig> = {};
|
|
84
|
+
let projectConfig: Partial<SandboxConfig> = {};
|
|
85
|
+
|
|
86
|
+
if (existsSync(globalConfigPath)) {
|
|
87
|
+
try {
|
|
88
|
+
globalConfig = JSON.parse(readFileSync(globalConfigPath, "utf-8"));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error(`Warning: Could not parse ${globalConfigPath}: ${e}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (existsSync(projectConfigPath)) {
|
|
95
|
+
try {
|
|
96
|
+
projectConfig = JSON.parse(readFileSync(projectConfigPath, "utf-8"));
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(`Warning: Could not parse ${projectConfigPath}: ${e}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return deepMerge(deepMerge(DEFAULT_CONFIG, globalConfig), projectConfig);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function deepMerge(base: SandboxConfig, overrides: Partial<SandboxConfig>): SandboxConfig {
|
|
106
|
+
const result: SandboxConfig = { ...base };
|
|
107
|
+
|
|
108
|
+
if (overrides.enabled !== undefined) result.enabled = overrides.enabled;
|
|
109
|
+
if (overrides.network) {
|
|
110
|
+
result.network = { ...base.network, ...overrides.network };
|
|
111
|
+
}
|
|
112
|
+
if (overrides.filesystem) {
|
|
113
|
+
result.filesystem = { ...base.filesystem, ...overrides.filesystem };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const extOverrides = overrides as {
|
|
117
|
+
ignoreViolations?: Record<string, string[]>;
|
|
118
|
+
enableWeakerNestedSandbox?: boolean;
|
|
119
|
+
};
|
|
120
|
+
const extResult = result as { ignoreViolations?: Record<string, string[]>; enableWeakerNestedSandbox?: boolean };
|
|
121
|
+
|
|
122
|
+
if (extOverrides.ignoreViolations) {
|
|
123
|
+
extResult.ignoreViolations = extOverrides.ignoreViolations;
|
|
124
|
+
}
|
|
125
|
+
if (extOverrides.enableWeakerNestedSandbox !== undefined) {
|
|
126
|
+
extResult.enableWeakerNestedSandbox = extOverrides.enableWeakerNestedSandbox;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function createSandboxedBashOps(): BashOperations {
|
|
133
|
+
return {
|
|
134
|
+
async exec(command, cwd, { onData, signal, timeout }) {
|
|
135
|
+
if (!existsSync(cwd)) {
|
|
136
|
+
throw new Error(`Working directory does not exist: ${cwd}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const wrappedCommand = await SandboxManager.wrapWithSandbox(command);
|
|
140
|
+
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
const child = spawn("bash", ["-c", wrappedCommand], {
|
|
143
|
+
cwd,
|
|
144
|
+
detached: true,
|
|
145
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
let timedOut = false;
|
|
149
|
+
let timeoutHandle: NodeJS.Timeout | undefined;
|
|
150
|
+
|
|
151
|
+
if (timeout !== undefined && timeout > 0) {
|
|
152
|
+
timeoutHandle = setTimeout(() => {
|
|
153
|
+
timedOut = true;
|
|
154
|
+
if (child.pid) {
|
|
155
|
+
try {
|
|
156
|
+
process.kill(-child.pid, "SIGKILL");
|
|
157
|
+
} catch {
|
|
158
|
+
child.kill("SIGKILL");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}, timeout * 1000);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
child.stdout?.on("data", onData);
|
|
165
|
+
child.stderr?.on("data", onData);
|
|
166
|
+
|
|
167
|
+
child.on("error", (err) => {
|
|
168
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
169
|
+
reject(err);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const onAbort = () => {
|
|
173
|
+
if (child.pid) {
|
|
174
|
+
try {
|
|
175
|
+
process.kill(-child.pid, "SIGKILL");
|
|
176
|
+
} catch {
|
|
177
|
+
child.kill("SIGKILL");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
183
|
+
|
|
184
|
+
child.on("close", (code) => {
|
|
185
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
186
|
+
signal?.removeEventListener("abort", onAbort);
|
|
187
|
+
|
|
188
|
+
if (signal?.aborted) {
|
|
189
|
+
reject(new Error("aborted"));
|
|
190
|
+
} else if (timedOut) {
|
|
191
|
+
reject(new Error(`timeout:${timeout}`));
|
|
192
|
+
} else {
|
|
193
|
+
resolve({ exitCode: code });
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default function (pi: ExtensionAPI) {
|
|
202
|
+
pi.registerFlag("no-sandbox", {
|
|
203
|
+
description: "Disable OS-level sandboxing for bash commands",
|
|
204
|
+
type: "boolean",
|
|
205
|
+
default: false,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const localCwd = process.cwd();
|
|
209
|
+
const localBash = createBashTool(localCwd);
|
|
210
|
+
|
|
211
|
+
let sandboxEnabled = false;
|
|
212
|
+
let sandboxInitialized = false;
|
|
213
|
+
|
|
214
|
+
pi.registerTool({
|
|
215
|
+
...localBash,
|
|
216
|
+
label: "bash (sandboxed)",
|
|
217
|
+
async execute(id, params, signal, onUpdate, _ctx) {
|
|
218
|
+
if (!sandboxEnabled || !sandboxInitialized) {
|
|
219
|
+
return localBash.execute(id, params, signal, onUpdate);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const sandboxedBash = createBashTool(localCwd, {
|
|
223
|
+
operations: createSandboxedBashOps(),
|
|
224
|
+
});
|
|
225
|
+
return sandboxedBash.execute(id, params, signal, onUpdate);
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
pi.on("user_bash", () => {
|
|
230
|
+
if (!sandboxEnabled || !sandboxInitialized) return;
|
|
231
|
+
return { operations: createSandboxedBashOps() };
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
235
|
+
const noSandbox = pi.getFlag("no-sandbox") as boolean;
|
|
236
|
+
|
|
237
|
+
if (noSandbox) {
|
|
238
|
+
sandboxEnabled = false;
|
|
239
|
+
ctx.ui.notify("Sandbox disabled via --no-sandbox", "warning");
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const config = loadConfig(ctx.cwd);
|
|
244
|
+
|
|
245
|
+
if (!config.enabled) {
|
|
246
|
+
sandboxEnabled = false;
|
|
247
|
+
ctx.ui.notify("Sandbox disabled via config", "info");
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const platform = process.platform;
|
|
252
|
+
if (platform !== "darwin" && platform !== "linux") {
|
|
253
|
+
sandboxEnabled = false;
|
|
254
|
+
ctx.ui.notify(`Sandbox not supported on ${platform}`, "warning");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
const configExt = config as unknown as {
|
|
260
|
+
ignoreViolations?: Record<string, string[]>;
|
|
261
|
+
enableWeakerNestedSandbox?: boolean;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
await SandboxManager.initialize({
|
|
265
|
+
network: config.network,
|
|
266
|
+
filesystem: config.filesystem,
|
|
267
|
+
ignoreViolations: configExt.ignoreViolations,
|
|
268
|
+
enableWeakerNestedSandbox: configExt.enableWeakerNestedSandbox,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
sandboxEnabled = true;
|
|
272
|
+
sandboxInitialized = true;
|
|
273
|
+
|
|
274
|
+
const networkCount = config.network?.allowedDomains?.length ?? 0;
|
|
275
|
+
const writeCount = config.filesystem?.allowWrite?.length ?? 0;
|
|
276
|
+
ctx.ui.setStatus(
|
|
277
|
+
"sandbox",
|
|
278
|
+
ctx.ui.theme.fg("accent", `🔒 Sandbox: ${networkCount} domains, ${writeCount} write paths`),
|
|
279
|
+
);
|
|
280
|
+
ctx.ui.notify("Sandbox initialized", "info");
|
|
281
|
+
} catch (err) {
|
|
282
|
+
sandboxEnabled = false;
|
|
283
|
+
ctx.ui.notify(`Sandbox initialization failed: ${err instanceof Error ? err.message : err}`, "error");
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
pi.on("session_shutdown", async () => {
|
|
288
|
+
if (sandboxInitialized) {
|
|
289
|
+
try {
|
|
290
|
+
await SandboxManager.reset();
|
|
291
|
+
} catch {
|
|
292
|
+
// Ignore cleanup errors
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
pi.registerCommand("sandbox", {
|
|
298
|
+
description: "Show sandbox configuration",
|
|
299
|
+
handler: async (_args, ctx) => {
|
|
300
|
+
if (!sandboxEnabled) {
|
|
301
|
+
ctx.ui.notify("Sandbox is disabled", "info");
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const config = loadConfig(ctx.cwd);
|
|
306
|
+
const lines = [
|
|
307
|
+
"Sandbox Configuration:",
|
|
308
|
+
"",
|
|
309
|
+
"Network:",
|
|
310
|
+
` Allowed: ${config.network?.allowedDomains?.join(", ") || "(none)"}`,
|
|
311
|
+
` Denied: ${config.network?.deniedDomains?.join(", ") || "(none)"}`,
|
|
312
|
+
"",
|
|
313
|
+
"Filesystem:",
|
|
314
|
+
` Deny Read: ${config.filesystem?.denyRead?.join(", ") || "(none)"}`,
|
|
315
|
+
` Allow Write: ${config.filesystem?.allowWrite?.join(", ") || "(none)"}`,
|
|
316
|
+
` Deny Write: ${config.filesystem?.denyWrite?.join(", ") || "(none)"}`,
|
|
317
|
+
];
|
|
318
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-extension-sandbox",
|
|
3
|
+
"version": "1.14.4",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "pi-extension-sandbox",
|
|
9
|
+
"version": "1.14.4",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@anthropic-ai/sandbox-runtime": "^0.0.26"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"node_modules/@anthropic-ai/sandbox-runtime": {
|
|
15
|
+
"version": "0.0.26",
|
|
16
|
+
"resolved": "https://registry.npmjs.org/@anthropic-ai/sandbox-runtime/-/sandbox-runtime-0.0.26.tgz",
|
|
17
|
+
"integrity": "sha512-DYV5LSsVMnzq0lbfaYMSpxZPUMAx4+hy343dRss+pVCLIfF62qOhxpYfZ5TmOk1GTDQm5f9wPprMNSStmnsV4w==",
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@pondwader/socks5-server": "^1.0.10",
|
|
21
|
+
"@types/lodash-es": "^4.17.12",
|
|
22
|
+
"commander": "^12.1.0",
|
|
23
|
+
"lodash-es": "^4.17.21",
|
|
24
|
+
"shell-quote": "^1.8.3",
|
|
25
|
+
"zod": "^3.24.1"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"srt": "dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"node_modules/@pondwader/socks5-server": {
|
|
35
|
+
"version": "1.0.10",
|
|
36
|
+
"resolved": "https://registry.npmjs.org/@pondwader/socks5-server/-/socks5-server-1.0.10.tgz",
|
|
37
|
+
"integrity": "sha512-bQY06wzzR8D2+vVCUoBsr5QS2U6UgPUQRmErNwtsuI6vLcyRKkafjkr3KxbtGFf9aBBIV2mcvlsKD1UYaIV+sg==",
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
},
|
|
40
|
+
"node_modules/@types/lodash": {
|
|
41
|
+
"version": "4.17.23",
|
|
42
|
+
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.23.tgz",
|
|
43
|
+
"integrity": "sha512-RDvF6wTulMPjrNdCoYRC8gNR880JNGT8uB+REUpC2Ns4pRqQJhGz90wh7rgdXDPpCczF3VGktDuFGVnz8zP7HA==",
|
|
44
|
+
"license": "MIT"
|
|
45
|
+
},
|
|
46
|
+
"node_modules/@types/lodash-es": {
|
|
47
|
+
"version": "4.17.12",
|
|
48
|
+
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
|
|
49
|
+
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@types/lodash": "*"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"node_modules/commander": {
|
|
56
|
+
"version": "12.1.0",
|
|
57
|
+
"resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz",
|
|
58
|
+
"integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==",
|
|
59
|
+
"license": "MIT",
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"node_modules/lodash-es": {
|
|
65
|
+
"version": "4.18.1",
|
|
66
|
+
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz",
|
|
67
|
+
"integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==",
|
|
68
|
+
"license": "MIT"
|
|
69
|
+
},
|
|
70
|
+
"node_modules/shell-quote": {
|
|
71
|
+
"version": "1.8.3",
|
|
72
|
+
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
|
|
73
|
+
"integrity": "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==",
|
|
74
|
+
"license": "MIT",
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">= 0.4"
|
|
77
|
+
},
|
|
78
|
+
"funding": {
|
|
79
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"node_modules/zod": {
|
|
83
|
+
"version": "3.25.76",
|
|
84
|
+
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
|
85
|
+
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
|
86
|
+
"license": "MIT",
|
|
87
|
+
"funding": {
|
|
88
|
+
"url": "https://github.com/sponsors/colinhacks"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-extension-sandbox",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.14.4",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "echo 'nothing to clean'",
|
|
8
|
+
"build": "echo 'nothing to build'",
|
|
9
|
+
"check": "echo 'nothing to check'"
|
|
10
|
+
},
|
|
11
|
+
"pi": {
|
|
12
|
+
"extensions": [
|
|
13
|
+
"./index.ts"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@anthropic-ai/sandbox-runtime": "0.0.26"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send User Message Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates pi.sendUserMessage() for sending user messages from extensions.
|
|
5
|
+
* Unlike pi.sendMessage() which sends custom messages, sendUserMessage() sends
|
|
6
|
+
* actual user messages that appear in the conversation as if typed by the user.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* /ask What is 2+2? - Sends a user message (always triggers a turn)
|
|
10
|
+
* /steer Focus on X - Sends while streaming with steer delivery
|
|
11
|
+
* /followup And then? - Sends while streaming with followUp delivery
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
|
|
16
|
+
export default function (pi: ExtensionAPI) {
|
|
17
|
+
// Simple command that sends a user message
|
|
18
|
+
pi.registerCommand("ask", {
|
|
19
|
+
description: "Send a user message to the agent",
|
|
20
|
+
handler: async (args, ctx) => {
|
|
21
|
+
if (!args.trim()) {
|
|
22
|
+
ctx.ui.notify("Usage: /ask <message>", "warning");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// sendUserMessage always triggers a turn when not streaming
|
|
27
|
+
// If streaming, it will throw (no deliverAs specified)
|
|
28
|
+
if (!ctx.isIdle()) {
|
|
29
|
+
ctx.ui.notify("Agent is busy. Use /steer or /followup instead.", "warning");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pi.sendUserMessage(args);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Command that steers the agent mid-conversation
|
|
38
|
+
pi.registerCommand("steer", {
|
|
39
|
+
description: "Send a steering message (interrupts current processing)",
|
|
40
|
+
handler: async (args, ctx) => {
|
|
41
|
+
if (!args.trim()) {
|
|
42
|
+
ctx.ui.notify("Usage: /steer <message>", "warning");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ctx.isIdle()) {
|
|
47
|
+
// Not streaming, just send normally
|
|
48
|
+
pi.sendUserMessage(args);
|
|
49
|
+
} else {
|
|
50
|
+
// Streaming - use steer to interrupt
|
|
51
|
+
pi.sendUserMessage(args, { deliverAs: "steer" });
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Command that queues a follow-up message
|
|
57
|
+
pi.registerCommand("followup", {
|
|
58
|
+
description: "Queue a follow-up message (waits for current processing)",
|
|
59
|
+
handler: async (args, ctx) => {
|
|
60
|
+
if (!args.trim()) {
|
|
61
|
+
ctx.ui.notify("Usage: /followup <message>", "warning");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (ctx.isIdle()) {
|
|
66
|
+
// Not streaming, just send normally
|
|
67
|
+
pi.sendUserMessage(args);
|
|
68
|
+
} else {
|
|
69
|
+
// Streaming - queue as follow-up
|
|
70
|
+
pi.sendUserMessage(args, { deliverAs: "followUp" });
|
|
71
|
+
ctx.ui.notify("Follow-up queued", "info");
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Example with content array (text + images would go here)
|
|
77
|
+
pi.registerCommand("askwith", {
|
|
78
|
+
description: "Send a user message with structured content",
|
|
79
|
+
handler: async (args, ctx) => {
|
|
80
|
+
if (!args.trim()) {
|
|
81
|
+
ctx.ui.notify("Usage: /askwith <message>", "warning");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!ctx.isIdle()) {
|
|
86
|
+
ctx.ui.notify("Agent is busy", "warning");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// sendUserMessage accepts string or (TextContent | ImageContent)[]
|
|
91
|
+
pi.sendUserMessage([
|
|
92
|
+
{ type: "text", text: `User request: ${args}` },
|
|
93
|
+
{ type: "text", text: "Please respond concisely." },
|
|
94
|
+
]);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session naming example.
|
|
3
|
+
*
|
|
4
|
+
* Shows setSessionName/getSessionName to give sessions friendly names
|
|
5
|
+
* that appear in the session selector instead of the first message.
|
|
6
|
+
*
|
|
7
|
+
* Usage: /session-name [name] - set or show session name
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
export default function (pi: ExtensionAPI) {
|
|
13
|
+
pi.registerCommand("session-name", {
|
|
14
|
+
description: "Set or show session name (usage: /session-name [new name])",
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
const name = args.trim();
|
|
17
|
+
|
|
18
|
+
if (name) {
|
|
19
|
+
pi.setSessionName(name);
|
|
20
|
+
ctx.ui.notify(`Session named: ${name}`, "info");
|
|
21
|
+
} else {
|
|
22
|
+
const current = pi.getSessionName();
|
|
23
|
+
ctx.ui.notify(current ? `Session: ${current}` : "No session name set", "info");
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shutdown Command Extension
|
|
3
|
+
*
|
|
4
|
+
* Adds a /quit command that allows extensions to trigger clean shutdown.
|
|
5
|
+
* Demonstrates how extensions can use ctx.shutdown() to exit pi cleanly.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
|
|
11
|
+
export default function (pi: ExtensionAPI) {
|
|
12
|
+
// Register a /quit command that cleanly exits pi
|
|
13
|
+
pi.registerCommand("quit", {
|
|
14
|
+
description: "Exit pi cleanly",
|
|
15
|
+
handler: async (_args, ctx) => {
|
|
16
|
+
ctx.shutdown();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// You can also create a tool that shuts down after completing work
|
|
21
|
+
pi.registerTool({
|
|
22
|
+
name: "finish_and_exit",
|
|
23
|
+
label: "Finish and Exit",
|
|
24
|
+
description: "Complete a task and exit pi",
|
|
25
|
+
parameters: Type.Object({}),
|
|
26
|
+
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
27
|
+
// Do any final work here...
|
|
28
|
+
// Request graceful shutdown (deferred until agent is idle)
|
|
29
|
+
ctx.shutdown();
|
|
30
|
+
|
|
31
|
+
// This return is sent to the LLM before shutdown occurs
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: "text", text: "Shutdown requested. Exiting after this response." }],
|
|
34
|
+
details: {},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// You could also create a more complex tool with parameters
|
|
40
|
+
pi.registerTool({
|
|
41
|
+
name: "deploy_and_exit",
|
|
42
|
+
label: "Deploy and Exit",
|
|
43
|
+
description: "Deploy the application and exit pi",
|
|
44
|
+
parameters: Type.Object({
|
|
45
|
+
environment: Type.String({ description: "Target environment (e.g., production, staging)" }),
|
|
46
|
+
}),
|
|
47
|
+
async execute(_toolCallId, params, _signal, onUpdate, ctx) {
|
|
48
|
+
onUpdate?.({ content: [{ type: "text", text: `Deploying to ${params.environment}...` }], details: {} });
|
|
49
|
+
|
|
50
|
+
// Example deployment logic
|
|
51
|
+
// const result = await pi.exec("npm", ["run", "deploy", params.environment], { signal });
|
|
52
|
+
|
|
53
|
+
// On success, request graceful shutdown
|
|
54
|
+
onUpdate?.({ content: [{ type: "text", text: "Deployment complete, exiting..." }], details: {} });
|
|
55
|
+
ctx.shutdown();
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
content: [{ type: "text", text: "Done! Shutdown requested." }],
|
|
59
|
+
details: { environment: params.environment },
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|