@vaclav-synacek/pi-coding-agent-termux 0.45.7

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 (478) hide show
  1. package/CHANGELOG.md +1961 -0
  2. package/README.md +1392 -0
  3. package/dist/cli/args.d.ts +42 -0
  4. package/dist/cli/args.d.ts.map +1 -0
  5. package/dist/cli/args.js +248 -0
  6. package/dist/cli/args.js.map +1 -0
  7. package/dist/cli/file-processor.d.ts +15 -0
  8. package/dist/cli/file-processor.d.ts.map +1 -0
  9. package/dist/cli/file-processor.js +79 -0
  10. package/dist/cli/file-processor.js.map +1 -0
  11. package/dist/cli/list-models.d.ts +9 -0
  12. package/dist/cli/list-models.d.ts.map +1 -0
  13. package/dist/cli/list-models.js +92 -0
  14. package/dist/cli/list-models.js.map +1 -0
  15. package/dist/cli/session-picker.d.ts +9 -0
  16. package/dist/cli/session-picker.d.ts.map +1 -0
  17. package/dist/cli/session-picker.js +32 -0
  18. package/dist/cli/session-picker.js.map +1 -0
  19. package/dist/cli.d.ts +3 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +10 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/config.d.ts +61 -0
  24. package/dist/config.d.ts.map +1 -0
  25. package/dist/config.js +141 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/core/agent-session.d.ts +523 -0
  28. package/dist/core/agent-session.d.ts.map +1 -0
  29. package/dist/core/agent-session.js +1795 -0
  30. package/dist/core/agent-session.js.map +1 -0
  31. package/dist/core/auth-storage.d.ts +112 -0
  32. package/dist/core/auth-storage.d.ts.map +1 -0
  33. package/dist/core/auth-storage.js +297 -0
  34. package/dist/core/auth-storage.js.map +1 -0
  35. package/dist/core/bash-executor.d.ts +47 -0
  36. package/dist/core/bash-executor.d.ts.map +1 -0
  37. package/dist/core/bash-executor.js +211 -0
  38. package/dist/core/bash-executor.js.map +1 -0
  39. package/dist/core/compaction/branch-summarization.d.ts +84 -0
  40. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  41. package/dist/core/compaction/branch-summarization.js +235 -0
  42. package/dist/core/compaction/branch-summarization.js.map +1 -0
  43. package/dist/core/compaction/compaction.d.ts +110 -0
  44. package/dist/core/compaction/compaction.d.ts.map +1 -0
  45. package/dist/core/compaction/compaction.js +559 -0
  46. package/dist/core/compaction/compaction.js.map +1 -0
  47. package/dist/core/compaction/index.d.ts +7 -0
  48. package/dist/core/compaction/index.d.ts.map +1 -0
  49. package/dist/core/compaction/index.js +7 -0
  50. package/dist/core/compaction/index.js.map +1 -0
  51. package/dist/core/compaction/utils.d.ts +35 -0
  52. package/dist/core/compaction/utils.d.ts.map +1 -0
  53. package/dist/core/compaction/utils.js +138 -0
  54. package/dist/core/compaction/utils.js.map +1 -0
  55. package/dist/core/event-bus.d.ts +9 -0
  56. package/dist/core/event-bus.d.ts.map +1 -0
  57. package/dist/core/event-bus.js +25 -0
  58. package/dist/core/event-bus.js.map +1 -0
  59. package/dist/core/exec.d.ts +29 -0
  60. package/dist/core/exec.d.ts.map +1 -0
  61. package/dist/core/exec.js +71 -0
  62. package/dist/core/exec.js.map +1 -0
  63. package/dist/core/export-html/index.d.ts +17 -0
  64. package/dist/core/export-html/index.d.ts.map +1 -0
  65. package/dist/core/export-html/index.js +193 -0
  66. package/dist/core/export-html/index.js.map +1 -0
  67. package/dist/core/export-html/template.css +910 -0
  68. package/dist/core/export-html/template.html +54 -0
  69. package/dist/core/export-html/template.js +1329 -0
  70. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  71. package/dist/core/export-html/vendor/marked.min.js +6 -0
  72. package/dist/core/extensions/index.d.ts +10 -0
  73. package/dist/core/extensions/index.d.ts.map +1 -0
  74. package/dist/core/extensions/index.js +9 -0
  75. package/dist/core/extensions/index.js.map +1 -0
  76. package/dist/core/extensions/loader.d.ts +25 -0
  77. package/dist/core/extensions/loader.d.ts.map +1 -0
  78. package/dist/core/extensions/loader.js +383 -0
  79. package/dist/core/extensions/loader.js.map +1 -0
  80. package/dist/core/extensions/runner.d.ts +89 -0
  81. package/dist/core/extensions/runner.d.ts.map +1 -0
  82. package/dist/core/extensions/runner.js +406 -0
  83. package/dist/core/extensions/runner.js.map +1 -0
  84. package/dist/core/extensions/types.d.ts +654 -0
  85. package/dist/core/extensions/types.d.ts.map +1 -0
  86. package/dist/core/extensions/types.js +32 -0
  87. package/dist/core/extensions/types.js.map +1 -0
  88. package/dist/core/extensions/wrapper.d.ts +27 -0
  89. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  90. package/dist/core/extensions/wrapper.js +102 -0
  91. package/dist/core/extensions/wrapper.js.map +1 -0
  92. package/dist/core/footer-data-provider.d.ts +25 -0
  93. package/dist/core/footer-data-provider.d.ts.map +1 -0
  94. package/dist/core/footer-data-provider.js +121 -0
  95. package/dist/core/footer-data-provider.js.map +1 -0
  96. package/dist/core/index.d.ts +9 -0
  97. package/dist/core/index.d.ts.map +1 -0
  98. package/dist/core/index.js +9 -0
  99. package/dist/core/index.js.map +1 -0
  100. package/dist/core/keybindings.d.ts +59 -0
  101. package/dist/core/keybindings.d.ts.map +1 -0
  102. package/dist/core/keybindings.js +151 -0
  103. package/dist/core/keybindings.js.map +1 -0
  104. package/dist/core/messages.d.ts +77 -0
  105. package/dist/core/messages.d.ts.map +1 -0
  106. package/dist/core/messages.js +123 -0
  107. package/dist/core/messages.js.map +1 -0
  108. package/dist/core/model-registry.d.ts +57 -0
  109. package/dist/core/model-registry.d.ts.map +1 -0
  110. package/dist/core/model-registry.js +314 -0
  111. package/dist/core/model-registry.js.map +1 -0
  112. package/dist/core/model-resolver.d.ts +76 -0
  113. package/dist/core/model-resolver.d.ts.map +1 -0
  114. package/dist/core/model-resolver.js +308 -0
  115. package/dist/core/model-resolver.js.map +1 -0
  116. package/dist/core/prompt-templates.d.ts +40 -0
  117. package/dist/core/prompt-templates.d.ts.map +1 -0
  118. package/dist/core/prompt-templates.js +197 -0
  119. package/dist/core/prompt-templates.js.map +1 -0
  120. package/dist/core/sdk.d.ts +181 -0
  121. package/dist/core/sdk.d.ts.map +1 -0
  122. package/dist/core/sdk.js +466 -0
  123. package/dist/core/sdk.js.map +1 -0
  124. package/dist/core/session-manager.d.ts +313 -0
  125. package/dist/core/session-manager.d.ts.map +1 -0
  126. package/dist/core/session-manager.js +996 -0
  127. package/dist/core/session-manager.js.map +1 -0
  128. package/dist/core/settings-manager.d.ts +138 -0
  129. package/dist/core/settings-manager.d.ts.map +1 -0
  130. package/dist/core/settings-manager.js +327 -0
  131. package/dist/core/settings-manager.js.map +1 -0
  132. package/dist/core/skills.d.ts +50 -0
  133. package/dist/core/skills.d.ts.map +1 -0
  134. package/dist/core/skills.js +338 -0
  135. package/dist/core/skills.js.map +1 -0
  136. package/dist/core/system-prompt.d.ts +48 -0
  137. package/dist/core/system-prompt.d.ts.map +1 -0
  138. package/dist/core/system-prompt.js +224 -0
  139. package/dist/core/system-prompt.js.map +1 -0
  140. package/dist/core/timings.d.ts +7 -0
  141. package/dist/core/timings.d.ts.map +1 -0
  142. package/dist/core/timings.js +25 -0
  143. package/dist/core/timings.js.map +1 -0
  144. package/dist/core/tools/bash.d.ts +42 -0
  145. package/dist/core/tools/bash.d.ts.map +1 -0
  146. package/dist/core/tools/bash.js +223 -0
  147. package/dist/core/tools/bash.js.map +1 -0
  148. package/dist/core/tools/edit-diff.d.ts +33 -0
  149. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  150. package/dist/core/tools/edit-diff.js +171 -0
  151. package/dist/core/tools/edit-diff.js.map +1 -0
  152. package/dist/core/tools/edit.d.ts +37 -0
  153. package/dist/core/tools/edit.d.ts.map +1 -0
  154. package/dist/core/tools/edit.js +143 -0
  155. package/dist/core/tools/edit.js.map +1 -0
  156. package/dist/core/tools/find.d.ts +37 -0
  157. package/dist/core/tools/find.d.ts.map +1 -0
  158. package/dist/core/tools/find.js +206 -0
  159. package/dist/core/tools/find.js.map +1 -0
  160. package/dist/core/tools/grep.d.ts +43 -0
  161. package/dist/core/tools/grep.d.ts.map +1 -0
  162. package/dist/core/tools/grep.js +239 -0
  163. package/dist/core/tools/grep.js.map +1 -0
  164. package/dist/core/tools/index.d.ts +70 -0
  165. package/dist/core/tools/index.d.ts.map +1 -0
  166. package/dist/core/tools/index.js +56 -0
  167. package/dist/core/tools/index.js.map +1 -0
  168. package/dist/core/tools/ls.d.ts +38 -0
  169. package/dist/core/tools/ls.d.ts.map +1 -0
  170. package/dist/core/tools/ls.js +118 -0
  171. package/dist/core/tools/ls.js.map +1 -0
  172. package/dist/core/tools/path-utils.d.ts +8 -0
  173. package/dist/core/tools/path-utils.d.ts.map +1 -0
  174. package/dist/core/tools/path-utils.js +53 -0
  175. package/dist/core/tools/path-utils.js.map +1 -0
  176. package/dist/core/tools/read.d.ts +37 -0
  177. package/dist/core/tools/read.d.ts.map +1 -0
  178. package/dist/core/tools/read.js +165 -0
  179. package/dist/core/tools/read.js.map +1 -0
  180. package/dist/core/tools/truncate.d.ts +70 -0
  181. package/dist/core/tools/truncate.d.ts.map +1 -0
  182. package/dist/core/tools/truncate.js +205 -0
  183. package/dist/core/tools/truncate.js.map +1 -0
  184. package/dist/core/tools/write.d.ts +27 -0
  185. package/dist/core/tools/write.d.ts.map +1 -0
  186. package/dist/core/tools/write.js +78 -0
  187. package/dist/core/tools/write.js.map +1 -0
  188. package/dist/index.d.ts +19 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +35 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/main.d.ts +8 -0
  193. package/dist/main.d.ts.map +1 -0
  194. package/dist/main.js +354 -0
  195. package/dist/main.js.map +1 -0
  196. package/dist/migrations.d.ts +33 -0
  197. package/dist/migrations.d.ts.map +1 -0
  198. package/dist/migrations.js +261 -0
  199. package/dist/migrations.js.map +1 -0
  200. package/dist/modes/index.d.ts +9 -0
  201. package/dist/modes/index.d.ts.map +1 -0
  202. package/dist/modes/index.js +8 -0
  203. package/dist/modes/index.js.map +1 -0
  204. package/dist/modes/interactive/components/armin.d.ts +34 -0
  205. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  206. package/dist/modes/interactive/components/armin.js +333 -0
  207. package/dist/modes/interactive/components/armin.js.map +1 -0
  208. package/dist/modes/interactive/components/assistant-message.d.ts +15 -0
  209. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  210. package/dist/modes/interactive/components/assistant-message.js +89 -0
  211. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  212. package/dist/modes/interactive/components/bash-execution.d.ts +35 -0
  213. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  214. package/dist/modes/interactive/components/bash-execution.js +161 -0
  215. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  216. package/dist/modes/interactive/components/bordered-loader.d.ts +12 -0
  217. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  218. package/dist/modes/interactive/components/bordered-loader.js +30 -0
  219. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  220. package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
  221. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  222. package/dist/modes/interactive/components/branch-summary-message.js +39 -0
  223. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  224. package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  225. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  226. package/dist/modes/interactive/components/compaction-summary-message.js +40 -0
  227. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  228. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  229. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  230. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  231. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  232. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  233. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  234. package/dist/modes/interactive/components/custom-editor.js +69 -0
  235. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  236. package/dist/modes/interactive/components/custom-message.d.ts +19 -0
  237. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  238. package/dist/modes/interactive/components/custom-message.js +84 -0
  239. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  240. package/dist/modes/interactive/components/diff.d.ts +12 -0
  241. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  242. package/dist/modes/interactive/components/diff.js +133 -0
  243. package/dist/modes/interactive/components/diff.js.map +1 -0
  244. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  245. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  246. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  247. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  248. package/dist/modes/interactive/components/extension-editor.d.ts +15 -0
  249. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  250. package/dist/modes/interactive/components/extension-editor.js +96 -0
  251. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  252. package/dist/modes/interactive/components/extension-input.d.ts +20 -0
  253. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  254. package/dist/modes/interactive/components/extension-input.js +51 -0
  255. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  256. package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
  257. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  258. package/dist/modes/interactive/components/extension-selector.js +73 -0
  259. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  260. package/dist/modes/interactive/components/footer.d.ts +26 -0
  261. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  262. package/dist/modes/interactive/components/footer.js +207 -0
  263. package/dist/modes/interactive/components/footer.js.map +1 -0
  264. package/dist/modes/interactive/components/index.d.ts +29 -0
  265. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  266. package/dist/modes/interactive/components/index.js +30 -0
  267. package/dist/modes/interactive/components/index.js.map +1 -0
  268. package/dist/modes/interactive/components/login-dialog.d.ts +39 -0
  269. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  270. package/dist/modes/interactive/components/login-dialog.js +135 -0
  271. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  272. package/dist/modes/interactive/components/model-selector.d.ts +35 -0
  273. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  274. package/dist/modes/interactive/components/model-selector.js +211 -0
  275. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  276. package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
  277. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  278. package/dist/modes/interactive/components/oauth-selector.js +98 -0
  279. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  280. package/dist/modes/interactive/components/scoped-models-selector.d.ts +46 -0
  281. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  282. package/dist/modes/interactive/components/scoped-models-selector.js +258 -0
  283. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  284. package/dist/modes/interactive/components/session-selector.d.ts +44 -0
  285. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  286. package/dist/modes/interactive/components/session-selector.js +311 -0
  287. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  288. package/dist/modes/interactive/components/settings-selector.d.ts +43 -0
  289. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  290. package/dist/modes/interactive/components/settings-selector.js +219 -0
  291. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  292. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  293. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  294. package/dist/modes/interactive/components/show-images-selector.js +35 -0
  295. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  296. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  297. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  298. package/dist/modes/interactive/components/theme-selector.js +46 -0
  299. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  300. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  301. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  302. package/dist/modes/interactive/components/thinking-selector.js +47 -0
  303. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  304. package/dist/modes/interactive/components/tool-execution.d.ts +70 -0
  305. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  306. package/dist/modes/interactive/components/tool-execution.js +606 -0
  307. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  308. package/dist/modes/interactive/components/tree-selector.d.ts +52 -0
  309. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  310. package/dist/modes/interactive/components/tree-selector.js +745 -0
  311. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  312. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  313. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  314. package/dist/modes/interactive/components/user-message-selector.js +113 -0
  315. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  316. package/dist/modes/interactive/components/user-message.d.ts +8 -0
  317. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  318. package/dist/modes/interactive/components/user-message.js +16 -0
  319. package/dist/modes/interactive/components/user-message.js.map +1 -0
  320. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  321. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  322. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  323. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  324. package/dist/modes/interactive/interactive-mode.d.ts +261 -0
  325. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  326. package/dist/modes/interactive/interactive-mode.js +3194 -0
  327. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  328. package/dist/modes/interactive/theme/dark.json +85 -0
  329. package/dist/modes/interactive/theme/light.json +84 -0
  330. package/dist/modes/interactive/theme/theme-schema.json +308 -0
  331. package/dist/modes/interactive/theme/theme.d.ts +71 -0
  332. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  333. package/dist/modes/interactive/theme/theme.js +893 -0
  334. package/dist/modes/interactive/theme/theme.js.map +1 -0
  335. package/dist/modes/print-mode.d.ts +28 -0
  336. package/dist/modes/print-mode.d.ts.map +1 -0
  337. package/dist/modes/print-mode.js +140 -0
  338. package/dist/modes/print-mode.js.map +1 -0
  339. package/dist/modes/rpc/rpc-client.d.ts +209 -0
  340. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  341. package/dist/modes/rpc/rpc-client.js +392 -0
  342. package/dist/modes/rpc/rpc-client.js.map +1 -0
  343. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  344. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  345. package/dist/modes/rpc/rpc-mode.js +486 -0
  346. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  347. package/dist/modes/rpc/rpc-types.d.ts +372 -0
  348. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  349. package/dist/modes/rpc/rpc-types.js +8 -0
  350. package/dist/modes/rpc/rpc-types.js.map +1 -0
  351. package/dist/utils/changelog.d.ts +21 -0
  352. package/dist/utils/changelog.d.ts.map +1 -0
  353. package/dist/utils/changelog.js +87 -0
  354. package/dist/utils/changelog.js.map +1 -0
  355. package/dist/utils/clipboard-image.d.ts +11 -0
  356. package/dist/utils/clipboard-image.d.ts.map +1 -0
  357. package/dist/utils/clipboard-image.js +129 -0
  358. package/dist/utils/clipboard-image.js.map +1 -0
  359. package/dist/utils/clipboard.d.ts +2 -0
  360. package/dist/utils/clipboard.d.ts.map +1 -0
  361. package/dist/utils/clipboard.js +73 -0
  362. package/dist/utils/clipboard.js.map +1 -0
  363. package/dist/utils/image-convert.d.ts +9 -0
  364. package/dist/utils/image-convert.d.ts.map +1 -0
  365. package/dist/utils/image-convert.js +31 -0
  366. package/dist/utils/image-convert.js.map +1 -0
  367. package/dist/utils/image-resize.d.ts +36 -0
  368. package/dist/utils/image-resize.d.ts.map +1 -0
  369. package/dist/utils/image-resize.js +188 -0
  370. package/dist/utils/image-resize.js.map +1 -0
  371. package/dist/utils/mime.d.ts +2 -0
  372. package/dist/utils/mime.d.ts.map +1 -0
  373. package/dist/utils/mime.js +26 -0
  374. package/dist/utils/mime.js.map +1 -0
  375. package/dist/utils/shell.d.ts +26 -0
  376. package/dist/utils/shell.d.ts.map +1 -0
  377. package/dist/utils/shell.js +151 -0
  378. package/dist/utils/shell.js.map +1 -0
  379. package/dist/utils/tools-manager.d.ts +3 -0
  380. package/dist/utils/tools-manager.d.ts.map +1 -0
  381. package/dist/utils/tools-manager.js +187 -0
  382. package/dist/utils/tools-manager.js.map +1 -0
  383. package/dist/utils/vips.d.ts +11 -0
  384. package/dist/utils/vips.d.ts.map +1 -0
  385. package/dist/utils/vips.js +35 -0
  386. package/dist/utils/vips.js.map +1 -0
  387. package/docs/compaction.md +388 -0
  388. package/docs/extensions.md +1524 -0
  389. package/docs/rpc.md +1046 -0
  390. package/docs/sdk.md +1024 -0
  391. package/docs/session.md +255 -0
  392. package/docs/skills.md +317 -0
  393. package/docs/theme.md +617 -0
  394. package/docs/tree.md +201 -0
  395. package/docs/tui.md +797 -0
  396. package/examples/README.md +24 -0
  397. package/examples/extensions/README.md +168 -0
  398. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  399. package/examples/extensions/chalk-logger.ts +26 -0
  400. package/examples/extensions/claude-rules.ts +86 -0
  401. package/examples/extensions/confirm-destructive.ts +59 -0
  402. package/examples/extensions/custom-compaction.ts +114 -0
  403. package/examples/extensions/custom-footer.ts +64 -0
  404. package/examples/extensions/custom-header.ts +72 -0
  405. package/examples/extensions/dirty-repo-guard.ts +56 -0
  406. package/examples/extensions/doom-overlay/README.md +46 -0
  407. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  408. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  409. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  410. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  411. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  412. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  413. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  414. package/examples/extensions/doom-overlay/index.ts +74 -0
  415. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  416. package/examples/extensions/file-trigger.ts +41 -0
  417. package/examples/extensions/git-checkpoint.ts +53 -0
  418. package/examples/extensions/handoff.ts +150 -0
  419. package/examples/extensions/hello.ts +25 -0
  420. package/examples/extensions/interactive-shell.ts +196 -0
  421. package/examples/extensions/mac-system-theme.ts +47 -0
  422. package/examples/extensions/modal-editor.ts +85 -0
  423. package/examples/extensions/model-status.ts +31 -0
  424. package/examples/extensions/notify.ts +25 -0
  425. package/examples/extensions/overlay-qa-tests.ts +881 -0
  426. package/examples/extensions/overlay-test.ts +145 -0
  427. package/examples/extensions/permission-gate.ts +34 -0
  428. package/examples/extensions/pirate.ts +47 -0
  429. package/examples/extensions/plan-mode/README.md +65 -0
  430. package/examples/extensions/plan-mode/index.ts +340 -0
  431. package/examples/extensions/plan-mode/utils.ts +168 -0
  432. package/examples/extensions/preset.ts +398 -0
  433. package/examples/extensions/protected-paths.ts +30 -0
  434. package/examples/extensions/qna.ts +119 -0
  435. package/examples/extensions/question.ts +277 -0
  436. package/examples/extensions/questionnaire.ts +427 -0
  437. package/examples/extensions/rainbow-editor.ts +95 -0
  438. package/examples/extensions/sandbox/index.ts +318 -0
  439. package/examples/extensions/sandbox/package-lock.json +92 -0
  440. package/examples/extensions/sandbox/package.json +19 -0
  441. package/examples/extensions/send-user-message.ts +97 -0
  442. package/examples/extensions/shutdown-command.ts +63 -0
  443. package/examples/extensions/snake.ts +343 -0
  444. package/examples/extensions/ssh.ts +220 -0
  445. package/examples/extensions/status-line.ts +40 -0
  446. package/examples/extensions/subagent/README.md +172 -0
  447. package/examples/extensions/subagent/agents/planner.md +37 -0
  448. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  449. package/examples/extensions/subagent/agents/scout.md +50 -0
  450. package/examples/extensions/subagent/agents/worker.md +24 -0
  451. package/examples/extensions/subagent/agents.ts +156 -0
  452. package/examples/extensions/subagent/index.ts +963 -0
  453. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  454. package/examples/extensions/subagent/prompts/implement.md +10 -0
  455. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  456. package/examples/extensions/summarize.ts +195 -0
  457. package/examples/extensions/timed-confirm.ts +70 -0
  458. package/examples/extensions/todo.ts +299 -0
  459. package/examples/extensions/tool-override.ts +143 -0
  460. package/examples/extensions/tools.ts +146 -0
  461. package/examples/extensions/truncated-tool.ts +192 -0
  462. package/examples/extensions/with-deps/index.ts +36 -0
  463. package/examples/extensions/with-deps/package-lock.json +31 -0
  464. package/examples/extensions/with-deps/package.json +22 -0
  465. package/examples/sdk/01-minimal.ts +22 -0
  466. package/examples/sdk/02-custom-model.ts +49 -0
  467. package/examples/sdk/03-custom-prompt.ts +44 -0
  468. package/examples/sdk/04-skills.ts +47 -0
  469. package/examples/sdk/05-tools.ts +56 -0
  470. package/examples/sdk/06-extensions.ts +79 -0
  471. package/examples/sdk/07-context-files.ts +36 -0
  472. package/examples/sdk/08-prompt-templates.ts +42 -0
  473. package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
  474. package/examples/sdk/10-settings.ts +38 -0
  475. package/examples/sdk/11-sessions.ts +48 -0
  476. package/examples/sdk/12-full-control.ts +72 -0
  477. package/examples/sdk/README.md +150 -0
  478. package/package.json +88 -0
@@ -0,0 +1,24 @@
1
+ # Examples
2
+
3
+ Example code for pi-coding-agent SDK and extensions.
4
+
5
+ ## Directories
6
+
7
+ ### [sdk/](sdk/)
8
+ Programmatic usage via `createAgentSession()`. Shows how to customize models, prompts, tools, extensions, and session management.
9
+
10
+ ### [extensions/](extensions/)
11
+ Example extensions demonstrating:
12
+ - Lifecycle event handlers (tool interception, safety gates, context modifications)
13
+ - Custom tools (todo lists, questions, subagents, output truncation)
14
+ - Commands and keyboard shortcuts
15
+ - Custom UI (footers, headers, editors, overlays)
16
+ - Git integration (checkpoints, auto-commit)
17
+ - System prompt modifications and custom compaction
18
+ - External integrations (SSH, file watchers, system theme sync)
19
+
20
+ ## Documentation
21
+
22
+ - [SDK Reference](sdk/README.md)
23
+ - [Extensions Documentation](../docs/extensions.md)
24
+ - [Skills Documentation](../docs/skills.md)
@@ -0,0 +1,168 @@
1
+ # Extension Examples
2
+
3
+ Example extensions for pi-coding-agent.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # Load an extension with --extension flag
9
+ pi --extension examples/extensions/permission-gate.ts
10
+
11
+ # Or copy to extensions directory for auto-discovery
12
+ cp permission-gate.ts ~/.pi/agent/extensions/
13
+ ```
14
+
15
+ ## Examples
16
+
17
+ ### Lifecycle & Safety
18
+
19
+ | Extension | Description |
20
+ |-----------|-------------|
21
+ | `permission-gate.ts` | Prompts for confirmation before dangerous bash commands (rm -rf, sudo, etc.) |
22
+ | `protected-paths.ts` | Blocks writes to protected paths (.env, .git/, node_modules/) |
23
+ | `confirm-destructive.ts` | Confirms before destructive session actions (clear, switch, fork) |
24
+ | `dirty-repo-guard.ts` | Prevents session changes with uncommitted git changes |
25
+ | `sandbox/` | OS-level sandboxing using `@anthropic-ai/sandbox-runtime` with per-project config |
26
+
27
+ ### Custom Tools
28
+
29
+ | Extension | Description |
30
+ |-----------|-------------|
31
+ | `todo.ts` | Todo list tool + `/todos` command with custom rendering and state persistence |
32
+ | `hello.ts` | Minimal custom tool example |
33
+ | `question.ts` | Demonstrates `ctx.ui.select()` for asking the user questions with custom UI |
34
+ | `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
35
+ | `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
36
+ | `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
37
+ | `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
38
+ | `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
39
+
40
+ ### Commands & UI
41
+
42
+ | Extension | Description |
43
+ |-----------|-------------|
44
+ | `preset.ts` | Named presets for model, thinking level, tools, and instructions via `--preset` flag and `/preset` command |
45
+ | `plan-mode/` | Claude Code-style plan mode for read-only exploration with `/plan` command and step tracking |
46
+ | `tools.ts` | Interactive `/tools` command to enable/disable tools with session persistence |
47
+ | `handoff.ts` | Transfer context to a new focused session via `/handoff <goal>` |
48
+ | `qna.ts` | Extracts questions from last response into editor via `ctx.ui.setEditorText()` |
49
+ | `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
50
+ | `model-status.ts` | Shows model changes in status bar via `model_select` hook |
51
+ | `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
52
+ | `send-user-message.ts` | Demonstrates `pi.sendUserMessage()` for sending user messages from extensions |
53
+ | `timed-confirm.ts` | Demonstrates AbortSignal for auto-dismissing `ctx.ui.confirm()` and `ctx.ui.select()` dialogs |
54
+ | `modal-editor.ts` | Custom vim-like modal editor via `ctx.ui.setEditorComponent()` |
55
+ | `rainbow-editor.ts` | Animated rainbow text effect via custom editor |
56
+ | `notify.ts` | Desktop notifications via OSC 777 when agent finishes (Ghostty, iTerm2, WezTerm) |
57
+ | `summarize.ts` | Summarize conversation with GPT-5.2 and show in transient UI |
58
+ | `custom-footer.ts` | Custom footer with git branch and token stats via `ctx.ui.setFooter()` |
59
+ | `custom-header.ts` | Custom header via `ctx.ui.setHeader()` |
60
+ | `overlay-test.ts` | Test overlay compositing with inline text inputs and edge cases |
61
+ | `overlay-qa-tests.ts` | Comprehensive overlay QA tests: anchors, margins, stacking, overflow, animation |
62
+ | `doom-overlay/` | DOOM game running as an overlay at 35 FPS (demonstrates real-time game rendering) |
63
+ | `shutdown-command.ts` | Adds `/quit` command demonstrating `ctx.shutdown()` |
64
+ | `interactive-shell.ts` | Run interactive commands (vim, htop) with full terminal via `user_bash` hook |
65
+
66
+ ### Git Integration
67
+
68
+ | Extension | Description |
69
+ |-----------|-------------|
70
+ | `git-checkpoint.ts` | Creates git stash checkpoints at each turn for code restoration on fork |
71
+ | `auto-commit-on-exit.ts` | Auto-commits on exit using last assistant message for commit message |
72
+
73
+ ### System Prompt & Compaction
74
+
75
+ | Extension | Description |
76
+ |-----------|-------------|
77
+ | `pirate.ts` | Demonstrates `systemPromptAppend` to dynamically modify system prompt |
78
+ | `claude-rules.ts` | Scans `.claude/rules/` folder and lists rules in system prompt |
79
+ | `custom-compaction.ts` | Custom compaction that summarizes entire conversation |
80
+
81
+ ### System Integration
82
+
83
+ | Extension | Description |
84
+ |-----------|-------------|
85
+ | `mac-system-theme.ts` | Syncs pi theme with macOS dark/light mode |
86
+
87
+ ### External Dependencies
88
+
89
+ | Extension | Description |
90
+ |-----------|-------------|
91
+ | `chalk-logger.ts` | Uses chalk from parent node_modules (demonstrates jiti module resolution) |
92
+ | `with-deps/` | Extension with its own package.json and dependencies |
93
+ | `file-trigger.ts` | Watches a trigger file and injects contents into conversation |
94
+
95
+ ## Writing Extensions
96
+
97
+ See [docs/extensions.md](../../docs/extensions.md) for full documentation.
98
+
99
+ ```typescript
100
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
101
+ import { Type } from "@sinclair/typebox";
102
+
103
+ export default function (pi: ExtensionAPI) {
104
+ // Subscribe to lifecycle events
105
+ pi.on("tool_call", async (event, ctx) => {
106
+ if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
107
+ const ok = await ctx.ui.confirm("Dangerous!", "Allow rm -rf?");
108
+ if (!ok) return { block: true, reason: "Blocked by user" };
109
+ }
110
+ });
111
+
112
+ // Register custom tools
113
+ pi.registerTool({
114
+ name: "greet",
115
+ label: "Greeting",
116
+ description: "Generate a greeting",
117
+ parameters: Type.Object({
118
+ name: Type.String({ description: "Name to greet" }),
119
+ }),
120
+ async execute(toolCallId, params, onUpdate, ctx, signal) {
121
+ return {
122
+ content: [{ type: "text", text: `Hello, ${params.name}!` }],
123
+ details: {},
124
+ };
125
+ },
126
+ });
127
+
128
+ // Register commands
129
+ pi.registerCommand("hello", {
130
+ description: "Say hello",
131
+ handler: async (args, ctx) => {
132
+ ctx.ui.notify("Hello!", "info");
133
+ },
134
+ });
135
+ }
136
+ ```
137
+
138
+ ## Key Patterns
139
+
140
+ **Use StringEnum for string parameters** (required for Google API compatibility):
141
+ ```typescript
142
+ import { StringEnum } from "@mariozechner/pi-ai";
143
+
144
+ // Good
145
+ action: StringEnum(["list", "add"] as const)
146
+
147
+ // Bad - doesn't work with Google
148
+ action: Type.Union([Type.Literal("list"), Type.Literal("add")])
149
+ ```
150
+
151
+ **State persistence via details:**
152
+ ```typescript
153
+ // Store state in tool result details for proper forking support
154
+ return {
155
+ content: [{ type: "text", text: "Done" }],
156
+ details: { todos: [...todos], nextId }, // Persisted in session
157
+ };
158
+
159
+ // Reconstruct on session events
160
+ pi.on("session_start", async (_event, ctx) => {
161
+ for (const entry of ctx.sessionManager.getBranch()) {
162
+ if (entry.type === "message" && entry.message.toolName === "my_tool") {
163
+ const details = entry.message.details;
164
+ // Reconstruct state from details
165
+ }
166
+ }
167
+ });
168
+ ```
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Auto-Commit on Exit Extension
3
+ *
4
+ * Automatically commits changes when the agent exits.
5
+ * Uses the last assistant message to generate a commit message.
6
+ */
7
+
8
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
9
+
10
+ export default function (pi: ExtensionAPI) {
11
+ pi.on("session_shutdown", async (_event, ctx) => {
12
+ // Check for uncommitted changes
13
+ const { stdout: status, code } = await pi.exec("git", ["status", "--porcelain"]);
14
+
15
+ if (code !== 0 || status.trim().length === 0) {
16
+ // Not a git repo or no changes
17
+ return;
18
+ }
19
+
20
+ // Find the last assistant message for commit context
21
+ const entries = ctx.sessionManager.getEntries();
22
+ let lastAssistantText = "";
23
+ for (let i = entries.length - 1; i >= 0; i--) {
24
+ const entry = entries[i];
25
+ if (entry.type === "message" && entry.message.role === "assistant") {
26
+ const content = entry.message.content;
27
+ if (Array.isArray(content)) {
28
+ lastAssistantText = content
29
+ .filter((c): c is { type: "text"; text: string } => c.type === "text")
30
+ .map((c) => c.text)
31
+ .join("\n");
32
+ }
33
+ break;
34
+ }
35
+ }
36
+
37
+ // Generate a simple commit message
38
+ const firstLine = lastAssistantText.split("\n")[0] || "Work in progress";
39
+ const commitMessage = `[pi] ${firstLine.slice(0, 50)}${firstLine.length > 50 ? "..." : ""}`;
40
+
41
+ // Stage and commit
42
+ await pi.exec("git", ["add", "-A"]);
43
+ const { code: commitCode } = await pi.exec("git", ["commit", "-m", commitMessage]);
44
+
45
+ if (commitCode === 0 && ctx.hasUI) {
46
+ ctx.ui.notify(`Auto-committed: ${commitMessage}`, "info");
47
+ }
48
+ });
49
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Example extension that uses a 3rd party dependency (chalk).
3
+ * Tests that jiti can resolve npm modules correctly.
4
+ */
5
+
6
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
7
+ import chalk from "chalk";
8
+
9
+ export default function (pi: ExtensionAPI) {
10
+ // Log with colors using chalk
11
+ console.log(`${chalk.green("✓")} ${chalk.bold("chalk-logger extension loaded")}`);
12
+
13
+ pi.on("agent_start", async () => {
14
+ console.log(`${chalk.blue("[chalk-logger]")} Agent starting`);
15
+ });
16
+
17
+ pi.on("tool_call", async (event) => {
18
+ console.log(`${chalk.yellow("[chalk-logger]")} Tool: ${chalk.cyan(event.toolName)}`);
19
+ return undefined;
20
+ });
21
+
22
+ pi.on("agent_end", async (event) => {
23
+ const count = event.messages.length;
24
+ console.log(`${chalk.green("[chalk-logger]")} Done with ${chalk.bold(String(count))} messages`);
25
+ });
26
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Claude Rules Extension
3
+ *
4
+ * Scans the project's .claude/rules/ folder for rule files and lists them
5
+ * in the system prompt. The agent can then use the read tool to load
6
+ * specific rules when needed.
7
+ *
8
+ * Best practices for .claude/rules/:
9
+ * - Keep rules focused: Each file should cover one topic (e.g., testing.md, api-design.md)
10
+ * - Use descriptive filenames: The filename should indicate what the rules cover
11
+ * - Use conditional rules sparingly: Only add paths frontmatter when rules truly apply to specific file types
12
+ * - Organize with subdirectories: Group related rules (e.g., frontend/, backend/)
13
+ *
14
+ * Usage:
15
+ * 1. Copy this file to ~/.pi/agent/extensions/ or your project's .pi/extensions/
16
+ * 2. Create .claude/rules/ folder in your project root
17
+ * 3. Add .md files with your rules
18
+ */
19
+
20
+ import * as fs from "node:fs";
21
+ import * as path from "node:path";
22
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
23
+
24
+ /**
25
+ * Recursively find all .md files in a directory
26
+ */
27
+ function findMarkdownFiles(dir: string, basePath: string = ""): string[] {
28
+ const results: string[] = [];
29
+
30
+ if (!fs.existsSync(dir)) {
31
+ return results;
32
+ }
33
+
34
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
35
+
36
+ for (const entry of entries) {
37
+ const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
38
+
39
+ if (entry.isDirectory()) {
40
+ results.push(...findMarkdownFiles(path.join(dir, entry.name), relativePath));
41
+ } else if (entry.isFile() && entry.name.endsWith(".md")) {
42
+ results.push(relativePath);
43
+ }
44
+ }
45
+
46
+ return results;
47
+ }
48
+
49
+ export default function claudeRulesExtension(pi: ExtensionAPI) {
50
+ let ruleFiles: string[] = [];
51
+ let rulesDir: string = "";
52
+
53
+ // Scan for rules on session start
54
+ pi.on("session_start", async (_event, ctx) => {
55
+ rulesDir = path.join(ctx.cwd, ".claude", "rules");
56
+ ruleFiles = findMarkdownFiles(rulesDir);
57
+
58
+ if (ruleFiles.length > 0) {
59
+ ctx.ui.notify(`Found ${ruleFiles.length} rule(s) in .claude/rules/`, "info");
60
+ }
61
+ });
62
+
63
+ // Append available rules to system prompt
64
+ pi.on("before_agent_start", async (event) => {
65
+ if (ruleFiles.length === 0) {
66
+ return;
67
+ }
68
+
69
+ const rulesList = ruleFiles.map((f) => `- .claude/rules/${f}`).join("\n");
70
+
71
+ return {
72
+ systemPrompt:
73
+ event.systemPrompt +
74
+ `
75
+
76
+ ## Project Rules
77
+
78
+ The following project rules are available in .claude/rules/:
79
+
80
+ ${rulesList}
81
+
82
+ When working on tasks related to these rules, use the read tool to load the relevant rule files for guidance.
83
+ `,
84
+ };
85
+ });
86
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Confirm Destructive Actions Extension
3
+ *
4
+ * Prompts for confirmation before destructive session actions (clear, switch, branch).
5
+ * Demonstrates how to cancel session events using the before_* events.
6
+ */
7
+
8
+ import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from "@mariozechner/pi-coding-agent";
9
+
10
+ export default function (pi: ExtensionAPI) {
11
+ pi.on("session_before_switch", async (event: SessionBeforeSwitchEvent, ctx) => {
12
+ if (!ctx.hasUI) return;
13
+
14
+ if (event.reason === "new") {
15
+ const confirmed = await ctx.ui.confirm(
16
+ "Clear session?",
17
+ "This will delete all messages in the current session.",
18
+ );
19
+
20
+ if (!confirmed) {
21
+ ctx.ui.notify("Clear cancelled", "info");
22
+ return { cancel: true };
23
+ }
24
+ return;
25
+ }
26
+
27
+ // reason === "resume" - check if there are unsaved changes (messages since last assistant response)
28
+ const entries = ctx.sessionManager.getEntries();
29
+ const hasUnsavedWork = entries.some(
30
+ (e): e is SessionMessageEntry => e.type === "message" && e.message.role === "user",
31
+ );
32
+
33
+ if (hasUnsavedWork) {
34
+ const confirmed = await ctx.ui.confirm(
35
+ "Switch session?",
36
+ "You have messages in the current session. Switch anyway?",
37
+ );
38
+
39
+ if (!confirmed) {
40
+ ctx.ui.notify("Switch cancelled", "info");
41
+ return { cancel: true };
42
+ }
43
+ }
44
+ });
45
+
46
+ pi.on("session_before_fork", async (event, ctx) => {
47
+ if (!ctx.hasUI) return;
48
+
49
+ const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
50
+ "Yes, create fork",
51
+ "No, stay in current session",
52
+ ]);
53
+
54
+ if (choice !== "Yes, create fork") {
55
+ ctx.ui.notify("Fork cancelled", "info");
56
+ return { cancel: true };
57
+ }
58
+ });
59
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Custom Compaction Extension
3
+ *
4
+ * Replaces the default compaction behavior with a full summary of the entire context.
5
+ * Instead of keeping the last 20k tokens of conversation turns, this extension:
6
+ * 1. Summarizes ALL messages (messagesToSummarize + turnPrefixMessages)
7
+ * 2. Discards all old turns completely, keeping only the summary
8
+ *
9
+ * This example also demonstrates using a different model (Gemini Flash) for summarization,
10
+ * which can be cheaper/faster than the main conversation model.
11
+ *
12
+ * Usage:
13
+ * pi --extension examples/extensions/custom-compaction.ts
14
+ */
15
+
16
+ import { complete, getModel } from "@mariozechner/pi-ai";
17
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
18
+ import { convertToLlm, serializeConversation } from "@mariozechner/pi-coding-agent";
19
+
20
+ export default function (pi: ExtensionAPI) {
21
+ pi.on("session_before_compact", async (event, ctx) => {
22
+ ctx.ui.notify("Custom compaction extension triggered", "info");
23
+
24
+ const { preparation, branchEntries: _, signal } = event;
25
+ const { messagesToSummarize, turnPrefixMessages, tokensBefore, firstKeptEntryId, previousSummary } = preparation;
26
+
27
+ // Use Gemini Flash for summarization (cheaper/faster than most conversation models)
28
+ const model = getModel("google", "gemini-2.5-flash");
29
+ if (!model) {
30
+ ctx.ui.notify(`Could not find Gemini Flash model, using default compaction`, "warning");
31
+ return;
32
+ }
33
+
34
+ // Resolve API key for the summarization model
35
+ const apiKey = await ctx.modelRegistry.getApiKey(model);
36
+ if (!apiKey) {
37
+ ctx.ui.notify(`No API key for ${model.provider}, using default compaction`, "warning");
38
+ return;
39
+ }
40
+
41
+ // Combine all messages for full summary
42
+ const allMessages = [...messagesToSummarize, ...turnPrefixMessages];
43
+
44
+ ctx.ui.notify(
45
+ `Custom compaction: summarizing ${allMessages.length} messages (${tokensBefore.toLocaleString()} tokens) with ${model.id}...`,
46
+ "info",
47
+ );
48
+
49
+ // Convert messages to readable text format
50
+ const conversationText = serializeConversation(convertToLlm(allMessages));
51
+
52
+ // Include previous summary context if available
53
+ const previousContext = previousSummary ? `\n\nPrevious session summary for context:\n${previousSummary}` : "";
54
+
55
+ // Build messages that ask for a comprehensive summary
56
+ const summaryMessages = [
57
+ {
58
+ role: "user" as const,
59
+ content: [
60
+ {
61
+ type: "text" as const,
62
+ text: `You are a conversation summarizer. Create a comprehensive summary of this conversation that captures:${previousContext}
63
+
64
+ 1. The main goals and objectives discussed
65
+ 2. Key decisions made and their rationale
66
+ 3. Important code changes, file modifications, or technical details
67
+ 4. Current state of any ongoing work
68
+ 5. Any blockers, issues, or open questions
69
+ 6. Next steps that were planned or suggested
70
+
71
+ Be thorough but concise. The summary will replace the ENTIRE conversation history, so include all information needed to continue the work effectively.
72
+
73
+ Format the summary as structured markdown with clear sections.
74
+
75
+ <conversation>
76
+ ${conversationText}
77
+ </conversation>`,
78
+ },
79
+ ],
80
+ timestamp: Date.now(),
81
+ },
82
+ ];
83
+
84
+ try {
85
+ // Pass signal to honor abort requests (e.g., user cancels compaction)
86
+ const response = await complete(model, { messages: summaryMessages }, { apiKey, maxTokens: 8192, signal });
87
+
88
+ const summary = response.content
89
+ .filter((c): c is { type: "text"; text: string } => c.type === "text")
90
+ .map((c) => c.text)
91
+ .join("\n");
92
+
93
+ if (!summary.trim()) {
94
+ if (!signal.aborted) ctx.ui.notify("Compaction summary was empty, using default compaction", "warning");
95
+ return;
96
+ }
97
+
98
+ // Return compaction content - SessionManager adds id/parentId
99
+ // Use firstKeptEntryId from preparation to keep recent messages
100
+ return {
101
+ compaction: {
102
+ summary,
103
+ firstKeptEntryId,
104
+ tokensBefore,
105
+ },
106
+ };
107
+ } catch (error) {
108
+ const message = error instanceof Error ? error.message : String(error);
109
+ ctx.ui.notify(`Compaction failed: ${message}`, "error");
110
+ // Fall back to default compaction on error
111
+ return;
112
+ }
113
+ });
114
+ }
@@ -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 "@mariozechner/pi-ai";
12
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
13
+ import { truncateToWidth, visibleWidth } from "@mariozechner/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,72 @@
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 "@mariozechner/pi-coding-agent";
9
+
10
+ // --- PI MASCOT ---
11
+ // Based on pi_mascot.ts - the pi agent character
12
+ function getPiMascot(theme: Theme): string[] {
13
+ // --- COLORS ---
14
+ // 3b1b Blue: R=80, G=180, B=230
15
+ const piBlue = (text: string) => theme.fg("accent", text);
16
+ const white = (text: string) => text; // Use plain white (or theme.fg("text", text))
17
+ const black = (text: string) => theme.fg("dim", text); // Use dim for contrast
18
+
19
+ // --- GLYPHS ---
20
+ const BLOCK = "█";
21
+ const PUPIL = "▌"; // Vertical half-block for the pupil
22
+
23
+ // --- CONSTRUCTION ---
24
+
25
+ // 1. The Eye Unit: [White Full Block][Black Vertical Sliver]
26
+ // This creates the "looking sideways" effect
27
+ const eye = `${white(BLOCK)}${black(PUPIL)}`;
28
+
29
+ // 2. Line 1: The Eyes
30
+ // 5 spaces indent aligns them with the start of the legs
31
+ const lineEyes = ` ${eye} ${eye}`;
32
+
33
+ // 3. Line 2: The Wide Top Bar (The "Overhang")
34
+ // 14 blocks wide for that serif-style roof
35
+ const lineBar = ` ${piBlue(BLOCK.repeat(14))}`;
36
+
37
+ // 4. Lines 3-6: The Legs
38
+ // Indented 5 spaces relative to the very left edge
39
+ // Leg width: 2 blocks | Gap: 4 blocks
40
+ const lineLeg = ` ${piBlue(BLOCK.repeat(2))} ${piBlue(BLOCK.repeat(2))}`;
41
+
42
+ // --- ASSEMBLY ---
43
+ return ["", lineEyes, lineBar, lineLeg, lineLeg, lineLeg, lineLeg, ""];
44
+ }
45
+
46
+ export default function (pi: ExtensionAPI) {
47
+ // Set custom header immediately on load (if UI is available)
48
+ pi.on("session_start", async (_event, ctx) => {
49
+ if (ctx.hasUI) {
50
+ ctx.ui.setHeader((_tui, theme) => {
51
+ return {
52
+ render(_width: number): string[] {
53
+ const mascotLines = getPiMascot(theme);
54
+ // Add a subtitle with hint
55
+ const subtitle = theme.fg("muted", " shitty coding agent");
56
+ return [...mascotLines, subtitle];
57
+ },
58
+ invalidate() {},
59
+ };
60
+ });
61
+ }
62
+ });
63
+
64
+ // Command to restore built-in header
65
+ pi.registerCommand("builtin-header", {
66
+ description: "Restore built-in header with keybinding hints",
67
+ handler: async (_args, ctx) => {
68
+ ctx.ui.setHeader(undefined);
69
+ ctx.ui.notify("Built-in header restored", "info");
70
+ },
71
+ });
72
+ }