@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,185 @@
1
+ {
2
+ "name": "pi-extension-gondolin",
3
+ "version": "0.84.4",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "pi-extension-gondolin",
9
+ "version": "0.84.4",
10
+ "dependencies": {
11
+ "@earendil-works/gondolin": "0.12.0"
12
+ }
13
+ },
14
+ "node_modules/@cto.af/wtf8": {
15
+ "version": "0.0.5",
16
+ "resolved": "https://registry.npmjs.org/@cto.af/wtf8/-/wtf8-0.0.5.tgz",
17
+ "integrity": "sha512-LfUFi+Vv4eDzj+XAtR89e3wwjXA/NZjUSwU5NhwbBrLecxPaBYFy3exCuc1j+D4UZeOVdqlsl8G7LmOt18V0tg==",
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=20"
21
+ }
22
+ },
23
+ "node_modules/@earendil-works/gondolin": {
24
+ "version": "0.12.0",
25
+ "resolved": "https://registry.npmjs.org/@earendil-works/gondolin/-/gondolin-0.12.0.tgz",
26
+ "integrity": "sha512-BXbvzQKb5QmxY5NtthRDONJTu7+IDKbzqWGrJyyNXMP7N681Tx0Q9TK8pK1ba8nUvYQTipNJyGZOsJfYiZll1A==",
27
+ "license": "Apache-2.0",
28
+ "dependencies": {
29
+ "cbor2": "^2.3.0",
30
+ "node-forge": "^1.3.3",
31
+ "ssh2": "^1.17.0",
32
+ "undici": "^6.21.0"
33
+ },
34
+ "bin": {
35
+ "gondolin": "dist/bin/gondolin.js"
36
+ },
37
+ "engines": {
38
+ "node": ">=23.6.0"
39
+ },
40
+ "optionalDependencies": {
41
+ "@earendil-works/gondolin-krun-runner-darwin-arm64": "0.12.0",
42
+ "@earendil-works/gondolin-krun-runner-linux-x64": "0.12.0"
43
+ }
44
+ },
45
+ "node_modules/@earendil-works/gondolin-krun-runner-darwin-arm64": {
46
+ "version": "0.12.0",
47
+ "resolved": "https://registry.npmjs.org/@earendil-works/gondolin-krun-runner-darwin-arm64/-/gondolin-krun-runner-darwin-arm64-0.12.0.tgz",
48
+ "integrity": "sha512-ftDlusht4PcT7Y3TuPrZIKrCXy3isiBTVMvlXYK0pcud2uXY6uwFTGeunYgP+8ND/60ddb+MImqbfmkcK8B84A==",
49
+ "cpu": [
50
+ "arm64"
51
+ ],
52
+ "license": "Apache-2.0",
53
+ "optional": true,
54
+ "os": [
55
+ "darwin"
56
+ ],
57
+ "bin": {
58
+ "gondolin-krun-runner": "bin/gondolin-krun-runner"
59
+ }
60
+ },
61
+ "node_modules/@earendil-works/gondolin-krun-runner-linux-x64": {
62
+ "version": "0.12.0",
63
+ "resolved": "https://registry.npmjs.org/@earendil-works/gondolin-krun-runner-linux-x64/-/gondolin-krun-runner-linux-x64-0.12.0.tgz",
64
+ "integrity": "sha512-RRYsgwe2r5ApKmFNy469QgwnyjAHpAs9XANdWpTd9ol4iUYOY3sX7e0xIooAKxd+ktxGI4N/xRWicwGen3D/Ow==",
65
+ "cpu": [
66
+ "x64"
67
+ ],
68
+ "license": "Apache-2.0",
69
+ "optional": true,
70
+ "os": [
71
+ "linux"
72
+ ],
73
+ "bin": {
74
+ "gondolin-krun-runner": "bin/gondolin-krun-runner"
75
+ }
76
+ },
77
+ "node_modules/asn1": {
78
+ "version": "0.2.6",
79
+ "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
80
+ "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==",
81
+ "license": "MIT",
82
+ "dependencies": {
83
+ "safer-buffer": "~2.1.0"
84
+ }
85
+ },
86
+ "node_modules/bcrypt-pbkdf": {
87
+ "version": "1.0.2",
88
+ "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
89
+ "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==",
90
+ "license": "BSD-3-Clause",
91
+ "dependencies": {
92
+ "tweetnacl": "^0.14.3"
93
+ }
94
+ },
95
+ "node_modules/buildcheck": {
96
+ "version": "0.0.7",
97
+ "resolved": "https://registry.npmjs.org/buildcheck/-/buildcheck-0.0.7.tgz",
98
+ "integrity": "sha512-lHblz4ahamxpTmnsk+MNTRWsjYKv965MwOrSJyeD588rR3Jcu7swE+0wN5F+PbL5cjgu/9ObkhfzEPuofEMwLA==",
99
+ "optional": true,
100
+ "engines": {
101
+ "node": ">=10.0.0"
102
+ }
103
+ },
104
+ "node_modules/cbor2": {
105
+ "version": "2.3.0",
106
+ "resolved": "https://registry.npmjs.org/cbor2/-/cbor2-2.3.0.tgz",
107
+ "integrity": "sha512-76WB3hq8BoaGkMkBVJ27fW5LJU+qqDLEpgRNCG/SYKhODWXpVPOTD4UcUto3IEzYLA52nsvbhb0wabhHDn3qXg==",
108
+ "license": "MIT",
109
+ "dependencies": {
110
+ "@cto.af/wtf8": "0.0.5"
111
+ },
112
+ "engines": {
113
+ "node": ">=20"
114
+ }
115
+ },
116
+ "node_modules/cpu-features": {
117
+ "version": "0.0.10",
118
+ "resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.10.tgz",
119
+ "integrity": "sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==",
120
+ "hasInstallScript": true,
121
+ "optional": true,
122
+ "dependencies": {
123
+ "buildcheck": "~0.0.6",
124
+ "nan": "^2.19.0"
125
+ },
126
+ "engines": {
127
+ "node": ">=10.0.0"
128
+ }
129
+ },
130
+ "node_modules/nan": {
131
+ "version": "2.27.0",
132
+ "resolved": "https://registry.npmjs.org/nan/-/nan-2.27.0.tgz",
133
+ "integrity": "sha512-hC+0LidcL3XE4rp1C4H54KujgXKzbfyTngZTwBByQxsOxCEKZT0MPQ4hOKUH2jU1OYstqdDH4onyHPDzcV0XdQ==",
134
+ "license": "MIT",
135
+ "optional": true
136
+ },
137
+ "node_modules/node-forge": {
138
+ "version": "1.4.0",
139
+ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.4.0.tgz",
140
+ "integrity": "sha512-LarFH0+6VfriEhqMMcLX2F7SwSXeWwnEAJEsYm5QKWchiVYVvJyV9v7UDvUv+w5HO23ZpQTXDv/GxdDdMyOuoQ==",
141
+ "license": "(BSD-3-Clause OR GPL-2.0)",
142
+ "engines": {
143
+ "node": ">= 6.13.0"
144
+ }
145
+ },
146
+ "node_modules/safer-buffer": {
147
+ "version": "2.1.2",
148
+ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
149
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
150
+ "license": "MIT"
151
+ },
152
+ "node_modules/ssh2": {
153
+ "version": "1.17.0",
154
+ "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.17.0.tgz",
155
+ "integrity": "sha512-wPldCk3asibAjQ/kziWQQt1Wh3PgDFpC0XpwclzKcdT1vql6KeYxf5LIt4nlFkUeR8WuphYMKqUA56X4rjbfgQ==",
156
+ "hasInstallScript": true,
157
+ "dependencies": {
158
+ "asn1": "^0.2.6",
159
+ "bcrypt-pbkdf": "^1.0.2"
160
+ },
161
+ "engines": {
162
+ "node": ">=10.16.0"
163
+ },
164
+ "optionalDependencies": {
165
+ "cpu-features": "~0.0.10",
166
+ "nan": "^2.23.0"
167
+ }
168
+ },
169
+ "node_modules/tweetnacl": {
170
+ "version": "0.14.5",
171
+ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
172
+ "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==",
173
+ "license": "Unlicense"
174
+ },
175
+ "node_modules/undici": {
176
+ "version": "6.26.0",
177
+ "resolved": "https://registry.npmjs.org/undici/-/undici-6.26.0.tgz",
178
+ "integrity": "sha512-4yqz8a3n5HmGTlsbADNtr/dJlhkh/55Rq798G6ibiULcXbDtaLpTl1pvdqcbFfeoj3iSi52lePFM7h9H21cw/A==",
179
+ "license": "MIT",
180
+ "engines": {
181
+ "node": ">=18.17"
182
+ }
183
+ }
184
+ }
185
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "pi-extension-gondolin",
3
+ "private": true,
4
+ "version": "0.84.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
+ "@earendil-works/gondolin": "0.12.0"
18
+ }
19
+ }
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Handoff extension - transfer context to a new focused session
3
+ *
4
+ * Instead of compacting (which is lossy), handoff extracts what matters
5
+ * for your next task and creates a new session with a generated prompt.
6
+ *
7
+ * Usage:
8
+ * /handoff now implement this for teams as well
9
+ * /handoff execute phase one of the plan
10
+ * /handoff check other places that need this fix
11
+ *
12
+ * The generated prompt appears as a draft in the editor for review/editing.
13
+ */
14
+
15
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
16
+ import { type Message, uuidv7 } from "@earendil-works/pi-ai";
17
+ import type { ExtensionAPI, SessionEntry } from "@earendil-works/pi-coding-agent";
18
+ import { BorderedLoader, convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
19
+
20
+ const SYSTEM_PROMPT = `You are a context transfer assistant. Given a conversation history and the user's goal for a new thread, generate a focused prompt that:
21
+
22
+ 1. Summarizes relevant context from the conversation (decisions made, approaches taken, key findings)
23
+ 2. Lists any relevant files that were discussed or modified
24
+ 3. Clearly states the next task based on the user's goal
25
+ 4. Is self-contained - the new thread should be able to proceed without the old conversation
26
+
27
+ Format your response as a prompt the user can send to start the new thread. Be concise but include all necessary context. Do not include any preamble like "Here's the prompt" - just output the prompt itself.
28
+
29
+ Example output format:
30
+ ## Context
31
+ We've been working on X. Key decisions:
32
+ - Decision 1
33
+ - Decision 2
34
+
35
+ Files involved:
36
+ - path/to/file1.ts
37
+ - path/to/file2.ts
38
+
39
+ ## Task
40
+ [Clear description of what to do next based on user's goal]`;
41
+
42
+ function entryToMessage(entry: SessionEntry): AgentMessage | undefined {
43
+ if (entry.type === "message") {
44
+ return entry.message;
45
+ }
46
+ if (entry.type === "compaction") {
47
+ return {
48
+ role: "compactionSummary",
49
+ summary: entry.summary,
50
+ tokensBefore: entry.tokensBefore,
51
+ timestamp: new Date(entry.timestamp).getTime(),
52
+ };
53
+ }
54
+ return undefined;
55
+ }
56
+
57
+ function getHandoffMessages(branch: SessionEntry[]): AgentMessage[] {
58
+ let compactionIndex = -1;
59
+ for (let i = branch.length - 1; i >= 0; i--) {
60
+ if (branch[i].type === "compaction") {
61
+ compactionIndex = i;
62
+ break;
63
+ }
64
+ }
65
+ if (compactionIndex < 0) {
66
+ return branch.map(entryToMessage).filter((message) => message !== undefined);
67
+ }
68
+
69
+ const compaction = branch[compactionIndex];
70
+ const firstKeptIndex =
71
+ compaction.type === "compaction" ? branch.findIndex((entry) => entry.id === compaction.firstKeptEntryId) : -1;
72
+ const compactedBranch = [
73
+ compaction,
74
+ ...(firstKeptIndex >= 0 ? branch.slice(firstKeptIndex, compactionIndex) : []),
75
+ ...branch.slice(compactionIndex + 1),
76
+ ];
77
+ return compactedBranch.map(entryToMessage).filter((message) => message !== undefined);
78
+ }
79
+
80
+ export default function (pi: ExtensionAPI) {
81
+ pi.registerCommand("handoff", {
82
+ description: "Transfer context to a new focused session",
83
+ handler: async (args, ctx) => {
84
+ if (ctx.mode !== "tui") {
85
+ ctx.ui.notify("handoff requires interactive mode", "error");
86
+ return;
87
+ }
88
+
89
+ if (!ctx.model) {
90
+ ctx.ui.notify("No model selected", "error");
91
+ return;
92
+ }
93
+
94
+ const goal = args.trim();
95
+ if (!goal) {
96
+ ctx.ui.notify("Usage: /handoff <goal for new thread>", "error");
97
+ return;
98
+ }
99
+
100
+ // Gather conversation context from current branch. If the branch was compacted,
101
+ // include the compaction summary plus entries from firstKeptEntryId onward.
102
+ const messages = getHandoffMessages(ctx.sessionManager.getBranch());
103
+
104
+ if (messages.length === 0) {
105
+ ctx.ui.notify("No conversation to hand off", "error");
106
+ return;
107
+ }
108
+
109
+ // Convert to LLM format and serialize
110
+ const llmMessages = convertToLlm(messages);
111
+ const conversationText = serializeConversation(llmMessages);
112
+ const currentSessionFile = ctx.sessionManager.getSessionFile();
113
+
114
+ // Generate the handoff prompt with loader UI
115
+ const result = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
116
+ const loader = new BorderedLoader(tui, theme, `Generating handoff prompt...`);
117
+ loader.onAbort = () => done(null);
118
+
119
+ const doGenerate = async () => {
120
+ const userMessage: Message = {
121
+ role: "user",
122
+ content: [
123
+ {
124
+ type: "text",
125
+ text: `## Conversation History\n\n${conversationText}\n\n## User's Goal for New Thread\n\n${goal}`,
126
+ },
127
+ ],
128
+ timestamp: Date.now(),
129
+ };
130
+
131
+ const response = await ctx.modelRegistry.complete(
132
+ ctx.model!,
133
+ { systemPrompt: SYSTEM_PROMPT, messages: [userMessage] },
134
+ {
135
+ signal: loader.signal,
136
+ cacheRetention: "none",
137
+ sessionId: uuidv7(),
138
+ },
139
+ );
140
+
141
+ if (response.stopReason === "aborted") {
142
+ return null;
143
+ }
144
+
145
+ return response.content
146
+ .filter((c): c is { type: "text"; text: string } => c.type === "text")
147
+ .map((c) => c.text)
148
+ .join("\n");
149
+ };
150
+
151
+ doGenerate()
152
+ .then(done)
153
+ .catch((err) => {
154
+ console.error("Handoff generation failed:", err);
155
+ done(null);
156
+ });
157
+
158
+ return loader;
159
+ });
160
+
161
+ if (result === null) {
162
+ ctx.ui.notify("Cancelled", "info");
163
+ return;
164
+ }
165
+
166
+ // Let user edit the generated prompt
167
+ const editedPrompt = await ctx.ui.editor("Edit handoff prompt", result);
168
+
169
+ if (editedPrompt === undefined) {
170
+ ctx.ui.notify("Cancelled", "info");
171
+ return;
172
+ }
173
+
174
+ // Create new session with parent tracking. Use the replacement-session
175
+ // context for post-switch UI work; the original ctx is stale after a
176
+ // successful session replacement.
177
+ const newSessionResult = await ctx.newSession({
178
+ parentSession: currentSessionFile,
179
+ withSession: async (replacementCtx) => {
180
+ replacementCtx.ui.setEditorText(editedPrompt);
181
+ replacementCtx.ui.notify("Handoff ready. Submit when ready.", "info");
182
+ },
183
+ });
184
+
185
+ if (newSessionResult.cancelled) {
186
+ ctx.ui.notify("New session cancelled", "info");
187
+ }
188
+ },
189
+ });
190
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Hello Tool - Minimal custom tool example
3
+ */
4
+
5
+ import { Type } from "@earendil-works/pi-ai";
6
+ import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
7
+
8
+ const helloTool = defineTool({
9
+ name: "hello",
10
+ label: "Hello",
11
+ description: "A simple greeting tool",
12
+ parameters: Type.Object({
13
+ name: Type.String({ description: "Name to greet" }),
14
+ }),
15
+
16
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
17
+ return {
18
+ content: [{ type: "text", text: `Hello, ${params.name}!` }],
19
+ details: { greeted: params.name },
20
+ };
21
+ },
22
+ });
23
+
24
+ export default function (pi: ExtensionAPI) {
25
+ pi.registerTool(helloTool);
26
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Hidden Thinking Label Extension
3
+ *
4
+ * Demonstrates `ctx.ui.setHiddenThinkingLabel()` for customizing the label shown
5
+ * when thinking blocks are hidden.
6
+ *
7
+ * Usage:
8
+ * pi --extension examples/extensions/hidden-thinking-label.ts
9
+ *
10
+ * Test:
11
+ * 1. Load this extension
12
+ * 2. Hide thinking blocks with Ctrl+T
13
+ * 3. Ask for something that produces reasoning output
14
+ * 4. The collapsed thinking block label will show the custom text
15
+ *
16
+ * Commands:
17
+ * /thinking-label <text> Set a custom hidden thinking label
18
+ * /thinking-label Reset to the default label
19
+ */
20
+
21
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
22
+
23
+ const DEFAULT_LABEL = "Pondering...";
24
+
25
+ export default function (pi: ExtensionAPI) {
26
+ let label = DEFAULT_LABEL;
27
+
28
+ const applyLabel = (ctx: ExtensionContext) => {
29
+ ctx.ui.setHiddenThinkingLabel(label);
30
+ };
31
+
32
+ pi.on("session_start", async (_event, ctx) => {
33
+ applyLabel(ctx);
34
+ });
35
+
36
+ pi.registerCommand("thinking-label", {
37
+ description: "Set the hidden thinking label. Use without args to reset.",
38
+ handler: async (args, ctx) => {
39
+ const nextLabel = args.trim();
40
+
41
+ if (!nextLabel) {
42
+ label = DEFAULT_LABEL;
43
+ ctx.ui.setHiddenThinkingLabel();
44
+ ctx.ui.notify(`Hidden thinking label reset to: ${DEFAULT_LABEL}`);
45
+ return;
46
+ }
47
+
48
+ label = nextLabel;
49
+ ctx.ui.setHiddenThinkingLabel(label);
50
+ ctx.ui.notify(`Hidden thinking label set to: ${label}`);
51
+ },
52
+ });
53
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Inline Bash Extension - expands inline bash commands in user prompts.
3
+ *
4
+ * Start pi with this extension:
5
+ * pi -e ./examples/extensions/inline-bash.ts
6
+ *
7
+ * Then type prompts with inline bash:
8
+ * What's in !{pwd}?
9
+ * The current branch is !{git branch --show-current} and status: !{git status --short}
10
+ * My node version is !{node --version}
11
+ *
12
+ * The !{command} patterns are executed and replaced with their output before
13
+ * the prompt is sent to the agent.
14
+ *
15
+ * Note: Regular !command syntax (whole-line bash) is preserved and works as before.
16
+ */
17
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
18
+
19
+ export default function (pi: ExtensionAPI) {
20
+ const PATTERN = /!\{([^}]+)\}/g;
21
+ const TIMEOUT_MS = 30000;
22
+
23
+ pi.on("input", async (event, ctx) => {
24
+ const text = event.text;
25
+
26
+ // Don't process if it's a whole-line bash command (starts with !)
27
+ // This preserves the existing !command behavior
28
+ if (text.trimStart().startsWith("!") && !text.trimStart().startsWith("!{")) {
29
+ return { action: "continue" };
30
+ }
31
+
32
+ // Check if there are any inline bash patterns
33
+ if (!PATTERN.test(text)) {
34
+ return { action: "continue" };
35
+ }
36
+
37
+ // Reset regex state after test()
38
+ PATTERN.lastIndex = 0;
39
+
40
+ let result = text;
41
+ const expansions: Array<{ command: string; output: string; error?: string }> = [];
42
+
43
+ // Find all matches first (to avoid issues with replacing while iterating)
44
+ const matches: Array<{ full: string; command: string }> = [];
45
+ let match = PATTERN.exec(text);
46
+ while (match) {
47
+ matches.push({ full: match[0], command: match[1] });
48
+ match = PATTERN.exec(text);
49
+ }
50
+
51
+ // Execute each command and collect results
52
+ for (const { full, command } of matches) {
53
+ try {
54
+ const bashResult = await pi.exec("bash", ["-c", command], {
55
+ timeout: TIMEOUT_MS,
56
+ });
57
+
58
+ const output = bashResult.stdout || bashResult.stderr || "";
59
+ const trimmed = output.trim();
60
+
61
+ if (bashResult.code !== 0 && bashResult.stderr) {
62
+ expansions.push({
63
+ command,
64
+ output: trimmed,
65
+ error: `exit code ${bashResult.code}`,
66
+ });
67
+ } else {
68
+ expansions.push({ command, output: trimmed });
69
+ }
70
+
71
+ result = result.replace(full, trimmed);
72
+ } catch (err) {
73
+ const errorMsg = err instanceof Error ? err.message : String(err);
74
+ expansions.push({ command, output: "", error: errorMsg });
75
+ result = result.replace(full, `[error: ${errorMsg}]`);
76
+ }
77
+ }
78
+
79
+ // Show what was expanded (if UI available)
80
+ if (ctx.hasUI && expansions.length > 0) {
81
+ const summary = expansions
82
+ .map((e) => {
83
+ const status = e.error ? ` (${e.error})` : "";
84
+ const preview = e.output.length > 50 ? `${e.output.slice(0, 50)}...` : e.output;
85
+ return `!{${e.command}}${status} -> "${preview}"`;
86
+ })
87
+ .join("\n");
88
+
89
+ ctx.ui.notify(`Expanded ${expansions.length} inline command(s):\n${summary}`, "info");
90
+ }
91
+
92
+ return { action: "transform", text: result, images: event.images };
93
+ });
94
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Streaming-Aware Input Gate
3
+ *
4
+ * Demonstrates `event.streamingBehavior` to skip expensive pre-processing
5
+ * during mid-stream steering, where low latency matters.
6
+ *
7
+ * This extension prepends `git diff --stat` output when the user mentions
8
+ * file changes, giving the model immediate context. During steering the
9
+ * exec call is skipped so the correction reaches the model without delay.
10
+ *
11
+ * Start pi with this extension:
12
+ * pi -e ./examples/extensions/input-transform-streaming.ts
13
+ */
14
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15
+
16
+ const TRIGGER = /\b(changes?|diff|modified)\b/i;
17
+
18
+ export default function (pi: ExtensionAPI) {
19
+ pi.on("input", async (event) => {
20
+ // During steering, skip the exec call — corrections should be fast
21
+ if (event.streamingBehavior === "steer") {
22
+ return { action: "continue" };
23
+ }
24
+
25
+ if (!TRIGGER.test(event.text)) {
26
+ return { action: "continue" };
27
+ }
28
+
29
+ const { stdout, code } = await pi.exec("git", ["diff", "--stat"]);
30
+ if (code !== 0 || !stdout.trim()) {
31
+ return { action: "continue" };
32
+ }
33
+
34
+ return {
35
+ action: "transform",
36
+ text: `${event.text}\n\nCurrent uncommitted changes:\n\`\`\`\n${stdout.trim()}\n\`\`\``,
37
+ };
38
+ });
39
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Input Transform Example - demonstrates the `input` event for intercepting user input.
3
+ *
4
+ * Start pi with this extension:
5
+ * pi -e ./examples/extensions/input-transform.ts
6
+ *
7
+ * Then type these inside pi:
8
+ * ?quick What is TypeScript? → "Respond briefly: What is TypeScript?"
9
+ * ping → "pong" (instant, no LLM)
10
+ * time → current time (instant, no LLM)
11
+ */
12
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
13
+
14
+ export default function (pi: ExtensionAPI) {
15
+ pi.on("input", async (event, ctx) => {
16
+ // Source-based logic: skip processing for extension-injected messages
17
+ if (event.source === "extension") {
18
+ return { action: "continue" };
19
+ }
20
+
21
+ // Transform: ?quick prefix for brief responses
22
+ if (event.text.startsWith("?quick ")) {
23
+ const query = event.text.slice(7).trim();
24
+ if (!query) {
25
+ ctx.ui.notify("Usage: ?quick <question>", "warning");
26
+ return { action: "handled" };
27
+ }
28
+ return { action: "transform", text: `Respond briefly in 1-2 sentences: ${query}` };
29
+ }
30
+
31
+ // Handle: instant responses without LLM (extension shows its own feedback)
32
+ if (event.text.toLowerCase() === "ping") {
33
+ ctx.ui.notify("pong", "info");
34
+ return { action: "handled" };
35
+ }
36
+ if (event.text.toLowerCase() === "time") {
37
+ ctx.ui.notify(new Date().toLocaleString(), "info");
38
+ return { action: "handled" };
39
+ }
40
+
41
+ return { action: "continue" };
42
+ });
43
+ }