@openeryc/pi-coding-agent 0.75.28 → 0.75.30

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 (320) hide show
  1. package/CHANGELOG.md +11 -3
  2. package/dist/cli/config-selector.d.ts +13 -1
  3. package/dist/cli/config-selector.d.ts.map +1 -1
  4. package/dist/cli/config-selector.js +29 -4
  5. package/dist/cli/config-selector.js.map +1 -1
  6. package/dist/cli/list-models.d.ts.map +1 -1
  7. package/dist/cli/list-models.js +1 -1
  8. package/dist/cli/list-models.js.map +1 -1
  9. package/dist/cli/session-picker.d.ts +9 -0
  10. package/dist/cli/session-picker.d.ts.map +1 -0
  11. package/dist/cli/session-picker.js +35 -0
  12. package/dist/cli/session-picker.js.map +1 -0
  13. package/dist/core/agent-session.d.ts +3 -0
  14. package/dist/core/agent-session.d.ts.map +1 -1
  15. package/dist/core/agent-session.js +40 -12
  16. package/dist/core/agent-session.js.map +1 -1
  17. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  18. package/dist/core/export-html/tool-renderer.js.map +1 -1
  19. package/dist/core/extensions/loader.d.ts.map +1 -1
  20. package/dist/core/extensions/loader.js +1 -1
  21. package/dist/core/extensions/loader.js.map +1 -1
  22. package/dist/core/extensions/runner.d.ts +1 -1
  23. package/dist/core/extensions/runner.d.ts.map +1 -1
  24. package/dist/core/extensions/runner.js +1 -1
  25. package/dist/core/extensions/runner.js.map +1 -1
  26. package/dist/core/extensions/types.d.ts +1 -1
  27. package/dist/core/extensions/types.d.ts.map +1 -1
  28. package/dist/core/extensions/types.js.map +1 -1
  29. package/dist/core/hook-runner.d.ts +23 -0
  30. package/dist/core/hook-runner.d.ts.map +1 -0
  31. package/dist/core/hook-runner.js +116 -0
  32. package/dist/core/hook-runner.js.map +1 -0
  33. package/dist/core/keybindings.d.ts +135 -7
  34. package/dist/core/keybindings.d.ts.map +1 -1
  35. package/dist/core/keybindings.js +1 -1
  36. package/dist/core/keybindings.js.map +1 -1
  37. package/dist/core/mcp/client.d.ts +19 -28
  38. package/dist/core/mcp/client.d.ts.map +1 -1
  39. package/dist/core/mcp/client.js +169 -16
  40. package/dist/core/mcp/client.js.map +1 -1
  41. package/dist/core/mcp/index.d.ts +1 -0
  42. package/dist/core/mcp/index.d.ts.map +1 -1
  43. package/dist/core/mcp/index.js.map +1 -1
  44. package/dist/core/mcp/manager.d.ts +3 -0
  45. package/dist/core/mcp/manager.d.ts.map +1 -1
  46. package/dist/core/mcp/manager.js +38 -12
  47. package/dist/core/mcp/manager.js.map +1 -1
  48. package/dist/core/mcp/types.d.ts +49 -0
  49. package/dist/core/mcp/types.d.ts.map +1 -0
  50. package/dist/core/mcp/types.js +2 -0
  51. package/dist/core/mcp/types.js.map +1 -0
  52. package/dist/core/settings-manager.d.ts +8 -2
  53. package/dist/core/settings-manager.d.ts.map +1 -1
  54. package/dist/core/settings-manager.js.map +1 -1
  55. package/dist/core/tools/ask-user-question.d.ts +21 -0
  56. package/dist/core/tools/ask-user-question.d.ts.map +1 -0
  57. package/dist/core/tools/ask-user-question.js +75 -0
  58. package/dist/core/tools/ask-user-question.js.map +1 -0
  59. package/dist/core/tools/bash.d.ts.map +1 -1
  60. package/dist/core/tools/bash.js +1 -1
  61. package/dist/core/tools/bash.js.map +1 -1
  62. package/dist/core/tools/edit.d.ts +1 -1
  63. package/dist/core/tools/edit.d.ts.map +1 -1
  64. package/dist/core/tools/edit.js +1 -1
  65. package/dist/core/tools/edit.js.map +1 -1
  66. package/dist/core/tools/find.d.ts.map +1 -1
  67. package/dist/core/tools/find.js +1 -1
  68. package/dist/core/tools/find.js.map +1 -1
  69. package/dist/core/tools/grep.d.ts.map +1 -1
  70. package/dist/core/tools/grep.js +1 -1
  71. package/dist/core/tools/grep.js.map +1 -1
  72. package/dist/core/tools/index.d.ts +2 -1
  73. package/dist/core/tools/index.d.ts.map +1 -1
  74. package/dist/core/tools/index.js +9 -0
  75. package/dist/core/tools/index.js.map +1 -1
  76. package/dist/core/tools/ls.d.ts.map +1 -1
  77. package/dist/core/tools/ls.js +1 -1
  78. package/dist/core/tools/ls.js.map +1 -1
  79. package/dist/core/tools/read.d.ts.map +1 -1
  80. package/dist/core/tools/read.js +1 -1
  81. package/dist/core/tools/read.js.map +1 -1
  82. package/dist/core/tools/render-utils.d.ts.map +1 -1
  83. package/dist/core/tools/render-utils.js +1 -1
  84. package/dist/core/tools/render-utils.js.map +1 -1
  85. package/dist/core/tools/write.d.ts.map +1 -1
  86. package/dist/core/tools/write.js +1 -1
  87. package/dist/core/tools/write.js.map +1 -1
  88. package/dist/index.d.ts +3 -5
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +5 -7
  91. package/dist/index.js.map +1 -1
  92. package/dist/main.d.ts.map +1 -1
  93. package/dist/main.js +106 -92
  94. package/dist/main.js.map +1 -1
  95. package/dist/modes/index.d.ts +4 -0
  96. package/dist/modes/index.d.ts.map +1 -1
  97. package/dist/modes/index.js +4 -0
  98. package/dist/modes/index.js.map +1 -1
  99. package/dist/modes/interactive/assets/clankolas.png +0 -0
  100. package/dist/modes/interactive/components/armin.d.ts +34 -0
  101. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  102. package/dist/modes/interactive/components/armin.js +333 -0
  103. package/dist/modes/interactive/components/armin.js.map +1 -0
  104. package/dist/modes/interactive/components/assistant-message.d.ts +20 -0
  105. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  106. package/dist/modes/interactive/components/assistant-message.js +121 -0
  107. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  108. package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
  109. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  110. package/dist/modes/interactive/components/bash-execution.js +175 -0
  111. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  112. package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
  113. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  114. package/dist/modes/interactive/components/bordered-loader.js +54 -0
  115. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  116. package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  117. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  118. package/dist/modes/interactive/components/branch-summary-message.js +44 -0
  119. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  120. package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  121. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  122. package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
  123. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  124. package/dist/modes/interactive/components/config-selector.d.ts +71 -0
  125. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  126. package/dist/modes/interactive/components/config-selector.js +506 -0
  127. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  128. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  129. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  130. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  131. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  132. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  133. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  134. package/dist/modes/interactive/components/custom-editor.js +70 -0
  135. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  136. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  137. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  138. package/dist/modes/interactive/components/custom-message.js +79 -0
  139. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  140. package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
  141. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
  142. package/dist/modes/interactive/components/daxnuts.js +140 -0
  143. package/dist/modes/interactive/components/daxnuts.js.map +1 -0
  144. package/dist/modes/interactive/components/diff.d.ts +8 -1
  145. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  146. package/dist/modes/interactive/components/diff.js +131 -2
  147. package/dist/modes/interactive/components/diff.js.map +1 -1
  148. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  149. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  150. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  151. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  152. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  153. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  154. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  155. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  156. package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
  157. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  158. package/dist/modes/interactive/components/extension-editor.js +119 -0
  159. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  160. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  161. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  162. package/dist/modes/interactive/components/extension-input.js +61 -0
  163. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  164. package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
  165. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  166. package/dist/modes/interactive/components/extension-selector.js +83 -0
  167. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  168. package/dist/modes/interactive/components/footer.d.ts +27 -0
  169. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  170. package/dist/modes/interactive/components/footer.js +201 -0
  171. package/dist/modes/interactive/components/footer.js.map +1 -0
  172. package/dist/modes/interactive/components/index.d.ts +32 -0
  173. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  174. package/dist/modes/interactive/components/index.js +33 -0
  175. package/dist/modes/interactive/components/index.js.map +1 -0
  176. package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -2
  177. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  178. package/dist/modes/interactive/components/keybinding-hints.js +33 -4
  179. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  180. package/dist/modes/interactive/components/login-dialog.d.ts +46 -0
  181. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  182. package/dist/modes/interactive/components/login-dialog.js +160 -0
  183. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  184. package/dist/modes/interactive/components/model-selector.d.ts +47 -0
  185. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  186. package/dist/modes/interactive/components/model-selector.js +278 -0
  187. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  188. package/dist/modes/interactive/components/oauth-selector.d.ts +31 -0
  189. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  190. package/dist/modes/interactive/components/oauth-selector.js +165 -0
  191. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  192. package/dist/modes/interactive/components/scoped-models-selector.d.ts +42 -0
  193. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  194. package/dist/modes/interactive/components/scoped-models-selector.js +290 -0
  195. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  196. package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
  197. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  198. package/dist/modes/interactive/components/session-selector-search.js +155 -0
  199. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  200. package/dist/modes/interactive/components/session-selector.d.ts +96 -0
  201. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  202. package/dist/modes/interactive/components/session-selector.js +861 -0
  203. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  204. package/dist/modes/interactive/components/settings-selector.d.ts +69 -0
  205. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  206. package/dist/modes/interactive/components/settings-selector.js +390 -0
  207. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  208. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  209. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  210. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  211. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  212. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  213. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  214. package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
  215. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  216. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  217. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  218. package/dist/modes/interactive/components/theme-selector.js +50 -0
  219. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  220. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  221. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  222. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  223. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  224. package/dist/modes/interactive/components/tool-execution.d.ts +63 -0
  225. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  226. package/dist/modes/interactive/components/tool-execution.js +295 -0
  227. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  228. package/dist/modes/interactive/components/tree-selector.d.ts +89 -0
  229. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  230. package/dist/modes/interactive/components/tree-selector.js +1093 -0
  231. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  232. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  233. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  234. package/dist/modes/interactive/components/user-message-selector.js +114 -0
  235. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  236. package/dist/modes/interactive/components/user-message.d.ts +10 -0
  237. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  238. package/dist/modes/interactive/components/user-message.js +29 -0
  239. package/dist/modes/interactive/components/user-message.js.map +1 -0
  240. package/dist/modes/interactive/components/visual-truncate.d.ts +19 -1
  241. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  242. package/dist/modes/interactive/components/visual-truncate.js +31 -4
  243. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  244. package/dist/modes/interactive/interactive-mode.d.ts +375 -0
  245. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  246. package/dist/modes/interactive/interactive-mode.js +4799 -0
  247. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  248. package/dist/modes/interactive/theme/dark.json +86 -0
  249. package/dist/modes/interactive/theme/light.json +85 -0
  250. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  251. package/dist/modes/interactive/theme/theme.d.ts +89 -27
  252. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  253. package/dist/modes/interactive/theme/theme.js +992 -44
  254. package/dist/modes/interactive/theme/theme.js.map +1 -1
  255. package/dist/package-manager-cli.d.ts.map +1 -1
  256. package/dist/package-manager-cli.js +1 -1
  257. package/dist/package-manager-cli.js.map +1 -1
  258. package/examples/extensions/border-status-editor.ts +150 -0
  259. package/examples/extensions/built-in-tool-renderer.ts +249 -0
  260. package/examples/extensions/custom-footer.ts +64 -0
  261. package/examples/extensions/custom-header.ts +73 -0
  262. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  263. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  264. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  265. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  266. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  267. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  268. package/examples/extensions/doom-overlay/README.md +46 -0
  269. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  270. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  271. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  272. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  273. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  274. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  275. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  276. package/examples/extensions/doom-overlay/index.ts +74 -0
  277. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  278. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  279. package/examples/extensions/handoff.ts +191 -0
  280. package/examples/extensions/interactive-shell.ts +196 -0
  281. package/examples/extensions/message-renderer.ts +59 -0
  282. package/examples/extensions/minimal-mode.ts +426 -0
  283. package/examples/extensions/modal-editor.ts +85 -0
  284. package/examples/extensions/overlay-qa-tests.ts +1379 -0
  285. package/examples/extensions/overlay-test.ts +153 -0
  286. package/examples/extensions/plan-mode/index.ts +340 -0
  287. package/examples/extensions/preset.ts +430 -0
  288. package/examples/extensions/qna.ts +122 -0
  289. package/examples/extensions/question.ts +264 -0
  290. package/examples/extensions/questionnaire.ts +427 -0
  291. package/examples/extensions/rainbow-editor.ts +88 -0
  292. package/examples/extensions/sandbox/index.ts +321 -0
  293. package/examples/extensions/sandbox/package-lock.json +92 -0
  294. package/examples/extensions/sandbox/package.json +19 -0
  295. package/examples/extensions/snake.ts +343 -0
  296. package/examples/extensions/space-invaders.ts +560 -0
  297. package/examples/extensions/ssh.ts +220 -0
  298. package/examples/extensions/status-line.ts +32 -0
  299. package/examples/extensions/structured-output.ts +65 -0
  300. package/examples/extensions/subagent/index.ts +1009 -0
  301. package/examples/extensions/summarize.ts +206 -0
  302. package/examples/extensions/tic-tac-toe.ts +1008 -0
  303. package/examples/extensions/todo.ts +297 -0
  304. package/examples/extensions/tools.ts +141 -0
  305. package/examples/extensions/truncated-tool.ts +195 -0
  306. package/examples/extensions/with-deps/index.ts +32 -0
  307. package/examples/extensions/with-deps/package-lock.json +31 -0
  308. package/examples/extensions/with-deps/package.json +22 -0
  309. package/examples/extensions/working-indicator.ts +123 -0
  310. package/examples/rpc-extension-ui.ts +632 -0
  311. package/npm-shrinkwrap.json +246 -240
  312. package/package.json +7 -6
  313. package/dist/core/index.d.ts +0 -12
  314. package/dist/core/index.d.ts.map +0 -1
  315. package/dist/core/index.js +0 -12
  316. package/dist/core/index.js.map +0 -1
  317. package/dist/core/tui-stubs.d.ts +0 -95
  318. package/dist/core/tui-stubs.d.ts.map +0 -1
  319. package/dist/core/tui-stubs.js +0 -90
  320. package/dist/core/tui-stubs.js.map +0 -1
@@ -0,0 +1,150 @@
1
+ import {
2
+ CustomEditor,
3
+ type ExtensionAPI,
4
+ type ExtensionContext,
5
+ type KeybindingsManager,
6
+ } from "@openeryc/pi-coding-agent";
7
+ import type { Component, EditorTheme, TUI } from "@openeryc/pi-tui";
8
+ import { truncateToWidth, visibleWidth } from "@openeryc/pi-tui";
9
+
10
+ function fitBorder(
11
+ left: string,
12
+ right: string,
13
+ width: number,
14
+ border: (text: string) => string,
15
+ fill: (text: string) => string = border,
16
+ ): string {
17
+ if (width <= 0) return "";
18
+ if (width === 1) return border("─");
19
+
20
+ let leftText = left;
21
+ let rightText = right;
22
+ const fixedWidth = 2;
23
+ const minimumGap = 3;
24
+
25
+ while (
26
+ fixedWidth + visibleWidth(leftText) + visibleWidth(rightText) + minimumGap > width &&
27
+ visibleWidth(rightText) > 0
28
+ ) {
29
+ rightText = truncateToWidth(rightText, Math.max(0, visibleWidth(rightText) - 1), "");
30
+ }
31
+ while (
32
+ fixedWidth + visibleWidth(leftText) + visibleWidth(rightText) + minimumGap > width &&
33
+ visibleWidth(leftText) > 0
34
+ ) {
35
+ leftText = truncateToWidth(leftText, Math.max(0, visibleWidth(leftText) - 1), "");
36
+ }
37
+
38
+ const gapWidth = Math.max(0, width - fixedWidth - visibleWidth(leftText) - visibleWidth(rightText));
39
+ return `${border("─")}${leftText}${fill("─".repeat(gapWidth))}${rightText}${border("─")}`;
40
+ }
41
+
42
+ function formatCwd(cwd: string): string {
43
+ const home = process.env.HOME;
44
+ if (home && cwd.startsWith(home)) {
45
+ return `~${cwd.slice(home.length)}`;
46
+ }
47
+ return cwd;
48
+ }
49
+
50
+ function formatContext(ctx: ExtensionContext): string {
51
+ const usage = ctx.getContextUsage();
52
+ const contextWindow = usage?.contextWindow ?? ctx.model?.contextWindow;
53
+ if (!contextWindow || !usage || usage.percent === null) {
54
+ return "ctx ?";
55
+ }
56
+ return `ctx ${Math.round(usage.percent)}%/${(contextWindow / 1000).toFixed(0)}k`;
57
+ }
58
+
59
+ function formatThinking(level: string): string {
60
+ return level === "off" ? "off" : level;
61
+ }
62
+
63
+ class EmptyFooter implements Component {
64
+ render(): string[] {
65
+ return [];
66
+ }
67
+
68
+ invalidate(): void {}
69
+ }
70
+
71
+ export default function (pi: ExtensionAPI) {
72
+ let isWorking = false;
73
+ let spinnerIndex = 0;
74
+ let spinnerTimer: ReturnType<typeof setInterval> | undefined;
75
+ let activeTui: TUI | undefined;
76
+ const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
77
+
78
+ const stopSpinner = () => {
79
+ if (spinnerTimer) {
80
+ clearInterval(spinnerTimer);
81
+ spinnerTimer = undefined;
82
+ }
83
+ };
84
+
85
+ pi.on("agent_start", () => {
86
+ isWorking = true;
87
+ stopSpinner();
88
+ spinnerTimer = setInterval(() => {
89
+ spinnerIndex = (spinnerIndex + 1) % spinnerFrames.length;
90
+ activeTui?.requestRender();
91
+ }, 80);
92
+ activeTui?.requestRender();
93
+ });
94
+
95
+ pi.on("agent_end", () => {
96
+ isWorking = false;
97
+ stopSpinner();
98
+ activeTui?.requestRender();
99
+ });
100
+
101
+ pi.on("session_shutdown", () => {
102
+ stopSpinner();
103
+ activeTui = undefined;
104
+ });
105
+
106
+ pi.on("session_start", (_event, ctx) => {
107
+ ctx.ui.setWorkingVisible(false);
108
+ ctx.ui.setFooter(() => new EmptyFooter());
109
+
110
+ let branch: string | undefined;
111
+
112
+ const refreshBranch = async () => {
113
+ const result = await pi.exec("git", ["branch", "--show-current"], { cwd: ctx.cwd }).catch(() => undefined);
114
+ const stdout = result?.stdout.trim();
115
+ branch = stdout && stdout.length > 0 ? stdout : undefined;
116
+ activeTui?.requestRender();
117
+ };
118
+ void refreshBranch();
119
+
120
+ class BorderStatusEditor extends CustomEditor {
121
+ constructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager) {
122
+ super(tui, theme, keybindings, { paddingX: 0 });
123
+ activeTui = tui;
124
+ }
125
+
126
+ render(width: number): string[] {
127
+ const lines = super.render(width);
128
+ if (lines.length < 2) return lines;
129
+
130
+ const thm = ctx.ui.theme;
131
+ const model = ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : "no model";
132
+ const thinking = pi.getThinkingLevel();
133
+ const topLeft = isWorking ? thm.fg("accent", ` ${spinnerFrames[spinnerIndex]} `) : "";
134
+ const topRight = "";
135
+ const bottomLeft = thm.fg("muted", ` ${model} · ${formatThinking(thinking)} `);
136
+ const bottomRight = thm.fg(
137
+ "muted",
138
+ ` ${formatContext(ctx)} · ${formatCwd(ctx.cwd)}${branch ? ` (${branch})` : ""} `,
139
+ );
140
+ const borderColor = (text: string) => this.borderColor(text);
141
+
142
+ lines[0] = fitBorder(topLeft, topRight, width, borderColor);
143
+ lines[lines.length - 1] = fitBorder(bottomLeft, bottomRight, width, borderColor);
144
+ return lines;
145
+ }
146
+ }
147
+
148
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => new BorderStatusEditor(tui, theme, keybindings));
149
+ });
150
+ }
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Built-in Tool Renderer Example - Custom rendering for built-in tools
3
+ *
4
+ * Demonstrates how to override the rendering of built-in tools (read, bash,
5
+ * edit, write) without changing their behavior. Each tool is re-registered
6
+ * with the same name, delegating execution to the original implementation
7
+ * while providing compact custom renderCall/renderResult functions.
8
+ *
9
+ * This is useful for users who prefer more concise tool output, or who want
10
+ * to highlight specific information (e.g., showing only the diff stats for
11
+ * edit, or just the exit code for bash).
12
+ *
13
+ * How it works:
14
+ * - registerTool() with the same name as a built-in replaces it entirely
15
+ * - We create instances of the original tools via createReadTool(), etc.
16
+ * and delegate execute() to them
17
+ * - renderCall() controls what's shown when the tool is invoked
18
+ * - renderResult() controls what's shown after execution completes
19
+ * - renderShell: "self" lets a tool render its own outer shell instead of
20
+ * using the default boxed shell from ToolExecutionComponent
21
+ * - The `expanded` flag in renderResult indicates whether the user has
22
+ * toggled the tool output open (via ctrl+e or clicking)
23
+ *
24
+ * Usage:
25
+ * pi -e ./built-in-tool-renderer.ts
26
+ */
27
+
28
+ import type { BashToolDetails, EditToolDetails, ExtensionAPI, ReadToolDetails } from "@openeryc/pi-coding-agent";
29
+ import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@openeryc/pi-coding-agent";
30
+ import { Text } from "@openeryc/pi-tui";
31
+
32
+ export default function (pi: ExtensionAPI) {
33
+ const cwd = process.cwd();
34
+
35
+ // --- Read tool: show path and line count ---
36
+ const originalRead = createReadTool(cwd);
37
+ pi.registerTool({
38
+ name: "read",
39
+ label: "read",
40
+ description: originalRead.description,
41
+ parameters: originalRead.parameters,
42
+
43
+ async execute(toolCallId, params, signal, onUpdate) {
44
+ return originalRead.execute(toolCallId, params, signal, onUpdate);
45
+ },
46
+
47
+ renderCall(args, theme, _context) {
48
+ let text = theme.fg("toolTitle", theme.bold("read "));
49
+ text += theme.fg("accent", args.path);
50
+ if (args.offset || args.limit) {
51
+ const parts: string[] = [];
52
+ if (args.offset) parts.push(`offset=${args.offset}`);
53
+ if (args.limit) parts.push(`limit=${args.limit}`);
54
+ text += theme.fg("dim", ` (${parts.join(", ")})`);
55
+ }
56
+ return new Text(text, 0, 0);
57
+ },
58
+
59
+ renderResult(result, { expanded, isPartial }, theme, _context) {
60
+ if (isPartial) return new Text(theme.fg("warning", "Reading..."), 0, 0);
61
+
62
+ const details = result.details as ReadToolDetails | undefined;
63
+ const content = result.content[0];
64
+
65
+ if (content?.type === "image") {
66
+ return new Text(theme.fg("success", "Image loaded"), 0, 0);
67
+ }
68
+
69
+ if (content?.type !== "text") {
70
+ return new Text(theme.fg("error", "No content"), 0, 0);
71
+ }
72
+
73
+ const lineCount = content.text.split("\n").length;
74
+ let text = theme.fg("success", `${lineCount} lines`);
75
+
76
+ if (details?.truncation?.truncated) {
77
+ text += theme.fg("warning", ` (truncated from ${details.truncation.totalLines})`);
78
+ }
79
+
80
+ if (expanded) {
81
+ const lines = content.text.split("\n").slice(0, 15);
82
+ for (const line of lines) {
83
+ text += `\n${theme.fg("dim", line)}`;
84
+ }
85
+ if (lineCount > 15) {
86
+ text += `\n${theme.fg("muted", `... ${lineCount - 15} more lines`)}`;
87
+ }
88
+ }
89
+
90
+ return new Text(text, 0, 0);
91
+ },
92
+ });
93
+
94
+ // --- Bash tool: show command and exit code ---
95
+ const originalBash = createBashTool(cwd);
96
+ pi.registerTool({
97
+ name: "bash",
98
+ label: "bash",
99
+ description: originalBash.description,
100
+ parameters: originalBash.parameters,
101
+
102
+ async execute(toolCallId, params, signal, onUpdate) {
103
+ return originalBash.execute(toolCallId, params, signal, onUpdate);
104
+ },
105
+
106
+ renderCall(args, theme, _context) {
107
+ let text = theme.fg("toolTitle", theme.bold("$ "));
108
+ const cmd = args.command.length > 80 ? `${args.command.slice(0, 77)}...` : args.command;
109
+ text += theme.fg("accent", cmd);
110
+ if (args.timeout) {
111
+ text += theme.fg("dim", ` (timeout: ${args.timeout}s)`);
112
+ }
113
+ return new Text(text, 0, 0);
114
+ },
115
+
116
+ renderResult(result, { expanded, isPartial }, theme, _context) {
117
+ if (isPartial) return new Text(theme.fg("warning", "Running..."), 0, 0);
118
+
119
+ const details = result.details as BashToolDetails | undefined;
120
+ const content = result.content[0];
121
+ const output = content?.type === "text" ? content.text : "";
122
+
123
+ const exitMatch = output.match(/exit code: (\d+)/);
124
+ const exitCode = exitMatch ? parseInt(exitMatch[1], 10) : null;
125
+ const lineCount = output.split("\n").filter((l) => l.trim()).length;
126
+
127
+ let text = "";
128
+ if (exitCode === 0 || exitCode === null) {
129
+ text += theme.fg("success", "done");
130
+ } else {
131
+ text += theme.fg("error", `exit ${exitCode}`);
132
+ }
133
+ text += theme.fg("dim", ` (${lineCount} lines)`);
134
+
135
+ if (details?.truncation?.truncated) {
136
+ text += theme.fg("warning", " [truncated]");
137
+ }
138
+
139
+ if (expanded) {
140
+ const lines = output.split("\n").slice(0, 20);
141
+ for (const line of lines) {
142
+ text += `\n${theme.fg("dim", line)}`;
143
+ }
144
+ if (output.split("\n").length > 20) {
145
+ text += `\n${theme.fg("muted", "... more output")}`;
146
+ }
147
+ }
148
+
149
+ return new Text(text, 0, 0);
150
+ },
151
+ });
152
+
153
+ // --- Edit tool: show path and diff stats ---
154
+ const originalEdit = createEditTool(cwd);
155
+ pi.registerTool({
156
+ name: "edit",
157
+ label: "edit",
158
+ description: originalEdit.description,
159
+ parameters: originalEdit.parameters,
160
+ renderShell: "self",
161
+
162
+ async execute(toolCallId, params, signal, onUpdate) {
163
+ return originalEdit.execute(toolCallId, params, signal, onUpdate);
164
+ },
165
+
166
+ renderCall(args, theme, _context) {
167
+ let text = theme.fg("toolTitle", theme.bold("edit "));
168
+ text += theme.fg("accent", args.path);
169
+ return new Text(text, 0, 0);
170
+ },
171
+
172
+ renderResult(result, { expanded, isPartial }, theme, _context) {
173
+ if (isPartial) return new Text(theme.fg("warning", "Editing..."), 0, 0);
174
+
175
+ const details = result.details as EditToolDetails | undefined;
176
+ const content = result.content[0];
177
+
178
+ if (content?.type === "text" && content.text.startsWith("Error")) {
179
+ return new Text(theme.fg("error", content.text.split("\n")[0]), 0, 0);
180
+ }
181
+
182
+ if (!details?.diff) {
183
+ return new Text(theme.fg("success", "Applied"), 0, 0);
184
+ }
185
+
186
+ // Count additions and removals from the diff
187
+ const diffLines = details.diff.split("\n");
188
+ let additions = 0;
189
+ let removals = 0;
190
+ for (const line of diffLines) {
191
+ if (line.startsWith("+") && !line.startsWith("+++")) additions++;
192
+ if (line.startsWith("-") && !line.startsWith("---")) removals++;
193
+ }
194
+
195
+ let text = theme.fg("success", `+${additions}`);
196
+ text += theme.fg("dim", " / ");
197
+ text += theme.fg("error", `-${removals}`);
198
+
199
+ if (expanded) {
200
+ for (const line of diffLines.slice(0, 30)) {
201
+ if (line.startsWith("+") && !line.startsWith("+++")) {
202
+ text += `\n${theme.fg("success", line)}`;
203
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
204
+ text += `\n${theme.fg("error", line)}`;
205
+ } else {
206
+ text += `\n${theme.fg("dim", line)}`;
207
+ }
208
+ }
209
+ if (diffLines.length > 30) {
210
+ text += `\n${theme.fg("muted", `... ${diffLines.length - 30} more diff lines`)}`;
211
+ }
212
+ }
213
+
214
+ return new Text(text, 0, 0);
215
+ },
216
+ });
217
+
218
+ // --- Write tool: show path and size ---
219
+ const originalWrite = createWriteTool(cwd);
220
+ pi.registerTool({
221
+ name: "write",
222
+ label: "write",
223
+ description: originalWrite.description,
224
+ parameters: originalWrite.parameters,
225
+
226
+ async execute(toolCallId, params, signal, onUpdate) {
227
+ return originalWrite.execute(toolCallId, params, signal, onUpdate);
228
+ },
229
+
230
+ renderCall(args, theme, _context) {
231
+ let text = theme.fg("toolTitle", theme.bold("write "));
232
+ text += theme.fg("accent", args.path);
233
+ const lineCount = args.content.split("\n").length;
234
+ text += theme.fg("dim", ` (${lineCount} lines)`);
235
+ return new Text(text, 0, 0);
236
+ },
237
+
238
+ renderResult(result, { isPartial }, theme, _context) {
239
+ if (isPartial) return new Text(theme.fg("warning", "Writing..."), 0, 0);
240
+
241
+ const content = result.content[0];
242
+ if (content?.type === "text" && content.text.startsWith("Error")) {
243
+ return new Text(theme.fg("error", content.text.split("\n")[0]), 0, 0);
244
+ }
245
+
246
+ return new Text(theme.fg("success", "Written"), 0, 0);
247
+ },
248
+ });
249
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Custom Footer Extension - demonstrates ctx.ui.setFooter()
3
+ *
4
+ * footerData exposes data not otherwise accessible:
5
+ * - getGitBranch(): current git branch
6
+ * - getExtensionStatuses(): texts from ctx.ui.setStatus()
7
+ *
8
+ * Token stats come from ctx.sessionManager/ctx.model (already accessible).
9
+ */
10
+
11
+ import type { AssistantMessage } from "@openeryc/pi-ai";
12
+ import type { ExtensionAPI } from "@openeryc/pi-coding-agent";
13
+ import { truncateToWidth, visibleWidth } from "@openeryc/pi-tui";
14
+
15
+ export default function (pi: ExtensionAPI) {
16
+ let enabled = false;
17
+
18
+ pi.registerCommand("footer", {
19
+ description: "Toggle custom footer",
20
+ handler: async (_args, ctx) => {
21
+ enabled = !enabled;
22
+
23
+ if (enabled) {
24
+ ctx.ui.setFooter((tui, theme, footerData) => {
25
+ const unsub = footerData.onBranchChange(() => tui.requestRender());
26
+
27
+ return {
28
+ dispose: unsub,
29
+ invalidate() {},
30
+ render(width: number): string[] {
31
+ // Compute tokens from ctx (already accessible to extensions)
32
+ let input = 0,
33
+ output = 0,
34
+ cost = 0;
35
+ for (const e of ctx.sessionManager.getBranch()) {
36
+ if (e.type === "message" && e.message.role === "assistant") {
37
+ const m = e.message as AssistantMessage;
38
+ input += m.usage.input;
39
+ output += m.usage.output;
40
+ cost += m.usage.cost.total;
41
+ }
42
+ }
43
+
44
+ // Get git branch (not otherwise accessible)
45
+ const branch = footerData.getGitBranch();
46
+ const fmt = (n: number) => (n < 1000 ? `${n}` : `${(n / 1000).toFixed(1)}k`);
47
+
48
+ const left = theme.fg("dim", `↑${fmt(input)} ↓${fmt(output)} $${cost.toFixed(3)}`);
49
+ const branchStr = branch ? ` (${branch})` : "";
50
+ const right = theme.fg("dim", `${ctx.model?.id || "no-model"}${branchStr}`);
51
+
52
+ const pad = " ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(right)));
53
+ return [truncateToWidth(left + pad + right, width)];
54
+ },
55
+ };
56
+ });
57
+ ctx.ui.notify("Custom footer enabled", "info");
58
+ } else {
59
+ ctx.ui.setFooter(undefined);
60
+ ctx.ui.notify("Default footer restored", "info");
61
+ }
62
+ },
63
+ });
64
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Custom Header Extension
3
+ *
4
+ * Demonstrates ctx.ui.setHeader() for replacing the built-in header
5
+ * (logo + keybinding hints) with a custom component showing the pi mascot.
6
+ */
7
+
8
+ import type { ExtensionAPI, Theme } from "@openeryc/pi-coding-agent";
9
+ import { VERSION } from "@openeryc/pi-coding-agent";
10
+
11
+ // --- PI MASCOT ---
12
+ // Based on pi_mascot.ts - the pi agent character
13
+ function getPiMascot(theme: Theme): string[] {
14
+ // --- COLORS ---
15
+ // 3b1b Blue: R=80, G=180, B=230
16
+ const piBlue = (text: string) => theme.fg("accent", text);
17
+ const white = (text: string) => text; // Use plain white (or theme.fg("text", text))
18
+ const black = (text: string) => theme.fg("dim", text); // Use dim for contrast
19
+
20
+ // --- GLYPHS ---
21
+ const BLOCK = "█";
22
+ const PUPIL = "▌"; // Vertical half-block for the pupil
23
+
24
+ // --- CONSTRUCTION ---
25
+
26
+ // 1. The Eye Unit: [White Full Block][Black Vertical Sliver]
27
+ // This creates the "looking sideways" effect
28
+ const eye = `${white(BLOCK)}${black(PUPIL)}`;
29
+
30
+ // 2. Line 1: The Eyes
31
+ // 5 spaces indent aligns them with the start of the legs
32
+ const lineEyes = ` ${eye} ${eye}`;
33
+
34
+ // 3. Line 2: The Wide Top Bar (The "Overhang")
35
+ // 14 blocks wide for that serif-style roof
36
+ const lineBar = ` ${piBlue(BLOCK.repeat(14))}`;
37
+
38
+ // 4. Lines 3-6: The Legs
39
+ // Indented 5 spaces relative to the very left edge
40
+ // Leg width: 2 blocks | Gap: 4 blocks
41
+ const lineLeg = ` ${piBlue(BLOCK.repeat(2))} ${piBlue(BLOCK.repeat(2))}`;
42
+
43
+ // --- ASSEMBLY ---
44
+ return ["", lineEyes, lineBar, lineLeg, lineLeg, lineLeg, lineLeg, ""];
45
+ }
46
+
47
+ export default function (pi: ExtensionAPI) {
48
+ // Set custom header immediately on load (if UI is available)
49
+ pi.on("session_start", async (_event, ctx) => {
50
+ if (ctx.hasUI) {
51
+ ctx.ui.setHeader((_tui, theme) => {
52
+ return {
53
+ render(_width: number): string[] {
54
+ const mascotLines = getPiMascot(theme);
55
+ // Add a subtitle with hint
56
+ const subtitle = `${theme.fg("muted", " shitty coding agent")}${theme.fg("dim", ` v${VERSION}`)}`;
57
+ return [...mascotLines, subtitle];
58
+ },
59
+ invalidate() {},
60
+ };
61
+ });
62
+ }
63
+ });
64
+
65
+ // Command to restore built-in header
66
+ pi.registerCommand("builtin-header", {
67
+ description: "Restore built-in header with keybinding hints",
68
+ handler: async (_args, ctx) => {
69
+ ctx.ui.setHeader(undefined);
70
+ ctx.ui.notify("Built-in header restored", "info");
71
+ },
72
+ });
73
+ }