@bevel-software/platform-core-frontend 0.4.1 → 0.5.1

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 (327) hide show
  1. package/THIRD-PARTY-NOTICES.md +5366 -0
  2. package/package.json +7 -4
  3. package/src/core/CoreAppShell.tsx +195 -56
  4. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  6. package/src/core/__tests__/bootstrap.test.ts +63 -0
  7. package/src/core/bootstrap.ts +73 -0
  8. package/src/core/events.ts +12 -0
  9. package/src/core/registry.ts +58 -9
  10. package/src/index.css +100 -11
  11. package/src/index.ts +24 -23
  12. package/src/lib/utils.ts +93 -117
  13. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  15. package/src/modules/access/api.ts +49 -0
  16. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  17. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  18. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  19. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  20. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  21. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  23. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  24. package/src/modules/admin/state/admin.context.tsx +15 -6
  25. package/src/modules/auth/components/AccountPage.tsx +11 -11
  26. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  27. package/src/modules/auth/services/sso.ts +47 -1
  28. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  29. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  30. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  31. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  32. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  33. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  34. package/src/modules/change-requests/change-requests.css +22 -0
  35. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  36. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  37. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  38. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  39. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  40. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  41. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  42. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  43. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  44. package/src/modules/change-requests/services/propose.api.ts +162 -0
  45. package/src/modules/change-requests/utils/author.ts +47 -0
  46. package/src/modules/change-requests/utils/conflict.ts +38 -0
  47. package/src/modules/change-requests/utils/diff.ts +80 -0
  48. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  49. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  50. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  51. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  52. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  53. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  54. package/src/modules/git/components/DiffView.tsx +4 -4
  55. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  56. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  57. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  58. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  59. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  60. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  61. package/src/modules/git/hooks/useGitState.ts +15 -14
  62. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  63. package/src/modules/git/services/error-messages.ts +7 -7
  64. package/src/modules/git/services/git.api.ts +17 -11
  65. package/src/modules/git/services/pr-prompts.ts +2 -2
  66. package/src/modules/git/state/git.context.ts +10 -1
  67. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  68. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  69. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  70. package/src/modules/layout/breakpoints.ts +6 -0
  71. package/src/modules/layout/components/AppLayout.tsx +17 -5
  72. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  73. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  74. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  75. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  76. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  77. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  78. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  79. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  80. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  81. package/src/modules/layout/state/sidebar.ts +200 -0
  82. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  83. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  84. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  85. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  86. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  89. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  90. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  91. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  92. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  93. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  94. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  95. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  96. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  97. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  98. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  99. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  100. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  101. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  102. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  103. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  104. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  105. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  106. package/src/modules/library/__tests__/status.test.ts +113 -20
  107. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  108. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  109. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  110. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  111. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  112. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  113. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  114. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  115. package/src/modules/library/components/GroupPage.tsx +373 -0
  116. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  117. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  118. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  119. package/src/modules/library/components/LibraryCard.tsx +123 -102
  120. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  121. package/src/modules/library/components/LibraryPage.tsx +111 -227
  122. package/src/modules/library/components/LockGlyph.tsx +31 -0
  123. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  124. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  125. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  126. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  127. package/src/modules/library/components/PageActions.tsx +156 -0
  128. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  129. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  130. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  131. package/src/modules/library/components/StatusDot.tsx +25 -0
  132. package/src/modules/library/components/ToolLogo.tsx +171 -0
  133. package/src/modules/library/components/group-page-parts.tsx +419 -0
  134. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  135. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  136. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  137. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  138. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  139. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  140. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  141. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  142. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  143. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  144. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  145. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  146. package/src/modules/library/hooks/useToolPage.ts +145 -0
  147. package/src/modules/library/library.css +33 -245
  148. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  149. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  150. package/src/modules/library/routes/library-paths.ts +191 -0
  151. package/src/modules/library/services/groups.api.ts +189 -0
  152. package/src/modules/library/services/library.api.ts +291 -164
  153. package/src/modules/library/services/tools.api.ts +60 -0
  154. package/src/modules/library/state/library-context.ts +22 -0
  155. package/src/modules/library/state/library-data.tsx +223 -0
  156. package/src/modules/library/state/toast.context.ts +32 -0
  157. package/src/modules/library/state/toast.tsx +84 -42
  158. package/src/modules/library/utils/clipboard.ts +33 -0
  159. package/src/modules/library/utils/group-summary.ts +68 -0
  160. package/src/modules/library/utils/names.ts +30 -0
  161. package/src/modules/library/utils/navigate-external.ts +15 -0
  162. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  163. package/src/modules/library/utils/personal-group.ts +36 -0
  164. package/src/modules/library/utils/status.ts +108 -25
  165. package/src/modules/library/utils/toast-duration.ts +16 -0
  166. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  167. package/src/modules/onboarding/agent-clients.ts +48 -0
  168. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  169. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  170. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  171. package/src/modules/onboarding/paths.ts +9 -0
  172. package/src/modules/onboarding/state/onboarding.ts +191 -0
  173. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  174. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  175. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  176. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  177. package/src/modules/review/components/DiffViewer.tsx +4 -4
  178. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  179. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  180. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  181. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  182. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  183. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  184. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  185. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  186. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  187. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  188. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  189. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  190. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  191. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  192. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  193. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  194. package/src/modules/settings/settings-nav-items.tsx +166 -0
  195. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  196. package/src/modules/setup/components/SetupGate.tsx +67 -0
  197. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  198. package/src/modules/setup/services/setup.api.ts +106 -0
  199. package/src/modules/setup/utils/git-host.ts +34 -0
  200. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  201. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  202. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  203. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  204. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  205. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  206. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  207. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  208. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  209. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  210. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  211. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  212. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  213. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  214. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  215. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  216. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  217. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  218. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  219. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  220. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  221. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  222. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  223. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  224. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  225. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  226. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  227. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  228. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  229. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  230. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  231. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  232. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  233. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  234. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  235. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  236. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  237. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  238. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  240. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  241. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  242. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  243. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  244. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  245. package/src/modules/workspace/components/renderers/index.ts +78 -2
  246. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  247. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  248. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  249. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  250. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  251. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  252. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  253. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  254. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  255. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  256. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  257. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  258. package/src/modules/workspace/services/workspace.api.ts +9 -2
  259. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  260. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  261. package/src/modules/workspace/state/workspace.context.ts +9 -0
  262. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  263. package/src/modules/workspace/utils/diff.ts +130 -53
  264. package/src/modules/workspace/utils/fileTree.ts +7 -4
  265. package/src/modules/workspace/workspace.css +28 -0
  266. package/src/shared/components/Badge.tsx +62 -0
  267. package/src/shared/components/Banner.tsx +58 -0
  268. package/src/shared/components/Button.tsx +90 -0
  269. package/src/shared/components/Dialog.tsx +6 -6
  270. package/src/shared/components/Field.tsx +45 -0
  271. package/src/shared/components/IconButton.tsx +74 -0
  272. package/src/shared/components/ListRow.tsx +96 -0
  273. package/src/shared/components/Menu.tsx +88 -0
  274. package/src/shared/components/PageShell.tsx +8 -5
  275. package/src/shared/components/Surface.tsx +86 -0
  276. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  277. package/src/shared/components/index.ts +48 -0
  278. package/src/shared/components/useDismissableMenu.ts +71 -0
  279. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  280. package/src/shared/theme/index.css +12 -0
  281. package/src/shared/theme/measure.ts +64 -0
  282. package/src/shared/theme/shadows.css +34 -0
  283. package/src/shared/theme/tokens.css +193 -0
  284. package/src/test-setup.ts +9 -0
  285. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  286. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  287. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  288. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  289. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  290. package/src/modules/library/__tests__/diff.test.ts +0 -62
  291. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  292. package/src/modules/library/components/CompareView.tsx +0 -357
  293. package/src/modules/library/components/DetailDialog.tsx +0 -566
  294. package/src/modules/library/components/GearIcon.tsx +0 -12
  295. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  296. package/src/modules/library/components/StatusGem.tsx +0 -21
  297. package/src/modules/library/components/SuggestChange.tsx +0 -171
  298. package/src/modules/library/components/particles.ts +0 -50
  299. package/src/modules/library/state/loadout.tsx +0 -129
  300. package/src/modules/library/utils/diff.ts +0 -102
  301. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  302. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  303. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  304. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  305. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  306. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  307. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  308. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  309. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  310. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  311. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  312. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  313. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  314. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  315. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  316. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  317. package/src/modules/pr/components/PrHeader.tsx +0 -45
  318. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  319. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  320. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  321. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  322. package/src/modules/pr/components/PrViewer.tsx +0 -364
  323. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  324. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  325. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  326. package/src/modules/pr/utils/parsePatch.ts +0 -57
  327. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -0,0 +1,713 @@
1
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
2
+ import {
3
+ type FileDiffPayload,
4
+ type PullRequestDetail,
5
+ type PullRequestSummary,
6
+ } from '@bevel-software/platform-shared';
7
+ import '../change-requests.css';
8
+ import { Banner, Button, Surface } from '../../../shared/components';
9
+ import { useModalLayer } from '../../../shared/components/useModalLayer';
10
+ import { cn } from '../../../lib/utils';
11
+ import { AuthContext } from '../../auth/state/auth.context';
12
+ import { fetchPrDetail } from '../../pr/services/pr-detail.api';
13
+ import { approvePrFile, revertPrFile, unapprovePrFile } from '../../pr/services/pr-approvals.api';
14
+ import { deleteChangeRequest } from '../../pr/services/pr-cancel.api';
15
+ import { useApplyChangeRequest } from '../hooks/useApplyChangeRequest';
16
+ import { readFileOnBranch } from '../services/change-requests.api';
17
+ import { changeAuthorName } from '../utils/author';
18
+ import { conflictResolutionPrompt } from '../utils/conflict';
19
+ import { ConflictHelp } from './ConflictHelp';
20
+ import { useDefaultBranchFile } from '../hooks/useFileOnBranch';
21
+ import { diffLines, type DiffLine } from '../utils/diff';
22
+ import { isBinaryFile } from '../../workspace/components/renderers';
23
+ import { MarkdownDiffViewer } from '../../review/components/MarkdownDiffViewer';
24
+ import { CrFileTree, type CrTreeFileState } from './CrFileTree';
25
+
26
+ /**
27
+ * Extra context for the file list — NOT a filter. The dialog always shows
28
+ * EVERY file the request touches, repo-relative, whatever surface opened it:
29
+ * a decision about the whole request must not hide part of it behind a badge.
30
+ * A scope only ADDS the surface's own files (a skill's SKILL.md and bundle)
31
+ * so the owner can read the untouched parts of the thing under review too.
32
+ */
33
+ export interface ChangeRequestScope {
34
+ /** Repo-root-relative folder, no trailing slash (e.g. `Groups/gtm/rfi`). */
35
+ prefix: string;
36
+ /** Files that ALWAYS list, relative to `prefix`, whether touched or not. */
37
+ baseFiles: string[];
38
+ }
39
+
40
+ interface ChangeRequestDialogProps {
41
+ cr: PullRequestSummary;
42
+ scope?: ChangeRequestScope;
43
+ onClose(): void;
44
+ /** Applying is the only verdict this view reaches. Declining a change
45
+ * request lives on the skill page, beside the request's own row. */
46
+ onResolved(): void;
47
+ }
48
+
49
+ /**
50
+ * The whole change request, as one decision — Juan's change-request view,
51
+ * and THE change-request view for every surface (the skill page opens it
52
+ * over a skill scope; the Knowledge viewer opens it unscoped).
53
+ *
54
+ * The per-file boxes answer "what does this do to the file I am reading?".
55
+ * This answers the different question an owner has to answer before applying
56
+ * anything: what does this change do as a WHOLE? So it reads top-down as an
57
+ * argument — what is being asked, why, how big it is, and only then the
58
+ * files — rather than as two panels to compare word by word.
59
+ *
60
+ * The layout is deliberately fixed to the viewport: the buttons never move and
61
+ * the document scrolls to meet them. A decision surface where the verdict
62
+ * scrolls off screen invites the reader to act before reaching the bottom.
63
+ */
64
+ export function ChangeRequestDialog({
65
+ cr,
66
+ scope,
67
+ onClose,
68
+ onResolved,
69
+ }: ChangeRequestDialogProps) {
70
+ const [detail, setDetail] = useState<PullRequestDetail | null>(null);
71
+ const [error, setError] = useState<string | null>(null);
72
+ const [branchContents, setBranchContents] = useState<Record<string, string | null>>({});
73
+ /** Files whose branch copy could not be read — shown as such, never guessed at. */
74
+ const [unreadable, setUnreadable] = useState<Set<string>>(new Set());
75
+ const [blocked, setBlocked] = useState(false);
76
+
77
+ const isTop = useModalLayer(true);
78
+ useEffect(() => {
79
+ function onKeyDown(e: KeyboardEvent) {
80
+ if (e.key === 'Escape' && isTop()) {
81
+ e.stopPropagation();
82
+ onClose();
83
+ }
84
+ }
85
+ document.addEventListener('keydown', onKeyDown);
86
+ return () => document.removeEventListener('keydown', onKeyDown);
87
+ }, [isTop, onClose]);
88
+
89
+ useEffect(() => {
90
+ let cancelled = false;
91
+ fetchPrDetail(cr.number)
92
+ .then((d) => {
93
+ if (!cancelled) setDetail(d);
94
+ })
95
+ .catch((err) => {
96
+ if (!cancelled) {
97
+ setError(err instanceof Error ? err.message : "Couldn't load this change request.");
98
+ }
99
+ });
100
+ return () => {
101
+ cancelled = true;
102
+ };
103
+ }, [cr.number]);
104
+
105
+ // EVERYTHING is repo-relative, scoped or not — the scope's baseFiles are
106
+ // lifted to full paths, and every touched file lists whatever folder it is
107
+ // in. The dialog is a decision about the WHOLE request; a file it touches
108
+ // outside the surface that opened it is part of the decision, not a badge.
109
+ const mainFiles = useMemo(
110
+ () => (scope ? scope.baseFiles.map((f) => `${scope.prefix}/${f}`) : []),
111
+ [scope],
112
+ );
113
+ const changedFiles = useMemo(() => {
114
+ const set = new Set<string>();
115
+ for (const f of detail?.files ?? []) set.add(f.path);
116
+ return set;
117
+ }, [detail]);
118
+ const addedFiles = useMemo(
119
+ () => (detail?.files ?? []).filter((f) => f.status === 'added').map((f) => f.path),
120
+ [detail],
121
+ );
122
+ const allFiles = useMemo(() => {
123
+ const touched = [...changedFiles].filter((f) => !mainFiles.includes(f));
124
+ return [...mainFiles, ...touched];
125
+ }, [mainFiles, changedFiles]);
126
+
127
+ /** The scale line: how much this touches, in the KB's own terms. */
128
+ const scale = useMemo(() => {
129
+ const files = detail?.files ?? [];
130
+ return {
131
+ files: files.length,
132
+ plus: files.reduce((n, f) => n + f.additions, 0),
133
+ minus: files.reduce((n, f) => n + f.deletions, 0),
134
+ };
135
+ }, [detail]);
136
+
137
+ /**
138
+ * Land on the first changed file, until the reader picks one — DERIVED, so
139
+ * the landing happens on the render the detail arrives rather than one render
140
+ * later. `picked` staying null is what keeps "I haven't chosen yet" distinct
141
+ * from "I chose the first file".
142
+ */
143
+ const [picked, setPicked] = useState<string | null>(null);
144
+ const selected =
145
+ picked ?? allFiles.find((f) => changedFiles.has(f)) ?? allFiles[0] ?? '';
146
+ const setSelected = setPicked;
147
+
148
+ /**
149
+ * In-flight guard as a ref, not as a `null` placeholder written into state:
150
+ * writing the placeholder was a synchronous setState inside the effect, which
151
+ * costs a cascading render on every file click. The ref answers "already
152
+ * asked?" without a render, and only the arriving content is state.
153
+ */
154
+ // A binary file (image, pdf, spreadsheet…) has no honest TEXT before and
155
+ // after. Reading its bytes as a string and line-diffing them used to hang
156
+ // the tab — the LCS differ is quadratic, and a binary blob decodes into
157
+ // pathological "lines" — so a binary selection never fetches and never
158
+ // diffs; it states what happened to the file instead.
159
+ const selectedIsBinary = selected !== '' && isBinaryFile(selected);
160
+ // Markdown renders as a DOCUMENT with red/green change blocks — the same
161
+ // `MarkdownDiffViewer` the review flow and version history use — because the
162
+ // person deciding on a knowledge or skill change reads prose, not source.
163
+ // Everything else keeps the marked-source view below.
164
+ const selectedIsMarkdown = /\.md$/i.test(selected);
165
+
166
+ const asked = useRef<Set<string>>(new Set());
167
+ useEffect(() => {
168
+ // `selected` is '' until the detail names any file in an unscoped dialog —
169
+ // nothing to read yet. Binary files are never read at all (above).
170
+ if (selected && !selectedIsBinary && !asked.current.has(selected)) {
171
+ asked.current.add(selected);
172
+ readFileOnBranch(cr.branch, selected)
173
+ .then((content) => setBranchContents((c) => ({ ...c, [selected]: content })))
174
+ // NOT `''`. An unreadable branch copy stored as empty would diff as
175
+ // "every line deleted" — a change request that erases the file.
176
+ .catch(() => setUnreadable((s) => new Set(s).add(selected)));
177
+ }
178
+ }, [selected, selectedIsBinary, cr.branch]);
179
+
180
+ const isAdded = addedFiles.includes(selected);
181
+ // Raw-vs-raw: the skills API hands back SKILL.md's PARSED body (frontmatter
182
+ // stripped), and diffing that against a raw branch read renders the
183
+ // frontmatter as a deletion and the whole file as changed.
184
+ const mainRaw = useDefaultBranchFile(
185
+ isAdded || !selected || selectedIsBinary ? null : selected,
186
+ );
187
+ const branchRaw = branchContents[selected] ?? null;
188
+
189
+ /**
190
+ * BOTH sides or nothing.
191
+ *
192
+ * The empty string is not a stand-in for "hasn't loaded". Diffing `''`
193
+ * against the branch copy marks every line added and paints the whole file
194
+ * green — a confident claim that this change request rewrites the file,
195
+ * shown right above the Apply button, while the scale line beside it
196
+ * correctly reads `+1 −1`. A file genuinely new on the branch is the ONE
197
+ * case where an empty other side is real, and `isAdded` is how we know.
198
+ */
199
+ const bothSidesIn = branchRaw !== null && (isAdded || mainRaw !== null);
200
+ // Only for the marked-source view: the markdown viewer diffs internally, so
201
+ // computing this for an .md selection would run the same LCS twice.
202
+ const diff: DiffLine[] | null =
203
+ bothSidesIn && !selectedIsMarkdown
204
+ ? diffLines(isAdded ? '' : (mainRaw as string), branchRaw as string)
205
+ : null;
206
+ // Memoised as a VALUE: `MarkdownDiffViewer` keys its diff computation on
207
+ // payload identity, so an object literal built in render would make every
208
+ // dialog state change (an apply phase tick, another file's content
209
+ // arriving) re-run the LCS and frontmatter parse.
210
+ const mdPayload = useMemo<FileDiffPayload | null>(
211
+ () =>
212
+ selectedIsMarkdown && bothSidesIn
213
+ ? {
214
+ path: selected,
215
+ kind: isAdded ? 'added' : 'modified',
216
+ baseline: isAdded ? null : mainRaw,
217
+ current: branchRaw,
218
+ isBinary: false,
219
+ }
220
+ : null,
221
+ [selectedIsMarkdown, bothSidesIn, selected, isAdded, mainRaw, branchRaw],
222
+ );
223
+ const touchesSelected = changedFiles.has(selected);
224
+
225
+ /** Per-file approval verdicts, straight from the detail. */
226
+ const approvalByPath = useMemo(
227
+ () => new Map((detail?.approvals ?? []).map((a) => [a.path, a])),
228
+ [detail],
229
+ );
230
+
231
+ /**
232
+ * The old CR system's rule, restored: Apply exists only when every file is
233
+ * either already approved or approvable BY THIS VIEWER (they hold write on
234
+ * it, so their click completes the gate). Anything less and Apply was a
235
+ * button that walked into "Waiting on approval for …" — offering a verdict
236
+ * the viewer cannot actually deliver.
237
+ */
238
+ const canApply =
239
+ detail !== null &&
240
+ detail.approvals.length > 0 &&
241
+ detail.approvals.every((a) => a.isApproved || a.viewerCanApprove);
242
+
243
+ /** Approve / revert verbs — per file, from the tree. */
244
+ const [verbBusy, setVerbBusy] = useState(false);
245
+ const [verbError, setVerbError] = useState<string | null>(null);
246
+ useEffect(() => {
247
+ setVerbError(null);
248
+ }, [selected]);
249
+
250
+ async function toggleApprove(path: string, approved: boolean) {
251
+ if (!detail || verbBusy) return;
252
+ setVerbBusy(true);
253
+ setVerbError(null);
254
+ try {
255
+ const approvals = approved
256
+ ? await unapprovePrFile(cr.number, path)
257
+ : await approvePrFile(cr.number, path);
258
+ setDetail((d) => (d ? { ...d, approvals } : d));
259
+ } catch (err) {
260
+ setVerbError(err instanceof Error ? err.message : "Couldn't record that.");
261
+ } finally {
262
+ setVerbBusy(false);
263
+ }
264
+ }
265
+
266
+ async function revertFile(path: string) {
267
+ if (!detail || verbBusy) return;
268
+ setVerbBusy(true);
269
+ setVerbError(null);
270
+ try {
271
+ const result = await revertPrFile(cr.number, path);
272
+ if (result.closed) {
273
+ // That was the last file: the request closed itself and its branch
274
+ // is retired. The dialog's subject is gone — leave through the same
275
+ // door an apply does, so every list behind it refreshes.
276
+ onResolved();
277
+ return;
278
+ }
279
+ // The file is out of the diff; the branch copy we cached for it is
280
+ // stale. Refetch the detail and drop the cached read so a re-selection
281
+ // (via the scope's baseFiles) reads the restored content.
282
+ asked.current.delete(path);
283
+ setBranchContents((c) => {
284
+ const next = { ...c };
285
+ delete next[path];
286
+ return next;
287
+ });
288
+ setPicked(null);
289
+ setDetail(await fetchPrDetail(cr.number));
290
+ } catch (err) {
291
+ setVerbError(err instanceof Error ? err.message : "Couldn't revert this file.");
292
+ } finally {
293
+ setVerbBusy(false);
294
+ }
295
+ }
296
+
297
+ // Tolerant read (not useAuth): the dialog renders in tests without the
298
+ // provider, and the email only sharpens the withdraw affordance.
299
+ const viewerEmail = useContext(AuthContext)?.user?.email ?? '';
300
+
301
+ /** The tree's per-file state, in the file list's order. */
302
+ const treeFiles: CrTreeFileState[] = useMemo(() => {
303
+ const statusByPath = new Map((detail?.files ?? []).map((f) => [f.path, f.status]));
304
+ return allFiles.map((path) => ({
305
+ path,
306
+ changed: changedFiles.has(path),
307
+ added: addedFiles.includes(path),
308
+ status: statusByPath.get(path),
309
+ approval: approvalByPath.get(path),
310
+ }));
311
+ }, [detail, allFiles, changedFiles, addedFiles, approvalByPath]);
312
+
313
+ /** The footer's verdicts: apply plainly, apply by covering, or wait. */
314
+ const allApproved =
315
+ detail !== null && detail.approvals.length > 0 && detail.approvals.every((a) => a.isApproved);
316
+
317
+ /** Admin-only: delete the request and its branch, with an armed confirm. */
318
+ const [deleteArmed, setDeleteArmed] = useState(false);
319
+ const [deleting, setDeleting] = useState(false);
320
+ async function deleteRequest() {
321
+ if (deleting) return;
322
+ setDeleting(true);
323
+ setVerbError(null);
324
+ try {
325
+ await deleteChangeRequest(cr.number);
326
+ onResolved();
327
+ } catch (err) {
328
+ setVerbError(err instanceof Error ? err.message : "Couldn't delete this change request.");
329
+ setDeleting(false);
330
+ setDeleteArmed(false);
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Apply = record the approvals the gate requires, then merge, then wait for
336
+ * the merge to land. The POST only acks — see `useApplyChangeRequest` for
337
+ * why awaiting it is not an answer.
338
+ */
339
+ const applying = useApplyChangeRequest({
340
+ onApplied: () => onResolved(),
341
+ onFailed: (_number, refusal) => {
342
+ // Git refusing the merge IS the conflict answer — say what happened and
343
+ // what fixes it, instead of leaving a button that will fail again. Any
344
+ // other refusal (an approval the gate is still waiting on, a transient
345
+ // git error) can change under the reader, so it is reported with the
346
+ // button intact.
347
+ if (refusal.conflicts) setBlocked(true);
348
+ else setError(refusal.reason);
349
+ },
350
+ });
351
+ const applyBusy = applying.activeCr === cr.number;
352
+ // Name the step: recording approvals and merging are separately slow, and one
353
+ // label over both makes the longer half look stalled.
354
+ const applyLabel = applying.phase === 'approving' ? 'Approving…' : 'Applying…';
355
+
356
+ const author = changeAuthorName(cr);
357
+ const firstName = author.split(' ')[0];
358
+ const why = authorsReason(detail?.body);
359
+ const [whyExpanded, setWhyExpanded] = useState(false);
360
+ /**
361
+ * Whether the one-line view is actually hiding anything — a short reason
362
+ * with a pointless "Read more" beside it would be a button that does
363
+ * nothing visible. Length is a heuristic (true truncation depends on the
364
+ * viewport), erring toward showing the toggle: a newline always overflows a
365
+ * single line, and ~90 characters approximates one row of the quote.
366
+ */
367
+ const whyOverflows = !!why && (why.includes('\n') || why.length > 90);
368
+
369
+ return (
370
+ <div
371
+ className="fixed inset-0 z-[60] flex flex-col"
372
+ role="dialog"
373
+ aria-modal="true"
374
+ aria-label={`Change request: ${cr.title}`}
375
+ >
376
+ <div className="absolute inset-0 bg-scrim" onClick={onClose} />
377
+
378
+ <Surface
379
+ tone="surface"
380
+ radius="2xl"
381
+ elevation="overlay"
382
+ className="relative mx-auto mt-[4vh] mb-[4vh] flex h-[92vh] w-full max-w-6xl flex-col overflow-hidden"
383
+ >
384
+ <div className="flex items-start gap-4 px-8 pt-7">
385
+ <div className="min-w-0 flex-1">
386
+ <p className="text-label font-semibold uppercase text-ink-faint">Change request</p>
387
+ <h1 className="mt-1 text-title font-medium text-ink">{cr.title}</h1>
388
+ <p className="mt-2 flex flex-wrap items-center gap-2 text-detail text-ink-muted">
389
+ <span>{author}</span>
390
+ <span aria-hidden="true" className="text-ink-faint">·</span>
391
+ <span className="font-mono">{cr.branch}</span>
392
+ </p>
393
+ </div>
394
+ <Button variant="quiet" size="sm" onClick={onClose} aria-label="Close change request">
395
+ ✕
396
+ </Button>
397
+ </div>
398
+
399
+ {/* Why, in the author's words. Omitted rather than faked when the
400
+ request carries no description — an empty quote block reads as the
401
+ author having said nothing worth reading.
402
+
403
+ ONE line by default, because agents write essays: the decision is
404
+ made on the diff below, and every line the description takes is a
405
+ line the file grid (the dialog's one flexible region) loses. Read
406
+ more opens the whole thing (self-scrolling past half the surface,
407
+ so even an essay never pushes the files off screen); Hide folds it
408
+ back to the line. */}
409
+ {why && (
410
+ <blockquote
411
+ className={cn(
412
+ 'mx-8 mt-5 shrink-0 border-l-2 border-line-strong pl-4 text-body text-ink',
413
+ whyExpanded && 'max-h-[50vh] overflow-y-auto',
414
+ )}
415
+ >
416
+ {whyExpanded ? (
417
+ <>
418
+ <span className="whitespace-pre-wrap">{why}</span>{' '}
419
+ <button
420
+ type="button"
421
+ className="text-detail font-medium text-ink-faint transition-colors hover:text-ink"
422
+ onClick={() => setWhyExpanded(false)}
423
+ >
424
+ Hide
425
+ </button>
426
+ </>
427
+ ) : (
428
+ <span className="flex items-baseline gap-3">
429
+ <span className="min-w-0 flex-1 truncate">{why}</span>
430
+ {whyOverflows && (
431
+ <button
432
+ type="button"
433
+ className="shrink-0 text-detail font-medium text-ink-faint transition-colors hover:text-ink"
434
+ onClick={() => setWhyExpanded(true)}
435
+ >
436
+ Read more
437
+ </button>
438
+ )}
439
+ </span>
440
+ )}
441
+ </blockquote>
442
+ )}
443
+
444
+ {/* Never state a scale we do not have yet. `detail` can take many
445
+ seconds, and "0 files · +0 −0" is not a loading state — it is a
446
+ claim that this change request does nothing. */}
447
+ <p className="mt-5 px-8 text-detail tabular-nums text-ink-faint">
448
+ {detail === null ? (
449
+ 'Measuring the change…'
450
+ ) : (
451
+ <>
452
+ {scale.files} file{scale.files === 1 ? '' : 's'} ·{' '}
453
+ <span className="text-ok">+{scale.plus}</span>{' '}
454
+ <span className="text-danger">−{scale.minus}</span>
455
+ </>
456
+ )}
457
+ </p>
458
+
459
+ {error && (
460
+ <Banner tone="danger" role="alert" className="mx-8 mt-4">
461
+ {error}
462
+ </Banner>
463
+ )}
464
+
465
+ {blocked && (
466
+ <Banner tone="wait" role="alert" className="mx-8 mt-4">
467
+ <b className="font-semibold">Can't apply</b>: files changed after {firstName} wrote
468
+ this, so there is no honest before and after to apply. It has to be redone against
469
+ the current text.
470
+ <div className="mt-2.5">
471
+ <ConflictHelp prompt={conflictResolutionPrompt(cr)} />
472
+ </div>
473
+ </Banner>
474
+ )}
475
+
476
+ {/* A request that no longer changes anything — everything it proposed
477
+ has since landed on (or been removed from) the target, or its only
478
+ change was one the merge never takes (roles.yaml). The file grid
479
+ below would render a blank pill over an eternal "Loading…", which
480
+ reads as a hang; the truth is simpler and gets said instead. */}
481
+ {detail !== null && allFiles.length === 0 ? (
482
+ <div className="mt-4 min-h-0 flex-1 px-8">
483
+ <p className="mx-auto max-w-[52ch] py-10 text-center text-detail text-ink-faint">
484
+ This request doesn't change anything anymore. What it proposed is already part of
485
+ the current text, or has since been removed on its branch — there is nothing left
486
+ to review or apply. {firstName} can withdraw it.
487
+ </p>
488
+ </div>
489
+ ) : (
490
+ <>
491
+ {/* The folder on the left, the file with the change marked in it on the
492
+ right — the same reading as version history. */}
493
+ <div className="mt-4 grid min-h-0 flex-1 grid-cols-[17rem_minmax(0,1fr)] gap-7 px-8">
494
+ <Surface
495
+ tone="surface"
496
+ radius="lg"
497
+ elevation="none"
498
+ className="max-h-full self-start overflow-y-auto p-2"
499
+ >
500
+ <CrFileTree
501
+ files={treeFiles}
502
+ selected={selected}
503
+ currentUserEmail={viewerEmail}
504
+ onSelect={(p) => setSelected(p)}
505
+ onToggleApprove={(p, approved) => void toggleApprove(p, approved)}
506
+ onRevert={(p) => void revertFile(p)}
507
+ busy={verbBusy}
508
+ />
509
+ </Surface>
510
+
511
+ <div className="flex min-h-0 flex-col">
512
+ <div className="flex items-center gap-3 pb-1">
513
+ <span className="truncate font-mono text-meta text-ink-faint">
514
+ {selected}
515
+ {detail === null
516
+ ? ''
517
+ : touchesSelected
518
+ ? ' · what changes is marked'
519
+ : ' · not touched by this request'}
520
+ </span>
521
+ </div>
522
+ {verbError && (
523
+ <Banner tone="danger" role="alert" className="mb-2">
524
+ {verbError}
525
+ </Banner>
526
+ )}
527
+ <div className="min-h-0 flex-1 overflow-y-auto">
528
+ {/* The diff only needs the two file contents, so it renders as
529
+ soon as those arrive rather than waiting on the (slow) detail
530
+ fetch that tells us which files were touched. */}
531
+ {selectedIsBinary ? (
532
+ <p className="py-6 text-center text-detail text-ink-faint">
533
+ {isAdded
534
+ ? 'A new binary file (an image, a document…). There is no text to compare. Apply the request to take it as proposed.'
535
+ : touchesSelected
536
+ ? 'A binary file (an image, a document…) changed in this request. There is no text to compare.'
537
+ : 'A binary file. No text to show, and this request does not touch it.'}
538
+ </p>
539
+ ) : mdPayload !== null && !unreadable.has(selected) ? (
540
+ // An untouched file arrives here too and simply renders as a
541
+ // clean document — identical sides diff to all-same blocks —
542
+ // so the reader gets prose everywhere, marked or not.
543
+ //
544
+ // No link resolvers, deliberately. This dialog shows a diff of
545
+ // the CHANGE REQUEST's branch, while the navigation hooks
546
+ // resolve against the branch that is checked out — so wiring
547
+ // them through would send a reviewer to a different branch's
548
+ // copy of whatever they clicked, and an id-link to a node the
549
+ // change request itself creates would resolve to nothing with
550
+ // only a console warning. Links therefore render as inert
551
+ // anchors; everything else the KB pipeline brings (rendered
552
+ // details blocks, mermaid, sanitised HTML, escaped link
553
+ // destinations) applies here as it does in the document view.
554
+ // Navigating away from a modal mid-review would also lose the
555
+ // review context, so inert is the better default regardless.
556
+ <MarkdownDiffViewer payload={mdPayload} />
557
+ ) : (
558
+ <MarkedFile
559
+ diff={diff}
560
+ raw={
561
+ !selectedIsMarkdown && detail !== null && !touchesSelected
562
+ ? (mainRaw ?? branchRaw)
563
+ : null
564
+ }
565
+ unreadable={unreadable.has(selected)}
566
+ />
567
+ )}
568
+ </div>
569
+ </div>
570
+ </div>
571
+ </>
572
+ )}
573
+
574
+ {/* The verdict. Fixed to the bottom of the surface — a decision the
575
+ reader has to scroll to find is one they will make without reading. */}
576
+ <div className="mt-4 flex flex-wrap items-center gap-3 border-t border-line bg-sunken px-8 py-4">
577
+ <p className="mr-auto max-w-[52ch] text-meta text-ink-muted">
578
+ {blocked
579
+ ? `Nothing changes for anyone until ${firstName} proposes it again against the current text.`
580
+ : detail === null
581
+ ? ''
582
+ : allFiles.length === 0
583
+ ? 'Applying would change nothing, so the button stays away.'
584
+ : canApply
585
+ ? 'Every agent that connects after this picks it up. There is no staged rollout.'
586
+ : detail.mergeWarnings[0] ??
587
+ 'Waiting on approval from the files’ owners — applying is theirs to do.'}
588
+ </p>
589
+ {/* Admins carry the moderation verb: delete the request AND its
590
+ branch, armed on the first click. `viewerCanBypassMerge` is the
591
+ server's admin verdict — the DELETE route re-checks it. */}
592
+ {!blocked && detail?.viewerCanBypassMerge && (
593
+ deleteArmed ? (
594
+ <>
595
+ <Button
596
+ variant="danger"
597
+ size="sm"
598
+ disabled={deleting}
599
+ onClick={() => void deleteRequest()}
600
+ >
601
+ {deleting ? 'Deleting…' : 'Really delete request and branch?'}
602
+ </Button>
603
+ <Button variant="quiet" size="sm" disabled={deleting} onClick={() => setDeleteArmed(false)}>
604
+ Keep
605
+ </Button>
606
+ </>
607
+ ) : (
608
+ <Button
609
+ variant="quiet"
610
+ size="sm"
611
+ className="text-danger"
612
+ onClick={() => setDeleteArmed(true)}
613
+ >
614
+ Delete request
615
+ </Button>
616
+ )
617
+ )}
618
+ {/* Apply exists only when the viewer can actually deliver the
619
+ verdict. All files approved → plain Apply. Some not yet approved
620
+ but every one of them approvable BY THIS VIEWER (write access) →
621
+ the same click, named for what it is: their authority covers the
622
+ missing approvals. Anyone else gets the waiting line above. */}
623
+ {!blocked && canApply && (
624
+ <Button
625
+ variant="primary"
626
+ size="sm"
627
+ disabled={applyBusy}
628
+ onClick={() => applying.apply(cr)}
629
+ >
630
+ {applyBusy ? applyLabel : allApproved ? 'Apply changes' : 'Bypass approval and apply'}
631
+ </Button>
632
+ )}
633
+ </div>
634
+ </Surface>
635
+ </div>
636
+ );
637
+ }
638
+
639
+ /**
640
+ * The author's reason, or nothing.
641
+ *
642
+ * A change request's body is part human and part machine: the backend appends
643
+ * an `## Affected owners` block (and hidden identity markers) to whatever the
644
+ * author wrote, and our propose flow writes no description at all — so the body
645
+ * is USUALLY pure machinery. Rendering it as a pull-quote under the title
646
+ * presents a routing table as the reason someone wants this change. Everything
647
+ * from the first generated heading on is dropped; what survives is quoted only
648
+ * if a human actually wrote it.
649
+ */
650
+ function authorsReason(body: string | undefined): string | null {
651
+ if (!body) return null;
652
+ const human = body
653
+ .split(/^##\s+/m)[0]
654
+ .replace(/<!--[\s\S]*?-->/g, '')
655
+ .trim();
656
+ return human.length > 0 ? human : null;
657
+ }
658
+
659
+ /**
660
+ * The file with the change marked in it — one document, not two panes. Removed
661
+ * passages stay in place struck through, added ones sit where they will land,
662
+ * so what you read is the file as it would become.
663
+ *
664
+ * Markdown never reaches this view when both sides are in — it renders
665
+ * through `MarkdownDiffViewer` above. This is the presentation for the files
666
+ * that ARE source (yaml, scripts, config), plus the loading and unreadable
667
+ * states for everything.
668
+ */
669
+ function MarkedFile({
670
+ diff,
671
+ raw,
672
+ unreadable,
673
+ }: {
674
+ diff: DiffLine[] | null;
675
+ raw: string | null;
676
+ unreadable?: boolean;
677
+ }) {
678
+ if (unreadable) {
679
+ return (
680
+ <p className="py-6 text-center text-detail text-ink-faint">
681
+ This file's copy on the change request couldn't be read, so there is no honest before and
682
+ after to show.
683
+ </p>
684
+ );
685
+ }
686
+ if (raw !== null) {
687
+ return (
688
+ <pre className="whitespace-pre-wrap break-words font-mono text-detail leading-relaxed text-ink-muted">
689
+ {raw}
690
+ </pre>
691
+ );
692
+ }
693
+ if (diff === null) {
694
+ return <p className="py-6 text-center text-detail text-ink-faint">Loading…</p>;
695
+ }
696
+ return (
697
+ <pre className="lib-sug whitespace-pre-wrap break-words font-mono text-detail leading-relaxed text-ink-muted">
698
+ {diff.map((l, i) =>
699
+ l.kind === 'removed' ? (
700
+ <del key={i} className="block">
701
+ {l.text || ' '}
702
+ </del>
703
+ ) : l.kind === 'added' ? (
704
+ <ins key={i} className="block">
705
+ {l.text || ' '}
706
+ </ins>
707
+ ) : (
708
+ <div key={i}>{l.text || ' '}</div>
709
+ ),
710
+ )}
711
+ </pre>
712
+ );
713
+ }