@bevel-software/platform-core-frontend 0.4.1 → 0.5.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 (326) hide show
  1. package/package.json +5 -3
  2. package/src/core/CoreAppShell.tsx +195 -56
  3. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  5. package/src/core/__tests__/bootstrap.test.ts +63 -0
  6. package/src/core/bootstrap.ts +73 -0
  7. package/src/core/events.ts +12 -0
  8. package/src/core/registry.ts +58 -9
  9. package/src/index.css +100 -11
  10. package/src/index.ts +24 -23
  11. package/src/lib/utils.ts +93 -117
  12. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  14. package/src/modules/access/api.ts +49 -0
  15. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  16. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  17. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  18. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  19. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  22. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  23. package/src/modules/admin/state/admin.context.tsx +15 -6
  24. package/src/modules/auth/components/AccountPage.tsx +11 -11
  25. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  26. package/src/modules/auth/services/sso.ts +47 -1
  27. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  28. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  29. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  30. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  31. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  32. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  33. package/src/modules/change-requests/change-requests.css +22 -0
  34. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  35. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  36. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  37. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  38. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  39. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  40. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  41. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  42. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  43. package/src/modules/change-requests/services/propose.api.ts +162 -0
  44. package/src/modules/change-requests/utils/author.ts +47 -0
  45. package/src/modules/change-requests/utils/conflict.ts +38 -0
  46. package/src/modules/change-requests/utils/diff.ts +80 -0
  47. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  48. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  49. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  50. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  51. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  52. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  53. package/src/modules/git/components/DiffView.tsx +4 -4
  54. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  55. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  56. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  57. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  58. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  59. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  60. package/src/modules/git/hooks/useGitState.ts +15 -14
  61. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  62. package/src/modules/git/services/error-messages.ts +7 -7
  63. package/src/modules/git/services/git.api.ts +17 -11
  64. package/src/modules/git/services/pr-prompts.ts +2 -2
  65. package/src/modules/git/state/git.context.ts +10 -1
  66. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  67. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  68. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  69. package/src/modules/layout/breakpoints.ts +6 -0
  70. package/src/modules/layout/components/AppLayout.tsx +17 -5
  71. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  72. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  73. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  74. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  75. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  76. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  77. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  78. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  79. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  80. package/src/modules/layout/state/sidebar.ts +200 -0
  81. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  82. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  83. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  84. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  85. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  86. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  89. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  90. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  91. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  92. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  93. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  94. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  95. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  96. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  97. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  98. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  99. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  100. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  101. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  102. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  103. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  104. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  105. package/src/modules/library/__tests__/status.test.ts +113 -20
  106. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  107. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  108. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  109. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  110. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  111. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  112. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  113. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  114. package/src/modules/library/components/GroupPage.tsx +373 -0
  115. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  116. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  117. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  118. package/src/modules/library/components/LibraryCard.tsx +123 -102
  119. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  120. package/src/modules/library/components/LibraryPage.tsx +111 -227
  121. package/src/modules/library/components/LockGlyph.tsx +31 -0
  122. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  123. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  124. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  125. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  126. package/src/modules/library/components/PageActions.tsx +156 -0
  127. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  128. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  129. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  130. package/src/modules/library/components/StatusDot.tsx +25 -0
  131. package/src/modules/library/components/ToolLogo.tsx +171 -0
  132. package/src/modules/library/components/group-page-parts.tsx +419 -0
  133. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  134. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  135. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  136. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  137. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  138. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  139. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  140. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  141. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  142. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  143. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  144. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  145. package/src/modules/library/hooks/useToolPage.ts +145 -0
  146. package/src/modules/library/library.css +33 -245
  147. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  148. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  149. package/src/modules/library/routes/library-paths.ts +191 -0
  150. package/src/modules/library/services/groups.api.ts +189 -0
  151. package/src/modules/library/services/library.api.ts +291 -164
  152. package/src/modules/library/services/tools.api.ts +60 -0
  153. package/src/modules/library/state/library-context.ts +22 -0
  154. package/src/modules/library/state/library-data.tsx +223 -0
  155. package/src/modules/library/state/toast.context.ts +32 -0
  156. package/src/modules/library/state/toast.tsx +84 -42
  157. package/src/modules/library/utils/clipboard.ts +33 -0
  158. package/src/modules/library/utils/group-summary.ts +68 -0
  159. package/src/modules/library/utils/names.ts +30 -0
  160. package/src/modules/library/utils/navigate-external.ts +15 -0
  161. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  162. package/src/modules/library/utils/personal-group.ts +36 -0
  163. package/src/modules/library/utils/status.ts +108 -25
  164. package/src/modules/library/utils/toast-duration.ts +16 -0
  165. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  166. package/src/modules/onboarding/agent-clients.ts +48 -0
  167. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  168. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  169. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  170. package/src/modules/onboarding/paths.ts +9 -0
  171. package/src/modules/onboarding/state/onboarding.ts +191 -0
  172. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  173. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  174. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  175. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  176. package/src/modules/review/components/DiffViewer.tsx +4 -4
  177. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  178. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  179. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  180. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  181. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  182. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  183. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  184. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  185. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  186. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  187. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  188. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  189. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  190. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  191. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  192. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  193. package/src/modules/settings/settings-nav-items.tsx +166 -0
  194. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  195. package/src/modules/setup/components/SetupGate.tsx +67 -0
  196. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  197. package/src/modules/setup/services/setup.api.ts +106 -0
  198. package/src/modules/setup/utils/git-host.ts +34 -0
  199. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  200. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  201. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  202. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  203. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  204. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  205. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  206. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  207. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  208. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  209. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  210. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  211. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  212. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  213. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  214. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  215. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  216. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  217. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  218. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  219. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  220. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  221. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  222. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  223. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  224. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  225. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  226. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  227. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  228. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  229. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  230. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  231. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  232. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  233. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  234. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  235. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  236. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  237. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  238. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  240. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  241. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  242. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  243. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  244. package/src/modules/workspace/components/renderers/index.ts +78 -2
  245. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  246. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  247. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  248. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  249. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  250. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  251. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  252. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  253. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  254. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  255. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  256. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  257. package/src/modules/workspace/services/workspace.api.ts +9 -2
  258. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  259. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  260. package/src/modules/workspace/state/workspace.context.ts +9 -0
  261. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  262. package/src/modules/workspace/utils/diff.ts +130 -53
  263. package/src/modules/workspace/utils/fileTree.ts +7 -4
  264. package/src/modules/workspace/workspace.css +28 -0
  265. package/src/shared/components/Badge.tsx +62 -0
  266. package/src/shared/components/Banner.tsx +58 -0
  267. package/src/shared/components/Button.tsx +90 -0
  268. package/src/shared/components/Dialog.tsx +6 -6
  269. package/src/shared/components/Field.tsx +45 -0
  270. package/src/shared/components/IconButton.tsx +74 -0
  271. package/src/shared/components/ListRow.tsx +96 -0
  272. package/src/shared/components/Menu.tsx +88 -0
  273. package/src/shared/components/PageShell.tsx +8 -5
  274. package/src/shared/components/Surface.tsx +86 -0
  275. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  276. package/src/shared/components/index.ts +48 -0
  277. package/src/shared/components/useDismissableMenu.ts +71 -0
  278. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  279. package/src/shared/theme/index.css +12 -0
  280. package/src/shared/theme/measure.ts +64 -0
  281. package/src/shared/theme/shadows.css +34 -0
  282. package/src/shared/theme/tokens.css +193 -0
  283. package/src/test-setup.ts +9 -0
  284. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  285. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  286. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  287. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  288. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  289. package/src/modules/library/__tests__/diff.test.ts +0 -62
  290. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  291. package/src/modules/library/components/CompareView.tsx +0 -357
  292. package/src/modules/library/components/DetailDialog.tsx +0 -566
  293. package/src/modules/library/components/GearIcon.tsx +0 -12
  294. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  295. package/src/modules/library/components/StatusGem.tsx +0 -21
  296. package/src/modules/library/components/SuggestChange.tsx +0 -171
  297. package/src/modules/library/components/particles.ts +0 -50
  298. package/src/modules/library/state/loadout.tsx +0 -129
  299. package/src/modules/library/utils/diff.ts +0 -102
  300. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  301. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  302. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  303. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  304. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  305. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  306. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  307. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  308. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  309. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  310. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  311. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  312. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  313. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  314. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  315. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  316. package/src/modules/pr/components/PrHeader.tsx +0 -45
  317. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  318. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  319. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  320. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  321. package/src/modules/pr/components/PrViewer.tsx +0 -364
  322. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  323. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  324. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  325. package/src/modules/pr/utils/parsePatch.ts +0 -57
  326. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -0,0 +1,673 @@
1
+ import { useCallback, useEffect, useId, useMemo, useState, type ReactNode } from 'react';
2
+ import { useLocation, useNavigate, useParams } from 'react-router-dom';
3
+ import {
4
+ DEFAULT_BRANCH,
5
+ groupOfPath,
6
+ type PullRequestSummary,
7
+ } from '@bevel-software/platform-shared';
8
+ import '../../library.css';
9
+ import { Badge, Button } from '../../../../shared/components';
10
+ import { useAuth } from '../../../auth/state/auth.context';
11
+ import { useWorkspace } from '../../../workspace/state/workspace.context';
12
+ import { kbFileUrl, resolveRelativePath, useNodeIdNav } from '../../../workspace/routing/kb-routes';
13
+ import { cancelPullRequest } from '../../../pr/services/pr-cancel.api';
14
+ import { useFileAccess } from '../../../access/hooks/useFileAccess';
15
+ import { proposeChange, suggestionBranchFor } from '../../services/library.api';
16
+ import { getOrCreateWorkspace, writeFile } from '../../../workspace/services/workspace.api';
17
+ import { useSkillDetail } from '../../hooks/useSkillDetail';
18
+ import { useApplyChangeRequest } from '../../../change-requests/hooks/useApplyChangeRequest';
19
+ import { useCrFileDiffs } from '../../../change-requests/hooks/useCrFileDiffs';
20
+ import { useDefaultBranchFile, useFileOnBranch } from '../../../change-requests/hooks/useFileOnBranch';
21
+ import { useLibrary } from '../../state/library-data';
22
+ import { useLibraryToast } from '../../state/toast.context';
23
+ import { libraryHomeForItemPath, urlForSkillFile } from '../../routes/library-paths';
24
+ import { changeAuthorName, formatWhen } from '../../../change-requests/utils/author';
25
+ import { ownersTextOf } from '../../utils/group-summary';
26
+ import { neededToolsFor, toolStatus } from '../../utils/status';
27
+ import { StatusDot } from '../StatusDot';
28
+ import { ChangeRequestDock } from '../ChangeRequestDock';
29
+ import { ChangeRequestDialog } from '../../../change-requests/components/ChangeRequestDialog';
30
+ import { SkillFileTabs } from './SkillFileTabs';
31
+ import { skillPanelId, skillTabId } from './tab-ids';
32
+ import { SkillFilePane } from './SkillFilePane';
33
+ import { SkillFileEditor } from './SkillFileEditor';
34
+ import { ChangeBox } from '../../../change-requests/components/ChangeBox';
35
+ import { conflictResolutionPrompt } from '../../../change-requests/utils/conflict';
36
+ import { isBinaryFile } from '../../../workspace/components/renderers';
37
+
38
+ /**
39
+ * One skill, as a page — the prototype's skill item (line 1964), which says of
40
+ * itself: "the heading, its files, and the open file. Nothing else."
41
+ *
42
+ * It replaces the detail DIALOG for skills, and the reason it is a route is the
43
+ * same reason the tool page is one: a skill is a thing you link to. A dialog has
44
+ * no URL, so "look at the newsletter skill" could only ever be "open the
45
+ * library, find the card, click it" — and the change-request flow that lands on
46
+ * top of this page needs somewhere for a review link to point.
47
+ *
48
+ * One thing the prototype's page does NOT have is kept here, because dropping
49
+ * it would remove function rather than chrome: the integrations the skill
50
+ * needs (the only place a skill states what has to be connected before it
51
+ * will run). The description is NOT repeated above the content anymore — the
52
+ * file pane renders the RAW file, so the frontmatter panel already carries
53
+ * `description` (and everything else the YAML says), exactly as the Knowledge
54
+ * view would render the same file.
55
+ */
56
+ export function SkillPage({
57
+ name: nameProp,
58
+ activeFile,
59
+ }: {
60
+ /**
61
+ * Both provided when the page is mounted at its CANONICAL address — the
62
+ * skill file's own /workspace URL (see `WorkspaceItemGate`): `name` names
63
+ * the skill, `activeFile` the tab, and switching tabs NAVIGATES (each file
64
+ * has its own URL). Absent on the legacy `/skills-and-tools/skills/:name`
65
+ * mount, where the name comes from the route and tabs are local state.
66
+ */
67
+ name?: string;
68
+ activeFile?: string;
69
+ } = {}) {
70
+ const { name: rawName = '' } = useParams<{ name: string }>();
71
+ const name = nameProp ?? safeDecode(rawName);
72
+ const navigate = useNavigate();
73
+ const toast = useLibraryToast();
74
+ const { kbDirName } = useWorkspace();
75
+ const { user } = useAuth();
76
+ const data = useLibrary();
77
+ const detail = useSkillDetail(name);
78
+ // The same id-link resolver the Knowledge renderer uses — a `[text](node-id)`
79
+ // link inside a skill file navigates to that node, not to a dead span.
80
+ const { openNodeId } = useNodeIdNav();
81
+
82
+ const [selectedState, setSelected] = useState('SKILL.md');
83
+ const selected = activeFile ?? selectedState;
84
+ const [compareCr, setCompareCr] = useState<PullRequestSummary | null>(null);
85
+ /** Ties the tabs to the panel they control; unique per mounted page. */
86
+ const tabsId = useId();
87
+
88
+ // Ownership is a property of the CATALOG entry, not of the skill document —
89
+ // it comes from the per-file ACL the provider already resolved, so the page
90
+ // reads it rather than asking again.
91
+ const owned = useMemo(
92
+ () => data.items.some((i) => i.kind === 'skill' && i.id === name && i.owned),
93
+ [data.items, name],
94
+ );
95
+
96
+ const skill = detail.skill;
97
+ const skillPath = skill?.path ?? '';
98
+ const prefix = `${skillPath}/`;
99
+
100
+ /**
101
+ * Who has to say yes. A skill has no owner of its own — it inherits its group
102
+ * folder's `access.md` — so the people who review a change to it are the
103
+ * group's owners. Naming the wrong reviewer is worse than naming none, hence
104
+ * the neutral fallback when the group index hasn't resolved.
105
+ */
106
+ const ownerName = useMemo(() => {
107
+ const group = skill ? groupOfPath(skill.path) : null;
108
+ const summary = group ? data.groupSummaries.find((g) => g.name === group) : undefined;
109
+ return summary ? ownersTextOf(summary) : 'the owner';
110
+ }, [skill, data.groupSummaries]);
111
+
112
+ const files = useMemo(
113
+ () => ['SKILL.md', ...(skill?.files ?? []).map((f) => f.slice(prefix.length))],
114
+ [skill, prefix],
115
+ );
116
+
117
+ /**
118
+ * The file actually on screen. DERIVED rather than corrected in an effect: a
119
+ * selection that no longer exists (a stale tab after a merge renamed the file,
120
+ * or a skill switched underneath the page) resolves straight back to SKILL.md
121
+ * on the same render, so the pane never paints a frame pointing at nothing.
122
+ */
123
+ const active = files.includes(selected) ? selected : 'SKILL.md';
124
+
125
+ useEffect(() => {
126
+ if (active !== 'SKILL.md') detail.loadFile(active);
127
+ // `detail.loadFile` is keyed by (name, contents) and self-dedupes; widening
128
+ // these deps re-runs it on every content arrival for no gain.
129
+ // eslint-disable-next-line react-hooks/exhaustive-deps
130
+ }, [active, skill]);
131
+
132
+ const needed = useMemo(
133
+ () => (skill ? neededToolsFor(skill, data.tools) : []),
134
+ [skill, data.tools],
135
+ );
136
+
137
+ /** Open change requests touching anything inside this skill's folder. */
138
+ const skillCrs = useMemo(
139
+ () => (skillPath ? data.crs.filter((c) => touchesSkill(c, skillPath)) : []),
140
+ [data.crs, skillPath],
141
+ );
142
+ /**
143
+ * The caller's own open change request for this skill, resolved by BRANCH.
144
+ *
145
+ * Not by touched paths: `touchedNodePaths` is documented "Empty if not yet
146
+ * computed", and while it is empty every path-derived check collapses at
147
+ * once — the request stops looking like it touches this skill, so `ownCr`
148
+ * goes null, the editor offers itself again, and `proposeChange` takes its
149
+ * no-existing-request path and opens a SECOND change request against the
150
+ * branch that already has one.
151
+ *
152
+ * The branch is deterministic (`suggestionBranchFor`) and exists from the
153
+ * moment the request does, so it answers "is this mine?" in the window where
154
+ * paths cannot. The path-based lookup stays as a fallback — it can only add
155
+ * matches, never remove them — so a request opened on some other branch (by
156
+ * an agent, say) is still recognised as the caller's.
157
+ */
158
+ const myBranch = user ? suggestionBranchFor(user.email, name) : null;
159
+ const ownCr = useMemo(
160
+ () =>
161
+ data.crs.find((c) => data.myCrNumbers.has(c.number) && c.branch === myBranch) ??
162
+ skillCrs.find((c) => data.myCrNumbers.has(c.number)) ??
163
+ null,
164
+ [data.crs, data.myCrNumbers, myBranch, skillCrs],
165
+ );
166
+
167
+ /** Which tabs get a dot: the files an open change request actually touches. */
168
+ const pendingFiles = useMemo(() => {
169
+ const set = new Set<string>();
170
+ for (const cr of skillCrs) {
171
+ for (const p of cr.touchedNodePaths) {
172
+ if (p.startsWith(prefix)) set.add(p.slice(prefix.length));
173
+ }
174
+ }
175
+ return set;
176
+ }, [skillCrs, prefix]);
177
+
178
+ const fileRepoPath = `${skillPath}/${active}`;
179
+
180
+ /**
181
+ * May the caller WRITE this file — the real per-file ACL answer, resolved
182
+ * against the default branch (where skills live), not a guess from the
183
+ * catalog's `owned` flag. This is what decides which button the file bar
184
+ * carries: `Edit` for a hard-or-optimistic yes (null = lookup in flight,
185
+ * same rule as the Knowledge viewer), `Propose changes` for a hard no.
186
+ */
187
+ const fileAccess = useFileAccess(
188
+ kbDirName && skillPath ? `${kbDirName}/${fileRepoPath}` : null,
189
+ DEFAULT_BRANCH,
190
+ );
191
+
192
+ /** Bumped after every write so the branch reads re-run against fresh content. */
193
+ const [revision, setRevision] = useState(0);
194
+ /**
195
+ * Creation hands off straight into the editor: `NewSkillPanel` navigates
196
+ * here with `startEditing` in the router state, so the person who just made
197
+ * an empty skill lands with the cursor in it instead of on an empty page.
198
+ */
199
+ const location = useLocation();
200
+ const [editing, setEditing] = useState(
201
+ Boolean((location.state as { startEditing?: boolean } | null)?.startEditing),
202
+ );
203
+ const [busyCr, setBusyCr] = useState<number | null>(null);
204
+ /**
205
+ * Change requests a merge attempt has REFUSED as unmergeable. Git is the only
206
+ * thing that can answer "does this still apply?", and it answers when asked
207
+ * to merge — so this fills in from failures rather than from a guess made up
208
+ * front. Only CONFLICTS land here; a gate refusal ("waiting on approval
209
+ * from …") is a state that can change under the reader, so it is reported
210
+ * without withdrawing the button.
211
+ */
212
+ const [blockedCrs, setBlockedCrs] = useState<Set<number>>(new Set());
213
+
214
+ /**
215
+ * Approve = record the approvals, then merge, then wait for the merge to
216
+ * actually happen. All three matter and none of them are the POST returning:
217
+ * see `useApplyChangeRequest`.
218
+ */
219
+ const applying = useApplyChangeRequest({
220
+ onApplied() {
221
+ toast('Approved: the skill now reads with that change.');
222
+ setRevision((r) => r + 1);
223
+ data.reload();
224
+ // The pane renders `skill.body`, which this hook holds and the merge just
225
+ // changed. Without re-reading it the page keeps showing the pre-merge
226
+ // text under a message saying the skill now reads with the change.
227
+ detail.reload();
228
+ },
229
+ onFailed(number, refusal) {
230
+ // A conflict is the one refusal that makes Approve pointless to retry, so
231
+ // it withdraws the button — in the SAME commit as the refusal, which is
232
+ // why this is not derived from `refusals` in an effect: a commit's delay
233
+ // leaves the failed button live and clickable.
234
+ if (refusal.conflicts) {
235
+ setBlockedCrs((s) => (s.has(number) ? s : new Set(s).add(number)));
236
+ toast('Blocked: the file changed after this was written.', 'danger');
237
+ }
238
+ },
239
+ });
240
+
241
+ /**
242
+ * The file's raw bytes on the default branch. `raw` above is what gets
243
+ * RENDERED (SKILL.md arrives from the skills API with its frontmatter already
244
+ * parsed off); this is what gets diffed and edited. Mixing the two marks the
245
+ * frontmatter as a deletion and, on submit, would commit it away.
246
+ */
247
+ const rawOnMain = useDefaultBranchFile(skillPath ? fileRepoPath : null, revision);
248
+
249
+ /**
250
+ * What the reading pane renders: the file's RAW bytes for every tab —
251
+ * including SKILL.md, whose `skill.body` copy has had the frontmatter parsed
252
+ * off by the skills API. The raw bytes are what make this pane render
253
+ * IDENTICALLY to the Knowledge view of the same file: `KbMarkdownView`
254
+ * parses the frontmatter itself and shows it as the panel above the body,
255
+ * which is where the skill's description now lives (rather than being
256
+ * repeated in the page header).
257
+ */
258
+ const raw = active === 'SKILL.md' ? rawOnMain : detail.fileContent(active);
259
+
260
+ /** Every open change request's version of the file on screen. */
261
+ const crDiffs = useCrFileDiffs(skillCrs, fileRepoPath, rawOnMain, revision);
262
+
263
+ /** The change requests with something to say about THIS file. */
264
+ const boxes = useMemo(
265
+ () => skillCrs.filter((c) => c.touchedNodePaths.includes(fileRepoPath)),
266
+ [skillCrs, fileRepoPath],
267
+ );
268
+
269
+ /**
270
+ * The editor's BASE — the text the proposal is typed over and diffed
271
+ * against. With no open request of your own it is the default branch's
272
+ * file; with one, it is the file as it reads on YOUR suggestions branch,
273
+ * fetched only once the editor opens. That branch read is what makes a
274
+ * second round of edits INCREMENTAL: it stacks on what you already
275
+ * proposed instead of silently starting over from the published text and
276
+ * overwriting your own pending change.
277
+ *
278
+ * Resolved through `ownCr` (recognised by BRANCH — see above) so the
279
+ * submit path reuses the existing request; a proposal on top of a request
280
+ * the page failed to recognise would open a second one against the same
281
+ * branch.
282
+ */
283
+ const canEditDirectly = fileAccess.canWrite === true;
284
+ const ownBranchBase = useFileOnBranch(
285
+ editing && !canEditDirectly && ownCr ? ownCr.branch : null,
286
+ skillPath ? fileRepoPath : null,
287
+ revision,
288
+ );
289
+ // A direct edit always bases on the default branch — the file as everyone
290
+ // reads it. Only the propose flow stacks on the caller's own branch copy.
291
+ const editorBase = !canEditDirectly && ownCr ? ownBranchBase : rawOnMain;
292
+
293
+ const openInEditor = useCallback(
294
+ (wsRelative: string) => navigate(kbFileUrl(DEFAULT_BRANCH, wsRelative)),
295
+ [navigate],
296
+ );
297
+
298
+ /**
299
+ * A heading's citation deep-link — the file's KNOWLEDGE URL plus `#slug`,
300
+ * because that is the surface that scrolls to a heading fragment. Same
301
+ * affordance, same destination as copying the link from the Knowledge view
302
+ * of this file; the two views must not hand out different URLs for the same
303
+ * heading.
304
+ */
305
+ const headingLink = useCallback(
306
+ (slug: string) =>
307
+ kbDirName && skillPath
308
+ ? `${window.location.origin}${kbFileUrl(DEFAULT_BRANCH, `${kbDirName}/${skillPath}/${active}`)}#${slug}`
309
+ : `${window.location.origin}${window.location.pathname}#${slug}`,
310
+ [kbDirName, skillPath, active],
311
+ );
312
+
313
+ /**
314
+ * The writer's submit: straight onto the default branch. One `writeFile` is
315
+ * a complete save — the route acquires the file lock (where the ACL gate
316
+ * runs), writes, and releases into the commit queue — so this is the same
317
+ * save the Knowledge editor performs, minus the app switch.
318
+ */
319
+ async function saveDirect(content: string) {
320
+ const { workspace } = await getOrCreateWorkspace(DEFAULT_BRANCH);
321
+ await writeFile(workspace.id, `${workspace.kbDirName}/${fileRepoPath}`, content);
322
+ setEditing(false);
323
+ setRevision((r) => r + 1);
324
+ toast('Saved: the skill now reads with your change.');
325
+ data.reload();
326
+ }
327
+
328
+ async function submitProposal(content: string) {
329
+ if (!user) throw new Error('Sign in to propose a change.');
330
+ await proposeChange({
331
+ skillName: name,
332
+ repoRelativePath: fileRepoPath,
333
+ content,
334
+ userEmail: user.email,
335
+ userName: user.name,
336
+ existingCr: ownCr,
337
+ });
338
+ setEditing(false);
339
+ setRevision((r) => r + 1);
340
+ toast(`Sent to ${ownerName}: nothing changes until they approve it.`);
341
+ data.reload();
342
+ }
343
+
344
+ async function decline(cr: PullRequestSummary) {
345
+ setBusyCr(cr.number);
346
+ try {
347
+ await cancelPullRequest(cr.number);
348
+ toast('Declined. Nothing was changed.');
349
+ data.reload();
350
+ } catch (err) {
351
+ toast(err instanceof Error ? err.message : "Couldn't decline this change.", 'danger');
352
+ } finally {
353
+ setBusyCr(null);
354
+ }
355
+ }
356
+
357
+ async function withdraw(cr: PullRequestSummary) {
358
+ setBusyCr(cr.number);
359
+ try {
360
+ await cancelPullRequest(cr.number);
361
+ toast('Withdrawn.');
362
+ data.reload();
363
+ } catch (err) {
364
+ toast(err instanceof Error ? err.message : "Couldn't withdraw this change.", 'danger');
365
+ } finally {
366
+ setBusyCr(null);
367
+ }
368
+ }
369
+
370
+ // The page the skill lives on, not the Library root: "back" from a skill
371
+ // you opened off its group page must land on that group page. Derived from
372
+ // the path, so a deep link gets the same honest destination as a click.
373
+ const home = libraryHomeForItemPath(skillPath);
374
+ const backLink = (
375
+ <Button variant="quiet" size="sm" onClick={() => navigate(home.path)}>
376
+ {`‹ ${home.label}`}
377
+ </Button>
378
+ );
379
+
380
+ if (!detail.loading && (detail.error || !skill)) {
381
+ return (
382
+ <Article>
383
+ {backLink}
384
+ <p className="mt-4 text-label font-semibold uppercase text-ink-faint">Skill</p>
385
+ <p className="mt-2 text-body text-ink-muted">
386
+ This skill doesn't exist, or you don't have access to it.
387
+ </p>
388
+ </Article>
389
+ );
390
+ }
391
+
392
+
393
+ // The change-request dialog is a full-screen surface, not a layer over this
394
+ // page — rendering both would leave the page's dock and tabs live
395
+ // underneath it. It is the SHARED dialog, scoped to this skill: its folder
396
+ // frames the file list, and the skill's own files always show so an owner
397
+ // can read the untouched parts too.
398
+ if (compareCr && skill) {
399
+ return (
400
+ <ChangeRequestDialog
401
+ cr={compareCr}
402
+ scope={{ prefix: skill.path, baseFiles: files }}
403
+ onClose={() => setCompareCr(null)}
404
+ onResolved={() => {
405
+ toast('Change request is being applied');
406
+ setCompareCr(null);
407
+ data.reload();
408
+ }}
409
+ />
410
+ );
411
+ }
412
+
413
+ // Loading deliberately falls through to this real page tree. The route
414
+ // already knows the skill name, `files` already contains SKILL.md, and
415
+ // keeping these exact nodes mounted prevents a blank handoff followed by a
416
+ // second layout when the detail request settles.
417
+ return (
418
+ <Article>
419
+ {backLink}
420
+
421
+ <header className="mt-4">
422
+ <div className="flex items-center gap-3">
423
+ <h1 className="text-display font-semibold text-ink">{skill?.name ?? name}</h1>
424
+ {skill && owned && (
425
+ <Badge tone="outline" size="xs" className="shrink-0 uppercase">
426
+ Owner
427
+ </Badge>
428
+ )}
429
+ </div>
430
+ {/* No description line here — the file pane renders the raw SKILL.md,
431
+ and its frontmatter panel already says what the skill is for.
432
+ Repeating it above the pane said the same sentence twice on the
433
+ first screenful. */}
434
+ {/* No `Manage access` here, deliberately — a skill inherits its group
435
+ folder's `access.md`, and the group's Share panel is the one place
436
+ those rules are decided. Same call the tool page made. */}
437
+ </header>
438
+
439
+ <IntegrationsSection needed={needed} onConnect={() => navigate('/connect')} />
440
+
441
+ <SkillFileTabs
442
+ files={files}
443
+ selected={active}
444
+ pending={pendingFiles}
445
+ baseId={tabsId}
446
+ onSelect={(f) => {
447
+ // At the canonical mount every file has its own URL — a tab switch
448
+ // is a navigation, so the address bar always names what is on
449
+ // screen and any tab can be deep-linked or shared.
450
+ if (activeFile !== undefined && skill && kbDirName) {
451
+ navigate(urlForSkillFile(kbDirName, skill.path, f));
452
+ } else {
453
+ setSelected(f);
454
+ }
455
+ setEditing(false);
456
+ }}
457
+ />
458
+
459
+ {/* The panel the tabs control. It wraps BOTH the reading pane and the
460
+ editor that replaces it, so `aria-controls` resolves in either state
461
+ rather than pointing at an element that exists only half the time. */}
462
+ <div
463
+ role="tabpanel"
464
+ id={skillPanelId(tabsId)}
465
+ aria-labelledby={skillTabId(tabsId, active)}
466
+ aria-busy={detail.loading || raw === null || undefined}
467
+ >
468
+ {detail.loading ? (
469
+ <SkillFilePane
470
+ file={active}
471
+ raw={null}
472
+ suggestion={null}
473
+ headingLink={headingLink}
474
+ />
475
+ ) : editing && editorBase !== null && fileAccess.canWrite !== null ? (
476
+ <SkillFileEditor
477
+ file={active}
478
+ base={editorBase}
479
+ mode={canEditDirectly ? 'edit' : 'propose'}
480
+ owner={ownerName}
481
+ onCancel={() => setEditing(false)}
482
+ onSubmit={canEditDirectly ? saveDirect : submitProposal}
483
+ />
484
+ ) : (
485
+ <SkillFilePane
486
+ file={active}
487
+ raw={raw}
488
+ suggestion={null}
489
+ onOpenLink={(href) => {
490
+ if (!kbDirName) return;
491
+ openInEditor(resolveRelativePath(`${kbDirName}/${skillPath}/${active}`, href));
492
+ }}
493
+ onOpenNodeId={openNodeId}
494
+ headingLink={headingLink}
495
+ /*
496
+ * ONE action, decided by the ACL. An `Edit` used to sit beside
497
+ * `Propose changes` for EVERYONE and jump to the Knowledge editor —
498
+ * where, for anyone without a write grant, it ended in AccessDenied
499
+ * after they had navigated away and typed the change. The trap was
500
+ * never the button; it was offering it to people it would refuse.
501
+ * So the file bar asks the per-file access resolver and shows
502
+ * exactly one of the two — and BOTH now open the same editor in
503
+ * place, right over the rendered file. What differs is what
504
+ * submitting does: a writer's Save lands on the default branch, a
505
+ * proposal lands on the author's suggestion branch as a change
506
+ * request. Edit used to leave for the Knowledge app; being bounced
507
+ * to a different surface to change the file you are reading was
508
+ * the last piece of that old trap.
509
+ *
510
+ * One open proposal per person per SKILL, still — but proposing
511
+ * again while yours is open is not refused anymore: it opens the
512
+ * editor over the file AS YOU PROPOSED IT (see `editorBase`), and
513
+ * submitting updates the same change request. Incremental, never a
514
+ * fork, never a silent restart from the published text.
515
+ */
516
+ actions={
517
+ // Only a RESOLVED verdict earns a button: `null` (lookup in
518
+ // flight) briefly shows no action rather than an Edit that might
519
+ // open the wrong mode — a writer's text must never ride the
520
+ // proposal path just because they clicked before the ACL answered.
521
+ fileAccess.canWrite === true
522
+ ? rawOnMain !== null && (
523
+ <Button
524
+ variant="outline"
525
+ size="tiny"
526
+ onClick={() => setEditing(true)}
527
+ title="Edit this file in place"
528
+ >
529
+ Edit
530
+ </Button>
531
+ )
532
+ : fileAccess.canWrite === false && rawOnMain !== null && (
533
+ <Button
534
+ variant="outline"
535
+ size="tiny"
536
+ onClick={() => setEditing(true)}
537
+ title={
538
+ ownCr
539
+ ? 'Continue your open proposal. Edits update the same change request'
540
+ : "You can't edit this file directly. Propose a change for its owners to approve"
541
+ }
542
+ >
543
+ Propose changes
544
+ </Button>
545
+ )
546
+ }
547
+ />
548
+ )}
549
+
550
+ {/* Every open proposal on this file, under the file it is about. The
551
+ owner decides here; the author can take theirs back. */}
552
+ {!editing &&
553
+ boxes.map((cr) => {
554
+ const mine = data.myCrNumbers.has(cr.number);
555
+ // `[]` is the hook's "overtaken" answer — the proposal and the file
556
+ // now say the same thing — and is distinct from `null`, which only
557
+ // means a side has not arrived yet.
558
+ const fileDiff = crDiffs.get(cr.number) ?? null;
559
+ return (
560
+ <ChangeBox
561
+ key={cr.number}
562
+ file={active}
563
+ author={changeAuthorName(cr)}
564
+ when={formatWhen(cr.createdAt)}
565
+ mine={mine}
566
+ canDecide={owned && !mine}
567
+ diff={fileDiff}
568
+ binary={isBinaryFile(active)}
569
+ upToDate={fileDiff !== null && fileDiff.length === 0}
570
+ blocked={blockedCrs.has(cr.number)}
571
+ conflictPrompt={conflictResolutionPrompt(cr)}
572
+ // A conflict already speaks through `blocked`; repeating it as a
573
+ // refusal line would say the same thing twice in one box.
574
+ refusal={
575
+ applying.refusals.get(cr.number)?.conflicts === false
576
+ ? (applying.refusals.get(cr.number)?.reason ?? null)
577
+ : null
578
+ }
579
+ owner={ownerName}
580
+ busy={busyCr === cr.number || applying.activeCr === cr.number}
581
+ phase={applying.activeCr === cr.number ? applying.phase : 'idle'}
582
+ onApprove={() => applying.apply(cr)}
583
+ onDecline={() => void decline(cr)}
584
+ onWithdraw={() => void withdraw(cr)}
585
+ onOpenFull={owned ? () => setCompareCr(cr) : undefined}
586
+ />
587
+ );
588
+ })}
589
+ </div>
590
+
591
+ {/* Outside the panel: the dock lists change requests touching ANY file of
592
+ the skill, so it is not about the selected tab. The boxes above only
593
+ cover the file on screen, and without this a proposal to a file you
594
+ are not looking at has no way to reach you. */}
595
+ {skill && owned && <ChangeRequestDock crs={skillCrs} onSelect={setCompareCr} />}
596
+ </Article>
597
+ );
598
+ }
599
+
600
+ /** Does this change request touch anything inside the skill folder? */
601
+ function touchesSkill(cr: PullRequestSummary, skillPath: string): boolean {
602
+ return cr.touchedNodePaths.some((p) => p === skillPath || p.startsWith(`${skillPath}/`));
603
+ }
604
+
605
+ /**
606
+ * The reading column. Horizontal and vertical padding come from the Library
607
+ * layout's `<main>`, which already wraps every page in the shared
608
+ * `DOCUMENT_COLUMN` measure — the SAME 880px the Knowledge viewer uses. No
609
+ * extra `max-w` here: narrowing this page below the measure made the same
610
+ * document render at two widths depending on which surface opened it.
611
+ */
612
+ function Article({ children }: { children: ReactNode }) {
613
+ return <article className="w-full pb-14">{children}</article>;
614
+ }
615
+
616
+ /**
617
+ * What has to be connected before this skill will run. Silent when the skill
618
+ * needs nothing — a "Knowledge base only" row on most of the catalog is a line
619
+ * of noise that pushes the file the reader came for below the fold.
620
+ */
621
+ function IntegrationsSection({
622
+ needed,
623
+ onConnect,
624
+ }: {
625
+ needed: ReturnType<typeof neededToolsFor>;
626
+ onConnect(): void;
627
+ }) {
628
+ if (needed.length === 0) return null;
629
+
630
+ return (
631
+ <section className="mt-6">
632
+ <h2 className="mb-2.5 text-label font-semibold uppercase text-ink-faint">
633
+ Integrations this skill needs
634
+ </h2>
635
+ <div className="flex flex-col gap-1.5">
636
+ {needed.map((t) => {
637
+ const status = toolStatus(t);
638
+ return (
639
+ <div
640
+ key={t.slug}
641
+ className="flex items-center gap-3 rounded-md border border-line bg-sunken px-3 py-2"
642
+ >
643
+ <div className="min-w-0">
644
+ <b className="block text-detail font-semibold text-ink">{t.name}</b>
645
+ <small className="block text-meta text-ink-faint">
646
+ {status.state === 'ok' ? 'Connected. Nothing to do' : status.text}
647
+ </small>
648
+ </div>
649
+ <div className="ml-auto flex shrink-0 items-center gap-2">
650
+ {status.state === 'ok' ? (
651
+ <StatusDot state="ok" />
652
+ ) : (
653
+ <Button variant="outline" size="tiny" onClick={onConnect}>
654
+ {status.state === 'err' ? 'Reconnect' : 'Connect'}
655
+ </Button>
656
+ )}
657
+ </div>
658
+ </div>
659
+ );
660
+ })}
661
+ </div>
662
+ </section>
663
+ );
664
+ }
665
+
666
+ /** A malformed escape is a bad link, not a crash — fall back to the raw segment. */
667
+ function safeDecode(raw: string): string {
668
+ try {
669
+ return decodeURIComponent(raw);
670
+ } catch {
671
+ return raw;
672
+ }
673
+ }