@kabmo-labs/kabmo 0.11.1 → 0.12.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 (324) hide show
  1. package/README.md +67 -421
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +426 -413
  4. package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
  5. package/dist/client/static/js/index-shexbk5f.css +1 -0
  6. package/marketplace/marketplace.json +13 -3
  7. package/marketplace/plugins/command-runner/package.json +4 -2
  8. package/marketplace/plugins/git-forge/README.md +219 -0
  9. package/marketplace/plugins/git-forge/icon.svg +20 -0
  10. package/marketplace/plugins/git-forge/package.json +56 -0
  11. package/marketplace/plugins/git-forge/src/app.tsx +82 -0
  12. package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
  13. package/marketplace/plugins/git-forge/src/command.ts +119 -0
  14. package/marketplace/plugins/git-forge/src/header.tsx +87 -0
  15. package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
  16. package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
  17. package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
  18. package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
  19. package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
  20. package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
  21. package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
  22. package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
  23. package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
  24. package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
  25. package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
  26. package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
  27. package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
  28. package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
  29. package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
  30. package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
  31. package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
  32. package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
  33. package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
  34. package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
  35. package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
  36. package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
  37. package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
  38. package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
  39. package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
  40. package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
  41. package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
  42. package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
  43. package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
  44. package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
  45. package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
  46. package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
  47. package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
  48. package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
  49. package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
  50. package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
  51. package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
  52. package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
  53. package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
  54. package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
  55. package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
  56. package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
  57. package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
  58. package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
  59. package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
  60. package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
  61. package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
  62. package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
  63. package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
  64. package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
  65. package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
  66. package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
  67. package/marketplace/plugins/git-forge/src/server.ts +284 -0
  68. package/marketplace/plugins/git-forge/tsconfig.json +16 -0
  69. package/marketplace/plugins/session-info/package.json +4 -2
  70. package/marketplace/plugins/stats/package.json +4 -2
  71. package/package.json +6 -1
  72. package/src/client/components/common/code-surface/blame-hover.ts +188 -0
  73. package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
  74. package/src/client/components/common/code-surface/blame-panel.ts +306 -0
  75. package/src/client/components/common/code-surface/blame.test.ts +303 -0
  76. package/src/client/components/common/code-surface/blame.ts +227 -0
  77. package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
  78. package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
  79. package/src/client/components/common/code-surface/documents.ts +48 -1
  80. package/src/client/components/common/code-surface/extensions.test.ts +4 -0
  81. package/src/client/components/common/code-surface/extensions.ts +44 -0
  82. package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
  83. package/src/client/components/common/code-surface/indent.test.ts +5 -0
  84. package/src/client/components/common/code-surface/index.tsx +16 -2
  85. package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
  86. package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
  87. package/src/client/components/common/code-surface/lint.test.ts +101 -0
  88. package/src/client/components/common/code-surface/lint.ts +85 -0
  89. package/src/client/components/common/code-surface/props.ts +17 -0
  90. package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
  91. package/src/client/components/common/code-surface/theme.ts +71 -0
  92. package/src/client/components/common/header-controls/index.test.tsx +1 -1
  93. package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
  94. package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
  95. package/src/client/components/common/provider-icon/Plate.tsx +88 -0
  96. package/src/client/components/common/provider-icon/index.tsx +55 -11
  97. package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
  98. package/src/client/components/mobile/SessionSidebar.tsx +2 -10
  99. package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
  100. package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
  101. package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
  102. package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
  103. package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
  104. package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
  105. package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
  106. package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
  107. package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
  108. package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
  109. package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
  110. package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
  111. package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
  112. package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
  113. package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
  114. package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
  115. package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
  116. package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
  117. package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
  118. package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
  119. package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
  120. package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
  121. package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
  122. package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
  123. package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
  124. package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
  125. package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
  126. package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
  127. package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
  128. package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
  129. package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
  130. package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
  131. package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
  132. package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
  133. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
  134. package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
  135. package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
  136. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
  137. package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
  138. package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
  139. package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
  140. package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
  141. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
  142. package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
  143. package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
  144. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
  145. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
  146. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
  147. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
  148. package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
  149. package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
  150. package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
  151. package/src/client/components/workspace/diff-panel/changes.ts +69 -0
  152. package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
  153. package/src/client/components/workspace/diff-panel/index.tsx +21 -1
  154. package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
  155. package/src/client/components/workspace/diff-panel/merge.ts +63 -68
  156. package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
  157. package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
  158. package/src/client/components/workspace/editor/FilePane.tsx +25 -1
  159. package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
  160. package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
  161. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
  162. package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
  163. package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
  164. package/src/client/components/workspace/git-panel/index.test.ts +46 -1
  165. package/src/client/components/workspace/git-panel/index.tsx +11 -38
  166. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
  167. package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
  168. package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
  169. package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
  170. package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
  171. package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
  172. package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
  173. package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
  174. package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
  175. package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
  176. package/src/client/hooks/chat/omp/index.ts +20 -0
  177. package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
  178. package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
  179. package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
  180. package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
  181. package/src/client/hooks/chat/omp/stream.ts +8 -1
  182. package/src/client/hooks/chat/timeline/index.ts +1 -1
  183. package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
  184. package/src/client/hooks/editor/blame-settings.ts +67 -0
  185. package/src/client/hooks/editor/blame.test.ts +272 -0
  186. package/src/client/hooks/editor/blame.ts +232 -0
  187. package/src/client/hooks/editor/file-editor-types.ts +23 -0
  188. package/src/client/hooks/editor/save-file.test.ts +20 -0
  189. package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
  190. package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
  191. package/src/client/hooks/editor/use-editor-drop.ts +19 -36
  192. package/src/client/hooks/editor/use-file-editor.ts +7 -1
  193. package/src/client/hooks/settings/providers/actions.ts +90 -194
  194. package/src/client/hooks/settings/providers/api.ts +7 -1
  195. package/src/client/hooks/settings/providers/index.ts +171 -59
  196. package/src/client/hooks/settings/providers/login.test.ts +79 -0
  197. package/src/client/hooks/settings/providers/login.ts +276 -0
  198. package/src/client/hooks/settings/providers/messages.ts +28 -0
  199. package/src/client/hooks/settings/providers/model-actions.ts +178 -0
  200. package/src/client/hooks/ui/editor-error-toast.ts +47 -0
  201. package/src/client/hooks/ui/open-file.ts +7 -0
  202. package/src/client/hooks/ui/toasts.ts +7 -0
  203. package/src/client/hooks/workspace/file-tabs.ts +4 -1
  204. package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
  205. package/src/client/hooks/workspace/folder-expansion.ts +33 -0
  206. package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
  207. package/src/client/hooks/workspace/git-actions.ts +29 -2
  208. package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
  209. package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
  210. package/src/client/lib/editor-errors.test.ts +85 -0
  211. package/src/client/lib/editor-errors.ts +71 -0
  212. package/src/client/lib/fs/resolve-open.test.ts +125 -0
  213. package/src/client/lib/fs/resolve-open.ts +90 -0
  214. package/src/client/lib/git/action-message.test.ts +82 -0
  215. package/src/client/lib/git/action-message.ts +160 -0
  216. package/src/client/lib/launch/device-files.test.ts +160 -0
  217. package/src/client/lib/launch/device-files.ts +197 -0
  218. package/src/client/lib/native/open-paths.test.ts +140 -0
  219. package/src/client/lib/native/open-paths.ts +157 -0
  220. package/src/client/lib/plugins/bootstrap.test.ts +1 -1
  221. package/src/client/main.tsx +20 -0
  222. package/src/server/db.server.test.ts +39 -0
  223. package/src/server/db.server.ts +21 -2
  224. package/src/server/lib/db/schema.ts +2 -0
  225. package/src/server/lib/fs/external-roots.test.ts +100 -0
  226. package/src/server/lib/fs/external-roots.ts +101 -0
  227. package/src/server/lib/fs/git-actions-branch.ts +15 -2
  228. package/src/server/lib/fs/git-actions-shared.ts +24 -0
  229. package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
  230. package/src/server/lib/fs/git-actions-worktree.ts +5 -1
  231. package/src/server/lib/fs/git-blame.test.ts +206 -0
  232. package/src/server/lib/fs/git-blame.ts +189 -0
  233. package/src/server/lib/fs/root.ts +14 -0
  234. package/src/server/lib/http/same-origin.ts +28 -7
  235. package/src/server/lib/models/catalog.server.ts +230 -0
  236. package/src/server/lib/models/catalog.test.ts +83 -0
  237. package/src/server/lib/models/credential-origin.server.ts +108 -0
  238. package/src/server/lib/models/credential-origin.test.ts +132 -0
  239. package/src/server/lib/models/provider-icon-fetch.ts +115 -0
  240. package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
  241. package/src/server/lib/models/provider-icon-parse.ts +139 -0
  242. package/src/server/lib/models/provider-icon-store.server.ts +118 -0
  243. package/src/server/lib/models/provider-icon-store.test.ts +107 -0
  244. package/src/server/lib/models/provider-icon.server.ts +209 -0
  245. package/src/server/lib/models/provider-items.server.ts +211 -37
  246. package/src/server/lib/models/provider-items.test.ts +201 -0
  247. package/src/server/lib/models/provider-registry.server.test.ts +27 -9
  248. package/src/server/lib/models/provider-registry.server.ts +160 -67
  249. package/src/server/lib/models/registry.server.test.ts +3 -3
  250. package/src/server/lib/models/registry.server.ts +8 -0
  251. package/src/server/lib/omp/config/definitions.test.ts +5 -4
  252. package/src/server/lib/omp/config/models-config.ts +42 -0
  253. package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
  254. package/src/server/lib/omp/config/provider-entry.ts +197 -0
  255. package/src/server/lib/omp/config/provider-seeds.ts +10 -0
  256. package/src/server/lib/omp/core/models-json.ts +69 -0
  257. package/src/server/lib/omp/session/messages.ts +17 -3
  258. package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
  259. package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
  260. package/src/server/lib/panels/catalog-offers.server.ts +68 -0
  261. package/src/server/lib/panels/git-update.server.test.ts +14 -0
  262. package/src/server/lib/panels/git-update.server.ts +63 -1
  263. package/src/server/lib/panels/manifest.test.ts +65 -0
  264. package/src/server/lib/panels/manifest.ts +55 -1
  265. package/src/server/lib/panels/offers.server.test.ts +191 -0
  266. package/src/server/lib/panels/offers.server.ts +108 -0
  267. package/src/server/lib/panels/registry.server.test.ts +35 -1
  268. package/src/server/lib/panels/registry.server.ts +51 -142
  269. package/src/server/lib/panels/scan.server.ts +162 -0
  270. package/src/server/lib/route-adapter.ts +13 -2
  271. package/src/server/lib/tray/tray.test.ts +2 -1
  272. package/src/server/lib/usage/providers.server.ts +4 -1
  273. package/src/server/routes/chat/session.ts +7 -1
  274. package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
  275. package/src/server/routes/fs/git.ts +17 -0
  276. package/src/server/routes/fs/grant.test.ts +135 -0
  277. package/src/server/routes/fs/grant.ts +79 -0
  278. package/src/server/routes/fs/index.ts +2 -0
  279. package/src/server/routes/fs/scope.ts +34 -17
  280. package/src/server/routes/omp/login.ts +41 -14
  281. package/src/server/routes/omp/routes.test.ts +23 -10
  282. package/src/server/routes/settings/index.ts +8 -0
  283. package/src/server/routes/settings/provider-entry.ts +108 -0
  284. package/src/server/routes/settings/provider-icon.ts +99 -0
  285. package/src/server/routes/settings/provider-model.ts +4 -1
  286. package/src/server/routes/settings/provider-refresh.ts +87 -0
  287. package/src/server/routes/settings/providers.ts +31 -2
  288. package/src/shared/lib/chat/omp/fold.test.ts +34 -0
  289. package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
  290. package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
  291. package/src/shared/lib/chat/omp/tool-results.ts +29 -3
  292. package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
  293. package/src/shared/lib/fs/git-blame.test.ts +266 -0
  294. package/src/shared/lib/fs/git-blame.ts +246 -0
  295. package/src/shared/lib/git/url.ts +18 -0
  296. package/src/shared/lib/markdown/sanitize.test.ts +57 -0
  297. package/src/shared/lib/markdown/sanitize.ts +30 -7
  298. package/src/shared/lib/models/provider/connection.ts +135 -0
  299. package/src/shared/lib/models/provider/dialect.test.ts +4 -2
  300. package/src/shared/lib/models/provider/dialect.ts +76 -6
  301. package/src/shared/lib/models/provider/models.ts +2 -0
  302. package/src/shared/lib/models/provider/origin.ts +94 -0
  303. package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
  304. package/src/shared/lib/models/server-cache.ts +8 -3
  305. package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
  306. package/src/shared/lib/omp/session/messages-map.ts +34 -2
  307. package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
  308. package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
  309. package/src/shared/lib/omp/session/prewarm.ts +23 -1
  310. package/src/shared/lib/omp/session/wait.test.ts +28 -0
  311. package/src/shared/lib/omp/session/wait.ts +38 -3
  312. package/src/shared/lib/panels/slot-labels.test.ts +61 -0
  313. package/src/shared/lib/panels/slot-labels.ts +133 -0
  314. package/src/shared/lib/workspace/panel-ids.ts +11 -0
  315. package/src/shared/types/fs.ts +6 -0
  316. package/src/shared/types/index.ts +1 -0
  317. package/src/shared/types/models.ts +12 -0
  318. package/src/shared/types/panels-registry.ts +277 -0
  319. package/src/shared/types/panels.ts +46 -213
  320. package/src/shared/types/settings/provider.ts +58 -0
  321. package/src/shared/types/settings/usage.ts +10 -0
  322. package/src/test-support/pristine-globals.ts +7 -0
  323. package/dist/client/static/js/index-bq6qeayr.css +0 -1
  324. package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
@@ -29,6 +29,7 @@
29
29
  * breaking a second read.
30
30
  */
31
31
 
32
+ import { deviceFileFor } from '@/client/lib/launch/device-files';
32
33
  import { fileHandleFor } from '@/client/lib/launch/file-handlers';
33
34
  import { getRawContentType } from '@/shared/lib/fs/file-kind';
34
35
 
@@ -101,6 +102,21 @@ export function byteSourceFor(target: {
101
102
  },
102
103
  };
103
104
  }
105
+ // The device registry comes first: a document a PHONE handed over has no
106
+ // handle and no server path — its bytes were pushed into the page by the
107
+ // shell (`client/lib/launch/device-files.ts`), and that map is the only copy.
108
+ const delivered = deviceFileFor(target.handleId);
109
+ if (delivered) {
110
+ const { bytes } = delivered;
111
+ return {
112
+ id: target.handleId as string,
113
+ url: null,
114
+ mimeType: delivered.mimeType ?? mimeType,
115
+ // A fresh `ArrayBuffer` per call, like every other source here: a parser
116
+ // may detach or transfer it, and the registry must survive a second read.
117
+ loadBytes: async () => bytes.slice().buffer as ArrayBuffer,
118
+ };
119
+ }
104
120
  const handle = fileHandleFor(target.handleId);
105
121
  if (handle) {
106
122
  return {
@@ -81,6 +81,8 @@ afterAll(() => {
81
81
  async function mount(options: {
82
82
  topicSync?: { ahead: number; behind: number };
83
83
  httpSync?: { ahead: number; behind: number };
84
+ /** What a POST to `/api/fs/git` answers — the action channel. */
85
+ action?: unknown;
84
86
  } = {}): Promise<void> {
85
87
  server = await startRealtimeTestServer(new Map<string, TopicResolver>([
86
88
  [TOPIC, async () => statusOf(1, options.topicSync)],
@@ -90,11 +92,14 @@ async function mount(options: {
90
92
  installDomGlobals(win);
91
93
  const target = globalThis as unknown as Record<string, unknown>;
92
94
  target.WebSocket = pristineWebSocket;
93
- target.fetch = async (input: unknown) => {
95
+ target.fetch = async (input: unknown, init?: RequestInit) => {
94
96
  const url = String(input);
95
97
  const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
96
98
  if (url.includes('/state')) return json({ sessionId: SESSION, state: {} });
97
99
  if (url.includes('reposOnly')) return json({ repos: ['.'], reposPending: false });
100
+ // The action channel, before the status read: a mutation and a read share
101
+ // `/api/fs/git` and differ only by method.
102
+ if (init?.method === 'POST' && options.action !== undefined) return json(options.action);
98
103
  // The panel's own HTTP read (mount + Refresh): EMPTY, deliberately.
99
104
  return json(statusOf(0, options.httpSync));
100
105
  };
@@ -219,6 +224,46 @@ describe('GitPanel sync badge', () => {
219
224
  });
220
225
  });
221
226
 
227
+ /**
228
+ * A mutation's outcome is REPORTED.
229
+ *
230
+ * The change list is the answer for a stage or a discard, but a Sync leaves the
231
+ * working tree byte-identical — without a toast the press has no observable
232
+ * effect at all, which is the reported "sync does nothing". The toast is
233
+ * portal-mounted to `document.body`, so the assertion is against the document
234
+ * rather than the panel's own container.
235
+ */
236
+ describe('GitPanel action toast', () => {
237
+ /** Click a toolbar control and let the request, the answer and the effect land. */
238
+ async function clickAndSettle(selector: string): Promise<void> {
239
+ const button = container.querySelector(selector);
240
+ if (!button) throw new Error(`no control for ${selector}`);
241
+ await act(async () => {
242
+ (button as HTMLElement).click();
243
+ });
244
+ for (let i = 0; i < 20; i += 1) await act(async () => {});
245
+ }
246
+
247
+ test('a successful Sync says so', async () => {
248
+ await mount({ action: { success: true } });
249
+ await clickAndSettle('button[aria-label="Sync with upstream"]');
250
+ expect(document.body.textContent).toContain('Synced with upstream');
251
+ });
252
+
253
+ test('a Sync that stopped on a conflict says the push did not run', async () => {
254
+ await mount({ action: { success: true, stopped: 'merge' } });
255
+ await clickAndSettle('button[aria-label="Sync with upstream"]');
256
+ expect(document.body.textContent).toContain('nothing was pushed');
257
+ expect(document.body.textContent).not.toContain('Synced with upstream');
258
+ });
259
+
260
+ test('a refused action reports the server sentence', async () => {
261
+ await mount({ action: { success: false, error: 'no upstream configured' } });
262
+ await clickAndSettle('button[aria-label="Sync with upstream"]');
263
+ expect(document.body.textContent).toContain('no upstream configured');
264
+ });
265
+ });
266
+
222
267
  /**
223
268
  * The commit modal's own cases live in `commit-modal.test.ts`: the two files
224
269
  * together exceeded the repo's line ceiling, and each mounts its own harness.
@@ -17,6 +17,7 @@ import { useGitActions } from '@/client/hooks/workspace/git-actions';
17
17
  import { useCommitBox } from '@/client/hooks/workspace/commit-box';
18
18
  import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
19
19
  import { isUnmergedCode } from '@/shared/lib/fs/git-unmerged';
20
+ import { useGitActionOutcome } from '@/client/hooks/workspace/git-action-outcome';
20
21
  import { confirmRequestFor } from '@/client/components/workspace/git-panel/confirm-request';
21
22
  import type { ConfirmRequest } from '@/client/components/workspace/git-panel/confirm-request';
22
23
 
@@ -67,18 +68,6 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
67
68
  // History and Graph states
68
69
  const [viewingOutput, setViewingOutput] = useState<CommitHistoryPage | null>(null);
69
70
  const [mounted, setMounted] = useState(false);
70
- /**
71
- * The payload this effect has already acted on.
72
- *
73
- * `actionFetcher.data` is STICKY — it holds the last response for the life of
74
- * the mount — while `loadRepo` is a dependency whose identity changes whenever
75
- * `rootPath` does. Switching to a session in another workspace therefore
76
- * re-ran the effect against the PREVIOUS history payload and reopened a modal
77
- * the user had already dismissed, which is the reported "clicking a session
78
- * item opens the commit modal". Consuming each response exactly once is what
79
- * makes the modal open because the user ASKED for it and nothing else.
80
- */
81
- const consumedActionRef = useRef<unknown>(null);
82
71
 
83
72
  const { toasts, pushToast, dismissToast } = useToasts();
84
73
 
@@ -93,32 +82,16 @@ export function GitPanel({ className = '', enabled = true, rootPath, refreshKey
93
82
  }
94
83
  }, [branchPrompt]);
95
84
 
96
- // Reload after action completes. A response is acted on ONCE: the fetcher
97
- // keeps its last payload, so without the guard any later run of this effect
98
- // (a new `loadRepo` identity, a re-render) would re-open the commit modal the
99
- // user just closed.
100
- useEffect(() => {
101
- if (actionFetcher.state === 'idle' && actionFetcher.data) {
102
- const payload = actionFetcher.data;
103
- if (payload === consumedActionRef.current) return;
104
- consumedActionRef.current = payload;
105
- if (payload.type === 'history' || payload.type === 'graph') {
106
- // `hasMore` and `total` are part of the page, not decoration: without
107
- // them the modal cannot know the branch holds more than the 50 rows it
108
- // was handed, and the header reports the page size as the total.
109
- setViewingOutput({
110
- title: payload.type === 'graph' ? 'Git Graph' : 'Commit History',
111
- data: payload.data || [],
112
- hasMore: payload.hasMore,
113
- total: payload.total,
114
- });
115
- } else if (payload.success) {
116
- loadRepo();
117
- } else {
118
- pushToast(payload.error || 'Git operation failed');
119
- }
120
- }
121
- }, [actionFetcher.state, actionFetcher.data, loadRepo]);
85
+ // Reload after an action completes, open the page a read answered with, and
86
+ // report a mutation's outcome — see `git-action-outcome.ts` for the
87
+ // consume-once rule and why a stage stays silent while a sync does not.
88
+ useGitActionOutcome({
89
+ fetcher: actionFetcher,
90
+ onPage: setViewingOutput,
91
+ onReload: loadRepo,
92
+ onSuccess: (message) => pushToast(message, 'success'),
93
+ onError: (message) => pushToast(message),
94
+ });
122
95
 
123
96
  useOnClickOutside(optionsRef, () => setShowOptions(false));
124
97
  useOnClickOutside(branchRef, () => setShowBranchMenu(false));
@@ -88,3 +88,69 @@ describe('model picker and the providerIcon slot', () => {
88
88
  expect(mark()?.getAttribute('viewBox')).toBe(PROVIDER_GLYPHS.deepseek.viewBox);
89
89
  });
90
90
  });
91
+
92
+ describe('composer row: provider mark and text grid', () => {
93
+ /** The row's plate — the fixed box that keeps every name at one x. */
94
+ function plate(): HTMLElement | null {
95
+ return container.querySelector('[role="button"] > div > span[aria-hidden]');
96
+ }
97
+
98
+ test('the provider mark sits on a fixed plate, so names share a left edge', () => {
99
+ mount({ id: 'v3', name: 'DeepSeek V3', provider: 'DeepSeek', providerIcon: 'deepseek' });
100
+
101
+ const box = plate();
102
+ expect(box).not.toBeNull();
103
+ expect(box?.style.width).toBe('18px');
104
+ expect(box?.style.height).toBe('18px');
105
+ });
106
+
107
+ test('a fetched web icon is drawn in colour on that plate', () => {
108
+ // The composer is the surface a user stares at; a provider whose site logo
109
+ // was fetched must not show initials here while Settings shows the logo.
110
+ mount({
111
+ id: 'v3',
112
+ name: 'DeepSeek V3',
113
+ provider: 'DeepSeek',
114
+ providerIconUrl: '/api/provider-icon?slug=deepseek&v=1700000000000',
115
+ });
116
+
117
+ const image = plate()?.querySelector('img') as HTMLImageElement | null;
118
+ expect(image).not.toBeNull();
119
+ expect(image?.getAttribute('src')).toBe('/api/provider-icon?slug=deepseek&v=1700000000000');
120
+ expect(image?.className).toContain('object-contain');
121
+ });
122
+
123
+ test('the model name takes the slack and the context badge is a fixed column', () => {
124
+ mount({ id: 'v3', name: 'DeepSeek V3', provider: 'DeepSeek', contextWindow: 200000 });
125
+
126
+ const name = container.querySelector('[role="button"] span[title="DeepSeek V3"]') as HTMLElement;
127
+ expect(name.className).toContain('flex-1');
128
+ expect(name.className).toContain('truncate');
129
+ const context = name.nextElementSibling as HTMLElement;
130
+ expect(context.className).toContain('w-11');
131
+ expect(context.className).toContain('text-right');
132
+ expect(context.className).toContain('tabular-nums');
133
+ });
134
+
135
+ test('a row with no context window keeps the column, so the names still align', () => {
136
+ mount({ id: 'v3', name: 'DeepSeek V3', provider: 'DeepSeek' });
137
+
138
+ const name = container.querySelector('[role="button"] span[title="DeepSeek V3"]') as HTMLElement;
139
+ const context = name.nextElementSibling as HTMLElement;
140
+ expect(context.textContent).toBe('');
141
+ expect(context.className).toContain('w-11');
142
+ });
143
+ });
144
+
145
+ describe('composer row: the context column is pinned', () => {
146
+ test('the right cluster is a fixed width, so a check or a pill cannot move it', () => {
147
+ // Measured in the browser before this: the context badge sat at x=572 on 94
148
+ // rows and x=547 on the one selected row, whose checkmark and wider thinking
149
+ // label grew the right cluster by 25px.
150
+ mount({ id: 'v3', name: 'DeepSeek V3', provider: 'DeepSeek', contextWindow: 128000, thinkingLevel: 'auto' });
151
+
152
+ const right = container.querySelector('[role="button"] > div:last-child') as HTMLElement;
153
+ expect(right.className).toContain('w-[100px]');
154
+ expect(right.className).toContain('justify-end');
155
+ });
156
+ });
@@ -2,7 +2,7 @@ import type { TargetedMouseEvent } from 'preact';
2
2
  import { Brain, Check, Command, GripVertical, Star } from 'lucide-preact';
3
3
  import type { AIModelOption } from '@/shared/types';
4
4
  import { formatContextWindow } from '@/shared/lib/code/format';
5
- import { ProviderIcon } from '@/client/components/common/provider-icon';
5
+ import { ProviderIconPlate } from '@/client/components/common/provider-icon/Plate';
6
6
 
7
7
  interface ModelDropdownItemProps {
8
8
  model: AIModelOption;
@@ -14,6 +14,17 @@ interface ModelDropdownItemProps {
14
14
  onMouseEnter: () => void;
15
15
  }
16
16
 
17
+ /**
18
+ * One model row in the composer's picker.
19
+ *
20
+ * The row is a GRID so the names line up down the list: a fixed grip slot, a
21
+ * fixed plate, a name that takes the slack, and a fixed right-aligned context
22
+ * column. Before, the mark was a raw 13px icon — an SVG for a brand, a
23
+ * text-width pill for the initials fallback — so every row's name started at a
24
+ * different x, and the context badge floated against whatever the name's length
25
+ * happened to be. A provider's own web icon is drawn in colour on the plate
26
+ * (see `ProviderIconPlate`); everything else stays monochrome.
27
+ */
17
28
  export function ModelDropdownItem({
18
29
  model,
19
30
  isSelected,
@@ -23,74 +34,74 @@ export function ModelDropdownItem({
23
34
  onCycleThinking,
24
35
  onMouseEnter,
25
36
  }: ModelDropdownItemProps) {
26
- // Provider / Agent icon renderer
27
- const renderIcon = () => {
28
- if (model.isCmdAgent) {
29
- return (
30
- <span
31
- className="inline-flex items-center justify-center w-4 h-4 rounded border border-ink/20 bg-ink/5 text-ink/80 flex-shrink-0"
32
- title="Autonomous Agent Command Mode [CMD]"
33
- >
34
- <Command size={10} />
35
- </span>
36
- );
37
- }
38
-
39
- // The provider's own mark, keyed on the catalog's `providerIcon` first so a
40
- // legacy key still resolves; unknown providers fall back to their initials.
41
- return (
42
- <ProviderIcon
43
- icon={model.providerIcon}
44
- slug={model.provider}
45
- name={model.provider}
46
- size={13}
47
- className="text-ink/70"
48
- />
49
- );
50
- };
51
-
52
37
  return (
53
38
  <div
54
39
  role="button"
55
40
  tabIndex={0}
56
41
  onClick={() => onSelect(model)}
57
42
  onMouseEnter={onMouseEnter}
58
- className={`group relative w-full flex items-center justify-between px-2.5 py-1.5 rounded-lg text-xs transition-colors cursor-pointer select-none ${
59
- isFocused
60
- ? 'bg-ink/10 text-ink'
61
- : isSelected
62
- ? 'bg-ink/5 text-ink'
43
+ className={`group relative w-full flex items-center justify-between gap-2 pl-1 pr-2 py-1.5 rounded-lg text-xs transition-colors cursor-pointer select-none ${
44
+ isFocused
45
+ ? 'bg-ink/10 text-ink'
46
+ : isSelected
47
+ ? 'bg-ink/5 text-ink'
63
48
  : 'text-ink/85 hover:bg-ink/5'
64
49
  }`}
65
50
  >
66
- {/* Left: Drag Handle, Icon, Title, Context */}
67
- <div className="flex items-center space-x-2 min-w-0 flex-1 mr-2">
68
- <GripVertical
69
- size={12}
70
- className="text-ink/20 group-hover:text-ink/50 transition-colors flex-shrink-0"
51
+ {/* Left: drag handle, plate, name, context. The grip keeps its own fixed
52
+ slot so a hover-only affordance cannot move the name. */}
53
+ <div className="flex items-center gap-2 min-w-0 flex-1">
54
+ <GripVertical
55
+ size={12}
56
+ className="text-ink/20 group-hover:text-ink/50 transition-colors flex-shrink-0"
71
57
  />
72
-
73
- {renderIcon()}
74
58
 
75
- <div className="flex items-center space-x-1.5 truncate">
76
- {model.isCmdAgent && (
77
- <span className="font-mono text-[11px] font-semibold text-ink/75 flex-shrink-0">
78
- [CMD]
79
- </span>
80
- )}
81
- <span className={`truncate ${isSelected ? 'font-semibold text-ink' : 'font-normal text-ink/90'}`}>
82
- {model.name}
59
+ {model.isCmdAgent ? (
60
+ <span
61
+ className="inline-flex items-center justify-center w-[18px] h-[18px] rounded-[5px] border border-ink/20 bg-ink/5 text-ink/80 flex-shrink-0"
62
+ title="Autonomous Agent Command Mode [CMD]"
63
+ >
64
+ <Command size={10} />
83
65
  </span>
84
- {model.contextWindow && (
85
- <span className="font-mono text-[10px] text-ink/45 flex-shrink-0">
86
- {formatContextWindow(model.contextWindow)}
87
- </span>
88
- )}
89
- </div>
66
+ ) : (
67
+ <ProviderIconPlate
68
+ provider={{
69
+ icon: model.providerIcon,
70
+ slug: model.provider,
71
+ name: model.provider,
72
+ ...(model.providerIconUrl ? { iconUrl: model.providerIconUrl } : {}),
73
+ }}
74
+ size={18}
75
+ />
76
+ )}
77
+
78
+ {model.isCmdAgent && (
79
+ <span className="font-mono text-[11px] font-semibold text-ink/75 flex-shrink-0">
80
+ [CMD]
81
+ </span>
82
+ )}
83
+ <span
84
+ className={`flex-1 min-w-0 truncate ${
85
+ isSelected ? 'font-semibold text-ink' : 'font-normal text-ink/90'
86
+ }`}
87
+ title={model.name}
88
+ >
89
+ {model.name}
90
+ </span>
91
+ {/* Fixed column: a number has to be comparable down the list, and a
92
+ badge that follows the name cannot be. */}
93
+ <span className="w-11 shrink-0 text-right font-mono text-[10px] tabular-nums text-ink/45">
94
+ {model.contextWindow ? formatContextWindow(model.contextWindow) : ''}
95
+ </span>
90
96
  </div>
91
97
 
92
- {/* Right: Thinking pill, Checkmark, Star */}
93
- <div className="flex items-center space-x-2 flex-shrink-0">
98
+ {/* Right: thinking pill, checkmark, star.
99
+ A FIXED width, right-aligned: the pill's label and the checkmark's
100
+ presence both change this cluster's width, which moved the context
101
+ column 25px to the left on the one selected row (measured: 547 vs 572).
102
+ Reserving the whole cluster pins that column, and the star — the one
103
+ control on every row — stays on the row's edge. */}
104
+ <div className="flex items-center justify-end gap-1.5 flex-shrink-0 w-[100px]">
94
105
  {model.thinkingLevel && (
95
106
  <button
96
107
  type="button"
@@ -99,16 +110,14 @@ export function ModelDropdownItem({
99
110
  onCycleThinking?.(model, e);
100
111
  }}
101
112
  title={`Thinking preset: ${model.thinkingLevel} (Click or use ← / → to change)`}
102
- className="inline-flex items-center space-x-1 px-1.5 py-0.5 rounded text-[10px] font-mono text-ink/70 bg-ink/5 hover:bg-ink/10 border border-ink/10 transition-colors cursor-pointer"
113
+ className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-mono text-ink/70 bg-ink/5 hover:bg-ink/10 border border-ink/10 transition-colors cursor-pointer"
103
114
  >
104
115
  <Brain size={10} className="text-ink/50" />
105
116
  <span>{model.thinkingLevel}</span>
106
117
  </button>
107
118
  )}
108
119
 
109
- {isSelected && (
110
- <Check size={13} className="text-ink flex-shrink-0" />
111
- )}
120
+ {isSelected && <Check size={13} className="text-ink flex-shrink-0" />}
112
121
 
113
122
  <button
114
123
  type="button"
@@ -116,9 +125,9 @@ export function ModelDropdownItem({
116
125
  title={model.isFavorite ? 'Remove from favorites' : 'Add to favorites'}
117
126
  className="p-1 rounded text-ink/30 hover:text-sky-400 hover:bg-ink/5 transition-colors cursor-pointer"
118
127
  >
119
- <Star
120
- size={13}
121
- className={model.isFavorite ? 'fill-sky-400 text-sky-400' : 'text-ink/30 hover:text-sky-400'}
128
+ <Star
129
+ size={13}
130
+ className={model.isFavorite ? 'fill-sky-400 text-sky-400' : 'text-ink/30 hover:text-sky-400'}
122
131
  />
123
132
  </button>
124
133
  </div>
@@ -2,7 +2,7 @@ import type { TargetedMouseEvent } from 'preact';
2
2
  import { ChevronDown, ChevronUp, History, Star } from 'lucide-preact';
3
3
  import type { AIModelOption } from '@/shared/types';
4
4
  import { ModelDropdownItem } from '@/client/components/workspace/model-dropdown/Item';
5
- import { ProviderIcon } from '@/client/components/common/provider-icon';
5
+ import { ProviderIconPlate } from '@/client/components/common/provider-icon/Plate';
6
6
  import { modelKey } from '@/shared/lib/models/identity';
7
7
 
8
8
  interface ModelDropdownSectionProps {
@@ -42,30 +42,47 @@ export function ModelDropdownSection({
42
42
 
43
43
  return (
44
44
  <div className="space-y-0.5">
45
+ {/* The header shares the row grid — a fixed grip slot, then the plate at
46
+ the same size the rows use — so a section title starts at the same x
47
+ as the model names under it. It used to start at its own icon's edge,
48
+ which left the title a few pixels left of every row beneath. */}
45
49
  <button
46
50
  type="button"
47
51
  onClick={() => onToggleCollapse(id)}
48
- className="w-full flex items-center justify-between px-2 py-1 text-[11px] font-semibold text-ink/60 uppercase tracking-wider hover:text-ink cursor-pointer select-none"
52
+ className="w-full flex items-center justify-between gap-2 pl-1 pr-2 py-1 text-[11px] font-semibold text-ink/60 uppercase tracking-wider hover:text-ink cursor-pointer select-none"
49
53
  >
50
- <div className="flex items-center space-x-1.5">
51
- {iconType === 'star' && <Star size={12} className="fill-sky-400 text-sky-400" />}
52
- {iconType === 'recent' && <History size={12} className="text-ink/60" />}
54
+ <div className="flex items-center gap-2 min-w-0">
55
+ <span className="w-3 shrink-0" aria-hidden="true" />
56
+ {iconType === 'star' && (
57
+ <span className="inline-flex items-center justify-center w-[18px] h-[18px] shrink-0">
58
+ <Star size={12} className="fill-sky-400 text-sky-400" />
59
+ </span>
60
+ )}
61
+ {iconType === 'recent' && (
62
+ <span className="inline-flex items-center justify-center w-[18px] h-[18px] shrink-0">
63
+ <History size={12} className="text-ink/60" />
64
+ </span>
65
+ )}
53
66
  {iconType === 'provider' && (
54
67
  // The section's own provider, taken from a row rather than the
55
- // uppercased group key, so the mark resolves off the real slug.
56
- <ProviderIcon
57
- icon={models[0]?.providerIcon}
58
- slug={models[0]?.provider ?? id}
59
- name={models[0]?.provider ?? id}
60
- size={12}
68
+ // uppercased group key, so the mark resolves off the real slug —
69
+ // and its fetched web icon, when the server has one.
70
+ <ProviderIconPlate
71
+ provider={{
72
+ icon: models[0]?.providerIcon,
73
+ slug: models[0]?.provider ?? id,
74
+ name: models[0]?.provider ?? id,
75
+ ...(models[0]?.providerIconUrl ? { iconUrl: models[0].providerIconUrl } : {}),
76
+ }}
77
+ size={18}
61
78
  />
62
79
  )}
63
- <span>{title}</span>
80
+ <span className="min-w-0 truncate">{title}</span>
64
81
  </div>
65
82
  {isCollapsed ? (
66
- <ChevronDown size={12} className="text-ink/40" />
83
+ <ChevronDown size={12} className="text-ink/40 shrink-0" />
67
84
  ) : (
68
- <ChevronUp size={12} className="text-ink/40" />
85
+ <ChevronUp size={12} className="text-ink/40 shrink-0" />
69
86
  )}
70
87
  </button>
71
88
 
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Whether a model-picker section (a provider, FAVORITES, RECENT) is collapsed,
8
+ * remembered per session.
9
+ *
10
+ * The state used to live in a `useState` inside `ModelDropdown`, so a reload —
11
+ * the exact restart the stale-list bug forced — or a session switch reset every
12
+ * section, and a reader who had folded the providers they never use had to fold
13
+ * them again. It is a preference about a list, which is what `session_ui_state`
14
+ * holds (the same slot family `chat.toolOpen` uses).
15
+ *
16
+ * The provider is read OPTIONALLY, the way `useScrollRestore` reads it: the
17
+ * composer's unit tests mount `ModelDropdown` without a `SessionStateProvider`
18
+ * (the provider's own load kicks a realtime reconnect that outlives those
19
+ * files), and a null context makes this hook inert — the store APIs take a
20
+ * null session and do nothing — rather than throwing from a component that
21
+ * has no blob to persist into.
22
+ */
23
+
24
+ import { useCallback, useContext, useEffect, useState } from 'preact/hooks';
25
+ import { SessionStateContext } from '@/client/hooks/workspace/session-state/context';
26
+ import { getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
27
+ import { subscribeSessionReplaced } from '@/shared/lib/workspace/session-state/listeners';
28
+
29
+ /** Session slot holding `{ [section]: collapsed }` for the model picker. */
30
+ export const MODEL_DROPDOWN_COLLAPSED_KEY = 'chat.modelDropdownCollapsed';
31
+
32
+ export function useCollapsedSections(): [Record<string, boolean>, (section: string) => void] {
33
+ const context = useContext(SessionStateContext);
34
+ const sessionId = context?.sessionId ?? null;
35
+ const ready = context?.ready ?? false;
36
+
37
+ const [collapsed, setCollapsed] = useState<Record<string, boolean>>(() =>
38
+ sessionId
39
+ ? (getSessionValue<Record<string, boolean>>(sessionId, MODEL_DROPDOWN_COLLAPSED_KEY) ?? {})
40
+ : {},
41
+ );
42
+
43
+ // Restore the stored value once the session's blob landed (or reset to
44
+ // empty for a session that never stored one). The initial useState already
45
+ // read the store; this catches the load landing after the first render.
46
+ useEffect(() => {
47
+ if (!ready || !sessionId) return;
48
+ setCollapsed(getSessionValue<Record<string, boolean>>(sessionId, MODEL_DROPDOWN_COLLAPSED_KEY) ?? {});
49
+ }, [sessionId, ready]);
50
+
51
+ // The store replaced this session's blob under the copy (a load landing, an
52
+ // adoption migrate, a delete) — re-read on the event, same as `useSessionState`.
53
+ useEffect(() => {
54
+ if (!sessionId) return;
55
+ return subscribeSessionReplaced(sessionId, () => {
56
+ setCollapsed(getSessionValue<Record<string, boolean>>(sessionId, MODEL_DROPDOWN_COLLAPSED_KEY) ?? {});
57
+ });
58
+ }, [sessionId]);
59
+
60
+ const toggleSection = useCallback(
61
+ (section: string) => {
62
+ setCollapsed(prev => {
63
+ const next = { ...prev, [section]: !prev[section] };
64
+ setSessionKey(sessionId, MODEL_DROPDOWN_COLLAPSED_KEY, next);
65
+ return next;
66
+ });
67
+ },
68
+ [sessionId],
69
+ );
70
+
71
+ return [collapsed, toggleSection];
72
+ }