@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,30 @@
1
+ import { Users } from 'lucide-react';
2
+ import type { AccessEligible } from '../api';
3
+ import { formatEligible } from '../hooks/useFileAccess';
4
+
5
+ interface Props {
6
+ owners: AccessEligible;
7
+ }
8
+
9
+ /**
10
+ * A subtle line above the editor naming the file's owners — the people to
11
+ * contact for more information about the node. Owners come from the `owner:`
12
+ * lists in the access tree; they also hold write + approval rights, but this
13
+ * banner is purely informational. Render only when there is at least one
14
+ * owner.
15
+ */
16
+ export function NodeOwnersBanner({ owners }: Props) {
17
+ if (owners.roles.length === 0 && owners.users.length === 0) return null;
18
+ const summary = formatEligible(owners);
19
+ return (
20
+ <div
21
+ role="note"
22
+ className="flex items-center gap-2 px-3 py-1.5 bg-slate-50 border-b border-slate-200 text-xs text-slate-600 shrink-0"
23
+ >
24
+ <Users size={13} className="shrink-0 text-slate-500" />
25
+ <span className="flex-1">
26
+ Owners — contact for more information: <span className="font-medium">{summary}</span>
27
+ </span>
28
+ </div>
29
+ );
30
+ }
@@ -0,0 +1,151 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { isProtectedBranch } from '@bevel-software/platform-shared';
3
+ import { useWorkspace } from '../../workspace/state/workspace.context';
4
+ import { fetchFileAccess, type AccessEligible } from '../api';
5
+
6
+ export interface FileAccessState {
7
+ /**
8
+ * `null` while the request is in flight (or while we don't have a path to
9
+ * check). `true` / `false` once the backend has answered. On error we fall
10
+ * back to `true` so a transient API failure doesn't surprise-block edits
11
+ * — the backend is the authoritative gate at commit time anyway.
12
+ */
13
+ canWrite: boolean | null;
14
+ eligible: AccessEligible;
15
+ /**
16
+ * The node's owners — who to contact about it. Populated only when the
17
+ * access lookup actually runs (protected branches with the file inside the
18
+ * KB). Empty on drafts / non-KB paths, where the lookup is short-circuited.
19
+ */
20
+ owners: AccessEligible;
21
+ /** True while the network request is in flight. */
22
+ loading: boolean;
23
+ /** Non-null when the lookup failed; we default-allow in that case. */
24
+ error: string | null;
25
+ }
26
+
27
+ const EMPTY_ELIGIBLE: AccessEligible = { roles: [], users: [] };
28
+
29
+ /**
30
+ * Resolve write permission for the given workspace-relative path against the
31
+ * active workspace's access tree. Returns a loading-aware state so callers can
32
+ * render an optimistic editor (`canWrite === null`) until the answer lands.
33
+ *
34
+ * `workspacePath` is workspace-relative — the same string the file tree uses
35
+ * (`knowledge-base/Knowledge/Foo.md` for KB files, `my-notes.txt` for a
36
+ * user-owned scratch file at workspace root). `branch` is the branch the
37
+ * user is currently on. The hook splits three cases:
38
+ *
39
+ * - **Path outside the KB repo dir.** Returns `canWrite: true` with empty
40
+ * eligible and never hits the network. Files outside `<kbDirName>/` are
41
+ * the user's own workspace; the access-control tree only governs the KB.
42
+ * - **Branch is non-protected (a draft).** Returns `canWrite: true` and
43
+ * never hits the network. Drafts are free-for-all in this model — the
44
+ * backend doesn't gate commit / push / lock on drafts either; the real
45
+ * access boundary is the change-request merge against the protected
46
+ * base. Showing the editor as read-only on a draft would contradict
47
+ * what the backend would happily accept.
48
+ * - **Branch is protected (and path is inside the KB).** Strips the
49
+ * `<kbDirName>/` prefix and queries the backend with the repo-relative
50
+ * path the resolver expects.
51
+ *
52
+ * Pass `null` for `workspacePath` when no file is open, and `null` for
53
+ * `branch` while the working-tree status is still loading. The hook also
54
+ * returns the no-path state while `kbDirName` is still null (workspace
55
+ * bootstrap in flight) so we don't fire a misclassified request before we
56
+ * know where the repo lives.
57
+ */
58
+ export function useFileAccess(
59
+ workspacePath: string | null,
60
+ branch: string | null,
61
+ ): FileAccessState {
62
+ const { workspaceId, kbDirName } = useWorkspace();
63
+ const [state, setState] = useState<FileAccessState>({
64
+ canWrite: null,
65
+ eligible: EMPTY_ELIGIBLE,
66
+ owners: EMPTY_ELIGIBLE,
67
+ loading: false,
68
+ error: null,
69
+ });
70
+
71
+ useEffect(() => {
72
+ if (!workspacePath || !kbDirName || !workspaceId) {
73
+ setState({ canWrite: null, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
74
+ return;
75
+ }
76
+ // Files outside the KB repo dir are the user's own workspace — never
77
+ // gated. Short-circuit before any network call so a misconfigured
78
+ // access tree can't lock users out of their own scratch files.
79
+ const prefix = `${kbDirName}/`;
80
+ if (!workspacePath.startsWith(prefix)) {
81
+ setState({ canWrite: true, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
82
+ return;
83
+ }
84
+ // Drafts are free-for-all (mirrors the backend's branch-protected gates
85
+ // in workflow/git.service.ts and workflow.service.ts). Skip the network
86
+ // call entirely so a slow/failed lookup never grays out the editor on a
87
+ // draft. `branch === null` is the bootstrap window before status loads;
88
+ // return canWrite=null so callers stay optimistic until we know.
89
+ if (branch === null) {
90
+ setState({ canWrite: null, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
91
+ return;
92
+ }
93
+ if (!isProtectedBranch(branch)) {
94
+ setState({ canWrite: true, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
95
+ return;
96
+ }
97
+
98
+ let cancelled = false;
99
+ setState((s) => ({ ...s, loading: true, error: null }));
100
+ // Strip kbDirName/ so the backend resolver receives the repo-relative
101
+ // path it expects (`Knowledge/Foo.md`, not `knowledge-base/…`).
102
+ const repoRelative = workspacePath.slice(prefix.length);
103
+ fetchFileAccess(workspaceId, repoRelative)
104
+ .then((res) => {
105
+ if (cancelled) return;
106
+ setState({
107
+ canWrite: res.canWrite,
108
+ eligible: res.eligible,
109
+ owners: res.owners,
110
+ loading: false,
111
+ error: null,
112
+ });
113
+ })
114
+ .catch((err) => {
115
+ if (cancelled) return;
116
+ const msg = err instanceof Error ? err.message : String(err);
117
+ // Default-allow: transient API failures shouldn't trap users in a
118
+ // read-only editor. The backend will still refuse the save if they
119
+ // truly don't have access.
120
+ setState({
121
+ canWrite: true,
122
+ eligible: EMPTY_ELIGIBLE,
123
+ owners: EMPTY_ELIGIBLE,
124
+ loading: false,
125
+ error: msg,
126
+ });
127
+ });
128
+
129
+ return () => {
130
+ cancelled = true;
131
+ };
132
+ }, [workspaceId, workspacePath, kbDirName, branch]);
133
+
134
+ return state;
135
+ }
136
+
137
+ /**
138
+ * Render-helper for the "you don't have permission to edit this file" copy.
139
+ * Used by the AccessRestrictedBanner and as a tooltip on disabled save
140
+ * buttons.
141
+ */
142
+ export function formatEligible(eligible: AccessEligible): string {
143
+ const parts: string[] = [];
144
+ if (eligible.roles.length) parts.push(eligible.roles.join(', '));
145
+ if (eligible.users.length) {
146
+ parts.push(
147
+ eligible.users.map((u) => (u.name ? `${u.name} (${u.email})` : u.email)).join(', '),
148
+ );
149
+ }
150
+ return parts.join('; ') || 'no one';
151
+ }