@kabmo-labs/kabmo 0.17.0 → 0.18.0

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 (269) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +538 -457
  3. package/dist/client/static/js/index-hp75vsv9.css +1 -0
  4. package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
  5. package/package.json +1 -1
  6. package/src/client/components/common/MarkdownRenderer.tsx +136 -89
  7. package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
  8. package/src/client/components/common/anchored-menu/index.tsx +143 -0
  9. package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
  10. package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
  11. package/src/client/components/common/markdown-review/index.tsx +129 -0
  12. package/src/client/components/common/server-control/Panel.tsx +33 -23
  13. package/src/client/components/common/server-control/index.test.tsx +11 -5
  14. package/src/client/components/common/server-control/index.tsx +10 -8
  15. package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
  16. package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
  17. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
  18. package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
  19. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
  20. package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
  21. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
  23. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
  24. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
  25. package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
  26. package/src/client/components/layout/update-popup/index.tsx +5 -1
  27. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
  28. package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
  29. package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
  30. package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
  31. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
  32. package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
  33. package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
  34. package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
  35. package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
  36. package/src/client/components/settings/categories/McpSettings.tsx +4 -21
  37. package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
  38. package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
  39. package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
  40. package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
  41. package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
  42. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
  43. package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
  44. package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
  45. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
  46. package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
  47. package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
  48. package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
  49. package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
  50. package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
  51. package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
  52. package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
  53. package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
  54. package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
  55. package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
  56. package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
  57. package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
  58. package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
  59. package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
  60. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
  61. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
  62. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
  63. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
  64. package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
  65. package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
  66. package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
  67. package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
  68. package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
  69. package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
  70. package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
  71. package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
  72. package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
  73. package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
  74. package/src/client/components/workspace/browser-panel/index.tsx +50 -4
  75. package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
  76. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
  77. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
  78. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
  87. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
  88. package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
  89. package/src/client/components/workspace/diff-panel/changes.ts +28 -12
  90. package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
  91. package/src/client/components/workspace/diff-panel/merge.ts +21 -1
  92. package/src/client/components/workspace/editor/Body.tsx +7 -0
  93. package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
  94. package/src/client/components/workspace/editor/FilePane.tsx +12 -0
  95. package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
  96. package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
  97. package/src/client/components/workspace/editor/index.tsx +25 -22
  98. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
  99. package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
  100. package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
  101. package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
  102. package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
  103. package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
  104. package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
  105. package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
  106. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
  107. package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
  108. package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
  109. package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
  110. package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
  111. package/src/client/data/agent-data/builtin.ts +0 -10
  112. package/src/client/data/agent-data/orchestrator.ts +0 -45
  113. package/src/client/data/agent-data/specialist.ts +0 -100
  114. package/src/client/data/mock/token-usage.ts +170 -120
  115. package/src/client/data/settings/omp-schema.json +33 -1
  116. package/src/client/hooks/browser/use-annotate.test.ts +143 -0
  117. package/src/client/hooks/browser/use-annotate.ts +98 -0
  118. package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
  119. package/src/client/hooks/browser/use-close-tab.ts +67 -0
  120. package/src/client/hooks/browser/use-screencast.ts +13 -1
  121. package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
  122. package/src/client/hooks/chat/composer/browser-context.ts +40 -16
  123. package/src/client/hooks/chat/composer/items.test.ts +1 -1
  124. package/src/client/hooks/chat/composer/review-context.ts +38 -0
  125. package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
  126. package/src/client/hooks/chat/composer/use-draft.ts +31 -2
  127. package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
  128. package/src/client/hooks/editor/use-document-annotations.ts +124 -0
  129. package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
  130. package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
  131. package/src/client/hooks/editor/use-preview-review.ts +148 -0
  132. package/src/client/hooks/settings/agents.ts +149 -0
  133. package/src/client/hooks/settings/crud-list.test.ts +28 -6
  134. package/src/client/hooks/settings/crud-list.ts +96 -57
  135. package/src/client/hooks/settings/omp-config.ts +164 -0
  136. package/src/client/hooks/settings/useTokenUsage.ts +125 -0
  137. package/src/client/hooks/settings/write-feedback.test.ts +104 -0
  138. package/src/client/hooks/settings/write-feedback.ts +63 -0
  139. package/src/client/hooks/ui/markdown-hydration.ts +125 -0
  140. package/src/client/hooks/ui/updates/index.test.ts +100 -1
  141. package/src/client/hooks/ui/updates/index.ts +50 -0
  142. package/src/client/hooks/ui/updates/notes.test.ts +138 -0
  143. package/src/client/hooks/ui/updates/notes.ts +57 -0
  144. package/src/client/lib/browser/element-at.test.ts +229 -0
  145. package/src/client/lib/browser/element-at.ts +139 -0
  146. package/src/client/lib/review/client.ts +73 -0
  147. package/src/client/lib/router/search-params.ts +42 -20
  148. package/src/client/tailwind.css +65 -0
  149. package/src/server/lib/btw/lifecycle.server.ts +2 -2
  150. package/src/server/lib/db/schema.ts +7 -0
  151. package/src/server/lib/db/seed-terminal.test.ts +4 -0
  152. package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
  153. package/src/server/lib/omp/config/agents.ts +231 -61
  154. package/src/server/lib/omp/config/definitions.test.ts +9 -105
  155. package/src/server/lib/omp/config/extensions.ts +16 -7
  156. package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
  157. package/src/server/lib/omp/rpc/constants.test.ts +11 -0
  158. package/src/server/lib/omp/rpc/constants.ts +15 -0
  159. package/src/server/lib/omp/rpc/process.ts +11 -14
  160. package/src/server/lib/omp/rpc/session-commands.ts +6 -3
  161. package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
  162. package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
  163. package/src/server/lib/omp/rpc/utility.ts +12 -0
  164. package/src/server/lib/review/schema.server.ts +45 -0
  165. package/src/server/lib/review/store.server.ts +138 -0
  166. package/src/server/lib/terminal/attach-replay.test.ts +132 -0
  167. package/src/server/lib/terminal/output.test.ts +166 -0
  168. package/src/server/lib/terminal/output.ts +104 -0
  169. package/src/server/lib/terminal/runtime.server.ts +5 -0
  170. package/src/server/lib/terminal/send-result.test.ts +33 -0
  171. package/src/server/lib/terminal/send-result.ts +32 -0
  172. package/src/server/lib/terminal/session.server.ts +45 -11
  173. package/src/server/lib/terminal/store-liveness.test.ts +4 -0
  174. package/src/server/lib/updates/active-notes.test.ts +149 -0
  175. package/src/server/lib/updates/active-notes.ts +75 -0
  176. package/src/server/lib/updates/changelog-file.ts +42 -11
  177. package/src/server/lib/updates/changelog.test.ts +15 -1
  178. package/src/server/lib/updates/omp.ts +42 -15
  179. package/src/server/lib/updates/release-url.ts +27 -1
  180. package/src/server/lib/usage/index-parse.test.ts +200 -0
  181. package/src/server/lib/usage/index-parse.ts +178 -0
  182. package/src/server/lib/usage/index-query.server.ts +248 -0
  183. package/src/server/lib/usage/index-scan.server.ts +343 -0
  184. package/src/server/lib/usage/index-schema.server.ts +82 -0
  185. package/src/server/lib/usage/index.test.ts +234 -0
  186. package/src/server/lib/usage/providers.server.ts +4 -53
  187. package/src/server/routes/browser/index.ts +3 -0
  188. package/src/server/routes/browser/stream.ts +31 -2
  189. package/src/server/routes/browser/tabs.test.ts +94 -0
  190. package/src/server/routes/browser/tabs.ts +85 -0
  191. package/src/server/routes/index.ts +2 -0
  192. package/src/server/routes/review/bindings.ts +11 -0
  193. package/src/server/routes/review/index.ts +127 -0
  194. package/src/server/routes/review/routes.test.ts +191 -0
  195. package/src/server/routes/settings/agents.test.ts +180 -0
  196. package/src/server/routes/settings/agents.ts +95 -102
  197. package/src/server/routes/settings/mcp.test.ts +135 -0
  198. package/src/server/routes/settings/mcp.ts +14 -6
  199. package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
  200. package/src/server/routes/telemetry/tokens.test.ts +145 -0
  201. package/src/server/routes/telemetry/tokens.ts +70 -149
  202. package/src/server/routes/terminal/ws.ts +6 -5
  203. package/src/server/routes/updates/index.ts +2 -0
  204. package/src/server/routes/updates/notes.ts +34 -0
  205. package/src/server/routes/updates/routes.test.ts +49 -0
  206. package/src/shared/lib/browser/annotate.test.ts +283 -0
  207. package/src/shared/lib/browser/annotate.ts +231 -0
  208. package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
  209. package/src/shared/lib/browser/frame-gate.test.ts +91 -0
  210. package/src/shared/lib/browser/frame-gate.ts +69 -0
  211. package/src/shared/lib/browser/frame-params.test.ts +43 -0
  212. package/src/shared/lib/browser/frame-params.ts +60 -0
  213. package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
  214. package/src/shared/lib/browser/frame-pipeline.ts +80 -0
  215. package/src/shared/lib/browser/page-context.ts +60 -4
  216. package/src/shared/lib/browser/snapshot.test.ts +115 -0
  217. package/src/shared/lib/browser/snapshot.ts +112 -0
  218. package/src/shared/lib/browser/tab-close.test.ts +74 -0
  219. package/src/shared/lib/browser/tab-close.ts +77 -0
  220. package/src/shared/lib/browser/viewer.ts +45 -26
  221. package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
  222. package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
  223. package/src/shared/lib/chat/tool/artifact.ts +55 -20
  224. package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
  225. package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
  226. package/src/shared/lib/chat/tool/minimized.ts +64 -0
  227. package/src/shared/lib/chat/tool/summary.test.ts +28 -8
  228. package/src/shared/lib/chat/tool/summary.ts +3 -32
  229. package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
  230. package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
  231. package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
  232. package/src/shared/lib/markdown/blocks/scan.ts +100 -0
  233. package/src/shared/lib/markdown/blocks/types.ts +62 -0
  234. package/src/shared/lib/markdown/marked.ts +58 -147
  235. package/src/shared/lib/markdown/math-extensions.ts +168 -0
  236. package/src/shared/lib/markdown/review/prompt.ts +77 -0
  237. package/src/shared/lib/markdown/review/reconcile.ts +55 -0
  238. package/src/shared/lib/markdown/review/review.test.ts +96 -0
  239. package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
  240. package/src/shared/lib/markdown/xml-sections.ts +139 -0
  241. package/src/shared/lib/models/provider/label.ts +57 -0
  242. package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
  243. package/src/shared/lib/omp/config/agent-file.ts +43 -0
  244. package/src/shared/lib/omp/config/row-value.test.ts +95 -0
  245. package/src/shared/lib/omp/config/row-value.ts +97 -0
  246. package/src/shared/lib/omp/config/schema.test.ts +31 -0
  247. package/src/shared/lib/omp/config/schema.ts +6 -0
  248. package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
  249. package/src/shared/lib/omp/rpc/frame.ts +49 -40
  250. package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
  251. package/src/shared/lib/ui/menu-anchor.ts +89 -0
  252. package/src/shared/lib/usage/breakdown.test.ts +197 -0
  253. package/src/shared/lib/usage/breakdown.ts +241 -0
  254. package/src/shared/lib/usage/range.test.ts +204 -0
  255. package/src/shared/lib/usage/range.ts +240 -0
  256. package/src/shared/lib/usage/view.test.ts +85 -0
  257. package/src/shared/lib/usage/view.ts +74 -0
  258. package/src/shared/types/browser.ts +78 -0
  259. package/src/shared/types/index.ts +1 -0
  260. package/src/shared/types/settings/agent.ts +28 -6
  261. package/src/shared/types/settings/state.ts +4 -3
  262. package/src/shared/types/settings/write.ts +6 -0
  263. package/src/shared/types/tokenUsage.ts +128 -21
  264. package/src/shared/types/updates.ts +20 -0
  265. package/dist/client/static/js/index-3ve31rzx.css +0 -1
  266. package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
  267. package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
  268. package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
  269. package/src/server/lib/omp/session/usage/shaping.ts +0 -130
@@ -9,10 +9,18 @@
9
9
  * condition holds against the live config snapshot and when the global
10
10
  * search matches. Entries without UI metadata (upstream or extras) never
11
11
  * render — matching upstream's own panel surface plus Kabmo extras.
12
+ *
13
+ * Search is a WHOLE-SCHEMA view, so the tab strip is replaced by its own
14
+ * summary line while a query is active: leaving the pills up made a tab click
15
+ * look broken, because results stay global and the highlighted tab changed
16
+ * nothing. Each tab carries its visible row count so an empty tab is
17
+ * recognisable before it is opened, and `Reset` is offered only for a key that
18
+ * config.yml actually holds — resetting an unset key wrote nothing and looked
19
+ * like a failure.
12
20
  */
13
21
 
14
22
  import { useMemo } from 'preact/hooks';
15
- import { Check, RotateCcw } from 'lucide-preact';
23
+ import { Check, RotateCcw, Search, X } from 'lucide-preact';
16
24
  import type { ConfigEntry } from '@/server/lib/omp/config/config-cli';
17
25
  import type { SchemaTab } from '@/shared/lib/omp/config/schema-types';
18
26
  import { ALL_SCHEMA_ENTRIES, entriesForTab, isConditionMet, matchesSearch } from '@/shared/lib/omp/config/schema';
@@ -29,9 +37,11 @@ interface ConfigTabsProps {
29
37
  saveErrors: Map<string, string>;
30
38
  onCommit: (key: string, value: unknown) => Promise<boolean>;
31
39
  onReset: (key: string) => Promise<boolean>;
32
- onDirty: (key: string, dirty: boolean, revert: () => void) => void;
40
+ onDirty: (key: string, dirty: boolean) => void;
33
41
  }
34
42
 
43
+ const SEARCH_LIMIT = 80;
44
+
35
45
  export function ConfigTabs({
36
46
  tabs,
37
47
  entries,
@@ -46,23 +56,33 @@ export function ConfigTabs({
46
56
  onDirty,
47
57
  }: ConfigTabsProps) {
48
58
  const activeTab = tabs.find((tab) => tab.id === activeTabId) ?? tabs[0];
59
+ const query = searchQuery.trim().toLowerCase();
60
+
61
+ /** Keys per tab under the live snapshot, so the pills can state a count. */
62
+ const countsByTab = useMemo(() => {
63
+ const counts = new Map<string, number>();
64
+ for (const entry of Object.values(ALL_SCHEMA_ENTRIES)) {
65
+ if (!entry.ui || !isConditionMet(entry.ui.condition, entries)) continue;
66
+ counts.set(entry.ui.tab, (counts.get(entry.ui.tab) ?? 0) + 1);
67
+ }
68
+ return counts;
69
+ }, [entries]);
49
70
 
50
71
  const visibleEntries = useMemo(() => {
51
- const query = searchQuery.trim().toLowerCase();
52
72
  if (query) {
53
73
  return Object.entries(ALL_SCHEMA_ENTRIES)
54
- .filter(([key, entry]) => matchesSearch(key, entry, query))
74
+ .filter(([key, entry]) => entry.ui && matchesSearch(key, entry, query))
55
75
  .map(([key]) => key)
56
- .slice(0, 80);
76
+ .slice(0, SEARCH_LIMIT);
57
77
  }
58
78
  return entriesForTab(activeTab.id)
59
- .filter(([, entry]) => isConditionMet(entry.ui.condition, entries))
79
+ .filter(([, entry]) => entry.ui && isConditionMet(entry.ui.condition, entries))
60
80
  .map(([key]) => key);
61
- }, [entries, activeTab.id, searchQuery]);
81
+ }, [entries, activeTab.id, query]);
62
82
 
63
83
  /** Search results grouped by "Tab · Group", mirroring the tab/group layout. */
64
84
  const searchGroups = useMemo(() => {
65
- if (!searchQuery.trim()) return [];
85
+ if (!query) return [];
66
86
  const order: Array<{ id: string; label: string; keys: string[] }> = [];
67
87
  const byId = new Map<string, { label: string; keys: string[] }>();
68
88
  for (const key of visibleEntries) {
@@ -83,31 +103,69 @@ export function ConfigTabs({
83
103
  bucket.keys.push(key);
84
104
  }
85
105
  return order;
86
- }, [visibleEntries, searchQuery, tabs]);
106
+ }, [visibleEntries, query, tabs]);
107
+
108
+ const totalMatches = useMemo(
109
+ () => (query
110
+ ? Object.entries(ALL_SCHEMA_ENTRIES).filter(([key, entry]) => entry.ui && matchesSearch(key, entry, query)).length
111
+ : 0),
112
+ [query],
113
+ );
87
114
 
88
115
  return (
89
116
  <div className="w-full flex flex-col gap-3 text-xs">
90
- {/* Horizontal tab pills — mirror omp's own setting tabs */}
91
- <div className="flex items-center gap-1 overflow-x-auto pb-1 scrollbar-overlay-container">
92
- {tabs.map((tab) => (
93
- <button
94
- key={tab.id}
95
- type="button"
96
- onClick={() => onSelectTab(tab.id)}
97
- className={`shrink-0 rounded-md px-2.5 py-1 text-[11px] font-medium transition-colors cursor-pointer ${
98
- tab.id === activeTab.id
99
- ? 'bg-ink/10 text-ink'
100
- : 'text-ink/55 hover:bg-ink/5 hover:text-ink'
101
- }`}
102
- >
103
- {tab.label}
104
- </button>
105
- ))}
106
- </div>
117
+ {query ? (
118
+ <div className="flex items-center justify-between gap-3 rounded-md border border-ink/15 bg-ink/[0.03] px-2.5 py-1.5">
119
+ <span className="flex min-w-0 items-center gap-1.5 text-[11px] text-ink/60">
120
+ <Search size={11} className="shrink-0 text-ink/40" />
121
+ <span className="truncate">
122
+ Searching every tab — <span className="font-medium text-ink">{totalMatches}</span>
123
+ {totalMatches > SEARCH_LIMIT && <span> (showing the first {SEARCH_LIMIT})</span>}
124
+ {' '}matching key{totalMatches === 1 ? '' : 's'}
125
+ </span>
126
+ </span>
127
+ <span className="shrink-0 rounded bg-ink/10 px-1.5 py-px font-mono text-[10px] text-ink/60">{searchQuery.trim()}</span>
128
+ </div>
129
+ ) : (
130
+ <div
131
+ role="tablist"
132
+ aria-label="OMP config tabs"
133
+ className="flex items-center gap-1 overflow-x-auto pb-1 scrollbar-overlay-container"
134
+ >
135
+ {tabs.map((tab) => {
136
+ const isActive = tab.id === activeTab.id;
137
+ const count = countsByTab.get(tab.id) ?? 0;
138
+ return (
139
+ <button
140
+ key={tab.id}
141
+ type="button"
142
+ role="tab"
143
+ aria-selected={isActive}
144
+ onClick={() => onSelectTab(tab.id)}
145
+ title={count === 0 ? `${tab.label} — no setting is available in this tab right now` : `${count} setting${count === 1 ? '' : 's'}`}
146
+ className={`shrink-0 rounded-md px-2.5 py-1 text-[11px] font-medium transition-colors cursor-pointer ${
147
+ isActive
148
+ ? 'bg-ink/10 text-ink'
149
+ : 'text-ink/55 hover:bg-ink/5 hover:text-ink'
150
+ }`}
151
+ >
152
+ {tab.label}
153
+ <span className={`ml-1.5 font-mono text-[9px] ${isActive ? 'text-ink/50' : 'text-ink/30'}`}>{count}</span>
154
+ </button>
155
+ );
156
+ })}
157
+ </div>
158
+ )}
159
+
160
+ {query && (
161
+ <div className="flex items-center gap-2 text-[10px] text-ink/40">
162
+ <X size={10} />
163
+ Clear the search to browse by tab again.
164
+ </div>
165
+ )}
107
166
 
108
- {/* Tab body: groups with heading rows */}
109
167
  <div className="w-full rounded-lg border border-ink/10 divide-y divide-ink/5">
110
- {searchQuery.trim() ? (
168
+ {query ? (
111
169
  searchGroups.map((group) => (
112
170
  <GroupedRows
113
171
  key={group.id}
@@ -144,7 +202,7 @@ export function ConfigTabs({
144
202
  )}
145
203
  {visibleEntries.length === 0 && (
146
204
  <div className="px-3 py-6 text-center text-ink/40">
147
- {searchQuery.trim() ? 'No settings match your search.' : 'No settings in this tab.'}
205
+ {query ? 'No setting matches that search.' : 'No setting is available in this tab right now.'}
148
206
  </div>
149
207
  )}
150
208
  </div>
@@ -161,7 +219,7 @@ interface GroupedRowsProps {
161
219
  saveErrors: Map<string, string>;
162
220
  onCommit: (key: string, value: unknown) => Promise<boolean>;
163
221
  onReset: (key: string) => Promise<boolean>;
164
- onDirty: (key: string, dirty: boolean, revert: () => void) => void;
222
+ onDirty: (key: string, dirty: boolean) => void;
165
223
  }
166
224
 
167
225
  function GroupedRows({
@@ -184,13 +242,16 @@ function GroupedRows({
184
242
  const schemaEntry = ALL_SCHEMA_ENTRIES[key];
185
243
  if (!schemaEntry?.ui) return null;
186
244
  const liveValue = entries[key]?.value;
245
+ // `omp config list` carries every registered key; an unset one has no
246
+ // `value`. Reset is only meaningful when config.yml holds a value.
247
+ const isStored = entries[key]?.value !== undefined;
187
248
  const isDirty = dirtyKeys.has(key);
188
249
  const saving = savingKeys.has(key);
189
250
  const errorMessage = saveErrors.get(key);
190
251
  return (
191
- <div key={key} className="flex items-center justify-between gap-3 px-3 py-2">
252
+ <div key={key} className="flex items-start justify-between gap-3 px-3 py-2 hover:bg-ink/[0.02]">
192
253
  <div className="min-w-0 flex-1">
193
- <div className="flex items-center gap-1.5">
254
+ <div className="flex flex-wrap items-center gap-1.5">
194
255
  <span className="font-medium text-ink">{schemaEntry.ui.label}</span>
195
256
  <span className="font-mono text-[9px] text-ink/30" title="config key">{key}</span>
196
257
  {isDirty && !saving && (
@@ -221,7 +282,7 @@ function GroupedRows({
221
282
  <div className="text-[10px] text-error/80 leading-snug">{schemaEntry.ui.warning}</div>
222
283
  )}
223
284
  </div>
224
- <div className="flex items-center gap-1.5 shrink-0">
285
+ <div className="flex shrink-0 items-center gap-1.5 pt-0.5">
225
286
  <RowEditor
226
287
  entryKey={key}
227
288
  entry={schemaEntry}
@@ -235,10 +296,10 @@ function GroupedRows({
235
296
  <button
236
297
  type="button"
237
298
  aria-label={`Reset ${schemaEntry.ui.label}`}
238
- title="Reset to schema default"
299
+ title={isStored ? 'Reset to the schema default' : 'This key is not set — omp already uses the schema default'}
239
300
  onClick={() => onReset(key)}
240
- disabled={saving}
241
- className={`rounded p-1 text-ink/30 hover:text-ink transition-colors cursor-pointer disabled:opacity-40 ${saving ? '' : 'hover:bg-ink/5'}`}
301
+ disabled={saving || !isStored}
302
+ className="rounded p-1 text-ink/30 hover:text-ink transition-colors cursor-pointer hover:bg-ink/5 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent"
242
303
  >
243
304
  <RotateCcw size={11} />
244
305
  </button>
@@ -0,0 +1,151 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The OMP Engine panel's header: live state at a glance, plus the two controls
8
+ * that belong to the snapshot (search and refresh).
9
+ *
10
+ * The snapshot used to be four static tiles that only changed on a full panel
11
+ * reload, so a running engine reported whatever it held when the modal opened.
12
+ * Refresh now owns its own busy state, the tiles carry the provider beside the
13
+ * model and a context meter with its token counts, and the moment of the
14
+ * reading is printed — a live-state panel that cannot say when it was read is
15
+ * indistinguishable from a stale one.
16
+ */
17
+
18
+ import type { ComponentChildren } from 'preact';
19
+ import { Loader2, RefreshCw, Search, X } from 'lucide-preact';
20
+ import { CONTEXT_BAND_TONES, clampContextPercent, contextUsageBand } from '@/shared/lib/chat/context/usage';
21
+ import { formatCompactTokens } from '@/shared/lib/format/number';
22
+ import type { EngineState } from '@/client/components/settings/categories/omp-settings/types';
23
+
24
+ interface EngineHeaderProps {
25
+ running: boolean;
26
+ state: EngineState | null;
27
+ refreshing: boolean;
28
+ updatedAt: number | null;
29
+ searchQuery: string;
30
+ onSearchChange: (value: string) => void;
31
+ onRefresh: () => void;
32
+ }
33
+
34
+ /** `12:34:56`, the local read time of the snapshot. */
35
+ function readTime(at: number): string {
36
+ return new Date(at).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
37
+ }
38
+
39
+ export function EngineHeader({
40
+ running,
41
+ state,
42
+ refreshing,
43
+ updatedAt,
44
+ searchQuery,
45
+ onSearchChange,
46
+ onRefresh,
47
+ }: EngineHeaderProps) {
48
+ const percent = state?.contextUsage?.percent;
49
+ const hasPercent = typeof percent === 'number' && Number.isFinite(percent);
50
+ const clamped = hasPercent ? clampContextPercent(percent) : 0;
51
+ const tone = CONTEXT_BAND_TONES[contextUsageBand(clamped)];
52
+ const tokens = formatCompactTokens(state?.contextUsage?.tokens);
53
+ const window = formatCompactTokens(state?.contextUsage?.contextWindow);
54
+ const modelId = state?.model?.id;
55
+
56
+ return (
57
+ <div className="flex flex-col gap-3 pb-3 border-b border-ink/10">
58
+ <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
59
+ <div>
60
+ <h2 className="text-sm font-semibold text-ink">OMP Engine</h2>
61
+ <p className="text-ink/50 mt-0.5">
62
+ Live agent state and the full native config schema from oh-my-pi.
63
+ {updatedAt !== null && <span className="text-ink/40"> Read at {readTime(updatedAt)}.</span>}
64
+ </p>
65
+ </div>
66
+ <div className="flex items-center gap-2">
67
+ <div className="relative">
68
+ <Search size={12} className="absolute left-2 top-1/2 -translate-y-1/2 text-ink/40 pointer-events-none" />
69
+ <input
70
+ aria-label="Search settings"
71
+ type="search"
72
+ value={searchQuery}
73
+ onChange={(e) => onSearchChange(e.currentTarget.value)}
74
+ placeholder="Search every setting…"
75
+ className="w-52 bg-paper border border-ink/15 rounded-md pl-6 pr-6 py-1 text-ink placeholder:text-ink/40 focus:outline-none focus:border-ink/40"
76
+ />
77
+ {searchQuery && (
78
+ <button
79
+ type="button"
80
+ aria-label="Clear search"
81
+ onClick={() => onSearchChange('')}
82
+ className="absolute right-1.5 top-1/2 -translate-y-1/2 text-ink/40 hover:text-ink cursor-pointer"
83
+ >
84
+ <X size={11} />
85
+ </button>
86
+ )}
87
+ </div>
88
+ <button
89
+ type="button"
90
+ onClick={onRefresh}
91
+ disabled={refreshing}
92
+ aria-busy={refreshing}
93
+ className="flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-ink/15 text-ink/70 hover:text-ink hover:bg-ink/5 transition-all cursor-pointer disabled:opacity-50"
94
+ >
95
+ {refreshing
96
+ ? <Loader2 size={12} className="animate-spin" />
97
+ : <RefreshCw size={12} />}
98
+ {refreshing ? 'Refreshing…' : 'Refresh'}
99
+ </button>
100
+ </div>
101
+ </div>
102
+
103
+ <div className="grid grid-cols-2 sm:grid-cols-4 gap-2">
104
+ <Stat label="Engine">
105
+ <span className="flex items-center gap-1.5">
106
+ <span
107
+ aria-hidden="true"
108
+ className={`h-1.5 w-1.5 rounded-full ${running ? 'bg-success' : 'bg-ink/25'}`}
109
+ />
110
+ {running ? 'Running' : 'Idle'}
111
+ </span>
112
+ </Stat>
113
+ <Stat label="Model">
114
+ <span className="block truncate" title={modelId ? `${state?.model?.provider ?? ''} / ${modelId}` : undefined}>
115
+ {modelId ?? '—'}
116
+ </span>
117
+ {state?.model?.provider && (
118
+ <span className="block truncate text-[10px] font-normal text-ink/40">{state.model.provider}</span>
119
+ )}
120
+ </Stat>
121
+ <Stat label="Thinking">
122
+ <span className="capitalize">{state?.thinkingLevel ?? '—'}</span>
123
+ </Stat>
124
+ <Stat label="Context">
125
+ <span className={hasPercent ? tone.text : undefined}>
126
+ {hasPercent ? `${percent.toFixed(1)}%` : '—'}
127
+ </span>
128
+ {hasPercent && (
129
+ <span className="mt-1 block h-1 w-full overflow-hidden rounded-full bg-ink/10" aria-hidden="true">
130
+ <span className={`block h-full rounded-full ${tone.fill}`} style={{ width: `${clamped}%` }} />
131
+ </span>
132
+ )}
133
+ {tokens && (
134
+ <span className="mt-0.5 block text-[10px] font-normal text-ink/40">
135
+ {tokens}{window ? ` / ${window}` : ''} tokens
136
+ </span>
137
+ )}
138
+ </Stat>
139
+ </div>
140
+ </div>
141
+ );
142
+ }
143
+
144
+ function Stat({ label, children }: { label: string; children: ComponentChildren }) {
145
+ return (
146
+ <div className="rounded-lg border border-ink/10 bg-ink/[0.03] px-3 py-2">
147
+ <div className="text-[10px] uppercase tracking-wide text-ink/40">{label}</div>
148
+ <div className="font-semibold text-ink mt-0.5">{children}</div>
149
+ </div>
150
+ );
151
+ }
@@ -6,56 +6,92 @@
6
6
  /**
7
7
  * Extension list — TS/JS modules loaded from .omp/extensions. Toggling
8
8
  * disabled writes to config.yml through /api/omp/extensions.
9
+ *
10
+ * The control is a SWITCH, not a `<select>`: the row's value is a boolean, and
11
+ * a select that reports "enabled"/"disabled" while its `onChange` ignores the
12
+ * chosen value reads as a two-state control that cannot be trusted. The switch
13
+ * disables only its own row while the write is in flight, so one slow toggle
14
+ * does not freeze the list, and the empty case is stated rather than returning
15
+ * `null` (a panel that vanishes is indistinguishable from a broken one).
9
16
  */
10
17
 
11
- import { Check } from 'lucide-preact';
12
-
13
- interface ExtensionItem {
14
- id: string;
15
- name: string;
16
- sourceRoot: string;
17
- filePath: string;
18
- disabled: boolean;
19
- }
18
+ import { Check, Loader2, Puzzle } from 'lucide-preact';
19
+ import type { ExtensionItem } from '@/client/components/settings/categories/omp-settings/types';
20
20
 
21
21
  interface ExtensionsPanelProps {
22
22
  extensions: ExtensionItem[];
23
23
  savedExtension: string | null;
24
+ /** Ids whose toggle is in flight. */
25
+ pendingIds: Set<string>;
24
26
  onToggle: (extension: ExtensionItem) => void;
25
27
  }
26
28
 
27
- export function ExtensionsPanel({ extensions, savedExtension, onToggle }: ExtensionsPanelProps) {
28
- if (extensions.length === 0) return null;
29
+ export function ExtensionsPanel({ extensions, savedExtension, pendingIds, onToggle }: ExtensionsPanelProps) {
29
30
  return (
30
31
  <div className="pt-2">
31
32
  <div className="flex items-center justify-between pb-2">
32
33
  <div>
33
34
  <h3 className="text-sm font-semibold text-ink">Extensions</h3>
34
- <p className="text-ink/50 mt-0.5">TS/JS modules loaded from .omp/extensions. Disable writes to config.yml.</p>
35
+ <p className="text-ink/50 mt-0.5">
36
+ TS/JS modules loaded from <span className="font-mono">.omp/extensions</span>. Disabling one writes to
37
+ config.yml and applies to the next session.
38
+ </p>
35
39
  </div>
36
40
  {savedExtension && (
37
- <span className="inline-flex items-center gap-1 text-[10px] text-ink/60"><Check size={11} /> saved</span>
41
+ <span className="inline-flex shrink-0 items-center gap-1 text-[10px] text-ink/60">
42
+ <Check size={11} /> saved
43
+ </span>
38
44
  )}
39
45
  </div>
40
- <div className="rounded-lg border border-ink/10 divide-y divide-ink/5">
41
- {extensions.map((extension) => (
42
- <div key={extension.id} className="flex items-center justify-between gap-3 px-3 py-2.5">
43
- <div className="min-w-0">
44
- <div className="font-medium text-ink">{extension.name}</div>
45
- <div className="text-[10px] text-ink/40 truncate font-mono">{extension.sourceRoot} · {extension.filePath}</div>
46
- </div>
47
- <select
48
- aria-label={`${extension.name} enabled`}
49
- value={extension.disabled ? 'false' : 'true'}
50
- onChange={() => onToggle(extension)}
51
- className="bg-paper border border-ink/15 rounded-md px-2 py-1 text-ink"
52
- >
53
- <option value="true">enabled</option>
54
- <option value="false">disabled</option>
55
- </select>
56
- </div>
57
- ))}
58
- </div>
46
+ {extensions.length === 0 ? (
47
+ <div className="flex items-center gap-2 rounded-lg border border-dashed border-ink/15 px-3 py-3 text-[11px] text-ink/50">
48
+ <Puzzle size={13} className="text-ink/35" />
49
+ <span>
50
+ No extension modules found. Add a <span className="font-mono">.ts</span> or{' '}
51
+ <span className="font-mono">.js</span> file under{' '}
52
+ <span className="font-mono">~/.omp/extensions</span> (or a workspace’s{' '}
53
+ <span className="font-mono">.omp/extensions</span>) and refresh.
54
+ </span>
55
+ </div>
56
+ ) : (
57
+ <div className="rounded-lg border border-ink/10 divide-y divide-ink/5">
58
+ {extensions.map((extension) => {
59
+ const enabled = !extension.disabled;
60
+ const pending = pendingIds.has(extension.id);
61
+ return (
62
+ <div key={extension.id} className="flex items-center justify-between gap-3 px-3 py-2.5">
63
+ <div className="min-w-0">
64
+ <div className="font-medium text-ink">{extension.name}</div>
65
+ <div className="text-[10px] text-ink/40 truncate font-mono" title={`${extension.sourceRoot}/${extension.filePath}`}>
66
+ {extension.sourceRoot} · {extension.filePath}
67
+ </div>
68
+ </div>
69
+ <div className="flex shrink-0 items-center gap-2">
70
+ <span className="text-[10px] text-ink/40">{pending ? 'saving…' : enabled ? 'enabled' : 'disabled'}</span>
71
+ {pending && <Loader2 size={11} className="animate-spin text-ink/40" />}
72
+ <button
73
+ type="button"
74
+ role="switch"
75
+ aria-checked={enabled}
76
+ aria-label={`${extension.name} enabled`}
77
+ disabled={pending}
78
+ onClick={() => onToggle(extension)}
79
+ className={`relative h-5 w-9 rounded-full transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-progress ${
80
+ enabled ? 'bg-ink' : 'bg-ink/15'
81
+ }`}
82
+ >
83
+ <span
84
+ className={`absolute top-0.5 h-4 w-4 rounded-full bg-paper shadow-sm transition-all ${
85
+ enabled ? 'left-[18px]' : 'left-0.5'
86
+ }`}
87
+ />
88
+ </button>
89
+ </div>
90
+ </div>
91
+ );
92
+ })}
93
+ </div>
94
+ )}
59
95
  </div>
60
96
  );
61
97
  }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Ordered multi-select for a row whose value is an ARRAY of schema options
8
+ * (first-match-ordered lists such as `tools.approval`).
9
+ *
10
+ * Chips with ←/→ and an add menu, rather than a plain multi-select: the ORDER
11
+ * is the meaning for these keys, and a `<select multiple>` cannot express it.
12
+ * Every mutation commits immediately — there is nothing to blur — so the
13
+ * parent's saving state is the only guard, and the add menu closes on pick.
14
+ */
15
+
16
+ import { useState } from 'preact/hooks';
17
+ import { Plus, X } from 'lucide-preact';
18
+ import type { SchemaOption } from '@/shared/lib/omp/config/schema-types';
19
+
20
+ interface OrderedChipsProps {
21
+ options: SchemaOption[];
22
+ value: unknown;
23
+ saving: boolean;
24
+ onCommit: (next: string[]) => void;
25
+ }
26
+
27
+ export function OrderedChips({ options, value, saving, onCommit }: OrderedChipsProps) {
28
+ const [open, setOpen] = useState(false);
29
+ const current = Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];
30
+ const remaining = options.filter((option) => !current.includes(option.value));
31
+ // Four aria-labels and the chip text read the same option, so the lookup is
32
+ // named once rather than repeated.
33
+ const labelOf = (optionValue: string) => options.find((o) => o.value === optionValue)?.label || optionValue;
34
+
35
+ const move = (index: number, delta: number) => {
36
+ const target = index + delta;
37
+ if (target < 0 || target >= current.length) return;
38
+ const next = [...current];
39
+ const [moved] = next.splice(index, 1);
40
+ next.splice(target, 0, moved);
41
+ onCommit(next);
42
+ };
43
+
44
+ return (
45
+ <div className="flex max-w-72 flex-wrap items-center justify-end gap-1.5">
46
+ {current.map((chip, index) => (
47
+ <span
48
+ key={chip}
49
+ className="inline-flex items-center gap-1 rounded-md border border-ink/15 bg-ink/[0.03] px-2 py-0.5 text-[10px] text-ink"
50
+ >
51
+ {index > 0 && (
52
+ <button
53
+ type="button"
54
+ aria-label={`Move ${labelOf(chip)} earlier`}
55
+ onClick={() => move(index, -1)}
56
+ disabled={saving}
57
+ className="text-ink/40 hover:text-ink cursor-pointer disabled:opacity-40"
58
+ >
59
+ ←
60
+ </button>
61
+ )}
62
+ {labelOf(chip)}
63
+ {index < current.length - 1 && (
64
+ <button
65
+ type="button"
66
+ aria-label={`Move ${labelOf(chip)} later`}
67
+ onClick={() => move(index, 1)}
68
+ disabled={saving}
69
+ className="text-ink/40 hover:text-ink cursor-pointer disabled:opacity-40"
70
+ >
71
+ →
72
+ </button>
73
+ )}
74
+ <button
75
+ type="button"
76
+ aria-label={`Remove ${labelOf(chip)}`}
77
+ onClick={() => onCommit(current.filter((entry) => entry !== chip))}
78
+ disabled={saving}
79
+ className="text-ink/40 hover:text-error cursor-pointer disabled:opacity-40"
80
+ >
81
+ <X size={10} />
82
+ </button>
83
+ </span>
84
+ ))}
85
+
86
+ {current.length === 0 && <span className="text-[10px] text-ink/40">nothing selected</span>}
87
+
88
+ <div className="relative">
89
+ <button
90
+ type="button"
91
+ onClick={() => setOpen((isOpen) => !isOpen)}
92
+ disabled={saving || remaining.length === 0}
93
+ aria-expanded={open}
94
+ aria-label="Add an option"
95
+ className="flex items-center gap-0.5 rounded-md border border-ink/15 px-2 py-0.5 text-[10px] text-ink/70 hover:text-ink hover:bg-ink/5 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"
96
+ >
97
+ <Plus size={10} /> add
98
+ </button>
99
+ {open && remaining.length > 0 && (
100
+ <div className="absolute right-0 top-full z-20 mt-1 max-h-44 w-48 overflow-auto rounded-md border border-ink/15 bg-paper p-1 shadow-lg">
101
+ {remaining.map((option) => (
102
+ <button
103
+ key={option.value}
104
+ type="button"
105
+ onClick={() => {
106
+ onCommit([...current, option.value]);
107
+ setOpen(false);
108
+ }}
109
+ className="block w-full rounded px-2 py-1 text-left text-[11px] text-ink/80 hover:bg-ink/5 cursor-pointer"
110
+ >
111
+ {option.label || option.value}
112
+ </button>
113
+ ))}
114
+ </div>
115
+ )}
116
+ </div>
117
+ </div>
118
+ );
119
+ }
@@ -42,7 +42,8 @@ interface PresetBarProps {
42
42
  /** A write is in flight; every control is disabled rather than racing it. */
43
43
  busy: boolean;
44
44
  onApply: (preset: ModelRolePreset) => void;
45
- onSave: (name: string) => void;
45
+ /** Resolves whether the preset was stored; a refusal keeps the name form open. */
46
+ onSave: (name: string) => Promise<boolean>;
46
47
  onUpdate: () => void;
47
48
  onDelete: () => void;
48
49
  }
@@ -61,12 +62,18 @@ export function PresetBar({
61
62
  const [name, setName] = useState('');
62
63
  const [confirmDelete, setConfirmDelete] = useState(false);
63
64
 
64
- const commitNew = () => {
65
+ /**
66
+ * Keep the name form open until the preset is actually stored. Closing it on
67
+ * the click threw away what the user typed, so a refused name ("A preset
68
+ * named “cheap” already exists") left them re-typing it from scratch.
69
+ */
70
+ const commitNew = async () => {
65
71
  const trimmed = name.trim();
66
72
  if (!trimmed) return;
67
- onSave(trimmed);
68
- setName('');
69
- setCreating(false);
73
+ if (await onSave(trimmed)) {
74
+ setName('');
75
+ setCreating(false);
76
+ }
70
77
  };
71
78
 
72
79
  return (
@@ -138,7 +145,7 @@ export function PresetBar({
138
145
  autoFocus
139
146
  onInput={(event) => setName(event.currentTarget.value)}
140
147
  onKeyDown={(event) => {
141
- if (event.key === 'Enter') commitNew();
148
+ if (event.key === 'Enter') void commitNew();
142
149
  if (event.key === 'Escape') { setCreating(false); setName(''); }
143
150
  }}
144
151
  placeholder="e.g. cheap, thinking, review"
@@ -146,7 +153,7 @@ export function PresetBar({
146
153
  />
147
154
  <button
148
155
  type="button"
149
- onClick={commitNew}
156
+ onClick={() => void commitNew()}
150
157
  disabled={!name.trim() || busy}
151
158
  className="px-2 py-1 rounded-md border border-ink/15 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-50 text-[11px]"
152
159
  >