@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,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Customizer Extension
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates using systemPromptOptions to make informed, context-aware
|
|
5
|
+
* modifications to the system prompt without re-discovering resources.
|
|
6
|
+
*
|
|
7
|
+
* This extension adds tool-specific guidance based on what tools and skills
|
|
8
|
+
* are currently active, respecting whatever the user has configured.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* 1. Copy this file to ~/.pi/agent/extensions/ or your project's .pi/extensions/
|
|
12
|
+
* 2. Use the extension — it automatically adapts to your active tools and skills
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { BuildSystemPromptOptions, ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds tool-specific guidance that adapts to the active tool set.
|
|
19
|
+
* Instead of appending one-size-fits-all instructions, this reads what's
|
|
20
|
+
* actually loaded and tailors the guidance accordingly.
|
|
21
|
+
*/
|
|
22
|
+
function addToolGuidance(options: BuildSystemPromptOptions, basePrompt: string): string {
|
|
23
|
+
const hasTool = (name: string) => options.selectedTools?.includes(name) ?? false;
|
|
24
|
+
|
|
25
|
+
const parts: string[] = [];
|
|
26
|
+
|
|
27
|
+
if (hasTool("read")) {
|
|
28
|
+
parts.push(
|
|
29
|
+
"• Use the `read` tool for file contents (supports text and images).",
|
|
30
|
+
" - For large files, use `offset` and `limit` to read in chunks.",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (hasTool("bash")) {
|
|
35
|
+
parts.push("• Execute commands with the `bash` tool. Use it for file operations like `ls`, `find`, `grep`.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (hasTool("edit")) {
|
|
39
|
+
parts.push(
|
|
40
|
+
"• Use the `edit` tool for precise text replacements in files. Match exact content including whitespace.",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (hasTool("write")) {
|
|
45
|
+
parts.push("• Use the `write` tool to create new files or overwrite existing ones completely.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.skills && options.skills.length > 0) {
|
|
49
|
+
const skillNames = options.skills.map((s) => s.name).join(", ");
|
|
50
|
+
parts.push(`\nAvailable skills: ${skillNames}`, "Use skill documentation for best practices on specific tools.");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (parts.length === 0) {
|
|
54
|
+
return basePrompt;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return `${basePrompt}
|
|
58
|
+
|
|
59
|
+
## Tool Guidance
|
|
60
|
+
|
|
61
|
+
${parts.join("\n")}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Merges extension instructions with user-provided append prompts.
|
|
67
|
+
* This respects whatever the user configured via --append-system-prompt
|
|
68
|
+
* flags or files, rather than duplicating that work.
|
|
69
|
+
*/
|
|
70
|
+
function mergeWithUserAppend(options: BuildSystemPromptOptions): string {
|
|
71
|
+
const userAppend = options.appendSystemPrompt;
|
|
72
|
+
const extensionSpecific = `
|
|
73
|
+
## Extension-Added Context
|
|
74
|
+
|
|
75
|
+
This prompt includes tool guidance and skill information loaded dynamically.
|
|
76
|
+
If you have additional requirements, configure them via --append-system-prompt or project context files.
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
if (userAppend) {
|
|
80
|
+
return `${userAppend}\n\n${extensionSpecific}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return extensionSpecific;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default function promptCustomizer(pi: ExtensionAPI) {
|
|
87
|
+
pi.on("before_agent_start", async (event) => {
|
|
88
|
+
const { systemPrompt, systemPromptOptions } = event;
|
|
89
|
+
|
|
90
|
+
const customPrompt = addToolGuidance(systemPromptOptions, systemPrompt);
|
|
91
|
+
const appendSection = mergeWithUserAppend(systemPromptOptions);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
systemPrompt: `${customPrompt}${appendSection}`,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protected Paths Extension
|
|
3
|
+
*
|
|
4
|
+
* Blocks write and edit operations to protected paths.
|
|
5
|
+
* Useful for preventing accidental modifications to sensitive files.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
|
|
10
|
+
export default function (pi: ExtensionAPI) {
|
|
11
|
+
const protectedPaths = [".env", ".git/", "node_modules/"];
|
|
12
|
+
|
|
13
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
14
|
+
if (event.toolName !== "write" && event.toolName !== "edit") {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const path = event.input.path as string;
|
|
19
|
+
const isProtected = protectedPaths.some((p) => path.includes(p));
|
|
20
|
+
|
|
21
|
+
if (isProtected) {
|
|
22
|
+
if (ctx.hasUI) {
|
|
23
|
+
ctx.ui.notify(`Blocked write to protected path: ${path}`, "warning");
|
|
24
|
+
}
|
|
25
|
+
return { block: true, reason: `Path "${path}" is protected` };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CONFIG_DIR_NAME, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
export default function (pi: ExtensionAPI) {
|
|
6
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
7
|
+
const logFile = join(ctx.cwd, CONFIG_DIR_NAME, "provider-payload.log");
|
|
8
|
+
appendFileSync(logFile, `${JSON.stringify(event.payload, null, 2)}\n\n`, "utf8");
|
|
9
|
+
|
|
10
|
+
// Optional: replace the payload instead of only logging it.
|
|
11
|
+
// return { ...event.payload, temperature: 0 };
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
pi.on("after_provider_response", (event, ctx) => {
|
|
15
|
+
const logFile = join(ctx.cwd, CONFIG_DIR_NAME, "provider-payload.log");
|
|
16
|
+
appendFileSync(logFile, `[${event.status}] ${JSON.stringify(event.headers)}\n\n`, "utf8");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Q&A extraction extension - extracts questions from assistant responses
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates the "prompt generator" pattern:
|
|
5
|
+
* 1. /qna command gets the last assistant message
|
|
6
|
+
* 2. Shows a spinner while extracting (hides editor)
|
|
7
|
+
* 3. Loads the result into the editor for user to fill in answers
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { UserMessage } from "@earendil-works/pi-ai";
|
|
11
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import { BorderedLoader } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
|
|
14
|
+
const SYSTEM_PROMPT = `You are a question extractor. Given text from a conversation, extract any questions that need answering and format them for the user to fill in.
|
|
15
|
+
|
|
16
|
+
Output format:
|
|
17
|
+
- List each question on its own line, prefixed with "Q: "
|
|
18
|
+
- After each question, add a blank line for the answer prefixed with "A: "
|
|
19
|
+
- If no questions are found, output "No questions found in the last message."
|
|
20
|
+
|
|
21
|
+
Example output:
|
|
22
|
+
Q: What is your preferred database?
|
|
23
|
+
A:
|
|
24
|
+
|
|
25
|
+
Q: Should we use TypeScript or JavaScript?
|
|
26
|
+
A:
|
|
27
|
+
|
|
28
|
+
Keep questions in the order they appeared. Be concise.`;
|
|
29
|
+
|
|
30
|
+
export default function (pi: ExtensionAPI) {
|
|
31
|
+
pi.registerCommand("qna", {
|
|
32
|
+
description: "Extract questions from last assistant message into editor",
|
|
33
|
+
handler: async (_args, ctx) => {
|
|
34
|
+
if (ctx.mode !== "tui") {
|
|
35
|
+
ctx.ui.notify("qna requires interactive mode", "error");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!ctx.model) {
|
|
40
|
+
ctx.ui.notify("No model selected", "error");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Find the last assistant message on the current branch
|
|
45
|
+
const branch = ctx.sessionManager.getBranch();
|
|
46
|
+
let lastAssistantText: string | undefined;
|
|
47
|
+
|
|
48
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
49
|
+
const entry = branch[i];
|
|
50
|
+
if (entry.type === "message") {
|
|
51
|
+
const msg = entry.message;
|
|
52
|
+
if ("role" in msg && msg.role === "assistant") {
|
|
53
|
+
if (msg.stopReason !== "stop") {
|
|
54
|
+
ctx.ui.notify(`Last assistant message incomplete (${msg.stopReason})`, "error");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const textParts = msg.content
|
|
58
|
+
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
|
59
|
+
.map((c) => c.text);
|
|
60
|
+
if (textParts.length > 0) {
|
|
61
|
+
lastAssistantText = textParts.join("\n");
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!lastAssistantText) {
|
|
69
|
+
ctx.ui.notify("No assistant messages found", "error");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Run extraction with loader UI
|
|
74
|
+
const result = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
|
|
75
|
+
const loader = new BorderedLoader(tui, theme, `Extracting questions using ${ctx.model!.id}...`);
|
|
76
|
+
loader.onAbort = () => done(null);
|
|
77
|
+
|
|
78
|
+
// Do the work
|
|
79
|
+
const doExtract = async () => {
|
|
80
|
+
const userMessage: UserMessage = {
|
|
81
|
+
role: "user",
|
|
82
|
+
content: [{ type: "text", text: lastAssistantText! }],
|
|
83
|
+
timestamp: Date.now(),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const response = await ctx.modelRegistry.complete(
|
|
87
|
+
ctx.model!,
|
|
88
|
+
{ systemPrompt: SYSTEM_PROMPT, messages: [userMessage] },
|
|
89
|
+
{ signal: loader.signal },
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (response.stopReason === "aborted") {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return response.content
|
|
97
|
+
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
|
98
|
+
.map((c) => c.text)
|
|
99
|
+
.join("\n");
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
doExtract()
|
|
103
|
+
.then(done)
|
|
104
|
+
.catch(() => done(null));
|
|
105
|
+
|
|
106
|
+
return loader;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (result === null) {
|
|
110
|
+
ctx.ui.notify("Cancelled", "info");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ctx.ui.setEditorText(result);
|
|
115
|
+
ctx.ui.notify("Questions loaded. Edit and submit when ready.", "info");
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Question Tool - Single question with options
|
|
3
|
+
* Full custom UI: options list + inline editor for "Type something..."
|
|
4
|
+
* Escape in editor returns to options, Escape in options cancels
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
Editor,
|
|
10
|
+
type EditorTheme,
|
|
11
|
+
Key,
|
|
12
|
+
matchesKey,
|
|
13
|
+
Text,
|
|
14
|
+
visibleWidth,
|
|
15
|
+
wrapTextWithAnsi,
|
|
16
|
+
} from "@earendil-works/pi-tui";
|
|
17
|
+
import { Type } from "typebox";
|
|
18
|
+
|
|
19
|
+
interface OptionWithDesc {
|
|
20
|
+
label: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type DisplayOption = OptionWithDesc & { isOther?: boolean };
|
|
25
|
+
|
|
26
|
+
interface QuestionDetails {
|
|
27
|
+
question: string;
|
|
28
|
+
options: string[];
|
|
29
|
+
answer: string | null;
|
|
30
|
+
wasCustom?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Options with labels and optional descriptions
|
|
34
|
+
const OptionSchema = Type.Object({
|
|
35
|
+
label: Type.String({ description: "Display label for the option" }),
|
|
36
|
+
description: Type.Optional(Type.String({ description: "Optional description shown below label" })),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const QuestionParams = Type.Object({
|
|
40
|
+
question: Type.String({ description: "The question to ask the user" }),
|
|
41
|
+
options: Type.Array(OptionSchema, { description: "Options for the user to choose from" }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export default function question(pi: ExtensionAPI) {
|
|
45
|
+
pi.registerTool({
|
|
46
|
+
name: "question",
|
|
47
|
+
label: "Question",
|
|
48
|
+
description: "Ask the user a question and let them pick from options. Use when you need user input to proceed.",
|
|
49
|
+
parameters: QuestionParams,
|
|
50
|
+
executionMode: "sequential",
|
|
51
|
+
|
|
52
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
53
|
+
if (ctx.mode !== "tui") {
|
|
54
|
+
return {
|
|
55
|
+
content: [{ type: "text", text: "Error: UI not available (running in non-interactive mode)" }],
|
|
56
|
+
details: {
|
|
57
|
+
question: params.question,
|
|
58
|
+
options: params.options.map((o) => o.label),
|
|
59
|
+
answer: null,
|
|
60
|
+
} as QuestionDetails,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (params.options.length === 0) {
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: "text", text: "Error: No options provided" }],
|
|
67
|
+
details: { question: params.question, options: [], answer: null } as QuestionDetails,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const allOptions: DisplayOption[] = [...params.options, { label: "Type something.", isOther: true }];
|
|
72
|
+
|
|
73
|
+
const result = await ctx.ui.custom<{ answer: string; wasCustom: boolean; index?: number } | null>(
|
|
74
|
+
(tui, theme, _kb, done) => {
|
|
75
|
+
let optionIndex = 0;
|
|
76
|
+
let editMode = false;
|
|
77
|
+
let cachedLines: string[] | undefined;
|
|
78
|
+
|
|
79
|
+
const editorTheme: EditorTheme = {
|
|
80
|
+
borderColor: (s) => theme.fg("accent", s),
|
|
81
|
+
selectList: {
|
|
82
|
+
selectedPrefix: (t) => theme.fg("accent", t),
|
|
83
|
+
selectedText: (t) => theme.fg("accent", t),
|
|
84
|
+
description: (t) => theme.fg("muted", t),
|
|
85
|
+
scrollInfo: (t) => theme.fg("dim", t),
|
|
86
|
+
noMatch: (t) => theme.fg("warning", t),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
const editor = new Editor(tui, editorTheme);
|
|
90
|
+
|
|
91
|
+
editor.onSubmit = (value) => {
|
|
92
|
+
const trimmed = value.trim();
|
|
93
|
+
if (trimmed) {
|
|
94
|
+
done({ answer: trimmed, wasCustom: true });
|
|
95
|
+
} else {
|
|
96
|
+
editMode = false;
|
|
97
|
+
editor.setText("");
|
|
98
|
+
refresh();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
function refresh() {
|
|
103
|
+
cachedLines = undefined;
|
|
104
|
+
tui.requestRender();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function handleInput(data: string) {
|
|
108
|
+
if (editMode) {
|
|
109
|
+
if (matchesKey(data, Key.escape)) {
|
|
110
|
+
editMode = false;
|
|
111
|
+
editor.setText("");
|
|
112
|
+
refresh();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
editor.handleInput(data);
|
|
116
|
+
refresh();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (matchesKey(data, Key.up)) {
|
|
121
|
+
optionIndex = Math.max(0, optionIndex - 1);
|
|
122
|
+
refresh();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (matchesKey(data, Key.down)) {
|
|
126
|
+
optionIndex = Math.min(allOptions.length - 1, optionIndex + 1);
|
|
127
|
+
refresh();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (matchesKey(data, Key.enter)) {
|
|
132
|
+
const selected = allOptions[optionIndex];
|
|
133
|
+
if (selected.isOther) {
|
|
134
|
+
editMode = true;
|
|
135
|
+
refresh();
|
|
136
|
+
} else {
|
|
137
|
+
done({ answer: selected.label, wasCustom: false, index: optionIndex + 1 });
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (matchesKey(data, Key.escape)) {
|
|
143
|
+
done(null);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function render(width: number): string[] {
|
|
148
|
+
if (cachedLines) return cachedLines;
|
|
149
|
+
|
|
150
|
+
const lines: string[] = [];
|
|
151
|
+
const renderWidth = Math.max(1, width);
|
|
152
|
+
|
|
153
|
+
function addWrapped(text: string) {
|
|
154
|
+
lines.push(...wrapTextWithAnsi(text, renderWidth));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function addWrappedWithPrefix(prefix: string, text: string) {
|
|
158
|
+
const prefixWidth = visibleWidth(prefix);
|
|
159
|
+
if (prefixWidth >= renderWidth) {
|
|
160
|
+
addWrapped(prefix + text);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const wrapped = wrapTextWithAnsi(text, renderWidth - prefixWidth);
|
|
164
|
+
const continuationPrefix = " ".repeat(prefixWidth);
|
|
165
|
+
for (let i = 0; i < wrapped.length; i++) {
|
|
166
|
+
lines.push(`${i === 0 ? prefix : continuationPrefix}${wrapped[i]}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
lines.push(theme.fg("accent", "─".repeat(renderWidth)));
|
|
171
|
+
addWrappedWithPrefix(" ", theme.fg("text", params.question));
|
|
172
|
+
lines.push("");
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < allOptions.length; i++) {
|
|
175
|
+
const opt = allOptions[i];
|
|
176
|
+
const selected = i === optionIndex;
|
|
177
|
+
const isOther = opt.isOther === true;
|
|
178
|
+
const prefix = selected ? theme.fg("accent", "> ") : " ";
|
|
179
|
+
const label = `${i + 1}. ${opt.label}${isOther && editMode ? " ✎" : ""}`;
|
|
180
|
+
const color = selected || (isOther && editMode) ? "accent" : "text";
|
|
181
|
+
|
|
182
|
+
addWrappedWithPrefix(prefix, theme.fg(color, label));
|
|
183
|
+
|
|
184
|
+
// Show description if present
|
|
185
|
+
if (opt.description) {
|
|
186
|
+
addWrappedWithPrefix(" ", theme.fg("muted", opt.description));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (editMode) {
|
|
191
|
+
lines.push("");
|
|
192
|
+
addWrappedWithPrefix(" ", theme.fg("muted", "Your answer:"));
|
|
193
|
+
for (const line of editor.render(Math.max(1, renderWidth - 2))) {
|
|
194
|
+
lines.push(` ${line}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
lines.push("");
|
|
199
|
+
if (editMode) {
|
|
200
|
+
addWrappedWithPrefix(" ", theme.fg("dim", "Enter to submit • Esc to go back"));
|
|
201
|
+
} else {
|
|
202
|
+
addWrappedWithPrefix(" ", theme.fg("dim", "↑↓ navigate • Enter to select • Esc to cancel"));
|
|
203
|
+
}
|
|
204
|
+
lines.push(theme.fg("accent", "─".repeat(renderWidth)));
|
|
205
|
+
|
|
206
|
+
cachedLines = lines;
|
|
207
|
+
return lines;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
render,
|
|
212
|
+
invalidate: () => {
|
|
213
|
+
cachedLines = undefined;
|
|
214
|
+
},
|
|
215
|
+
handleInput,
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Build simple options list for details
|
|
221
|
+
const simpleOptions = params.options.map((o) => o.label);
|
|
222
|
+
|
|
223
|
+
if (!result) {
|
|
224
|
+
return {
|
|
225
|
+
content: [{ type: "text", text: "User cancelled the selection" }],
|
|
226
|
+
details: { question: params.question, options: simpleOptions, answer: null } as QuestionDetails,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (result.wasCustom) {
|
|
231
|
+
return {
|
|
232
|
+
content: [{ type: "text", text: `User wrote: ${result.answer}` }],
|
|
233
|
+
details: {
|
|
234
|
+
question: params.question,
|
|
235
|
+
options: simpleOptions,
|
|
236
|
+
answer: result.answer,
|
|
237
|
+
wasCustom: true,
|
|
238
|
+
} as QuestionDetails,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
content: [{ type: "text", text: `User selected: ${result.index}. ${result.answer}` }],
|
|
243
|
+
details: {
|
|
244
|
+
question: params.question,
|
|
245
|
+
options: simpleOptions,
|
|
246
|
+
answer: result.answer,
|
|
247
|
+
wasCustom: false,
|
|
248
|
+
} as QuestionDetails,
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
renderCall(args, theme, _context) {
|
|
253
|
+
let text = theme.fg("toolTitle", theme.bold("question ")) + theme.fg("muted", args.question);
|
|
254
|
+
const opts = Array.isArray(args.options) ? args.options : [];
|
|
255
|
+
if (opts.length) {
|
|
256
|
+
const labels = opts.map((o: OptionWithDesc) => o.label);
|
|
257
|
+
const numbered = [...labels, "Type something."].map((o, i) => `${i + 1}. ${o}`);
|
|
258
|
+
text += `\n${theme.fg("dim", ` Options: ${numbered.join(", ")}`)}`;
|
|
259
|
+
}
|
|
260
|
+
return new Text(text, 0, 0);
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
renderResult(result, _options, theme, _context) {
|
|
264
|
+
const details = result.details as QuestionDetails | undefined;
|
|
265
|
+
if (!details) {
|
|
266
|
+
const text = result.content[0];
|
|
267
|
+
return new Text(text?.type === "text" ? text.text : "", 0, 0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (details.answer === null) {
|
|
271
|
+
return new Text(theme.fg("warning", "Cancelled"), 0, 0);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (details.wasCustom) {
|
|
275
|
+
return new Text(
|
|
276
|
+
theme.fg("success", "✓ ") + theme.fg("muted", "(wrote) ") + theme.fg("accent", details.answer),
|
|
277
|
+
0,
|
|
278
|
+
0,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
const idx = details.options.indexOf(details.answer) + 1;
|
|
282
|
+
const display = idx > 0 ? `${idx}. ${details.answer}` : details.answer;
|
|
283
|
+
return new Text(theme.fg("success", "✓ ") + theme.fg("accent", display), 0, 0);
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
}
|