@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,171 @@
1
+ import { useEffect, useRef, useState, type RefObject } from 'react';
2
+
3
+ interface SuggestChangeProps {
4
+ /** The file-viewer element whose text selections trigger the chip. */
5
+ containerRef: RefObject<HTMLElement | null>;
6
+ /** Raw content of the file on screen (selection must occur in it verbatim). */
7
+ raw: string | null;
8
+ /** Commit the suggestion; resolves when it landed on the suggestion branch. */
9
+ onSubmit(find: string, replace: string, note: string): Promise<void>;
10
+ }
11
+
12
+ interface ChipState {
13
+ text: string;
14
+ left: number;
15
+ top: number;
16
+ }
17
+
18
+ /**
19
+ * Select-text → "Suggest a change" chip → small form. The selection must be a
20
+ * single-line stretch that appears verbatim in the raw file content (rendered
21
+ * markdown can differ from source — same guard as the approved mock).
22
+ */
23
+ export function SuggestChange({ containerRef, raw, onSubmit }: SuggestChangeProps) {
24
+ const [chip, setChip] = useState<ChipState | null>(null);
25
+ const [form, setForm] = useState<ChipState | null>(null);
26
+ const [replaceValue, setReplaceValue] = useState('');
27
+ const [note, setNote] = useState('');
28
+ const [busy, setBusy] = useState(false);
29
+ const [error, setError] = useState<string | null>(null);
30
+ const rootRef = useRef<HTMLDivElement>(null);
31
+
32
+ useEffect(() => {
33
+ function onMouseUp(e: MouseEvent) {
34
+ if (rootRef.current?.contains(e.target as Node)) return;
35
+ const sel = window.getSelection();
36
+ const text = sel?.toString().trim() ?? '';
37
+ const container = containerRef.current;
38
+ if (
39
+ !container ||
40
+ !sel ||
41
+ sel.rangeCount === 0 ||
42
+ !sel.anchorNode ||
43
+ !container.contains(sel.anchorNode) ||
44
+ text.length <= 2 ||
45
+ text.includes('\n')
46
+ ) {
47
+ setChip(null);
48
+ return;
49
+ }
50
+ const r = sel.getRangeAt(0).getBoundingClientRect();
51
+ setChip({
52
+ text,
53
+ left: Math.max(8, r.left + r.width / 2 - 70),
54
+ top: Math.max(8, r.top - 40),
55
+ });
56
+ }
57
+ document.addEventListener('mouseup', onMouseUp);
58
+ return () => document.removeEventListener('mouseup', onMouseUp);
59
+ }, [containerRef]);
60
+
61
+ useEffect(() => {
62
+ function onKeyDown(e: KeyboardEvent) {
63
+ if (e.key === 'Escape' && (form || chip)) {
64
+ e.stopPropagation();
65
+ setForm(null);
66
+ setChip(null);
67
+ }
68
+ }
69
+ if (!form && !chip) return;
70
+ document.addEventListener('keydown', onKeyDown, true);
71
+ return () => document.removeEventListener('keydown', onKeyDown, true);
72
+ }, [form, chip]);
73
+
74
+ async function submit() {
75
+ if (!form) return;
76
+ const replace = replaceValue.trim();
77
+ if (!replace || replace === form.text) {
78
+ setForm(null);
79
+ return;
80
+ }
81
+ if (raw !== null && !raw.includes(form.text)) {
82
+ setError('Select a plain stretch of text to suggest on.');
83
+ return;
84
+ }
85
+ setBusy(true);
86
+ setError(null);
87
+ try {
88
+ await onSubmit(form.text, replace, note.trim());
89
+ setForm(null);
90
+ window.getSelection()?.removeAllRanges();
91
+ } catch (err) {
92
+ setError(err instanceof Error ? err.message : "Couldn't save your suggestion.");
93
+ } finally {
94
+ setBusy(false);
95
+ }
96
+ }
97
+
98
+ return (
99
+ <div ref={rootRef}>
100
+ {chip && !form && (
101
+ <button
102
+ type="button"
103
+ className="fixed z-[85] flex items-center gap-1.5 rounded-full bg-slate-800 px-3.5 py-1.5 text-xs font-semibold text-white shadow-[0_8px_24px_rgba(22,35,58,0.32)] hover:bg-slate-700"
104
+ style={{ left: chip.left, top: chip.top }}
105
+ onClick={() => {
106
+ setForm(chip);
107
+ setReplaceValue(chip.text);
108
+ setNote('');
109
+ setError(null);
110
+ setChip(null);
111
+ }}
112
+ >
113
+ Suggest a change
114
+ </button>
115
+ )}
116
+ {form && (
117
+ <div
118
+ className="fixed z-[85] w-[290px] rounded-[14px] border border-slate-200 bg-white p-4 shadow-[0_16px_44px_rgba(22,35,58,0.24)]"
119
+ style={{
120
+ left: Math.min(Math.max(8, form.left), window.innerWidth - 300),
121
+ top: Math.min(Math.max(8, form.top + 34), window.innerHeight - 260),
122
+ }}
123
+ role="dialog"
124
+ aria-label="Suggest a change"
125
+ >
126
+ <h5 className="mb-2 text-[12.5px] font-bold text-slate-800">Suggest a change</h5>
127
+ <div className="mb-1 max-h-[58px] overflow-auto rounded-md bg-[#fdecec] px-2 py-1 font-mono text-[11px] text-[#b91c1c] line-through">
128
+ {form.text}
129
+ </div>
130
+ <label className="mb-1 mt-2 block text-[10px] font-bold uppercase tracking-[.07em] text-slate-400">
131
+ Your version
132
+ <textarea
133
+ rows={3}
134
+ className="mt-1 w-full resize-y rounded-lg border border-slate-200 px-2 py-1.5 text-xs font-normal normal-case tracking-normal text-slate-800 outline-none focus:border-[#0d9488]"
135
+ value={replaceValue}
136
+ onChange={(e) => setReplaceValue(e.target.value)}
137
+ />
138
+ </label>
139
+ <label className="mb-1 mt-2 block text-[10px] font-bold uppercase tracking-[.07em] text-slate-400">
140
+ Note (optional)
141
+ <input
142
+ className="mt-1 w-full rounded-lg border border-slate-200 px-2 py-1.5 text-xs font-normal normal-case tracking-normal text-slate-800 outline-none focus:border-[#0d9488]"
143
+ placeholder="Why this change?"
144
+ value={note}
145
+ onChange={(e) => setNote(e.target.value)}
146
+ />
147
+ </label>
148
+ {error && <div className="mt-1 text-[11px] text-[#c53030]">{error}</div>}
149
+ <div className="mt-3 flex justify-end gap-2">
150
+ <button
151
+ type="button"
152
+ className="rounded-[10px] border border-slate-200 px-3.5 py-2 text-[12.5px] font-semibold text-slate-500 hover:text-slate-800"
153
+ onClick={() => setForm(null)}
154
+ disabled={busy}
155
+ >
156
+ Cancel
157
+ </button>
158
+ <button
159
+ type="button"
160
+ className="rounded-[10px] bg-gradient-to-br from-[#0d9488] to-[#0f766e] px-4 py-2 text-[12.5px] font-bold text-white shadow-[0_4px_14px_rgba(13,148,136,0.22)] disabled:opacity-60"
161
+ onClick={() => void submit()}
162
+ disabled={busy}
163
+ >
164
+ {busy ? 'Saving…' : 'Suggest'}
165
+ </button>
166
+ </div>
167
+ </div>
168
+ )}
169
+ </div>
170
+ );
171
+ }
@@ -0,0 +1,50 @@
1
+ import type { LoadoutKind } from '../state/loadout';
2
+
3
+ /**
4
+ * Particle flight from a card to its freshly-landed loadout row (Web
5
+ * Animations API, ~14 particles, green for skills / teal for integrations) —
6
+ * straight from the approved mock. Called after the add re-render; looks the
7
+ * row up by its `data-loadout-key` and quietly no-ops if it isn't there
8
+ * (e.g. reduced test DOM).
9
+ */
10
+ export function flyParticles(fromRect: DOMRect, kind: LoadoutKind, id: string): void {
11
+ requestAnimationFrame(() => {
12
+ const row = document.querySelector<HTMLElement>(
13
+ `[data-loadout-key="${CSS.escape(`${kind}:${id}`)}"]`,
14
+ );
15
+ if (!row) return;
16
+ row.classList.add('lib-slot-arrive');
17
+ const to = row.getBoundingClientRect();
18
+ const sx = fromRect.left + fromRect.width / 2;
19
+ const sy = fromRect.top + fromRect.height / 2;
20
+ const ex = to.left + to.width / 2;
21
+ const ey = to.top + to.height / 2;
22
+ for (let i = 0; i < 14; i++) {
23
+ const p = document.createElement('div');
24
+ p.className = 'lib-particle' + (kind === 'integration' ? ' lib-particle-tool' : '');
25
+ const size = 4 + Math.random() * 5;
26
+ p.style.width = `${size}px`;
27
+ p.style.height = `${size}px`;
28
+ document.body.appendChild(p);
29
+ // Start scattered across the card, arc upward toward the row.
30
+ const jx = sx + (Math.random() - 0.5) * fromRect.width * 0.7;
31
+ const jy = sy + (Math.random() - 0.5) * fromRect.height * 0.6;
32
+ const mx = (jx + ex) / 2 + (Math.random() - 0.5) * 120;
33
+ const my = (jy + ey) / 2 - (50 + Math.random() * 90);
34
+ const animation = p.animate(
35
+ [
36
+ { transform: `translate(${jx}px,${jy}px) scale(1)`, opacity: 1 },
37
+ { transform: `translate(${mx}px,${my}px) scale(.9)`, opacity: 0.95, offset: 0.55 },
38
+ { transform: `translate(${ex}px,${ey}px) scale(.2)`, opacity: 0 },
39
+ ],
40
+ {
41
+ duration: 480 + Math.random() * 280,
42
+ delay: Math.random() * 100,
43
+ easing: 'cubic-bezier(.3,.1,.3,1)',
44
+ fill: 'forwards',
45
+ },
46
+ );
47
+ animation.onfinish = () => p.remove();
48
+ }
49
+ });
50
+ }
@@ -0,0 +1,119 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import type { PullRequestSummary } from '@bevel-software/platform-shared';
3
+ import { fetchFileAccessBatch } from '../../access/api';
4
+ import { listToolSecrets, type ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
5
+ import {
6
+ DEFAULT_WORKSPACE_ID,
7
+ getSkill,
8
+ listMyChangeRequests,
9
+ listOpenChangeRequests,
10
+ listSkills,
11
+ type LibrarySkillSummary,
12
+ } from '../services/library.api';
13
+
14
+ /**
15
+ * All the list-level data the Library gallery needs, loaded in parallel:
16
+ *
17
+ * - skills — `GET /api/skills` (default-branch catalog, canRead-filtered)
18
+ * - tools — `GET /api/secrets/tools` (variables + per-user config status
19
+ * + per-tool `canWrite`)
20
+ * - ownership — "owned by me" = write access on the skill's `SKILL.md`
21
+ * (`POST /workspace/:id/access/batch` on the default-branch
22
+ * workspace); tools reuse the `canWrite` the secrets route
23
+ * already computes
24
+ * - change requests — all open + the caller's own, for the review layer
25
+ *
26
+ * Non-critical failures degrade to empty sets rather than blocking the page —
27
+ * only the skills+tools pair failing surfaces as a load error.
28
+ */
29
+ export interface LibraryData {
30
+ loading: boolean;
31
+ error: string | null;
32
+ skills: LibrarySkillSummary[];
33
+ tools: ToolSecrets[];
34
+ /** Skill names (folder ids) whose SKILL.md the caller can write. */
35
+ ownedSkills: Set<string>;
36
+ /**
37
+ * Per-skill `allowed-tools` frontmatter (name → entries), used to derive
38
+ * which integrations a skill needs. Loaded via one `getSkill` per catalog
39
+ * entry — the browser skill surface has no bulk endpoint for frontmatter.
40
+ */
41
+ allowedToolsBySkill: Map<string, string[]>;
42
+ /** Open change requests, all authors. */
43
+ crs: PullRequestSummary[];
44
+ /** Numbers of the caller's own change requests. */
45
+ myCrNumbers: Set<number>;
46
+ reload(): void;
47
+ }
48
+
49
+ export function useLibraryData(): LibraryData {
50
+ const [state, setState] = useState<Omit<LibraryData, 'reload'>>({
51
+ loading: true,
52
+ error: null,
53
+ skills: [],
54
+ tools: [],
55
+ ownedSkills: new Set(),
56
+ allowedToolsBySkill: new Map(),
57
+ crs: [],
58
+ myCrNumbers: new Set(),
59
+ });
60
+ const [revision, setRevision] = useState(0);
61
+
62
+ useEffect(() => {
63
+ let cancelled = false;
64
+ setState((s) => ({ ...s, loading: true, error: null }));
65
+
66
+ (async () => {
67
+ const [skills, tools] = await Promise.all([listSkills(), listToolSecrets()]);
68
+
69
+ const [ownership, crs, mine, details] = await Promise.all([
70
+ skills.length
71
+ ? fetchFileAccessBatch(
72
+ DEFAULT_WORKSPACE_ID,
73
+ skills.map((s) => `${s.path}/SKILL.md`),
74
+ ).catch(() => ({ results: {} as Record<string, boolean> }))
75
+ : Promise.resolve({ results: {} as Record<string, boolean> }),
76
+ listOpenChangeRequests().catch(() => [] as PullRequestSummary[]),
77
+ listMyChangeRequests().catch(() => [] as PullRequestSummary[]),
78
+ Promise.all(
79
+ skills.map(
80
+ (s): Promise<[string, string[]]> =>
81
+ getSkill(s.name)
82
+ .then((d): [string, string[]] => [s.name, d.allowedTools ?? []])
83
+ .catch((): [string, string[]] => [s.name, []]),
84
+ ),
85
+ ),
86
+ ]);
87
+
88
+ if (cancelled) return;
89
+ const ownedSkills = new Set(
90
+ skills.filter((s) => ownership.results[`${s.path}/SKILL.md`] === true).map((s) => s.name),
91
+ );
92
+ setState({
93
+ loading: false,
94
+ error: null,
95
+ skills,
96
+ tools,
97
+ ownedSkills,
98
+ allowedToolsBySkill: new Map(details),
99
+ crs: crs.filter((c) => c.state === 'open'),
100
+ myCrNumbers: new Set(mine.map((c) => c.number)),
101
+ });
102
+ })().catch((err) => {
103
+ if (cancelled) return;
104
+ setState((s) => ({
105
+ ...s,
106
+ loading: false,
107
+ error: err instanceof Error ? err.message : "Couldn't load the library.",
108
+ }));
109
+ });
110
+
111
+ return () => {
112
+ cancelled = true;
113
+ };
114
+ }, [revision]);
115
+
116
+ const reload = useCallback(() => setRevision((r) => r + 1), []);
117
+
118
+ return { ...state, reload };
119
+ }
@@ -0,0 +1,74 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { getSkill, getSkillFile, type LibrarySkill } from '../services/library.api';
3
+
4
+ /**
5
+ * Detail-level data for one skill: the SKILL.md body + bundled file list on
6
+ * open, then bundled file contents on demand (cached per file for the dialog's
7
+ * lifetime). Mirrors the backend's progressive disclosure (`getSkill` →
8
+ * `getSkill(file)`).
9
+ */
10
+ export interface SkillDetailState {
11
+ skill: LibrarySkill | null;
12
+ loading: boolean;
13
+ error: string | null;
14
+ /** Content of a bundled file (relative to the skill folder), or null while loading. */
15
+ fileContent(relFile: string): string | null;
16
+ /** Kick off (or re-use) the fetch for a bundled file. */
17
+ loadFile(relFile: string): void;
18
+ }
19
+
20
+ export function useSkillDetail(name: string): SkillDetailState {
21
+ const [skill, setSkill] = useState<LibrarySkill | null>(null);
22
+ const [loading, setLoading] = useState(true);
23
+ const [error, setError] = useState<string | null>(null);
24
+ const [contents, setContents] = useState<Record<string, string>>({});
25
+ const inFlight = useRef<Set<string>>(new Set());
26
+
27
+ useEffect(() => {
28
+ let cancelled = false;
29
+ setSkill(null);
30
+ setContents({});
31
+ inFlight.current = new Set();
32
+ setLoading(true);
33
+ setError(null);
34
+ getSkill(name)
35
+ .then((s) => {
36
+ if (cancelled) return;
37
+ setSkill(s);
38
+ setLoading(false);
39
+ })
40
+ .catch((err) => {
41
+ if (cancelled) return;
42
+ setError(err instanceof Error ? err.message : "Couldn't load this skill.");
43
+ setLoading(false);
44
+ });
45
+ return () => {
46
+ cancelled = true;
47
+ };
48
+ }, [name]);
49
+
50
+ const loadFile = useCallback(
51
+ (relFile: string) => {
52
+ if (contents[relFile] !== undefined || inFlight.current.has(relFile)) return;
53
+ inFlight.current.add(relFile);
54
+ getSkillFile(name, relFile)
55
+ .then((content) => {
56
+ setContents((c) => ({ ...c, [relFile]: content }));
57
+ })
58
+ .catch(() => {
59
+ setContents((c) => ({ ...c, [relFile]: "Couldn't load this file." }));
60
+ })
61
+ .finally(() => {
62
+ inFlight.current.delete(relFile);
63
+ });
64
+ },
65
+ [name, contents],
66
+ );
67
+
68
+ const fileContent = useCallback(
69
+ (relFile: string) => contents[relFile] ?? null,
70
+ [contents],
71
+ );
72
+
73
+ return { skill, loading, error, fileContent, loadFile };
74
+ }