@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,173 @@
1
+ /**
2
+ * DOOM Engine - WebAssembly wrapper for doomgeneric
3
+ */
4
+
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { createRequire } from "node:module";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ export interface DoomModule {
11
+ _doomgeneric_Create: (argc: number, argv: number) => void;
12
+ _doomgeneric_Tick: () => void;
13
+ _DG_GetFrameBuffer: () => number;
14
+ _DG_GetScreenWidth: () => number;
15
+ _DG_GetScreenHeight: () => number;
16
+ _DG_PushKeyEvent: (pressed: number, key: number) => void;
17
+ _malloc: (size: number) => number;
18
+ _free: (ptr: number) => void;
19
+ HEAPU8: Uint8Array;
20
+ HEAPU32: Uint32Array;
21
+ FS_createDataFile: (parent: string, name: string, data: number[], canRead: boolean, canWrite: boolean) => void;
22
+ FS_createPath: (parent: string, path: string, canRead: boolean, canWrite: boolean) => string;
23
+ setValue: (ptr: number, value: number, type: string) => void;
24
+ getValue: (ptr: number, type: string) => number;
25
+ }
26
+
27
+ export class DoomEngine {
28
+ private module: DoomModule | null = null;
29
+ private frameBufferPtr: number = 0;
30
+ private initialized = false;
31
+ private wadPath: string;
32
+ private _width = 640;
33
+ private _height = 400;
34
+
35
+ constructor(wadPath: string) {
36
+ this.wadPath = wadPath;
37
+ }
38
+
39
+ get width(): number {
40
+ return this._width;
41
+ }
42
+
43
+ get height(): number {
44
+ return this._height;
45
+ }
46
+
47
+ async init(): Promise<void> {
48
+ // Locate WASM build
49
+ const __dirname = dirname(fileURLToPath(import.meta.url));
50
+ const buildDir = join(__dirname, "doom", "build");
51
+ const doomJsPath = join(buildDir, "doom.js");
52
+
53
+ if (!existsSync(doomJsPath)) {
54
+ throw new Error(`WASM not found at ${doomJsPath}. Run ./doom/build.sh first`);
55
+ }
56
+
57
+ // Read WAD file
58
+ const wadData = readFileSync(this.wadPath);
59
+ const wadArray = Array.from(new Uint8Array(wadData));
60
+
61
+ // Load WASM module - eval to bypass jiti completely
62
+ const doomJsCode = readFileSync(doomJsPath, "utf-8");
63
+ const moduleExports: { exports: unknown } = { exports: {} };
64
+ const nativeRequire = createRequire(doomJsPath);
65
+ const moduleFunc = new Function("module", "exports", "__dirname", "__filename", "require", doomJsCode);
66
+ moduleFunc(moduleExports, moduleExports.exports, buildDir, doomJsPath, nativeRequire);
67
+ const createDoomModule = moduleExports.exports as (config: unknown) => Promise<DoomModule>;
68
+
69
+ const moduleConfig = {
70
+ locateFile: (path: string) => {
71
+ if (path.endsWith(".wasm")) {
72
+ return join(buildDir, path);
73
+ }
74
+ return path;
75
+ },
76
+ print: () => {},
77
+ printErr: () => {},
78
+ preRun: [
79
+ (module: DoomModule) => {
80
+ // Create /doom directory and add WAD
81
+ module.FS_createPath("/", "doom", true, true);
82
+ module.FS_createDataFile("/doom", "doom1.wad", wadArray, true, false);
83
+ },
84
+ ],
85
+ };
86
+
87
+ this.module = await createDoomModule(moduleConfig);
88
+ if (!this.module) {
89
+ throw new Error("Failed to initialize DOOM module");
90
+ }
91
+
92
+ // Initialize DOOM
93
+ this.initDoom();
94
+
95
+ // Get framebuffer info
96
+ this.frameBufferPtr = this.module._DG_GetFrameBuffer();
97
+ this._width = this.module._DG_GetScreenWidth();
98
+ this._height = this.module._DG_GetScreenHeight();
99
+ this.initialized = true;
100
+ }
101
+
102
+ private initDoom(): void {
103
+ if (!this.module) return;
104
+
105
+ const args = ["doom", "-iwad", "/doom/doom1.wad"];
106
+ const argPtrs: number[] = [];
107
+
108
+ for (const arg of args) {
109
+ const ptr = this.module._malloc(arg.length + 1);
110
+ for (let i = 0; i < arg.length; i++) {
111
+ this.module.setValue(ptr + i, arg.charCodeAt(i), "i8");
112
+ }
113
+ this.module.setValue(ptr + arg.length, 0, "i8");
114
+ argPtrs.push(ptr);
115
+ }
116
+
117
+ const argvPtr = this.module._malloc(argPtrs.length * 4);
118
+ for (let i = 0; i < argPtrs.length; i++) {
119
+ this.module.setValue(argvPtr + i * 4, argPtrs[i]!, "i32");
120
+ }
121
+
122
+ this.module._doomgeneric_Create(args.length, argvPtr);
123
+
124
+ for (const ptr of argPtrs) {
125
+ this.module._free(ptr);
126
+ }
127
+ this.module._free(argvPtr);
128
+ }
129
+
130
+ /**
131
+ * Run one game tick
132
+ */
133
+ tick(): void {
134
+ if (!this.module || !this.initialized) return;
135
+ this.module._doomgeneric_Tick();
136
+ }
137
+
138
+ /**
139
+ * Get current frame as RGBA pixel data
140
+ * DOOM outputs ARGB, we convert to RGBA
141
+ */
142
+ getFrameRGBA(): Uint8Array {
143
+ if (!this.module || !this.initialized) {
144
+ return new Uint8Array(this._width * this._height * 4);
145
+ }
146
+
147
+ const pixels = this._width * this._height;
148
+ const buffer = new Uint8Array(pixels * 4);
149
+
150
+ for (let i = 0; i < pixels; i++) {
151
+ const argb = this.module.getValue(this.frameBufferPtr + i * 4, "i32");
152
+ const offset = i * 4;
153
+ buffer[offset + 0] = (argb >> 16) & 0xff; // R
154
+ buffer[offset + 1] = (argb >> 8) & 0xff; // G
155
+ buffer[offset + 2] = argb & 0xff; // B
156
+ buffer[offset + 3] = 255; // A
157
+ }
158
+
159
+ return buffer;
160
+ }
161
+
162
+ /**
163
+ * Push a key event
164
+ */
165
+ pushKey(pressed: boolean, key: number): void {
166
+ if (!this.module || !this.initialized) return;
167
+ this.module._DG_PushKeyEvent(pressed ? 1 : 0, key);
168
+ }
169
+
170
+ isInitialized(): boolean {
171
+ return this.initialized;
172
+ }
173
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * DOOM key codes (from doomkeys.h)
3
+ */
4
+ export const DoomKeys = {
5
+ KEY_RIGHTARROW: 0xae,
6
+ KEY_LEFTARROW: 0xac,
7
+ KEY_UPARROW: 0xad,
8
+ KEY_DOWNARROW: 0xaf,
9
+ KEY_STRAFE_L: 0xa0,
10
+ KEY_STRAFE_R: 0xa1,
11
+ KEY_USE: 0xa2,
12
+ KEY_FIRE: 0xa3,
13
+ KEY_ESCAPE: 27,
14
+ KEY_ENTER: 13,
15
+ KEY_TAB: 9,
16
+ KEY_F1: 0x80 + 0x3b,
17
+ KEY_F2: 0x80 + 0x3c,
18
+ KEY_F3: 0x80 + 0x3d,
19
+ KEY_F4: 0x80 + 0x3e,
20
+ KEY_F5: 0x80 + 0x3f,
21
+ KEY_F6: 0x80 + 0x40,
22
+ KEY_F7: 0x80 + 0x41,
23
+ KEY_F8: 0x80 + 0x42,
24
+ KEY_F9: 0x80 + 0x43,
25
+ KEY_F10: 0x80 + 0x44,
26
+ KEY_F11: 0x80 + 0x57,
27
+ KEY_F12: 0x80 + 0x58,
28
+ KEY_BACKSPACE: 127,
29
+ KEY_PAUSE: 0xff,
30
+ KEY_EQUALS: 0x3d,
31
+ KEY_MINUS: 0x2d,
32
+ KEY_RSHIFT: 0x80 + 0x36,
33
+ KEY_RCTRL: 0x80 + 0x1d,
34
+ KEY_RALT: 0x80 + 0x38,
35
+ } as const;
36
+
37
+ import { Key, matchesKey, parseKey } from "@valni/tui";
38
+
39
+ /**
40
+ * Map terminal key input to DOOM key codes
41
+ * Supports both raw terminal input and Kitty protocol sequences
42
+ */
43
+ export function mapKeyToDoom(data: string): number[] {
44
+ // Arrow keys
45
+ if (matchesKey(data, Key.up)) return [DoomKeys.KEY_UPARROW];
46
+ if (matchesKey(data, Key.down)) return [DoomKeys.KEY_DOWNARROW];
47
+ if (matchesKey(data, Key.right)) return [DoomKeys.KEY_RIGHTARROW];
48
+ if (matchesKey(data, Key.left)) return [DoomKeys.KEY_LEFTARROW];
49
+
50
+ // WASD - check both raw char and Kitty sequences
51
+ if (data === "w" || matchesKey(data, "w")) return [DoomKeys.KEY_UPARROW];
52
+ if (data === "W" || matchesKey(data, Key.shift("w"))) return [DoomKeys.KEY_UPARROW, DoomKeys.KEY_RSHIFT];
53
+ if (data === "s" || matchesKey(data, "s")) return [DoomKeys.KEY_DOWNARROW];
54
+ if (data === "S" || matchesKey(data, Key.shift("s"))) return [DoomKeys.KEY_DOWNARROW, DoomKeys.KEY_RSHIFT];
55
+ if (data === "a" || matchesKey(data, "a")) return [DoomKeys.KEY_STRAFE_L];
56
+ if (data === "A" || matchesKey(data, Key.shift("a"))) return [DoomKeys.KEY_STRAFE_L, DoomKeys.KEY_RSHIFT];
57
+ if (data === "d" || matchesKey(data, "d")) return [DoomKeys.KEY_STRAFE_R];
58
+ if (data === "D" || matchesKey(data, Key.shift("d"))) return [DoomKeys.KEY_STRAFE_R, DoomKeys.KEY_RSHIFT];
59
+
60
+ // Fire - F key
61
+ if (data === "f" || data === "F" || matchesKey(data, "f") || matchesKey(data, Key.shift("f"))) {
62
+ return [DoomKeys.KEY_FIRE];
63
+ }
64
+
65
+ // Use/Open
66
+ if (data === " " || matchesKey(data, Key.space)) return [DoomKeys.KEY_USE];
67
+
68
+ // Menu/UI keys
69
+ if (matchesKey(data, Key.enter)) return [DoomKeys.KEY_ENTER];
70
+ if (matchesKey(data, Key.escape)) return [DoomKeys.KEY_ESCAPE];
71
+ if (matchesKey(data, Key.tab)) return [DoomKeys.KEY_TAB];
72
+ if (matchesKey(data, Key.backspace)) return [DoomKeys.KEY_BACKSPACE];
73
+
74
+ // Ctrl keys (except Ctrl+C) = fire (legacy support)
75
+ const parsed = parseKey(data);
76
+ if (parsed?.startsWith("ctrl+") && parsed !== "ctrl+c") {
77
+ return [DoomKeys.KEY_FIRE];
78
+ }
79
+ if (data.length === 1 && data.charCodeAt(0) < 32 && data !== "\x03") {
80
+ return [DoomKeys.KEY_FIRE];
81
+ }
82
+
83
+ // Weapon selection (0-9)
84
+ if (data >= "0" && data <= "9") return [data.charCodeAt(0)];
85
+
86
+ // Plus/minus for screen size
87
+ if (data === "+" || data === "=") return [DoomKeys.KEY_EQUALS];
88
+ if (data === "-") return [DoomKeys.KEY_MINUS];
89
+
90
+ // Y/N for prompts
91
+ if (data === "y" || data === "Y" || matchesKey(data, "y") || matchesKey(data, Key.shift("y"))) {
92
+ return ["y".charCodeAt(0)];
93
+ }
94
+ if (data === "n" || data === "N" || matchesKey(data, "n") || matchesKey(data, Key.shift("n"))) {
95
+ return ["n".charCodeAt(0)];
96
+ }
97
+
98
+ // Other printable characters (for cheats)
99
+ if (data.length === 1 && data.charCodeAt(0) >= 32) {
100
+ return [data.toLowerCase().charCodeAt(0)];
101
+ }
102
+
103
+ return [];
104
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * DOOM Overlay Demo - Play DOOM as an overlay
3
+ *
4
+ * Usage: valni --extension ./examples/extensions/doom-overlay
5
+ *
6
+ * Commands:
7
+ * /doom-overlay - Play DOOM in an overlay (Q to pause/exit)
8
+ *
9
+ * This demonstrates that overlays can handle real-time game rendering at 35 FPS.
10
+ */
11
+
12
+ import type { ExtensionAPI } from "@valni/cli";
13
+ import { DoomOverlayComponent } from "./doom-component.ts";
14
+ import { DoomEngine } from "./doom-engine.ts";
15
+ import { ensureWadFile } from "./wad-finder.ts";
16
+
17
+ // Persistent engine instance - survives between invocations
18
+ let activeEngine: DoomEngine | null = null;
19
+ let activeWadPath: string | null = null;
20
+
21
+ export default function (valni: ExtensionAPI) {
22
+ valni.registerCommand("doom-overlay", {
23
+ description: "Play DOOM as an overlay. Q to pause and exit.",
24
+
25
+ handler: async (args, ctx) => {
26
+ if (ctx.mode !== "tui") {
27
+ ctx.ui.notify("DOOM requires interactive mode", "error");
28
+ return;
29
+ }
30
+
31
+ // Auto-download WAD if not present
32
+ ctx.ui.notify("Loading DOOM...", "info");
33
+ const wad = args?.trim() ? args.trim() : await ensureWadFile();
34
+
35
+ if (!wad) {
36
+ ctx.ui.notify("Failed to download DOOM WAD file. Check your internet connection.", "error");
37
+ return;
38
+ }
39
+
40
+ try {
41
+ // Reuse existing engine if same WAD, otherwise create new
42
+ let isResume = false;
43
+ if (activeEngine && activeWadPath === wad) {
44
+ ctx.ui.notify("Resuming DOOM...", "info");
45
+ isResume = true;
46
+ } else {
47
+ ctx.ui.notify(`Loading DOOM from ${wad}...`, "info");
48
+ activeEngine = new DoomEngine(wad);
49
+ await activeEngine.init();
50
+ activeWadPath = wad;
51
+ }
52
+
53
+ await ctx.ui.custom(
54
+ (tui, _theme, _keybindings, done) => {
55
+ return new DoomOverlayComponent(tui, activeEngine!, () => done(undefined), isResume);
56
+ },
57
+ {
58
+ overlay: true,
59
+ overlayOptions: {
60
+ width: "75%",
61
+ maxHeight: "95%",
62
+ anchor: "center",
63
+ margin: { top: 1 },
64
+ },
65
+ },
66
+ );
67
+ } catch (error) {
68
+ ctx.ui.notify(`Failed to load DOOM: ${error}`, "error");
69
+ activeEngine = null;
70
+ activeWadPath = null;
71
+ }
72
+ },
73
+ });
74
+ }
@@ -0,0 +1,51 @@
1
+ import { existsSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ // Get the bundled WAD path (relative to this module)
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const BUNDLED_WAD = join(__dirname, "doom1.wad");
8
+ const WAD_URL = "https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad";
9
+
10
+ const DEFAULT_WAD_PATHS = ["./doom1.wad", "./DOOM1.WAD", "~/doom1.wad", "~/.doom/doom1.wad"];
11
+
12
+ export function findWadFile(customPath?: string): string | null {
13
+ if (customPath) {
14
+ const resolved = resolve(customPath.replace(/^~/, process.env.HOME || ""));
15
+ if (existsSync(resolved)) return resolved;
16
+ return null;
17
+ }
18
+
19
+ // Check bundled WAD first
20
+ if (existsSync(BUNDLED_WAD)) {
21
+ return BUNDLED_WAD;
22
+ }
23
+
24
+ // Fall back to default paths
25
+ for (const p of DEFAULT_WAD_PATHS) {
26
+ const resolved = resolve(p.replace(/^~/, process.env.HOME || ""));
27
+ if (existsSync(resolved)) return resolved;
28
+ }
29
+
30
+ return null;
31
+ }
32
+
33
+ /** Download the shareware WAD if not present. Returns path or null on failure. */
34
+ export async function ensureWadFile(): Promise<string | null> {
35
+ // Check if already exists
36
+ const existing = findWadFile();
37
+ if (existing) return existing;
38
+
39
+ // Download to bundled location
40
+ try {
41
+ const response = await fetch(WAD_URL);
42
+ if (!response.ok) {
43
+ throw new Error(`HTTP ${response.status}`);
44
+ }
45
+ const buffer = await response.arrayBuffer();
46
+ writeFileSync(BUNDLED_WAD, Buffer.from(buffer));
47
+ return BUNDLED_WAD;
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "dynamic-resources",
3
+ "vars": {
4
+ "cyan": "#00d7ff",
5
+ "blue": "#5f87ff",
6
+ "green": "#b5bd68",
7
+ "red": "#cc6666",
8
+ "yellow": "#ffff00",
9
+ "gray": "#808080",
10
+ "dimGray": "#666666",
11
+ "darkGray": "#505050",
12
+ "accent": "#8abeb7",
13
+ "selectedBg": "#3a3a4a",
14
+ "userMsgBg": "#343541",
15
+ "toolPendingBg": "#282832",
16
+ "toolSuccessBg": "#283228",
17
+ "toolErrorBg": "#3c2828",
18
+ "customMsgBg": "#2d2838"
19
+ },
20
+ "colors": {
21
+ "accent": "accent",
22
+ "border": "blue",
23
+ "borderAccent": "cyan",
24
+ "borderMuted": "darkGray",
25
+ "success": "green",
26
+ "error": "red",
27
+ "warning": "yellow",
28
+ "muted": "gray",
29
+ "dim": "dimGray",
30
+ "text": "",
31
+ "thinkingText": "gray",
32
+ "selectedBg": "selectedBg",
33
+ "userMessageBg": "userMsgBg",
34
+ "userMessageText": "",
35
+ "customMessageBg": "customMsgBg",
36
+ "customMessageText": "",
37
+ "customMessageLabel": "#9575cd",
38
+ "toolPendingBg": "toolPendingBg",
39
+ "toolSuccessBg": "toolSuccessBg",
40
+ "toolErrorBg": "toolErrorBg",
41
+ "toolTitle": "",
42
+ "toolOutput": "gray",
43
+ "mdHeading": "#f0c674",
44
+ "mdLink": "#81a2be",
45
+ "mdLinkUrl": "dimGray",
46
+ "mdCode": "accent",
47
+ "mdCodeBlock": "green",
48
+ "mdCodeBlockBorder": "gray",
49
+ "mdQuote": "gray",
50
+ "mdQuoteBorder": "gray",
51
+ "mdHr": "gray",
52
+ "mdListBullet": "accent",
53
+ "toolDiffAdded": "green",
54
+ "toolDiffRemoved": "red",
55
+ "toolDiffContext": "gray",
56
+ "syntaxComment": "#6A9955",
57
+ "syntaxKeyword": "#569CD6",
58
+ "syntaxFunction": "#DCDCAA",
59
+ "syntaxVariable": "#9CDCFE",
60
+ "syntaxString": "#CE9178",
61
+ "syntaxNumber": "#B5CEA8",
62
+ "syntaxType": "#4EC9B0",
63
+ "syntaxOperator": "#D4D4D4",
64
+ "syntaxPunctuation": "#D4D4D4",
65
+ "thinkingOff": "darkGray",
66
+ "thinkingMinimal": "#6e6e6e",
67
+ "thinkingLow": "#5f87af",
68
+ "thinkingMedium": "#81a2be",
69
+ "thinkingHigh": "#b294bb",
70
+ "thinkingXhigh": "#d183e8",
71
+ "bashMode": "green"
72
+ },
73
+ "export": {
74
+ "pageBg": "#18181e",
75
+ "cardBg": "#1e1e24",
76
+ "infoBg": "#3c3728"
77
+ }
78
+ }
@@ -0,0 +1,13 @@
1
+ import { dirname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import type { ExtensionAPI } from "@valni/cli";
4
+
5
+ const baseDir = dirname(fileURLToPath(import.meta.url));
6
+
7
+ export default function (valni: ExtensionAPI) {
8
+ valni.on("resources_discover", () => {
9
+ return {
10
+ themePaths: [join(baseDir, "dynamic.json")],
11
+ };
12
+ });
13
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Dynamic Tools Extension
3
+ *
4
+ * Demonstrates registering tools after session initialization.
5
+ *
6
+ * - Registers one tool during session_start
7
+ * - Registers additional tools at runtime via /add-echo-tool <name>
8
+ */
9
+
10
+ import type { ExtensionAPI } from "@valni/cli";
11
+ import { Type } from "typebox";
12
+
13
+ const ECHO_PARAMS = Type.Object({
14
+ message: Type.String({ description: "Message to echo" }),
15
+ });
16
+
17
+ function normalizeToolName(input: string): string | undefined {
18
+ const trimmed = input.trim().toLowerCase();
19
+ if (!trimmed) return undefined;
20
+ if (!/^[a-z0-9_]+$/.test(trimmed)) return undefined;
21
+ return trimmed;
22
+ }
23
+
24
+ export default function dynamicToolsExtension(valni: ExtensionAPI) {
25
+ const registeredToolNames = new Set<string>();
26
+
27
+ const registerEchoTool = (name: string, label: string, prefix: string): boolean => {
28
+ if (registeredToolNames.has(name)) {
29
+ return false;
30
+ }
31
+
32
+ registeredToolNames.add(name);
33
+ valni.registerTool({
34
+ name,
35
+ label,
36
+ description: `Echo a message with prefix: ${prefix}`,
37
+ promptSnippet: `Echo back user-provided text with ${prefix.trim()} prefix`,
38
+ promptGuidelines: ["Use echo_session when the user asks for exact echo output."],
39
+ parameters: ECHO_PARAMS,
40
+ async execute(_toolCallId, params) {
41
+ return {
42
+ content: [{ type: "text", text: `${prefix}${params.message}` }],
43
+ details: { tool: name, prefix },
44
+ };
45
+ },
46
+ });
47
+
48
+ return true;
49
+ };
50
+
51
+ valni.on("session_start", (_event, ctx) => {
52
+ registerEchoTool("echo_session", "Echo Session", "[session] ");
53
+ ctx.ui.notify("Registered dynamic tool: echo_session", "info");
54
+ });
55
+
56
+ valni.registerCommand("add-echo-tool", {
57
+ description: "Register a new echo tool dynamically: /add-echo-tool <tool_name>",
58
+ handler: async (args, ctx) => {
59
+ const toolName = normalizeToolName(args);
60
+ if (!toolName) {
61
+ ctx.ui.notify("Usage: /add-echo-tool <tool_name> (lowercase, numbers, underscores)", "warning");
62
+ return;
63
+ }
64
+
65
+ const created = registerEchoTool(toolName, `Echo ${toolName}`, `[${toolName}] `);
66
+ if (!created) {
67
+ ctx.ui.notify(`Tool already registered: ${toolName}`, "warning");
68
+ return;
69
+ }
70
+
71
+ ctx.ui.notify(`Registered dynamic tool: ${toolName}`, "info");
72
+ },
73
+ });
74
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Custom entry rendering example.
3
+ *
4
+ * Shows how to render durable extension data inside the chat without sending it
5
+ * to the LLM. Custom entries are stored in the session via valni.appendEntry() and
6
+ * rendered in interactive mode via valni.registerEntryRenderer().
7
+ *
8
+ * Usage: /status-card [message]
9
+ */
10
+
11
+ import type { ExtensionAPI } from "@valni/cli";
12
+ import { Box, Text } from "@valni/tui";
13
+
14
+ interface StatusCardData {
15
+ message: string;
16
+ timestamp: number;
17
+ }
18
+
19
+ export default function (valni: ExtensionAPI) {
20
+ valni.registerEntryRenderer<StatusCardData>("status-card", (entry, { expanded }, theme) => {
21
+ const data = entry.data ?? { message: "No data", timestamp: Date.now() };
22
+ const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text));
23
+ box.addChild(new Text(`${theme.fg("accent", "[status]")} ${data.message}`, 0, 0));
24
+
25
+ if (expanded) {
26
+ box.addChild(new Text(theme.fg("dim", new Date(data.timestamp).toLocaleString()), 0, 0));
27
+ }
28
+
29
+ return box;
30
+ });
31
+
32
+ valni.registerCommand("status-card", {
33
+ description: "Render a durable status card that is not sent to the LLM",
34
+ handler: async (args) => {
35
+ valni.appendEntry<StatusCardData>("status-card", {
36
+ message: args.trim() || "Status card",
37
+ timestamp: Date.now(),
38
+ });
39
+ },
40
+ });
41
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Inter-extension event bus example.
3
+ *
4
+ * Shows valni.events for communication between extensions. One extension
5
+ * can emit events that other extensions listen to.
6
+ *
7
+ * Usage: /emit [event-name] [data] - emit an event on the bus
8
+ */
9
+
10
+ import type { ExtensionAPI, ExtensionContext } from "@valni/cli";
11
+
12
+ export default function (valni: ExtensionAPI) {
13
+ // Store ctx for use in event handler
14
+ let currentCtx: ExtensionContext | undefined;
15
+
16
+ valni.on("session_start", async (_event, ctx) => {
17
+ currentCtx = ctx;
18
+ });
19
+
20
+ // Listen for events from other extensions
21
+ valni.events.on("my:notification", (data) => {
22
+ const { message, from } = data as { message: string; from: string };
23
+ currentCtx?.ui.notify(`Event from ${from}: ${message}`, "info");
24
+ });
25
+
26
+ // Command to emit events (emits "my:notification" which the listener above receives)
27
+ valni.registerCommand("emit", {
28
+ description: "Emit my:notification event (usage: /emit message)",
29
+ handler: async (args, _ctx) => {
30
+ const message = args.trim() || "hello";
31
+ valni.events.emit("my:notification", { message, from: "/emit command" });
32
+ // Listener above will show the notification
33
+ },
34
+ });
35
+
36
+ // Example: emit on session start
37
+ valni.on("session_start", async () => {
38
+ valni.events.emit("my:notification", {
39
+ message: "Session started",
40
+ from: "event-bus-example",
41
+ });
42
+ });
43
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * File Trigger Extension
3
+ *
4
+ * Watches a trigger file and injects its contents into the conversation.
5
+ * Useful for external systems to send messages to the agent.
6
+ *
7
+ * Usage:
8
+ * echo "Run the tests" > /tmp/agent-trigger.txt
9
+ */
10
+
11
+ import * as fs from "node:fs";
12
+ import type { ExtensionAPI } from "@valni/cli";
13
+
14
+ export default function (valni: ExtensionAPI) {
15
+ valni.on("session_start", async (_event, ctx) => {
16
+ const triggerFile = "/tmp/agent-trigger.txt";
17
+
18
+ fs.watch(triggerFile, () => {
19
+ try {
20
+ const content = fs.readFileSync(triggerFile, "utf-8").trim();
21
+ if (content) {
22
+ valni.sendMessage(
23
+ {
24
+ customType: "file-trigger",
25
+ content: `External trigger: ${content}`,
26
+ display: true,
27
+ },
28
+ { triggerTurn: true }, // triggerTurn - get LLM to respond
29
+ );
30
+ fs.writeFileSync(triggerFile, ""); // Clear after reading
31
+ }
32
+ } catch {
33
+ // File might not exist yet
34
+ }
35
+ });
36
+
37
+ if (ctx.hasUI) {
38
+ ctx.ui.notify(`Watching ${triggerFile}`, "info");
39
+ }
40
+ });
41
+ }