@bevel-software/platform-core-frontend 0.1.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 (203) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +70 -0
  3. package/src/core/CoreAppShell.tsx +444 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +95 -0
  5. package/src/core/events.ts +29 -0
  6. package/src/core/registry.ts +336 -0
  7. package/src/css-side-effect-imports.d.ts +7 -0
  8. package/src/html-extensions.ts +12 -0
  9. package/src/index.css +49 -0
  10. package/src/index.ts +23 -0
  11. package/src/lib/api.ts +57 -0
  12. package/src/lib/utils.ts +138 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +130 -0
  14. package/src/modules/access/__tests__/useFileAccess.test.tsx +253 -0
  15. package/src/modules/access/api.ts +205 -0
  16. package/src/modules/access/components/AccessRestrictedBanner.tsx +31 -0
  17. package/src/modules/access/components/ManageAccessDialog.tsx +1232 -0
  18. package/src/modules/access/components/NodeOwnersBanner.tsx +30 -0
  19. package/src/modules/access/hooks/useFileAccess.ts +151 -0
  20. package/src/modules/admin/components/AdminRolesPage.tsx +943 -0
  21. package/src/modules/admin/components/RolesCorruptedBanner.tsx +74 -0
  22. package/src/modules/admin/services/admin.api.ts +92 -0
  23. package/src/modules/admin/services/roles.api.ts +136 -0
  24. package/src/modules/admin/state/admin.context.tsx +223 -0
  25. package/src/modules/auth/components/LoginScreen.tsx +135 -0
  26. package/src/modules/auth/hooks/useAuthState.ts +59 -0
  27. package/src/modules/auth/services/auth.api.ts +24 -0
  28. package/src/modules/auth/services/microsoft-oauth.ts +57 -0
  29. package/src/modules/auth/state/auth.context.ts +18 -0
  30. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +347 -0
  31. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +201 -0
  32. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +82 -0
  33. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +441 -0
  34. package/src/modules/git/__tests__/git.api.test.ts +113 -0
  35. package/src/modules/git/__tests__/pr.api.test.ts +44 -0
  36. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +212 -0
  37. package/src/modules/git/components/BranchSwitcher.tsx +527 -0
  38. package/src/modules/git/components/DiffView.tsx +30 -0
  39. package/src/modules/git/components/FileComparisonPanel.tsx +377 -0
  40. package/src/modules/git/components/FileHistoryPanel.tsx +320 -0
  41. package/src/modules/git/components/ProtectedBranchBanner.tsx +42 -0
  42. package/src/modules/git/components/PullNeededBanner.tsx +204 -0
  43. package/src/modules/git/components/PullRequestsForMe.tsx +244 -0
  44. package/src/modules/git/components/UnifiedDiffView.tsx +37 -0
  45. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +99 -0
  46. package/src/modules/git/hooks/useAutoPullUpdates.ts +121 -0
  47. package/src/modules/git/hooks/useGitState.ts +335 -0
  48. package/src/modules/git/services/__tests__/error-messages.test.ts +134 -0
  49. package/src/modules/git/services/error-messages.ts +257 -0
  50. package/src/modules/git/services/git.api.ts +163 -0
  51. package/src/modules/git/services/pr-prompts.ts +159 -0
  52. package/src/modules/git/services/pr.api.ts +39 -0
  53. package/src/modules/git/state/auto-update.context.ts +21 -0
  54. package/src/modules/git/state/git.context.ts +82 -0
  55. package/src/modules/layout/components/AppLayout.tsx +40 -0
  56. package/src/modules/layout/components/DemoBanner.tsx +57 -0
  57. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -0
  58. package/src/modules/layout/components/MobileChatLayout.tsx +153 -0
  59. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +203 -0
  60. package/src/modules/layout/components/SlideOverlay.tsx +224 -0
  61. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +77 -0
  62. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +57 -0
  63. package/src/modules/layout/hooks/useMediaQuery.ts +23 -0
  64. package/src/modules/layout/state/__tests__/layout.context.test.tsx +39 -0
  65. package/src/modules/layout/state/layout.context.ts +46 -0
  66. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -0
  67. package/src/modules/library/__tests__/diff.test.ts +62 -0
  68. package/src/modules/library/__tests__/loadout.test.tsx +72 -0
  69. package/src/modules/library/__tests__/status.test.ts +117 -0
  70. package/src/modules/library/components/ChangeRequestDock.tsx +47 -0
  71. package/src/modules/library/components/CompareView.tsx +357 -0
  72. package/src/modules/library/components/DetailDialog.tsx +566 -0
  73. package/src/modules/library/components/GearIcon.tsx +12 -0
  74. package/src/modules/library/components/LibraryCard.tsx +132 -0
  75. package/src/modules/library/components/LibraryPage.tsx +254 -0
  76. package/src/modules/library/components/LoadoutSidebar.tsx +156 -0
  77. package/src/modules/library/components/StatusGem.tsx +21 -0
  78. package/src/modules/library/components/SuggestChange.tsx +171 -0
  79. package/src/modules/library/components/particles.ts +50 -0
  80. package/src/modules/library/hooks/useLibraryData.ts +119 -0
  81. package/src/modules/library/hooks/useSkillDetail.ts +74 -0
  82. package/src/modules/library/library.css +320 -0
  83. package/src/modules/library/services/library.api.ts +164 -0
  84. package/src/modules/library/state/loadout.tsx +129 -0
  85. package/src/modules/library/state/toast.tsx +42 -0
  86. package/src/modules/library/utils/diff.ts +102 -0
  87. package/src/modules/library/utils/status.ts +116 -0
  88. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +93 -0
  89. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +158 -0
  90. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +44 -0
  91. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +360 -0
  92. package/src/modules/pr/__tests__/bucketize-comments.test.ts +85 -0
  93. package/src/modules/pr/__tests__/parsePatch.test.ts +104 -0
  94. package/src/modules/pr/__tests__/usePrViewerState.test.ts +72 -0
  95. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +193 -0
  96. package/src/modules/pr/components/PrApprovalBadge.tsx +80 -0
  97. package/src/modules/pr/components/PrCancelButton.tsx +99 -0
  98. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +119 -0
  99. package/src/modules/pr/components/PrCommentComposer.tsx +92 -0
  100. package/src/modules/pr/components/PrCommentThread.tsx +168 -0
  101. package/src/modules/pr/components/PrCommentsPanel.tsx +143 -0
  102. package/src/modules/pr/components/PrDiffPane.tsx +425 -0
  103. package/src/modules/pr/components/PrFileRow.tsx +164 -0
  104. package/src/modules/pr/components/PrFilesList.tsx +53 -0
  105. package/src/modules/pr/components/PrHeader.tsx +45 -0
  106. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +58 -0
  107. package/src/modules/pr/components/PrMergeButton.tsx +268 -0
  108. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +112 -0
  109. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +110 -0
  110. package/src/modules/pr/components/PrViewer.tsx +364 -0
  111. package/src/modules/pr/hooks/usePrViewerState.ts +150 -0
  112. package/src/modules/pr/services/pr-approvals.api.ts +31 -0
  113. package/src/modules/pr/services/pr-cancel.api.ts +19 -0
  114. package/src/modules/pr/services/pr-comments.api.ts +45 -0
  115. package/src/modules/pr/services/pr-detail.api.ts +17 -0
  116. package/src/modules/pr/services/pr-merge.api.ts +53 -0
  117. package/src/modules/pr/services/pr-open.api.ts +30 -0
  118. package/src/modules/pr/state/pr-viewer.context.ts +34 -0
  119. package/src/modules/pr/utils/bucketize-comments.ts +55 -0
  120. package/src/modules/pr/utils/parsePatch.ts +57 -0
  121. package/src/modules/review/__tests__/review.api.test.ts +121 -0
  122. package/src/modules/review/components/BinaryChangePlaceholder.tsx +15 -0
  123. package/src/modules/review/components/DiffViewer.tsx +78 -0
  124. package/src/modules/review/components/MarkdownDiffViewer.tsx +263 -0
  125. package/src/modules/review/components/ReviewFileRow.tsx +114 -0
  126. package/src/modules/review/components/ReviewPanel.tsx +260 -0
  127. package/src/modules/review/components/ReviewPanelSurface.tsx +52 -0
  128. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +106 -0
  129. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +88 -0
  130. package/src/modules/review/hooks/useReviewState.ts +256 -0
  131. package/src/modules/review/services/review.api.ts +72 -0
  132. package/src/modules/review/state/ReviewProvider.tsx +28 -0
  133. package/src/modules/review/state/review.context.ts +29 -0
  134. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +488 -0
  135. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -0
  136. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +362 -0
  137. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -0
  138. package/src/modules/secrets-vault/services/connect.api.ts +113 -0
  139. package/src/modules/secrets-vault/services/secrets.api.ts +82 -0
  140. package/src/modules/secrets-vault/services/tool-secrets.api.ts +116 -0
  141. package/src/modules/toolbar/components/AdminMenu.tsx +250 -0
  142. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -0
  143. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -0
  144. package/src/modules/toolbar/components/Toolbar.tsx +123 -0
  145. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +122 -0
  146. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +353 -0
  147. package/src/modules/toolbar/services/external-api-keys.api.ts +65 -0
  148. package/src/modules/tools/ToolsExplorerPage.tsx +380 -0
  149. package/src/modules/workflow/hooks/useEventBusSubscription.ts +24 -0
  150. package/src/modules/workflow/hooks/useFileLock.ts +430 -0
  151. package/src/modules/workflow/services/lock.api.ts +139 -0
  152. package/src/modules/workflow/state/EventBusFocusBinder.tsx +25 -0
  153. package/src/modules/workflow/state/EventBusProvider.tsx +232 -0
  154. package/src/modules/workflow/state/event-bus.context.ts +75 -0
  155. package/src/modules/workspace/__tests__/testFixtures.ts +54 -0
  156. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +91 -0
  157. package/src/modules/workspace/components/EditorTabs.tsx +384 -0
  158. package/src/modules/workspace/components/FileExplorer.tsx +1068 -0
  159. package/src/modules/workspace/components/FileRoute.tsx +392 -0
  160. package/src/modules/workspace/components/FileViewer.tsx +906 -0
  161. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +241 -0
  162. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +666 -0
  163. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +330 -0
  164. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +492 -0
  165. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +174 -0
  166. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +87 -0
  167. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +231 -0
  168. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +50 -0
  169. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +287 -0
  170. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +252 -0
  171. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +268 -0
  172. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +81 -0
  173. package/src/modules/workspace/components/renderers/TextRenderer.tsx +86 -0
  174. package/src/modules/workspace/components/renderers/ToolForm.tsx +404 -0
  175. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +417 -0
  176. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +157 -0
  177. package/src/modules/workspace/components/renderers/__tests__/CsvRenderer.test.ts +57 -0
  178. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +95 -0
  179. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +328 -0
  180. package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +167 -0
  181. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +318 -0
  182. package/src/modules/workspace/components/renderers/csvUtils.ts +76 -0
  183. package/src/modules/workspace/components/renderers/htmlSandbox.ts +332 -0
  184. package/src/modules/workspace/components/renderers/index.ts +39 -0
  185. package/src/modules/workspace/components/renderers/types.ts +27 -0
  186. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +298 -0
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +1315 -0
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +99 -0
  189. package/src/modules/workspace/routing/kb-routes.ts +266 -0
  190. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +72 -0
  191. package/src/modules/workspace/services/workspace.api.ts +185 -0
  192. package/src/modules/workspace/state/workspace.context.ts +235 -0
  193. package/src/modules/workspace/utils/__tests__/frontmatter.test.ts +107 -0
  194. package/src/modules/workspace/utils/diff.ts +53 -0
  195. package/src/modules/workspace/utils/fileTree.ts +179 -0
  196. package/src/modules/workspace/utils/frontmatter.ts +80 -0
  197. package/src/modules/workspace/utils/readDroppedEntries.ts +119 -0
  198. package/src/modules/workspace/utils/tab-persistence.ts +23 -0
  199. package/src/shared/components/Dialog.tsx +198 -0
  200. package/src/shared/components/PageShell.tsx +51 -0
  201. package/src/shared/components/useModalLayer.ts +35 -0
  202. package/src/shared/markdown/Markdown.tsx +62 -0
  203. package/src/test-setup.ts +59 -0
@@ -0,0 +1,444 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ useEffect,
5
+ useMemo,
6
+ useState,
7
+ Fragment,
8
+ type ReactNode,
9
+ } from 'react';
10
+ import { BrowserRouter, Navigate, Routes, Route, useLocation } from 'react-router-dom';
11
+ import { AuthContext } from '../modules/auth/state/auth.context';
12
+ import { useAuthState } from '../modules/auth/hooks/useAuthState';
13
+ import { LoginScreen } from '../modules/auth/components/LoginScreen';
14
+ import { WorkspaceContext } from '../modules/workspace/state/workspace.context';
15
+ import { useWorkspaceState } from '../modules/workspace/hooks/useWorkspaceState';
16
+ import { GitContext } from '../modules/git/state/git.context';
17
+ import { AutoUpdateContext } from '../modules/git/state/auto-update.context';
18
+ import { useGitState } from '../modules/git/hooks/useGitState';
19
+ import { useAutoPullUpdates } from '../modules/git/hooks/useAutoPullUpdates';
20
+ import { PrViewerContext } from '../modules/pr/state/pr-viewer.context';
21
+ import { usePrViewerState } from '../modules/pr/hooks/usePrViewerState';
22
+ import { EventBusProvider } from '../modules/workflow/state/EventBusProvider';
23
+ import { EventBusFocusBinder } from '../modules/workflow/state/EventBusFocusBinder';
24
+ import { Toolbar } from '../modules/toolbar/components/Toolbar';
25
+ import { DemoBanner } from '../modules/layout/components/DemoBanner';
26
+ import { FileExplorer } from '../modules/workspace/components/FileExplorer';
27
+ import { FileViewer } from '../modules/workspace/components/FileViewer';
28
+ import { FileRoute } from '../modules/workspace/components/FileRoute';
29
+ import { KB_ROUTE_PREFIX } from '../modules/workspace/routing/kb-routes';
30
+ import { AppLayout } from '../modules/layout/components/AppLayout';
31
+ import {
32
+ LayoutContext,
33
+ NO_PANES_LAYOUT,
34
+ type LayoutController,
35
+ } from '../modules/layout/state/layout.context';
36
+ import { MaintenanceOverlay } from '../modules/layout/components/MaintenanceOverlay';
37
+ import { AdminProvider } from '../modules/admin/state/admin.context';
38
+ import { RolesCorruptedBanner } from '../modules/admin/components/RolesCorruptedBanner';
39
+ import { ReviewProvider } from '../modules/review/state/ReviewProvider';
40
+ import { ReviewPanelSurface } from '../modules/review/components/ReviewPanelSurface';
41
+ import { ConnectToolsPage } from '../modules/secrets-vault/components/ConnectToolsPage';
42
+ import { SecretsPage } from '../modules/secrets-vault/components/SecretsPage';
43
+ import { ExternalAgentAccessPage } from '../modules/toolbar/components/ExternalAgentAccessPage';
44
+ import { AdminRolesPage } from '../modules/admin/components/AdminRolesPage';
45
+ import { ToolsExplorerPage } from '../modules/tools/ToolsExplorerPage';
46
+ import { LibraryPage } from '../modules/library/components/LibraryPage';
47
+ import { OpenChangeRequestDialog } from '../modules/pr/components/OpenChangeRequestDialog';
48
+ import {
49
+ activeAppId,
50
+ ActiveAppIdContext,
51
+ AppRegistryContext,
52
+ CrCreationPortContext,
53
+ SuggestedPromptSeedContext,
54
+ useAppRegistry,
55
+ type AppDef,
56
+ type AppRegistry,
57
+ type BannerDef,
58
+ type CrCreationInput,
59
+ type CrCreationPort,
60
+ type PaneDef,
61
+ } from './registry';
62
+
63
+ /**
64
+ * The registry-driven application shell for the core modules (workspace, git,
65
+ * pr, access, auth, workflow/SSE, layout, secrets-vault, tools, toolbar,
66
+ * library, review — the UI of the core diff backend — and the admin roles
67
+ * page). Everything else — chat, connectors, routines, watchlist, voice,
68
+ * embed, onboarding, admin LLM/feedback pages — is contributed through the
69
+ * {@link AppRegistry} passed in (see `src/enterprise-registry.tsx` for the
70
+ * current enterprise composition).
71
+ */
72
+
73
+ /**
74
+ * Outer authenticated shell. Mounts `EventBusProvider` BEFORE any state
75
+ * hook so the hooks below can subscribe to the SSE bus via `useEventBus()`.
76
+ *
77
+ * Why this split exists: `useWorkspaceState`, `useReviewState`, etc. each
78
+ * call `useEventBus()` and register subscriptions in a `useEffect`. The
79
+ * subscription bails when `bus === null`. If these hooks ran in the same
80
+ * component that *returns* `<EventBusProvider>`, they'd execute before
81
+ * the provider is mounted in the React tree — so `useContext(EventBusContext)`
82
+ * would return the default `null` and the subscriptions would silently
83
+ * drop on the floor (the symptom: events fire, `handlerCount: 0` in the
84
+ * dispatch log, and the file-changed live-refresh never wires up). Putting
85
+ * the provider above the state hooks fixes the ordering. (This also covers
86
+ * registry-provided state wrappers like the enterprise ReviewProvider —
87
+ * they render inside `AuthenticatedAppInner`, i.e. under the bus.)
88
+ */
89
+ function AuthenticatedApp() {
90
+ return (
91
+ <EventBusProvider>
92
+ <AuthenticatedAppInner />
93
+ </EventBusProvider>
94
+ );
95
+ }
96
+
97
+ function AuthenticatedAppInner() {
98
+ const registry = useAppRegistry();
99
+ const workspaceState = useWorkspaceState();
100
+ const gitState = useGitState(workspaceState.workspaceId);
101
+ const autoUpdateState = useAutoPullUpdates(gitState, workspaceState);
102
+ const prViewerState = usePrViewerState();
103
+
104
+ // Refresh git status whenever the user accepts/rejects pending content, since that
105
+ // is the moment new bytes hit the working tree.
106
+ const { pendingFileContent, fsRevision } = workspaceState;
107
+ const { refreshStatus } = gitState;
108
+ useEffect(() => {
109
+ if (pendingFileContent === null) {
110
+ refreshStatus();
111
+ }
112
+ }, [pendingFileContent, refreshStatus]);
113
+
114
+ // Same idea for direct FS mutations (create, delete, rename, upload, save) — the
115
+ // 30s status poll in useGitState would otherwise leave the Share Changes button
116
+ // stale until the next tick. Skip the initial mount (fsRevision === 0) since the
117
+ // effect above already covers the first-load refresh.
118
+ useEffect(() => {
119
+ if (fsRevision > 0) refreshStatus();
120
+ }, [fsRevision, refreshStatus]);
121
+
122
+ // Registry-provided wrappers (chat, onboarding-import, agent ports, …)
123
+ // apply INSIDE the core providers below — so they can read workspace/git
124
+ // state — but OUTSIDE the layout, so every pane (including registered ones)
125
+ // sees them. `providers[0]` ends up outermost. ReviewProvider is CORE (the
126
+ // UI of the core diff/pending-changes backend) and sits innermost — the
127
+ // same slot it occupied when it was registry-provided.
128
+ const chrome = registry.providers.reduceRight<ReactNode>(
129
+ (children, wrap) => wrap(children),
130
+ <ReviewProvider>
131
+ <AppChrome />
132
+ </ReviewProvider>,
133
+ );
134
+
135
+ return (
136
+ <WorkspaceContext.Provider value={workspaceState}>
137
+ <EventBusFocusBinder />
138
+ <GitContext.Provider value={gitState}>
139
+ <AutoUpdateContext.Provider value={autoUpdateState}>
140
+ <PrViewerContext.Provider value={prViewerState}>
141
+ <AdminProvider>
142
+ <CrCreationHost>{chrome}</CrCreationHost>
143
+ </AdminProvider>
144
+ </PrViewerContext.Provider>
145
+ </AutoUpdateContext.Provider>
146
+ </GitContext.Provider>
147
+ </WorkspaceContext.Provider>
148
+ );
149
+ }
150
+
151
+ // Core banner strip entries; merged (by `order`) with registry-contributed
152
+ // banners in AppChrome. The enterprise registry slots its CrDeepLink before
153
+ // and its onboarding-import banner after these.
154
+ const CORE_BANNERS: BannerDef[] = [
155
+ { id: 'demo', order: 20, node: <DemoBanner /> },
156
+ { id: 'roles-corrupted', order: 30, node: <RolesCorruptedBanner /> },
157
+ ];
158
+
159
+ // Core panes; merged (by `order`) with registry-contributed panes (the
160
+ // enterprise chat pane registers at order 30). Sizing mirrors the historical
161
+ // hard-coded three-pane layout exactly. These are the KNOWLEDGE app's panes —
162
+ // other apps render their own full surface (see CORE_APPS).
163
+ const CORE_PANES: PaneDef[] = [
164
+ {
165
+ id: 'explorer',
166
+ order: 10,
167
+ node: <FileExplorer />,
168
+ defaultSize: '17%',
169
+ minSize: '10%',
170
+ maxSize: '35%',
171
+ collapsible: true,
172
+ },
173
+ { id: 'viewer', order: 20, node: <ViewerRoutes />, minSize: '30%' },
174
+ ];
175
+
176
+ /**
177
+ * The core apps behind the toolbar's app switcher. Each app is a full
178
+ * surface below the always-mounted toolbar. "Skills & Tools" renders the
179
+ * Library full-bleed for now and will move to the dedicated view when it
180
+ * lands. Knowledge's path IS `KB_ROUTE_PREFIX` ('/workspace') — the KB file
181
+ * links `kbFileUrl()` produces are absolute `/workspace/<branch>/<path>`
182
+ * URLs, so they land inside the Knowledge surface by construction.
183
+ */
184
+ const CORE_APPS: AppDef[] = [
185
+ {
186
+ id: 'knowledge',
187
+ label: 'Knowledge',
188
+ path: KB_ROUTE_PREFIX,
189
+ description: 'Browse and edit your knowledge base',
190
+ order: 10,
191
+ element: <KnowledgeSurface />,
192
+ },
193
+ {
194
+ id: 'skills-tools',
195
+ label: 'Skills & Tools',
196
+ path: '/skills-and-tools',
197
+ description: 'What your assistant can do, and what it connects to',
198
+ order: 20,
199
+ element: <LibraryPage />,
200
+ },
201
+ ];
202
+
203
+ /**
204
+ * Setter through which the Knowledge surface's pane layout reports its
205
+ * controller to AppChrome (whose LayoutContext provider wraps the toolbar).
206
+ */
207
+ const PaneControllerContext = createContext<(c: LayoutController | null) => void>(
208
+ () => {},
209
+ );
210
+
211
+ /** The Knowledge app: the historical pane workspace (explorer / viewer / panes). */
212
+ function KnowledgeSurface() {
213
+ const registry = useAppRegistry();
214
+ const setController = useContext(PaneControllerContext);
215
+ const panes = useMemo(
216
+ () =>
217
+ [...CORE_PANES, ...registry.panes].sort(
218
+ (a, b) => (a.order ?? 100) - (b.order ?? 100),
219
+ ),
220
+ [registry],
221
+ );
222
+ return <AppLayout panes={panes} onController={setController} />;
223
+ }
224
+
225
+ function AppChrome() {
226
+ const registry = useAppRegistry();
227
+ const location = useLocation();
228
+ const banners = useMemo(
229
+ () =>
230
+ [...CORE_BANNERS, ...registry.banners].sort(
231
+ (a, b) => (a.order ?? 100) - (b.order ?? 100),
232
+ ),
233
+ [registry],
234
+ );
235
+ // The full app list (core apps were merged into the registry by the shell).
236
+ const apps = useMemo(
237
+ () => [...registry.apps].sort((a, b) => (a.order ?? 100) - (b.order ?? 100)),
238
+ [registry],
239
+ );
240
+ const activeId = activeAppId(apps, location.pathname);
241
+
242
+ // Pane controller bridge: the toolbar sits OUTSIDE the active app's surface,
243
+ // so the Knowledge pane layout reports its controller up here and the shell
244
+ // provides it around toolbar + surface. While a pane-less app (Skills &
245
+ // Tools, registry apps) is active the controller is null → NO_PANES_LAYOUT,
246
+ // which hides the toolbar's pane-toggle buttons.
247
+ const [paneController, setPaneController] = useState<LayoutController | null>(null);
248
+
249
+ return (
250
+ <ActiveAppIdContext.Provider value={activeId}>
251
+ <LayoutContext.Provider value={paneController ?? NO_PANES_LAYOUT}>
252
+ <PaneControllerContext.Provider value={setPaneController}>
253
+ {/* Flex-col wrapper so the (conditional) banner strip takes its own
254
+ height and the toolbar + active surface flex into the rest. */}
255
+ <div className="flex flex-col h-screen">
256
+ {banners.map((banner) => (
257
+ <Fragment key={banner.id}>{banner.node}</Fragment>
258
+ ))}
259
+ <Toolbar />
260
+ <div className="flex-1 min-h-0">
261
+ {/* Switching routes swaps EVERYTHING below the toolbar: an app
262
+ surface, a standalone settings page, or a redirect. */}
263
+ <ShellRoutes apps={apps} />
264
+ </div>
265
+ </div>
266
+ </PaneControllerContext.Provider>
267
+ </LayoutContext.Provider>
268
+ </ActiveAppIdContext.Provider>
269
+ );
270
+ }
271
+
272
+ /**
273
+ * The shell-level route table below the persistent toolbar:
274
+ *
275
+ * - App surfaces at `<path>/*` (a legacy `/` app path maps to `*` for API
276
+ * stability — apps come before the redirect catch-all, so a match-all app
277
+ * still wins over it).
278
+ * - The standalone settings pages — full pages under the toolbar, outside
279
+ * any app surface (activeAppId is undefined there, so the switcher shows
280
+ * no checkmark and the pane toggles hide via NO_PANES_LAYOUT). `/connect`
281
+ * and `/secrets` are OAuth return targets: external redirects land on
282
+ * these exact URLs, so they must stay routes with these exact paths.
283
+ * - Redirects: `/` → `/workspace`, and a final catch-all for anything
284
+ * unknown (including the retired `/library` path).
285
+ *
286
+ * Extracted from AppChrome so the routing behavior is testable without the
287
+ * full provider stack.
288
+ */
289
+ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
290
+ return (
291
+ <Routes>
292
+ {apps.map((app) => (
293
+ <Route
294
+ key={app.id}
295
+ path={app.path === '/' ? '*' : `${app.path}/*`}
296
+ element={app.element}
297
+ />
298
+ ))}
299
+ <Route path="/connect" element={<ConnectToolsPage />} />
300
+ <Route path="/secrets" element={<SecretsPage />} />
301
+ <Route path="/external-agent-access" element={<ExternalAgentAccessPage />} />
302
+ <Route path="/roles-and-members" element={<AdminRolesPage />} />
303
+ <Route path="/tools" element={<ToolsExplorerPage />} />
304
+ <Route path="/" element={<Navigate to={KB_ROUTE_PREFIX} replace />} />
305
+ <Route path="*" element={<Navigate to={KB_ROUTE_PREFIX} replace />} />
306
+ </Routes>
307
+ );
308
+ }
309
+
310
+ /**
311
+ * The viewer pane: registry routes first, then the core routes. This
312
+ * `<Routes>` block is nested inside the Knowledge surface's
313
+ * `${KB_ROUTE_PREFIX}/*` route, so every path here matches the REMAINDER
314
+ * after `/workspace` — `:branch/*` is `/workspace/<branch>/<path>` (the
315
+ * absolute URLs `kbFileUrl()` builds), and the default `*` is the
316
+ * knowledge-home fallback for `/workspace` itself.
317
+ */
318
+ function ViewerRoutes() {
319
+ const registry = useAppRegistry();
320
+ return (
321
+ <Routes>
322
+ {registry.viewerRoutes.map((r) => (
323
+ <Route key={r.path} path={r.path} element={r.element} />
324
+ ))}
325
+ <Route path=":branch/*" element={<FileRoute />} />
326
+ <Route path="*" element={<FileViewer />} />
327
+ </Routes>
328
+ );
329
+ }
330
+
331
+ /**
332
+ * Provides the change-request creation port. A registry-supplied override
333
+ * (`registry.crCreation`) wins; otherwise the core default opens the direct
334
+ * {@link OpenChangeRequestDialog}. Registries that need runtime state for
335
+ * their override (e.g. the chat dispatch) instead shadow
336
+ * `CrCreationPortContext` from one of their provider wrappers — those render
337
+ * deeper than this host, so the shadow wins for everything under it.
338
+ * Same story for the suggested-prompt seed.
339
+ */
340
+ function CrCreationHost({ children }: { children: ReactNode }) {
341
+ const registry = useAppRegistry();
342
+ const [dialogCtx, setDialogCtx] = useState<CrCreationInput | null>(null);
343
+
344
+ const port = useMemo<CrCreationPort>(
345
+ () => registry.crCreation ?? { start: (ctx) => setDialogCtx(ctx) },
346
+ [registry],
347
+ );
348
+
349
+ const content = (
350
+ <>
351
+ {children}
352
+ {dialogCtx && (
353
+ <OpenChangeRequestDialog
354
+ open
355
+ sourceBranch={dialogCtx.branch}
356
+ initialTargetBranch={dialogCtx.targetBranch}
357
+ onClose={() => setDialogCtx(null)}
358
+ />
359
+ )}
360
+ </>
361
+ );
362
+
363
+ return (
364
+ <CrCreationPortContext.Provider value={port}>
365
+ {registry.suggestedPromptSeed ? (
366
+ <SuggestedPromptSeedContext.Provider value={registry.suggestedPromptSeed}>
367
+ {content}
368
+ </SuggestedPromptSeedContext.Provider>
369
+ ) : (
370
+ content
371
+ )}
372
+ </CrCreationPortContext.Provider>
373
+ );
374
+ }
375
+
376
+ /** Auth gate: resolves the session, shows the login screen until the user is in. */
377
+ export function AuthGate({ children }: { children: ReactNode }) {
378
+ const auth = useAuthState();
379
+
380
+ return (
381
+ <AuthContext.Provider value={auth}>
382
+ {auth.isLoading ? (
383
+ <div className="flex items-center justify-center h-full bg-white text-slate-600 text-sm">
384
+ Loading…
385
+ </div>
386
+ ) : auth.user ? (
387
+ children
388
+ ) : (
389
+ <LoginScreen />
390
+ )}
391
+ </AuthContext.Provider>
392
+ );
393
+ }
394
+
395
+ function AppShell() {
396
+ return (
397
+ <AuthGate>
398
+ <AuthenticatedApp />
399
+ </AuthGate>
400
+ );
401
+ }
402
+
403
+ export function CoreAppShell({ registry }: { registry: AppRegistry }) {
404
+ // Core contributions merge ahead of registry-contributed ones: the review
405
+ // file-viewer panel (core — it renders the pending-changes session served
406
+ // by the core diff backend at /api/workspace/:id/review*) and the core
407
+ // apps (Knowledge + Skills & Tools) that the switcher and AppChrome read.
408
+ const mergedRegistry = useMemo<AppRegistry>(
409
+ () => ({
410
+ ...registry,
411
+ apps: [...CORE_APPS, ...registry.apps],
412
+ fileViewerPanels: [
413
+ { id: 'review', Component: ReviewPanelSurface },
414
+ ...registry.fileViewerPanels.filter((p) => p.id !== 'review'),
415
+ ],
416
+ }),
417
+ [registry],
418
+ );
419
+ // BrowserRouter wraps both auth and authenticated views so the address bar URL
420
+ // (e.g. a pasted /workspace/<branch>/<path> link) survives login —
421
+ // FileRoute picks it up automatically once auth resolves.
422
+ //
423
+ // Registry `topLevelRoutes` (the enterprise /embed* and /onboarding
424
+ // surfaces today) sit OUTSIDE `AppShell` and its auth gate — they own their
425
+ // auth story themselves (see the comments on each route definition). They
426
+ // are matched BEFORE the AppShell catch-all, so a registry can also shadow
427
+ // a shell route (e.g. serve its own /tools) when it needs a different auth
428
+ // wrapper.
429
+ return (
430
+ <AppRegistryContext.Provider value={mergedRegistry}>
431
+ <BrowserRouter>
432
+ {/* Sits above every route (including /embed) — backend downtime during
433
+ a redeploy affects them all equally. */}
434
+ <MaintenanceOverlay />
435
+ <Routes>
436
+ {registry.topLevelRoutes.map((r) => (
437
+ <Route key={r.path} path={r.path} element={r.element} />
438
+ ))}
439
+ <Route path="*" element={<AppShell />} />
440
+ </Routes>
441
+ </BrowserRouter>
442
+ </AppRegistryContext.Provider>
443
+ );
444
+ }
@@ -0,0 +1,95 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { MemoryRouter, useLocation } from 'react-router-dom';
4
+ import { ShellRoutes } from '../CoreAppShell';
5
+ import type { AppDef } from '../registry';
6
+
7
+ // The /secrets standalone page fetches on mount — stub its data layer so the
8
+ // route can render without a network. (The other standalone pages are not
9
+ // visited by these tests.)
10
+ vi.mock('../../modules/secrets-vault/services/secrets.api', () => ({
11
+ listSecrets: vi.fn(async () => []),
12
+ createOAuthSecret: vi.fn(async () => {}),
13
+ deleteSecret: vi.fn(async () => {}),
14
+ startOAuth: vi.fn(async () => ''),
15
+ }));
16
+ vi.mock('../../modules/secrets-vault/services/tool-secrets.api', () => ({
17
+ listToolSecrets: vi.fn(async () => []),
18
+ setAdminVar: vi.fn(async () => {}),
19
+ setUserVar: vi.fn(async () => {}),
20
+ setOAuthClientSecret: vi.fn(async () => {}),
21
+ deleteAdminVar: vi.fn(async () => {}),
22
+ deleteUserVar: vi.fn(async () => {}),
23
+ }));
24
+
25
+ /** Exposes the router's current pathname so redirects can be asserted. */
26
+ function LocationProbe() {
27
+ const location = useLocation();
28
+ return <div data-testid="pathname">{location.pathname}</div>;
29
+ }
30
+
31
+ // Stub app surfaces — the route table is what's under test, not the panes.
32
+ const apps: AppDef[] = [
33
+ {
34
+ id: 'knowledge',
35
+ label: 'Knowledge',
36
+ path: '/workspace',
37
+ order: 10,
38
+ element: <div data-testid="knowledge-surface" />,
39
+ },
40
+ {
41
+ id: 'skills-tools',
42
+ label: 'Skills & Tools',
43
+ path: '/skills-and-tools',
44
+ order: 20,
45
+ element: <div data-testid="skills-surface" />,
46
+ },
47
+ ];
48
+
49
+ function renderAt(path: string) {
50
+ return render(
51
+ <MemoryRouter initialEntries={[path]}>
52
+ <ShellRoutes apps={apps} />
53
+ <LocationProbe />
54
+ </MemoryRouter>,
55
+ );
56
+ }
57
+
58
+ describe('ShellRoutes', () => {
59
+ it('redirects / to /workspace and renders the Knowledge surface', () => {
60
+ renderAt('/');
61
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/workspace$/);
62
+ expect(screen.getByTestId('knowledge-surface')).toBeInTheDocument();
63
+ });
64
+
65
+ it('sends the retired /library path into the catch-all → /workspace', () => {
66
+ renderAt('/library');
67
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/workspace$/);
68
+ expect(screen.getByTestId('knowledge-surface')).toBeInTheDocument();
69
+ });
70
+
71
+ it('sends an unknown URL into the catch-all → /workspace', () => {
72
+ renderAt('/no-such-page/at-all');
73
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/workspace$/);
74
+ expect(screen.getByTestId('knowledge-surface')).toBeInTheDocument();
75
+ });
76
+
77
+ it('keeps a KB deep link inside the Knowledge surface', () => {
78
+ renderAt('/workspace/main/SomeFile.md');
79
+ expect(screen.getByTestId('pathname')).toHaveTextContent('/workspace/main/SomeFile.md');
80
+ expect(screen.getByTestId('knowledge-surface')).toBeInTheDocument();
81
+ });
82
+
83
+ it('renders the Skills & Tools surface at /skills-and-tools', () => {
84
+ renderAt('/skills-and-tools');
85
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/skills-and-tools$/);
86
+ expect(screen.getByTestId('skills-surface')).toBeInTheDocument();
87
+ });
88
+
89
+ it('renders the standalone Secrets page at /secrets without redirecting', async () => {
90
+ renderAt('/secrets');
91
+ expect(screen.getByTestId('pathname')).toHaveTextContent(/^\/secrets$/);
92
+ expect(await screen.findByRole('heading', { name: 'Secrets' })).toBeInTheDocument();
93
+ expect(screen.queryByTestId('knowledge-surface')).not.toBeInTheDocument();
94
+ });
95
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Window-level custom-event names shared across modules. Centralised here so
3
+ * core and registry-contributed (enterprise) modules agree on the same wire
4
+ * names without importing each other's components.
5
+ */
6
+
7
+ /**
8
+ * Fired whenever something in the app may have mutated the change-request
9
+ * list (a merge/apply completed, the agent opened or closed a CR via `gh`,
10
+ * a pull brought in teammates' merges, a cancel went through). Listeners
11
+ * (the "Change requests for you" sidebar) refetch immediately instead of
12
+ * waiting for their next poll tick.
13
+ */
14
+ export const PR_STALE_EVENT = 'bevel:pr-stale';
15
+
16
+ /**
17
+ * Custom event the chat-side `compare_files` tool-card dispatches to deep-link
18
+ * into the comparison panel. The FileViewer listens for this and forwards
19
+ * `path` to the workspace open-file flow plus the from/to refs to the
20
+ * FileComparisonPanel.
21
+ */
22
+ export const OPEN_COMPARISON_EVENT = 'bevel:open-comparison';
23
+
24
+ /** Payload carried by {@link OPEN_COMPARISON_EVENT}. */
25
+ export interface OpenComparisonDetail {
26
+ path: string;
27
+ fromBranch: string;
28
+ toBranch: string;
29
+ }