@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.
Files changed (348) hide show
  1. package/CHANGELOG.md +5619 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +66 -0
  4. package/README.md +723 -0
  5. package/dist/bundle/chunks/anthropic-messages-IBCPCIJO.js +45 -0
  6. package/dist/bundle/chunks/anthropic.js +75 -0
  7. package/dist/bundle/chunks/azure-openai-responses-GUUG57CZ.js +2 -0
  8. package/dist/bundle/chunks/bedrock-converse-stream.js +74 -0
  9. package/dist/bundle/chunks/chunk-4L3WN2XY.js +2 -0
  10. package/dist/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
  11. package/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
  12. package/dist/bundle/chunks/chunk-AXIIZGTV.js +2 -0
  13. package/dist/bundle/chunks/chunk-CO7LIZG5.js +2 -0
  14. package/dist/bundle/chunks/chunk-DRQDKNXA.js +2 -0
  15. package/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
  16. package/dist/bundle/chunks/chunk-HOFU6X66.js +50 -0
  17. package/dist/bundle/chunks/chunk-JUUC5AZY.js +2 -0
  18. package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  19. package/dist/bundle/chunks/chunk-MNAIPA3J.js +2 -0
  20. package/dist/bundle/chunks/chunk-NBBFIJUL.js +11 -0
  21. package/dist/bundle/chunks/chunk-NUHFSC37.js +25 -0
  22. package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  23. package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  24. package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  25. package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
  26. package/dist/bundle/chunks/chunk-TRDNDS6A.js +4 -0
  27. package/dist/bundle/chunks/chunk-UAQELI3K.js +2 -0
  28. package/dist/bundle/chunks/chunk-X5QHCKY4.js +1653 -0
  29. package/dist/bundle/chunks/chunk-XDUWOHPL.js +6 -0
  30. package/dist/bundle/chunks/github-copilot.js +2 -0
  31. package/dist/bundle/chunks/google-generative-ai-YRXF7C4I.js +2 -0
  32. package/dist/bundle/chunks/google-vertex-BVZ6VBRQ.js +2 -0
  33. package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +13 -0
  34. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  35. package/dist/bundle/chunks/kimi-coding.js +2 -0
  36. package/dist/bundle/chunks/lib-HGQMNYVT.js +9 -0
  37. package/dist/bundle/chunks/mistral-conversations-Q3AWZJAZ.js +5 -0
  38. package/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
  39. package/dist/bundle/chunks/openai-codex-responses-GJVBJXLB.js +8 -0
  40. package/dist/bundle/chunks/openai-codex.js +75 -0
  41. package/dist/bundle/chunks/openai-completions-OICQQ5JB.js +7 -0
  42. package/dist/bundle/chunks/openai-responses-P5LIZTXX.js +2 -0
  43. package/dist/bundle/chunks/openrouter-images-XTKS2AS3.js +2 -0
  44. package/dist/bundle/chunks/openrouter.js +75 -0
  45. package/dist/bundle/chunks/pi-messages-TPFH44NP.js +8 -0
  46. package/dist/bundle/chunks/radius.js +75 -0
  47. package/dist/bundle/chunks/src-UK77SYZE.js +4 -0
  48. package/dist/bundle/chunks/xai.js +2 -0
  49. package/dist/bundle/cli.js +3 -0
  50. package/dist/bundle/client.js +2 -0
  51. package/dist/bundle/index.js +2 -0
  52. package/dist/bundle/rpc-entry.js +3 -0
  53. package/dist/core/export-html/template.css +1066 -0
  54. package/dist/core/export-html/template.html +55 -0
  55. package/dist/core/export-html/template.js +1864 -0
  56. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  57. package/dist/core/export-html/vendor/marked.min.js +78 -0
  58. package/dist/kpi/graphs/coding-loop.auto.json +377 -0
  59. package/dist/kpi/graphs/coding-loop.gated.json +417 -0
  60. package/dist/kpi/graphs/spec-first.json +40 -0
  61. package/dist/kpi/kstack/NOTICE +5 -0
  62. package/dist/kpi/kstack/UPSTREAM.md +23 -0
  63. package/dist/kpi/kstack/generated/LICENSE +21 -0
  64. package/dist/kpi/kstack/generated/skills/architect/SKILL.md +83 -0
  65. package/dist/kpi/kstack/generated/skills/architect/references/design-red-flags.md +33 -0
  66. package/dist/kpi/kstack/generated/skills/architect/references/rationale-template.md +35 -0
  67. package/dist/kpi/kstack/generated/skills/architect/references/runner-prompt.md +20 -0
  68. package/dist/kpi/kstack/generated/skills/arena/SKILL.md +29 -0
  69. package/dist/kpi/kstack/generated/skills/blast-radius/SKILL.md +50 -0
  70. package/dist/kpi/kstack/generated/skills/bro/SKILL.md +7 -0
  71. package/dist/kpi/kstack/generated/skills/create-verification-skill/SKILL.md +44 -0
  72. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
  73. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
  74. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
  75. package/dist/kpi/kstack/generated/skills/figure-it-out/SKILL.md +55 -0
  76. package/dist/kpi/kstack/generated/skills/how/SKILL.md +135 -0
  77. package/dist/kpi/kstack/generated/skills/how/references/critic-prompt.md +59 -0
  78. package/dist/kpi/kstack/generated/skills/how/references/critique-rubric.md +58 -0
  79. package/dist/kpi/kstack/generated/skills/how/references/explainer-prompt.md +55 -0
  80. package/dist/kpi/kstack/generated/skills/how/references/explorer-prompt.md +52 -0
  81. package/dist/kpi/kstack/generated/skills/interrogate/SKILL.md +113 -0
  82. package/dist/kpi/kstack/generated/skills/interrogate/references/code-quality-review.md +47 -0
  83. package/dist/kpi/kstack/generated/skills/interrogate/references/lead-judgment.md +58 -0
  84. package/dist/kpi/kstack/generated/skills/interrogate/references/reviewer-prompt.md +72 -0
  85. package/dist/kpi/kstack/generated/skills/interrogate/references/rubric.md +77 -0
  86. package/dist/kpi/kstack/generated/skills/k-agent/SKILL.md +17 -0
  87. package/dist/kpi/kstack/generated/skills/k-mode/SKILL.md +64 -0
  88. package/dist/kpi/kstack/generated/skills/k-stack-principles/SKILL.md +24 -0
  89. package/dist/kpi/kstack/generated/skills/maintain-verification-skill/SKILL.md +39 -0
  90. package/dist/kpi/kstack/generated/skills/no-comments/SKILL.md +24 -0
  91. package/dist/kpi/kstack/generated/skills/playbook-arena/SKILL.md +20 -0
  92. package/dist/kpi/kstack/generated/skills/playbook-autonomous-run/SKILL.md +22 -0
  93. package/dist/kpi/kstack/generated/skills/playbook-autopilot-full/SKILL.md +20 -0
  94. package/dist/kpi/kstack/generated/skills/playbook-autopilot-stack/SKILL.md +20 -0
  95. package/dist/kpi/kstack/generated/skills/playbook-bug-fix/SKILL.md +21 -0
  96. package/dist/kpi/kstack/generated/skills/playbook-feature/SKILL.md +22 -0
  97. package/dist/kpi/kstack/generated/skills/playbook-investigation/SKILL.md +21 -0
  98. package/dist/kpi/kstack/generated/skills/playbook-shipping/SKILL.md +18 -0
  99. package/dist/kpi/kstack/generated/skills/playbook-swarm/SKILL.md +20 -0
  100. package/dist/kpi/kstack/generated/skills/principle-boundary-discipline/SKILL.md +34 -0
  101. package/dist/kpi/kstack/generated/skills/principle-build-the-lever/SKILL.md +23 -0
  102. package/dist/kpi/kstack/generated/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
  103. package/dist/kpi/kstack/generated/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
  104. package/dist/kpi/kstack/generated/skills/principle-experience-first/SKILL.md +19 -0
  105. package/dist/kpi/kstack/generated/skills/principle-fix-root-causes/SKILL.md +23 -0
  106. package/dist/kpi/kstack/generated/skills/principle-foundational-thinking/SKILL.md +21 -0
  107. package/dist/kpi/kstack/generated/skills/principle-guard-the-context-window/SKILL.md +17 -0
  108. package/dist/kpi/kstack/generated/skills/principle-laziness-protocol/SKILL.md +18 -0
  109. package/dist/kpi/kstack/generated/skills/principle-make-operations-idempotent/SKILL.md +24 -0
  110. package/dist/kpi/kstack/generated/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
  111. package/dist/kpi/kstack/generated/skills/principle-minimize-reader-load/SKILL.md +23 -0
  112. package/dist/kpi/kstack/generated/skills/principle-model-the-domain/SKILL.md +26 -0
  113. package/dist/kpi/kstack/generated/skills/principle-never-block-on-the-human/SKILL.md +23 -0
  114. package/dist/kpi/kstack/generated/skills/principle-outcome-oriented-execution/SKILL.md +22 -0
  115. package/dist/kpi/kstack/generated/skills/principle-prove-it-works/SKILL.md +33 -0
  116. package/dist/kpi/kstack/generated/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
  117. package/dist/kpi/kstack/generated/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
  118. package/dist/kpi/kstack/generated/skills/principle-sequence-verifiable-units/SKILL.md +22 -0
  119. package/dist/kpi/kstack/generated/skills/principle-subtract-before-you-add/SKILL.md +22 -0
  120. package/dist/kpi/kstack/generated/skills/principle-type-system-discipline/SKILL.md +31 -0
  121. package/dist/kpi/kstack/generated/skills/recall/SKILL.md +35 -0
  122. package/dist/kpi/kstack/generated/skills/reflect/SKILL.md +77 -0
  123. package/dist/kpi/kstack/generated/skills/reflect/references/divergent-reviewer.md +43 -0
  124. package/dist/kpi/kstack/generated/skills/reflect/references/judgment-reviewer.md +42 -0
  125. package/dist/kpi/kstack/generated/skills/reflect/references/synthesizer.md +56 -0
  126. package/dist/kpi/kstack/generated/skills/reflect/references/tooling-reviewer.md +57 -0
  127. package/dist/kpi/kstack/generated/skills/setup-kstack/SKILL.md +48 -0
  128. package/dist/kpi/kstack/generated/skills/show-me-your-work/SKILL.md +82 -0
  129. package/dist/kpi/kstack/generated/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  130. package/dist/kpi/kstack/generated/skills/show-me-your-work/scripts/log.sh +40 -0
  131. package/dist/kpi/kstack/generated/skills/swarm/SKILL.md +27 -0
  132. package/dist/kpi/kstack/generated/skills/tdd/SKILL.md +44 -0
  133. package/dist/kpi/kstack/generated/skills/teach/SKILL.md +21 -0
  134. package/dist/kpi/kstack/generated/skills/technical-writing/SKILL.md +130 -0
  135. package/dist/kpi/kstack/generated/skills/typescript-best-practices/SKILL.md +30 -0
  136. package/dist/kpi/kstack/generated/skills/typescript-best-practices/references/patterns.md +313 -0
  137. package/dist/kpi/kstack/generated/skills/unslop/SKILL.md +81 -0
  138. package/dist/kpi/kstack/generated/skills/why/SKILL.md +230 -0
  139. package/dist/kpi/kstack/generated/skills/why/references/epistemics.md +144 -0
  140. package/dist/kpi/kstack/generated/skills/why/references/investigator-prompt.md +103 -0
  141. package/dist/kpi/kstack/generated/skills/why/references/source-playbook.md +17 -0
  142. package/dist/kpi/kstack/generated/skills/why/references/sources/code-archaeology.md +88 -0
  143. package/dist/kpi/kstack/generated/skills/why/references/sources/databricks.md +70 -0
  144. package/dist/kpi/kstack/generated/skills/why/references/sources/datadog.md +99 -0
  145. package/dist/kpi/kstack/generated/skills/why/references/sources/incident-postmortem.md +15 -0
  146. package/dist/kpi/kstack/generated/skills/why/references/sources/linear.md +48 -0
  147. package/dist/kpi/kstack/generated/skills/why/references/sources/notion.md +55 -0
  148. package/dist/kpi/kstack/generated/skills/why/references/sources/sentry.md +100 -0
  149. package/dist/kpi/kstack/generated/skills/why/references/sources/slack.md +54 -0
  150. package/dist/kpi/kstack/generated/skills/why/references/synthesizer-prompt.md +135 -0
  151. package/dist/kpi/kstack/model-ladder.md +50 -0
  152. package/dist/kpi/kstack/provenance.json +17 -0
  153. package/dist/kpi/prompts/implement.md +6 -0
  154. package/dist/kpi/prompts/plan.md +6 -0
  155. package/dist/kpi/prompts/review.md +6 -0
  156. package/dist/kpi/prompts/ship.md +6 -0
  157. package/dist/kpi/prompts/specify.md +6 -0
  158. package/dist/kpi/prompts/verify.md +6 -0
  159. package/dist/kpi/schemas/event.schema.json +1314 -0
  160. package/dist/kpi/schemas/evidence.schema.json +43 -0
  161. package/dist/kpi/schemas/stack.schema.json +102 -0
  162. package/dist/kpi/schemas/task.schema.json +165 -0
  163. package/dist/kpi/schemas/verdict.schema.json +44 -0
  164. package/dist/kpi/skills/concise-output/SKILL.md +10 -0
  165. package/dist/kpi/skills/context-pack/SKILL.md +10 -0
  166. package/dist/kpi/skills/conventional-commit/SKILL.md +12 -0
  167. package/dist/kpi/skills/isolated-review/SKILL.md +10 -0
  168. package/dist/kpi/skills/kg-claim/SKILL.md +26 -0
  169. package/dist/kpi/skills/minimalist/SKILL.md +24 -0
  170. package/dist/kpi/skills/quality-gates/SKILL.md +10 -0
  171. package/dist/kpi/skills/spec-first/SKILL.md +10 -0
  172. package/dist/kpi/skills/tdd-cycle/SKILL.md +10 -0
  173. package/dist/kpi/templates/AGENTS.md +31 -0
  174. package/dist/kpi/templates/APPEND_SYSTEM.md +13 -0
  175. package/dist/kpi/templates/context-pack/product.md +7 -0
  176. package/dist/kpi/templates/context-pack/structure.md +7 -0
  177. package/dist/kpi/templates/context-pack/tech.md +9 -0
  178. package/dist/kpi/templates/policy.json +17 -0
  179. package/dist/kpi/themes/loop-amber.json +82 -0
  180. package/dist/kpi/themes/protocol-blue.json +82 -0
  181. package/dist/modes/interactive/assets/clankolas.png +0 -0
  182. package/dist/modes/interactive/theme/dark.json +90 -0
  183. package/dist/modes/interactive/theme/light.json +89 -0
  184. package/dist/modes/interactive/theme/theme-schema.json +352 -0
  185. package/docs/compaction.md +418 -0
  186. package/docs/containerization.md +111 -0
  187. package/docs/custom-provider.md +777 -0
  188. package/docs/development.md +71 -0
  189. package/docs/docs.json +156 -0
  190. package/docs/environment-variables.md +97 -0
  191. package/docs/extensions.md +3020 -0
  192. package/docs/images/doom-extension.png +0 -0
  193. package/docs/images/exy.png +0 -0
  194. package/docs/images/interactive-mode.png +0 -0
  195. package/docs/images/tree-view.png +0 -0
  196. package/docs/index.md +84 -0
  197. package/docs/json.md +98 -0
  198. package/docs/keybindings.md +236 -0
  199. package/docs/llama-cpp.md +101 -0
  200. package/docs/models.md +571 -0
  201. package/docs/packages.md +228 -0
  202. package/docs/prompt-templates.md +96 -0
  203. package/docs/providers.md +317 -0
  204. package/docs/quickstart.md +167 -0
  205. package/docs/rpc.md +1618 -0
  206. package/docs/sdk.md +1219 -0
  207. package/docs/security.md +59 -0
  208. package/docs/session-format.md +438 -0
  209. package/docs/sessions.md +145 -0
  210. package/docs/settings.md +369 -0
  211. package/docs/shell-aliases.md +13 -0
  212. package/docs/skills.md +232 -0
  213. package/docs/terminal-setup.md +177 -0
  214. package/docs/termux.md +127 -0
  215. package/docs/themes.md +320 -0
  216. package/docs/tmux.md +63 -0
  217. package/docs/tui.md +942 -0
  218. package/docs/usage.md +311 -0
  219. package/docs/windows.md +39 -0
  220. package/examples/README.md +25 -0
  221. package/examples/extensions/README.md +213 -0
  222. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  223. package/examples/extensions/bash-spawn-hook.ts +30 -0
  224. package/examples/extensions/bookmark.ts +50 -0
  225. package/examples/extensions/border-status-editor.ts +150 -0
  226. package/examples/extensions/built-in-tool-renderer.ts +249 -0
  227. package/examples/extensions/claude-rules.ts +86 -0
  228. package/examples/extensions/commands.ts +72 -0
  229. package/examples/extensions/confirm-destructive.ts +59 -0
  230. package/examples/extensions/custom-compaction.ts +117 -0
  231. package/examples/extensions/custom-footer.ts +64 -0
  232. package/examples/extensions/custom-header.ts +73 -0
  233. package/examples/extensions/custom-provider-anthropic/index.ts +611 -0
  234. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  235. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  236. package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
  237. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  238. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  239. package/examples/extensions/dirty-repo-guard.ts +56 -0
  240. package/examples/extensions/doom-overlay/README.md +46 -0
  241. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  242. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  243. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  244. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  245. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  246. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  247. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  248. package/examples/extensions/doom-overlay/index.ts +74 -0
  249. package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
  250. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  251. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  252. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  253. package/examples/extensions/dynamic-resources/index.ts +15 -0
  254. package/examples/extensions/dynamic-tools.ts +74 -0
  255. package/examples/extensions/entry-renderer.ts +41 -0
  256. package/examples/extensions/event-bus.ts +43 -0
  257. package/examples/extensions/file-trigger.ts +41 -0
  258. package/examples/extensions/git-checkpoint.ts +53 -0
  259. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  260. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  261. package/examples/extensions/gondolin/index.ts +531 -0
  262. package/examples/extensions/gondolin/package-lock.json +185 -0
  263. package/examples/extensions/gondolin/package.json +19 -0
  264. package/examples/extensions/handoff.ts +190 -0
  265. package/examples/extensions/hello.ts +26 -0
  266. package/examples/extensions/hidden-thinking-label.ts +53 -0
  267. package/examples/extensions/inline-bash.ts +94 -0
  268. package/examples/extensions/input-transform-streaming.ts +39 -0
  269. package/examples/extensions/input-transform.ts +43 -0
  270. package/examples/extensions/interactive-shell.ts +196 -0
  271. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  272. package/examples/extensions/mac-system-theme.ts +47 -0
  273. package/examples/extensions/message-renderer.ts +59 -0
  274. package/examples/extensions/minimal-mode.ts +426 -0
  275. package/examples/extensions/modal-editor.ts +85 -0
  276. package/examples/extensions/model-status.ts +31 -0
  277. package/examples/extensions/notify.ts +57 -0
  278. package/examples/extensions/overlay-qa-tests.ts +1450 -0
  279. package/examples/extensions/overlay-test.ts +153 -0
  280. package/examples/extensions/permission-gate.ts +34 -0
  281. package/examples/extensions/pirate.ts +47 -0
  282. package/examples/extensions/plan-mode/README.md +66 -0
  283. package/examples/extensions/plan-mode/index.ts +390 -0
  284. package/examples/extensions/plan-mode/utils.ts +168 -0
  285. package/examples/extensions/preset.ts +436 -0
  286. package/examples/extensions/project-trust.ts +64 -0
  287. package/examples/extensions/prompt-customizer.ts +97 -0
  288. package/examples/extensions/protected-paths.ts +30 -0
  289. package/examples/extensions/provider-payload.ts +18 -0
  290. package/examples/extensions/qna.ts +118 -0
  291. package/examples/extensions/question.ts +286 -0
  292. package/examples/extensions/questionnaire.ts +448 -0
  293. package/examples/extensions/rainbow-editor.ts +88 -0
  294. package/examples/extensions/reload-runtime.ts +37 -0
  295. package/examples/extensions/rpc-demo.ts +118 -0
  296. package/examples/extensions/sandbox/index.ts +321 -0
  297. package/examples/extensions/sandbox/package-lock.json +92 -0
  298. package/examples/extensions/sandbox/package.json +19 -0
  299. package/examples/extensions/send-user-message.ts +97 -0
  300. package/examples/extensions/session-name.ts +27 -0
  301. package/examples/extensions/shutdown-command.ts +63 -0
  302. package/examples/extensions/snake.ts +343 -0
  303. package/examples/extensions/space-invaders.ts +560 -0
  304. package/examples/extensions/ssh.ts +220 -0
  305. package/examples/extensions/status-line.ts +32 -0
  306. package/examples/extensions/structured-output.ts +65 -0
  307. package/examples/extensions/subagent/README.md +177 -0
  308. package/examples/extensions/subagent/agents/planner.md +37 -0
  309. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  310. package/examples/extensions/subagent/agents/scout.md +50 -0
  311. package/examples/extensions/subagent/agents/worker.md +24 -0
  312. package/examples/extensions/subagent/agents.ts +157 -0
  313. package/examples/extensions/subagent/index.ts +1038 -0
  314. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  315. package/examples/extensions/subagent/prompts/implement.md +10 -0
  316. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  317. package/examples/extensions/summarize.ts +199 -0
  318. package/examples/extensions/system-prompt-header.ts +17 -0
  319. package/examples/extensions/tic-tac-toe.ts +1008 -0
  320. package/examples/extensions/timed-confirm.ts +70 -0
  321. package/examples/extensions/titlebar-spinner.ts +58 -0
  322. package/examples/extensions/todo.ts +297 -0
  323. package/examples/extensions/tool-override.ts +144 -0
  324. package/examples/extensions/tools.ts +146 -0
  325. package/examples/extensions/trigger-compact.ts +50 -0
  326. package/examples/extensions/truncated-tool.ts +195 -0
  327. package/examples/extensions/widget-placement.ts +9 -0
  328. package/examples/extensions/with-deps/index.ts +32 -0
  329. package/examples/extensions/with-deps/package-lock.json +31 -0
  330. package/examples/extensions/with-deps/package.json +22 -0
  331. package/examples/extensions/working-indicator.ts +123 -0
  332. package/examples/extensions/working-message-test.ts +25 -0
  333. package/examples/rpc-extension-ui.ts +641 -0
  334. package/examples/sdk/01-minimal.ts +26 -0
  335. package/examples/sdk/02-custom-model.ts +49 -0
  336. package/examples/sdk/03-custom-prompt.ts +75 -0
  337. package/examples/sdk/04-skills.ts +55 -0
  338. package/examples/sdk/05-tools.ts +48 -0
  339. package/examples/sdk/06-extensions.ts +99 -0
  340. package/examples/sdk/07-context-files.ts +47 -0
  341. package/examples/sdk/08-prompt-templates.ts +51 -0
  342. package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  343. package/examples/sdk/10-settings.ts +53 -0
  344. package/examples/sdk/11-sessions.ts +52 -0
  345. package/examples/sdk/12-full-control.ts +74 -0
  346. package/examples/sdk/13-session-runtime.ts +67 -0
  347. package/examples/sdk/README.md +140 -0
  348. package/package.json +55 -0
@@ -0,0 +1,173 @@
1
+ /**
2
+ * DOOM Engine - WebAssembly wrapper for doomgeneric
3
+ */
4
+
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { createRequire } from "node:module";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ export interface DoomModule {
11
+ _doomgeneric_Create: (argc: number, argv: number) => void;
12
+ _doomgeneric_Tick: () => void;
13
+ _DG_GetFrameBuffer: () => number;
14
+ _DG_GetScreenWidth: () => number;
15
+ _DG_GetScreenHeight: () => number;
16
+ _DG_PushKeyEvent: (pressed: number, key: number) => void;
17
+ _malloc: (size: number) => number;
18
+ _free: (ptr: number) => void;
19
+ HEAPU8: Uint8Array;
20
+ HEAPU32: Uint32Array;
21
+ FS_createDataFile: (parent: string, name: string, data: number[], canRead: boolean, canWrite: boolean) => void;
22
+ FS_createPath: (parent: string, path: string, canRead: boolean, canWrite: boolean) => string;
23
+ setValue: (ptr: number, value: number, type: string) => void;
24
+ getValue: (ptr: number, type: string) => number;
25
+ }
26
+
27
+ export class DoomEngine {
28
+ private module: DoomModule | null = null;
29
+ private frameBufferPtr: number = 0;
30
+ private initialized = false;
31
+ private wadPath: string;
32
+ private _width = 640;
33
+ private _height = 400;
34
+
35
+ constructor(wadPath: string) {
36
+ this.wadPath = wadPath;
37
+ }
38
+
39
+ get width(): number {
40
+ return this._width;
41
+ }
42
+
43
+ get height(): number {
44
+ return this._height;
45
+ }
46
+
47
+ async init(): Promise<void> {
48
+ // Locate WASM build
49
+ const __dirname = dirname(fileURLToPath(import.meta.url));
50
+ const buildDir = join(__dirname, "doom", "build");
51
+ const doomJsPath = join(buildDir, "doom.js");
52
+
53
+ if (!existsSync(doomJsPath)) {
54
+ throw new Error(`WASM not found at ${doomJsPath}. Run ./doom/build.sh first`);
55
+ }
56
+
57
+ // Read WAD file
58
+ const wadData = readFileSync(this.wadPath);
59
+ const wadArray = Array.from(new Uint8Array(wadData));
60
+
61
+ // Load WASM module - eval to bypass jiti completely
62
+ const doomJsCode = readFileSync(doomJsPath, "utf-8");
63
+ const moduleExports: { exports: unknown } = { exports: {} };
64
+ const nativeRequire = createRequire(doomJsPath);
65
+ const moduleFunc = new Function("module", "exports", "__dirname", "__filename", "require", doomJsCode);
66
+ moduleFunc(moduleExports, moduleExports.exports, buildDir, doomJsPath, nativeRequire);
67
+ const createDoomModule = moduleExports.exports as (config: unknown) => Promise<DoomModule>;
68
+
69
+ const moduleConfig = {
70
+ locateFile: (path: string) => {
71
+ if (path.endsWith(".wasm")) {
72
+ return join(buildDir, path);
73
+ }
74
+ return path;
75
+ },
76
+ print: () => {},
77
+ printErr: () => {},
78
+ preRun: [
79
+ (module: DoomModule) => {
80
+ // Create /doom directory and add WAD
81
+ module.FS_createPath("/", "doom", true, true);
82
+ module.FS_createDataFile("/doom", "doom1.wad", wadArray, true, false);
83
+ },
84
+ ],
85
+ };
86
+
87
+ this.module = await createDoomModule(moduleConfig);
88
+ if (!this.module) {
89
+ throw new Error("Failed to initialize DOOM module");
90
+ }
91
+
92
+ // Initialize DOOM
93
+ this.initDoom();
94
+
95
+ // Get framebuffer info
96
+ this.frameBufferPtr = this.module._DG_GetFrameBuffer();
97
+ this._width = this.module._DG_GetScreenWidth();
98
+ this._height = this.module._DG_GetScreenHeight();
99
+ this.initialized = true;
100
+ }
101
+
102
+ private initDoom(): void {
103
+ if (!this.module) return;
104
+
105
+ const args = ["doom", "-iwad", "/doom/doom1.wad"];
106
+ const argPtrs: number[] = [];
107
+
108
+ for (const arg of args) {
109
+ const ptr = this.module._malloc(arg.length + 1);
110
+ for (let i = 0; i < arg.length; i++) {
111
+ this.module.setValue(ptr + i, arg.charCodeAt(i), "i8");
112
+ }
113
+ this.module.setValue(ptr + arg.length, 0, "i8");
114
+ argPtrs.push(ptr);
115
+ }
116
+
117
+ const argvPtr = this.module._malloc(argPtrs.length * 4);
118
+ for (let i = 0; i < argPtrs.length; i++) {
119
+ this.module.setValue(argvPtr + i * 4, argPtrs[i]!, "i32");
120
+ }
121
+
122
+ this.module._doomgeneric_Create(args.length, argvPtr);
123
+
124
+ for (const ptr of argPtrs) {
125
+ this.module._free(ptr);
126
+ }
127
+ this.module._free(argvPtr);
128
+ }
129
+
130
+ /**
131
+ * Run one game tick
132
+ */
133
+ tick(): void {
134
+ if (!this.module || !this.initialized) return;
135
+ this.module._doomgeneric_Tick();
136
+ }
137
+
138
+ /**
139
+ * Get current frame as RGBA pixel data
140
+ * DOOM outputs ARGB, we convert to RGBA
141
+ */
142
+ getFrameRGBA(): Uint8Array {
143
+ if (!this.module || !this.initialized) {
144
+ return new Uint8Array(this._width * this._height * 4);
145
+ }
146
+
147
+ const pixels = this._width * this._height;
148
+ const buffer = new Uint8Array(pixels * 4);
149
+
150
+ for (let i = 0; i < pixels; i++) {
151
+ const argb = this.module.getValue(this.frameBufferPtr + i * 4, "i32");
152
+ const offset = i * 4;
153
+ buffer[offset + 0] = (argb >> 16) & 0xff; // R
154
+ buffer[offset + 1] = (argb >> 8) & 0xff; // G
155
+ buffer[offset + 2] = argb & 0xff; // B
156
+ buffer[offset + 3] = 255; // A
157
+ }
158
+
159
+ return buffer;
160
+ }
161
+
162
+ /**
163
+ * Push a key event
164
+ */
165
+ pushKey(pressed: boolean, key: number): void {
166
+ if (!this.module || !this.initialized) return;
167
+ this.module._DG_PushKeyEvent(pressed ? 1 : 0, key);
168
+ }
169
+
170
+ isInitialized(): boolean {
171
+ return this.initialized;
172
+ }
173
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * DOOM key codes (from doomkeys.h)
3
+ */
4
+ export const DoomKeys = {
5
+ KEY_RIGHTARROW: 0xae,
6
+ KEY_LEFTARROW: 0xac,
7
+ KEY_UPARROW: 0xad,
8
+ KEY_DOWNARROW: 0xaf,
9
+ KEY_STRAFE_L: 0xa0,
10
+ KEY_STRAFE_R: 0xa1,
11
+ KEY_USE: 0xa2,
12
+ KEY_FIRE: 0xa3,
13
+ KEY_ESCAPE: 27,
14
+ KEY_ENTER: 13,
15
+ KEY_TAB: 9,
16
+ KEY_F1: 0x80 + 0x3b,
17
+ KEY_F2: 0x80 + 0x3c,
18
+ KEY_F3: 0x80 + 0x3d,
19
+ KEY_F4: 0x80 + 0x3e,
20
+ KEY_F5: 0x80 + 0x3f,
21
+ KEY_F6: 0x80 + 0x40,
22
+ KEY_F7: 0x80 + 0x41,
23
+ KEY_F8: 0x80 + 0x42,
24
+ KEY_F9: 0x80 + 0x43,
25
+ KEY_F10: 0x80 + 0x44,
26
+ KEY_F11: 0x80 + 0x57,
27
+ KEY_F12: 0x80 + 0x58,
28
+ KEY_BACKSPACE: 127,
29
+ KEY_PAUSE: 0xff,
30
+ KEY_EQUALS: 0x3d,
31
+ KEY_MINUS: 0x2d,
32
+ KEY_RSHIFT: 0x80 + 0x36,
33
+ KEY_RCTRL: 0x80 + 0x1d,
34
+ KEY_RALT: 0x80 + 0x38,
35
+ } as const;
36
+
37
+ import { Key, matchesKey, parseKey } from "@earendil-works/pi-tui";
38
+
39
+ /**
40
+ * Map terminal key input to DOOM key codes
41
+ * Supports both raw terminal input and Kitty protocol sequences
42
+ */
43
+ export function mapKeyToDoom(data: string): number[] {
44
+ // Arrow keys
45
+ if (matchesKey(data, Key.up)) return [DoomKeys.KEY_UPARROW];
46
+ if (matchesKey(data, Key.down)) return [DoomKeys.KEY_DOWNARROW];
47
+ if (matchesKey(data, Key.right)) return [DoomKeys.KEY_RIGHTARROW];
48
+ if (matchesKey(data, Key.left)) return [DoomKeys.KEY_LEFTARROW];
49
+
50
+ // WASD - check both raw char and Kitty sequences
51
+ if (data === "w" || matchesKey(data, "w")) return [DoomKeys.KEY_UPARROW];
52
+ if (data === "W" || matchesKey(data, Key.shift("w"))) return [DoomKeys.KEY_UPARROW, DoomKeys.KEY_RSHIFT];
53
+ if (data === "s" || matchesKey(data, "s")) return [DoomKeys.KEY_DOWNARROW];
54
+ if (data === "S" || matchesKey(data, Key.shift("s"))) return [DoomKeys.KEY_DOWNARROW, DoomKeys.KEY_RSHIFT];
55
+ if (data === "a" || matchesKey(data, "a")) return [DoomKeys.KEY_STRAFE_L];
56
+ if (data === "A" || matchesKey(data, Key.shift("a"))) return [DoomKeys.KEY_STRAFE_L, DoomKeys.KEY_RSHIFT];
57
+ if (data === "d" || matchesKey(data, "d")) return [DoomKeys.KEY_STRAFE_R];
58
+ if (data === "D" || matchesKey(data, Key.shift("d"))) return [DoomKeys.KEY_STRAFE_R, DoomKeys.KEY_RSHIFT];
59
+
60
+ // Fire - F key
61
+ if (data === "f" || data === "F" || matchesKey(data, "f") || matchesKey(data, Key.shift("f"))) {
62
+ return [DoomKeys.KEY_FIRE];
63
+ }
64
+
65
+ // Use/Open
66
+ if (data === " " || matchesKey(data, Key.space)) return [DoomKeys.KEY_USE];
67
+
68
+ // Menu/UI keys
69
+ if (matchesKey(data, Key.enter)) return [DoomKeys.KEY_ENTER];
70
+ if (matchesKey(data, Key.escape)) return [DoomKeys.KEY_ESCAPE];
71
+ if (matchesKey(data, Key.tab)) return [DoomKeys.KEY_TAB];
72
+ if (matchesKey(data, Key.backspace)) return [DoomKeys.KEY_BACKSPACE];
73
+
74
+ // Ctrl keys (except Ctrl+C) = fire (legacy support)
75
+ const parsed = parseKey(data);
76
+ if (parsed?.startsWith("ctrl+") && parsed !== "ctrl+c") {
77
+ return [DoomKeys.KEY_FIRE];
78
+ }
79
+ if (data.length === 1 && data.charCodeAt(0) < 32 && data !== "\x03") {
80
+ return [DoomKeys.KEY_FIRE];
81
+ }
82
+
83
+ // Weapon selection (0-9)
84
+ if (data >= "0" && data <= "9") return [data.charCodeAt(0)];
85
+
86
+ // Plus/minus for screen size
87
+ if (data === "+" || data === "=") return [DoomKeys.KEY_EQUALS];
88
+ if (data === "-") return [DoomKeys.KEY_MINUS];
89
+
90
+ // Y/N for prompts
91
+ if (data === "y" || data === "Y" || matchesKey(data, "y") || matchesKey(data, Key.shift("y"))) {
92
+ return ["y".charCodeAt(0)];
93
+ }
94
+ if (data === "n" || data === "N" || matchesKey(data, "n") || matchesKey(data, Key.shift("n"))) {
95
+ return ["n".charCodeAt(0)];
96
+ }
97
+
98
+ // Other printable characters (for cheats)
99
+ if (data.length === 1 && data.charCodeAt(0) >= 32) {
100
+ return [data.toLowerCase().charCodeAt(0)];
101
+ }
102
+
103
+ return [];
104
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * DOOM Overlay Demo - Play DOOM as an overlay
3
+ *
4
+ * Usage: pi --extension ./examples/extensions/doom-overlay
5
+ *
6
+ * Commands:
7
+ * /doom-overlay - Play DOOM in an overlay (Q to pause/exit)
8
+ *
9
+ * This demonstrates that overlays can handle real-time game rendering at 35 FPS.
10
+ */
11
+
12
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
13
+ import { DoomOverlayComponent } from "./doom-component.ts";
14
+ import { DoomEngine } from "./doom-engine.ts";
15
+ import { ensureWadFile } from "./wad-finder.ts";
16
+
17
+ // Persistent engine instance - survives between invocations
18
+ let activeEngine: DoomEngine | null = null;
19
+ let activeWadPath: string | null = null;
20
+
21
+ export default function (pi: ExtensionAPI) {
22
+ pi.registerCommand("doom-overlay", {
23
+ description: "Play DOOM as an overlay. Q to pause and exit.",
24
+
25
+ handler: async (args, ctx) => {
26
+ if (ctx.mode !== "tui") {
27
+ ctx.ui.notify("DOOM requires interactive mode", "error");
28
+ return;
29
+ }
30
+
31
+ // Auto-download WAD if not present
32
+ ctx.ui.notify("Loading DOOM...", "info");
33
+ const wad = args?.trim() ? args.trim() : await ensureWadFile();
34
+
35
+ if (!wad) {
36
+ ctx.ui.notify("Failed to download DOOM WAD file. Check your internet connection.", "error");
37
+ return;
38
+ }
39
+
40
+ try {
41
+ // Reuse existing engine if same WAD, otherwise create new
42
+ let isResume = false;
43
+ if (activeEngine && activeWadPath === wad) {
44
+ ctx.ui.notify("Resuming DOOM...", "info");
45
+ isResume = true;
46
+ } else {
47
+ ctx.ui.notify(`Loading DOOM from ${wad}...`, "info");
48
+ activeEngine = new DoomEngine(wad);
49
+ await activeEngine.init();
50
+ activeWadPath = wad;
51
+ }
52
+
53
+ await ctx.ui.custom(
54
+ (tui, _theme, _keybindings, done) => {
55
+ return new DoomOverlayComponent(tui, activeEngine!, () => done(undefined), isResume);
56
+ },
57
+ {
58
+ overlay: true,
59
+ overlayOptions: {
60
+ width: "75%",
61
+ maxHeight: "95%",
62
+ anchor: "center",
63
+ margin: { top: 1 },
64
+ },
65
+ },
66
+ );
67
+ } catch (error) {
68
+ ctx.ui.notify(`Failed to load DOOM: ${error}`, "error");
69
+ activeEngine = null;
70
+ activeWadPath = null;
71
+ }
72
+ },
73
+ });
74
+ }
@@ -0,0 +1,55 @@
1
+ import { existsSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { gunzipSync } from "node:zlib";
5
+
6
+ // Get the bundled WAD path (relative to this module)
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const BUNDLED_WAD = join(__dirname, "doom1.wad");
9
+ const WAD_URL = "https://www.gamers.org/pub/idgames/idstuff/doom/doom-1.8.wad.gz";
10
+
11
+ const DEFAULT_WAD_PATHS = ["./doom1.wad", "./DOOM1.WAD", "~/doom1.wad", "~/.doom/doom1.wad"];
12
+
13
+ export function findWadFile(customPath?: string): string | null {
14
+ if (customPath) {
15
+ const resolved = resolve(customPath.replace(/^~/, process.env.HOME || ""));
16
+ if (existsSync(resolved)) return resolved;
17
+ return null;
18
+ }
19
+
20
+ // Check bundled WAD first
21
+ if (existsSync(BUNDLED_WAD)) {
22
+ return BUNDLED_WAD;
23
+ }
24
+
25
+ // Fall back to default paths
26
+ for (const p of DEFAULT_WAD_PATHS) {
27
+ const resolved = resolve(p.replace(/^~/, process.env.HOME || ""));
28
+ if (existsSync(resolved)) return resolved;
29
+ }
30
+
31
+ return null;
32
+ }
33
+
34
+ /** Download the shareware WAD if not present. Returns path or null on failure. */
35
+ export async function ensureWadFile(): Promise<string | null> {
36
+ // Check if already exists
37
+ const existing = findWadFile();
38
+ if (existing) return existing;
39
+
40
+ // Download to bundled location
41
+ try {
42
+ const response = await fetch(WAD_URL);
43
+ if (!response.ok) {
44
+ throw new Error(`HTTP ${response.status}`);
45
+ }
46
+ const wad = gunzipSync(Buffer.from(await response.arrayBuffer()));
47
+ if (wad.subarray(0, 4).toString("ascii") !== "IWAD") {
48
+ throw new Error("Downloaded file is not a valid IWAD");
49
+ }
50
+ writeFileSync(BUNDLED_WAD, wad);
51
+ return BUNDLED_WAD;
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
@@ -0,0 +1,8 @@
1
+ ---
2
+ name: dynamic-resources
3
+ description: Example skill loaded from resources_discover
4
+ ---
5
+
6
+ # Dynamic Resources Skill
7
+
8
+ This skill is provided by the dynamic-resources extension.
@@ -0,0 +1,79 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/earendil-works/pi/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
3
+ "name": "dynamic-resources",
4
+ "vars": {
5
+ "cyan": "#00d7ff",
6
+ "blue": "#5f87ff",
7
+ "green": "#b5bd68",
8
+ "red": "#cc6666",
9
+ "yellow": "#ffff00",
10
+ "gray": "#808080",
11
+ "dimGray": "#666666",
12
+ "darkGray": "#505050",
13
+ "accent": "#8abeb7",
14
+ "selectedBg": "#3a3a4a",
15
+ "userMsgBg": "#343541",
16
+ "toolPendingBg": "#282832",
17
+ "toolSuccessBg": "#283228",
18
+ "toolErrorBg": "#3c2828",
19
+ "customMsgBg": "#2d2838"
20
+ },
21
+ "colors": {
22
+ "accent": "accent",
23
+ "border": "blue",
24
+ "borderAccent": "cyan",
25
+ "borderMuted": "darkGray",
26
+ "success": "green",
27
+ "error": "red",
28
+ "warning": "yellow",
29
+ "muted": "gray",
30
+ "dim": "dimGray",
31
+ "text": "",
32
+ "thinkingText": "gray",
33
+ "selectedBg": "selectedBg",
34
+ "userMessageBg": "userMsgBg",
35
+ "userMessageText": "",
36
+ "customMessageBg": "customMsgBg",
37
+ "customMessageText": "",
38
+ "customMessageLabel": "#9575cd",
39
+ "toolPendingBg": "toolPendingBg",
40
+ "toolSuccessBg": "toolSuccessBg",
41
+ "toolErrorBg": "toolErrorBg",
42
+ "toolTitle": "",
43
+ "toolOutput": "gray",
44
+ "mdHeading": "#f0c674",
45
+ "mdLink": "#81a2be",
46
+ "mdLinkUrl": "dimGray",
47
+ "mdCode": "accent",
48
+ "mdCodeBlock": "green",
49
+ "mdCodeBlockBorder": "gray",
50
+ "mdQuote": "gray",
51
+ "mdQuoteBorder": "gray",
52
+ "mdHr": "gray",
53
+ "mdListBullet": "accent",
54
+ "toolDiffAdded": "green",
55
+ "toolDiffRemoved": "red",
56
+ "toolDiffContext": "gray",
57
+ "syntaxComment": "#6A9955",
58
+ "syntaxKeyword": "#569CD6",
59
+ "syntaxFunction": "#DCDCAA",
60
+ "syntaxVariable": "#9CDCFE",
61
+ "syntaxString": "#CE9178",
62
+ "syntaxNumber": "#B5CEA8",
63
+ "syntaxType": "#4EC9B0",
64
+ "syntaxOperator": "#D4D4D4",
65
+ "syntaxPunctuation": "#D4D4D4",
66
+ "thinkingOff": "darkGray",
67
+ "thinkingMinimal": "#6e6e6e",
68
+ "thinkingLow": "#5f87af",
69
+ "thinkingMedium": "#81a2be",
70
+ "thinkingHigh": "#b294bb",
71
+ "thinkingXhigh": "#d183e8",
72
+ "bashMode": "green"
73
+ },
74
+ "export": {
75
+ "pageBg": "#18181e",
76
+ "cardBg": "#1e1e24",
77
+ "infoBg": "#3c3728"
78
+ }
79
+ }
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Example prompt template loaded from resources_discover
3
+ ---
4
+
5
+ Summarize the current repository structure and mention any build or test commands.
@@ -0,0 +1,15 @@
1
+ import { dirname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+
5
+ const baseDir = dirname(fileURLToPath(import.meta.url));
6
+
7
+ export default function (pi: ExtensionAPI) {
8
+ pi.on("resources_discover", () => {
9
+ return {
10
+ skillPaths: [join(baseDir, "SKILL.md")],
11
+ promptPaths: [join(baseDir, "dynamic.md")],
12
+ themePaths: [join(baseDir, "dynamic.json")],
13
+ };
14
+ });
15
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Dynamic Tools Extension
3
+ *
4
+ * Demonstrates registering tools after session initialization.
5
+ *
6
+ * - Registers one tool during session_start
7
+ * - Registers additional tools at runtime via /add-echo-tool <name>
8
+ */
9
+
10
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
11
+ import { Type } from "typebox";
12
+
13
+ const ECHO_PARAMS = Type.Object({
14
+ message: Type.String({ description: "Message to echo" }),
15
+ });
16
+
17
+ function normalizeToolName(input: string): string | undefined {
18
+ const trimmed = input.trim().toLowerCase();
19
+ if (!trimmed) return undefined;
20
+ if (!/^[a-z0-9_]+$/.test(trimmed)) return undefined;
21
+ return trimmed;
22
+ }
23
+
24
+ export default function dynamicToolsExtension(pi: ExtensionAPI) {
25
+ const registeredToolNames = new Set<string>();
26
+
27
+ const registerEchoTool = (name: string, label: string, prefix: string): boolean => {
28
+ if (registeredToolNames.has(name)) {
29
+ return false;
30
+ }
31
+
32
+ registeredToolNames.add(name);
33
+ pi.registerTool({
34
+ name,
35
+ label,
36
+ description: `Echo a message with prefix: ${prefix}`,
37
+ promptSnippet: `Echo back user-provided text with ${prefix.trim()} prefix`,
38
+ promptGuidelines: ["Use echo_session when the user asks for exact echo output."],
39
+ parameters: ECHO_PARAMS,
40
+ async execute(_toolCallId, params) {
41
+ return {
42
+ content: [{ type: "text", text: `${prefix}${params.message}` }],
43
+ details: { tool: name, prefix },
44
+ };
45
+ },
46
+ });
47
+
48
+ return true;
49
+ };
50
+
51
+ pi.on("session_start", (_event, ctx) => {
52
+ registerEchoTool("echo_session", "Echo Session", "[session] ");
53
+ ctx.ui.notify("Registered dynamic tool: echo_session", "info");
54
+ });
55
+
56
+ pi.registerCommand("add-echo-tool", {
57
+ description: "Register a new echo tool dynamically: /add-echo-tool <tool_name>",
58
+ handler: async (args, ctx) => {
59
+ const toolName = normalizeToolName(args);
60
+ if (!toolName) {
61
+ ctx.ui.notify("Usage: /add-echo-tool <tool_name> (lowercase, numbers, underscores)", "warning");
62
+ return;
63
+ }
64
+
65
+ const created = registerEchoTool(toolName, `Echo ${toolName}`, `[${toolName}] `);
66
+ if (!created) {
67
+ ctx.ui.notify(`Tool already registered: ${toolName}`, "warning");
68
+ return;
69
+ }
70
+
71
+ ctx.ui.notify(`Registered dynamic tool: ${toolName}`, "info");
72
+ },
73
+ });
74
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Custom entry rendering example.
3
+ *
4
+ * Shows how to render durable extension data inside the chat without sending it
5
+ * to the LLM. Custom entries are stored in the session via pi.appendEntry() and
6
+ * rendered in interactive mode via pi.registerEntryRenderer().
7
+ *
8
+ * Usage: /status-card [message]
9
+ */
10
+
11
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { Box, Text } from "@earendil-works/pi-tui";
13
+
14
+ interface StatusCardData {
15
+ message: string;
16
+ timestamp: number;
17
+ }
18
+
19
+ export default function (pi: ExtensionAPI) {
20
+ pi.registerEntryRenderer<StatusCardData>("status-card", (entry, { expanded }, theme) => {
21
+ const data = entry.data ?? { message: "No data", timestamp: Date.now() };
22
+ const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text));
23
+ box.addChild(new Text(`${theme.fg("accent", "[status]")} ${data.message}`, 0, 0));
24
+
25
+ if (expanded) {
26
+ box.addChild(new Text(theme.fg("dim", new Date(data.timestamp).toLocaleString()), 0, 0));
27
+ }
28
+
29
+ return box;
30
+ });
31
+
32
+ pi.registerCommand("status-card", {
33
+ description: "Render a durable status card that is not sent to the LLM",
34
+ handler: async (args) => {
35
+ pi.appendEntry<StatusCardData>("status-card", {
36
+ message: args.trim() || "Status card",
37
+ timestamp: Date.now(),
38
+ });
39
+ },
40
+ });
41
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Inter-extension event bus example.
3
+ *
4
+ * Shows pi.events for communication between extensions. One extension
5
+ * can emit events that other extensions listen to.
6
+ *
7
+ * Usage: /emit [event-name] [data] - emit an event on the bus
8
+ */
9
+
10
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
11
+
12
+ export default function (pi: ExtensionAPI) {
13
+ // Store ctx for use in event handler
14
+ let currentCtx: ExtensionContext | undefined;
15
+
16
+ pi.on("session_start", async (_event, ctx) => {
17
+ currentCtx = ctx;
18
+ });
19
+
20
+ // Listen for events from other extensions
21
+ pi.events.on("my:notification", (data) => {
22
+ const { message, from } = data as { message: string; from: string };
23
+ currentCtx?.ui.notify(`Event from ${from}: ${message}`, "info");
24
+ });
25
+
26
+ // Command to emit events (emits "my:notification" which the listener above receives)
27
+ pi.registerCommand("emit", {
28
+ description: "Emit my:notification event (usage: /emit message)",
29
+ handler: async (args, _ctx) => {
30
+ const message = args.trim() || "hello";
31
+ pi.events.emit("my:notification", { message, from: "/emit command" });
32
+ // Listener above will show the notification
33
+ },
34
+ });
35
+
36
+ // Example: emit on session start
37
+ pi.on("session_start", async () => {
38
+ pi.events.emit("my:notification", {
39
+ message: "Session started",
40
+ from: "event-bus-example",
41
+ });
42
+ });
43
+ }