@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,336 @@
1
+ /**
2
+ * The app registry: the contract between the core shell (`CoreAppShell`) and
3
+ * optional (enterprise) modules. The core owns workspace, git, pr, access,
4
+ * auth, workflow/SSE, layout, secrets-vault, tools, toolbar and the admin
5
+ * roles page; everything else (chat, connectors, routines, watchlist, voice,
6
+ * embed, review, onboarding, admin LLM/feedback pages) is contributed through
7
+ * an `AppRegistry` instance passed to `<CoreAppShell registry={...} />`.
8
+ *
9
+ * Follows the same registration pattern as the file-renderer registry in
10
+ * `modules/workspace/components/renderers/index.ts`: a plain data structure
11
+ * the shell iterates over, no runtime plugin machinery.
12
+ */
13
+ import {
14
+ createContext,
15
+ useContext,
16
+ type ComponentType,
17
+ type ReactElement,
18
+ type ReactNode,
19
+ } from 'react';
20
+ import type { FileTreeEntry } from '@bevel-software/platform-shared';
21
+ import type { FileRendererProps } from '../modules/workspace/components/renderers/types';
22
+
23
+ /** A route contributed to one of the shell's `<Routes>` blocks. */
24
+ export interface RouteDef {
25
+ path: string;
26
+ element: ReactElement;
27
+ }
28
+
29
+ /**
30
+ * One pane of the main (three-pane today) layout. The core registers
31
+ * `explorer` and `viewer`; the enterprise registry contributes `chat`.
32
+ * The layout's panel ids (and therefore the persisted layout shape) are
33
+ * derived from the registered pane list.
34
+ *
35
+ * ⚠️ The pane list must be static for the lifetime of the shell — panes are
36
+ * not designed to be added/removed at runtime.
37
+ */
38
+ export interface PaneDef {
39
+ id: string;
40
+ node: ReactNode;
41
+ /** Merge position among all registered panes (ascending). */
42
+ order?: number;
43
+ /** e.g. '17%' — omitted panes share the remaining space. */
44
+ defaultSize?: string;
45
+ minSize?: string;
46
+ maxSize?: string;
47
+ /** Collapsible panes get collapse tracking + a toolbar toggle. */
48
+ collapsible?: boolean;
49
+ }
50
+
51
+ /** A banner strip rendered above the main layout (order ascending). */
52
+ export interface BannerDef {
53
+ id: string;
54
+ node: ReactNode;
55
+ order?: number;
56
+ }
57
+
58
+ export interface AdminMenuItemHelpers {
59
+ /** Close the gear menu and return focus to the trigger. */
60
+ closeMenu(): void;
61
+ /** react-router navigation. */
62
+ navigate(to: string): void;
63
+ }
64
+
65
+ /**
66
+ * One row of the toolbar gear menu. Core rows (Skills & Tools, External
67
+ * agent access, Secrets, Browse available tools, Roles & Members) are built
68
+ * into AdminMenu and navigate to standalone routed pages; enterprise rows
69
+ * are contributed here. A row either opens a dialog (`dialog` — mounted
70
+ * persistently by AdminMenu, driven by an open flag, so existing dialog
71
+ * components need no changes) or runs an action (`onSelect`, e.g. a
72
+ * navigation).
73
+ */
74
+ export interface AdminMenuItem {
75
+ id: string;
76
+ label: ReactNode;
77
+ icon?: ReactNode;
78
+ /** 'admin' rows render under the "Admin only" section (admin users only). */
79
+ section?: 'default' | 'admin';
80
+ /** Merge position among core + registered rows of the same section. */
81
+ order?: number;
82
+ onSelect?(helpers: AdminMenuItemHelpers): void;
83
+ dialog?(props: { open: boolean; onClose(): void }): ReactElement;
84
+ }
85
+
86
+ /**
87
+ * An auxiliary surface mounted inside the FileViewer container (rendered on
88
+ * every FileViewer return path, positioned via its own absolute styling).
89
+ * The enterprise registry contributes the agent-review surface here; the
90
+ * change-request viewer (PrViewer) is core and stays hard-mounted.
91
+ */
92
+ export interface FileViewerPanelDef {
93
+ id: string;
94
+ Component: ComponentType;
95
+ }
96
+
97
+ /**
98
+ * A file renderer OVERRIDE consulted by the FileViewer before the built-in
99
+ * extension map (`modules/workspace/components/renderers`). The enterprise
100
+ * registry replaces the plain `.html` renderer with one that inlines its
101
+ * vendored d3/mermaid libraries and the KB graph client.
102
+ */
103
+ export interface FileRendererDef {
104
+ /** Lowercase extensions including the dot, e.g. `['.html', '.htm']`. */
105
+ extensions: string[];
106
+ Component: ComponentType<FileRendererProps>;
107
+ }
108
+
109
+ /**
110
+ * A row appended to the file explorer's "Pinned" section (after the pinned
111
+ * folders). The component receives the explorer's merged file tree (null
112
+ * while loading) and renders its own row — plus any overlay that row opens.
113
+ * The enterprise knowledge system contributes its "Graph view" entry here.
114
+ */
115
+ export interface ExplorerItemDef {
116
+ id: string;
117
+ Component: ComponentType<{ tree: FileTreeEntry | null }>;
118
+ }
119
+
120
+ /** Context passed when the user asks to open a change request from a draft. */
121
+ export interface CrCreationInput {
122
+ workspaceId: string | null;
123
+ /** Source branch (the user's current shared draft). */
124
+ branch: string;
125
+ /** Target branch, when the caller already picked one. */
126
+ targetBranch?: string;
127
+ /** True when this creation is part of a conflict-recovery flow. */
128
+ conflict?: boolean;
129
+ }
130
+
131
+ /** Context for "my draft is behind / a pull failed" recovery. */
132
+ export interface PullIssueInput {
133
+ workspaceId: string | null;
134
+ branch: string;
135
+ /** 'behind' = updates waiting; 'pull-failed' = a direct pull was refused. */
136
+ kind: 'behind' | 'pull-failed';
137
+ /** Plain-language classification of the failure (never raw git output). */
138
+ reason?: string;
139
+ }
140
+
141
+ /** Context for conflicts while applying/refreshing an existing change request. */
142
+ export interface CrConflictInput {
143
+ kind: 'apply' | 'refresh';
144
+ changeRequestNumber: number;
145
+ base: string;
146
+ conflictedPaths: string[];
147
+ }
148
+
149
+ /**
150
+ * The change-request port. Core git/pr components call this instead of
151
+ * seeding chat prompts directly, which keeps the chat module out of core.
152
+ *
153
+ * - Default (no override registered): `start` opens the core
154
+ * `OpenChangeRequestDialog`, which posts straight to
155
+ * `POST /api/workflow/change-requests`. The optional recovery methods are
156
+ * absent, so their affordances hide / fall back to inline errors.
157
+ * - Enterprise: a provider shadows {@link CrCreationPortContext} with an
158
+ * implementation that seeds the chat composer (agent-driven flow) —
159
+ * today's behavior, unchanged.
160
+ */
161
+ export interface CrCreationPort {
162
+ start(ctx: CrCreationInput): void;
163
+ /** Absent → the "Ask assistant" affordance hides. */
164
+ resolvePullIssue?(ctx: PullIssueInput): void;
165
+ /** Absent → apply/refresh conflicts surface as inline errors. */
166
+ resolveCrConflicts?(ctx: CrConflictInput): void;
167
+ }
168
+
169
+ /**
170
+ * An entry in the app switcher behind the toolbar brand (top-left). Each app
171
+ * is a top-level SURFACE: switching apps swaps everything below the (always
172
+ * mounted) toolbar for the app's `element`. Core ships "Knowledge" (the pane
173
+ * workspace) and "Skills & Tools"; the enterprise registry appends its own.
174
+ */
175
+ export interface AppDef {
176
+ id: string;
177
+ label: string;
178
+ /** Route the switcher navigates to. Also drives the active highlight and
179
+ * the surface's route (`<path>/*`): the app whose path is the longest
180
+ * prefix of the current location is active. Core ships Knowledge at
181
+ * '/workspace' and Skills & Tools at '/skills-and-tools'; on locations no
182
+ * app claims (the standalone settings pages) no app is active. A '/' path
183
+ * is still honored as a match-everything fallback for API stability, but
184
+ * no core app uses it anymore. */
185
+ path: string;
186
+ /** The full-height surface rendered below the toolbar while active. */
187
+ element: ReactElement;
188
+ /** One-line subtitle under the label in the switcher list. */
189
+ description?: string;
190
+ /** Sort order in the list (core: Knowledge 10, Skills & Tools 20). */
191
+ order?: number;
192
+ }
193
+
194
+ /**
195
+ * Pick the active app for a location: the app whose `path` is the longest
196
+ * prefix of the pathname, or undefined when no app claims it (the standalone
197
+ * settings pages — no switcher checkmark, no pane toggles). A '/' app path
198
+ * matches everything and only wins when no more specific path does; core no
199
+ * longer registers one (Knowledge lives at '/workspace'), but the fallback
200
+ * semantics are kept for registries that do.
201
+ */
202
+ export function activeAppId(apps: AppDef[], pathname: string): string | undefined {
203
+ let best: AppDef | undefined;
204
+ for (const app of apps) {
205
+ const matches =
206
+ app.path === '/'
207
+ ? true
208
+ : pathname === app.path || pathname.startsWith(`${app.path}/`);
209
+ if (matches && (!best || app.path.length > best.path.length)) best = app;
210
+ }
211
+ return best?.id;
212
+ }
213
+
214
+ /**
215
+ * A toolbar contribution rendered in the left cluster next to the app
216
+ * switcher (and on the compact second row on narrow screens). The node runs
217
+ * under the shell's providers, so it can read {@link useActiveAppId} and
218
+ * render only for specific apps — that is how the enterprise scopes its
219
+ * branch switcher to the Knowledge app.
220
+ */
221
+ export interface ToolbarItemDef {
222
+ id: string;
223
+ node: ReactNode;
224
+ order?: number;
225
+ }
226
+
227
+ export interface AppRegistry {
228
+ /** Apps appended to the toolbar's app switcher (see {@link AppDef}). */
229
+ apps: AppDef[];
230
+ /** Toolbar left-cluster contributions (see {@link ToolbarItemDef}). */
231
+ toolbarItems: ToolbarItemDef[];
232
+ /** Routes mounted OUTSIDE the app shell (own auth handling, no workspace chrome). */
233
+ topLevelRoutes: RouteDef[];
234
+ /**
235
+ * Extra routes inside the viewer pane's `<Routes>`. The viewer pane is
236
+ * nested under the Knowledge surface's `/workspace/*` route, so these
237
+ * paths are RELATIVE to `/workspace` (a route registered as 'connectors'
238
+ * renders at `/workspace/connectors`). Surfaces that need a top-level URL
239
+ * of their own belong in `topLevelRoutes` instead.
240
+ */
241
+ viewerRoutes: RouteDef[];
242
+ /**
243
+ * Ordered wrappers applied INSIDE the core providers (workspace, git,
244
+ * auto-update, pr-viewer, admin, event bus) but OUTSIDE the layout, so they
245
+ * can read core state and every pane sees them. `providers[0]` is outermost.
246
+ */
247
+ providers: Array<(children: ReactNode) => ReactElement>;
248
+ /** Panes merged with the core explorer/viewer panes (see {@link PaneDef}). */
249
+ panes: PaneDef[];
250
+ /** Banners merged with the core banner strip above the layout. */
251
+ banners: BannerDef[];
252
+ /** Gear-menu rows merged with the core rows (see {@link AdminMenuItem}). */
253
+ adminMenuItems: AdminMenuItem[];
254
+ /** Auxiliary FileViewer surfaces (see {@link FileViewerPanelDef}). */
255
+ fileViewerPanels: FileViewerPanelDef[];
256
+ /** File-renderer overrides by extension (see {@link FileRendererDef}). */
257
+ renderers: FileRendererDef[];
258
+ /** Extra rows in the explorer's Pinned section (see {@link ExplorerItemDef}). */
259
+ explorerItems: ExplorerItemDef[];
260
+ /**
261
+ * Static override of the change-request port. Overrides that need runtime
262
+ * state (e.g. the chat dispatch) should instead shadow
263
+ * {@link CrCreationPortContext} from one of the `providers` wrappers.
264
+ */
265
+ crCreation?: CrCreationPort;
266
+ /**
267
+ * Static override of the suggested-prompt seeding callback (see
268
+ * {@link SuggestedPromptSeedContext} for the runtime-state variant). When
269
+ * neither is provided the FileViewer hides its suggested-prompt buttons.
270
+ */
271
+ suggestedPromptSeed?: (prompt: string) => void;
272
+ }
273
+
274
+ export const EMPTY_REGISTRY: AppRegistry = {
275
+ topLevelRoutes: [],
276
+ viewerRoutes: [],
277
+ providers: [],
278
+ panes: [],
279
+ banners: [],
280
+ adminMenuItems: [],
281
+ fileViewerPanels: [],
282
+ renderers: [],
283
+ explorerItems: [],
284
+ apps: [],
285
+ toolbarItems: [],
286
+ };
287
+
288
+ /**
289
+ * The active app's id (see {@link activeAppId}), provided by the shell above
290
+ * the toolbar and every app surface. `undefined` outside the shell (tests,
291
+ * standalone renders) — treat that as "no app context".
292
+ */
293
+ export const ActiveAppIdContext = createContext<string | undefined>(undefined);
294
+
295
+ export function useActiveAppId(): string | undefined {
296
+ return useContext(ActiveAppIdContext);
297
+ }
298
+
299
+ /** Convenience builder: fill in the empty defaults for unspecified fields. */
300
+ export function makeRegistry(partial: Partial<AppRegistry>): AppRegistry {
301
+ return { ...EMPTY_REGISTRY, ...partial };
302
+ }
303
+
304
+ /**
305
+ * The registry itself, readable anywhere under `CoreAppShell`. Defaults to
306
+ * the empty registry so components (AdminMenu, FileViewer, layout) degrade to
307
+ * core-only behavior when rendered standalone (tests, storybooks).
308
+ */
309
+ export const AppRegistryContext = createContext<AppRegistry>(EMPTY_REGISTRY);
310
+
311
+ export function useAppRegistry(): AppRegistry {
312
+ return useContext(AppRegistryContext);
313
+ }
314
+
315
+ /**
316
+ * The change-request port (see {@link CrCreationPort}). The core shell always
317
+ * provides a default (the direct-creation dialog); enterprise wrappers may
318
+ * shadow it. Null only when rendered outside the shell entirely.
319
+ */
320
+ export const CrCreationPortContext = createContext<CrCreationPort | null>(null);
321
+
322
+ export function useCrCreationPort(): CrCreationPort | null {
323
+ return useContext(CrCreationPortContext);
324
+ }
325
+
326
+ /**
327
+ * Seeds the chat composer with a suggested prompt (FileViewer empty state).
328
+ * Null → no chat surface registered → the suggested-prompt UI hides.
329
+ */
330
+ export const SuggestedPromptSeedContext = createContext<
331
+ ((prompt: string) => void) | null
332
+ >(null);
333
+
334
+ export function useSuggestedPromptSeed(): ((prompt: string) => void) | null {
335
+ return useContext(SuggestedPromptSeedContext);
336
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Ambient declaration for side-effect CSS imports (`import '../library.css'`).
3
+ * The enterprise app gets this from Vite's `vite/client` types; this package
4
+ * is published as raw source and typechecked without Vite, so it declares the
5
+ * module shape itself (harmless alongside vite/client in consumers).
6
+ */
7
+ declare module '*.css';
@@ -0,0 +1,12 @@
1
+ // Non-standard but widely-supported HTML attributes that React's typings omit.
2
+ // `webkitdirectory` makes `<input type="file">` enumerate the contents of a
3
+ // chosen directory (with `File.webkitRelativePath` populated). Used by the
4
+ // FileExplorer's "Add folder" picker.
5
+
6
+ import 'react';
7
+
8
+ declare module 'react' {
9
+ interface InputHTMLAttributes<T> extends HTMLAttributes<T> {
10
+ webkitdirectory?: string;
11
+ }
12
+ }
package/src/index.css ADDED
@@ -0,0 +1,49 @@
1
+ @import "tailwindcss";
2
+ @plugin "@tailwindcss/typography";
3
+
4
+ @theme {
5
+ --color-bevel: #863bff;
6
+ --color-bevel-deep: #7e14ff;
7
+ --color-bevel-soft: #ede6ff;
8
+ }
9
+
10
+ /* Tailwind Typography ships dark <pre> backgrounds by default; the app is
11
+ light-only, so retheme prose code blocks to slate. */
12
+ .prose {
13
+ --tw-prose-pre-bg: var(--color-slate-100);
14
+ --tw-prose-pre-code: var(--color-slate-900);
15
+ }
16
+ .prose :where(pre):not(:where([class~="not-prose"] *)) {
17
+ border: 1px solid var(--color-slate-200);
18
+ }
19
+
20
+ html, body, #root {
21
+ height: 100%;
22
+ margin: 0;
23
+ overflow: hidden;
24
+ }
25
+
26
+ body {
27
+ font-family: system-ui, -apple-system, sans-serif;
28
+ -webkit-font-smoothing: antialiased;
29
+ }
30
+
31
+ /* Persistent scrollbars in the VSCode webview. macOS overlay scrollbars fade
32
+ out by default, leaving long chat threads with no visible scroll affordance. */
33
+ ::-webkit-scrollbar {
34
+ width: 10px;
35
+ height: 10px;
36
+ }
37
+ ::-webkit-scrollbar-track {
38
+ background: transparent;
39
+ }
40
+ ::-webkit-scrollbar-thumb {
41
+ background: rgb(64 64 64);
42
+ border-radius: 5px;
43
+ border: 2px solid transparent;
44
+ background-clip: content-box;
45
+ }
46
+ ::-webkit-scrollbar-thumb:hover {
47
+ background: rgb(82 82 82);
48
+ background-clip: content-box;
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @bevel-software/platform-core-frontend — the open-source core UI of the Bevel
3
+ * platform, published as RAW TypeScript/TSX source (the consuming app's
4
+ * bundler compiles it; react / react-dom / react-router-dom / tailwindcss are
5
+ * peer dependencies).
6
+ *
7
+ * Mount `<CoreAppShell registry={makeRegistry({...})} />` and contribute
8
+ * optional surfaces (extra panes, routes, providers, gear-menu rows, file-
9
+ * viewer panels, the change-request port) through the {@link AppRegistry}.
10
+ *
11
+ * Tailwind: import `@bevel-software/platform-core-frontend/index.css` and add an
12
+ * `@source` directive pointing at this package's `src/` so the consumer's
13
+ * Tailwind build emits the classes used here.
14
+ */
15
+
16
+ // Global React typings augmentation (webkitdirectory on <input>) — a real
17
+ // module (not a bare .d.ts) so consumers pick it up just by importing the
18
+ // package; emits an empty runtime module.
19
+ import './html-extensions';
20
+
21
+ export { CoreAppShell, AuthGate } from './core/CoreAppShell';
22
+ export * from './core/registry';
23
+ export * from './core/events';
package/src/lib/api.ts ADDED
@@ -0,0 +1,57 @@
1
+ const TOKEN_KEY = 'bevel_token';
2
+
3
+ /**
4
+ * Window event dispatched when an API call fails at the transport level —
5
+ * the fetch itself rejected (backend/container down, connection refused) or
6
+ * the reverse proxy answered for a dead upstream (502/503/504). The
7
+ * MaintenanceOverlay listens for this, confirms via /api/health, and takes
8
+ * over the screen during a redeploy. Application-level errors (4xx, 500)
9
+ * are NOT signalled — those mean the backend is up and responding.
10
+ */
11
+ export const API_UNREACHABLE_EVENT = 'bevel:api-unreachable';
12
+
13
+ const PROXY_DOWN_STATUSES = new Set([502, 503, 504]);
14
+
15
+ function signalUnreachable(): void {
16
+ window.dispatchEvent(new Event(API_UNREACHABLE_EVENT));
17
+ }
18
+
19
+ export function getToken(): string | null {
20
+ return localStorage.getItem(TOKEN_KEY);
21
+ }
22
+
23
+ export function setToken(token: string): void {
24
+ localStorage.setItem(TOKEN_KEY, token);
25
+ }
26
+
27
+ export function clearToken(): void {
28
+ localStorage.removeItem(TOKEN_KEY);
29
+ }
30
+
31
+ /**
32
+ * Fetch wrapper that injects the Authorization header from localStorage.
33
+ * On 401 responses, clears the stored token.
34
+ */
35
+ export async function authFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
36
+ const token = getToken();
37
+ const headers = new Headers(init?.headers);
38
+ if (token) headers.set('Authorization', `Bearer ${token}`);
39
+
40
+ let response: Response;
41
+ try {
42
+ response = await fetch(input, { ...init, headers });
43
+ } catch (err) {
44
+ signalUnreachable();
45
+ throw err;
46
+ }
47
+
48
+ if (PROXY_DOWN_STATUSES.has(response.status)) {
49
+ signalUnreachable();
50
+ }
51
+
52
+ if (response.status === 401) {
53
+ clearToken();
54
+ }
55
+
56
+ return response;
57
+ }
@@ -0,0 +1,138 @@
1
+ import { clsx, type ClassValue } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
7
+
8
+ // Hide the extension in display labels. Dot-prefixed names (.env, .gitignore)
9
+ // keep their full name. Compound suffixes (foo.test.ts) only lose the final part.
10
+ export function stripExtension(filename: string): string {
11
+ const lastDot = filename.lastIndexOf('.');
12
+ if (lastDot <= 0) return filename;
13
+ return filename.slice(0, lastDot);
14
+ }
15
+
16
+ export function getFileExtension(filename: string): string {
17
+ const lastDot = filename.lastIndexOf('.');
18
+ if (lastDot <= 0) return '';
19
+ return filename.slice(lastDot + 1).toLowerCase();
20
+ }
21
+
22
+ const ICON_BY_FILENAME: Record<string, string> = {
23
+ 'package.json': 'nodejs',
24
+ 'package-lock.json': 'nodejs',
25
+ 'pnpm-lock.yaml': 'pnpm',
26
+ 'pnpm-workspace.yaml': 'pnpm',
27
+ 'yarn.lock': 'yarn',
28
+ 'tsconfig.json': 'tsconfig',
29
+ 'tsconfig.base.json': 'tsconfig',
30
+ 'vite.config.ts': 'vite',
31
+ 'vite.config.js': 'vite',
32
+ 'vitest.config.ts': 'vitest',
33
+ '.gitignore': 'git',
34
+ '.gitattributes': 'git',
35
+ '.prettierrc': 'prettier',
36
+ '.prettierrc.json': 'prettier',
37
+ '.prettierignore': 'prettier',
38
+ '.eslintrc': 'eslint',
39
+ '.eslintrc.json': 'eslint',
40
+ '.eslintrc.js': 'eslint',
41
+ 'eslint.config.js': 'eslint',
42
+ 'eslint.config.ts': 'eslint',
43
+ dockerfile: 'docker',
44
+ 'docker-compose.yml': 'docker',
45
+ 'docker-compose.yaml': 'docker',
46
+ makefile: 'makefile',
47
+ 'readme.md': 'readme',
48
+ readme: 'readme',
49
+ license: 'license',
50
+ 'license.md': 'license',
51
+ '.env': 'tune',
52
+ '.env.local': 'tune',
53
+ '.env.production': 'tune',
54
+ '.env.development': 'tune',
55
+ 'components.json': 'json',
56
+ };
57
+
58
+ const ICON_BY_EXT: Record<string, string> = {
59
+ md: 'markdown',
60
+ mdx: 'markdown',
61
+ txt: 'document',
62
+ rtf: 'document',
63
+ pdf: 'pdf',
64
+ ts: 'typescript',
65
+ tsx: 'react-ts',
66
+ js: 'javascript',
67
+ jsx: 'react',
68
+ mjs: 'javascript',
69
+ cjs: 'javascript',
70
+ py: 'python',
71
+ rs: 'rust',
72
+ go: 'go',
73
+ rb: 'ruby',
74
+ java: 'java',
75
+ c: 'c',
76
+ cpp: 'cpp',
77
+ cs: 'csharp',
78
+ php: 'php',
79
+ swift: 'swift',
80
+ kt: 'kotlin',
81
+ sh: 'console',
82
+ bash: 'console',
83
+ zsh: 'console',
84
+ fish: 'console',
85
+ html: 'html',
86
+ htm: 'html',
87
+ css: 'css',
88
+ scss: 'scss',
89
+ sass: 'sass',
90
+ less: 'less',
91
+ json: 'json',
92
+ jsonc: 'json',
93
+ yml: 'yaml',
94
+ yaml: 'yaml',
95
+ toml: 'toml',
96
+ xml: 'xml',
97
+ csv: 'table',
98
+ tsv: 'table',
99
+ xls: 'table',
100
+ xlsx: 'table',
101
+ ods: 'table',
102
+ sql: 'database',
103
+ png: 'image',
104
+ jpg: 'image',
105
+ jpeg: 'image',
106
+ gif: 'image',
107
+ webp: 'image',
108
+ avif: 'image',
109
+ bmp: 'image',
110
+ ico: 'image',
111
+ svg: 'svg',
112
+ mp3: 'audio',
113
+ wav: 'audio',
114
+ flac: 'audio',
115
+ ogg: 'audio',
116
+ mp4: 'video',
117
+ mov: 'video',
118
+ webm: 'video',
119
+ avi: 'video',
120
+ zip: 'zip',
121
+ tar: 'zip',
122
+ gz: 'zip',
123
+ '7z': 'zip',
124
+ rar: 'zip',
125
+ ttf: 'font',
126
+ otf: 'font',
127
+ woff: 'font',
128
+ woff2: 'font',
129
+ };
130
+
131
+ const DEFAULT_ICON = 'document';
132
+
133
+ export function getFileIcon(filename: string): string {
134
+ const lower = filename.toLowerCase();
135
+ const override = ICON_BY_FILENAME[lower];
136
+ if (override) return override;
137
+ return ICON_BY_EXT[getFileExtension(filename)] ?? DEFAULT_ICON;
138
+ }