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

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 (183) hide show
  1. package/LICENSE +52 -0
  2. package/package.json +18 -5
  3. package/runtime/LICENSE +52 -0
  4. package/runtime/assets/clankolas.png +0 -0
  5. package/runtime/examples/extensions/auto-commit-on-exit.ts +49 -0
  6. package/runtime/examples/extensions/bash-spawn-hook.ts +30 -0
  7. package/runtime/examples/extensions/bookmark.ts +50 -0
  8. package/runtime/examples/extensions/border-status-editor.ts +145 -0
  9. package/runtime/examples/extensions/built-in-tool-renderer.ts +249 -0
  10. package/runtime/examples/extensions/claude-rules.ts +86 -0
  11. package/runtime/examples/extensions/commands.ts +72 -0
  12. package/runtime/examples/extensions/confirm-destructive.ts +59 -0
  13. package/runtime/examples/extensions/custom-footer.ts +64 -0
  14. package/runtime/examples/extensions/custom-header.ts +73 -0
  15. package/runtime/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  16. package/runtime/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  17. package/runtime/examples/extensions/custom-provider-anthropic/package.json +19 -0
  18. package/runtime/examples/extensions/dirty-repo-guard.ts +56 -0
  19. package/runtime/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  20. package/runtime/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  21. package/runtime/examples/extensions/doom-overlay/doom/build.sh +152 -0
  22. package/runtime/examples/extensions/doom-overlay/doom/doomgeneric_valni.c +72 -0
  23. package/runtime/examples/extensions/doom-overlay/doom-component.ts +132 -0
  24. package/runtime/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  25. package/runtime/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  26. package/runtime/examples/extensions/doom-overlay/index.ts +74 -0
  27. package/runtime/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  28. package/runtime/examples/extensions/dynamic-resources/dynamic.json +78 -0
  29. package/runtime/examples/extensions/dynamic-resources/index.ts +13 -0
  30. package/runtime/examples/extensions/dynamic-tools.ts +74 -0
  31. package/runtime/examples/extensions/entry-renderer.ts +41 -0
  32. package/runtime/examples/extensions/event-bus.ts +43 -0
  33. package/runtime/examples/extensions/file-trigger.ts +41 -0
  34. package/runtime/examples/extensions/git-checkpoint.ts +53 -0
  35. package/runtime/examples/extensions/git-merge-and-resolve.ts +115 -0
  36. package/runtime/examples/extensions/github-issue-autocomplete.ts +185 -0
  37. package/runtime/examples/extensions/hello.ts +26 -0
  38. package/runtime/examples/extensions/hidden-thinking-label.ts +53 -0
  39. package/runtime/examples/extensions/inline-bash.ts +94 -0
  40. package/runtime/examples/extensions/input-transform-streaming.ts +39 -0
  41. package/runtime/examples/extensions/input-transform.ts +43 -0
  42. package/runtime/examples/extensions/interactive-shell.ts +196 -0
  43. package/runtime/examples/extensions/mac-system-theme.ts +47 -0
  44. package/runtime/examples/extensions/message-renderer.ts +59 -0
  45. package/runtime/examples/extensions/minimal-mode.ts +426 -0
  46. package/runtime/examples/extensions/modal-editor.ts +85 -0
  47. package/runtime/examples/extensions/model-status.ts +31 -0
  48. package/runtime/examples/extensions/notify.ts +55 -0
  49. package/runtime/examples/extensions/overlay-qa-tests.ts +1450 -0
  50. package/runtime/examples/extensions/overlay-test.ts +153 -0
  51. package/runtime/examples/extensions/permission-gate.ts +34 -0
  52. package/runtime/examples/extensions/pirate.ts +47 -0
  53. package/runtime/examples/extensions/plan-mode/index.ts +390 -0
  54. package/runtime/examples/extensions/plan-mode/utils.ts +168 -0
  55. package/runtime/examples/extensions/preset.ts +436 -0
  56. package/runtime/examples/extensions/project-trust.ts +64 -0
  57. package/runtime/examples/extensions/prompt-customizer.ts +97 -0
  58. package/runtime/examples/extensions/protected-paths.ts +30 -0
  59. package/runtime/examples/extensions/provider-payload.ts +18 -0
  60. package/runtime/examples/extensions/question.ts +278 -0
  61. package/runtime/examples/extensions/questionnaire.ts +440 -0
  62. package/runtime/examples/extensions/rainbow-editor.ts +88 -0
  63. package/runtime/examples/extensions/reload-runtime.ts +37 -0
  64. package/runtime/examples/extensions/rpc-demo.ts +118 -0
  65. package/runtime/examples/extensions/sandbox/index.ts +321 -0
  66. package/runtime/examples/extensions/sandbox/package-lock.json +92 -0
  67. package/runtime/examples/extensions/sandbox/package.json +19 -0
  68. package/runtime/examples/extensions/send-user-message.ts +97 -0
  69. package/runtime/examples/extensions/session-name.ts +27 -0
  70. package/runtime/examples/extensions/shutdown-command.ts +63 -0
  71. package/runtime/examples/extensions/snake.ts +343 -0
  72. package/runtime/examples/extensions/space-invaders.ts +560 -0
  73. package/runtime/examples/extensions/ssh.ts +220 -0
  74. package/runtime/examples/extensions/status-line.ts +32 -0
  75. package/runtime/examples/extensions/structured-output.ts +65 -0
  76. package/runtime/examples/extensions/subagent/agents.ts +126 -0
  77. package/runtime/examples/extensions/subagent/index.ts +1009 -0
  78. package/runtime/examples/extensions/system-prompt-header.ts +17 -0
  79. package/runtime/examples/extensions/tic-tac-toe.ts +1008 -0
  80. package/runtime/examples/extensions/timed-confirm.ts +70 -0
  81. package/runtime/examples/extensions/titlebar-spinner.ts +58 -0
  82. package/runtime/examples/extensions/todo.ts +297 -0
  83. package/runtime/examples/extensions/tool-override.ts +144 -0
  84. package/runtime/examples/extensions/tools.ts +146 -0
  85. package/runtime/examples/extensions/trigger-compact.ts +50 -0
  86. package/runtime/examples/extensions/truncated-tool.ts +195 -0
  87. package/runtime/examples/extensions/widget-placement.ts +9 -0
  88. package/runtime/examples/extensions/with-deps/index.ts +32 -0
  89. package/runtime/examples/extensions/with-deps/package-lock.json +31 -0
  90. package/runtime/examples/extensions/with-deps/package.json +22 -0
  91. package/runtime/examples/extensions/working-indicator.ts +123 -0
  92. package/runtime/examples/extensions/working-message-test.ts +25 -0
  93. package/runtime/examples/rpc-extension-ui.ts +632 -0
  94. package/runtime/examples/sdk/01-minimal.ts +26 -0
  95. package/runtime/examples/sdk/02-custom-model.ts +43 -0
  96. package/runtime/examples/sdk/03-custom-prompt.ts +70 -0
  97. package/runtime/examples/sdk/04-skills.ts +55 -0
  98. package/runtime/examples/sdk/05-tools.ts +48 -0
  99. package/runtime/examples/sdk/06-extensions.ts +94 -0
  100. package/runtime/examples/sdk/07-context-files.ts +42 -0
  101. package/runtime/examples/sdk/08-prompt-templates.ts +51 -0
  102. package/runtime/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  103. package/runtime/examples/sdk/10-settings.ts +53 -0
  104. package/runtime/examples/sdk/11-sessions.ts +52 -0
  105. package/runtime/examples/sdk/12-full-control.ts +71 -0
  106. package/runtime/examples/sdk/13-session-runtime.ts +67 -0
  107. package/runtime/export-html/ansi-to-html.js +249 -0
  108. package/runtime/export-html/index.js +226 -0
  109. package/runtime/export-html/template.css +1066 -0
  110. package/runtime/export-html/template.html +55 -0
  111. package/runtime/export-html/template.js +1864 -0
  112. package/runtime/export-html/tool-renderer.js +108 -0
  113. package/runtime/export-html/vendor/highlight.min.js +1213 -0
  114. package/runtime/export-html/vendor/marked.min.js +78 -0
  115. package/runtime/extensions/pi-switchboard/.github/workflows/ci.yml +51 -0
  116. package/runtime/extensions/pi-switchboard/LICENSE +22 -0
  117. package/runtime/extensions/pi-switchboard/README.md +85 -0
  118. package/runtime/extensions/pi-switchboard/extensions/switchboard/catalog.ts +183 -0
  119. package/runtime/extensions/pi-switchboard/extensions/switchboard/config.ts +97 -0
  120. package/runtime/extensions/pi-switchboard/extensions/switchboard/connections.ts +386 -0
  121. package/runtime/extensions/pi-switchboard/extensions/switchboard/constants.ts +12 -0
  122. package/runtime/extensions/pi-switchboard/extensions/switchboard/device-auth.ts +127 -0
  123. package/runtime/extensions/pi-switchboard/extensions/switchboard/envelope.ts +199 -0
  124. package/runtime/extensions/pi-switchboard/extensions/switchboard/errors.ts +180 -0
  125. package/runtime/extensions/pi-switchboard/extensions/switchboard/index.ts +125 -0
  126. package/runtime/extensions/pi-switchboard/extensions/switchboard/participant.ts +17 -0
  127. package/runtime/extensions/pi-switchboard/extensions/switchboard/sessionStream.ts +131 -0
  128. package/runtime/extensions/pi-switchboard/extensions/switchboard/toolProxy.ts +136 -0
  129. package/runtime/extensions/pi-switchboard/extensions/switchboard/tools.ts +16 -0
  130. package/runtime/extensions/pi-switchboard/extensions/switchboard/types.ts +37 -0
  131. package/runtime/extensions/pi-switchboard/package.json +30 -0
  132. package/runtime/extensions/pi-switchboard/tsconfig.json +13 -0
  133. package/runtime/extensions/switchboard-local/.github/workflows/ci.yml +80 -0
  134. package/runtime/extensions/switchboard-local/.github/workflows/release.yml +46 -0
  135. package/runtime/extensions/switchboard-local/README.md +98 -0
  136. package/runtime/extensions/switchboard-local/extensions/local/engine.ts +28 -0
  137. package/runtime/extensions/switchboard-local/extensions/local/engines/gguf.ts +324 -0
  138. package/runtime/extensions/switchboard-local/extensions/local/engines/llamaBuild.ts +62 -0
  139. package/runtime/extensions/switchboard-local/extensions/local/engines/mlx.ts +245 -0
  140. package/runtime/extensions/switchboard-local/extensions/local/engines/select.ts +38 -0
  141. package/runtime/extensions/switchboard-local/extensions/local/engines/support.ts +151 -0
  142. package/runtime/extensions/switchboard-local/extensions/local/hf.ts +106 -0
  143. package/runtime/extensions/switchboard-local/extensions/local/index.ts +67 -0
  144. package/runtime/extensions/switchboard-local/extensions/local/nativeStream.ts +602 -0
  145. package/runtime/extensions/switchboard-local/extensions/local/paths.ts +44 -0
  146. package/runtime/extensions/switchboard-local/extensions/local/provider.ts +57 -0
  147. package/runtime/extensions/switchboard-local/extensions/local/store.ts +82 -0
  148. package/runtime/extensions/switchboard-local/extensions/local/ui.ts +60 -0
  149. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/apiTypes.js +74 -0
  150. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/client.js +292 -0
  151. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/deviceAuth.js +155 -0
  152. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/errors.js +95 -0
  153. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/index.js +8 -0
  154. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/messages.js +253 -0
  155. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/models.js +19 -0
  156. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/native.js +886 -0
  157. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/dist/wire.js +85 -0
  158. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard/package.json +39 -0
  159. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/package.json +29 -0
  160. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/anthropic.ts +127 -0
  161. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/google.ts +111 -0
  162. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/index.ts +8 -0
  163. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/modelRecord.test.ts +25 -0
  164. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/modelRecord.ts +57 -0
  165. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/openaiGeneric.ts +103 -0
  166. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/openaiPro.ts +89 -0
  167. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/profile.ts +120 -0
  168. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/routing.test.ts +82 -0
  169. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/routing.ts +74 -0
  170. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.google.test.ts +137 -0
  171. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.openai.test.ts +241 -0
  172. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.test.ts +174 -0
  173. package/runtime/extensions/switchboard-local/node_modules/@valni/switchboard-native/src/validateConfig.ts +438 -0
  174. package/runtime/extensions/switchboard-local/package.json +34 -0
  175. package/runtime/extensions/switchboard-local/tsconfig.json +13 -0
  176. package/runtime/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  177. package/runtime/package.json +98 -0
  178. package/runtime/photon_rs_bg.wasm +0 -0
  179. package/runtime/theme/dark.json +86 -0
  180. package/runtime/theme/light.json +85 -0
  181. package/runtime/theme/theme-schema.json +340 -0
  182. package/runtime/valni +4 -0
  183. package/README.md +0 -3
@@ -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 ~/.valni/agent/extensions/ or your project's .valni/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(valni: ExtensionAPI) {
50
+ let ruleFiles: string[] = [];
51
+ let rulesDir: string = "";
52
+
53
+ // Scan for rules on session start
54
+ valni.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
+ valni.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 valni.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 ~/.valni/agent/extensions/ or your project's .valni/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(valni: ExtensionAPI) {
16
+ valni.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 = valni.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 (valni: ExtensionAPI) {
11
+ valni.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
+ valni.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 (valni: ExtensionAPI) {
16
+ let enabled = false;
17
+
18
+ valni.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 valni mascot.
6
+ */
7
+
8
+ import type { ExtensionAPI, Theme } from "@valni/cli";
9
+ import { VERSION } from "@valni/cli";
10
+
11
+ // --- PI MASCOT ---
12
+ // Based on the valni 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 (valni: ExtensionAPI) {
48
+ // Set custom header immediately on load (if UI is available)
49
+ valni.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
+ valni.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
+ }