apex-code 0.0.1-alpha.7 → 0.0.1-alpha.8

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 (256) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/README.md +5 -0
  3. package/dist/cli/args.d.ts +3 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +15 -0
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/concurrent-session.d.ts +3 -0
  8. package/dist/cli/concurrent-session.d.ts.map +1 -0
  9. package/dist/cli/concurrent-session.js +13 -0
  10. package/dist/cli/concurrent-session.js.map +1 -0
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +1 -2
  13. package/dist/cli.js.map +1 -1
  14. package/dist/core/agent-session-services.d.ts.map +1 -1
  15. package/dist/core/agent-session-services.js +20 -0
  16. package/dist/core/agent-session-services.js.map +1 -1
  17. package/dist/core/agent-session.d.ts +15 -2
  18. package/dist/core/agent-session.d.ts.map +1 -1
  19. package/dist/core/agent-session.js +9 -6
  20. package/dist/core/agent-session.js.map +1 -1
  21. package/dist/core/auth-storage.d.ts +4 -1
  22. package/dist/core/auth-storage.d.ts.map +1 -1
  23. package/dist/core/auth-storage.js +6 -2
  24. package/dist/core/auth-storage.js.map +1 -1
  25. package/dist/core/bash-executor.d.ts.map +1 -1
  26. package/dist/core/bash-executor.js +10 -9
  27. package/dist/core/bash-executor.js.map +1 -1
  28. package/dist/core/experimental.d.ts +4 -0
  29. package/dist/core/experimental.d.ts.map +1 -1
  30. package/dist/core/experimental.js +4 -0
  31. package/dist/core/experimental.js.map +1 -1
  32. package/dist/core/extensions/types.d.ts +4 -0
  33. package/dist/core/extensions/types.d.ts.map +1 -1
  34. package/dist/core/extensions/types.js.map +1 -1
  35. package/dist/core/http-dispatcher.d.ts +1 -2
  36. package/dist/core/http-dispatcher.d.ts.map +1 -1
  37. package/dist/core/http-dispatcher.js +2 -17
  38. package/dist/core/http-dispatcher.js.map +1 -1
  39. package/dist/core/http-idle-timeout.d.ts +12 -0
  40. package/dist/core/http-idle-timeout.d.ts.map +1 -0
  41. package/dist/core/http-idle-timeout.js +27 -0
  42. package/dist/core/http-idle-timeout.js.map +1 -0
  43. package/dist/core/keybindings.d.ts +24 -0
  44. package/dist/core/keybindings.d.ts.map +1 -1
  45. package/dist/core/lsp/client.d.ts +2 -0
  46. package/dist/core/lsp/client.d.ts.map +1 -1
  47. package/dist/core/lsp/client.js +27 -2
  48. package/dist/core/lsp/client.js.map +1 -1
  49. package/dist/core/model-config.d.ts +5 -0
  50. package/dist/core/model-config.d.ts.map +1 -1
  51. package/dist/core/model-config.js +1 -0
  52. package/dist/core/model-config.js.map +1 -1
  53. package/dist/core/sandbox/child-entry.d.ts.map +1 -1
  54. package/dist/core/sandbox/child-entry.js +8 -1
  55. package/dist/core/sandbox/child-entry.js.map +1 -1
  56. package/dist/core/sandbox/cli-launch.d.ts +3 -0
  57. package/dist/core/sandbox/cli-launch.d.ts.map +1 -1
  58. package/dist/core/sandbox/cli-launch.js +25 -4
  59. package/dist/core/sandbox/cli-launch.js.map +1 -1
  60. package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -1
  61. package/dist/core/sandbox/cli-supervisor.js +53 -13
  62. package/dist/core/sandbox/cli-supervisor.js.map +1 -1
  63. package/dist/core/sandbox/linux-backend.d.ts.map +1 -1
  64. package/dist/core/sandbox/linux-backend.js +15 -0
  65. package/dist/core/sandbox/linux-backend.js.map +1 -1
  66. package/dist/core/sandbox/macos-backend.d.ts.map +1 -1
  67. package/dist/core/sandbox/macos-backend.js +24 -1
  68. package/dist/core/sandbox/macos-backend.js.map +1 -1
  69. package/dist/core/sandbox/rpc/credential-client.d.ts +20 -0
  70. package/dist/core/sandbox/rpc/credential-client.d.ts.map +1 -0
  71. package/dist/core/sandbox/rpc/credential-client.js +170 -0
  72. package/dist/core/sandbox/rpc/credential-client.js.map +1 -0
  73. package/dist/core/sandbox/rpc/credential-proxy.d.ts +44 -0
  74. package/dist/core/sandbox/rpc/credential-proxy.d.ts.map +1 -0
  75. package/dist/core/sandbox/rpc/credential-proxy.js +381 -0
  76. package/dist/core/sandbox/rpc/credential-proxy.js.map +1 -0
  77. package/dist/core/sandbox/supervisor.d.ts +11 -0
  78. package/dist/core/sandbox/supervisor.d.ts.map +1 -1
  79. package/dist/core/sandbox/supervisor.js.map +1 -1
  80. package/dist/core/sandbox/terminal-size.d.ts +40 -0
  81. package/dist/core/sandbox/terminal-size.d.ts.map +1 -0
  82. package/dist/core/sandbox/terminal-size.js +105 -0
  83. package/dist/core/sandbox/terminal-size.js.map +1 -0
  84. package/dist/core/sdk.d.ts +6 -3
  85. package/dist/core/sdk.d.ts.map +1 -1
  86. package/dist/core/sdk.js +16 -4
  87. package/dist/core/sdk.js.map +1 -1
  88. package/dist/core/session-lease.d.ts +31 -0
  89. package/dist/core/session-lease.d.ts.map +1 -0
  90. package/dist/core/session-lease.js +138 -0
  91. package/dist/core/session-lease.js.map +1 -0
  92. package/dist/core/session-manager.d.ts +5 -0
  93. package/dist/core/session-manager.d.ts.map +1 -1
  94. package/dist/core/session-manager.js +3 -3
  95. package/dist/core/session-manager.js.map +1 -1
  96. package/dist/core/settings-manager.d.ts +26 -0
  97. package/dist/core/settings-manager.d.ts.map +1 -1
  98. package/dist/core/settings-manager.js +42 -3
  99. package/dist/core/settings-manager.js.map +1 -1
  100. package/dist/core/slash-commands.d.ts.map +1 -1
  101. package/dist/core/slash-commands.js +2 -0
  102. package/dist/core/slash-commands.js.map +1 -1
  103. package/dist/core/system-prompt.d.ts +2 -2
  104. package/dist/core/system-prompt.d.ts.map +1 -1
  105. package/dist/core/system-prompt.js +47 -62
  106. package/dist/core/system-prompt.js.map +1 -1
  107. package/dist/core/tools/bash.d.ts.map +1 -1
  108. package/dist/core/tools/bash.js +2 -0
  109. package/dist/core/tools/bash.js.map +1 -1
  110. package/dist/core/tools/delegate.d.ts.map +1 -1
  111. package/dist/core/tools/delegate.js +24 -0
  112. package/dist/core/tools/delegate.js.map +1 -1
  113. package/dist/core/tools/edit.d.ts.map +1 -1
  114. package/dist/core/tools/edit.js +2 -0
  115. package/dist/core/tools/edit.js.map +1 -1
  116. package/dist/core/tools/find.d.ts.map +1 -1
  117. package/dist/core/tools/find.js +1 -1
  118. package/dist/core/tools/find.js.map +1 -1
  119. package/dist/core/tools/grep.d.ts +2 -0
  120. package/dist/core/tools/grep.d.ts.map +1 -1
  121. package/dist/core/tools/grep.js +35 -10
  122. package/dist/core/tools/grep.js.map +1 -1
  123. package/dist/core/tools/ls.d.ts +2 -0
  124. package/dist/core/tools/ls.d.ts.map +1 -1
  125. package/dist/core/tools/ls.js +5 -1
  126. package/dist/core/tools/ls.js.map +1 -1
  127. package/dist/core/tools/read.d.ts.map +1 -1
  128. package/dist/core/tools/read.js +2 -0
  129. package/dist/core/tools/read.js.map +1 -1
  130. package/dist/core/tools/web-search-exa.d.ts +33 -0
  131. package/dist/core/tools/web-search-exa.d.ts.map +1 -0
  132. package/dist/core/tools/web-search-exa.js +128 -0
  133. package/dist/core/tools/web-search-exa.js.map +1 -0
  134. package/dist/core/tools/write.d.ts.map +1 -1
  135. package/dist/core/tools/write.js +2 -0
  136. package/dist/core/tools/write.js.map +1 -1
  137. package/dist/core/web-search-provider.d.ts +64 -0
  138. package/dist/core/web-search-provider.d.ts.map +1 -0
  139. package/dist/core/web-search-provider.js +149 -0
  140. package/dist/core/web-search-provider.js.map +1 -0
  141. package/dist/index.d.ts +1 -1
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js.map +1 -1
  144. package/dist/main.d.ts +1 -0
  145. package/dist/main.d.ts.map +1 -1
  146. package/dist/main.js +20 -1
  147. package/dist/main.js.map +1 -1
  148. package/dist/modes/interactive/components/custom-editor.d.ts +23 -0
  149. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  150. package/dist/modes/interactive/components/custom-editor.js +105 -2
  151. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  152. package/dist/modes/interactive/components/dynamic-border.d.ts +7 -1
  153. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  154. package/dist/modes/interactive/components/dynamic-border.js +11 -2
  155. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  156. package/dist/modes/interactive/components/extension-selector.d.ts +4 -0
  157. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  158. package/dist/modes/interactive/components/extension-selector.js +24 -6
  159. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  160. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  161. package/dist/modes/interactive/components/first-time-setup.js +6 -3
  162. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  163. package/dist/modes/interactive/components/first-use-hints.d.ts +8 -0
  164. package/dist/modes/interactive/components/first-use-hints.d.ts.map +1 -0
  165. package/dist/modes/interactive/components/first-use-hints.js +22 -0
  166. package/dist/modes/interactive/components/first-use-hints.js.map +1 -0
  167. package/dist/modes/interactive/components/footer.d.ts +12 -0
  168. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  169. package/dist/modes/interactive/components/footer.js +128 -9
  170. package/dist/modes/interactive/components/footer.js.map +1 -1
  171. package/dist/modes/interactive/components/index.d.ts +1 -0
  172. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  173. package/dist/modes/interactive/components/index.js +1 -0
  174. package/dist/modes/interactive/components/index.js.map +1 -1
  175. package/dist/modes/interactive/components/model-selector.d.ts +2 -0
  176. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  177. package/dist/modes/interactive/components/model-selector.js +20 -5
  178. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  179. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  180. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  181. package/dist/modes/interactive/components/settings-selector.js +10 -0
  182. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  183. package/dist/modes/interactive/components/splash-header.d.ts +29 -4
  184. package/dist/modes/interactive/components/splash-header.d.ts.map +1 -1
  185. package/dist/modes/interactive/components/splash-header.js +58 -23
  186. package/dist/modes/interactive/components/splash-header.js.map +1 -1
  187. package/dist/modes/interactive/components/tool-execution.d.ts +14 -0
  188. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  189. package/dist/modes/interactive/components/tool-execution.js +113 -35
  190. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  191. package/dist/modes/interactive/components/tool-panel.d.ts +30 -0
  192. package/dist/modes/interactive/components/tool-panel.d.ts.map +1 -0
  193. package/dist/modes/interactive/components/tool-panel.js +130 -0
  194. package/dist/modes/interactive/components/tool-panel.js.map +1 -0
  195. package/dist/modes/interactive/interactive-mode.d.ts +44 -9
  196. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  197. package/dist/modes/interactive/interactive-mode.js +282 -70
  198. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  199. package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
  200. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
  201. package/dist/modes/interactive/model-catalog-refresh.js +34 -0
  202. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
  203. package/dist/modes/interactive/theme/apex.json +62 -63
  204. package/dist/modes/interactive/theme/dark.json +2 -0
  205. package/dist/modes/interactive/theme/light.json +2 -0
  206. package/dist/modes/interactive/theme/theme-controller.d.ts +10 -2
  207. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  208. package/dist/modes/interactive/theme/theme-controller.js +25 -11
  209. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  210. package/dist/modes/interactive/theme/theme-schema.json +9 -1
  211. package/dist/modes/interactive/theme/theme.d.ts +14 -3
  212. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  213. package/dist/modes/interactive/theme/theme.js +55 -6
  214. package/dist/modes/interactive/theme/theme.js.map +1 -1
  215. package/dist/modes/json-event.d.ts +4 -1
  216. package/dist/modes/json-event.d.ts.map +1 -1
  217. package/dist/modes/json-event.js +5 -2
  218. package/dist/modes/json-event.js.map +1 -1
  219. package/dist/server/create-harness.d.ts.map +1 -1
  220. package/dist/server/create-harness.js +2 -0
  221. package/dist/server/create-harness.js.map +1 -1
  222. package/dist/themes/apex-logo.d.ts +36 -16
  223. package/dist/themes/apex-logo.d.ts.map +1 -1
  224. package/dist/themes/apex-logo.js +32 -28
  225. package/dist/themes/apex-logo.js.map +1 -1
  226. package/dist/utils/tools-manager.d.ts +10 -1
  227. package/dist/utils/tools-manager.d.ts.map +1 -1
  228. package/dist/utils/tools-manager.js +15 -20
  229. package/dist/utils/tools-manager.js.map +1 -1
  230. package/docs/compaction.md +3 -3
  231. package/docs/custom-provider.md +1 -1
  232. package/docs/environment-variables.md +1 -0
  233. package/docs/extensions.md +4 -0
  234. package/docs/json.md +6 -4
  235. package/docs/keybindings.md +8 -2
  236. package/docs/rpc.md +15 -4
  237. package/docs/sdk.md +9 -0
  238. package/docs/settings.md +63 -0
  239. package/docs/terminal-setup.md +23 -2
  240. package/docs/themes.md +24 -3
  241. package/docs/tui.md +2 -2
  242. package/docs/usage.md +3 -2
  243. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  244. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  245. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  246. package/examples/extensions/gondolin/package-lock.json +2 -2
  247. package/examples/extensions/gondolin/package.json +1 -1
  248. package/examples/extensions/sandbox/package-lock.json +2 -2
  249. package/examples/extensions/sandbox/package.json +1 -1
  250. package/examples/extensions/subagent/README.md +2 -0
  251. package/examples/extensions/subagent/agents.ts +40 -9
  252. package/examples/extensions/subagent/index.ts +21 -3
  253. package/examples/extensions/with-deps/package-lock.json +2 -2
  254. package/examples/extensions/with-deps/package.json +1 -1
  255. package/npm-shrinkwrap.json +27 -78
  256. package/package.json +6 -6
@@ -25,6 +25,9 @@ const COMMAND_TOKEN = /^(\s*)(\/\S+)/;
25
25
  * scanning in {@link colorVisibleRange}.
26
26
  */
27
27
  const CONTROL_SEQUENCE = /\x1b\[[0-9;]*[A-Za-z]|\x1b_[^\x07]*\x07/y;
28
+ /** The reverse-video cursor cell emitted by the inherited editor. */
29
+ const INVERTED_CURSOR_CELL = /\x1b\[7m[\s\S]\x1b\[(?:0|27)m/y;
30
+ const SURFACE_PADDING = 2;
28
31
  /**
29
32
  * ============================ ANSI measuring hazards ============================
30
33
  *
@@ -119,7 +122,11 @@ export class CustomEditor extends Editor {
119
122
  promptColor;
120
123
  placeholderColor;
121
124
  commandColor;
125
+ surfaceColor;
122
126
  placeholder;
127
+ autocompleteRule;
128
+ autocompleteFooter;
129
+ modeLabel = "";
123
130
  actionHandlers = new Map();
124
131
  // Special handlers that can be dynamically replaced
125
132
  onEscape;
@@ -135,9 +142,20 @@ export class CustomEditor extends Editor {
135
142
  this.placeholder = options?.placeholder;
136
143
  this.placeholderColor = options?.placeholderColor ?? ((text) => text);
137
144
  this.commandColor = options?.commandColor;
145
+ this.surfaceColor = options?.surfaceColor;
146
+ this.autocompleteRule = options?.autocompleteRule;
147
+ this.autocompleteFooter = options?.autocompleteFooter;
138
148
  }
139
149
  render(width) {
140
- const prefixWidth = visibleWidth(this.promptPrefix);
150
+ const canRenderSurface = this.surfaceColor !== undefined && width > 0;
151
+ const surfacePadding = canRenderSurface ? Math.min(SURFACE_PADDING, Math.floor((width - 1) / 2)) : 0;
152
+ const editorWidth = canRenderSurface ? width - surfacePadding * 2 : width;
153
+ const lines = this.withAutocompleteChrome(this.renderEditor(editorWidth), editorWidth);
154
+ return canRenderSurface ? this.withSurface(lines, width, surfacePadding) : lines;
155
+ }
156
+ renderEditor(width) {
157
+ const promptPrefix = this.modeLabel ? `[${this.modeLabel}] ${this.promptPrefix}` : this.promptPrefix;
158
+ const prefixWidth = visibleWidth(promptPrefix);
141
159
  // Reserve the prefix out of the width handed to the base Editor, so its
142
160
  // wrapping, scrolling and cursor column all account for the space the
143
161
  // prefix occupies. Bail out entirely when the terminal cannot spare it.
@@ -147,7 +165,7 @@ export class CustomEditor extends Editor {
147
165
  const inner = this.withCommandColor(this.withPlaceholder(super.render(width - prefixWidth)));
148
166
  const borderPad = this.borderColor(BORDER_CHAR.repeat(prefixWidth));
149
167
  const blank = " ".repeat(prefixWidth);
150
- const styledPrefix = this.promptColor(this.promptPrefix);
168
+ const styledPrefix = this.promptColor(promptPrefix);
151
169
  // Structure is: top border, content lines, bottom border, then optional
152
170
  // autocomplete rows. Counting borders tells the three regions apart
153
171
  // without depending on how many lines each contains.
@@ -169,6 +187,91 @@ export class CustomEditor extends Editor {
169
187
  return blank + line;
170
188
  });
171
189
  }
190
+ /**
191
+ * Brackets the autocomplete rows with a rule and a keybinding footer.
192
+ *
193
+ * The rows arrive after the editor's second border, so the same border count
194
+ * that separates the box from its dropdown elsewhere in this file finds them
195
+ * here. Nothing is added when the dropdown is closed.
196
+ */
197
+ withAutocompleteChrome(lines, width) {
198
+ if (!this.autocompleteRule && !this.autocompleteFooter)
199
+ return lines;
200
+ const blockLineCount = this.editorBlockLineCount(lines);
201
+ const rows = lines.slice(blockLineCount);
202
+ if (rows.length === 0)
203
+ return lines;
204
+ const chrome = [...lines.slice(0, blockLineCount)];
205
+ if (this.autocompleteRule)
206
+ chrome.push(this.autocompleteRule(width));
207
+ chrome.push(...rows);
208
+ if (this.autocompleteFooter)
209
+ chrome.push(this.autocompleteFooter());
210
+ return chrome;
211
+ }
212
+ withSurface(lines, width, padding) {
213
+ const surfaceColor = this.surfaceColor;
214
+ if (!surfaceColor)
215
+ return lines;
216
+ const result = [this.surfaceLine(" ".repeat(width), surfaceColor)];
217
+ const editorBlockLineCount = this.editorBlockLineCount(lines);
218
+ const editorContent = lines.slice(1, Math.max(1, editorBlockLineCount - 1));
219
+ for (const line of editorContent) {
220
+ result.push(this.surfaceLine(`${" ".repeat(padding)}${line}${" ".repeat(padding)}`, surfaceColor));
221
+ }
222
+ result.push(this.surfaceLine(" ".repeat(width), surfaceColor));
223
+ for (const line of lines.slice(editorBlockLineCount)) {
224
+ result.push(`${" ".repeat(padding)}${line}`);
225
+ }
226
+ return result;
227
+ }
228
+ editorBlockLineCount(lines) {
229
+ let borders = 0;
230
+ for (let index = 0; index < lines.length; index++) {
231
+ if (this.isBorderLine(lines[index]))
232
+ borders++;
233
+ if (borders === 2)
234
+ return index + 1;
235
+ }
236
+ return lines.length;
237
+ }
238
+ surfaceLine(line, surfaceColor) {
239
+ let output = "";
240
+ let visibleText = "";
241
+ let index = 0;
242
+ const flush = () => {
243
+ if (visibleText) {
244
+ output += surfaceColor(visibleText);
245
+ visibleText = "";
246
+ }
247
+ };
248
+ while (index < line.length) {
249
+ INVERTED_CURSOR_CELL.lastIndex = index;
250
+ const cursorCell = INVERTED_CURSOR_CELL.exec(line);
251
+ if (cursorCell) {
252
+ flush();
253
+ output += cursorCell[0];
254
+ index = INVERTED_CURSOR_CELL.lastIndex;
255
+ continue;
256
+ }
257
+ CONTROL_SEQUENCE.lastIndex = index;
258
+ const control = CONTROL_SEQUENCE.exec(line);
259
+ if (control) {
260
+ flush();
261
+ output += control[0];
262
+ index = CONTROL_SEQUENCE.lastIndex;
263
+ continue;
264
+ }
265
+ visibleText += line[index];
266
+ index += 1;
267
+ }
268
+ flush();
269
+ return output;
270
+ }
271
+ setModeLabel(label) {
272
+ this.modeLabel = label ?? "";
273
+ this.invalidate();
274
+ }
172
275
  isBorderLine(line) {
173
276
  const visible = stripAnsi(line.split(CURSOR_MARKER).join(""));
174
277
  return BORDER_RULE.test(visible) || BORDER_SCROLL.test(visible);
@@ -1 +1 @@
1
- {"version":3,"file":"custom-editor.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,MAAM,EAIN,eAAe,EACf,YAAY,GACZ,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAenD,qFAAqF;AACrF,MAAM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,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBACpE,IAAI,OAAO;oBAAE,OAAO,EAAE,CAAC;gBACvB,OAAO;YACR,CAAC;YACD,yEAAyE;QAC1E,CAAC;QAED,0FAA0F;QAC1F,uEAAuE;QACvE,IACC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,4BAA4B,CAAC;YAC5D,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,wBAAwB,CAAC,EACvD,CAAC;YACF,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACxB,OAAO;QACR,CAAC;QAED,8BAA8B;QAC9B,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACrD,IAAI,MAAM,KAAK,eAAe,IAAI,MAAM,KAAK,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;gBACnG,OAAO,EAAE,CAAC;gBACV,OAAO;YACR,CAAC;QACF,CAAC;QAED,qCAAqC;QACrC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAAA,CACxB;CACD","sourcesContent":["import {\n\tCURSOR_MARKER,\n\tEditor,\n\ttype EditorOptions,\n\ttype EditorTheme,\n\ttype TUI,\n\ttruncateToWidth,\n\tvisibleWidth,\n} from \"@earendil-works/pi-tui\";\nimport type { AppKeybinding, KeybindingsManager } from \"../../../core/keybindings.ts\";\nimport { stripAnsi } from \"../../../utils/ansi.ts\";\n\nexport interface CustomEditorOptions extends EditorOptions {\n\t/** Marker rendered at the start of the first input line, e.g. `\"> \"`. */\n\tpromptPrefix?: string;\n\t/** Styles the prompt prefix. Defaults to leaving it unstyled. */\n\tpromptColor?: (text: string) => string;\n\t/** Shown in place of the empty input line. */\n\tplaceholder?: string;\n\t/** Styles the placeholder. Defaults to leaving it unstyled. */\n\tplaceholderColor?: (text: string) => string;\n\t/** Styles a leading `/command` token. Defaults to leaving it unstyled. */\n\tcommandColor?: (text: string) => string;\n}\n\n/** Box-drawing horizontal rule: the character the base Editor draws borders from. */\nconst BORDER_CHAR = \"─\";\n\n/**\n * The two shapes the base Editor draws a border in: a plain full-width rule, and\n * the scroll indicator (`─── ↑ 3 more ────`).\n *\n * Both are anchored deliberately. A prefix test would count any content line that\n * merely *starts* with the rule character — a pasted divider, `─notes` — as a\n * border, which is worse than it sounds: {@link CustomEditor.render} tells the\n * content region from the autocomplete region by counting borders, so one\n * miscount shifts every later line into the wrong region.\n */\nconst BORDER_RULE = /^─+$/;\nconst BORDER_SCROLL = /^─+ [↑↓] \\d+ more/;\n\n/**\n * A leading `/command` token: optional indent, a slash, then non-space.\n * Matched against the line's *visible* text, not the rendered string.\n */\nconst COMMAND_TOKEN = /^(\\s*)(\\/\\S+)/;\n\n/**\n * One ANSI control sequence: a CSI escape (`ESC [ … letter`) or the APC\n * hardware-cursor marker (`ESC _ … BEL`). Sticky, for position-by-position\n * scanning in {@link colorVisibleRange}.\n */\nconst CONTROL_SEQUENCE = /\\x1b\\[[0-9;]*[A-Za-z]|\\x1b_[^\\x07]*\\x07/y;\n\n/**\n * ============================ ANSI measuring hazards ============================\n *\n * Two traps live in the rendered strings this file post-processes. Both produced\n * real bugs; both are cheap to re-introduce. Read this before touching the width\n * maths or any leading-sequence match.\n *\n * 1. DO NOT COMPOSE `stripAnsi` WITH `visibleWidth`.\n *\n * `stripAnsi` removes SGR colour codes but leaves the APC hardware-cursor\n * marker (`ESC _pi:c BEL`, see CURSOR_MARKER in packages/tui) fully intact —\n * all seven bytes of it. `visibleWidth` already handles that marker correctly\n * and scores it zero.\n *\n * So `visibleWidth(stripAnsi(line))` counts seven phantom columns on every\n * line carrying a cursor, which silently widened each placeholder line past\n * the terminal width. Measure with `visibleWidth` alone. Use `stripAnsi` only\n * to read text, never to measure it.\n *\n * 2. DO NOT MATCH THE LEADING SEQUENCE RUN GENERICALLY.\n *\n * The base Editor renders an empty line as:\n * CURSOR_MARKER ESC[7m <space> ESC[0m <padding>\n * The `ESC[7m` turns on reverse video for exactly the one-cell cursor block,\n * and `ESC[0m` turns it back off.\n *\n * A permissive prefix match such as `(?:\\x1b\\[[0-9;]*m)*` consumes that\n * `ESC[7m` as though it were ordinary leading styling. Whatever is appended\n * next then inherits reverse video, and because the matching `ESC[0m` was\n * left behind in the discarded remainder, the inversion runs on through the\n * placeholder and the rest of the frame. Match the reverse-video run\n * explicitly instead — see {@link CustomEditor.sliceLeadingCursorCell}.\n *\n * ==============================================================================\n */\n\n/**\n * Wrap the visible characters in `[start, end)` with `colorFn`, leaving every\n * control sequence in place.\n *\n * The range is in visible columns, so it is unaffected by however many escape\n * sequences are interleaved. That matters because the cursor cell can land in\n * the middle of the token being coloured: with the caret at column 3 of\n * `/model`, the line reads `/mo` + CURSOR_MARKER + `ESC[7m` + `d` + `ESC[0m` +\n * `el`. Colour is therefore re-opened after every control sequence rather than\n * once around the whole token, since the cursor cell's `ESC[0m` would otherwise\n * cancel it partway through.\n */\nfunction colorVisibleRange(line: string, start: number, end: number, colorFn: (text: string) => string): string {\n\tlet out = \"\";\n\tlet buffer = \"\";\n\tlet column = 0;\n\tlet index = 0;\n\n\tconst flush = () => {\n\t\tif (buffer) {\n\t\t\tout += colorFn(buffer);\n\t\t\tbuffer = \"\";\n\t\t}\n\t};\n\n\twhile (index < line.length) {\n\t\tCONTROL_SEQUENCE.lastIndex = index;\n\t\tconst control = CONTROL_SEQUENCE.exec(line);\n\t\tif (control) {\n\t\t\tflush();\n\t\t\tout += control[0];\n\t\t\tindex = CONTROL_SEQUENCE.lastIndex;\n\t\t\tcontinue;\n\t\t}\n\t\tconst char = line[index];\n\t\tif (column >= start && column < end) {\n\t\t\tbuffer += char;\n\t\t} else {\n\t\t\tflush();\n\t\t\tout += char;\n\t\t}\n\t\tcolumn += visibleWidth(char);\n\t\tindex += 1;\n\t}\n\tflush();\n\treturn out;\n}\n\n/**\n * Custom editor that handles app-level keybindings for coding-agent.\n *\n * The prompt prefix and placeholder are layered on in `render` rather than\n * inside the base Editor, because `packages/tui` is frozen under ADR 0001 and\n * its `EditorOptions` has no hook for either.\n */\nexport class CustomEditor extends Editor {\n\tprivate keybindings: KeybindingsManager;\n\tprivate readonly promptPrefix: string;\n\tprivate readonly promptColor: (text: string) => string;\n\tprivate readonly placeholderColor: (text: string) => string;\n\tprivate readonly commandColor: ((text: string) => string) | undefined;\n\tprivate readonly placeholder: string | undefined;\n\tpublic actionHandlers: Map<AppKeybinding, () => void> = new Map();\n\n\t// Special handlers that can be dynamically replaced\n\tpublic onEscape?: () => void;\n\tpublic onCtrlD?: () => void;\n\tpublic onPasteImage?: () => void;\n\t/** Handler for extension-registered shortcuts. Returns true if handled. */\n\tpublic onExtensionShortcut?: (data: string) => boolean;\n\n\tconstructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager, options?: CustomEditorOptions) {\n\t\tsuper(tui, theme, options);\n\t\tthis.keybindings = keybindings;\n\t\tthis.promptPrefix = options?.promptPrefix ?? \"\";\n\t\tthis.promptColor = options?.promptColor ?? ((text) => text);\n\t\tthis.placeholder = options?.placeholder;\n\t\tthis.placeholderColor = options?.placeholderColor ?? ((text) => text);\n\t\tthis.commandColor = options?.commandColor;\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst prefixWidth = visibleWidth(this.promptPrefix);\n\t\t// Reserve the prefix out of the width handed to the base Editor, so its\n\t\t// wrapping, scrolling and cursor column all account for the space the\n\t\t// prefix occupies. Bail out entirely when the terminal cannot spare it.\n\t\tif (prefixWidth === 0 || width <= prefixWidth + 4) {\n\t\t\treturn this.withCommandColor(this.withPlaceholder(super.render(width)));\n\t\t}\n\n\t\tconst inner = this.withCommandColor(this.withPlaceholder(super.render(width - prefixWidth)));\n\t\tconst borderPad = this.borderColor(BORDER_CHAR.repeat(prefixWidth));\n\t\tconst blank = \" \".repeat(prefixWidth);\n\t\tconst styledPrefix = this.promptColor(this.promptPrefix);\n\n\t\t// Structure is: top border, content lines, bottom border, then optional\n\t\t// autocomplete rows. Counting borders tells the three regions apart\n\t\t// without depending on how many lines each contains.\n\t\tlet borders = 0;\n\t\tlet firstContentLine = true;\n\t\treturn inner.map((line) => {\n\t\t\tif (this.isBorderLine(line)) {\n\t\t\t\tborders++;\n\t\t\t\treturn borderPad + line;\n\t\t\t}\n\t\t\tif (borders !== 1) {\n\t\t\t\t// Autocomplete rows sit below the box; indent them to match.\n\t\t\t\treturn blank + line;\n\t\t\t}\n\t\t\tif (firstContentLine) {\n\t\t\t\tfirstContentLine = false;\n\t\t\t\treturn styledPrefix + line;\n\t\t\t}\n\t\t\treturn blank + line;\n\t\t});\n\t}\n\n\tprivate isBorderLine(line: string): boolean {\n\t\tconst visible = stripAnsi(line.split(CURSOR_MARKER).join(\"\"));\n\t\treturn BORDER_RULE.test(visible) || BORDER_SCROLL.test(visible);\n\t}\n\n\t/**\n\t * Tint a leading `/command` on the first input line.\n\t *\n\t * The base Editor emits input text unstyled, so the only styling already\n\t * present on the line is the cursor cell — which `colorVisibleRange` steps\n\t * over. Only the command token is tinted; arguments after it stay plain, so\n\t * the highlight marks what is being invoked rather than the whole line.\n\t */\n\tprivate withCommandColor(lines: string[]): string[] {\n\t\tconst commandColor = this.commandColor;\n\t\tif (!commandColor || lines.length < 2) {\n\t\t\treturn lines;\n\t\t}\n\t\t// Read the token from the model rather than the rendered line: the first\n\t\t// visual row is the start of the text only when the caret has not scrolled\n\t\t// the view down, and getText is unambiguous either way.\n\t\tconst firstLine = this.getText().split(\"\\n\", 1)[0] ?? \"\";\n\t\tconst match = COMMAND_TOKEN.exec(firstLine);\n\t\tif (!match) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst [, indent, token] = match;\n\t\t// The rendered row must still begin with that token, or the view has\n\t\t// scrolled and the highlight would land on unrelated text.\n\t\tif (!stripAnsi(lines[1].split(CURSOR_MARKER).join(\"\")).startsWith(`${indent}${token}`)) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst start = visibleWidth(indent);\n\t\tconst updated = [...lines];\n\t\tupdated[1] = colorVisibleRange(lines[1], start, start + visibleWidth(token), commandColor);\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Replace the sole content line with the placeholder while the input is\n\t * empty. Index 1 is always the first content line, and an empty editor has\n\t * exactly one, so no line classification is needed here.\n\t */\n\tprivate withPlaceholder(lines: string[]): string[] {\n\t\tconst placeholder = this.placeholder;\n\t\tif (!placeholder || lines.length < 2 || this.getText().length > 0 || this.isShowingAutocomplete()) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst contentLine = lines[1];\n\t\t// Preserve the cursor cell when focused; unfocused there is none, and the\n\t\t// placeholder simply starts at column zero.\n\t\tconst cursorCell = this.sliceLeadingCursorCell(contentLine);\n\t\t// Measure with visibleWidth alone — never visibleWidth(stripAnsi(...)),\n\t\t// which scores the cursor marker as seven columns. See hazard 1 at the top\n\t\t// of this file.\n\t\tconst available = visibleWidth(contentLine) - visibleWidth(cursorCell);\n\t\tif (available <= 0) {\n\t\t\treturn lines;\n\t\t}\n\t\t// Cut by display width, not by String.slice: `available` counts terminal\n\t\t// columns, while slice counts UTF-16 code units. They only agree for\n\t\t// plain ASCII, and disagreeing splits a surrogate pair or overruns the\n\t\t// line on the first wide character.\n\t\tconst text = truncateToWidth(placeholder, available, \"\");\n\t\tconst padding = \" \".repeat(Math.max(0, available - visibleWidth(text)));\n\t\tconst updated = [...lines];\n\t\tupdated[1] = cursorCell + this.placeholderColor(text) + padding;\n\t\treturn updated;\n\t}\n\n\t/**\n\t * The base Editor renders an empty line as the hardware-cursor marker\n\t * followed by a reverse-video cell: `CURSOR_MARKER ESC[7m <space> ESC[0m`.\n\t * Both parts are kept verbatim.\n\t *\n\t * The `ESC[7m … ESC[0m` run is matched explicitly. Do not \"simplify\" this to\n\t * a general leading-SGR match such as `(?:\\x1b\\[[0-9;]*m)*` — see hazard 2 at\n\t * the top of this file for what that breaks.\n\t */\n\tprivate sliceLeadingCursorCell(line: string): string {\n\t\tconst match = /^(?:\\x1b_pi:c\\x07)?(?:\\x1b\\[7m.\\x1b\\[(?:0|27)m)?/.exec(line);\n\t\treturn match?.[0] ?? \"\";\n\t}\n\n\t/**\n\t * Register a handler for an app action.\n\t */\n\tonAction(action: AppKeybinding, handler: () => void): void {\n\t\tthis.actionHandlers.set(action, handler);\n\t}\n\n\thandleInput(data: string): void {\n\t\t// Check extension-registered shortcuts first\n\t\tif (this.onExtensionShortcut?.(data)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for clipboard paste keybinding\n\t\tif (this.keybindings.matches(data, \"app.clipboard.pasteImage\")) {\n\t\t\tthis.onPasteImage?.();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check app keybindings first\n\n\t\t// Escape/interrupt - only if autocomplete is NOT active\n\t\tif (this.keybindings.matches(data, \"app.interrupt\")) {\n\t\t\tif (!this.isShowingAutocomplete()) {\n\t\t\t\t// Use dynamic onEscape if set, otherwise registered handler\n\t\t\t\tconst handler = this.onEscape ?? this.actionHandlers.get(\"app.interrupt\");\n\t\t\t\tif (handler) {\n\t\t\t\t\thandler();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Let parent handle escape for autocomplete cancellation\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit (Ctrl+D) - only when editor is empty\n\t\tif (this.keybindings.matches(data, \"app.exit\")) {\n\t\t\tif (this.getText().length === 0) {\n\t\t\t\tconst handler = this.onCtrlD ?? this.actionHandlers.get(\"app.exit\");\n\t\t\t\tif (handler) handler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Fall through to editor handling for delete-char-forward when not empty\n\t\t}\n\n\t\t// Explicit history bindings take precedence over app actions while the editor is focused.\n\t\t// This lets users bind Ctrl+P even though it cycles models by default.\n\t\tif (\n\t\t\tthis.keybindings.matches(data, \"tui.editor.historyPrevious\") ||\n\t\t\tthis.keybindings.matches(data, \"tui.editor.historyNext\")\n\t\t) {\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check all other app actions\n\t\tfor (const [action, handler] of this.actionHandlers) {\n\t\t\tif (action !== \"app.interrupt\" && action !== \"app.exit\" && this.keybindings.matches(data, action)) {\n\t\t\t\thandler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Pass to parent for editor handling\n\t\tsuper.handleInput(data);\n\t}\n}\n"]}
1
+ {"version":3,"file":"custom-editor.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/custom-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,MAAM,EAIN,eAAe,EACf,YAAY,GACZ,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAqBnD,qFAAqF;AACrF,MAAM,WAAW,GAAG,KAAG,CAAC;AAExB;;;;;;;;;GASG;AACH,MAAM,WAAW,GAAG,QAAM,CAAC;AAC3B,MAAM,aAAa,GAAG,yBAAmB,CAAC;AAE1C;;;GAGG;AACH,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,0CAA0C,CAAC;AAEpE,qEAAqE;AACrE,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,OAAiC,EAAU;IAC/G,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,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OR_MARKER,\n\tEditor,\n\ttype EditorOptions,\n\ttype EditorTheme,\n\ttype TUI,\n\ttruncateToWidth,\n\tvisibleWidth,\n} from \"@earendil-works/pi-tui\";\nimport type { AppKeybinding, KeybindingsManager } from \"../../../core/keybindings.ts\";\nimport { stripAnsi } from \"../../../utils/ansi.ts\";\n\nexport interface CustomEditorOptions extends EditorOptions {\n\t/** Marker rendered at the start of the first input line, e.g. `\"> \"`. */\n\tpromptPrefix?: string;\n\t/** Styles the prompt prefix. Defaults to leaving it unstyled. */\n\tpromptColor?: (text: string) => string;\n\t/** Shown in place of the empty input line. */\n\tplaceholder?: string;\n\t/** Styles the placeholder. Defaults to leaving it unstyled. */\n\tplaceholderColor?: (text: string) => string;\n\t/** Styles a leading `/command` token. Defaults to leaving it unstyled. */\n\tcommandColor?: (text: string) => string;\n\t/** Applies the filled prompt surface around the editor block. */\n\tsurfaceColor?: (text: string) => string;\n\t/** Rule drawn above the autocomplete rows. Omit for no rule. */\n\tautocompleteRule?: (width: number) => string;\n\t/** Keybinding footer drawn under the autocomplete rows. Omit for no footer. */\n\tautocompleteFooter?: () => string;\n}\n\n/** Box-drawing horizontal rule: the character the base Editor draws borders from. */\nconst BORDER_CHAR = \"─\";\n\n/**\n * The two shapes the base Editor draws a border in: a plain full-width rule, and\n * the scroll indicator (`─── ↑ 3 more ────`).\n *\n * Both are anchored deliberately. A prefix test would count any content line that\n * merely *starts* with the rule character — a pasted divider, `─notes` — as a\n * border, which is worse than it sounds: {@link CustomEditor.render} tells the\n * content region from the autocomplete region by counting borders, so one\n * miscount shifts every later line into the wrong region.\n */\nconst BORDER_RULE = /^─+$/;\nconst BORDER_SCROLL = /^─+ [↑↓] \\d+ more/;\n\n/**\n * A leading `/command` token: optional indent, a slash, then non-space.\n * Matched against the line's *visible* text, not the rendered string.\n */\nconst COMMAND_TOKEN = /^(\\s*)(\\/\\S+)/;\n\n/**\n * One ANSI control sequence: a CSI escape (`ESC [ … letter`) or the APC\n * hardware-cursor marker (`ESC _ … BEL`). Sticky, for position-by-position\n * scanning in {@link colorVisibleRange}.\n */\nconst CONTROL_SEQUENCE = /\\x1b\\[[0-9;]*[A-Za-z]|\\x1b_[^\\x07]*\\x07/y;\n\n/** The reverse-video cursor cell emitted by the inherited editor. */\nconst INVERTED_CURSOR_CELL = /\\x1b\\[7m[\\s\\S]\\x1b\\[(?:0|27)m/y;\n\nconst SURFACE_PADDING = 2;\n\n/**\n * ============================ ANSI measuring hazards ============================\n *\n * Two traps live in the rendered strings this file post-processes. Both produced\n * real bugs; both are cheap to re-introduce. Read this before touching the width\n * maths or any leading-sequence match.\n *\n * 1. DO NOT COMPOSE `stripAnsi` WITH `visibleWidth`.\n *\n * `stripAnsi` removes SGR colour codes but leaves the APC hardware-cursor\n * marker (`ESC _pi:c BEL`, see CURSOR_MARKER in packages/tui) fully intact —\n * all seven bytes of it. `visibleWidth` already handles that marker correctly\n * and scores it zero.\n *\n * So `visibleWidth(stripAnsi(line))` counts seven phantom columns on every\n * line carrying a cursor, which silently widened each placeholder line past\n * the terminal width. Measure with `visibleWidth` alone. Use `stripAnsi` only\n * to read text, never to measure it.\n *\n * 2. DO NOT MATCH THE LEADING SEQUENCE RUN GENERICALLY.\n *\n * The base Editor renders an empty line as:\n * CURSOR_MARKER ESC[7m <space> ESC[0m <padding>\n * The `ESC[7m` turns on reverse video for exactly the one-cell cursor block,\n * and `ESC[0m` turns it back off.\n *\n * A permissive prefix match such as `(?:\\x1b\\[[0-9;]*m)*` consumes that\n * `ESC[7m` as though it were ordinary leading styling. Whatever is appended\n * next then inherits reverse video, and because the matching `ESC[0m` was\n * left behind in the discarded remainder, the inversion runs on through the\n * placeholder and the rest of the frame. Match the reverse-video run\n * explicitly instead — see {@link CustomEditor.sliceLeadingCursorCell}.\n *\n * ==============================================================================\n */\n\n/**\n * Wrap the visible characters in `[start, end)` with `colorFn`, leaving every\n * control sequence in place.\n *\n * The range is in visible columns, so it is unaffected by however many escape\n * sequences are interleaved. That matters because the cursor cell can land in\n * the middle of the token being coloured: with the caret at column 3 of\n * `/model`, the line reads `/mo` + CURSOR_MARKER + `ESC[7m` + `d` + `ESC[0m` +\n * `el`. Colour is therefore re-opened after every control sequence rather than\n * once around the whole token, since the cursor cell's `ESC[0m` would otherwise\n * cancel it partway through.\n */\nfunction colorVisibleRange(line: string, start: number, end: number, colorFn: (text: string) => string): string {\n\tlet out = \"\";\n\tlet buffer = \"\";\n\tlet column = 0;\n\tlet index = 0;\n\n\tconst flush = () => {\n\t\tif (buffer) {\n\t\t\tout += colorFn(buffer);\n\t\t\tbuffer = \"\";\n\t\t}\n\t};\n\n\twhile (index < line.length) {\n\t\tCONTROL_SEQUENCE.lastIndex = index;\n\t\tconst control = CONTROL_SEQUENCE.exec(line);\n\t\tif (control) {\n\t\t\tflush();\n\t\t\tout += control[0];\n\t\t\tindex = CONTROL_SEQUENCE.lastIndex;\n\t\t\tcontinue;\n\t\t}\n\t\tconst char = line[index];\n\t\tif (column >= start && column < end) {\n\t\t\tbuffer += char;\n\t\t} else {\n\t\t\tflush();\n\t\t\tout += char;\n\t\t}\n\t\tcolumn += visibleWidth(char);\n\t\tindex += 1;\n\t}\n\tflush();\n\treturn out;\n}\n\n/**\n * Custom editor that handles app-level keybindings for coding-agent.\n *\n * The prompt prefix and placeholder are layered on in `render` rather than\n * inside the base Editor, because `packages/tui` is frozen under ADR 0001 and\n * its `EditorOptions` has no hook for either.\n */\nexport class CustomEditor extends Editor {\n\tprivate keybindings: KeybindingsManager;\n\tprivate readonly promptPrefix: string;\n\tprivate readonly promptColor: (text: string) => string;\n\tprivate readonly placeholderColor: (text: string) => string;\n\tprivate readonly commandColor: ((text: string) => string) | undefined;\n\tprivate readonly surfaceColor: ((text: string) => string) | undefined;\n\tprivate readonly placeholder: string | undefined;\n\tprivate readonly autocompleteRule: ((width: number) => string) | undefined;\n\tprivate readonly autocompleteFooter: (() => string) | undefined;\n\tprivate modeLabel = \"\";\n\tpublic actionHandlers: Map<AppKeybinding, () => void> = new Map();\n\n\t// Special handlers that can be dynamically replaced\n\tpublic onEscape?: () => void;\n\tpublic onCtrlD?: () => void;\n\tpublic onPasteImage?: () => void;\n\t/** Handler for extension-registered shortcuts. Returns true if handled. */\n\tpublic onExtensionShortcut?: (data: string) => boolean;\n\n\tconstructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager, options?: CustomEditorOptions) {\n\t\tsuper(tui, theme, options);\n\t\tthis.keybindings = keybindings;\n\t\tthis.promptPrefix = options?.promptPrefix ?? \"\";\n\t\tthis.promptColor = options?.promptColor ?? ((text) => text);\n\t\tthis.placeholder = options?.placeholder;\n\t\tthis.placeholderColor = options?.placeholderColor ?? ((text) => text);\n\t\tthis.commandColor = options?.commandColor;\n\t\tthis.surfaceColor = options?.surfaceColor;\n\t\tthis.autocompleteRule = options?.autocompleteRule;\n\t\tthis.autocompleteFooter = options?.autocompleteFooter;\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst canRenderSurface = this.surfaceColor !== undefined && width > 0;\n\t\tconst surfacePadding = canRenderSurface ? Math.min(SURFACE_PADDING, Math.floor((width - 1) / 2)) : 0;\n\t\tconst editorWidth = canRenderSurface ? width - surfacePadding * 2 : width;\n\t\tconst lines = this.withAutocompleteChrome(this.renderEditor(editorWidth), editorWidth);\n\t\treturn canRenderSurface ? this.withSurface(lines, width, surfacePadding) : lines;\n\t}\n\n\tprivate renderEditor(width: number): string[] {\n\t\tconst promptPrefix = this.modeLabel ? `[${this.modeLabel}] ${this.promptPrefix}` : this.promptPrefix;\n\t\tconst prefixWidth = visibleWidth(promptPrefix);\n\t\t// Reserve the prefix out of the width handed to the base Editor, so its\n\t\t// wrapping, scrolling and cursor column all account for the space the\n\t\t// prefix occupies. Bail out entirely when the terminal cannot spare it.\n\t\tif (prefixWidth === 0 || width <= prefixWidth + 4) {\n\t\t\treturn this.withCommandColor(this.withPlaceholder(super.render(width)));\n\t\t}\n\n\t\tconst inner = this.withCommandColor(this.withPlaceholder(super.render(width - prefixWidth)));\n\t\tconst borderPad = this.borderColor(BORDER_CHAR.repeat(prefixWidth));\n\t\tconst blank = \" \".repeat(prefixWidth);\n\t\tconst styledPrefix = this.promptColor(promptPrefix);\n\n\t\t// Structure is: top border, content lines, bottom border, then optional\n\t\t// autocomplete rows. Counting borders tells the three regions apart\n\t\t// without depending on how many lines each contains.\n\t\tlet borders = 0;\n\t\tlet firstContentLine = true;\n\t\treturn inner.map((line) => {\n\t\t\tif (this.isBorderLine(line)) {\n\t\t\t\tborders++;\n\t\t\t\treturn borderPad + line;\n\t\t\t}\n\t\t\tif (borders !== 1) {\n\t\t\t\t// Autocomplete rows sit below the box; indent them to match.\n\t\t\t\treturn blank + line;\n\t\t\t}\n\t\t\tif (firstContentLine) {\n\t\t\t\tfirstContentLine = false;\n\t\t\t\treturn styledPrefix + line;\n\t\t\t}\n\t\t\treturn blank + line;\n\t\t});\n\t}\n\n\t/**\n\t * Brackets the autocomplete rows with a rule and a keybinding footer.\n\t *\n\t * The rows arrive after the editor's second border, so the same border count\n\t * that separates the box from its dropdown elsewhere in this file finds them\n\t * here. Nothing is added when the dropdown is closed.\n\t */\n\tprivate withAutocompleteChrome(lines: string[], width: number): string[] {\n\t\tif (!this.autocompleteRule && !this.autocompleteFooter) return lines;\n\t\tconst blockLineCount = this.editorBlockLineCount(lines);\n\t\tconst rows = lines.slice(blockLineCount);\n\t\tif (rows.length === 0) return lines;\n\n\t\tconst chrome = [...lines.slice(0, blockLineCount)];\n\t\tif (this.autocompleteRule) chrome.push(this.autocompleteRule(width));\n\t\tchrome.push(...rows);\n\t\tif (this.autocompleteFooter) chrome.push(this.autocompleteFooter());\n\t\treturn chrome;\n\t}\n\n\tprivate withSurface(lines: string[], width: number, padding: number): string[] {\n\t\tconst surfaceColor = this.surfaceColor;\n\t\tif (!surfaceColor) return lines;\n\n\t\tconst result = [this.surfaceLine(\" \".repeat(width), surfaceColor)];\n\t\tconst editorBlockLineCount = this.editorBlockLineCount(lines);\n\t\tconst editorContent = lines.slice(1, Math.max(1, editorBlockLineCount - 1));\n\t\tfor (const line of editorContent) {\n\t\t\tresult.push(this.surfaceLine(`${\" \".repeat(padding)}${line}${\" \".repeat(padding)}`, surfaceColor));\n\t\t}\n\t\tresult.push(this.surfaceLine(\" \".repeat(width), surfaceColor));\n\t\tfor (const line of lines.slice(editorBlockLineCount)) {\n\t\t\tresult.push(`${\" \".repeat(padding)}${line}`);\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate editorBlockLineCount(lines: string[]): number {\n\t\tlet borders = 0;\n\t\tfor (let index = 0; index < lines.length; index++) {\n\t\t\tif (this.isBorderLine(lines[index])) borders++;\n\t\t\tif (borders === 2) return index + 1;\n\t\t}\n\t\treturn lines.length;\n\t}\n\n\tprivate surfaceLine(line: string, surfaceColor: (text: string) => string): string {\n\t\tlet output = \"\";\n\t\tlet visibleText = \"\";\n\t\tlet index = 0;\n\n\t\tconst flush = () => {\n\t\t\tif (visibleText) {\n\t\t\t\toutput += surfaceColor(visibleText);\n\t\t\t\tvisibleText = \"\";\n\t\t\t}\n\t\t};\n\n\t\twhile (index < line.length) {\n\t\t\tINVERTED_CURSOR_CELL.lastIndex = index;\n\t\t\tconst cursorCell = INVERTED_CURSOR_CELL.exec(line);\n\t\t\tif (cursorCell) {\n\t\t\t\tflush();\n\t\t\t\toutput += cursorCell[0];\n\t\t\t\tindex = INVERTED_CURSOR_CELL.lastIndex;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tCONTROL_SEQUENCE.lastIndex = index;\n\t\t\tconst control = CONTROL_SEQUENCE.exec(line);\n\t\t\tif (control) {\n\t\t\t\tflush();\n\t\t\t\toutput += control[0];\n\t\t\t\tindex = CONTROL_SEQUENCE.lastIndex;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvisibleText += line[index];\n\t\t\tindex += 1;\n\t\t}\n\n\t\tflush();\n\t\treturn output;\n\t}\n\n\tsetModeLabel(label: string | undefined): void {\n\t\tthis.modeLabel = label ?? \"\";\n\t\tthis.invalidate();\n\t}\n\n\tprivate isBorderLine(line: string): boolean {\n\t\tconst visible = stripAnsi(line.split(CURSOR_MARKER).join(\"\"));\n\t\treturn BORDER_RULE.test(visible) || BORDER_SCROLL.test(visible);\n\t}\n\n\t/**\n\t * Tint a leading `/command` on the first input line.\n\t *\n\t * The base Editor emits input text unstyled, so the only styling already\n\t * present on the line is the cursor cell — which `colorVisibleRange` steps\n\t * over. Only the command token is tinted; arguments after it stay plain, so\n\t * the highlight marks what is being invoked rather than the whole line.\n\t */\n\tprivate withCommandColor(lines: string[]): string[] {\n\t\tconst commandColor = this.commandColor;\n\t\tif (!commandColor || lines.length < 2) {\n\t\t\treturn lines;\n\t\t}\n\t\t// Read the token from the model rather than the rendered line: the first\n\t\t// visual row is the start of the text only when the caret has not scrolled\n\t\t// the view down, and getText is unambiguous either way.\n\t\tconst firstLine = this.getText().split(\"\\n\", 1)[0] ?? \"\";\n\t\tconst match = COMMAND_TOKEN.exec(firstLine);\n\t\tif (!match) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst [, indent, token] = match;\n\t\t// The rendered row must still begin with that token, or the view has\n\t\t// scrolled and the highlight would land on unrelated text.\n\t\tif (!stripAnsi(lines[1].split(CURSOR_MARKER).join(\"\")).startsWith(`${indent}${token}`)) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst start = visibleWidth(indent);\n\t\tconst updated = [...lines];\n\t\tupdated[1] = colorVisibleRange(lines[1], start, start + visibleWidth(token), commandColor);\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Replace the sole content line with the placeholder while the input is\n\t * empty. Index 1 is always the first content line, and an empty editor has\n\t * exactly one, so no line classification is needed here.\n\t */\n\tprivate withPlaceholder(lines: string[]): string[] {\n\t\tconst placeholder = this.placeholder;\n\t\tif (!placeholder || lines.length < 2 || this.getText().length > 0 || this.isShowingAutocomplete()) {\n\t\t\treturn lines;\n\t\t}\n\t\tconst contentLine = lines[1];\n\t\t// Preserve the cursor cell when focused; unfocused there is none, and the\n\t\t// placeholder simply starts at column zero.\n\t\tconst cursorCell = this.sliceLeadingCursorCell(contentLine);\n\t\t// Measure with visibleWidth alone — never visibleWidth(stripAnsi(...)),\n\t\t// which scores the cursor marker as seven columns. See hazard 1 at the top\n\t\t// of this file.\n\t\tconst available = visibleWidth(contentLine) - visibleWidth(cursorCell);\n\t\tif (available <= 0) {\n\t\t\treturn lines;\n\t\t}\n\t\t// Cut by display width, not by String.slice: `available` counts terminal\n\t\t// columns, while slice counts UTF-16 code units. They only agree for\n\t\t// plain ASCII, and disagreeing splits a surrogate pair or overruns the\n\t\t// line on the first wide character.\n\t\tconst text = truncateToWidth(placeholder, available, \"\");\n\t\tconst padding = \" \".repeat(Math.max(0, available - visibleWidth(text)));\n\t\tconst updated = [...lines];\n\t\tupdated[1] = cursorCell + this.placeholderColor(text) + padding;\n\t\treturn updated;\n\t}\n\n\t/**\n\t * The base Editor renders an empty line as the hardware-cursor marker\n\t * followed by a reverse-video cell: `CURSOR_MARKER ESC[7m <space> ESC[0m`.\n\t * Both parts are kept verbatim.\n\t *\n\t * The `ESC[7m … ESC[0m` run is matched explicitly. Do not \"simplify\" this to\n\t * a general leading-SGR match such as `(?:\\x1b\\[[0-9;]*m)*` — see hazard 2 at\n\t * the top of this file for what that breaks.\n\t */\n\tprivate sliceLeadingCursorCell(line: string): string {\n\t\tconst match = /^(?:\\x1b_pi:c\\x07)?(?:\\x1b\\[7m.\\x1b\\[(?:0|27)m)?/.exec(line);\n\t\treturn match?.[0] ?? \"\";\n\t}\n\n\t/**\n\t * Register a handler for an app action.\n\t */\n\tonAction(action: AppKeybinding, handler: () => void): void {\n\t\tthis.actionHandlers.set(action, handler);\n\t}\n\n\thandleInput(data: string): void {\n\t\t// Check extension-registered shortcuts first\n\t\tif (this.onExtensionShortcut?.(data)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Check for clipboard paste keybinding\n\t\tif (this.keybindings.matches(data, \"app.clipboard.pasteImage\")) {\n\t\t\tthis.onPasteImage?.();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check app keybindings first\n\n\t\t// Escape/interrupt - only if autocomplete is NOT active\n\t\tif (this.keybindings.matches(data, \"app.interrupt\")) {\n\t\t\tif (!this.isShowingAutocomplete()) {\n\t\t\t\t// Use dynamic onEscape if set, otherwise registered handler\n\t\t\t\tconst handler = this.onEscape ?? this.actionHandlers.get(\"app.interrupt\");\n\t\t\t\tif (handler) {\n\t\t\t\t\thandler();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Let parent handle escape for autocomplete cancellation\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Exit (Ctrl+D) - only when editor is empty\n\t\tif (this.keybindings.matches(data, \"app.exit\")) {\n\t\t\tif (this.getText().length === 0) {\n\t\t\t\tconst handler = this.onCtrlD ?? this.actionHandlers.get(\"app.exit\");\n\t\t\t\tif (handler) handler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Fall through to editor handling for delete-char-forward when not empty\n\t\t}\n\n\t\t// Explicit history bindings take precedence over app actions while the editor is focused.\n\t\t// This lets users bind Ctrl+P even though it cycles models by default.\n\t\tif (\n\t\t\tthis.keybindings.matches(data, \"tui.editor.historyPrevious\") ||\n\t\t\tthis.keybindings.matches(data, \"tui.editor.historyNext\")\n\t\t) {\n\t\t\tsuper.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check all other app actions\n\t\tfor (const [action, handler] of this.actionHandlers) {\n\t\t\tif (action !== \"app.interrupt\" && action !== \"app.exit\" && this.keybindings.matches(data, action)) {\n\t\t\t\thandler();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Pass to parent for editor handling\n\t\tsuper.handleInput(data);\n\t}\n}\n"]}
@@ -2,13 +2,19 @@ import type { Component } from "@earendil-works/pi-tui";
2
2
  /**
3
3
  * Dynamic border component that adjusts to viewport width.
4
4
  *
5
+ * It is the boundary every overlay draws, so it is deliberately quiet: a dotted
6
+ * rule in `borderMuted` rather than a solid one in the brand accent. A
7
+ * full-width accent rule above and below every selector made the accent the
8
+ * loudest thing on screen in exactly the moment the user is reading a list.
9
+ *
5
10
  * Note: When used from extensions loaded via jiti, the global `theme` may be undefined
6
11
  * because jiti creates a separate module cache. Always pass an explicit color
7
12
  * function when using DynamicBorder in components exported for extension use.
8
13
  */
9
14
  export declare class DynamicBorder implements Component {
10
15
  private color;
11
- constructor(color?: (str: string) => string);
16
+ private glyph;
17
+ constructor(color?: (str: string) => string, glyph?: string);
12
18
  invalidate(): void;
13
19
  render(width: number): string[];
14
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-border.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/dynamic-border.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGxD;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,KAAK,CAA0B;IAEvC,YAAY,KAAK,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAyC,EAE5E;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;CACD","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Dynamic border component that adjusts to viewport width.\n *\n * Note: When used from extensions loaded via jiti, the global `theme` may be undefined\n * because jiti creates a separate module cache. Always pass an explicit color\n * function when using DynamicBorder in components exported for extension use.\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\n\tconstructor(color: (str: string) => string = (str) => theme.fg(\"border\", str)) {\n\t\tthis.color = color;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(\"─\".repeat(Math.max(1, width)))];\n\t}\n}\n"]}
1
+ {"version":3,"file":"dynamic-border.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/dynamic-border.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMxD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,KAAK,CAAS;IAEtB,YAAY,KAAK,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAA8C,EAAE,KAAK,SAAe,EAGvG;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;CACD","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\n/** Dotted, so an overlay boundary never reads as the solid structural rule. */\nconst OVERLAY_RULE = \"┄\";\n\n/**\n * Dynamic border component that adjusts to viewport width.\n *\n * It is the boundary every overlay draws, so it is deliberately quiet: a dotted\n * rule in `borderMuted` rather than a solid one in the brand accent. A\n * full-width accent rule above and below every selector made the accent the\n * loudest thing on screen in exactly the moment the user is reading a list.\n *\n * Note: When used from extensions loaded via jiti, the global `theme` may be undefined\n * because jiti creates a separate module cache. Always pass an explicit color\n * function when using DynamicBorder in components exported for extension use.\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\tprivate glyph: string;\n\n\tconstructor(color: (str: string) => string = (str) => theme.fg(\"borderMuted\", str), glyph = OVERLAY_RULE) {\n\t\tthis.color = color;\n\t\tthis.glyph = glyph;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(this.glyph.repeat(Math.max(1, width)))];\n\t}\n}\n"]}
@@ -1,21 +1,30 @@
1
1
  import { theme } from "../theme/theme.js";
2
+ /** Dotted, so an overlay boundary never reads as the solid structural rule. */
3
+ const OVERLAY_RULE = "┄";
2
4
  /**
3
5
  * Dynamic border component that adjusts to viewport width.
4
6
  *
7
+ * It is the boundary every overlay draws, so it is deliberately quiet: a dotted
8
+ * rule in `borderMuted` rather than a solid one in the brand accent. A
9
+ * full-width accent rule above and below every selector made the accent the
10
+ * loudest thing on screen in exactly the moment the user is reading a list.
11
+ *
5
12
  * Note: When used from extensions loaded via jiti, the global `theme` may be undefined
6
13
  * because jiti creates a separate module cache. Always pass an explicit color
7
14
  * function when using DynamicBorder in components exported for extension use.
8
15
  */
9
16
  export class DynamicBorder {
10
17
  color;
11
- constructor(color = (str) => theme.fg("border", str)) {
18
+ glyph;
19
+ constructor(color = (str) => theme.fg("borderMuted", str), glyph = OVERLAY_RULE) {
12
20
  this.color = color;
21
+ this.glyph = glyph;
13
22
  }
14
23
  invalidate() {
15
24
  // No cached state to invalidate currently
16
25
  }
17
26
  render(width) {
18
- return [this.color("─".repeat(Math.max(1, width)))];
27
+ return [this.color(this.glyph.repeat(Math.max(1, width)))];
19
28
  }
20
29
  }
21
30
  //# sourceMappingURL=dynamic-border.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-border.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/dynamic-border.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IACjB,KAAK,CAA0B;IAEvC,YAAY,KAAK,GAA4B,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE;QAC9E,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACnB;IAED,UAAU,GAAS;QAClB,0CAA0C;IADvB,CAEnB;IAED,MAAM,CAAC,KAAa,EAAY;QAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAAA,CACpD;CACD","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Dynamic border component that adjusts to viewport width.\n *\n * Note: When used from extensions loaded via jiti, the global `theme` may be undefined\n * because jiti creates a separate module cache. Always pass an explicit color\n * function when using DynamicBorder in components exported for extension use.\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\n\tconstructor(color: (str: string) => string = (str) => theme.fg(\"border\", str)) {\n\t\tthis.color = color;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(\"─\".repeat(Math.max(1, width)))];\n\t}\n}\n"]}
1
+ {"version":3,"file":"dynamic-border.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/dynamic-border.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,YAAY,GAAG,KAAG,CAAC;AAEzB;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IACjB,KAAK,CAA0B;IAC/B,KAAK,CAAS;IAEtB,YAAY,KAAK,GAA4B,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,KAAK,GAAG,YAAY,EAAE;QACzG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACnB;IAED,UAAU,GAAS;QAClB,0CAA0C;IADvB,CAEnB;IAED,MAAM,CAAC,KAAa,EAAY;QAC/B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAAA,CAC3D;CACD","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\n/** Dotted, so an overlay boundary never reads as the solid structural rule. */\nconst OVERLAY_RULE = \"┄\";\n\n/**\n * Dynamic border component that adjusts to viewport width.\n *\n * It is the boundary every overlay draws, so it is deliberately quiet: a dotted\n * rule in `borderMuted` rather than a solid one in the brand accent. A\n * full-width accent rule above and below every selector made the accent the\n * loudest thing on screen in exactly the moment the user is reading a list.\n *\n * Note: When used from extensions loaded via jiti, the global `theme` may be undefined\n * because jiti creates a separate module cache. Always pass an explicit color\n * function when using DynamicBorder in components exported for extension use.\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\tprivate glyph: string;\n\n\tconstructor(color: (str: string) => string = (str) => theme.fg(\"borderMuted\", str), glyph = OVERLAY_RULE) {\n\t\tthis.color = color;\n\t\tthis.glyph = glyph;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(this.glyph.repeat(Math.max(1, width)))];\n\t}\n}\n"]}
@@ -7,9 +7,11 @@ export interface ExtensionSelectorOptions {
7
7
  tui?: TUI;
8
8
  timeout?: number;
9
9
  onToggleToolsExpanded?: () => void;
10
+ enableSearch?: boolean;
10
11
  }
11
12
  export declare class ExtensionSelectorComponent extends Container {
12
13
  private options;
14
+ private filteredOptions;
13
15
  private selectedIndex;
14
16
  private listContainer;
15
17
  private onSelectCallback;
@@ -18,8 +20,10 @@ export declare class ExtensionSelectorComponent extends Container {
18
20
  private baseTitle;
19
21
  private countdown;
20
22
  private onToggleToolsExpanded;
23
+ private searchInput;
21
24
  constructor(title: string, options: string[], onSelect: (option: string) => void, onCancel: () => void, opts?: ExtensionSelectorOptions);
22
25
  private updateList;
26
+ private filterOptions;
23
27
  handleInput(keyData: string): void;
24
28
  dispose(): void;
25
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extension-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/extension-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAgC,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAM3F,MAAM,WAAW,wBAAwB;IACxC,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACnC;AAED,qBAAa,0BAA2B,SAAQ,SAAS;IACxD,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,qBAAqB,CAA2B;IAExD,YACC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EAClC,QAAQ,EAAE,MAAM,IAAI,EACpB,IAAI,CAAC,EAAE,wBAAwB,EA4C/B;IAED,OAAO,CAAC,UAAU;IAWlB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAgBjC;IAED,OAAO,IAAI,IAAI,CAEd;CACD","sourcesContent":["/**\n * Generic selector component for extensions.\n * Displays a list of string options with keyboard navigation.\n */\n\nimport { Container, getKeybindings, Spacer, Text, type TUI } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\nimport { CountdownTimer } from \"./countdown-timer.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport interface ExtensionSelectorOptions {\n\ttui?: TUI;\n\ttimeout?: number;\n\tonToggleToolsExpanded?: () => void;\n}\n\nexport class ExtensionSelectorComponent extends Container {\n\tprivate options: string[];\n\tprivate selectedIndex = 0;\n\tprivate listContainer: Container;\n\tprivate onSelectCallback: (option: string) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate titleText: Text;\n\tprivate baseTitle: string;\n\tprivate countdown: CountdownTimer | undefined;\n\tprivate onToggleToolsExpanded: (() => void) | undefined;\n\n\tconstructor(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\tonSelect: (option: string) => void,\n\t\tonCancel: () => void,\n\t\topts?: ExtensionSelectorOptions,\n\t) {\n\t\tsuper();\n\n\t\tthis.options = options;\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\t\tthis.onToggleToolsExpanded = opts?.onToggleToolsExpanded;\n\t\tthis.baseTitle = title;\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.titleText = new Text(theme.fg(\"accent\", theme.bold(title)), 1, 0);\n\t\tthis.addChild(this.titleText);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tif (opts?.timeout && opts.timeout > 0 && opts.tui) {\n\t\t\tthis.countdown = new CountdownTimer(\n\t\t\t\topts.timeout,\n\t\t\t\topts.tui,\n\t\t\t\t(s) => this.titleText.setText(theme.fg(\"accent\", theme.bold(`${this.baseTitle} (${s}s)`))),\n\t\t\t\t() => this.onCancelCallback(),\n\t\t\t);\n\t\t}\n\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"select\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"cancel\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tfor (let i = 0; i < this.options.length; i++) {\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst text = isSelected\n\t\t\t\t? theme.fg(\"accent\", \"→ \") + theme.fg(\"accent\", this.options[i])\n\t\t\t\t: ` ${theme.fg(\"text\", this.options[i])}`;\n\t\t\tthis.listContainer.addChild(new Text(text, 1, 0));\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"app.tools.expand\")) {\n\t\t\tthis.onToggleToolsExpanded?.();\n\t\t} else if (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.selectedIndex = Math.min(this.options.length - 1, this.selectedIndex + 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tconst selected = this.options[this.selectedIndex];\n\t\t\tif (selected) this.onSelectCallback(selected);\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.countdown?.dispose();\n\t}\n}\n"]}
1
+ {"version":3,"file":"extension-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/extension-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAoD,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAM/G,MAAM,WAAW,wBAAwB;IACxC,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,0BAA2B,SAAQ,SAAS;IACxD,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,qBAAqB,CAA2B;IACxD,OAAO,CAAC,WAAW,CAAoB;IAEvC,YACC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EAClC,QAAQ,EAAE,MAAM,IAAI,EACpB,IAAI,CAAC,EAAE,wBAAwB,EAkD/B;IAED,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,aAAa;IAOrB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAmBjC;IAED,OAAO,IAAI,IAAI,CAEd;CACD","sourcesContent":["/**\n * Generic selector component for extensions.\n * Displays a list of string options with keyboard navigation.\n */\n\nimport { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text, type TUI } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\nimport { CountdownTimer } from \"./countdown-timer.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport interface ExtensionSelectorOptions {\n\ttui?: TUI;\n\ttimeout?: number;\n\tonToggleToolsExpanded?: () => void;\n\tenableSearch?: boolean;\n}\n\nexport class ExtensionSelectorComponent extends Container {\n\tprivate options: string[];\n\tprivate filteredOptions: string[];\n\tprivate selectedIndex = 0;\n\tprivate listContainer: Container;\n\tprivate onSelectCallback: (option: string) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate titleText: Text;\n\tprivate baseTitle: string;\n\tprivate countdown: CountdownTimer | undefined;\n\tprivate onToggleToolsExpanded: (() => void) | undefined;\n\tprivate searchInput: Input | undefined;\n\n\tconstructor(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\tonSelect: (option: string) => void,\n\t\tonCancel: () => void,\n\t\topts?: ExtensionSelectorOptions,\n\t) {\n\t\tsuper();\n\n\t\tthis.options = options;\n\t\tthis.filteredOptions = options;\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\t\tthis.onToggleToolsExpanded = opts?.onToggleToolsExpanded;\n\t\tthis.baseTitle = title;\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.titleText = new Text(theme.fg(\"accent\", theme.bold(title)), 1, 0);\n\t\tthis.addChild(this.titleText);\n\t\tthis.addChild(new Spacer(1));\n\t\tif (opts?.enableSearch) {\n\t\t\tthis.searchInput = new Input();\n\t\t\tthis.addChild(this.searchInput);\n\t\t\tthis.addChild(new Spacer(1));\n\t\t}\n\n\t\tif (opts?.timeout && opts.timeout > 0 && opts.tui) {\n\t\t\tthis.countdown = new CountdownTimer(\n\t\t\t\topts.timeout,\n\t\t\t\topts.tui,\n\t\t\t\t(s) => this.titleText.setText(theme.fg(\"accent\", theme.bold(`${this.baseTitle} (${s}s)`))),\n\t\t\t\t() => this.onCancelCallback(),\n\t\t\t);\n\t\t}\n\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"select\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"cancel\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tfor (let i = 0; i < this.filteredOptions.length; i++) {\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst text = isSelected\n\t\t\t\t? theme.fg(\"accent\", \"→ \") + theme.fg(\"accent\", this.filteredOptions[i])\n\t\t\t\t: ` ${theme.fg(\"text\", this.filteredOptions[i])}`;\n\t\t\tthis.listContainer.addChild(new Text(text, 1, 0));\n\t\t}\n\t}\n\n\tprivate filterOptions(): void {\n\t\tconst query = this.searchInput?.getValue() ?? \"\";\n\t\tthis.filteredOptions = query ? fuzzyFilter(this.options, query, (option) => option) : this.options;\n\t\tthis.selectedIndex = 0;\n\t\tthis.updateList();\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"app.tools.expand\")) {\n\t\t\tthis.onToggleToolsExpanded?.();\n\t\t} else if (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.selectedIndex = Math.min(this.filteredOptions.length - 1, this.selectedIndex + 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tconst selected = this.filteredOptions[this.selectedIndex];\n\t\t\tif (selected) this.onSelectCallback(selected);\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t} else if (this.searchInput) {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterOptions();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.countdown?.dispose();\n\t}\n}\n"]}
@@ -2,13 +2,14 @@
2
2
  * Generic selector component for extensions.
3
3
  * Displays a list of string options with keyboard navigation.
4
4
  */
5
- import { Container, getKeybindings, Spacer, Text } from "@earendil-works/pi-tui";
5
+ import { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text } from "@earendil-works/pi-tui";
6
6
  import { theme } from "../theme/theme.js";
7
7
  import { CountdownTimer } from "./countdown-timer.js";
8
8
  import { DynamicBorder } from "./dynamic-border.js";
9
9
  import { keyHint, rawKeyHint } from "./keybinding-hints.js";
10
10
  export class ExtensionSelectorComponent extends Container {
11
11
  options;
12
+ filteredOptions;
12
13
  selectedIndex = 0;
13
14
  listContainer;
14
15
  onSelectCallback;
@@ -17,9 +18,11 @@ export class ExtensionSelectorComponent extends Container {
17
18
  baseTitle;
18
19
  countdown;
19
20
  onToggleToolsExpanded;
21
+ searchInput;
20
22
  constructor(title, options, onSelect, onCancel, opts) {
21
23
  super();
22
24
  this.options = options;
25
+ this.filteredOptions = options;
23
26
  this.onSelectCallback = onSelect;
24
27
  this.onCancelCallback = onCancel;
25
28
  this.onToggleToolsExpanded = opts?.onToggleToolsExpanded;
@@ -29,6 +32,11 @@ export class ExtensionSelectorComponent extends Container {
29
32
  this.titleText = new Text(theme.fg("accent", theme.bold(title)), 1, 0);
30
33
  this.addChild(this.titleText);
31
34
  this.addChild(new Spacer(1));
35
+ if (opts?.enableSearch) {
36
+ this.searchInput = new Input();
37
+ this.addChild(this.searchInput);
38
+ this.addChild(new Spacer(1));
39
+ }
32
40
  if (opts?.timeout && opts.timeout > 0 && opts.tui) {
33
41
  this.countdown = new CountdownTimer(opts.timeout, opts.tui, (s) => this.titleText.setText(theme.fg("accent", theme.bold(`${this.baseTitle} (${s}s)`))), () => this.onCancelCallback());
34
42
  }
@@ -46,14 +54,20 @@ export class ExtensionSelectorComponent extends Container {
46
54
  }
47
55
  updateList() {
48
56
  this.listContainer.clear();
49
- for (let i = 0; i < this.options.length; i++) {
57
+ for (let i = 0; i < this.filteredOptions.length; i++) {
50
58
  const isSelected = i === this.selectedIndex;
51
59
  const text = isSelected
52
- ? theme.fg("accent", "→ ") + theme.fg("accent", this.options[i])
53
- : ` ${theme.fg("text", this.options[i])}`;
60
+ ? theme.fg("accent", "→ ") + theme.fg("accent", this.filteredOptions[i])
61
+ : ` ${theme.fg("text", this.filteredOptions[i])}`;
54
62
  this.listContainer.addChild(new Text(text, 1, 0));
55
63
  }
56
64
  }
65
+ filterOptions() {
66
+ const query = this.searchInput?.getValue() ?? "";
67
+ this.filteredOptions = query ? fuzzyFilter(this.options, query, (option) => option) : this.options;
68
+ this.selectedIndex = 0;
69
+ this.updateList();
70
+ }
57
71
  handleInput(keyData) {
58
72
  const kb = getKeybindings();
59
73
  if (kb.matches(keyData, "app.tools.expand")) {
@@ -64,17 +78,21 @@ export class ExtensionSelectorComponent extends Container {
64
78
  this.updateList();
65
79
  }
66
80
  else if (kb.matches(keyData, "tui.select.down") || keyData === "j") {
67
- this.selectedIndex = Math.min(this.options.length - 1, this.selectedIndex + 1);
81
+ this.selectedIndex = Math.min(this.filteredOptions.length - 1, this.selectedIndex + 1);
68
82
  this.updateList();
69
83
  }
70
84
  else if (kb.matches(keyData, "tui.select.confirm") || keyData === "\n") {
71
- const selected = this.options[this.selectedIndex];
85
+ const selected = this.filteredOptions[this.selectedIndex];
72
86
  if (selected)
73
87
  this.onSelectCallback(selected);
74
88
  }
75
89
  else if (kb.matches(keyData, "tui.select.cancel")) {
76
90
  this.onCancelCallback();
77
91
  }
92
+ else if (this.searchInput) {
93
+ this.searchInput.handleInput(keyData);
94
+ this.filterOptions();
95
+ }
78
96
  }
79
97
  dispose() {
80
98
  this.countdown?.dispose();
@@ -1 +1 @@
1
- {"version":3,"file":"extension-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/extension-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAY,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAE,KAAK,EAA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IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClD,IAAI,QAAQ;gBAAE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACzB,CAAC;IAAA,CACD;IAED,OAAO,GAAS;QACf,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;IAAA,CAC1B;CACD","sourcesContent":["/**\n * Generic selector component for extensions.\n * Displays a list of string options with keyboard navigation.\n */\n\nimport { Container, getKeybindings, Spacer, Text, type TUI } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\nimport { CountdownTimer } from \"./countdown-timer.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport interface ExtensionSelectorOptions {\n\ttui?: TUI;\n\ttimeout?: number;\n\tonToggleToolsExpanded?: () => void;\n}\n\nexport class ExtensionSelectorComponent extends Container {\n\tprivate options: string[];\n\tprivate selectedIndex = 0;\n\tprivate listContainer: Container;\n\tprivate onSelectCallback: (option: string) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate titleText: Text;\n\tprivate baseTitle: string;\n\tprivate countdown: CountdownTimer | undefined;\n\tprivate onToggleToolsExpanded: (() => void) | undefined;\n\n\tconstructor(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\tonSelect: (option: string) => void,\n\t\tonCancel: () => void,\n\t\topts?: ExtensionSelectorOptions,\n\t) {\n\t\tsuper();\n\n\t\tthis.options = options;\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\t\tthis.onToggleToolsExpanded = opts?.onToggleToolsExpanded;\n\t\tthis.baseTitle = title;\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.titleText = new Text(theme.fg(\"accent\", theme.bold(title)), 1, 0);\n\t\tthis.addChild(this.titleText);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tif (opts?.timeout && opts.timeout > 0 && opts.tui) {\n\t\t\tthis.countdown = new CountdownTimer(\n\t\t\t\topts.timeout,\n\t\t\t\topts.tui,\n\t\t\t\t(s) => this.titleText.setText(theme.fg(\"accent\", theme.bold(`${this.baseTitle} (${s}s)`))),\n\t\t\t\t() => this.onCancelCallback(),\n\t\t\t);\n\t\t}\n\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"select\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"cancel\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tfor (let i = 0; i < this.options.length; i++) {\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst text = isSelected\n\t\t\t\t? theme.fg(\"accent\", \"→ \") + theme.fg(\"accent\", this.options[i])\n\t\t\t\t: ` ${theme.fg(\"text\", this.options[i])}`;\n\t\t\tthis.listContainer.addChild(new Text(text, 1, 0));\n\t\t}\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"app.tools.expand\")) {\n\t\t\tthis.onToggleToolsExpanded?.();\n\t\t} else if (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.selectedIndex = Math.min(this.options.length - 1, this.selectedIndex + 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tconst selected = this.options[this.selectedIndex];\n\t\t\tif (selected) this.onSelectCallback(selected);\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.countdown?.dispose();\n\t}\n}\n"]}
1
+ {"version":3,"file":"extension-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/extension-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAY,MAAM,wBAAwB,CAAC;AAC/G,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAS5D,MAAM,OAAO,0BAA2B,SAAQ,SAAS;IAChD,OAAO,CAAW;IAClB,eAAe,CAAW;IAC1B,aAAa,GAAG,CAAC,CAAC;IAClB,aAAa,CAAY;IACzB,gBAAgB,CAA2B;IAC3C,gBAAgB,CAAa;IAC7B,SAAS,CAAO;IAChB,SAAS,CAAS;IAClB,SAAS,CAA6B;IACtC,qBAAqB,CAA2B;IAChD,WAAW,CAAoB;IAEvC,YACC,KAAa,EACb,OAAiB,EACjB,QAAkC,EACl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tE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;YACvF,IAAI,CAAC,UAAU,EAAE,CAAC;QACnB,CAAC;aAAM,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC1D,IAAI,QAAQ;gBAAE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACzB,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACtC,IAAI,CAAC,aAAa,EAAE,CAAC;QACtB,CAAC;IAAA,CACD;IAED,OAAO,GAAS;QACf,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;IAAA,CAC1B;CACD","sourcesContent":["/**\n * Generic selector component for extensions.\n * Displays a list of string options with keyboard navigation.\n */\n\nimport { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text, type TUI } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\nimport { CountdownTimer } from \"./countdown-timer.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport interface ExtensionSelectorOptions {\n\ttui?: TUI;\n\ttimeout?: number;\n\tonToggleToolsExpanded?: () => void;\n\tenableSearch?: boolean;\n}\n\nexport class ExtensionSelectorComponent extends Container {\n\tprivate options: string[];\n\tprivate filteredOptions: string[];\n\tprivate selectedIndex = 0;\n\tprivate listContainer: Container;\n\tprivate onSelectCallback: (option: string) => void;\n\tprivate onCancelCallback: () => void;\n\tprivate titleText: Text;\n\tprivate baseTitle: string;\n\tprivate countdown: CountdownTimer | undefined;\n\tprivate onToggleToolsExpanded: (() => void) | undefined;\n\tprivate searchInput: Input | undefined;\n\n\tconstructor(\n\t\ttitle: string,\n\t\toptions: string[],\n\t\tonSelect: (option: string) => void,\n\t\tonCancel: () => void,\n\t\topts?: ExtensionSelectorOptions,\n\t) {\n\t\tsuper();\n\n\t\tthis.options = options;\n\t\tthis.filteredOptions = options;\n\t\tthis.onSelectCallback = onSelect;\n\t\tthis.onCancelCallback = onCancel;\n\t\tthis.onToggleToolsExpanded = opts?.onToggleToolsExpanded;\n\t\tthis.baseTitle = title;\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.titleText = new Text(theme.fg(\"accent\", theme.bold(title)), 1, 0);\n\t\tthis.addChild(this.titleText);\n\t\tthis.addChild(new Spacer(1));\n\t\tif (opts?.enableSearch) {\n\t\t\tthis.searchInput = new Input();\n\t\t\tthis.addChild(this.searchInput);\n\t\t\tthis.addChild(new Spacer(1));\n\t\t}\n\n\t\tif (opts?.timeout && opts.timeout > 0 && opts.tui) {\n\t\t\tthis.countdown = new CountdownTimer(\n\t\t\t\topts.timeout,\n\t\t\t\topts.tui,\n\t\t\t\t(s) => this.titleText.setText(theme.fg(\"accent\", theme.bold(`${this.baseTitle} (${s}s)`))),\n\t\t\t\t() => this.onCancelCallback(),\n\t\t\t);\n\t\t}\n\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"select\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"cancel\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.updateList();\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tfor (let i = 0; i < this.filteredOptions.length; i++) {\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst text = isSelected\n\t\t\t\t? theme.fg(\"accent\", \"→ \") + theme.fg(\"accent\", this.filteredOptions[i])\n\t\t\t\t: ` ${theme.fg(\"text\", this.filteredOptions[i])}`;\n\t\t\tthis.listContainer.addChild(new Text(text, 1, 0));\n\t\t}\n\t}\n\n\tprivate filterOptions(): void {\n\t\tconst query = this.searchInput?.getValue() ?? \"\";\n\t\tthis.filteredOptions = query ? fuzzyFilter(this.options, query, (option) => option) : this.options;\n\t\tthis.selectedIndex = 0;\n\t\tthis.updateList();\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"app.tools.expand\")) {\n\t\t\tthis.onToggleToolsExpanded?.();\n\t\t} else if (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.selectedIndex = Math.min(this.filteredOptions.length - 1, this.selectedIndex + 1);\n\t\t\tthis.updateList();\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tconst selected = this.filteredOptions[this.selectedIndex];\n\t\t\tif (selected) this.onSelectCallback(selected);\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.onCancelCallback();\n\t\t} else if (this.searchInput) {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterOptions();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.countdown?.dispose();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"first-time-setup.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/first-time-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AAGjF,OAAO,EAAE,KAAK,aAAa,EAAS,MAAM,mBAAmB,CAAC;AAI9D,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IACnD,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACjD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB;AASD,6CAA6C;AAC7C,qBAAa,uBAAwB,SAAQ,SAAS;IACrD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAEhD,YAAY,OAAO,EAAE,qBAAqB,EAQzC;IAGD,OAAO,CAAC,MAAM;IAmCd,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;IASrB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAWjC;CACD","sourcesContent":["import { Container, getKeybindings, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../../config.ts\";\nimport { APEX_PEAK_LOGO_COMPACT } from \"../../../themes/apex-logo.ts\";\nimport { type TerminalTheme, theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\nexport interface FirstTimeSetupResult {\n\ttheme: TerminalTheme;\n}\n\nexport interface FirstTimeSetupOptions {\n\tdetectedTheme: TerminalTheme;\n\tonThemePreview: (themeName: TerminalTheme) => void;\n\tonSubmit: (result: FirstTimeSetupResult) => void;\n\tonCancel: () => void;\n}\n\nconst THEME_OPTIONS: Array<{ value: TerminalTheme; label: string }> = [\n\t{ value: \"dark\", label: \"Dark\" },\n\t{ value: \"light\", label: \"Light\" },\n];\n\nconst SETUP_LOGO_LINES = APEX_PEAK_LOGO_COMPACT.split(\"\\n\");\n\n/** First-time setup dialog: theme choice. */\nexport class FirstTimeSetupComponent extends Container {\n\tprivate themeIndex: number;\n\tprivate readonly options: FirstTimeSetupOptions;\n\n\tconstructor(options: FirstTimeSetupOptions) {\n\t\tsuper();\n\t\tthis.options = options;\n\t\tthis.themeIndex = Math.max(\n\t\t\t0,\n\t\t\tTHEME_OPTIONS.findIndex((option) => option.value === options.detectedTheme),\n\t\t);\n\t\tthis.update();\n\t}\n\n\t// Rebuild the whole dialog on every change so theme previews recolor all text.\n\tprivate update(): void {\n\t\tthis.clear();\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", SETUP_LOGO_LINES.join(\"\\n\")), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"accent\", theme.bold(`Welcome to ${APP_NAME}, the minimal coding agent.`)), 1, 0),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.addChild(new Text(theme.fg(\"text\", \"Pick a theme.\"), 1, 0));\n\t\tthis.addChild(new Text(theme.fg(\"muted\", `Detected system appearance: ${this.options.detectedTheme}`), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addOptionList(\n\t\t\tTHEME_OPTIONS.map((option) => option.label),\n\t\t\tthis.themeIndex,\n\t\t);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"finish\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"skip setup\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tprivate addOptionList(labels: string[], selectedIndex: number): void {\n\t\tfor (let i = 0; i < labels.length; i++) {\n\t\t\tconst isSelected = i === selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst label = isSelected ? theme.fg(\"accent\", labels[i]) : theme.fg(\"text\", labels[i]);\n\t\t\tthis.addChild(new Text(`${prefix}${label}`, 1, 0));\n\t\t}\n\t}\n\n\tprivate moveSelection(delta: number): void {\n\t\tconst next = Math.max(0, Math.min(THEME_OPTIONS.length - 1, this.themeIndex + delta));\n\t\tif (next !== this.themeIndex) {\n\t\t\tthis.themeIndex = next;\n\t\t\tthis.options.onThemePreview(THEME_OPTIONS[this.themeIndex].value);\n\t\t}\n\t\tthis.update();\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.moveSelection(-1);\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.moveSelection(1);\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tthis.options.onSubmit({ theme: THEME_OPTIONS[this.themeIndex].value });\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.options.onCancel();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"first-time-setup.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/first-time-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AAGjF,OAAO,EAAE,KAAK,aAAa,EAAS,MAAM,mBAAmB,CAAC;AAK9D,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IACnD,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACjD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB;AAOD,6CAA6C;AAC7C,qBAAa,uBAAwB,SAAQ,SAAS;IACrD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAEhD,YAAY,OAAO,EAAE,qBAAqB,EAQzC;IAGD,OAAO,CAAC,MAAM;IAsCd,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;IASrB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAWjC;CACD","sourcesContent":["import { Container, getKeybindings, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../../config.ts\";\nimport { APEX_MARK_BLOCK } from \"../../../themes/apex-logo.ts\";\nimport { type TerminalTheme, theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\nimport { paintBrandMark } from \"./splash-header.ts\";\n\nexport interface FirstTimeSetupResult {\n\ttheme: TerminalTheme;\n}\n\nexport interface FirstTimeSetupOptions {\n\tdetectedTheme: TerminalTheme;\n\tonThemePreview: (themeName: TerminalTheme) => void;\n\tonSubmit: (result: FirstTimeSetupResult) => void;\n\tonCancel: () => void;\n}\n\nconst THEME_OPTIONS: Array<{ value: TerminalTheme; label: string }> = [\n\t{ value: \"dark\", label: \"Dark\" },\n\t{ value: \"light\", label: \"Light\" },\n];\n\n/** First-time setup dialog: theme choice. */\nexport class FirstTimeSetupComponent extends Container {\n\tprivate themeIndex: number;\n\tprivate readonly options: FirstTimeSetupOptions;\n\n\tconstructor(options: FirstTimeSetupOptions) {\n\t\tsuper();\n\t\tthis.options = options;\n\t\tthis.themeIndex = Math.max(\n\t\t\t0,\n\t\t\tTHEME_OPTIONS.findIndex((option) => option.value === options.detectedTheme),\n\t\t);\n\t\tthis.update();\n\t}\n\n\t// Rebuild the whole dialog on every change so theme previews recolor all text.\n\tprivate update(): void {\n\t\tthis.clear();\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\t// The same mark the splash header stamps, so a new user's first two screens\n\t\t// agree. Painted here rather than at module load: theme.fg throws until\n\t\t// initTheme has run, and this module is imported from the CLI entry point.\n\t\tthis.addChild(new Text(paintBrandMark(APEX_MARK_BLOCK).join(\"\\n\"), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"accent\", theme.bold(`Welcome to ${APP_NAME}, the minimal coding agent.`)), 1, 0),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.addChild(new Text(theme.fg(\"text\", \"Pick a theme.\"), 1, 0));\n\t\tthis.addChild(new Text(theme.fg(\"muted\", `Detected system appearance: ${this.options.detectedTheme}`), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addOptionList(\n\t\t\tTHEME_OPTIONS.map((option) => option.label),\n\t\t\tthis.themeIndex,\n\t\t);\n\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\trawKeyHint(\"↑↓\", \"navigate\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.confirm\", \"finish\") +\n\t\t\t\t\t\" \" +\n\t\t\t\t\tkeyHint(\"tui.select.cancel\", \"skip setup\"),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tprivate addOptionList(labels: string[], selectedIndex: number): void {\n\t\tfor (let i = 0; i < labels.length; i++) {\n\t\t\tconst isSelected = i === selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst label = isSelected ? theme.fg(\"accent\", labels[i]) : theme.fg(\"text\", labels[i]);\n\t\t\tthis.addChild(new Text(`${prefix}${label}`, 1, 0));\n\t\t}\n\t}\n\n\tprivate moveSelection(delta: number): void {\n\t\tconst next = Math.max(0, Math.min(THEME_OPTIONS.length - 1, this.themeIndex + delta));\n\t\tif (next !== this.themeIndex) {\n\t\t\tthis.themeIndex = next;\n\t\t\tthis.options.onThemePreview(THEME_OPTIONS[this.themeIndex].value);\n\t\t}\n\t\tthis.update();\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(keyData, \"tui.select.up\") || keyData === \"k\") {\n\t\t\tthis.moveSelection(-1);\n\t\t} else if (kb.matches(keyData, \"tui.select.down\") || keyData === \"j\") {\n\t\t\tthis.moveSelection(1);\n\t\t} else if (kb.matches(keyData, \"tui.select.confirm\") || keyData === \"\\n\") {\n\t\t\tthis.options.onSubmit({ theme: THEME_OPTIONS[this.themeIndex].value });\n\t\t} else if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\tthis.options.onCancel();\n\t\t}\n\t}\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  import { Container, getKeybindings, Spacer, Text } from "@earendil-works/pi-tui";
2
2
  import { APP_NAME } from "../../../config.js";
3
- import { APEX_PEAK_LOGO_COMPACT } from "../../../themes/apex-logo.js";
3
+ import { APEX_MARK_BLOCK } from "../../../themes/apex-logo.js";
4
4
  import { theme } from "../theme/theme.js";
5
5
  import { DynamicBorder } from "./dynamic-border.js";
6
6
  import { keyHint, rawKeyHint } from "./keybinding-hints.js";
7
+ import { paintBrandMark } from "./splash-header.js";
7
8
  const THEME_OPTIONS = [
8
9
  { value: "dark", label: "Dark" },
9
10
  { value: "light", label: "Light" },
10
11
  ];
11
- const SETUP_LOGO_LINES = APEX_PEAK_LOGO_COMPACT.split("\n");
12
12
  /** First-time setup dialog: theme choice. */
13
13
  export class FirstTimeSetupComponent extends Container {
14
14
  themeIndex;
@@ -24,7 +24,10 @@ export class FirstTimeSetupComponent extends Container {
24
24
  this.clear();
25
25
  this.addChild(new DynamicBorder());
26
26
  this.addChild(new Spacer(1));
27
- this.addChild(new Text(theme.fg("accent", SETUP_LOGO_LINES.join("\n")), 1, 0));
27
+ // The same mark the splash header stamps, so a new user's first two screens
28
+ // agree. Painted here rather than at module load: theme.fg throws until
29
+ // initTheme has run, and this module is imported from the CLI entry point.
30
+ this.addChild(new Text(paintBrandMark(APEX_MARK_BLOCK).join("\n"), 1, 0));
28
31
  this.addChild(new Spacer(1));
29
32
  this.addChild(new Text(theme.fg("accent", theme.bold(`Welcome to ${APP_NAME}, the minimal coding agent.`)), 1, 0));
30
33
  this.addChild(new Spacer(1));