bom-pi 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +33 -2
  2. package/apps/README.md +7 -0
  3. package/apps/web/README.md +21 -0
  4. package/apps/web/pocket-adapter.mjs +323 -0
  5. package/apps/web/public/LICENSE.pocket +21 -0
  6. package/apps/web/public/activity-fold.js +28 -0
  7. package/apps/web/public/agent-now.js +37 -0
  8. package/apps/web/public/agent-tile.js +79 -0
  9. package/apps/web/public/app.js +975 -0
  10. package/apps/web/public/apple-touch-icon.png +0 -0
  11. package/apps/web/public/artifact-bridge.js +687 -0
  12. package/apps/web/public/avatar.js +87 -0
  13. package/apps/web/public/back.js +554 -0
  14. package/apps/web/public/box-keys.js +216 -0
  15. package/apps/web/public/browser-panel.js +1097 -0
  16. package/apps/web/public/browser.js +68 -0
  17. package/apps/web/public/calls.js +139 -0
  18. package/apps/web/public/chat.js +919 -0
  19. package/apps/web/public/clock.js +34 -0
  20. package/apps/web/public/commands.js +578 -0
  21. package/apps/web/public/composer.js +2068 -0
  22. package/apps/web/public/diff-parse.js +672 -0
  23. package/apps/web/public/diff.js +1646 -0
  24. package/apps/web/public/dock.js +299 -0
  25. package/apps/web/public/extension-ui.js +2734 -0
  26. package/apps/web/public/files-panel.js +775 -0
  27. package/apps/web/public/files.js +368 -0
  28. package/apps/web/public/fonts/FiraCode-VF.woff2 +0 -0
  29. package/apps/web/public/fonts/Geist.woff2 +0 -0
  30. package/apps/web/public/fonts/IBMPlexMono-Variable-Italic.woff2 +0 -0
  31. package/apps/web/public/fonts/IBMPlexMono-Variable.woff2 +0 -0
  32. package/apps/web/public/fonts/InterVariable-Italic.woff2 +0 -0
  33. package/apps/web/public/fonts/InterVariable.woff2 +0 -0
  34. package/apps/web/public/fonts/Iosevka-Bold.woff2 +0 -0
  35. package/apps/web/public/fonts/Iosevka-BoldItalic.woff2 +0 -0
  36. package/apps/web/public/fonts/Iosevka-Italic.woff2 +0 -0
  37. package/apps/web/public/fonts/Iosevka-Regular.woff2 +0 -0
  38. package/apps/web/public/fonts/Iosevka-SemiBold.woff2 +0 -0
  39. package/apps/web/public/fonts/Iosevka-SemiBoldItalic.woff2 +0 -0
  40. package/apps/web/public/fonts/JetBrainsMono-Italic.woff2 +0 -0
  41. package/apps/web/public/fonts/JetBrainsMono.woff2 +0 -0
  42. package/apps/web/public/fonts/NerdFontsSymbolsMono.woff2 +0 -0
  43. package/apps/web/public/fonts/SOURCES.md +69 -0
  44. package/apps/web/public/gestures.js +610 -0
  45. package/apps/web/public/highlight.js +480 -0
  46. package/apps/web/public/history.js +70 -0
  47. package/apps/web/public/home.js +169 -0
  48. package/apps/web/public/icon-192.png +0 -0
  49. package/apps/web/public/icon-512.png +0 -0
  50. package/apps/web/public/icon-maskable-512.png +0 -0
  51. package/apps/web/public/icon.svg +16 -0
  52. package/apps/web/public/index.html +71 -0
  53. package/apps/web/public/launcher.js +1293 -0
  54. package/apps/web/public/linked-sessions.js +55 -0
  55. package/apps/web/public/live.js +39 -0
  56. package/apps/web/public/manifest.webmanifest +32 -0
  57. package/apps/web/public/model-refresh.js +73 -0
  58. package/apps/web/public/notify.js +251 -0
  59. package/apps/web/public/peeks.js +920 -0
  60. package/apps/web/public/pip-attachments.js +182 -0
  61. package/apps/web/public/pip-window.js +141 -0
  62. package/apps/web/public/pip.js +1217 -0
  63. package/apps/web/public/quote-reply.js +109 -0
  64. package/apps/web/public/quote-text.js +31 -0
  65. package/apps/web/public/rich.js +403 -0
  66. package/apps/web/public/run-frame.js +106 -0
  67. package/apps/web/public/safe-mode.js +71 -0
  68. package/apps/web/public/seen.js +169 -0
  69. package/apps/web/public/session-tree.js +117 -0
  70. package/apps/web/public/sessions.js +2695 -0
  71. package/apps/web/public/share.js +126 -0
  72. package/apps/web/public/sheets/appearance.js +820 -0
  73. package/apps/web/public/sheets/branch.js +353 -0
  74. package/apps/web/public/sheets/extensions.js +818 -0
  75. package/apps/web/public/sheets/file.js +318 -0
  76. package/apps/web/public/sheets/find.js +250 -0
  77. package/apps/web/public/sheets/folder.js +680 -0
  78. package/apps/web/public/sheets/gallery.js +2340 -0
  79. package/apps/web/public/sheets/hooks.js +350 -0
  80. package/apps/web/public/sheets/memory.js +531 -0
  81. package/apps/web/public/sheets/menu.js +580 -0
  82. package/apps/web/public/sheets/message.js +220 -0
  83. package/apps/web/public/sheets/model.js +412 -0
  84. package/apps/web/public/sheets/people.js +414 -0
  85. package/apps/web/public/sheets/pi-sessions.js +264 -0
  86. package/apps/web/public/sheets/providers.js +525 -0
  87. package/apps/web/public/sheets/running.js +130 -0
  88. package/apps/web/public/sheets/schedules.js +71 -0
  89. package/apps/web/public/sheets/session.js +249 -0
  90. package/apps/web/public/sheets/shortcuts.js +101 -0
  91. package/apps/web/public/sheets/spend.js +150 -0
  92. package/apps/web/public/sheets/text.js +53 -0
  93. package/apps/web/public/sheets/viewers.js +363 -0
  94. package/apps/web/public/sheets/worktree.js +50 -0
  95. package/apps/web/public/sheets.js +410 -0
  96. package/apps/web/public/signin.js +57 -0
  97. package/apps/web/public/slots.js +208 -0
  98. package/apps/web/public/store.js +1760 -0
  99. package/apps/web/public/style.css +18625 -0
  100. package/apps/web/public/subagents-board.js +879 -0
  101. package/apps/web/public/subagents.js +273 -0
  102. package/apps/web/public/sw.js +169 -0
  103. package/apps/web/public/taps.js +26 -0
  104. package/apps/web/public/theme-surface.d.ts +4 -0
  105. package/apps/web/public/theme-surface.js +266 -0
  106. package/apps/web/public/theme.js +845 -0
  107. package/apps/web/public/themes/lantern/colors.toml +25 -0
  108. package/apps/web/public/themes/lantern/direction.css +60 -0
  109. package/apps/web/public/themes/lantern/frame.css +254 -0
  110. package/apps/web/public/themes/lantern/theme.css +10 -0
  111. package/apps/web/public/themes/lantern/theme.json +7 -0
  112. package/apps/web/public/themes/pocket/theme.css +189 -0
  113. package/apps/web/public/themes/pocket/theme.json +6 -0
  114. package/apps/web/public/themes.js +556 -0
  115. package/apps/web/public/transcript.js +3348 -0
  116. package/apps/web/public/trust.js +295 -0
  117. package/apps/web/public/turns.js +507 -0
  118. package/apps/web/public/ui.js +1910 -0
  119. package/apps/web/public/voice.js +345 -0
  120. package/apps/web/server.mjs +774 -0
  121. package/package.json +43 -4
  122. package/packages/cli/src/bom-pi.mjs +452 -0
  123. package/packages/cli/templates/blank.factory.json +7 -0
  124. package/packages/cli/templates/dev.factory.json +11 -0
  125. package/packages/cli/templates/docs.factory.json +12 -0
  126. package/packages/cli/templates/ops.factory.json +14 -0
  127. package/packages/cli/templates/triage.factory.json +10 -0
  128. package/packages/core/src/daemon.mjs +2047 -0
  129. package/packages/core/src/limit-gate.mjs +192 -0
  130. package/packages/core/src/rpc-client.mjs +66 -0
  131. package/systemd/README.md +11 -0
@@ -0,0 +1,1293 @@
1
+ // The launcher, after Omarchy's Walker: one box for sessions, actions, and themes. Mod+K opens it anywhere. Arrowing
2
+ // onto a theme shows it at once; Enter keeps it, Escape goes back. Start with > for actions only, @ for sessions, # for
3
+ // themes.
4
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
5
+ import { browserAvailable, toggleBrowser } from "./browser.js";
6
+ import { folderColor } from "./avatar.js";
7
+ import {
8
+ planAvailable,
9
+ schedulesAvailable,
10
+ triggersOn,
11
+ watchAvailable,
12
+ watchPr,
13
+ } from "./commands.js";
14
+ import { extensionLauncherItems, sessionWords } from "./extension-ui.js";
15
+ import { filesAvailable, toggleFiles } from "./files-panel.js";
16
+ import { useDragToClose } from "./gestures.js";
17
+ import { togglePeeks } from "./peeks.js";
18
+ import { modelRefreshAvailable, refreshModels } from "./model-refresh.js";
19
+ import { openPip, pipAvailable } from "./pip.js";
20
+ import { setArchived, toggleBoard } from "./sessions.js";
21
+ import { branchAvailable, headLabel } from "./sheets/branch.js";
22
+ import { recentLabels } from "./sheets/folder.js";
23
+ import { galleryAvailable } from "./sheets/gallery.js";
24
+ import { memoryAvailable } from "./sheets/memory.js";
25
+ import { piSessionsAvailable } from "./sheets/pi-sessions.js";
26
+ import {
27
+ actions,
28
+ attempt,
29
+ api,
30
+ canSteer,
31
+ canToggleTurns,
32
+ collab,
33
+ navigate,
34
+ notify,
35
+ openSheet,
36
+ scoped,
37
+ sessionOrder,
38
+ setUnread,
39
+ signOut,
40
+ store,
41
+ workspaceOrder,
42
+ } from "./store.js";
43
+ import {
44
+ BASE_LOOK,
45
+ chooseLook,
46
+ folderPaletteIds,
47
+ isPinned,
48
+ lookIds,
49
+ paletteOf,
50
+ prefs,
51
+ preview,
52
+ setPrefs,
53
+ themeIds,
54
+ themeVars,
55
+ togglePin,
56
+ varsStyle,
57
+ } from "./theme.js";
58
+ import { trustAvailable } from "./trust.js";
59
+ import {
60
+ APPLE,
61
+ BOTTOM_SHEETS,
62
+ copyText,
63
+ html,
64
+ Icon,
65
+ Keys,
66
+ Marked,
67
+ scrimPress,
68
+ shortPath,
69
+ timeAgo,
70
+ } from "./ui.js";
71
+
72
+ /** How far a letter that does not begin a word may be from the one before it, in a match that is not contiguous. */
73
+ const MAX_GAP = 3;
74
+
75
+ /**
76
+ * How well `query` matches `text` as a subsequence: null for no match, else a score (higher is better) and the matched
77
+ * places. Runs of letters, letters at word starts, and an early first letter count for more. Letters scattered through a
78
+ * text must stay close (within a few characters) or begin a word, so "files" does not match "fix the login loop".
79
+ */
80
+ function fuzzy(text, query) {
81
+ if (query === "") {
82
+ return { score: 0, hits: [] };
83
+ }
84
+
85
+ const hay = text.toLowerCase();
86
+ const plain = hay.indexOf(query);
87
+
88
+ if (plain !== -1) {
89
+ const start = plain === 0 || /[\s/._-]/.test(hay[plain - 1]);
90
+
91
+ return {
92
+ score: 100 + query.length * 4 - plain + (start ? 30 : 0),
93
+ hits: Array.from({ length: query.length }, (_, index) => plain + index),
94
+ };
95
+ }
96
+
97
+ const hits = [];
98
+ let score = 0;
99
+ let from = 0;
100
+
101
+ for (const char of query) {
102
+ if (char === " ") {
103
+ continue;
104
+ }
105
+
106
+ const at = hay.indexOf(char, from);
107
+
108
+ if (at === -1) {
109
+ return null;
110
+ }
111
+
112
+ const run = hits.length > 0 && hits[hits.length - 1] === at - 1;
113
+ const start = at === 0 || /[\s/._-]/.test(hay[at - 1]);
114
+
115
+ if (hits.length > 0 && !start && at - from > MAX_GAP) {
116
+ return null;
117
+ }
118
+
119
+ score += 1 + (run ? 5 : 0) + (start ? 8 : 0) - Math.min(at - from, 10) * 0.3;
120
+ hits.push(at);
121
+ from = at + 1;
122
+ }
123
+
124
+ return { score, hits };
125
+ }
126
+
127
+ /** The actions that make sense here, as launcher items. */
128
+ function actionItems() {
129
+ const { view, conversationId, me, folderFavorites, server } = store.state;
130
+ const conversation = conversationId !== null ? view.conversation : null;
131
+ const session = conversation?.kind === "session";
132
+ const steer = canSteer();
133
+ // While take turns is on, the session's settings are the driver's (as in the menu).
134
+ const driving = !view.turns?.on || view.turns.driver === me?.id;
135
+ const canStart = steer && !scoped();
136
+ // The folder a session starts in "here": the one the open session works in. Issue #96, reported by @poncardasm.
137
+ const here = view.agent?.cwd ?? conversation?.cwd ?? null;
138
+ // As the folder picker names them: folders of one name get their parent's too.
139
+ const favoriteNames = recentLabels(folderFavorites, server?.home);
140
+ const wide = matchMedia("(min-width: 960px)").matches;
141
+ const list = [
142
+ canStart && {
143
+ label: "New session",
144
+ icon: "plus",
145
+ keys: "Alt N",
146
+ run: () => openSheet({ type: "cwd", mode: "new" }),
147
+ },
148
+ canStart &&
149
+ here !== null && {
150
+ label: "New session here",
151
+ detail: shortPath(here, server?.home),
152
+ keywords: "in this folder",
153
+ icon: "plus",
154
+ run: () =>
155
+ attempt(async () => {
156
+ const created = await actions.createSession(here);
157
+
158
+ navigate(created.id);
159
+ }),
160
+ },
161
+ piSessionsAvailable() && {
162
+ label: "Continue a Pi session",
163
+ detail: "from Pi in the terminal",
164
+ icon: "terminal",
165
+ run: () => openSheet({ type: "pi-sessions" }),
166
+ },
167
+ conversationId !== null && {
168
+ label: "All sessions",
169
+ detail: "home",
170
+ icon: "home",
171
+ run: () => navigate(null),
172
+ },
173
+ wide && {
174
+ label: prefs().sidebar === "rail" ? "Unfold the sidebar" : "Fold the sidebar",
175
+ icon: "sidebar",
176
+ keys: "Mod B",
177
+ run: () => setPrefs({ sidebar: prefs().sidebar === "rail" ? "open" : "rail" }),
178
+ },
179
+ {
180
+ label: "Appearance",
181
+ detail: "theme, colors, tiling, motion, text size, thinking, reply speed",
182
+ icon: "palette",
183
+ run: () => openSheet({ type: "appearance" }),
184
+ },
185
+ wide && {
186
+ label: prefs().tiling ? "Turn tiling off" : "Turn tiling on",
187
+ detail: "gaps and window borders",
188
+ icon: "swatch",
189
+ run: () => setPrefs({ tiling: !prefs().tiling }),
190
+ },
191
+ {
192
+ label: prefs().peeks ? "Hide peek tiles" : "Show peek tiles",
193
+ detail: "Peeks: other sessions' live work beside this one",
194
+ icon: "tiles",
195
+ keys: "Alt P",
196
+ run: togglePeeks,
197
+ },
198
+ {
199
+ label: prefs().showThinking ? "Hide thinking" : "Show thinking",
200
+ detail: "Pi's thoughts above the live line and in the conversation",
201
+ icon: "sparkle",
202
+ keys: "Alt T",
203
+ run: () => setPrefs({ showThinking: !prefs().showThinking }),
204
+ },
205
+ {
206
+ label: prefs().speed ? "Hide reply speed" : "Show reply speed",
207
+ detail: "how fast the last answer came, under the message box",
208
+ icon: "pulse",
209
+ run: () => setPrefs({ speed: !prefs().speed }),
210
+ },
211
+ conversation &&
212
+ steer && {
213
+ label: "Switch model",
214
+ icon: "sparkle",
215
+ run: () => openSheet({ type: "model" }),
216
+ },
217
+ store.state.me?.role === "owner" &&
218
+ store.state.server?.defaultModel !== undefined && {
219
+ label: "Default model",
220
+ detail: "owner default first; otherwise project, last picked, then Pi global",
221
+ icon: "sparkle",
222
+ run: () => openSheet({ type: "model", id: "default", forDefault: true }),
223
+ },
224
+ conversation &&
225
+ browserAvailable() && {
226
+ label: store.state.browserOpen ? "Close the browser" : "Open the browser",
227
+ detail: "see and test pages with Pi",
228
+ icon: "globe",
229
+ keys: "Alt B",
230
+ run: toggleBrowser,
231
+ },
232
+ conversation && {
233
+ label: "Artifacts",
234
+ icon: "artifact",
235
+ run: () => openSheet({ type: "artifacts" }),
236
+ },
237
+ conversation &&
238
+ filesAvailable() && {
239
+ label:
240
+ store.state.filesOpen && store.state.filesTab === "files"
241
+ ? "Close the files"
242
+ : "Files",
243
+ detail: "browse the folder, read files",
244
+ icon: "folder",
245
+ keys: "Alt E",
246
+ run: () => toggleFiles("files"),
247
+ },
248
+ conversation &&
249
+ filesAvailable() && {
250
+ label: "Changes",
251
+ detail: "review what changed, file by file",
252
+ keywords: "diff",
253
+ icon: "fork",
254
+ run: () => toggleFiles("changes"),
255
+ },
256
+ conversation &&
257
+ branchAvailable() && {
258
+ label: "Switch branch",
259
+ detail: `on ${headLabel(view.branch)}`,
260
+ icon: "fork",
261
+ run: () => openSheet({ type: "branch" }),
262
+ },
263
+ conversation &&
264
+ collab() && {
265
+ label: "Chat with people here",
266
+ icon: "chat",
267
+ run: () => openSheet({ type: "chat" }),
268
+ },
269
+ conversation && {
270
+ label: "Find in this session",
271
+ detail: "messages, by words",
272
+ keywords: "search",
273
+ icon: "search",
274
+ keys: "Mod F",
275
+ run: () => openSheet({ type: "find" }),
276
+ },
277
+ conversation &&
278
+ collab() &&
279
+ canToggleTurns() && {
280
+ label: view.turns?.on ? "Turn off take turns" : "Take turns",
281
+ detail: view.turns?.on
282
+ ? "anyone here can send to Pi again"
283
+ : "one person drives Pi at a time",
284
+ icon: "users",
285
+ run: () => attempt(() => actions.turns(view.turns?.on ? "off" : "on")),
286
+ },
287
+ session &&
288
+ steer && {
289
+ label: "Rename session",
290
+ icon: "sparkle",
291
+ run: () => openSheet({ type: "rename" }),
292
+ },
293
+ session &&
294
+ steer &&
295
+ planAvailable() && {
296
+ label: view.plan?.on ? "Turn plan mode off" : "Turn plan mode on",
297
+ detail: "Pi proposes, changes nothing",
298
+ icon: "shield",
299
+ run: () => attempt(() => actions.setPlan(!view.plan?.on)),
300
+ },
301
+ session && {
302
+ label: isPinned(conversation.id) ? "Unpin from the top" : "Pin to the top",
303
+ detail: "this browser",
304
+ icon: "pin",
305
+ run: () => togglePin(conversation.id),
306
+ },
307
+ session && {
308
+ label: "Mark unread",
309
+ detail: "this browser; opening it again clears it",
310
+ icon: "chat",
311
+ run: () => {
312
+ setUnread(conversation.id, true);
313
+ navigate(null);
314
+ },
315
+ },
316
+ conversation?.worktree && steer
317
+ ? {
318
+ label: "Worktree",
319
+ detail: conversation.worktree.branch,
320
+ keywords: "git branch",
321
+ icon: "fork",
322
+ run: () => openSheet({ type: "worktree" }),
323
+ }
324
+ : conversation &&
325
+ steer &&
326
+ driving &&
327
+ !scoped() && {
328
+ label: "Working directory",
329
+ detail: shortPath(view.agent?.cwd, server?.home),
330
+ keywords: "folder cwd",
331
+ icon: "folder",
332
+ run: () => openSheet({ type: "cwd", mode: "change" }),
333
+ },
334
+ conversation &&
335
+ trustAvailable() && {
336
+ label: "Project trust",
337
+ detail: "the project's own skills and model settings",
338
+ icon: "shield",
339
+ run: () => openSheet({ type: "trust" }),
340
+ },
341
+ session &&
342
+ steer &&
343
+ driving && {
344
+ label: "Instructions for Pi",
345
+ detail: view.agent?.instructions ? "on" : "none",
346
+ keywords: "prompt system",
347
+ icon: "sparkle",
348
+ run: () => openSheet({ type: "instructions" }),
349
+ },
350
+ conversation &&
351
+ steer &&
352
+ driving && {
353
+ label: "Compact context",
354
+ detail: "summarize older messages",
355
+ icon: "sparkle",
356
+ run: () => openSheet({ type: "compact" }),
357
+ },
358
+ conversation &&
359
+ steer &&
360
+ driving && {
361
+ label: "New context",
362
+ detail: "Pi starts fresh; history stays",
363
+ keywords: "reset clear",
364
+ icon: "reload",
365
+ run: () => openSheet({ type: "reset" }),
366
+ },
367
+ conversation &&
368
+ memoryAvailable() && {
369
+ label: "Memory",
370
+ detail: "lessons Pi keeps across sessions",
371
+ icon: "sparkle",
372
+ run: () => openSheet({ type: "memory" }),
373
+ },
374
+ watchAvailable() &&
375
+ steer &&
376
+ view.watch?.status !== "watching" && {
377
+ label: "Watch pull request",
378
+ detail: "fix CI, answer reviews",
379
+ keywords: "github pr",
380
+ icon: "fork",
381
+ run: () => attempt(() => watchPr()),
382
+ },
383
+ conversation && {
384
+ label: "Export as Markdown",
385
+ detail: "the whole history",
386
+ keywords: "download",
387
+ icon: "external",
388
+ run: () => {
389
+ const link = document.createElement("a");
390
+
391
+ link.href = `/api/c/${conversation.id}/export`;
392
+ link.download = "";
393
+ link.click();
394
+ },
395
+ },
396
+ schedulesAvailable() && {
397
+ label: "Scheduled messages",
398
+ icon: "pulse",
399
+ run: () => openSheet({ type: "schedules" }),
400
+ },
401
+ conversation && {
402
+ label: "Copy link to this session",
403
+ icon: "external",
404
+ run: () => copyText(location.href).then(() => notify("info", "Link copied.")),
405
+ },
406
+ conversation && {
407
+ label: "Session menu",
408
+ icon: "more",
409
+ run: () => openSheet({ type: "menu" }),
410
+ },
411
+ session &&
412
+ steer && {
413
+ label: conversation.archived ? "Unarchive session" : "Archive session",
414
+ icon: "archive",
415
+ run: () => setArchived([conversation.id], !conversation.archived),
416
+ },
417
+ pipAvailable() && {
418
+ label: "Ask PiP",
419
+ detail: "your assistant, over any screen",
420
+ icon: "pip",
421
+ keys: "Alt A",
422
+ run: () => openPip(),
423
+ },
424
+ {
425
+ label: "Running now",
426
+ detail: "everything Pi is doing",
427
+ icon: "pulse",
428
+ run: () => openSheet({ type: "running" }),
429
+ },
430
+ {
431
+ label: store.state.board ? "Close the subagents board" : "Subagents",
432
+ detail: "subagents in every session",
433
+ icon: "fork",
434
+ run: toggleBoard,
435
+ },
436
+ collab() && {
437
+ label: "Notifications",
438
+ detail: "Pi finished, approvals, chat",
439
+ icon: "pulse",
440
+ run: () => openSheet({ type: "notifications" }),
441
+ },
442
+ triggersOn() &&
443
+ me?.role !== "viewer" && {
444
+ label: "Webhooks and watches",
445
+ detail: "GitHub, other services",
446
+ keywords: "hooks triggers watch pull request",
447
+ icon: "external",
448
+ run: () => openSheet({ type: "hooks" }),
449
+ },
450
+ me?.role === "owner" && {
451
+ label: "Providers",
452
+ detail: "sign in to model providers",
453
+ icon: "key",
454
+ run: () => openSheet({ type: "providers" }),
455
+ },
456
+ modelRefreshAvailable() && {
457
+ label: "Refresh models",
458
+ detail: store.state.modelRefresh.loading
459
+ ? "refresh in progress"
460
+ : "reload configured models and check providers",
461
+ icon: "reload",
462
+ run: refreshModels,
463
+ },
464
+ { label: "Extensions", icon: "shield", run: () => openSheet({ type: "extensions" }) },
465
+ galleryAvailable() && {
466
+ label: "Find extensions",
467
+ detail: "browse and install drop-ins",
468
+ keywords: "gallery",
469
+ icon: "search",
470
+ run: () => openSheet({ type: "gallery" }),
471
+ },
472
+ { label: "Spend", icon: "pulse", run: () => openSheet({ type: "spend" }) },
473
+ collab()
474
+ ? {
475
+ label: "People and invites",
476
+ icon: "users",
477
+ run: () => openSheet({ type: "people" }),
478
+ }
479
+ : {
480
+ label: "Sign in another device",
481
+ icon: "users",
482
+ run: () => openSheet({ type: "invite" }),
483
+ },
484
+ {
485
+ label: "Keyboard shortcuts",
486
+ icon: "keyboard",
487
+ keys: "?",
488
+ run: () => openSheet({ type: "shortcuts" }),
489
+ },
490
+ {
491
+ label: "Your name",
492
+ detail: me?.name,
493
+ icon: "users",
494
+ run: () => openSheet({ type: "name" }),
495
+ },
496
+ me?.role === "owner" &&
497
+ server?.supervised && {
498
+ label: "Restart server",
499
+ detail: "running work resumes",
500
+ icon: "reload",
501
+ run: () =>
502
+ attempt(async () => {
503
+ await api("restart", {});
504
+ notify("info", "Restarting. Running work continues after the restart.");
505
+ }),
506
+ },
507
+ { label: "Sign out", detail: "this browser", icon: "logout", run: signOut },
508
+ // What extensions' browser modules added (`extension-ui.js`).
509
+ ...extensionLauncherItems(),
510
+ // Last: a list that is cut keeps the actions above, however many favorites there are (up to 100).
511
+ ...(canStart
512
+ ? folderFavorites.map((path, index) => ({
513
+ key: `action:new-favorite:${path}`,
514
+ label: `New session in ${favoriteNames[index]}`,
515
+ detail: shortPath(path, server?.home),
516
+ icon: "star",
517
+ run: () =>
518
+ attempt(async () => {
519
+ const created = await actions.createSession(path);
520
+
521
+ navigate(created.id);
522
+ }),
523
+ }))
524
+ : []),
525
+ ];
526
+
527
+ return list.filter(Boolean).map((item) => ({
528
+ ...item,
529
+ kind: "action",
530
+ key: item.key ?? `action:${item.label}`,
531
+ text: `${item.label} ${item.detail ?? ""} ${item.keywords ?? ""}`,
532
+ }));
533
+ }
534
+
535
+ function sessionItems() {
536
+ const { sessions, server } = store.state;
537
+ // Every session, folded ones too; the numbers are Alt's, which skip what a fold hides.
538
+ const order = sessionOrder();
539
+ const archived = sessions.filter((session) => session.archived);
540
+ const numbers = new Map(workspaceOrder().map((session, index) => [session.id, index]));
541
+
542
+ return [...order, ...archived].map((session) => {
543
+ const number = numbers.get(session.id) ?? -1;
544
+ // Words extensions give it (`pocket.sessionSearch`), such as tags: matched after the title and folder.
545
+ const words = sessionWords(session);
546
+
547
+ return {
548
+ kind: "session",
549
+ key: `session:${session.id}`,
550
+ label: session.title ?? "New session",
551
+ detail: shortPath(session.cwd, server?.home),
552
+ status:
553
+ [
554
+ session.id === store.state.conversationId ? "Current" : null,
555
+ session.waiting ? "Waiting" : session.busy ? "Working" : null,
556
+ session.archived ? "Archived" : null,
557
+ ]
558
+ .filter(Boolean)
559
+ .join(" · ") || timeAgo(session.updatedAt),
560
+ text: `${session.title ?? "New session"} ${shortPath(session.cwd, server?.home)}${words.length > 0 ? ` ${words.join(" ")}` : ""}`,
561
+ words,
562
+ keys: number >= 0 && number < 9 ? `Alt ${number + 1}` : undefined,
563
+ rank: session.archived ? -20 : -number * 0.01,
564
+ run: () => navigate(session.id),
565
+ folder: folderColor(session.cwd),
566
+ tone: session.waiting ? "waiting" : session.busy ? "working" : "quiet",
567
+ };
568
+ });
569
+ }
570
+
571
+ /** Theme folders that change the look, as launcher items: no preview (their stylesheets load when chosen). */
572
+ function lookItems() {
573
+ const vars = themeVars(paletteOf());
574
+
575
+ return lookIds()
576
+ .map(
577
+ (id) =>
578
+ store.state.themeList?.find((each) => each.id === id && each.usable) ??
579
+ (id === BASE_LOOK ? { id, name: "Pocket", builtIn: true } : null),
580
+ )
581
+ .filter(Boolean)
582
+ .map((look) => ({
583
+ kind: "theme",
584
+ key: `look:${look.id}`,
585
+ label: look.name,
586
+ detail: look.builtIn ? "theme, built in" : "theme",
587
+ text: `theme ${look.name} ${look.id}`,
588
+ look: look.id,
589
+ vars,
590
+ }));
591
+ }
592
+
593
+ function themeItems() {
594
+ const desktop = store.state.desktopTheme;
595
+ const ids = [...(desktop ? ["desktop"] : []), ...themeIds(), ...folderPaletteIds()];
596
+
597
+ return [
598
+ ...lookItems(),
599
+ ...ids.map((id) => {
600
+ const palette = paletteOf(id);
601
+ const name = id === "desktop" ? `Desktop · ${palette.name}` : palette.name;
602
+
603
+ return {
604
+ kind: "theme",
605
+ key: `theme:${id}`,
606
+ label: name,
607
+ detail:
608
+ id === "desktop"
609
+ ? "follows your Omarchy theme"
610
+ : palette.colors.mode === "light"
611
+ ? "light"
612
+ : "dark",
613
+ text: `theme ${name} ${id}`,
614
+ theme: id,
615
+ vars: themeVars(palette),
616
+ };
617
+ }),
618
+ ];
619
+ }
620
+
621
+ const GROUP_NAMES = { session: "Sessions", action: "Actions", theme: "Themes" };
622
+ const PREFIXES = { ">": "action", "@": "session", "#": "theme" };
623
+
624
+ /** Hits in one displayed field, without changing the text or score used by the fuzzy matcher. */
625
+ function fieldHits(hits, start, length) {
626
+ return hits.filter((at) => at >= start && at < start + length).map((at) => at - start);
627
+ }
628
+
629
+ /** Keep the distinguishing end of a long folder path; a match in the hidden prefix uses the full path instead. */
630
+ function resultDetail(item, hits) {
631
+ const text = item.detail ?? "";
632
+
633
+ if (item.kind !== "session") {
634
+ return { text, hits };
635
+ }
636
+
637
+ const end = text.lastIndexOf("/");
638
+ const start = text.lastIndexOf("/", end - 1) + 1;
639
+
640
+ if (text.length < 32 || start < 3 || hits.some((at) => at < start)) {
641
+ return { text, hits };
642
+ }
643
+
644
+ const prefix = text.startsWith("~/") ? "~/…/" : text.startsWith("/") ? "/…/" : "…/";
645
+
646
+ return {
647
+ text: prefix + text.slice(start),
648
+ hits: hits.map((at) => prefix.length + at - start),
649
+ };
650
+ }
651
+
652
+ const optionId = (item) => `launcher-option-${encodeURIComponent(item.key)}`;
653
+
654
+ export function Launcher({ leaving, returnTo }) {
655
+ const [query, setQuery] = useState("");
656
+ const [pick, setPick] = useState(0);
657
+ const [announcement, setAnnouncement] = useState("");
658
+ const input = useRef(null);
659
+ const list = useRef(null);
660
+ const dialog = useRef(null);
661
+ const chosen = useRef(false);
662
+
663
+ // Phones: a sheet from the bottom edge, which drags back down to close, as the app's other sheets do.
664
+ useDragToClose(dialog, {
665
+ dir: "down",
666
+ onClose: () => store.set({ launcher: false }),
667
+ enabled: BOTTOM_SHEETS.matches,
668
+ });
669
+
670
+ const prefix = PREFIXES[query[0]];
671
+ const needle = (prefix ? query.slice(1) : query).trim().toLowerCase();
672
+ const { sessions, view, conversationId } = store.state;
673
+
674
+ const groups = useMemo(() => {
675
+ const all = [
676
+ ...(prefix === undefined || prefix === "session" ? sessionItems() : []),
677
+ ...(prefix === undefined || prefix === "action" ? actionItems() : []),
678
+ ...(prefix === undefined || prefix === "theme" ? themeItems() : []),
679
+ ];
680
+ const scored = [];
681
+
682
+ for (const item of all) {
683
+ const match = fuzzy(item.text, needle);
684
+
685
+ if (!match) {
686
+ continue;
687
+ }
688
+
689
+ // Themes' scorer text begins with "theme ", not with their displayed label.
690
+ const hits = fieldHits(match.hits, item.kind === "theme" ? 6 : 0, item.label.length);
691
+ const detailHits =
692
+ item.kind === "theme"
693
+ ? []
694
+ : fieldHits(match.hits, item.label.length + 1, (item.detail ?? "").length);
695
+ const detail = resultDetail(item, detailHits);
696
+ const matchNote =
697
+ match.hits.length > 0 && hits.length === 0 && detailHits.length === 0
698
+ ? item.kind === "theme"
699
+ ? "Theme name or ID match"
700
+ : (item.words?.find((word) => word.includes(needle)) ?? "Keyword match")
701
+ : null;
702
+
703
+ scored.push({
704
+ ...item,
705
+ score: match.score + (item.rank ?? 0),
706
+ hits,
707
+ fullDetail: item.detail,
708
+ detail,
709
+ matchNote,
710
+ });
711
+ }
712
+
713
+ const byKind = new Map();
714
+
715
+ for (const item of scored) {
716
+ if (!byKind.has(item.kind)) {
717
+ byKind.set(item.kind, []);
718
+ }
719
+
720
+ byKind.get(item.kind).push(item);
721
+ }
722
+
723
+ const out = [...byKind.entries()].map(([kind, items]) => {
724
+ if (needle !== "") {
725
+ items.sort((a, b) => b.score - a.score);
726
+ }
727
+
728
+ const limit =
729
+ needle === "" && prefix === undefined ? (kind === "session" ? 6 : 99) : 40;
730
+
731
+ return {
732
+ kind,
733
+ items: items.slice(0, limit),
734
+ total: items.length,
735
+ best: items[0]?.score ?? 0,
736
+ };
737
+ });
738
+
739
+ // Preserve group-first ranking: with a query the best group's matches come first.
740
+ if (needle !== "") {
741
+ out.sort((a, b) => b.best - a.best);
742
+ }
743
+
744
+ return out;
745
+ }, [
746
+ needle,
747
+ prefix,
748
+ sessions,
749
+ view.conversation,
750
+ view.agent?.cwd,
751
+ view.plan?.on,
752
+ view.branch,
753
+ conversationId,
754
+ store.state.pinned,
755
+ store.state.browserOpen,
756
+ store.state.filesOpen,
757
+ store.state.filesTab,
758
+ store.state.desktopTheme,
759
+ store.state.appearance,
760
+ store.state.me,
761
+ store.state.server,
762
+ store.state.folderFavorites,
763
+ store.state.extensionsRev,
764
+ ]);
765
+
766
+ const flat = useMemo(() => groups.flatMap((group) => group.items), [groups]);
767
+ const index = Math.min(pick, Math.max(0, flat.length - 1));
768
+ const selected = flat[index];
769
+ const recent =
770
+ needle === "" && prefix === undefined
771
+ ? groups.find((group) => group.kind === "session")
772
+ : null;
773
+
774
+ const limitedRecent = recent && recent.total > recent.items.length;
775
+
776
+ // Focus after inert is removed, not in a pending passive effect. LauncherHost keys every logical opening,
777
+ // including a same-task reopen, so query, selection, and the theme commit flag cannot leak across openings.
778
+ // Issue #62, reported by @arunsathiya.
779
+ useLayoutEffect(() => {
780
+ if (leaving) {
781
+ return;
782
+ }
783
+
784
+ const overlay = input.current?.closest(".launcher-overlay");
785
+ const parent = overlay?.parentElement;
786
+ const blocked = new Map();
787
+ // Touch screens: the launcher takes focus, not its field, so no keyboard covers the results; a tap on the
788
+ // field brings it up. As Sheet does.
789
+ const home = matchMedia("(pointer: coarse)").matches ? dialog.current : input.current;
790
+
791
+ const restore = (child, { attribute, value }) => {
792
+ if (value === null) {
793
+ child.removeAttribute(attribute);
794
+ } else {
795
+ child.setAttribute(attribute, value);
796
+ }
797
+ };
798
+
799
+ const rememberOwners = (records) => {
800
+ for (const record of records) {
801
+ const owner = blocked.get(record.target);
802
+
803
+ if (record.type === "attributes" && record.attributeName === owner?.attribute) {
804
+ owner.value = record.target.getAttribute(owner.attribute);
805
+ }
806
+ }
807
+ };
808
+
809
+ const isolate = (records = []) => {
810
+ rememberOwners([...records, ...owners.takeRecords()]);
811
+ // Do not observe our own isolation writes. Retained layers can change their state while blocked.
812
+ owners.disconnect();
813
+
814
+ for (const record of records) {
815
+ for (const child of record.removedNodes) {
816
+ if (blocked.has(child)) {
817
+ restore(child, blocked.get(child));
818
+ blocked.delete(child);
819
+ }
820
+ }
821
+ }
822
+
823
+ for (const child of parent?.children ?? []) {
824
+ if (child === overlay || child.classList.contains("launcher-overlay")) {
825
+ continue;
826
+ }
827
+
828
+ if (!blocked.has(child)) {
829
+ // Native inert is costly on a sidebar with thousands of controls. The large primary windows
830
+ // are hidden from AT instead; the overlay and focus guard block pointer and keyboard access.
831
+ const attribute = child.matches(".sidebar, .pane") ? "aria-hidden" : "inert";
832
+
833
+ blocked.set(child, { attribute, value: child.getAttribute(attribute) });
834
+ }
835
+
836
+ const { attribute } = blocked.get(child);
837
+
838
+ child.setAttribute(attribute, attribute === "aria-hidden" ? "true" : "");
839
+ owners.observe(child, { attributes: true, attributeFilter: [attribute] });
840
+ }
841
+ };
842
+
843
+ const keepFocus = (event) => {
844
+ if (!overlay?.contains(event.target)) {
845
+ home?.focus({ preventScroll: true });
846
+ }
847
+ };
848
+
849
+ const owners = new MutationObserver(isolate);
850
+ const observer = new MutationObserver(isolate);
851
+
852
+ // Move focus out before hiding its old ancestor from AT (Chromium rejects aria-hidden on focused content).
853
+ document.addEventListener("focusin", keepFocus);
854
+ home?.focus({ preventScroll: true });
855
+ isolate();
856
+
857
+ if (parent) {
858
+ observer.observe(parent, { childList: true });
859
+ }
860
+
861
+ return () => {
862
+ rememberOwners(owners.takeRecords());
863
+ observer.disconnect();
864
+ owners.disconnect();
865
+ document.removeEventListener("focusin", keepFocus);
866
+
867
+ for (const [child, owner] of blocked) {
868
+ restore(child, owner);
869
+ }
870
+ };
871
+ }, [leaving]);
872
+ useEffect(
873
+ () => () => {
874
+ if (!chosen.current) {
875
+ preview(null);
876
+ }
877
+
878
+ const active = document.activeElement;
879
+ const lost =
880
+ active === null ||
881
+ active === document.body ||
882
+ active === input.current ||
883
+ active === dialog.current;
884
+ const sheet = document.querySelector(".sheet-host:not(.leaving) .sheet");
885
+ const back = sheet?.contains(returnTo) ? returnTo : (sheet ?? returnTo);
886
+
887
+ // A new launcher or a destination that already took focus keeps it.
888
+ if (
889
+ !store.state.launcher &&
890
+ lost &&
891
+ back?.isConnected &&
892
+ typeof back.focus === "function"
893
+ ) {
894
+ back.focus({ preventScroll: true });
895
+ }
896
+ },
897
+ [],
898
+ );
899
+ useEffect(() => {
900
+ if (leaving) {
901
+ if (!chosen.current) {
902
+ preview(null);
903
+ }
904
+
905
+ return;
906
+ }
907
+
908
+ preview(selected?.kind === "theme" && selected.theme ? selected.theme : null);
909
+ }, [selected?.key, leaving]);
910
+ useLayoutEffect(() => {
911
+ if (!leaving) {
912
+ list.current?.querySelector(".launcher-item.on")?.scrollIntoView({ block: "nearest" });
913
+ }
914
+ }, [selected?.key, index, needle, prefix, leaving]);
915
+ useEffect(() => {
916
+ const timer = setTimeout(() => {
917
+ setAnnouncement(
918
+ flat.length === 0
919
+ ? `No results for ${needle}.`
920
+ : `${flat.length} results${prefix ? ` in ${GROUP_NAMES[prefix].toLowerCase()}` : ""}.`,
921
+ );
922
+ }, 150);
923
+
924
+ return () => clearTimeout(timer);
925
+ }, [flat.length, needle, prefix]);
926
+
927
+ const changeQuery = (next) => {
928
+ setQuery(next);
929
+ setPick(0);
930
+ };
931
+
932
+ const chooseType = (next) => {
933
+ changeQuery(next + (prefix ? query.slice(1) : query));
934
+ input.current?.focus({ preventScroll: true });
935
+ };
936
+
937
+ const clear = () => {
938
+ changeQuery("");
939
+ input.current?.focus({ preventScroll: true });
940
+ };
941
+
942
+ const close = () => store.set({ launcher: false });
943
+
944
+ const run = (item, event) => {
945
+ if (!item) {
946
+ return;
947
+ }
948
+
949
+ chosen.current = item.kind === "theme";
950
+ close();
951
+
952
+ if (item.kind === "theme") {
953
+ preview(null);
954
+
955
+ if (item.look) {
956
+ chooseLook(item.look, event);
957
+
958
+ return;
959
+ }
960
+
961
+ if (item.theme !== prefs().theme) {
962
+ setPrefs({ theme: item.theme });
963
+ }
964
+
965
+ return;
966
+ }
967
+
968
+ item.run(event);
969
+ };
970
+
971
+ const move = (by) => {
972
+ setPick((index + by + flat.length) % Math.max(1, flat.length));
973
+ input.current?.focus({ preventScroll: true });
974
+ };
975
+
976
+ const onKey = (event) => {
977
+ const key = event.key;
978
+ // A touch screen with a keyboard: the launcher holds focus, not its field (see `home` above). Typing goes to the
979
+ // field, which takes focus before the key lands: a letter, a dead key (an accent to come), an input method's
980
+ // keys, or AltGr's (Ctrl+Alt on Windows); not a shortcut. The keys that move and open work from the launcher too.
981
+ const onDialog = event.target === dialog.current;
982
+ const composing = event.isComposing || event.keyCode === 229 || key === "Process";
983
+ const altGr = event.ctrlKey && event.altKey;
984
+ const typing =
985
+ (key.length === 1 || key === "Backspace" || key === "Dead" || composing) &&
986
+ !event.metaKey &&
987
+ (altGr || (!event.ctrlKey && !event.altKey) || composing);
988
+
989
+ if (onDialog && typing) {
990
+ input.current?.focus({ preventScroll: true });
991
+
992
+ return;
993
+ }
994
+
995
+ // The keys an input method uses to compose (Escape, Enter among them) are its own, not the launcher's.
996
+ if (composing) {
997
+ return;
998
+ }
999
+
1000
+ if (key === "Escape") {
1001
+ event.preventDefault();
1002
+ event.stopPropagation();
1003
+ close();
1004
+
1005
+ return;
1006
+ }
1007
+
1008
+ // Toolbar buttons keep their native Enter/Space behavior; options and the input share navigation.
1009
+ if (
1010
+ !onDialog &&
1011
+ event.target !== input.current &&
1012
+ !event.target.closest(".launcher-item")
1013
+ ) {
1014
+ return;
1015
+ }
1016
+
1017
+ if (
1018
+ key === "ArrowDown" ||
1019
+ (event.ctrlKey && (key === "n" || key === "j")) ||
1020
+ (key === "Tab" && !event.shiftKey)
1021
+ ) {
1022
+ event.preventDefault();
1023
+ move(1);
1024
+ } else if (
1025
+ key === "ArrowUp" ||
1026
+ (event.ctrlKey && key === "p") ||
1027
+ (key === "Tab" && event.shiftKey)
1028
+ ) {
1029
+ event.preventDefault();
1030
+ move(-1);
1031
+ } else if (key === "PageDown") {
1032
+ event.preventDefault();
1033
+ move(8);
1034
+ } else if (key === "PageUp") {
1035
+ event.preventDefault();
1036
+ move(-8);
1037
+ } else if (key === "Enter") {
1038
+ event.preventDefault();
1039
+ run(selected, event);
1040
+ }
1041
+ };
1042
+
1043
+ let at = 0;
1044
+
1045
+ return html`<div
1046
+ class=${`launcher-overlay ${leaving ? "leaving" : ""}`}
1047
+ data-part="scrim"
1048
+ data-for="launcher"
1049
+ inert=${leaving}
1050
+ onMouseDown=${scrimPress(close)}
1051
+ >
1052
+ <section
1053
+ class="launcher"
1054
+ data-part="launcher"
1055
+ data-state=${leaving ? "closing" : undefined}
1056
+ ref=${dialog}
1057
+ role="dialog"
1058
+ aria-modal="true"
1059
+ aria-label="Launcher"
1060
+ tabindex="-1"
1061
+ onKeyDown=${onKey}
1062
+ onMouseDown=${(event) => event.target !== input.current && event.preventDefault()}
1063
+ >
1064
+ <div class="grip" aria-hidden="true"></div>
1065
+ <div class="launcher-input" data-part="launcher-input">
1066
+ <span class="prompt" aria-hidden="true">❯</span>
1067
+ <input
1068
+ ref=${input}
1069
+ value=${query}
1070
+ placeholder="Sessions, actions, themes…"
1071
+ aria-label="Search sessions, actions, and themes"
1072
+ autocomplete="off"
1073
+ autocapitalize="none"
1074
+ spellcheck=${false}
1075
+ role="combobox"
1076
+ aria-expanded="true"
1077
+ aria-autocomplete="list"
1078
+ aria-controls="launcher-results"
1079
+ aria-activedescendant=${selected ? optionId(selected) : undefined}
1080
+ onInput=${(event) => changeQuery(event.currentTarget.value)}
1081
+ />
1082
+ <kbd class="launcher-escape" aria-hidden="true">esc</kbd>
1083
+ <button class="launcher-close" aria-label="Close launcher" onClick=${close}>
1084
+ <${Icon} name="close" size=${18} />
1085
+ </button>
1086
+ </div>
1087
+ <div
1088
+ class="launcher-types"
1089
+ data-part="launcher-filters"
1090
+ role="group"
1091
+ aria-label="Search type"
1092
+ >
1093
+ ${[
1094
+ ["", "All"],
1095
+ ["@", "Sessions"],
1096
+ [">", "Actions"],
1097
+ ["#", "Themes"],
1098
+ ].map(
1099
+ ([token, label]) => html`<button
1100
+ aria-pressed=${(prefix ? query[0] : "") === token}
1101
+ onClick=${() => chooseType(token)}
1102
+ >
1103
+ ${label}${token && html`<kbd aria-hidden="true">${token}</kbd>`}
1104
+ </button>`,
1105
+ )}
1106
+ </div>
1107
+ ${
1108
+ limitedRecent &&
1109
+ html`<div
1110
+ class="launcher-summary"
1111
+ role="group"
1112
+ aria-label="Recent session options"
1113
+ >
1114
+ <div class="launcher-group" data-part="launcher-group">
1115
+ <span id="launcher-group-session">Recent sessions</span>
1116
+ <span class="launcher-count">
1117
+ ${recent.items.length} of ${recent.total}
1118
+ </span>
1119
+ </div>
1120
+ <button aria-label="Show all sessions" onClick=${() => chooseType("@")}>
1121
+ Show all <span aria-hidden="true">@</span>
1122
+ </button>
1123
+ </div>`
1124
+ }
1125
+ <div
1126
+ class="launcher-list"
1127
+ id="launcher-results"
1128
+ ref=${list}
1129
+ role="listbox"
1130
+ aria-label="Search results"
1131
+ >
1132
+ ${groups.map(
1133
+ (group) => html`
1134
+ <div role="group" aria-labelledby=${`launcher-group-${group.kind}`}>
1135
+ ${
1136
+ !(group.kind === "session" && limitedRecent) &&
1137
+ html`<div class="launcher-group" data-part="launcher-group">
1138
+ <span id=${`launcher-group-${group.kind}`}>
1139
+ ${
1140
+ group.kind === "session" && recent
1141
+ ? "Recent sessions"
1142
+ : GROUP_NAMES[group.kind]
1143
+ }
1144
+ </span>
1145
+ <span class="launcher-count">
1146
+ ${group.items.length}${
1147
+ group.total > group.items.length
1148
+ ? ` of ${group.total}`
1149
+ : ""
1150
+ }
1151
+ </span>
1152
+ </div>`
1153
+ }
1154
+ ${group.items.map((item) => {
1155
+ const mine = at++;
1156
+ const on = mine === index;
1157
+ const fullDetail = item.fullDetail;
1158
+ const description = [
1159
+ item.label,
1160
+ fullDetail,
1161
+ item.status,
1162
+ item.matchNote,
1163
+ item.keys?.replace("Mod", APPLE ? "Command" : "Control"),
1164
+ ]
1165
+ .filter(Boolean)
1166
+ .join(", ");
1167
+
1168
+ return html`<button
1169
+ key=${item.key}
1170
+ id=${optionId(item)}
1171
+ class=${`launcher-item ${on ? "on" : ""}`}
1172
+ data-part="launcher-row"
1173
+ role="option"
1174
+ tabindex="-1"
1175
+ aria-label=${description}
1176
+ aria-selected=${on}
1177
+ title=${description}
1178
+ onFocus=${() => mine !== index && setPick(mine)}
1179
+ onMouseMove=${() => mine !== index && setPick(mine)}
1180
+ onClick=${(event) => run(item, event)}
1181
+ >
1182
+ ${
1183
+ item.kind === "theme"
1184
+ ? html`
1185
+ <span
1186
+ class="swatch"
1187
+ style=${varsStyle(item.vars)}
1188
+ aria-hidden="true"
1189
+ >
1190
+ <i style="background:var(--o-bg)"></i>
1191
+ <i style="background:var(--o-accent)"></i>
1192
+ <i style="background:var(--o-green)"></i>
1193
+ <i style="background:var(--o-red)"></i>
1194
+ </span>
1195
+ `
1196
+ : html`
1197
+ <span class="glyph" aria-hidden="true">
1198
+ ${
1199
+ item.kind === "session"
1200
+ ? html`<span
1201
+ class="launcher-folder"
1202
+ style=${`--folder:${item.folder}`}
1203
+ ></span>`
1204
+ : html`
1205
+ <${Icon}
1206
+ name=${item.icon}
1207
+ path=${item.iconPath}
1208
+ size=${16}
1209
+ />
1210
+ `
1211
+ }
1212
+ </span>
1213
+ `
1214
+ }
1215
+ <span class="main">
1216
+ <span class="launcher-title">
1217
+ <${Marked} text=${item.label} hits=${item.hits} />
1218
+ </span>
1219
+ ${
1220
+ (item.detail.text || item.matchNote) &&
1221
+ html`<span class="detail">
1222
+ <span
1223
+ class=${`launcher-path ${item.kind === "session" ? "session-path" : ""}`}
1224
+ >
1225
+ <${Marked}
1226
+ text=${item.detail.text}
1227
+ hits=${item.detail.hits}
1228
+ />
1229
+ </span>
1230
+ ${
1231
+ item.matchNote &&
1232
+ html`<span class="launcher-match-note">
1233
+ ${item.matchNote}
1234
+ </span>`
1235
+ }
1236
+ </span>`
1237
+ }
1238
+ </span>
1239
+ ${
1240
+ item.status &&
1241
+ html`<span class=${`launcher-state ${item.tone}`}>
1242
+ ${item.status}
1243
+ </span>`
1244
+ }
1245
+ ${
1246
+ item.kind === "theme" &&
1247
+ (item.look
1248
+ ? item.look === prefs().look
1249
+ : item.theme === prefs().theme) &&
1250
+ html`<span class="hint">current</span>`
1251
+ }
1252
+ ${
1253
+ item.keys &&
1254
+ html`<span class="hint">
1255
+ <${Keys} keys=${item.keys} />
1256
+ </span>`
1257
+ }
1258
+ </button>`;
1259
+ })}
1260
+ </div>
1261
+ `,
1262
+ )}
1263
+ </div>
1264
+ ${
1265
+ flat.length === 0 &&
1266
+ html`<div class="launcher-empty">
1267
+ <strong>No matches for “${needle}”.</strong>
1268
+ <span>Try fewer words, or search all types.</span>
1269
+ <button class="button" onClick=${clear}>Clear search</button>
1270
+ </div>`
1271
+ }
1272
+ <div
1273
+ class="launcher-status"
1274
+ role="status"
1275
+ aria-live="polite"
1276
+ aria-atomic="true"
1277
+ >
1278
+ ${announcement}
1279
+ </div>
1280
+ <div class="launcher-foot">
1281
+ <span class="launcher-key-help">
1282
+ <kbd>↑</kbd><kbd>↓</kbd> move <kbd>↵</kbd> open <kbd>esc</kbd> close
1283
+ </span>
1284
+ <span class="launcher-prefix-help">
1285
+ <kbd>></kbd> actions <kbd>@</kbd> sessions <kbd>#</kbd> themes
1286
+ </span>
1287
+ <span class="launcher-touch-help">
1288
+ Tap a result · > actions, @ sessions, # themes
1289
+ </span>
1290
+ </div>
1291
+ </section>
1292
+ </div>`;
1293
+ }