@openeryc/pi-coding-agent 0.75.28 → 0.75.29

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 (301) hide show
  1. package/CHANGELOG.md +0 -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 +2 -0
  14. package/dist/core/agent-session.d.ts.map +1 -1
  15. package/dist/core/agent-session.js +20 -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/keybindings.d.ts +135 -7
  30. package/dist/core/keybindings.d.ts.map +1 -1
  31. package/dist/core/keybindings.js +1 -1
  32. package/dist/core/keybindings.js.map +1 -1
  33. package/dist/core/mcp/client.d.ts +11 -30
  34. package/dist/core/mcp/client.d.ts.map +1 -1
  35. package/dist/core/mcp/client.js +110 -55
  36. package/dist/core/mcp/client.js.map +1 -1
  37. package/dist/core/mcp/index.d.ts +3 -1
  38. package/dist/core/mcp/index.d.ts.map +1 -1
  39. package/dist/core/mcp/index.js.map +1 -1
  40. package/dist/core/mcp/manager.d.ts +9 -3
  41. package/dist/core/mcp/manager.d.ts.map +1 -1
  42. package/dist/core/mcp/manager.js +105 -71
  43. package/dist/core/mcp/manager.js.map +1 -1
  44. package/dist/core/mcp/types.d.ts +86 -0
  45. package/dist/core/mcp/types.d.ts.map +1 -0
  46. package/dist/core/mcp/types.js +8 -0
  47. package/dist/core/mcp/types.js.map +1 -0
  48. package/dist/core/tools/bash.d.ts.map +1 -1
  49. package/dist/core/tools/bash.js +1 -1
  50. package/dist/core/tools/bash.js.map +1 -1
  51. package/dist/core/tools/edit.d.ts +1 -1
  52. package/dist/core/tools/edit.d.ts.map +1 -1
  53. package/dist/core/tools/edit.js +1 -1
  54. package/dist/core/tools/edit.js.map +1 -1
  55. package/dist/core/tools/find.d.ts.map +1 -1
  56. package/dist/core/tools/find.js +1 -1
  57. package/dist/core/tools/find.js.map +1 -1
  58. package/dist/core/tools/grep.d.ts.map +1 -1
  59. package/dist/core/tools/grep.js +1 -1
  60. package/dist/core/tools/grep.js.map +1 -1
  61. package/dist/core/tools/ls.d.ts.map +1 -1
  62. package/dist/core/tools/ls.js +1 -1
  63. package/dist/core/tools/ls.js.map +1 -1
  64. package/dist/core/tools/read.d.ts.map +1 -1
  65. package/dist/core/tools/read.js +1 -1
  66. package/dist/core/tools/read.js.map +1 -1
  67. package/dist/core/tools/render-utils.d.ts.map +1 -1
  68. package/dist/core/tools/render-utils.js +1 -1
  69. package/dist/core/tools/render-utils.js.map +1 -1
  70. package/dist/core/tools/write.d.ts.map +1 -1
  71. package/dist/core/tools/write.js +1 -1
  72. package/dist/core/tools/write.js.map +1 -1
  73. package/dist/index.d.ts +3 -5
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +5 -7
  76. package/dist/index.js.map +1 -1
  77. package/dist/main.d.ts.map +1 -1
  78. package/dist/main.js +106 -92
  79. package/dist/main.js.map +1 -1
  80. package/dist/modes/index.d.ts +4 -0
  81. package/dist/modes/index.d.ts.map +1 -1
  82. package/dist/modes/index.js +4 -0
  83. package/dist/modes/index.js.map +1 -1
  84. package/dist/modes/interactive/assets/clankolas.png +0 -0
  85. package/dist/modes/interactive/components/armin.d.ts +34 -0
  86. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  87. package/dist/modes/interactive/components/armin.js +333 -0
  88. package/dist/modes/interactive/components/armin.js.map +1 -0
  89. package/dist/modes/interactive/components/assistant-message.d.ts +20 -0
  90. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  91. package/dist/modes/interactive/components/assistant-message.js +121 -0
  92. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  93. package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
  94. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  95. package/dist/modes/interactive/components/bash-execution.js +175 -0
  96. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  97. package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
  98. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  99. package/dist/modes/interactive/components/bordered-loader.js +54 -0
  100. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  101. package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  102. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  103. package/dist/modes/interactive/components/branch-summary-message.js +44 -0
  104. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  105. package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  106. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  107. package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
  108. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  109. package/dist/modes/interactive/components/config-selector.d.ts +71 -0
  110. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  111. package/dist/modes/interactive/components/config-selector.js +506 -0
  112. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  113. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  114. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  115. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  116. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  117. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  118. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  119. package/dist/modes/interactive/components/custom-editor.js +70 -0
  120. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  121. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  122. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  123. package/dist/modes/interactive/components/custom-message.js +79 -0
  124. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  125. package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
  126. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
  127. package/dist/modes/interactive/components/daxnuts.js +140 -0
  128. package/dist/modes/interactive/components/daxnuts.js.map +1 -0
  129. package/dist/modes/interactive/components/diff.d.ts +8 -1
  130. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  131. package/dist/modes/interactive/components/diff.js +131 -2
  132. package/dist/modes/interactive/components/diff.js.map +1 -1
  133. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  134. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  135. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  136. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  137. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  138. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  139. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  140. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  141. package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
  142. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  143. package/dist/modes/interactive/components/extension-editor.js +119 -0
  144. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  145. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  146. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  147. package/dist/modes/interactive/components/extension-input.js +61 -0
  148. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  149. package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
  150. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  151. package/dist/modes/interactive/components/extension-selector.js +83 -0
  152. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  153. package/dist/modes/interactive/components/footer.d.ts +27 -0
  154. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  155. package/dist/modes/interactive/components/footer.js +201 -0
  156. package/dist/modes/interactive/components/footer.js.map +1 -0
  157. package/dist/modes/interactive/components/index.d.ts +32 -0
  158. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  159. package/dist/modes/interactive/components/index.js +33 -0
  160. package/dist/modes/interactive/components/index.js.map +1 -0
  161. package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -2
  162. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  163. package/dist/modes/interactive/components/keybinding-hints.js +33 -4
  164. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  165. package/dist/modes/interactive/components/login-dialog.d.ts +46 -0
  166. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  167. package/dist/modes/interactive/components/login-dialog.js +160 -0
  168. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  169. package/dist/modes/interactive/components/model-selector.d.ts +47 -0
  170. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  171. package/dist/modes/interactive/components/model-selector.js +278 -0
  172. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  173. package/dist/modes/interactive/components/oauth-selector.d.ts +31 -0
  174. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  175. package/dist/modes/interactive/components/oauth-selector.js +165 -0
  176. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  177. package/dist/modes/interactive/components/scoped-models-selector.d.ts +42 -0
  178. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  179. package/dist/modes/interactive/components/scoped-models-selector.js +290 -0
  180. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  181. package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
  182. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  183. package/dist/modes/interactive/components/session-selector-search.js +155 -0
  184. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  185. package/dist/modes/interactive/components/session-selector.d.ts +96 -0
  186. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  187. package/dist/modes/interactive/components/session-selector.js +861 -0
  188. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  189. package/dist/modes/interactive/components/settings-selector.d.ts +69 -0
  190. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  191. package/dist/modes/interactive/components/settings-selector.js +390 -0
  192. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  193. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  194. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  195. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  196. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  197. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  198. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  199. package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
  200. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  201. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  202. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  203. package/dist/modes/interactive/components/theme-selector.js +50 -0
  204. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  205. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  206. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  207. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  208. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  209. package/dist/modes/interactive/components/tool-execution.d.ts +63 -0
  210. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  211. package/dist/modes/interactive/components/tool-execution.js +295 -0
  212. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  213. package/dist/modes/interactive/components/tree-selector.d.ts +89 -0
  214. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  215. package/dist/modes/interactive/components/tree-selector.js +1093 -0
  216. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  217. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  218. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  219. package/dist/modes/interactive/components/user-message-selector.js +114 -0
  220. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  221. package/dist/modes/interactive/components/user-message.d.ts +10 -0
  222. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  223. package/dist/modes/interactive/components/user-message.js +29 -0
  224. package/dist/modes/interactive/components/user-message.js.map +1 -0
  225. package/dist/modes/interactive/components/visual-truncate.d.ts +19 -1
  226. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  227. package/dist/modes/interactive/components/visual-truncate.js +31 -4
  228. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  229. package/dist/modes/interactive/interactive-mode.d.ts +375 -0
  230. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  231. package/dist/modes/interactive/interactive-mode.js +4799 -0
  232. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  233. package/dist/modes/interactive/theme/dark.json +86 -0
  234. package/dist/modes/interactive/theme/light.json +85 -0
  235. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  236. package/dist/modes/interactive/theme/theme.d.ts +89 -27
  237. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  238. package/dist/modes/interactive/theme/theme.js +992 -44
  239. package/dist/modes/interactive/theme/theme.js.map +1 -1
  240. package/dist/package-manager-cli.d.ts.map +1 -1
  241. package/dist/package-manager-cli.js +1 -1
  242. package/dist/package-manager-cli.js.map +1 -1
  243. package/examples/extensions/border-status-editor.ts +150 -0
  244. package/examples/extensions/built-in-tool-renderer.ts +249 -0
  245. package/examples/extensions/custom-footer.ts +64 -0
  246. package/examples/extensions/custom-header.ts +73 -0
  247. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  248. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  249. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  250. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  251. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  252. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  253. package/examples/extensions/doom-overlay/README.md +46 -0
  254. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  255. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  256. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  257. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  258. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  259. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  260. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  261. package/examples/extensions/doom-overlay/index.ts +74 -0
  262. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  263. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  264. package/examples/extensions/handoff.ts +191 -0
  265. package/examples/extensions/interactive-shell.ts +196 -0
  266. package/examples/extensions/message-renderer.ts +59 -0
  267. package/examples/extensions/minimal-mode.ts +426 -0
  268. package/examples/extensions/modal-editor.ts +85 -0
  269. package/examples/extensions/overlay-qa-tests.ts +1379 -0
  270. package/examples/extensions/overlay-test.ts +153 -0
  271. package/examples/extensions/plan-mode/index.ts +340 -0
  272. package/examples/extensions/preset.ts +430 -0
  273. package/examples/extensions/qna.ts +122 -0
  274. package/examples/extensions/question.ts +264 -0
  275. package/examples/extensions/questionnaire.ts +427 -0
  276. package/examples/extensions/rainbow-editor.ts +88 -0
  277. package/examples/extensions/sandbox/index.ts +321 -0
  278. package/examples/extensions/sandbox/package-lock.json +92 -0
  279. package/examples/extensions/sandbox/package.json +19 -0
  280. package/examples/extensions/snake.ts +343 -0
  281. package/examples/extensions/space-invaders.ts +560 -0
  282. package/examples/extensions/ssh.ts +220 -0
  283. package/examples/extensions/status-line.ts +32 -0
  284. package/examples/extensions/structured-output.ts +65 -0
  285. package/examples/extensions/subagent/index.ts +1009 -0
  286. package/examples/extensions/summarize.ts +206 -0
  287. package/examples/extensions/tic-tac-toe.ts +1008 -0
  288. package/examples/extensions/todo.ts +297 -0
  289. package/examples/extensions/tools.ts +141 -0
  290. package/examples/extensions/truncated-tool.ts +195 -0
  291. package/examples/extensions/with-deps/index.ts +32 -0
  292. package/examples/extensions/with-deps/package-lock.json +31 -0
  293. package/examples/extensions/with-deps/package.json +22 -0
  294. package/examples/extensions/working-indicator.ts +123 -0
  295. package/examples/rpc-extension-ui.ts +632 -0
  296. package/npm-shrinkwrap.json +246 -240
  297. package/package.json +7 -6
  298. package/dist/core/tui-stubs.d.ts +0 -95
  299. package/dist/core/tui-stubs.d.ts.map +0 -1
  300. package/dist/core/tui-stubs.js +0 -90
  301. package/dist/core/tui-stubs.js.map +0 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Rainbow Editor - highlights "ultrathink" with animated shine effect
3
+ *
4
+ * Usage: pi --extension ./examples/extensions/rainbow-editor.ts
5
+ */
6
+
7
+ import { CustomEditor, type ExtensionAPI } from "@openeryc/pi-coding-agent";
8
+
9
+ // Base colors (coral → yellow → green → teal → blue → purple → pink)
10
+ const COLORS: [number, number, number][] = [
11
+ [233, 137, 115], // coral
12
+ [228, 186, 103], // yellow
13
+ [141, 192, 122], // green
14
+ [102, 194, 179], // teal
15
+ [121, 157, 207], // blue
16
+ [157, 134, 195], // purple
17
+ [206, 130, 172], // pink
18
+ ];
19
+ const RESET = "\x1b[0m";
20
+
21
+ function brighten(rgb: [number, number, number], factor: number): string {
22
+ const [r, g, b] = rgb.map((c) => Math.round(c + (255 - c) * factor));
23
+ return `\x1b[38;2;${r};${g};${b}m`;
24
+ }
25
+
26
+ function colorize(text: string, shinePos: number): string {
27
+ return (
28
+ [...text]
29
+ .map((c, i) => {
30
+ const baseColor = COLORS[i % COLORS.length]!;
31
+ // 3-letter shine: center bright, adjacent dimmer
32
+ let factor = 0;
33
+ if (shinePos >= 0) {
34
+ const dist = Math.abs(i - shinePos);
35
+ if (dist === 0) factor = 0.7;
36
+ else if (dist === 1) factor = 0.35;
37
+ }
38
+ return `${brighten(baseColor, factor)}${c}`;
39
+ })
40
+ .join("") + RESET
41
+ );
42
+ }
43
+
44
+ class RainbowEditor extends CustomEditor {
45
+ private animationTimer?: ReturnType<typeof setInterval>;
46
+ private frame = 0;
47
+
48
+ private hasUltrathink(): boolean {
49
+ return /ultrathink/i.test(this.getText());
50
+ }
51
+
52
+ private startAnimation(): void {
53
+ if (this.animationTimer) return;
54
+ this.animationTimer = setInterval(() => {
55
+ this.frame++;
56
+ this.tui.requestRender();
57
+ }, 60);
58
+ }
59
+
60
+ private stopAnimation(): void {
61
+ if (this.animationTimer) {
62
+ clearInterval(this.animationTimer);
63
+ this.animationTimer = undefined;
64
+ }
65
+ }
66
+
67
+ handleInput(data: string): void {
68
+ super.handleInput(data);
69
+ if (this.hasUltrathink()) {
70
+ this.startAnimation();
71
+ } else {
72
+ this.stopAnimation();
73
+ }
74
+ }
75
+
76
+ render(width: number): string[] {
77
+ // Cycle: 10 shine positions + 10 pause frames
78
+ const cycle = this.frame % 20;
79
+ const shinePos = cycle < 10 ? cycle : -1; // -1 means no shine (pause)
80
+ return super.render(width).map((line) => line.replace(/ultrathink/gi, (m) => colorize(m, shinePos)));
81
+ }
82
+ }
83
+
84
+ export default function (pi: ExtensionAPI) {
85
+ pi.on("session_start", (_event, ctx) => {
86
+ ctx.ui.setEditorComponent((tui, theme, kb) => new RainbowEditor(tui, theme, kb));
87
+ });
88
+ }
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Sandbox Extension - OS-level sandboxing for bash commands
3
+ *
4
+ * Uses @anthropic-ai/sandbox-runtime to enforce filesystem and network
5
+ * restrictions on bash commands at the OS level (sandbox-exec on macOS,
6
+ * bubblewrap on Linux).
7
+ *
8
+ * Note: this example intentionally overrides the built-in `bash` tool to show
9
+ * how built-in tools can be replaced. Alternatively, you could sandbox `bash`
10
+ * via `tool_call` input mutation without replacing the tool.
11
+ *
12
+ * Config files (merged, project takes precedence):
13
+ * - ~/.pi/agent/extensions/sandbox.json (global)
14
+ * - <cwd>/.pi/sandbox.json (project-local)
15
+ *
16
+ * Example .pi/sandbox.json:
17
+ * ```json
18
+ * {
19
+ * "enabled": true,
20
+ * "network": {
21
+ * "allowedDomains": ["github.com", "*.github.com"],
22
+ * "deniedDomains": []
23
+ * },
24
+ * "filesystem": {
25
+ * "denyRead": ["~/.ssh", "~/.aws"],
26
+ * "allowWrite": [".", "/tmp"],
27
+ * "denyWrite": [".env"]
28
+ * }
29
+ * }
30
+ * ```
31
+ *
32
+ * Usage:
33
+ * - `pi -e ./sandbox` - sandbox enabled with default/config settings
34
+ * - `pi -e ./sandbox --no-sandbox` - disable sandboxing
35
+ * - `/sandbox` - show current sandbox configuration
36
+ *
37
+ * Setup:
38
+ * 1. Copy sandbox/ directory to ~/.pi/agent/extensions/
39
+ * 2. Run `npm install` in ~/.pi/agent/extensions/sandbox/
40
+ *
41
+ * Linux also requires: bubblewrap, socat, ripgrep
42
+ */
43
+
44
+ import { spawn } from "node:child_process";
45
+ import { existsSync, readFileSync } from "node:fs";
46
+ import { join } from "node:path";
47
+ import { SandboxManager, type SandboxRuntimeConfig } from "@anthropic-ai/sandbox-runtime";
48
+ import type { ExtensionAPI } from "@openeryc/pi-coding-agent";
49
+ import { type BashOperations, createBashTool, getAgentDir } from "@openeryc/pi-coding-agent";
50
+
51
+ interface SandboxConfig extends SandboxRuntimeConfig {
52
+ enabled?: boolean;
53
+ }
54
+
55
+ const DEFAULT_CONFIG: SandboxConfig = {
56
+ enabled: true,
57
+ network: {
58
+ allowedDomains: [
59
+ "npmjs.org",
60
+ "*.npmjs.org",
61
+ "registry.npmjs.org",
62
+ "registry.yarnpkg.com",
63
+ "pypi.org",
64
+ "*.pypi.org",
65
+ "github.com",
66
+ "*.github.com",
67
+ "api.github.com",
68
+ "raw.githubusercontent.com",
69
+ ],
70
+ deniedDomains: [],
71
+ },
72
+ filesystem: {
73
+ denyRead: ["~/.ssh", "~/.aws", "~/.gnupg"],
74
+ allowWrite: [".", "/tmp"],
75
+ denyWrite: [".env", ".env.*", "*.pem", "*.key"],
76
+ },
77
+ };
78
+
79
+ function loadConfig(cwd: string): SandboxConfig {
80
+ const projectConfigPath = join(cwd, ".pi", "sandbox.json");
81
+ const globalConfigPath = join(getAgentDir(), "extensions", "sandbox.json");
82
+
83
+ let globalConfig: Partial<SandboxConfig> = {};
84
+ let projectConfig: Partial<SandboxConfig> = {};
85
+
86
+ if (existsSync(globalConfigPath)) {
87
+ try {
88
+ globalConfig = JSON.parse(readFileSync(globalConfigPath, "utf-8"));
89
+ } catch (e) {
90
+ console.error(`Warning: Could not parse ${globalConfigPath}: ${e}`);
91
+ }
92
+ }
93
+
94
+ if (existsSync(projectConfigPath)) {
95
+ try {
96
+ projectConfig = JSON.parse(readFileSync(projectConfigPath, "utf-8"));
97
+ } catch (e) {
98
+ console.error(`Warning: Could not parse ${projectConfigPath}: ${e}`);
99
+ }
100
+ }
101
+
102
+ return deepMerge(deepMerge(DEFAULT_CONFIG, globalConfig), projectConfig);
103
+ }
104
+
105
+ function deepMerge(base: SandboxConfig, overrides: Partial<SandboxConfig>): SandboxConfig {
106
+ const result: SandboxConfig = { ...base };
107
+
108
+ if (overrides.enabled !== undefined) result.enabled = overrides.enabled;
109
+ if (overrides.network) {
110
+ result.network = { ...base.network, ...overrides.network };
111
+ }
112
+ if (overrides.filesystem) {
113
+ result.filesystem = { ...base.filesystem, ...overrides.filesystem };
114
+ }
115
+
116
+ const extOverrides = overrides as {
117
+ ignoreViolations?: Record<string, string[]>;
118
+ enableWeakerNestedSandbox?: boolean;
119
+ };
120
+ const extResult = result as { ignoreViolations?: Record<string, string[]>; enableWeakerNestedSandbox?: boolean };
121
+
122
+ if (extOverrides.ignoreViolations) {
123
+ extResult.ignoreViolations = extOverrides.ignoreViolations;
124
+ }
125
+ if (extOverrides.enableWeakerNestedSandbox !== undefined) {
126
+ extResult.enableWeakerNestedSandbox = extOverrides.enableWeakerNestedSandbox;
127
+ }
128
+
129
+ return result;
130
+ }
131
+
132
+ function createSandboxedBashOps(): BashOperations {
133
+ return {
134
+ async exec(command, cwd, { onData, signal, timeout }) {
135
+ if (!existsSync(cwd)) {
136
+ throw new Error(`Working directory does not exist: ${cwd}`);
137
+ }
138
+
139
+ const wrappedCommand = await SandboxManager.wrapWithSandbox(command);
140
+
141
+ return new Promise((resolve, reject) => {
142
+ const child = spawn("bash", ["-c", wrappedCommand], {
143
+ cwd,
144
+ detached: true,
145
+ stdio: ["ignore", "pipe", "pipe"],
146
+ });
147
+
148
+ let timedOut = false;
149
+ let timeoutHandle: NodeJS.Timeout | undefined;
150
+
151
+ if (timeout !== undefined && timeout > 0) {
152
+ timeoutHandle = setTimeout(() => {
153
+ timedOut = true;
154
+ if (child.pid) {
155
+ try {
156
+ process.kill(-child.pid, "SIGKILL");
157
+ } catch {
158
+ child.kill("SIGKILL");
159
+ }
160
+ }
161
+ }, timeout * 1000);
162
+ }
163
+
164
+ child.stdout?.on("data", onData);
165
+ child.stderr?.on("data", onData);
166
+
167
+ child.on("error", (err) => {
168
+ if (timeoutHandle) clearTimeout(timeoutHandle);
169
+ reject(err);
170
+ });
171
+
172
+ const onAbort = () => {
173
+ if (child.pid) {
174
+ try {
175
+ process.kill(-child.pid, "SIGKILL");
176
+ } catch {
177
+ child.kill("SIGKILL");
178
+ }
179
+ }
180
+ };
181
+
182
+ signal?.addEventListener("abort", onAbort, { once: true });
183
+
184
+ child.on("close", (code) => {
185
+ if (timeoutHandle) clearTimeout(timeoutHandle);
186
+ signal?.removeEventListener("abort", onAbort);
187
+
188
+ if (signal?.aborted) {
189
+ reject(new Error("aborted"));
190
+ } else if (timedOut) {
191
+ reject(new Error(`timeout:${timeout}`));
192
+ } else {
193
+ resolve({ exitCode: code });
194
+ }
195
+ });
196
+ });
197
+ },
198
+ };
199
+ }
200
+
201
+ export default function (pi: ExtensionAPI) {
202
+ pi.registerFlag("no-sandbox", {
203
+ description: "Disable OS-level sandboxing for bash commands",
204
+ type: "boolean",
205
+ default: false,
206
+ });
207
+
208
+ const localCwd = process.cwd();
209
+ const localBash = createBashTool(localCwd);
210
+
211
+ let sandboxEnabled = false;
212
+ let sandboxInitialized = false;
213
+
214
+ pi.registerTool({
215
+ ...localBash,
216
+ label: "bash (sandboxed)",
217
+ async execute(id, params, signal, onUpdate, _ctx) {
218
+ if (!sandboxEnabled || !sandboxInitialized) {
219
+ return localBash.execute(id, params, signal, onUpdate);
220
+ }
221
+
222
+ const sandboxedBash = createBashTool(localCwd, {
223
+ operations: createSandboxedBashOps(),
224
+ });
225
+ return sandboxedBash.execute(id, params, signal, onUpdate);
226
+ },
227
+ });
228
+
229
+ pi.on("user_bash", () => {
230
+ if (!sandboxEnabled || !sandboxInitialized) return;
231
+ return { operations: createSandboxedBashOps() };
232
+ });
233
+
234
+ pi.on("session_start", async (_event, ctx) => {
235
+ const noSandbox = pi.getFlag("no-sandbox") as boolean;
236
+
237
+ if (noSandbox) {
238
+ sandboxEnabled = false;
239
+ ctx.ui.notify("Sandbox disabled via --no-sandbox", "warning");
240
+ return;
241
+ }
242
+
243
+ const config = loadConfig(ctx.cwd);
244
+
245
+ if (!config.enabled) {
246
+ sandboxEnabled = false;
247
+ ctx.ui.notify("Sandbox disabled via config", "info");
248
+ return;
249
+ }
250
+
251
+ const platform = process.platform;
252
+ if (platform !== "darwin" && platform !== "linux") {
253
+ sandboxEnabled = false;
254
+ ctx.ui.notify(`Sandbox not supported on ${platform}`, "warning");
255
+ return;
256
+ }
257
+
258
+ try {
259
+ const configExt = config as unknown as {
260
+ ignoreViolations?: Record<string, string[]>;
261
+ enableWeakerNestedSandbox?: boolean;
262
+ };
263
+
264
+ await SandboxManager.initialize({
265
+ network: config.network,
266
+ filesystem: config.filesystem,
267
+ ignoreViolations: configExt.ignoreViolations,
268
+ enableWeakerNestedSandbox: configExt.enableWeakerNestedSandbox,
269
+ });
270
+
271
+ sandboxEnabled = true;
272
+ sandboxInitialized = true;
273
+
274
+ const networkCount = config.network?.allowedDomains?.length ?? 0;
275
+ const writeCount = config.filesystem?.allowWrite?.length ?? 0;
276
+ ctx.ui.setStatus(
277
+ "sandbox",
278
+ ctx.ui.theme.fg("accent", `🔒 Sandbox: ${networkCount} domains, ${writeCount} write paths`),
279
+ );
280
+ ctx.ui.notify("Sandbox initialized", "info");
281
+ } catch (err) {
282
+ sandboxEnabled = false;
283
+ ctx.ui.notify(`Sandbox initialization failed: ${err instanceof Error ? err.message : err}`, "error");
284
+ }
285
+ });
286
+
287
+ pi.on("session_shutdown", async () => {
288
+ if (sandboxInitialized) {
289
+ try {
290
+ await SandboxManager.reset();
291
+ } catch {
292
+ // Ignore cleanup errors
293
+ }
294
+ }
295
+ });
296
+
297
+ pi.registerCommand("sandbox", {
298
+ description: "Show sandbox configuration",
299
+ handler: async (_args, ctx) => {
300
+ if (!sandboxEnabled) {
301
+ ctx.ui.notify("Sandbox is disabled", "info");
302
+ return;
303
+ }
304
+
305
+ const config = loadConfig(ctx.cwd);
306
+ const lines = [
307
+ "Sandbox Configuration:",
308
+ "",
309
+ "Network:",
310
+ ` Allowed: ${config.network?.allowedDomains?.join(", ") || "(none)"}`,
311
+ ` Denied: ${config.network?.deniedDomains?.join(", ") || "(none)"}`,
312
+ "",
313
+ "Filesystem:",
314
+ ` Deny Read: ${config.filesystem?.denyRead?.join(", ") || "(none)"}`,
315
+ ` Allow Write: ${config.filesystem?.allowWrite?.join(", ") || "(none)"}`,
316
+ ` Deny Write: ${config.filesystem?.denyWrite?.join(", ") || "(none)"}`,
317
+ ];
318
+ ctx.ui.notify(lines.join("\n"), "info");
319
+ },
320
+ });
321
+ }
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "pi-extension-sandbox",
3
+ "version": "1.5.29",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "pi-extension-sandbox",
9
+ "version": "1.5.29",
10
+ "dependencies": {
11
+ "@anthropic-ai/sandbox-runtime": "^0.0.26"
12
+ }
13
+ },
14
+ "node_modules/@anthropic-ai/sandbox-runtime": {
15
+ "version": "0.0.26",
16
+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sandbox-runtime/-/sandbox-runtime-0.0.26.tgz",
17
+ "integrity": "sha512-DYV5LSsVMnzq0lbfaYMSpxZPUMAx4+hy343dRss+pVCLIfF62qOhxpYfZ5TmOk1GTDQm5f9wPprMNSStmnsV4w==",
18
+ "license": "Apache-2.0",
19
+ "dependencies": {
20
+ "@pondwader/socks5-server": "^1.0.10",
21
+ "@types/lodash-es": "^4.17.12",
22
+ "commander": "^12.1.0",
23
+ "lodash-es": "^4.17.21",
24
+ "shell-quote": "^1.8.3",
25
+ "zod": "^3.24.1"
26
+ },
27
+ "bin": {
28
+ "srt": "dist/cli.js"
29
+ },
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ }
33
+ },
34
+ "node_modules/@pondwader/socks5-server": {
35
+ "version": "1.0.10",
36
+ "resolved": "https://registry.npmjs.org/@pondwader/socks5-server/-/socks5-server-1.0.10.tgz",
37
+ "integrity": "sha512-bQY06wzzR8D2+vVCUoBsr5QS2U6UgPUQRmErNwtsuI6vLcyRKkafjkr3KxbtGFf9aBBIV2mcvlsKD1UYaIV+sg==",
38
+ "license": "MIT"
39
+ },
40
+ "node_modules/@types/lodash": {
41
+ "version": "4.17.23",
42
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.23.tgz",
43
+ "integrity": "sha512-RDvF6wTulMPjrNdCoYRC8gNR880JNGT8uB+REUpC2Ns4pRqQJhGz90wh7rgdXDPpCczF3VGktDuFGVnz8zP7HA==",
44
+ "license": "MIT"
45
+ },
46
+ "node_modules/@types/lodash-es": {
47
+ "version": "4.17.12",
48
+ "resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
49
+ "integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
50
+ "license": "MIT",
51
+ "dependencies": {
52
+ "@types/lodash": "*"
53
+ }
54
+ },
55
+ "node_modules/commander": {
56
+ "version": "12.1.0",
57
+ "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz",
58
+ "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==",
59
+ "license": "MIT",
60
+ "engines": {
61
+ "node": ">=18"
62
+ }
63
+ },
64
+ "node_modules/lodash-es": {
65
+ "version": "4.18.1",
66
+ "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz",
67
+ "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==",
68
+ "license": "MIT"
69
+ },
70
+ "node_modules/shell-quote": {
71
+ "version": "1.8.3",
72
+ "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
73
+ "integrity": "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==",
74
+ "license": "MIT",
75
+ "engines": {
76
+ "node": ">= 0.4"
77
+ },
78
+ "funding": {
79
+ "url": "https://github.com/sponsors/ljharb"
80
+ }
81
+ },
82
+ "node_modules/zod": {
83
+ "version": "3.25.76",
84
+ "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
85
+ "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
86
+ "license": "MIT",
87
+ "funding": {
88
+ "url": "https://github.com/sponsors/colinhacks"
89
+ }
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "pi-extension-sandbox",
3
+ "private": true,
4
+ "version": "1.5.29",
5
+ "type": "module",
6
+ "scripts": {
7
+ "clean": "echo 'nothing to clean'",
8
+ "build": "echo 'nothing to build'",
9
+ "check": "echo 'nothing to check'"
10
+ },
11
+ "pi": {
12
+ "extensions": [
13
+ "./index.ts"
14
+ ]
15
+ },
16
+ "dependencies": {
17
+ "@anthropic-ai/sandbox-runtime": "0.0.26"
18
+ }
19
+ }