@bevel-software/platform-core-frontend 0.15.1 → 0.20.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 (347) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +20 -9
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/events.test.ts +43 -0
  6. package/src/core/bootstrap.ts +11 -3
  7. package/src/core/events.ts +85 -3
  8. package/src/core/registry.ts +1 -1
  9. package/src/lib/__tests__/email.test.ts +44 -0
  10. package/src/lib/email.ts +37 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  12. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  16. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  20. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
  21. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  22. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  23. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  24. package/src/modules/access/api.ts +140 -6
  25. package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
  26. package/src/modules/access/manage-access-affordance.ts +17 -0
  27. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  28. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  29. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  30. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  31. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  33. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  34. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  35. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  36. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  37. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  38. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  39. package/src/modules/admin/components/group-members-path.ts +32 -0
  40. package/src/modules/admin/services/roles.api.ts +12 -1
  41. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  42. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  43. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  44. package/src/modules/audit/components/principal-grouping.ts +49 -0
  45. package/src/modules/audit/services/audit.api.ts +98 -0
  46. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  47. package/src/modules/auth/components/AccountPage.tsx +73 -54
  48. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  49. package/src/modules/auth/services/account.api.ts +78 -4
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  58. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  59. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  60. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  61. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  62. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  63. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  64. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  65. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  66. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  67. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  68. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  69. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  70. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  71. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  72. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  73. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  74. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  75. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  76. package/src/modules/change-requests/services/propose.api.ts +97 -8
  77. package/src/modules/change-requests/utils/approval.ts +15 -0
  78. package/src/modules/change-requests/utils/author.ts +32 -0
  79. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  80. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  81. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  82. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  83. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  84. package/src/modules/git/services/error-messages.ts +12 -0
  85. package/src/modules/git/services/pr-prompts.ts +5 -5
  86. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  87. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  88. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  89. package/src/modules/layout/components/AppLayout.tsx +2 -0
  90. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  91. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  92. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  93. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  94. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  95. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  96. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  97. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  98. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  99. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  100. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  101. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  102. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  103. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  104. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  105. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  106. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  107. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  108. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  109. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  110. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  111. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  112. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  113. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  114. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  115. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  116. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  117. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  118. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  119. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  120. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  121. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  122. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  123. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  124. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  125. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  126. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  127. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  128. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  129. package/src/modules/library/__tests__/status.test.ts +82 -2
  130. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  131. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  132. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  133. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  134. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  135. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  136. package/src/modules/library/components/LibraryCard.tsx +146 -45
  137. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  138. package/src/modules/library/components/LibraryPage.tsx +172 -39
  139. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  140. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  141. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  142. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  143. package/src/modules/library/components/PageActions.tsx +11 -9
  144. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  145. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  146. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  147. package/src/modules/library/components/PluginExtras.tsx +140 -17
  148. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  149. package/src/modules/library/components/PluginPage.tsx +157 -41
  150. package/src/modules/library/components/PluginRows.tsx +286 -0
  151. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  152. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  153. package/src/modules/library/components/ShareButton.tsx +17 -0
  154. package/src/modules/library/components/SkillsTree.tsx +141 -28
  155. package/src/modules/library/components/TeamRoute.tsx +15 -0
  156. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  157. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  158. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  159. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  160. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  161. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  162. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  163. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  164. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  165. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  166. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  167. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  168. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  169. package/src/modules/library/routes/library-paths.ts +26 -28
  170. package/src/modules/library/services/library.api.ts +38 -20
  171. package/src/modules/library/services/plugins.api.ts +69 -8
  172. package/src/modules/library/services/teams.api.ts +15 -0
  173. package/src/modules/library/services/tools.api.ts +78 -0
  174. package/src/modules/library/state/library-data.tsx +170 -32
  175. package/src/modules/library/utils/personal-plugin.ts +13 -15
  176. package/src/modules/library/utils/plugin-entries.ts +134 -0
  177. package/src/modules/library/utils/plugin-summary.ts +75 -9
  178. package/src/modules/library/utils/status.ts +135 -33
  179. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  180. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  181. package/src/modules/onboarding/agent-clients.ts +55 -23
  182. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  183. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  184. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  185. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  186. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  187. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  188. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  189. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  190. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  191. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  192. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  193. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  194. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  195. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  196. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  197. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  198. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  199. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  200. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  201. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  202. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  203. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  204. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  205. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  206. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  207. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  208. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +7 -6
  209. package/src/modules/settings/services/github-facade.api.ts +23 -0
  210. package/src/modules/settings/settings-nav-items.tsx +13 -3
  211. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  212. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  213. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  214. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  215. package/src/modules/setup/components/SetupGate.tsx +16 -16
  216. package/src/modules/setup/components/SetupScreen.tsx +532 -43
  217. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  218. package/src/modules/setup/services/setup.api.ts +141 -4
  219. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  220. package/src/modules/setup/utils/root-folders.ts +46 -0
  221. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  232. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  233. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  234. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  235. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  236. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  237. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  238. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  239. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  240. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  241. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  242. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  243. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  244. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  245. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  246. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  247. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  248. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  249. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  250. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  251. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  252. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  254. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  255. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  256. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  257. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  258. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  259. package/src/modules/workspace/components/FileViewer.tsx +172 -46
  260. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  261. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  262. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  263. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2533 -129
  264. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  265. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +381 -12
  266. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  267. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  268. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  269. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  270. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  271. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  272. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  273. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  274. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  275. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  276. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  277. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  279. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  280. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  281. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  282. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  283. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  284. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  285. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  286. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  287. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  288. package/src/modules/workspace/components/renderers/index.ts +53 -2
  289. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  290. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  291. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  292. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  294. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  295. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  296. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  297. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  298. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  299. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  300. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  301. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +134 -1
  302. package/src/modules/workspace/services/workspace.api.ts +57 -4
  303. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  304. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  305. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  306. package/src/modules/workspace/state/workspace.context.ts +125 -19
  307. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  308. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  309. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  310. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  311. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  312. package/src/modules/workspace/utils/file-trace.ts +50 -0
  313. package/src/modules/workspace/utils/fileTree.ts +112 -36
  314. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  315. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  316. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  317. package/src/modules/workspace/utils/uploadError.ts +29 -0
  318. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  319. package/src/shared/components/Button.tsx +16 -2
  320. package/src/shared/components/Dialog.tsx +27 -11
  321. package/src/shared/components/Menu.tsx +13 -1
  322. package/src/shared/components/PageShell.tsx +13 -8
  323. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  324. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  325. package/src/shared/components/index.ts +2 -0
  326. package/src/shared/components/useDismissableMenu.ts +32 -10
  327. package/src/shared/components/useFocusHandoff.ts +51 -0
  328. package/src/shared/components/useLatestRef.ts +28 -0
  329. package/src/shared/markdown/Markdown.tsx +12 -3
  330. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  331. package/src/shared/markdown/hrefs.ts +50 -0
  332. package/src/shared/marketplace-url.ts +33 -5
  333. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  334. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  335. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  336. package/src/shared/mcp/connect-snippets.ts +14 -9
  337. package/src/shared/mcp/index.ts +1 -1
  338. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  339. package/src/shared/theme/header.ts +75 -0
  340. package/src/shared/theme/measure.ts +7 -4
  341. package/src/shared/theme/tokens.css +25 -0
  342. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  343. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  344. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  345. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  346. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  347. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -8,10 +8,11 @@ import {
8
8
  FileEdit,
9
9
  FilePlus2,
10
10
  FileX2,
11
- X,
11
+ Lock,
12
12
  } from 'lucide-react';
13
13
  import type { FileApprovalState, PrFileStatus } from '@bevel-software/platform-shared';
14
14
  import { cn } from '../../../lib/utils';
15
+ import { hasOwnApproval } from '../utils/approval';
15
16
 
16
17
  /**
17
18
  * The change request's files as a TREE — the Knowledge sidebar's visual
@@ -24,9 +25,11 @@ import { cn } from '../../../lib/utils';
24
25
  * - INLINE after the name: the approval STATE — green ✓ confirmed, amber
25
26
  * clock for outdated confirmations, grey clock waiting — with the
26
27
  * eligible approvers in the tooltip.
27
- * - RIGHT, revealed on hover: the ACTION for eligible viewers — a filled
28
- * green check to confirm the file, turning into an ✕ (withdraw) once
29
- * YOUR confirmation is the current one.
28
+ * - For a file that is the VIEWER's to approve, the state is theirs instead:
29
+ * a filled green check "Approved by you", or an outlined one "Waiting on
30
+ * your approval". A status mark, not a control — approving is the labelled
31
+ * button in the selected file's header, where the reviewer is reading
32
+ * (an unlabelled check on a tree row was not findable).
30
33
  *
31
34
  * Right-click a revertable file for the destructive verb, armed inside its
32
35
  * own context menu. Selection (which file the diff shows) stays a plain
@@ -43,19 +46,25 @@ export interface CrTreeFileState {
43
46
  /** Git status when changed (drives the kind icon). */
44
47
  status?: PrFileStatus;
45
48
  approval?: FileApprovalState;
49
+ /**
50
+ * The access sentence when this file's copy came back REFUSED — the lock
51
+ * glyph's tooltip, and the reason it is there. The same sentence the pane
52
+ * shows, so a reader who meets the lock in the list and the sentence in the
53
+ * pane is told one thing, not two. Absent for every other file, including
54
+ * one whose read merely broke: that is retryable and says so in the pane.
55
+ */
56
+ deniedNote?: string;
46
57
  }
47
58
 
48
59
  interface CrFileTreeProps {
49
60
  files: CrTreeFileState[];
50
61
  selected: string;
51
- /** The viewer — whose own current confirmation the withdraw action needs. */
62
+ /** The viewer — whose own current confirmation the status mark reads. */
52
63
  currentUserEmail: string;
53
64
  onSelect(path: string): void;
54
- /** Confirm `path`, or withdraw the viewer's own confirmation of it. */
55
- onToggleApprove(path: string, hasOwnApproval: boolean): void;
56
65
  /** Revert `path` on the source branch. Only called when approvable+changed. */
57
66
  onRevert(path: string): void;
58
- /** Disables the verbs while one is in flight. */
67
+ /** Disables the revert verb while one is in flight. */
59
68
  busy: boolean;
60
69
  }
61
70
 
@@ -96,7 +105,6 @@ export function CrFileTree({
96
105
  selected,
97
106
  currentUserEmail,
98
107
  onSelect,
99
- onToggleApprove,
100
108
  onRevert,
101
109
  busy,
102
110
  }: CrFileTreeProps) {
@@ -121,12 +129,10 @@ export function CrFileTree({
121
129
  selected={selected}
122
130
  currentUserEmail={currentUserEmail}
123
131
  onSelect={onSelect}
124
- onToggleApprove={onToggleApprove}
125
132
  onContextMenu={(path, e) => {
126
133
  e.preventDefault();
127
134
  setMenu({ path, x: e.clientX, y: e.clientY });
128
135
  }}
129
- busy={busy}
130
136
  />
131
137
  {menu && (
132
138
  <RevertMenu
@@ -151,9 +157,7 @@ function Level({
151
157
  selected,
152
158
  currentUserEmail,
153
159
  onSelect,
154
- onToggleApprove,
155
160
  onContextMenu,
156
- busy,
157
161
  }: {
158
162
  folder: TreeFolder;
159
163
  depth: number;
@@ -162,9 +166,7 @@ function Level({
162
166
  selected: string;
163
167
  currentUserEmail: string;
164
168
  onSelect(path: string): void;
165
- onToggleApprove(path: string, hasOwnApproval: boolean): void;
166
169
  onContextMenu(path: string, e: React.MouseEvent): void;
167
- busy: boolean;
168
170
  }) {
169
171
  return (
170
172
  <>
@@ -196,9 +198,7 @@ function Level({
196
198
  selected={selected}
197
199
  currentUserEmail={currentUserEmail}
198
200
  onSelect={onSelect}
199
- onToggleApprove={onToggleApprove}
200
201
  onContextMenu={onContextMenu}
201
- busy={busy}
202
202
  />
203
203
  )}
204
204
  </div>
@@ -208,15 +208,19 @@ function Level({
208
208
  const name = file.path.slice(file.path.lastIndexOf('/') + 1);
209
209
  const on = selected === file.path;
210
210
  const eligible = file.changed && file.approval?.viewerCanApprove === true;
211
- // The withdraw action toggles YOUR current confirmation, nobody
212
- // else's — stale rows stay for audit without arming it (presplit
213
- // PrFileRow's rule, kept verbatim).
214
- const email = currentUserEmail.trim().toLowerCase();
215
- const hasOwnApproval =
216
- !!email &&
217
- !!file.approval?.approvedBy.some(
218
- (a) => a.email.toLowerCase() === email && !a.isStale,
219
- );
211
+ // The viewer's own state wins the slot when there is one: approved
212
+ // by them, or still waiting on them. Otherwise the general badge.
213
+ // "Waiting" means the gate needs them: one eligible approval satisfies
214
+ // a file, so once someone else has confirmed it the file waits on
215
+ // nobody and reads "Confirmed" — the footer's count agrees. The header
216
+ // still lets them add their own.
217
+ const viewerMark = !eligible
218
+ ? null
219
+ : hasOwnApproval(file.approval, currentUserEmail)
220
+ ? 'approved'
221
+ : file.approval?.inMergeGate && !file.approval.isApproved
222
+ ? 'waiting'
223
+ : null;
220
224
  return (
221
225
  <div
222
226
  key={file.path}
@@ -243,33 +247,11 @@ function Level({
243
247
  >
244
248
  {name}
245
249
  </button>
246
- <ApprovalStateBadge approval={file.changed ? file.approval : undefined} />
247
- {eligible && (
248
- <span className="flex flex-none items-center opacity-70 group-hover/row:opacity-100">
249
- {hasOwnApproval ? (
250
- <button
251
- type="button"
252
- disabled={busy}
253
- title="Withdraw your confirmation"
254
- aria-label={`Withdraw your confirmation of ${file.path}`}
255
- onClick={() => onToggleApprove(file.path, true)}
256
- className="rounded-sm p-1 text-ok transition-colors hover:bg-danger-soft hover:text-danger disabled:cursor-not-allowed disabled:opacity-40"
257
- >
258
- <X size={12} />
259
- </button>
260
- ) : (
261
- <button
262
- type="button"
263
- disabled={busy}
264
- title="Confirm this file"
265
- aria-label={`Confirm ${file.path}`}
266
- onClick={() => onToggleApprove(file.path, false)}
267
- className="rounded-sm bg-ok p-1 text-white transition-colors hover:opacity-85 disabled:cursor-not-allowed disabled:opacity-40"
268
- >
269
- <Check size={12} />
270
- </button>
271
- )}
272
- </span>
250
+ {file.deniedNote && <DeniedMark note={file.deniedNote} />}
251
+ {viewerMark ? (
252
+ <ViewerApprovalMark state={viewerMark} />
253
+ ) : (
254
+ <ApprovalStateBadge approval={file.changed ? file.approval : undefined} />
273
255
  )}
274
256
  </div>
275
257
  );
@@ -298,16 +280,50 @@ function KindIcon({ status }: { status?: PrFileStatus }) {
298
280
  }
299
281
  }
300
282
 
283
+ /**
284
+ * A file whose copy the viewer may not read. Beside the name rather than in
285
+ * place of the kind icon: what the request DID to the file is still true and
286
+ * still worth seeing, and the lock is the extra fact — this one you can't open.
287
+ */
288
+ function DeniedMark({ note }: { note: string }) {
289
+ return (
290
+ <span
291
+ role="img"
292
+ aria-label={note}
293
+ title={note}
294
+ className="flex flex-none items-center text-ink-faint"
295
+ >
296
+ <Lock size={11} />
297
+ </span>
298
+ );
299
+ }
300
+
301
+ /** The viewer's own approval state on a file that is theirs to approve. */
302
+ function ViewerApprovalMark({ state }: { state: 'approved' | 'waiting' }) {
303
+ const label = state === 'approved' ? 'Approved by you' : 'Waiting on your approval';
304
+ return (
305
+ <span
306
+ role="img"
307
+ aria-label={label}
308
+ title={label}
309
+ className={cn(
310
+ 'flex flex-none items-center rounded-sm p-0.5',
311
+ state === 'approved' ? 'bg-ok text-white' : 'border border-ok text-ok',
312
+ )}
313
+ >
314
+ <Check size={11} />
315
+ </span>
316
+ );
317
+ }
318
+
301
319
  /**
302
320
  * The approval STATE, inline after the name — presplit PrApprovalBadge:
303
321
  * green ✓ confirmed, amber clock for outdated confirmations, grey clock
304
- * waiting; nothing at all for files outside the gate (keeps the tree quiet).
322
+ * waiting; nothing at all for files outside the gate (keeps the tree quiet,
323
+ * and names no one the gate does not wait on — the footer's rule).
305
324
  */
306
325
  function ApprovalStateBadge({ approval }: { approval?: FileApprovalState }) {
307
- if (!approval) return null;
308
- const hasEligible =
309
- approval.eligibleApprovers.roles.length > 0 || approval.eligibleApprovers.users.length > 0;
310
- if (!hasEligible) return null;
326
+ if (!approval?.inMergeGate) return null;
311
327
  const who = [
312
328
  ...approval.eligibleApprovers.roles,
313
329
  ...approval.eligibleApprovers.users.map((u) => u.name || u.email),
@@ -4,9 +4,8 @@ import { Banner, Button } from '../../../shared/components';
4
4
  import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
5
5
  import { useOpenChangeRequests } from '../../workspace/hooks/useOpenChangeRequests';
6
6
  import { PR_STALE_EVENT } from '../../../core/events';
7
- import { useApplyChangeRequest } from '../hooks/useApplyChangeRequest';
7
+ import { refusalLine, useApplyChangeRequest } from '../hooks/useApplyChangeRequest';
8
8
  import { useCrFileDiffs } from '../hooks/useCrFileDiffs';
9
- import { useDefaultBranchFile } from '../hooks/useFileOnBranch';
10
9
  import { changeAuthorName, formatWhen } from '../utils/author';
11
10
  import { conflictResolutionPrompt } from '../utils/conflict';
12
11
  import { isBinaryFile } from '../../workspace/components/renderers';
@@ -22,6 +21,11 @@ export interface FileChangeBoxesProps {
22
21
  canDecide: boolean;
23
22
  /** Who the decision waits on, for the non-owner's footer. */
24
23
  ownersLabel: string;
24
+ /**
25
+ * For a viewer who can decide: how many approvers besides them the file
26
+ * still waits on. Feeds "Waiting on you and N others".
27
+ */
28
+ othersPending?: number;
25
29
  /** The default branch just changed under this file — a request landed. */
26
30
  onApplied(): void;
27
31
  }
@@ -33,8 +37,8 @@ export interface FileChangeBoxesProps {
33
37
  * text become that text?") is unanswerable without the text, which is why
34
38
  * this is not a banner pointing at a review queue somewhere else.
35
39
  *
36
- * Owns the whole decision loop: per-request diffs against the default
37
- * branch, Approve (approvals → merge → wait for the outcome event),
40
+ * Owns the whole decision loop: per-request diffs from each request's fork
41
+ * point (see `useCrFileDiffs`), Approve (approvals → merge → wait for the outcome event),
38
42
  * Decline, the author's Withdraw, and "Read the whole change" opening the
39
43
  * shared {@link ChangeRequestDialog}. Resolutions dispatch
40
44
  * {@link PR_STALE_EVENT} so the tree dots, the tabs and this very list
@@ -45,6 +49,7 @@ export function FileChangeBoxes({
45
49
  requests,
46
50
  canDecide,
47
51
  ownersLabel,
52
+ othersPending,
48
53
  onApplied,
49
54
  }: FileChangeBoxesProps) {
50
55
  const { mineNumbers } = useOpenChangeRequests();
@@ -61,8 +66,7 @@ export function FileChangeBoxes({
61
66
  // Binary files never diff (see the box's `binary` prop) — so never fetch
62
67
  // and decode their default-branch bytes either.
63
68
  const binary = isBinaryFile(repoRelativePath);
64
- const rawOnMain = useDefaultBranchFile(binary ? null : repoRelativePath, revision);
65
- const crDiffs = useCrFileDiffs(requests, repoRelativePath, rawOnMain, revision);
69
+ const crDiffs = useCrFileDiffs(requests, repoRelativePath, revision);
66
70
 
67
71
  const resolved = useCallback(() => {
68
72
  setApplied(true);
@@ -119,7 +123,8 @@ export function FileChangeBoxes({
119
123
  // `[]` is the diff hook's "overtaken" answer — the proposal and the
120
124
  // file now say the same thing — distinct from `null`, which only
121
125
  // means a side has not arrived yet.
122
- const fileDiff = crDiffs.get(cr.number) ?? null;
126
+ const read = crDiffs.get(cr.number) ?? null;
127
+ const fileDiff = read === 'unreadable' ? null : read;
123
128
  return (
124
129
  <ChangeBox
125
130
  key={cr.number}
@@ -127,20 +132,19 @@ export function FileChangeBoxes({
127
132
  author={changeAuthorName(cr)}
128
133
  when={formatWhen(cr.createdAt)}
129
134
  mine={mine}
130
- canDecide={canDecide && !mine}
135
+ // Approval rights come from the file, not from authorship: an
136
+ // eligible approver decides their own proposal too (the gate
137
+ // accepts it and records it as a self-approval).
138
+ canDecide={canDecide}
131
139
  diff={fileDiff}
132
140
  binary={binary}
141
+ unreadable={read === 'unreadable'}
133
142
  upToDate={fileDiff !== null && fileDiff.length === 0}
134
143
  blocked={blockedCrs.has(cr.number)}
135
144
  conflictPrompt={conflictResolutionPrompt(cr)}
136
- // A conflict already speaks through `blocked`; repeating it as a
137
- // refusal line would say the same thing twice in one box.
138
- refusal={
139
- applying.refusals.get(cr.number)?.conflicts === false
140
- ? (applying.refusals.get(cr.number)?.reason ?? null)
141
- : null
142
- }
145
+ refusal={refusalLine(cr, applying.refusals)}
143
146
  owner={ownersLabel}
147
+ othersPending={othersPending}
144
148
  busy={busyCr === cr.number || applying.activeCr === cr.number}
145
149
  phase={applying.activeCr === cr.number ? applying.phase : 'idle'}
146
150
  onApprove={() => applying.apply(cr)}
@@ -22,6 +22,39 @@ export type ApplyPhase = 'idle' | 'approving' | 'applying';
22
22
  export interface ApplyRefusal {
23
23
  reason: string;
24
24
  conflicts: boolean;
25
+ /**
26
+ * When it failed (ISO): the server's instant for a refusal the server
27
+ * reported — the same one it persists — else this tab's clock.
28
+ */
29
+ at?: string;
30
+ }
31
+
32
+ /**
33
+ * The refusal line a change box shows for `cr`. This tab's own attempt speaks
34
+ * first, and a conflict there says nothing here because the box's blocked state
35
+ * already does — unless the request carries a LATER refusal, from somebody
36
+ * else's attempt since. Otherwise the refusal PERSISTED on the request, which
37
+ * is how the author and every other viewer learn that somebody's apply failed.
38
+ * That one never withdraws the button: the author may already have fixed the
39
+ * cause, and only a new attempt can say so.
40
+ */
41
+ export function refusalLine(
42
+ cr: PullRequestSummary,
43
+ refusals: ReadonlyMap<number, ApplyRefusal>,
44
+ ): string | null {
45
+ const own = refusals.get(cr.number);
46
+ const persisted = cr.lastApplyFailure ?? null;
47
+ if (own && !isLater(persisted?.at, own.at)) return own.conflicts ? null : own.reason;
48
+ return persisted?.reason ?? null;
49
+ }
50
+
51
+ /** True when `a` is a strictly later instant than `b`; unknown is never later. */
52
+ function isLater(a: string | undefined, b: string | undefined): boolean {
53
+ if (!a) return false;
54
+ if (!b) return true;
55
+ const ta = Date.parse(a);
56
+ const tb = Date.parse(b);
57
+ return Number.isFinite(ta) && Number.isFinite(tb) && ta > tb;
25
58
  }
26
59
 
27
60
  export interface ApplyChangeRequest {
@@ -40,8 +73,8 @@ export interface ApplyChangeRequest {
40
73
  * calling `mergePullRequest` and awaiting it:
41
74
  *
42
75
  * 1. **Approving is not merging.** The merge gate requires a recorded per-file
43
- * approval from an eligible approver for every markdown file that has
44
- * owners — which is precisely the case the skill page is built for, since a
76
+ * approval from an eligible approver for every file that has owners,
77
+ * whatever its type — which is precisely the case the skill page is built for, since a
45
78
  * SKILL.md inside a plugin folder inherits that folder's `access.md`. Going
46
79
  * straight to merge is refused with "Waiting on approval for …". So the
47
80
  * owner's click records the approvals FIRST, then merges. Files the caller
@@ -111,7 +144,8 @@ export function useApplyChangeRequest(opts: {
111
144
  const fail = useCallback(
112
145
  (number: number, refusal: ApplyRefusal) => {
113
146
  stop();
114
- setRefusals((m) => new Map(m).set(number, refusal));
147
+ const at = refusal.at ?? new Date().toISOString();
148
+ setRefusals((m) => new Map(m).set(number, { ...refusal, at }));
115
149
  onFailedRef.current?.(number, refusal);
116
150
  },
117
151
  [stop],
@@ -133,6 +167,7 @@ export function useApplyChangeRequest(opts: {
133
167
  fail(e.number, {
134
168
  reason: e.reason || "Couldn't apply this change.",
135
169
  conflicts: e.conflicts === true,
170
+ at: e.at,
136
171
  });
137
172
  });
138
173
  return () => {
@@ -173,10 +208,9 @@ export function useApplyChangeRequest(opts: {
173
208
 
174
209
  for (const a of detail.approvals) {
175
210
  if (a.isApproved) continue;
176
- // No eligible approvers means the gate ignores the file entirely.
177
- const gateCares =
178
- a.eligibleApprovers.roles.length > 0 || a.eligibleApprovers.users.length > 0;
179
- if (!gateCares) continue;
211
+ // The server's verdict on whether the gate binds the file at all —
212
+ // a file it ignores gets no recorded approval.
213
+ if (!a.inMergeGate) continue;
180
214
  // A refusal here is "not your file", which is normal on a change
181
215
  // request spanning several owners — let the gate below decide
182
216
  // whether what did get approved is enough.
@@ -1,79 +1,237 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import type { PullRequestSummary } from '@bevel-software/platform-shared';
3
- import { readFileOnBranch } from '../services/change-requests.api';
3
+ import { readFileAtForkPoint, readFileOnBranch, type ForkPointFile } from '../services/change-requests.api';
4
+ import { subscribePrStale } from '../../../core/events';
4
5
  import { isBinaryFile } from '../../workspace/components/renderers';
6
+ import { WorkspaceApiError } from '../../workspace/services/workspace.api';
5
7
  import { diffLines, hasChanges, type DiffLine } from '../utils/diff';
6
8
 
7
9
  /**
8
- * For each open change request touching `repoRelativePath`, that branch's copy
9
- * of the file diffed against the file as it stands on the default branch.
10
+ * For each open change request touching `repoRelativePath`, what THAT REQUEST
11
+ * changes in the file: its branch's copy diffed against the file as it stood
12
+ * at the request's fork point — the text its author started from.
10
13
  *
11
- * Against CURRENT main, not against what the author forked from: the person
12
- * deciding is being asked "should this text become that text?", and the only
13
- * honest answer to that compares the proposal with what is there right now.
14
+ * Not against current main. Diffing against the tip showed every edit made on
15
+ * main after the proposal as something the proposal DELETES: a reader saw
16
+ * another person's direct edit struck through inside somebody else's request,
17
+ * and feared approving it would undo that edit. (Applying is a merge, and keeps
18
+ * the newer edit.) The request dialog reads the same fork point, so the box and
19
+ * the whole-change view never disagree about what a request does.
14
20
  *
15
- * Keyed by CR number + path + revision so a tab switch or a reload can never
16
- * show the previous file's diff under this file's heading.
21
+ * The TARGET branch's text is the "before" in exactly one case: branches with
22
+ * no shared history have no fork point to read, and the target's tip is the
23
+ * only text left. That read is made HERE — against the request's own
24
+ * `base`, which is not always the default branch — and only once a fork read
25
+ * comes back without a fork point, so it carries the same generation as the
26
+ * two sides it joins. A copy passed in from the page would keep whatever
27
+ * moment the page last read it at, and pair a fresh branch copy with a stale
28
+ * target.
29
+ *
30
+ * Branch reads are keyed by CR number + path + revision so a tab switch or a
31
+ * reload can never show the previous file's diff under this file's heading.
32
+ * Fork reads carry no revision: resolving a fork point costs the server two
33
+ * branch fetches and a `merge-base` per box, and a revision bump (a tab
34
+ * switch, an apply elsewhere on the page) does not move any request's fork
35
+ * point. The one thing that does — an Update — announces itself with
36
+ * {@link PR_STALE_EVENT}.
37
+ *
38
+ * BOTH keys carry that event's epoch, because the two sides of one diff have
39
+ * to describe the same moment. Re-reading only the fork point after an Update
40
+ * paired the merged target's text with the branch copy cached from before the
41
+ * merge, and the target's own newer lines rendered as deletions inside the
42
+ * request — the exact reading this hook exists to prevent, arriving seconds
43
+ * after the Update that was supposed to settle it. Under a new epoch neither
44
+ * side is cached, so a box waits rather than mixing two moments.
45
+ *
46
+ * Each arrival drops what earlier generations left behind, so a page left open
47
+ * through many applies and pulls holds one set of reads, not one per event.
48
+ *
49
+ * Per request: the diff; `[]` when the proposal has been overtaken; `null`
50
+ * while a read is in flight; `'unreadable'` when a read failed, so the box
51
+ * can say so instead of loading forever.
17
52
  */
53
+ export type CrFileDiff = DiffLine[] | null | 'unreadable';
54
+
18
55
  export function useCrFileDiffs(
19
56
  crs: PullRequestSummary[],
20
57
  repoRelativePath: string,
21
- mainRaw: string | null,
22
58
  revision = 0,
23
- ): Map<number, DiffLine[] | null> {
59
+ ): Map<number, CrFileDiff> {
24
60
  const [contents, setContents] = useState<Map<string, string>>(new Map());
61
+ const [forkReads, setForkReads] = useState<Map<string, ForkPointFile>>(new Map());
62
+ /** Keys whose branch, fork or main read failed — no comparison is coming. */
63
+ const [failed, setFailed] = useState<Set<string>>(new Set());
25
64
  /** Requests already made, so a failed read is not retried on every render. */
26
65
  const asked = useRef<Set<string>>(new Set());
66
+ const forkAsked = useRef<Set<string>>(new Set());
67
+ const targetAsked = useRef<Set<string>>(new Set());
68
+ /**
69
+ * Bumped when something moved a request — an apply, a cancel, an Update.
70
+ * Both sides are re-read: a request that moved has a new head as well as a
71
+ * new fork point, and half a re-read is a diff between two moments.
72
+ */
73
+ const [staleEpoch, setStaleEpoch] = useState(0);
74
+ useEffect(
75
+ () =>
76
+ subscribePrStale(() => {
77
+ asked.current.clear();
78
+ forkAsked.current.clear();
79
+ targetAsked.current.clear();
80
+ setStaleEpoch((e) => e + 1);
81
+ }),
82
+ [],
83
+ );
27
84
 
28
85
  // Only the change requests that actually touch this file have anything to show.
29
86
  const relevant = useMemo(
30
87
  () => crs.filter((c) => c.touchedNodePaths.includes(repoRelativePath)),
31
88
  [crs, repoRelativePath],
32
89
  );
33
- const key = (n: number) => `${n}::${repoRelativePath}::${revision}`;
90
+ const key = (n: number) => `${n}::${repoRelativePath}::${revision}::${staleEpoch}`;
91
+ const forkKey = (n: number) => `${n}::${repoRelativePath}::${staleEpoch}`;
92
+ /**
93
+ * The fallback read is keyed by the TARGET BRANCH, not just the path: a
94
+ * request does not have to target the default branch, and two requests on
95
+ * one file can aim at different ones. Keying by path alone served whichever
96
+ * target happened to be read first to every no-history request on the file.
97
+ */
98
+ const targetKey = (base: string) => `target:${base}::${repoRelativePath}::${staleEpoch}`;
34
99
  const wanted = relevant.map((c) => `${c.number}|${c.branch}`).join(',');
35
100
 
101
+ /**
102
+ * Exactly the keys the CURRENT generation reads under. Held in a ref and
103
+ * refreshed before the reads are started, because the alternative — each
104
+ * callback testing against the generation it closed over — lets a slow read
105
+ * from an older generation prune the newer one's answers on arrival, and
106
+ * the `asked` guard then never fetches them again: a box loading forever.
107
+ * Anything not in this set is either a generation that has passed or a
108
+ * request that is no longer on this file, and neither is worth keeping.
109
+ */
110
+ const liveKeys = useRef<Set<string>>(new Set());
111
+ const live = (k: string) => liveKeys.current.has(k);
112
+ const prunedMap = <V,>(m: Map<string, V>) => new Map([...m].filter(([k]) => live(k)));
113
+ const prunedSet = (s: Set<string>) => new Set([...s].filter(live));
114
+ useEffect(() => {
115
+ liveKeys.current = new Set([
116
+ ...relevant.map((cr) => key(cr.number)),
117
+ ...relevant.map((cr) => forkKey(cr.number)),
118
+ ...relevant.map((cr) => targetKey(cr.base)),
119
+ ]);
120
+ // Declared BEFORE the read effect so it has already run when those reads
121
+ // are started, and so before any of their answers can arrive.
122
+ // eslint-disable-next-line react-hooks/exhaustive-deps
123
+ }, [wanted, repoRelativePath, revision, staleEpoch]);
124
+
36
125
  /**
37
126
  * No `cancelled` flag — see `useDefaultBranchFile` for why one would deadlock
38
127
  * against the `asked` guard under StrictMode. Stale answers are discarded by
39
- * the KEY (cr + path + revision), not by cleanup.
128
+ * the KEY (cr + path + revision + epoch), not by cleanup.
40
129
  */
41
130
  useEffect(() => {
42
131
  // A binary file has no honest text diff, and line-diffing decoded binary
43
132
  // bytes is quadratic enough to hang the tab — never even read it. The
44
133
  // boxes render their own binary notice instead of a diff.
45
134
  if (isBinaryFile(repoRelativePath)) return;
135
+ // The guards are refs, so they outlive the generation that filled them.
136
+ for (const set of [asked.current, forkAsked.current, targetAsked.current]) {
137
+ for (const k of [...set]) if (!live(k)) set.delete(k);
138
+ }
46
139
  for (const cr of relevant) {
47
140
  const k = key(cr.number);
48
141
  if (asked.current.has(k)) continue;
49
142
  asked.current.add(k);
50
143
  readFileOnBranch(cr.branch, repoRelativePath)
51
- .then((content) => setContents((m) => new Map(m).set(k, content)))
144
+ .then((content) => {
145
+ if (live(k)) setContents((m) => prunedMap(m).set(k, content));
146
+ })
147
+ .catch((err: unknown) => {
148
+ if (!live(k)) return;
149
+ // A 404 is the branch's own answer that the file is not there: the
150
+ // request DELETES it, and every line removed is exactly its diff.
151
+ if (err instanceof WorkspaceApiError && err.status === 404) {
152
+ setContents((m) => prunedMap(m).set(k, ''));
153
+ return;
154
+ }
155
+ // Anything else is deliberately NOT `''`. Storing empty for an
156
+ // unreadable branch copy would diff as "every line deleted" and
157
+ // present a proposal to erase the file. No content means no claim:
158
+ // the box says it couldn't read.
159
+ setFailed((s) => prunedSet(s).add(k));
160
+ });
161
+ }
162
+ for (const cr of relevant) {
163
+ const fk = forkKey(cr.number);
164
+ if (forkAsked.current.has(fk)) continue;
165
+ forkAsked.current.add(fk);
166
+ readFileAtForkPoint(cr.number, null, repoRelativePath)
167
+ .then((read) => {
168
+ if (!live(fk)) return;
169
+ setForkReads((m) => prunedMap(m).set(fk, read));
170
+ // No fork point (no shared history): main's tip is the only "before"
171
+ // left, and it is read now, under this generation's key.
172
+ const tk = targetKey(cr.base);
173
+ if (read.forkSha === null && !targetAsked.current.has(tk)) {
174
+ targetAsked.current.add(tk);
175
+ readFileOnBranch(cr.base, repoRelativePath)
176
+ .then((content) => {
177
+ if (live(tk)) setContents((m) => prunedMap(m).set(tk, content));
178
+ })
179
+ .catch((err: unknown) => {
180
+ if (!live(tk)) return;
181
+ // Absent on the target is a real answer: the request adds the file.
182
+ if (err instanceof WorkspaceApiError && err.status === 404) {
183
+ setContents((m) => prunedMap(m).set(tk, ''));
184
+ return;
185
+ }
186
+ setFailed((s) => prunedSet(s).add(tk));
187
+ });
188
+ }
189
+ })
52
190
  .catch(() => {
53
- // Deliberately NOT `''`. Storing empty for an unreadable branch copy
54
- // would diff as "every line deleted" and present a proposal to erase
55
- // the file. No content means no claim: the box keeps waiting.
191
+ if (!live(fk)) return;
192
+ // Same rule for the before side: an unreadable fork point is no
193
+ // claim, and falling back to main would bring back the very
194
+ // "deletions" this reads the fork point to avoid.
195
+ setFailed((s) => prunedSet(s).add(fk));
56
196
  });
57
197
  }
58
198
  // `contents` is intentionally out: it changes on every arrival, and the
59
199
  // `asked` guard already makes each (cr, file, revision) fetch once.
60
200
  // eslint-disable-next-line react-hooks/exhaustive-deps
61
- }, [wanted, repoRelativePath, revision]);
201
+ }, [wanted, repoRelativePath, revision, staleEpoch]);
62
202
 
63
203
  return useMemo(() => {
64
- const out = new Map<number, DiffLine[] | null>();
204
+ const out = new Map<number, CrFileDiff>();
65
205
  for (const cr of relevant) {
206
+ const fork = forkReads.get(forkKey(cr.number));
207
+ const noSharedHistory = fork !== undefined && fork.forkSha === null;
208
+ if (
209
+ failed.has(key(cr.number)) ||
210
+ failed.has(forkKey(cr.number)) ||
211
+ (noSharedHistory && failed.has(targetKey(cr.base)))
212
+ ) {
213
+ out.set(cr.number, 'unreadable');
214
+ continue;
215
+ }
66
216
  const branchRaw = contents.get(key(cr.number));
67
- if (mainRaw === null || branchRaw === undefined) {
217
+ // The before side: the fork point's text; '' when the request ADDS the
218
+ // file (absent at the fork point); main only when there is no fork point.
219
+ const before =
220
+ fork === undefined
221
+ ? null
222
+ : noSharedHistory
223
+ ? (contents.get(targetKey(cr.base)) ?? null)
224
+ : (fork.content ?? '');
225
+ if (before === null || branchRaw === undefined) {
68
226
  out.set(cr.number, null);
69
227
  continue;
70
228
  }
71
- const d = diffLines(mainRaw, branchRaw);
72
- // A proposal whose text now matches main has been overtaken — showing an
73
- // empty diff would ask for a decision about nothing.
229
+ const d = diffLines(before, branchRaw);
230
+ // A proposal that no longer changes anything has been overtaken — showing
231
+ // an empty diff would ask for a decision about nothing.
74
232
  out.set(cr.number, hasChanges(d) ? d : []);
75
233
  }
76
234
  return out;
77
235
  // eslint-disable-next-line react-hooks/exhaustive-deps
78
- }, [relevant, contents, mainRaw, repoRelativePath, revision]);
236
+ }, [relevant, contents, forkReads, failed, repoRelativePath, revision, staleEpoch]);
79
237
  }