@valni/cli-darwin-x64 0.0.0-stage → 0.1.2

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 (236) hide show
  1. package/LICENSE +53 -0
  2. package/package.json +18 -5
  3. package/runtime/LICENSE +53 -0
  4. package/runtime/README.md +674 -0
  5. package/runtime/assets/clankolas.png +0 -0
  6. package/runtime/docs/extensions.md +2910 -0
  7. package/runtime/docs/json.md +82 -0
  8. package/runtime/docs/models.md +540 -0
  9. package/runtime/docs/packages.md +228 -0
  10. package/runtime/docs/rpc.md +1480 -0
  11. package/runtime/docs/sdk.md +1183 -0
  12. package/runtime/docs/session-format.md +422 -0
  13. package/runtime/docs/settings.md +315 -0
  14. package/runtime/docs/shell-aliases.md +13 -0
  15. package/runtime/docs/terminal-setup.md +142 -0
  16. package/runtime/docs/termux.md +127 -0
  17. package/runtime/docs/tmux.md +63 -0
  18. package/runtime/docs/tui.md +927 -0
  19. package/runtime/docs/windows.md +17 -0
  20. package/runtime/examples/README.md +25 -0
  21. package/runtime/examples/extensions/README.md +212 -0
  22. package/runtime/examples/extensions/auto-commit-on-exit.ts +49 -0
  23. package/runtime/examples/extensions/bash-spawn-hook.ts +30 -0
  24. package/runtime/examples/extensions/bookmark.ts +50 -0
  25. package/runtime/examples/extensions/border-status-editor.ts +145 -0
  26. package/runtime/examples/extensions/built-in-tool-renderer.ts +249 -0
  27. package/runtime/examples/extensions/claude-rules.ts +86 -0
  28. package/runtime/examples/extensions/commands.ts +72 -0
  29. package/runtime/examples/extensions/confirm-destructive.ts +59 -0
  30. package/runtime/examples/extensions/custom-footer.ts +64 -0
  31. package/runtime/examples/extensions/custom-header.ts +73 -0
  32. package/runtime/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  33. package/runtime/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  34. package/runtime/examples/extensions/custom-provider-anthropic/package.json +19 -0
  35. package/runtime/examples/extensions/dirty-repo-guard.ts +56 -0
  36. package/runtime/examples/extensions/doom-overlay/README.md +46 -0
  37. package/runtime/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  38. package/runtime/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  39. package/runtime/examples/extensions/doom-overlay/doom/build.sh +152 -0
  40. package/runtime/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  41. package/runtime/examples/extensions/doom-overlay/doom-component.ts +132 -0
  42. package/runtime/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  43. package/runtime/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  44. package/runtime/examples/extensions/doom-overlay/index.ts +74 -0
  45. package/runtime/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  46. package/runtime/examples/extensions/dynamic-resources/SKILL.md +8 -0
  47. package/runtime/examples/extensions/dynamic-resources/dynamic.json +79 -0
  48. package/runtime/examples/extensions/dynamic-resources/dynamic.md +5 -0
  49. package/runtime/examples/extensions/dynamic-resources/index.ts +15 -0
  50. package/runtime/examples/extensions/dynamic-tools.ts +74 -0
  51. package/runtime/examples/extensions/entry-renderer.ts +41 -0
  52. package/runtime/examples/extensions/event-bus.ts +43 -0
  53. package/runtime/examples/extensions/file-trigger.ts +41 -0
  54. package/runtime/examples/extensions/git-checkpoint.ts +53 -0
  55. package/runtime/examples/extensions/git-merge-and-resolve.ts +115 -0
  56. package/runtime/examples/extensions/github-issue-autocomplete.ts +185 -0
  57. package/runtime/examples/extensions/gondolin/index.ts +531 -0
  58. package/runtime/examples/extensions/gondolin/package-lock.json +185 -0
  59. package/runtime/examples/extensions/gondolin/package.json +19 -0
  60. package/runtime/examples/extensions/hello.ts +26 -0
  61. package/runtime/examples/extensions/hidden-thinking-label.ts +53 -0
  62. package/runtime/examples/extensions/inline-bash.ts +94 -0
  63. package/runtime/examples/extensions/input-transform-streaming.ts +39 -0
  64. package/runtime/examples/extensions/input-transform.ts +43 -0
  65. package/runtime/examples/extensions/interactive-shell.ts +196 -0
  66. package/runtime/examples/extensions/mac-system-theme.ts +47 -0
  67. package/runtime/examples/extensions/message-renderer.ts +59 -0
  68. package/runtime/examples/extensions/minimal-mode.ts +426 -0
  69. package/runtime/examples/extensions/modal-editor.ts +85 -0
  70. package/runtime/examples/extensions/model-status.ts +31 -0
  71. package/runtime/examples/extensions/notify.ts +55 -0
  72. package/runtime/examples/extensions/overlay-qa-tests.ts +1450 -0
  73. package/runtime/examples/extensions/overlay-test.ts +153 -0
  74. package/runtime/examples/extensions/permission-gate.ts +34 -0
  75. package/runtime/examples/extensions/pirate.ts +47 -0
  76. package/runtime/examples/extensions/plan-mode/README.md +66 -0
  77. package/runtime/examples/extensions/plan-mode/index.ts +390 -0
  78. package/runtime/examples/extensions/plan-mode/utils.ts +168 -0
  79. package/runtime/examples/extensions/preset.ts +436 -0
  80. package/runtime/examples/extensions/project-trust.ts +64 -0
  81. package/runtime/examples/extensions/prompt-customizer.ts +97 -0
  82. package/runtime/examples/extensions/protected-paths.ts +30 -0
  83. package/runtime/examples/extensions/provider-payload.ts +18 -0
  84. package/runtime/examples/extensions/question.ts +278 -0
  85. package/runtime/examples/extensions/questionnaire.ts +440 -0
  86. package/runtime/examples/extensions/rainbow-editor.ts +88 -0
  87. package/runtime/examples/extensions/reload-runtime.ts +37 -0
  88. package/runtime/examples/extensions/rpc-demo.ts +118 -0
  89. package/runtime/examples/extensions/sandbox/index.ts +321 -0
  90. package/runtime/examples/extensions/sandbox/package-lock.json +92 -0
  91. package/runtime/examples/extensions/sandbox/package.json +19 -0
  92. package/runtime/examples/extensions/send-user-message.ts +97 -0
  93. package/runtime/examples/extensions/session-name.ts +27 -0
  94. package/runtime/examples/extensions/shutdown-command.ts +63 -0
  95. package/runtime/examples/extensions/snake.ts +343 -0
  96. package/runtime/examples/extensions/space-invaders.ts +560 -0
  97. package/runtime/examples/extensions/ssh.ts +220 -0
  98. package/runtime/examples/extensions/status-line.ts +32 -0
  99. package/runtime/examples/extensions/structured-output.ts +65 -0
  100. package/runtime/examples/extensions/subagent/README.md +175 -0
  101. package/runtime/examples/extensions/subagent/agents/planner.md +37 -0
  102. package/runtime/examples/extensions/subagent/agents/reviewer.md +35 -0
  103. package/runtime/examples/extensions/subagent/agents/scout.md +50 -0
  104. package/runtime/examples/extensions/subagent/agents/worker.md +24 -0
  105. package/runtime/examples/extensions/subagent/agents.ts +126 -0
  106. package/runtime/examples/extensions/subagent/index.ts +1009 -0
  107. package/runtime/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  108. package/runtime/examples/extensions/subagent/prompts/implement.md +10 -0
  109. package/runtime/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  110. package/runtime/examples/extensions/system-prompt-header.ts +17 -0
  111. package/runtime/examples/extensions/tic-tac-toe.ts +1008 -0
  112. package/runtime/examples/extensions/timed-confirm.ts +70 -0
  113. package/runtime/examples/extensions/titlebar-spinner.ts +58 -0
  114. package/runtime/examples/extensions/todo.ts +297 -0
  115. package/runtime/examples/extensions/tool-override.ts +144 -0
  116. package/runtime/examples/extensions/tools.ts +146 -0
  117. package/runtime/examples/extensions/trigger-compact.ts +50 -0
  118. package/runtime/examples/extensions/truncated-tool.ts +195 -0
  119. package/runtime/examples/extensions/widget-placement.ts +9 -0
  120. package/runtime/examples/extensions/with-deps/index.ts +32 -0
  121. package/runtime/examples/extensions/with-deps/package-lock.json +31 -0
  122. package/runtime/examples/extensions/with-deps/package.json +22 -0
  123. package/runtime/examples/extensions/working-indicator.ts +123 -0
  124. package/runtime/examples/extensions/working-message-test.ts +25 -0
  125. package/runtime/examples/rpc-extension-ui.ts +632 -0
  126. package/runtime/examples/sdk/01-minimal.ts +26 -0
  127. package/runtime/examples/sdk/02-custom-model.ts +43 -0
  128. package/runtime/examples/sdk/03-custom-prompt.ts +70 -0
  129. package/runtime/examples/sdk/04-skills.ts +55 -0
  130. package/runtime/examples/sdk/05-tools.ts +48 -0
  131. package/runtime/examples/sdk/06-extensions.ts +94 -0
  132. package/runtime/examples/sdk/07-context-files.ts +42 -0
  133. package/runtime/examples/sdk/08-prompt-templates.ts +51 -0
  134. package/runtime/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  135. package/runtime/examples/sdk/10-settings.ts +53 -0
  136. package/runtime/examples/sdk/11-sessions.ts +52 -0
  137. package/runtime/examples/sdk/12-full-control.ts +71 -0
  138. package/runtime/examples/sdk/13-session-runtime.ts +67 -0
  139. package/runtime/examples/sdk/README.md +140 -0
  140. package/runtime/export-html/ansi-to-html.js +249 -0
  141. package/runtime/export-html/index.js +226 -0
  142. package/runtime/export-html/template.css +1066 -0
  143. package/runtime/export-html/template.html +55 -0
  144. package/runtime/export-html/template.js +1864 -0
  145. package/runtime/export-html/tool-renderer.js +108 -0
  146. package/runtime/export-html/vendor/highlight.min.js +1213 -0
  147. package/runtime/export-html/vendor/marked.min.js +78 -0
  148. package/runtime/extensions/pi-switchboard/.github/workflows/ci.yml +51 -0
  149. package/runtime/extensions/pi-switchboard/LICENSE +22 -0
  150. package/runtime/extensions/pi-switchboard/README.md +85 -0
  151. package/runtime/extensions/pi-switchboard/extensions/switchboard/catalog.ts +183 -0
  152. package/runtime/extensions/pi-switchboard/extensions/switchboard/config.ts +97 -0
  153. package/runtime/extensions/pi-switchboard/extensions/switchboard/connections.ts +386 -0
  154. package/runtime/extensions/pi-switchboard/extensions/switchboard/constants.ts +12 -0
  155. package/runtime/extensions/pi-switchboard/extensions/switchboard/device-auth.ts +127 -0
  156. package/runtime/extensions/pi-switchboard/extensions/switchboard/envelope.ts +199 -0
  157. package/runtime/extensions/pi-switchboard/extensions/switchboard/errors.ts +180 -0
  158. package/runtime/extensions/pi-switchboard/extensions/switchboard/index.ts +125 -0
  159. package/runtime/extensions/pi-switchboard/extensions/switchboard/participant.ts +17 -0
  160. package/runtime/extensions/pi-switchboard/extensions/switchboard/sessionStream.ts +131 -0
  161. package/runtime/extensions/pi-switchboard/extensions/switchboard/toolProxy.ts +136 -0
  162. package/runtime/extensions/pi-switchboard/extensions/switchboard/tools.ts +16 -0
  163. package/runtime/extensions/pi-switchboard/extensions/switchboard/types.ts +37 -0
  164. package/runtime/extensions/pi-switchboard/package.json +30 -0
  165. package/runtime/extensions/pi-switchboard/tsconfig.json +13 -0
  166. package/runtime/extensions/switchboard-local/.github/workflows/ci.yml +80 -0
  167. package/runtime/extensions/switchboard-local/.github/workflows/release.yml +46 -0
  168. package/runtime/extensions/switchboard-local/README.md +98 -0
  169. package/runtime/extensions/switchboard-local/extensions/local/engine.ts +28 -0
  170. package/runtime/extensions/switchboard-local/extensions/local/engines/gguf.ts +324 -0
  171. package/runtime/extensions/switchboard-local/extensions/local/engines/llamaBuild.ts +62 -0
  172. package/runtime/extensions/switchboard-local/extensions/local/engines/mlx.ts +245 -0
  173. package/runtime/extensions/switchboard-local/extensions/local/engines/select.ts +38 -0
  174. package/runtime/extensions/switchboard-local/extensions/local/engines/support.ts +151 -0
  175. package/runtime/extensions/switchboard-local/extensions/local/hf.ts +106 -0
  176. package/runtime/extensions/switchboard-local/extensions/local/index.ts +67 -0
  177. package/runtime/extensions/switchboard-local/extensions/local/nativeStream.ts +602 -0
  178. package/runtime/extensions/switchboard-local/extensions/local/paths.ts +44 -0
  179. package/runtime/extensions/switchboard-local/extensions/local/provider.ts +57 -0
  180. package/runtime/extensions/switchboard-local/extensions/local/store.ts +82 -0
  181. package/runtime/extensions/switchboard-local/extensions/local/ui.ts +60 -0
  182. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/apiTypes.js +74 -0
  183. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/client.js +292 -0
  184. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/deviceAuth.js +155 -0
  185. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/errors.js +95 -0
  186. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/index.js +8 -0
  187. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/messages.js +253 -0
  188. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/models.js +19 -0
  189. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/native.js +886 -0
  190. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/wire.js +85 -0
  191. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/package.json +39 -0
  192. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/package.json +29 -0
  193. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/anthropic.ts +127 -0
  194. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/google.ts +111 -0
  195. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/index.ts +8 -0
  196. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/modelRecord.test.ts +25 -0
  197. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/modelRecord.ts +57 -0
  198. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/openaiGeneric.ts +103 -0
  199. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/openaiPro.ts +89 -0
  200. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/profile.ts +120 -0
  201. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/routing.test.ts +82 -0
  202. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/routing.ts +74 -0
  203. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.google.test.ts +137 -0
  204. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.openai.test.ts +241 -0
  205. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.test.ts +174 -0
  206. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.ts +438 -0
  207. package/runtime/extensions/switchboard-local/package.json +34 -0
  208. package/runtime/extensions/switchboard-local/tsconfig.json +13 -0
  209. package/runtime/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  210. package/runtime/node_modules/@mariozechner/clipboard/.yarnrc.yml +1 -0
  211. package/runtime/node_modules/@mariozechner/clipboard/Cargo.toml +45 -0
  212. package/runtime/node_modules/@mariozechner/clipboard/README.md +60 -0
  213. package/runtime/node_modules/@mariozechner/clipboard/build.rs +5 -0
  214. package/runtime/node_modules/@mariozechner/clipboard/clipboard.darwin-x64.node +0 -0
  215. package/runtime/node_modules/@mariozechner/clipboard/exp.ts +12 -0
  216. package/runtime/node_modules/@mariozechner/clipboard/index.js +606 -0
  217. package/runtime/node_modules/@mariozechner/clipboard/package.json +56 -0
  218. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/common.rs +307 -0
  219. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/mod.rs +93 -0
  220. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/ios.rs +313 -0
  221. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/macos.rs +471 -0
  222. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/mod.rs +252 -0
  223. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/wayland.rs +431 -0
  224. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/win.rs +712 -0
  225. package/runtime/node_modules/@mariozechner/clipboard/src/clipboard_rs/platform/x11.rs +916 -0
  226. package/runtime/node_modules/@mariozechner/clipboard/src/lib.rs +194 -0
  227. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/README.md +3 -0
  228. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/clipboard.darwin-x64.node +0 -0
  229. package/runtime/node_modules/@mariozechner/clipboard-darwin-x64/package.json +22 -0
  230. package/runtime/package.json +104 -0
  231. package/runtime/photon_rs_bg.wasm +0 -0
  232. package/runtime/theme/dark.json +87 -0
  233. package/runtime/theme/light.json +86 -0
  234. package/runtime/theme/theme-schema.json +340 -0
  235. package/runtime/valni +4 -0
  236. package/README.md +0 -3
@@ -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 "@valni/cli";
29
+ import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@valni/cli";
30
+ import { Text } from "@valni/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,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 "@valni/cli";
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,72 @@
1
+ /**
2
+ * Commands Extension
3
+ *
4
+ * Demonstrates the pi.getCommands() API by providing a /commands command
5
+ * that lists all available slash commands in the current session.
6
+ *
7
+ * Usage:
8
+ * 1. Copy this file to ~/.pi/agent/extensions/ or your project's .pi/extensions/
9
+ * 2. Use /commands to see available commands
10
+ * 3. Use /commands extensions to filter by source
11
+ */
12
+
13
+ import type { ExtensionAPI, SlashCommandInfo } from "@valni/cli";
14
+
15
+ export default function commandsExtension(pi: ExtensionAPI) {
16
+ pi.registerCommand("commands", {
17
+ description: "List available slash commands",
18
+ getArgumentCompletions: (prefix) => {
19
+ const sources = ["extension", "prompt", "skill"];
20
+ const filtered = sources.filter((s) => s.startsWith(prefix));
21
+ return filtered.length > 0 ? filtered.map((s) => ({ value: s, label: s })) : null;
22
+ },
23
+ handler: async (args, ctx) => {
24
+ const commands = pi.getCommands();
25
+ const sourceFilter = args.trim() as "extension" | "prompt" | "skill" | "";
26
+
27
+ // Filter by source if specified
28
+ const filtered = sourceFilter ? commands.filter((c) => c.source === sourceFilter) : commands;
29
+
30
+ if (filtered.length === 0) {
31
+ ctx.ui.notify(sourceFilter ? `No ${sourceFilter} commands found` : "No commands found", "info");
32
+ return;
33
+ }
34
+
35
+ // Build selection items grouped by source
36
+ const formatCommand = (cmd: SlashCommandInfo): string => {
37
+ const desc = cmd.description ? ` - ${cmd.description}` : "";
38
+ return `/${cmd.name}${desc}`;
39
+ };
40
+
41
+ const items: string[] = [];
42
+ const sources: Array<{ key: "extension" | "prompt" | "skill"; label: string }> = [
43
+ { key: "extension", label: "Extensions" },
44
+ { key: "prompt", label: "Prompts" },
45
+ { key: "skill", label: "Skills" },
46
+ ];
47
+
48
+ for (const { key, label } of sources) {
49
+ const cmds = filtered.filter((c) => c.source === key);
50
+ if (cmds.length > 0) {
51
+ items.push(`--- ${label} ---`);
52
+ items.push(...cmds.map(formatCommand));
53
+ }
54
+ }
55
+
56
+ // Show in a selector (user can scroll and see all commands)
57
+ const selected = await ctx.ui.select("Available Commands", items);
58
+
59
+ // If user selected a command (not a header), offer to show its path
60
+ if (selected && !selected.startsWith("---")) {
61
+ const cmdName = selected.split(" - ")[0].slice(1); // Remove leading /
62
+ const cmd = commands.find((c) => c.name === cmdName);
63
+ if (cmd?.sourceInfo.path) {
64
+ const showPath = await ctx.ui.confirm(cmd.name, `View source path?\n${cmd.sourceInfo.path}`);
65
+ if (showPath) {
66
+ ctx.ui.notify(cmd.sourceInfo.path, "info");
67
+ }
68
+ }
69
+ }
70
+ },
71
+ });
72
+ }
@@ -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 "@valni/cli";
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,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 "@valni/ai";
12
+ import type { ExtensionAPI } from "@valni/cli";
13
+ import { truncateToWidth, visibleWidth } from "@valni/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 "@valni/cli";
9
+ import { VERSION } from "@valni/cli";
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.mode === "tui") {
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
+ }