@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,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The DOM harness both `wait` panel suites mount through.
8
+ *
9
+ * Two files share it because the panel's two halves are different questions —
10
+ * a live/settled call (clock, bar, jobs) and a call with NO result (the reload
11
+ * shape) — and each suite is at the repo's per-file ceiling on its own.
12
+ *
13
+ * `happy-dom` is installed as globals here rather than in the suites so the two
14
+ * cannot drift on which globals a mounted panel needs; `render` runs inside
15
+ * `act` because the stopwatch schedules a `setInterval` on mount.
16
+ */
17
+
18
+ import { Window } from 'happy-dom';
19
+ import { h, render } from 'preact';
20
+ import { act } from 'preact/test-utils';
21
+ import { Wait } from '@/client/components/workspace/chat-timeline/tool-renderers/panels/Wait';
22
+ import type { ToolCallData } from '@/shared/types';
23
+
24
+ const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent'] as const;
25
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
26
+
27
+ /** Install the browser globals; call from `beforeAll`. */
28
+ export function installWaitDom(): void {
29
+ const win = new Window({ url: 'http://localhost' });
30
+ const target = globalThis as unknown as Record<string, unknown>;
31
+ for (const key of DOM_GLOBALS) {
32
+ nativeGlobals[key] = target[key];
33
+ target[key] = (win as unknown as Record<string, unknown>)[key];
34
+ }
35
+ }
36
+
37
+ /** Put the previous globals back; call from `afterAll`. */
38
+ export function restoreWaitDom(): void {
39
+ const target = globalThis as unknown as Record<string, unknown>;
40
+ for (const key of DOM_GLOBALS) {
41
+ if (nativeGlobals[key] === undefined) delete target[key];
42
+ else target[key] = nativeGlobals[key];
43
+ }
44
+ }
45
+
46
+ /** Mount the panel for one call and return its container. */
47
+ export async function mountWait(
48
+ partial: Partial<ToolCallData> & Pick<ToolCallData, 'type'>,
49
+ ): Promise<HTMLElement> {
50
+ const tool = { id: 'c1', name: partial.type, title: partial.type, ...partial } as ToolCallData;
51
+ const container = document.createElement('div');
52
+ document.body.appendChild(container);
53
+ await act(async () => {
54
+ render(h(Wait, { tool }), container);
55
+ });
56
+ return container;
57
+ }
58
+
59
+ /** The panel's progress track, if it drew one. */
60
+ export function waitBar(el: HTMLElement): HTMLElement | null {
61
+ return el.querySelector('[role="progressbar"]');
62
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The diff toolbar's hunk stepper: `‹ 2/5 ›`.
8
+ *
9
+ * Its own file for the per-file ceiling, and because it is the one cluster with
10
+ * state to read — the others are toggles over a prop. The index is 0-based in
11
+ * the view and 1-based on screen: "3 of 7" is what a reader counts, and `-1`
12
+ * (the caret outside every chunk) prints an en dash rather than `0`.
13
+ */
14
+
15
+ import { ChevronDown, ChevronUp } from 'lucide-preact';
16
+
17
+ const ACTION_CLASS =
18
+ 'flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer disabled:cursor-default disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-ink/50';
19
+
20
+ interface HunkStepperProps {
21
+ /** 0-based, or -1 when the caret is not inside a chunk. */
22
+ index: number;
23
+ count: number;
24
+ /** A git write or a reload is in flight; stepping a stale pair is misleading. */
25
+ locked: boolean;
26
+ onStep: (direction: 1 | -1) => void;
27
+ }
28
+
29
+ export function HunkStepper({ index, count, locked, onStep }: HunkStepperProps) {
30
+ const position = index >= 0 ? index + 1 : '–';
31
+ return (
32
+ <div className="flex items-center gap-0.5">
33
+ <button
34
+ type="button"
35
+ onClick={() => onStep(-1)}
36
+ disabled={locked}
37
+ className={`${ACTION_CLASS} text-ink/50 hover:text-ink hover:bg-ink/5`}
38
+ title="Previous change"
39
+ aria-label="Previous change"
40
+ >
41
+ <ChevronUp size={13} />
42
+ </button>
43
+ <span
44
+ className="text-[10px] font-mono tabular-nums text-ink/50 px-0.5 min-w-[3.5ch] text-center"
45
+ title={`Changed hunk ${position} of ${count}`}
46
+ aria-live="polite"
47
+ >
48
+ {position}/{count}
49
+ </span>
50
+ <button
51
+ type="button"
52
+ onClick={() => onStep(1)}
53
+ disabled={locked}
54
+ className={`${ACTION_CLASS} text-ink/50 hover:text-ink hover:bg-ink/5`}
55
+ title="Next change"
56
+ aria-label="Next change"
57
+ >
58
+ <ChevronDown size={13} />
59
+ </button>
60
+ </div>
61
+ );
62
+ }
@@ -23,6 +23,8 @@ import { EDITOR_LINE_HEIGHT } from '@/shared/lib/code/editor/typography';
23
23
  import {
24
24
  countChanges,
25
25
  foldWhitespaceOnly,
26
+ } from '@/client/components/workspace/diff-panel/changes';
27
+ import {
26
28
  mountSplitDiff,
27
29
  mountUnifiedDiff,
28
30
  type DiffViewHandle,
@@ -46,6 +48,22 @@ interface MergeDiffViewProps {
46
48
  * that draws its own badge from the patch (the chat's tool card).
47
49
  */
48
50
  onCounts?: (counts: { additions: number; deletions: number }) => void;
51
+ /**
52
+ * The changed chunks in the pair on screen, and which one holds the caret.
53
+ *
54
+ * Reported rather than owned: the toolbar that draws "2 of 5" and the two
55
+ * chevrons lives in the panel above, and it must read the same numbers the
56
+ * view is stepping through.
57
+ */
58
+ onChunkPosition?: (position: { index: number; count: number }) => void;
59
+ /**
60
+ * The step command, handed UP so the toolbar can call it.
61
+ *
62
+ * A callback rather than a ref because the handle is created in an effect
63
+ * that the toolbar's render cannot see; this runs after mount, once the view
64
+ * exists, and is a no-op before that.
65
+ */
66
+ onStepChunk?: (step: (direction: 1 | -1) => void) => void;
49
67
  /** Nothing to compare (both sides empty). */
50
68
  empty: boolean;
51
69
  fontFamily: string;
@@ -66,6 +84,8 @@ export function MergeDiffView({
66
84
  ignoreWhitespace,
67
85
  tabKey,
68
86
  onCounts,
87
+ onChunkPosition,
88
+ onStepChunk,
69
89
  empty,
70
90
  fontFamily,
71
91
  fontSize,
@@ -105,6 +125,7 @@ export function MergeDiffView({
105
125
  themes,
106
126
  scrollTestId: 'diff-scroller',
107
127
  onScroller: setScroller,
128
+ onChunkPosition,
108
129
  } as const;
109
130
  const handle =
110
131
  viewMode === 'split' ? mountSplitDiff(host, { ...options }) : mountUnifiedDiff(host, { ...options });
@@ -140,6 +161,14 @@ export function MergeDiffView({
140
161
  handleRef.current?.setWordWrap(wordWrap);
141
162
  }, [wordWrap]);
142
163
 
164
+ // The step command, published once the view exists. `stepChunk` reads the live
165
+ // handle, so a callback held across a re-mount still steps the current view.
166
+ useEffect(() => {
167
+ onStepChunk?.((direction) => {
168
+ handleRef.current?.stepChunk(direction);
169
+ });
170
+ }, [onStepChunk]);
171
+
143
172
  // Counts describe the pair ON SCREEN, so the badge cannot disagree with the
144
173
  // rows under it (git's own `+n/-n` still counts a hidden whitespace change).
145
174
  useEffect(() => {
@@ -1,9 +1,10 @@
1
- import { AlignJustify, Check, Code2, Columns, Copy, Diff, FileCode, Minus, Plus, RefreshCw, Space, Undo2, WrapText } from 'lucide-preact';
1
+ import { AlignJustify, Check, ChevronDown, ChevronUp, Code2, Columns, Copy, Diff, FileCode, Minus, Plus, RefreshCw, Space, Undo2, WrapText } from 'lucide-preact';
2
2
  import { FileIcon } from '@/client/components/common/file-icon';
3
3
  import { EditorViewButtons, useEditorViewActions } from '@/client/components/common/editor-view-buttons';
4
4
  import { getGitStatusInfo } from '@/shared/lib/fs/git-status';
5
5
  import { ToolbarRow, type ToolbarCluster } from '@/client/components/common/toolbar-row';
6
6
  import { DiffContentModeSegments, DiffViewModeSegments } from '@/client/components/workspace/diff-panel/ToolbarSegments';
7
+ import { HunkStepper } from '@/client/components/workspace/diff-panel/HunkStepper';
7
8
 
8
9
  export type DiffViewMode = 'unified' | 'split';
9
10
 
@@ -25,6 +26,11 @@ interface DiffToolbarProps {
25
26
  ignoreWhitespace: boolean;
26
27
  additions: number;
27
28
  deletions: number;
29
+ /** The chunk the caret is in (0-based, -1 for none), and how many there are. */
30
+ chunkIndex?: number;
31
+ chunkCount?: number;
32
+ /** Step to the next (`1`) or previous (`-1`) changed chunk. */
33
+ onStepChunk?: (direction: 1 | -1) => void;
28
34
  isLoading: boolean;
29
35
  isCopied: boolean;
30
36
  /** A stage/unstage/discard write is in flight; the toolbar locks its actions. */
@@ -59,6 +65,9 @@ export function DiffToolbar({
59
65
  ignoreWhitespace,
60
66
  additions,
61
67
  deletions,
68
+ chunkIndex = -1,
69
+ chunkCount = 0,
70
+ onStepChunk,
62
71
  isLoading,
63
72
  isCopied,
64
73
  isBusy = false,
@@ -135,6 +144,28 @@ export function DiffToolbar({
135
144
  children: <DiffContentModeSegments contentMode={contentMode} onSetContentMode={onSetContentMode} />,
136
145
  });
137
146
 
147
+ if (onStepChunk && chunkCount > 0) {
148
+ // NOT pinned, and pushed AFTER the two mode segments — both facts are the
149
+ // measured answer to a row that cannot hold everything. Pinned clusters are
150
+ // placed in full before anything else, and at the panel's 320px floor the
151
+ // five pinned clusters (counts, view modes, stage, edit) already claim
152
+ // 260px of a 296px row; the 76px stepper left 2px for the 76px
153
+ // Unified/Split pair, which therefore never reached the row. Unpinned
154
+ // placement follows ROW ORDER, so sitting beside the counts cluster would
155
+ // still have won the budget ahead of the shape control. Here it takes the
156
+ // row as soon as the row can hold it — measured on the row at a 637px panel
157
+ // (457px of row), in `⋯` at the 320px floor — and stays one click away
158
+ // below that, as the same two actions it draws.
159
+ clusters.push({
160
+ id: 'hunks',
161
+ actions: [
162
+ { label: 'Previous change', icon: ChevronUp, onSelect: () => onStepChunk(-1), disabled: locked },
163
+ { label: 'Next change', icon: ChevronDown, onSelect: () => onStepChunk(1), disabled: locked },
164
+ ],
165
+ children: <HunkStepper index={chunkIndex} count={chunkCount} locked={locked} onStep={onStepChunk} />,
166
+ });
167
+ }
168
+
138
169
  clusters.push({
139
170
  id: 'wrap',
140
171
  actions: [{ label: wrapLabel, icon: WrapText, onSelect: onToggleWordWrap, active: wordWrap }],
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * What the diff toolbar's badge counts, and what the whitespace toggle folds.
8
+ *
9
+ * Split out of `merge.ts` for the per-file ceiling, and the two belong together:
10
+ * both answer "what counts as a change" and they must answer it the SAME way.
11
+ * A badge that counted a whitespace change the toggle had hidden would be a
12
+ * number describing rows that are not on screen.
13
+ */
14
+
15
+ import { Chunk, diff } from '@codemirror/merge';
16
+ import { Text } from '@codemirror/state';
17
+
18
+ /**
19
+ * Additions and deletions, counted from the SAME line-level diff the view draws.
20
+ *
21
+ * `Chunk.build` is the merge view's own chunking — a line-level diff, which is
22
+ * what its rows are. `diff()` would be the wrong source here: it is a
23
+ * CHARACTER diff, so changing `line 5` into `line 5 changed` reports one
24
+ * insertion of `" changed"` and no deletion at all, and the badge would claim
25
+ * two additions for two edited lines.
26
+ */
27
+ export function countChanges(original: string, next: string): { additions: number; deletions: number } {
28
+ const a = Text.of(original.split('\n'));
29
+ const b = Text.of(next.split('\n'));
30
+ let additions = 0;
31
+ let deletions = 0;
32
+ for (const chunk of Chunk.build(a, b)) {
33
+ // `endA`/`endB` are the end of the chunk's last line, and equal the start
34
+ // when the chunk covers no lines on that side (a pure insertion/deletion).
35
+ if (chunk.endA > chunk.fromA) deletions += a.lineAt(chunk.endA).number - a.lineAt(chunk.fromA).number + 1;
36
+ if (chunk.endB > chunk.fromB) additions += b.lineAt(chunk.endB).number - b.lineAt(chunk.fromB).number + 1;
37
+ }
38
+ return { additions, deletions };
39
+ }
40
+
41
+ /**
42
+ * `original` with every whitespace-only change replaced by the new text.
43
+ *
44
+ * The toolbar's whitespace toggle means "do not show me formatting noise", and
45
+ * the merge view compares DOCUMENTS — so the way to honour it is to make the two
46
+ * sides agree there. The old table parser folded a `-`/`+` pair whose trimmed
47
+ * text matched back into a context row; this does the same at the source, which
48
+ * is why the toggle changes the CHUNKS rather than only their colour.
49
+ *
50
+ * Only line-for-line changes are folded: an inserted or deleted line is a real
51
+ * change even when it is blank, and hiding it would make the file's line count
52
+ * disagree with what is on screen.
53
+ */
54
+ export function foldWhitespaceOnly(original: string, next: string): string {
55
+ const changes = diff(original, next);
56
+ let folded = original;
57
+ // Back to front: an earlier splice would move every later offset.
58
+ for (let index = changes.length - 1; index >= 0; index--) {
59
+ const change = changes[index];
60
+ const before = original.slice(change.fromA, change.toA);
61
+ const after = next.slice(change.fromB, change.toB);
62
+ const beforeLines = before.split('\n');
63
+ const afterLines = after.split('\n');
64
+ if (beforeLines.length !== afterLines.length) continue;
65
+ if (!beforeLines.every((line, lineIndex) => line.trim() === afterLines[lineIndex].trim())) continue;
66
+ folded = folded.slice(0, change.fromA) + after + folded.slice(change.toA);
67
+ }
68
+ return folded;
69
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Stepping through a diff's changed chunks.
8
+ *
9
+ * Split out of `merge.ts` for the per-file ceiling, and it earns the boundary:
10
+ * everything here is a question about a LIVE view's selection, while `merge.ts`
11
+ * owns mounting and reconfiguring the two shapes.
12
+ *
13
+ * Three facts are load-bearing, and none is guessable:
14
+ *
15
+ * - `getChunks` is a FUNCTION on the state and answers `null` for a state with
16
+ * no merge extension. `state.field(getChunks)` throws "Field is not present
17
+ * in this state", and a null treated as "no changes" reads as an empty diff.
18
+ * - The side matters. A split view's B editor is the working file and reports
19
+ * `side: 'b'`; a unified view also reports `'b'` (it renders the new
20
+ * document). Reading `fromA` on a `'b'` view measures the wrong document.
21
+ * - The package's own `goToNextChunk` moves the SELECTION and scrolls through
22
+ * `scrollIntoView` on the range — which is not enough on a read-only reader,
23
+ * so the row is centred again after the move.
24
+ */
25
+
26
+ import type { Extension } from '@codemirror/state';
27
+ import { EditorView } from '@codemirror/view';
28
+ import { goToNextChunk, goToPreviousChunk, getChunks } from '@codemirror/merge';
29
+
30
+ /** The chunk the selection is in (`index` 0-based, or -1), and how many exist. */
31
+ export interface ChunkPosition {
32
+ index: number;
33
+ count: number;
34
+ }
35
+
36
+ /** `StateCommand`'s shape as this module invokes it (see `keymap.ts`). */
37
+ type ViewCommand = (view: EditorView) => boolean;
38
+
39
+ /**
40
+ * The chunk the selection is in, and how many there are.
41
+ *
42
+ * A pair rather than two calls because they are read in one render: a caller
43
+ * that fetched them separately could print "3 of 2" after a document swap.
44
+ */
45
+ export function chunkPositionOf(view: EditorView): ChunkPosition {
46
+ const field = getChunks(view.state);
47
+ if (!field || field.chunks.length === 0) return { index: -1, count: 0 };
48
+ const head = view.state.selection.main.head;
49
+ const index = field.chunks.findIndex((chunk) =>
50
+ field.side === 'a'
51
+ ? head >= chunk.fromA && head <= chunk.toA
52
+ : head >= chunk.fromB && head <= chunk.toB,
53
+ );
54
+ return { index, count: field.chunks.length };
55
+ }
56
+
57
+ /**
58
+ * Step to the next/previous chunk and bring it into view.
59
+ *
60
+ * False when there is nowhere to go — no chunks at all, or the caret already
61
+ * inside the only one — so a caller can leave a control inert.
62
+ */
63
+ export function stepChunkIn(view: EditorView, direction: 1 | -1): boolean {
64
+ const command = (direction === 1 ? goToNextChunk : goToPreviousChunk) as unknown as ViewCommand;
65
+ const moved = command(view);
66
+ if (moved) {
67
+ const head = view.state.selection.main.head;
68
+ view.dispatch({ effects: EditorView.scrollIntoView(head, { y: 'center' }) });
69
+ }
70
+ return moved;
71
+ }
72
+
73
+ /**
74
+ * Report the selection's chunk on every update that moves it.
75
+ *
76
+ * Attached to ONE view per shape (the B side of a split, the single view of a
77
+ * unified diff): both sides of a split carry the chunk field, and two reporters
78
+ * would race for the same toolbar label.
79
+ */
80
+ export function chunkReporter(report: (position: ChunkPosition) => void): Extension {
81
+ return EditorView.updateListener.of((update) => {
82
+ if (!update.docChanged && !update.selectionSet) return;
83
+ report(chunkPositionOf(update.view));
84
+ });
85
+ }
@@ -1,4 +1,4 @@
1
- import { useState } from 'preact/hooks';
1
+ import { useCallback, useRef, useState } from 'preact/hooks';
2
2
  import { useSessionUiState } from '@/client/hooks/workspace/session-state';
3
3
  import { isUnmergedCode } from '@/shared/lib/fs/git-unmerged';
4
4
  import { useFileDiff } from '@/client/hooks/workspace/diff-file';
@@ -58,6 +58,21 @@ export function DiffPanel({
58
58
  const [showDiscardConfirm, setShowDiscardConfirm] = useState<boolean>(false);
59
59
  /** Additions/deletions of the pair on screen, reported by the merge view. */
60
60
  const [counts, setCounts] = useState<{ additions: number; deletions: number }>({ additions: 0, deletions: 0 });
61
+ /**
62
+ * Which changed hunk the caret is in, reported by the merge view.
63
+ *
64
+ * The step command is held in a ref rather than state: it is a function the
65
+ * toolbar calls, and putting it in state would re-render the panel every time
66
+ * the view re-mounts (a shape switch) for a value nothing displays.
67
+ */
68
+ const [chunkPosition, setChunkPosition] = useState<{ index: number; count: number }>({ index: -1, count: 0 });
69
+ const stepChunkRef = useRef<((direction: 1 | -1) => void) | null>(null);
70
+ const handleStepChunk = useCallback((direction: 1 | -1) => {
71
+ stepChunkRef.current?.(direction);
72
+ }, []);
73
+ const handleChunkCommand = useCallback((step: (direction: 1 | -1) => void) => {
74
+ stepChunkRef.current = step;
75
+ }, []);
61
76
  const editorFontFamily = useEditorFontStack();
62
77
 
63
78
  const {
@@ -146,6 +161,9 @@ export function DiffPanel({
146
161
  ignoreWhitespace={ignoreWhitespace}
147
162
  additions={counts.additions}
148
163
  deletions={counts.deletions}
164
+ chunkIndex={chunkPosition.index}
165
+ chunkCount={chunkPosition.count}
166
+ onStepChunk={handleStepChunk}
149
167
  isLoading={isLoading}
150
168
  isCopied={isCopied}
151
169
  isBusy={isBusy}
@@ -230,6 +248,8 @@ export function DiffPanel({
230
248
  ignoreWhitespace={ignoreWhitespace}
231
249
  tabKey={tabKey}
232
250
  onCounts={setCounts}
251
+ onChunkPosition={setChunkPosition}
252
+ onStepChunk={handleChunkCommand}
233
253
  empty={!rawDiff || !rawDiff.trim()}
234
254
  fontFamily={editorFontFamily}
235
255
  fontSize={EDITOR_DEFAULT_FONT_SIZE}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The diff's hunk stepper: the two numbers the toolbar prints, and the move
8
+ * behind the two chevrons.
9
+ *
10
+ * Every way this fails is silent. `getChunks` is a FUNCTION on the state and
11
+ * answers `null` without a merge extension, so a wrong call reads as "no
12
+ * changes" — and the merge package's own `goToNextChunk` moves the SELECTION
13
+ * without scrolling, which on a read-only reader means the row changes somewhere
14
+ * off screen. Both cases mount a real view.
15
+ */
16
+
17
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
18
+ import { Window } from 'happy-dom';
19
+
20
+ import { mountSplitDiff, mountUnifiedDiff, type DiffViewHandle } from '@/client/components/workspace/diff-panel/merge';
21
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
22
+
23
+ const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame', 'ResizeObserver'] as const;
24
+ const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
25
+
26
+ let host: HTMLElement;
27
+
28
+ beforeAll(() => {
29
+ const win = new Window({ url: 'http://localhost' });
30
+ installDomGlobals(win);
31
+ const target = globalThis as unknown as Record<string, unknown>;
32
+ for (const key of EXTRA_GLOBALS) {
33
+ native[key] = target[key];
34
+ target[key] = (win as unknown as Record<string, unknown>)[key];
35
+ }
36
+ host = document.body.appendChild(document.createElement('div'));
37
+ });
38
+
39
+ afterAll(() => {
40
+ const target = globalThis as unknown as Record<string, unknown>;
41
+ for (const key of EXTRA_GLOBALS) {
42
+ if (native[key] === undefined) delete target[key];
43
+ else target[key] = native[key];
44
+ }
45
+ restoreDomGlobals();
46
+ });
47
+
48
+ const ORIGINAL = ['one', 'two', 'three', 'four', 'five', 'six'].join('\n');
49
+ // Two separate changes, far enough apart that the diff keeps them as two chunks.
50
+ const NEXT = ['one', 'TWO', 'three', 'four', 'FIVE', 'six'].join('\n');
51
+
52
+ interface Mounted {
53
+ handle: DiffViewHandle;
54
+ positions: Array<{ index: number; count: number }>;
55
+ }
56
+
57
+ function mount(kind: 'unified' | 'split', original = ORIGINAL, next = NEXT): Mounted {
58
+ const parent = document.createElement('div');
59
+ host.appendChild(parent);
60
+ const positions: Array<{ index: number; count: number }> = [];
61
+ const options = {
62
+ original,
63
+ next,
64
+ language: 'text',
65
+ wordWrap: false,
66
+ collapse: 'diff' as const,
67
+ scrollTestId: 'diff-scroller',
68
+ onScroller: () => {},
69
+ onChunkPosition: (position: { index: number; count: number }) => positions.push(position),
70
+ };
71
+ const handle = kind === 'split' ? mountSplitDiff(parent, options) : mountUnifiedDiff(parent, options);
72
+ return { handle, positions };
73
+ }
74
+
75
+ describe('chunk position', () => {
76
+ test('a changed pair reports its chunks on mount', () => {
77
+ for (const kind of ['unified', 'split'] as const) {
78
+ const { handle } = mount(kind);
79
+ const position = handle.chunkPosition();
80
+ expect(position.count).toBe(2);
81
+ // The selection starts at the top, which is not inside a chunk.
82
+ expect(position.index).toBe(-1);
83
+ handle.destroy();
84
+ }
85
+ });
86
+
87
+ test('an identical pair reports no chunks', () => {
88
+ const { handle } = mount('unified', ORIGINAL, ORIGINAL);
89
+ expect(handle.chunkPosition()).toEqual({ index: -1, count: 0 });
90
+ // Nothing to step to, so the toolbar must be able to tell.
91
+ expect(handle.stepChunk(1)).toBe(false);
92
+ handle.destroy();
93
+ });
94
+
95
+ test('the mount reports the seed position, so the badge is not "0 of 0"', () => {
96
+ const { handle, positions } = mount('unified');
97
+ expect(positions[0]).toEqual({ index: -1, count: 2 });
98
+ handle.destroy();
99
+ });
100
+ });
101
+
102
+ describe('stepChunk', () => {
103
+ test('steps forward through every chunk and wraps', () => {
104
+ const { handle } = mount('unified');
105
+ expect(handle.stepChunk(1)).toBe(true);
106
+ expect(handle.chunkPosition().index).toBe(0);
107
+ expect(handle.stepChunk(1)).toBe(true);
108
+ expect(handle.chunkPosition().index).toBe(1);
109
+ // Past the last one is the first one again: the package's own wrap.
110
+ expect(handle.stepChunk(1)).toBe(true);
111
+ expect(handle.chunkPosition().index).toBe(0);
112
+ handle.destroy();
113
+ });
114
+
115
+ test('steps backward and wraps the other way', () => {
116
+ const { handle } = mount('unified');
117
+ expect(handle.stepChunk(-1)).toBe(true);
118
+ expect(handle.chunkPosition().index).toBe(1);
119
+ expect(handle.stepChunk(-1)).toBe(true);
120
+ expect(handle.chunkPosition().index).toBe(0);
121
+ handle.destroy();
122
+ });
123
+
124
+ test('the split shape steps the B side, which is the working file', () => {
125
+ const { handle } = mount('split');
126
+ expect(handle.stepChunk(1)).toBe(true);
127
+ expect(handle.chunkPosition().index).toBe(0);
128
+ expect(handle.stepChunk(1)).toBe(true);
129
+ expect(handle.chunkPosition().index).toBe(1);
130
+ handle.destroy();
131
+ });
132
+
133
+ test('a single chunk is entered once and then refuses to move', () => {
134
+ // Measured: the package only refuses when the caret is ALREADY inside the
135
+ // one chunk. From outside it, the first step is the useful one — it puts the
136
+ // caret on the change — and every step after that returns false rather than
137
+ // re-selecting the same row.
138
+ const { handle } = mount('unified', 'a\nb\nc', 'a\nB\nc');
139
+ expect(handle.chunkPosition().count).toBe(1);
140
+ expect(handle.stepChunk(1)).toBe(true);
141
+ expect(handle.chunkPosition().index).toBe(0);
142
+ expect(handle.stepChunk(1)).toBe(false);
143
+ handle.destroy();
144
+ });
145
+ });