@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
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The blame labels and the card's interaction, mounted on a real editor view.
8
+ *
9
+ * Everything here is a DOM fact rather than a state assertion, because that is
10
+ * where this feature fails: a `Decoration.widget` at the wrong offset renders
11
+ * (the label just sits on the wrong line), a plugin that never rebuilds on a
12
+ * viewport change renders labels for the lines the reader scrolled away from,
13
+ * and an interaction that closes on the wrong event either makes the card
14
+ * impossible to select or leaves it on screen over a different file.
15
+ */
16
+
17
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
18
+ import { Window } from 'happy-dom';
19
+ import { Compartment, EditorState } from '@codemirror/state';
20
+ import { EditorView } from '@codemirror/view';
21
+
22
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
23
+ import type { BlamePayload } from '@/shared/lib/fs/git-blame';
24
+ import type { BlameSnapshot, BlameHistoryResult, FileBlame } from '@/client/hooks/editor/blame';
25
+ import { blameExtensions } from '@/client/components/common/code-surface/blame';
26
+ import { surfaceExtensions } from '@/client/components/common/code-surface/extensions';
27
+ import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
28
+
29
+ const SHA = 'a'.repeat(40);
30
+ const OTHER = 'b'.repeat(40);
31
+
32
+ const PAYLOAD: BlamePayload = {
33
+ available: true,
34
+ head: SHA,
35
+ lines: 6,
36
+ runs: [
37
+ { from: 1, to: 3, sha: SHA },
38
+ { from: 4, to: 6, sha: OTHER },
39
+ ],
40
+ commits: {
41
+ [SHA]: { sha: SHA, author: 'Ada Lovelace', mail: 'ada@example.com', time: 1_700_000_000, summary: 'feat: open' },
42
+ [OTHER]: { sha: OTHER, author: 'Grace Hopper', mail: 'grace@example.com', time: 1_690_000_000, summary: 'fix: bug' },
43
+ },
44
+ };
45
+
46
+ const DOC = 'one\ntwo\nthree\nfour\nfive\nsix\n';
47
+
48
+ interface FakeController {
49
+ controller: FileBlame;
50
+ /** Replace the answer the labels read, and notify — the controller's own path. */
51
+ publish(snapshot: BlameSnapshot): void;
52
+ readonly calls: number[];
53
+ }
54
+
55
+ function fakeController(
56
+ initial: BlameSnapshot,
57
+ options: { stale?: boolean; history?: BlameHistoryResult } = {},
58
+ ): FakeController {
59
+ const listeners = new Set<() => void>();
60
+ const calls: number[] = [];
61
+ let current = initial;
62
+ const controller: FileBlame = {
63
+ ensure: () => {},
64
+ reload: () => {},
65
+ history: async (line) => {
66
+ calls.push(line);
67
+ return options.history ?? { entries: [], truncated: false };
68
+ },
69
+ snapshot: () => current,
70
+ stale: () => options.stale === true,
71
+ subscribe: (listener) => {
72
+ listeners.add(listener);
73
+ return () => listeners.delete(listener);
74
+ },
75
+ };
76
+ return {
77
+ controller,
78
+ publish(next) {
79
+ current = next;
80
+ for (const listener of listeners) listener();
81
+ },
82
+ get calls() {
83
+ return calls;
84
+ },
85
+ };
86
+ }
87
+
88
+ /**
89
+ * Globals CM6's view needs and happy-dom does not install on `globalThis`.
90
+ * `fold-stack.test.ts` carries the same list for the same reason: the view
91
+ * mounts a `MutationObserver` in its constructor.
92
+ */
93
+ const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame'] as const;
94
+ const nativeGlobals: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
95
+
96
+ let host: HTMLElement;
97
+ let view: EditorView | null = null;
98
+
99
+ let fake: FakeController | null = null;
100
+
101
+ function mount(snapshot: BlameSnapshot, options: { compact?: boolean } = {}): EditorView {
102
+ fake = fakeController(snapshot);
103
+ view = new EditorView({
104
+ state: EditorState.create({
105
+ doc: DOC,
106
+ extensions: [blameExtensions({ controller: fake.controller, compact: options.compact })],
107
+ }),
108
+ parent: host,
109
+ });
110
+ return view;
111
+ }
112
+
113
+ function labels(): HTMLElement[] {
114
+ return [...host.querySelectorAll<HTMLElement>('.cm-blame-label')];
115
+ }
116
+
117
+ beforeAll(() => {
118
+ const win = new Window({ url: 'http://localhost' });
119
+ installDomGlobals(win);
120
+ const target = globalThis as unknown as Record<string, unknown>;
121
+ for (const key of EXTRA_GLOBALS) {
122
+ nativeGlobals[key] = target[key];
123
+ target[key] = (win as unknown as Record<string, unknown>)[key];
124
+ }
125
+ host = document.body.appendChild(document.createElement('div'));
126
+ });
127
+
128
+ afterAll(() => {
129
+ const target = globalThis as unknown as Record<string, unknown>;
130
+ for (const key of EXTRA_GLOBALS) {
131
+ if (nativeGlobals[key] === undefined) delete target[key];
132
+ else target[key] = nativeGlobals[key];
133
+ }
134
+ restoreDomGlobals();
135
+ });
136
+
137
+ beforeEach(() => {
138
+ view?.destroy();
139
+ view = null;
140
+ host.replaceChildren();
141
+ for (const card of document.querySelectorAll('[aria-label="Line blame"]')) card.remove();
142
+ });
143
+
144
+ describe('blame labels', () => {
145
+ test('one label per run, on the run’s FIRST line', () => {
146
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
147
+ const rendered = labels();
148
+ expect(rendered).toHaveLength(2);
149
+ expect(rendered[0].dataset.blameLine).toBe('1');
150
+ expect(rendered[1].dataset.blameLine).toBe('4');
151
+ });
152
+
153
+ test('the label names the author and carries the subject as its title', () => {
154
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
155
+ const [first, second] = labels();
156
+ expect(first.textContent).toContain('Ada Lovelace');
157
+ expect(first.title).toBe('feat: open');
158
+ expect(second.textContent).toContain('Grace Hopper');
159
+ });
160
+
161
+ test('compact mode drops the age, for a narrow panel', () => {
162
+ mount({ status: 'ready', payload: PAYLOAD, message: null }, { compact: true });
163
+ expect(labels()[0].textContent).toBe('Ada Lovelace');
164
+ });
165
+
166
+ test('an uncommitted run wears no label at all', () => {
167
+ const uncommitted = '0'.repeat(40);
168
+ mount({
169
+ status: 'ready',
170
+ message: null,
171
+ payload: {
172
+ ...PAYLOAD,
173
+ runs: [{ from: 1, to: 6, sha: uncommitted }],
174
+ commits: { [uncommitted]: { sha: uncommitted, author: 'Not Committed Yet', mail: '', time: 0, summary: '' } },
175
+ },
176
+ });
177
+ expect(labels()).toHaveLength(0);
178
+ });
179
+
180
+ test('an edit drops the labels until a NEW payload arrives', () => {
181
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
182
+ expect(labels().length).toBeGreaterThan(0);
183
+ view!.dispatch({ changes: { from: 0, insert: 'zero\n' } });
184
+ // Every line number after the edit now names a different line.
185
+ expect(labels()).toHaveLength(0);
186
+
187
+ // A cache HIT hands back the same object, which cannot describe the edit.
188
+ fake!.publish({ status: 'ready', payload: PAYLOAD, message: null });
189
+ expect(labels()).toHaveLength(0);
190
+
191
+ // A new answer does describe it: the bridge dispatches it, so the DOM
192
+ // follows with no transaction from the caller.
193
+ fake!.publish({ status: 'ready', payload: { ...PAYLOAD, lines: 7 }, message: null });
194
+ expect(labels().length).toBeGreaterThan(0);
195
+ });
196
+
197
+ test('an unavailable payload draws nothing rather than empty labels', () => {
198
+ mount({
199
+ status: 'unavailable',
200
+ message: null,
201
+ payload: { available: false, head: null, lines: 0, runs: [], commits: {}, reason: 'untracked' },
202
+ });
203
+ expect(labels()).toHaveLength(0);
204
+ });
205
+ });
206
+
207
+ describe('the gutter target, on the real extension stack', () => {
208
+ test('a hover on a line number opens the card for that line', () => {
209
+ // The gutter only exists because `lineNumbers()` is installed, so this
210
+ // mounts the component's own stack rather than the blame extensions alone —
211
+ // the same reason `fold-stack.test.ts` mounts it for `foldGutter`.
212
+ const { controller } = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
213
+ view = new EditorView({
214
+ state: EditorState.create({
215
+ doc: DOC,
216
+ extensions: surfaceExtensions({
217
+ language: 'typescript',
218
+ wordWrapCompartment: new Compartment(),
219
+ readOnlyCompartment: new Compartment(),
220
+ themeCompartment: new Compartment(),
221
+ languageCompartment: new Compartment(),
222
+ indentCompartment: new Compartment(),
223
+ typingCompartment: new Compartment(),
224
+ blameCompartment: new Compartment(),
225
+ blame: blameExtensions({ controller }),
226
+ wordWrap: false,
227
+ readOnly: false,
228
+ themes: SHIKI_THEMES,
229
+ indentUnitText: ' ',
230
+ typing: { autoCloseBrackets: false, autocomplete: false },
231
+ onDocChange: () => {},
232
+ onState: () => {},
233
+ }),
234
+ }),
235
+ parent: host,
236
+ });
237
+
238
+ const gutters = host.querySelectorAll<HTMLElement>('.cm-lineNumbers .cm-gutterElement');
239
+ expect(gutters.length).toBeGreaterThan(0);
240
+ // The first row is line 1; the second is line 2, inside the first run.
241
+ gutters[1].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
242
+ expect(document.querySelector('[aria-label="Line blame"]')?.textContent).toContain('Ada Lovelace');
243
+ });
244
+ });
245
+
246
+ describe('the blame card', () => {
247
+ test('a hover on a label opens the card for that line', () => {
248
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
249
+ const target = labels()[1];
250
+ target.dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
251
+
252
+ const card = document.querySelector<HTMLElement>('[aria-label="Line blame"]');
253
+ expect(card).not.toBeNull();
254
+ expect(card!.textContent).toContain('Grace Hopper');
255
+ });
256
+
257
+ test('a press on a label opens it too, which is the phone’s only path', () => {
258
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
259
+ labels()[0].dispatchEvent(new window.MouseEvent('mousedown', { bubbles: true }));
260
+ expect(document.querySelector('[aria-label="Line blame"]')?.textContent).toContain('Ada Lovelace');
261
+ });
262
+
263
+
264
+ test('a press outside the card closes it', () => {
265
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
266
+ labels()[0].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
267
+ expect(document.querySelector('[aria-label="Line blame"]')).not.toBeNull();
268
+
269
+ document.body.dispatchEvent(new window.MouseEvent('mousedown', { bubbles: true }));
270
+ expect(document.querySelector('[aria-label="Line blame"]')).toBeNull();
271
+ });
272
+
273
+ test('a press inside the card leaves it open, so its text can be selected', () => {
274
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
275
+ labels()[0].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
276
+ const card = document.querySelector<HTMLElement>('[aria-label="Line blame"]')!;
277
+
278
+ card.dispatchEvent(new window.MouseEvent('mousedown', { bubbles: true }));
279
+ expect(document.querySelector('[aria-label="Line blame"]')).not.toBeNull();
280
+ });
281
+
282
+ test('Escape closes it', () => {
283
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
284
+ labels()[0].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
285
+ document.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
286
+ expect(document.querySelector('[aria-label="Line blame"]')).toBeNull();
287
+ });
288
+
289
+ test('an edit closes it: the line it named has moved', () => {
290
+ mount({ status: 'ready', payload: PAYLOAD, message: null });
291
+ labels()[0].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
292
+ view!.dispatch({ changes: { from: 0, insert: 'x' } });
293
+ expect(document.querySelector('[aria-label="Line blame"]')).toBeNull();
294
+ });
295
+
296
+ test('destroying the view removes the card it opened', () => {
297
+ const mounted = mount({ status: 'ready', payload: PAYLOAD, message: null });
298
+ labels()[0].dispatchEvent(new window.MouseEvent('mouseover', { bubbles: true }));
299
+ mounted.destroy();
300
+ view = null;
301
+ expect(document.querySelector('[aria-label="Line blame"]')).toBeNull();
302
+ });
303
+ });
@@ -0,0 +1,227 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Line blame as the editor draws it: a label at the end of each run, and the
8
+ * card that opens from it.
9
+ *
10
+ * ## The label is a WIDGET, not a mark
11
+ *
12
+ * A `Decoration.mark` over the line's text is part of the document: the caret
13
+ * can land in it, `⌘C` copies it, and a replace-all would rewrite it. A widget
14
+ * at `line.to` is none of those things — it is drawn, it is not the file.
15
+ *
16
+ * ## Decorations are built for the VIEWPORT only
17
+ *
18
+ * One widget per run on a 20 000-line file is 2 249 DOM nodes on top of the
19
+ * document, and CM6 would lay all of them out on every scroll. The plugin
20
+ * builds the ranges the viewport can show (plus a screen of context), which is
21
+ * the same bound the Shiki tokenizer uses for the same reason.
22
+ *
23
+ * ## The answer is a STATE FIELD, fed by a bridge plugin
24
+ *
25
+ * The controller the panel owns is the source of truth, but a plugin that read
26
+ * it directly could not repaint: replacing a plugin's `decorations` outside a
27
+ * transaction leaves the DOM showing the previous set until something else
28
+ * dispatches. Measured in the component test — a fresh payload produced no
29
+ * labels at all until an unrelated transaction ran. So a small bridge
30
+ * subscribes to the controller and dispatches the payload as an effect, and the
31
+ * labels are a pure function of state.
32
+ *
33
+ * The field also carries what the controller cannot: "the document moved since
34
+ * this answer arrived". An edit shifts every line number, so the labels stop
35
+ * being drawn until a new payload lands — and a cache HIT hands back the same
36
+ * object, which cannot describe the edit either, so the flag is cleared by a
37
+ * new IDENTITY rather than by any notification.
38
+ *
39
+ * The hover target and the card live in `blame-hover.ts`: they are DOM
40
+ * interaction, and this module is the drawing.
41
+ */
42
+
43
+ import { Decoration, EditorView, ViewPlugin, WidgetType, type DecorationSet, type ViewUpdate } from '@codemirror/view';
44
+ import { StateEffect, StateField, type Extension } from '@codemirror/state';
45
+
46
+ import { formatBlameAge, isUncommittedSha, type BlamePayload } from '@/shared/lib/fs/git-blame';
47
+ import type { FileBlame } from '@/client/hooks/editor/blame';
48
+ import { blameInteraction } from '@/client/components/common/code-surface/blame-hover';
49
+
50
+ /** Lines of context above and below the viewport the labels are built for. */
51
+ const CONTEXT_LINES = 40;
52
+
53
+ /** What the labels are drawn from: the answer, and whether it still fits. */
54
+ export interface BlameViewState {
55
+ payload: BlamePayload | null;
56
+ /** The document changed since this payload was read. */
57
+ stale: boolean;
58
+ }
59
+
60
+ /** Install a payload the controller just produced. */
61
+ export const setBlame = StateEffect.define<BlameViewState>();
62
+
63
+ /**
64
+ * The field, seeded from the controller.
65
+ *
66
+ * A factory rather than a module constant because `create` reads the answer the
67
+ * controller already holds: a document opened with a cached blame must draw its
68
+ * labels on the first paint, and a plugin cannot dispatch during the view's own
69
+ * construction (CM6 throws "Calls to EditorView.update are not allowed while an
70
+ * update is in progress").
71
+ */
72
+ function blameField(controller: FileBlame): StateField<BlameViewState> {
73
+ return StateField.define<BlameViewState>({
74
+ create: () => ({ payload: controller.snapshot().payload, stale: false }),
75
+ update(value, tr) {
76
+ let next = value;
77
+ for (const effect of tr.effects) {
78
+ if (!effect.is(setBlame)) continue;
79
+ // A DIFFERENT payload is a fresh answer about the document as it is now;
80
+ // the same one is a cache hit and describes the bytes before the edit.
81
+ next =
82
+ effect.value.payload !== value.payload
83
+ ? { payload: effect.value.payload, stale: false }
84
+ : { payload: value.payload, stale: value.stale };
85
+ }
86
+ if (tr.docChanged && !next.stale) next = { payload: next.payload, stale: true };
87
+ return next;
88
+ },
89
+ });
90
+ }
91
+
92
+ /** `Ada Lovelace · 4d ago`, or just the name where the panel is narrow. */
93
+ function labelText(payload: BlamePayload, sha: string, compact: boolean): string | null {
94
+ const commit = payload.commits[sha];
95
+ if (!commit || isUncommittedSha(sha)) return null;
96
+ const author = commit.author.trim() || 'Unknown';
97
+ return compact ? author : `${author} · ${formatBlameAge(commit.time)}`;
98
+ }
99
+
100
+ class BlameLabel extends WidgetType {
101
+ constructor(
102
+ readonly line: number,
103
+ readonly text: string,
104
+ readonly title: string,
105
+ ) {
106
+ super();
107
+ }
108
+
109
+ override eq(other: BlameLabel): boolean {
110
+ return other.line === this.line && other.text === this.text && other.title === this.title;
111
+ }
112
+
113
+ override toDOM(): HTMLElement {
114
+ const span = document.createElement('span');
115
+ span.className = 'cm-blame-label';
116
+ // The interaction plugin reads these two off the DOM event's target, which
117
+ // is how a hover reaches the controller without a listener per label.
118
+ span.dataset.blameLine = String(this.line);
119
+ span.title = this.title;
120
+ span.textContent = this.text;
121
+ return span;
122
+ }
123
+ }
124
+
125
+ /** The runs the viewport can show, one label on each run's first visible line. */
126
+ function buildDecorations(state: BlameViewState, view: EditorView, compact: boolean): DecorationSet {
127
+ const { payload, stale } = state;
128
+ if (!payload?.available || stale) return Decoration.none;
129
+
130
+ const last = Math.min(payload.lines, view.state.doc.lines);
131
+ if (last < 1) return Decoration.none;
132
+ const top = view.state.doc.lineAt(Math.max(0, Math.min(view.viewport.from, view.state.doc.length))).number;
133
+ const bottom = view.state.doc.lineAt(Math.max(0, Math.min(view.viewport.to, view.state.doc.length))).number;
134
+ const startLine = Math.max(1, top - CONTEXT_LINES);
135
+ const endLine = Math.min(last, bottom + CONTEXT_LINES);
136
+
137
+ const ranges: { from: number; deco: Decoration }[] = [];
138
+ for (const run of payload.runs) {
139
+ // Only a run's first VISIBLE line wears the label: a 200-line block would
140
+ // otherwise repeat one author down the whole screen.
141
+ const line = Math.max(run.from, startLine);
142
+ if (line > run.to || line > endLine) continue;
143
+ const text = labelText(payload, run.sha, compact);
144
+ if (!text) continue;
145
+ const commit = payload.commits[run.sha];
146
+ const docLine = view.state.doc.line(line);
147
+ ranges.push({
148
+ from: docLine.to,
149
+ deco: Decoration.widget({
150
+ widget: new BlameLabel(docLine.number, text, commit.summary || commit.sha),
151
+ side: 1,
152
+ }),
153
+ });
154
+ }
155
+ // The builder requires ascending positions, and the runs are already sorted.
156
+ return Decoration.set(
157
+ ranges.map((entry) => entry.deco.range(entry.from)),
158
+ true,
159
+ );
160
+ }
161
+
162
+ /** Labels for the viewport, rebuilt when the payload or the visible lines move. */
163
+ function blameLabels(field: StateField<BlameViewState>, compact: boolean): Extension {
164
+ return ViewPlugin.fromClass(
165
+ class {
166
+ decorations: DecorationSet;
167
+
168
+ constructor(readonly view: EditorView) {
169
+ this.decorations = buildDecorations(view.state.field(field), view, compact);
170
+ }
171
+
172
+ update(update: ViewUpdate) {
173
+ const moved = update.startState.field(field) !== update.state.field(field);
174
+ if (!moved && !update.docChanged && !update.viewportChanged) return;
175
+ this.decorations = buildDecorations(update.state.field(field), update.view, compact);
176
+ }
177
+ },
178
+ { decorations: (plugin) => plugin.decorations },
179
+ );
180
+ }
181
+
182
+ /**
183
+ * The bridge: the controller's answer, dispatched into the field.
184
+ *
185
+ * A plugin rather than an effect in the component, because the answer arrives
186
+ * on the controller's own schedule (a fetch) and the component holds no view to
187
+ * dispatch to. It never publishes during the view's construction — that throws
188
+ * — because the field's own `create` already read the current answer.
189
+ */
190
+ function blameBridge(controller: FileBlame): Extension {
191
+ return ViewPlugin.define((view) => {
192
+ let alive = true;
193
+ const publish = () => {
194
+ if (!alive) return;
195
+ const snapshot = controller.snapshot();
196
+ view.dispatch({ effects: setBlame.of({ payload: snapshot.payload, stale: false }) });
197
+ };
198
+ const unsubscribe = controller.subscribe(publish);
199
+ return {
200
+ destroy() {
201
+ alive = false;
202
+ unsubscribe();
203
+ },
204
+ };
205
+ });
206
+ }
207
+
208
+ export interface BlameExtensionOptions {
209
+ controller: FileBlame;
210
+ /** Draw the label at all. Off keeps the card, which is the feature. */
211
+ inline?: boolean;
212
+ /** The author alone, for a narrow panel or a phone. */
213
+ compact?: boolean;
214
+ }
215
+
216
+ /**
217
+ * The whole feature as one extension: the field, the labels, the bridge and the
218
+ * card's interaction.
219
+ *
220
+ * `inline: false` keeps everything except the label, so the card stays reachable
221
+ * from the label when it is on — and the gutter's line number is the other
222
+ * hover target the interaction serves.
223
+ */
224
+ export function blameExtensions({ controller, inline = true, compact = false }: BlameExtensionOptions): Extension[] {
225
+ const field = blameField(controller);
226
+ return [field, blameBridge(controller), inline ? blameLabels(field, compact) : [], blameInteraction(controller)];
227
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Conflict markers: what is painted, and what is counted.
8
+ *
9
+ * Both halves have a way of looking right while being wrong:
10
+ *
11
+ * - A decorator whose regexp is not anchored to a line start also paints the
12
+ * `<<<<<<<` inside a string, which is the one place a marker is NOT a conflict.
13
+ * - `countConflicts` counting every occurrence would report a conflict for a
14
+ * file that merely mentions the marker in its own documentation — including
15
+ * this repository's wiki.
16
+ */
17
+
18
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
19
+ import { Window } from 'happy-dom';
20
+ import { EditorState } from '@codemirror/state';
21
+ import { EditorView } from '@codemirror/view';
22
+
23
+ import { conflictMarkers, countConflicts } from '@/client/components/common/code-surface/conflict-markers';
24
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
25
+
26
+ const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame'] as const;
27
+ const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
28
+
29
+ let host: HTMLElement;
30
+
31
+ beforeAll(() => {
32
+ const win = new Window({ url: 'http://localhost' });
33
+ installDomGlobals(win);
34
+ const target = globalThis as unknown as Record<string, unknown>;
35
+ for (const key of EXTRA_GLOBALS) {
36
+ native[key] = target[key];
37
+ target[key] = (win as unknown as Record<string, unknown>)[key];
38
+ }
39
+ host = document.body.appendChild(document.createElement('div'));
40
+ });
41
+
42
+ afterAll(() => {
43
+ const target = globalThis as unknown as Record<string, unknown>;
44
+ for (const key of EXTRA_GLOBALS) {
45
+ if (native[key] === undefined) delete target[key];
46
+ else target[key] = native[key];
47
+ }
48
+ restoreDomGlobals();
49
+ });
50
+
51
+ /** The classes the plugin painted, by line number, with the line's own text. */
52
+ function paintedLines(doc: string): Array<{ line: number; classes: string[]; text: string }> {
53
+ const view = new EditorView({
54
+ parent: host,
55
+ state: EditorState.create({ doc, extensions: [conflictMarkers()] }),
56
+ });
57
+ const lines = Array.from(view.contentDOM.querySelectorAll('.cm-line'));
58
+ const painted = lines.map((element, index) => ({
59
+ line: index + 1,
60
+ classes: Array.from(element.classList).filter((name) => name.startsWith('cm-conflict-')),
61
+ text: element.textContent ?? '',
62
+ }));
63
+ view.destroy();
64
+ return painted.filter((entry) => entry.classes.length > 0);
65
+ }
66
+
67
+ const CONFLICT = [
68
+ 'before();',
69
+ '<<<<<<< HEAD',
70
+ 'ours();',
71
+ '=======',
72
+ 'theirs();',
73
+ '>>>>>>> feature/x',
74
+ 'after();',
75
+ ].join('\n');
76
+
77
+ describe('conflictMarkers', () => {
78
+ test('paints ours, the base section and theirs, and leaves the separator alone', () => {
79
+ const doc = ['<<<<<<< HEAD', 'ours();', '||||||| base', 'base();', '=======', 'theirs();', '>>>>>>> x'].join('\n');
80
+ expect(paintedLines(doc)).toEqual([
81
+ { line: 1, classes: ['cm-conflict-ours'], text: '<<<<<<< HEAD' },
82
+ { line: 3, classes: ['cm-conflict-base'], text: '||||||| base' },
83
+ { line: 7, classes: ['cm-conflict-theirs'], text: '>>>>>>> x' },
84
+ ]);
85
+ });
86
+
87
+ test('the marker text is still rendered, not swallowed by the band', () => {
88
+ // The regression this pins: a line decoration added over the MATCHED RANGE
89
+ // (`MatchDecorator`'s shape) rendered the marker lines as blank rows while
90
+ // the document still held their text. A band is a decoration on an empty
91
+ // range at the line's start; anything else eats the content.
92
+ const painted = paintedLines(CONFLICT);
93
+ expect(painted.map((entry) => entry.text)).toEqual(['<<<<<<< HEAD', '>>>>>>> feature/x']);
94
+ });
95
+
96
+ test('a marker inside a line is not a marker', () => {
97
+ // A string literal and a comment are the two ways a file mentions the
98
+ // sequence without being conflicted.
99
+ const doc = ['const a = "<<<<<<< HEAD";', '// >>>>>>> not a marker either', 'plain();'].join('\n');
100
+ expect(paintedLines(doc)).toEqual([]);
101
+ });
102
+
103
+ test('a marker with no label still paints', () => {
104
+ expect(paintedLines('<<<<<<<\na\n>>>>>>>')).toEqual([
105
+ { line: 1, classes: ['cm-conflict-ours'], text: '<<<<<<<' },
106
+ { line: 3, classes: ['cm-conflict-theirs'], text: '>>>>>>>' },
107
+ ]);
108
+ });
109
+
110
+ test('an unconflicted file paints nothing', () => {
111
+ expect(paintedLines('function f() {\n return 1;\n}\n')).toEqual([]);
112
+ });
113
+ });
114
+
115
+ describe('countConflicts', () => {
116
+ test('counts one block per opening marker', () => {
117
+ expect(countConflicts(CONFLICT)).toBe(1);
118
+ expect(countConflicts(`${CONFLICT}\n${CONFLICT}`)).toBe(2);
119
+ });
120
+
121
+ test('a file with no conflict is zero', () => {
122
+ expect(countConflicts('')).toBe(0);
123
+ expect(countConflicts('a();\nb();\n')).toBe(0);
124
+ });
125
+
126
+ test('a mention mid-line is not a block', () => {
127
+ // The distinction the whole feature rests on: the marker is a LINE.
128
+ expect(countConflicts('const m = "<<<<<<< HEAD";')).toBe(0);
129
+ expect(countConflicts('see <<<<<<< in the docs\n')).toBe(0);
130
+ });
131
+
132
+ test('a marker at the very start of the file counts', () => {
133
+ expect(countConflicts('<<<<<<< HEAD\n')).toBe(1);
134
+ });
135
+ });