@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,62 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { diffLines, hasChanges } from '../utils/diff';
3
+
4
+ describe('diffLines (LCS line differ)', () => {
5
+ it('reports identical content as all-same', () => {
6
+ const d = diffLines('a\nb\nc', 'a\nb\nc');
7
+ expect(d).toEqual([
8
+ { kind: 'same', text: 'a' },
9
+ { kind: 'same', text: 'b' },
10
+ { kind: 'same', text: 'c' },
11
+ ]);
12
+ expect(hasChanges(d)).toBe(false);
13
+ });
14
+
15
+ it('marks a replaced line as removed-then-added in place', () => {
16
+ const d = diffLines('one\ntwo\nthree', 'one\nTWO\nthree');
17
+ expect(d).toEqual([
18
+ { kind: 'same', text: 'one' },
19
+ { kind: 'removed', text: 'two' },
20
+ { kind: 'added', text: 'TWO' },
21
+ { kind: 'same', text: 'three' },
22
+ ]);
23
+ });
24
+
25
+ it('handles pure insertions and deletions', () => {
26
+ expect(diffLines('a\nc', 'a\nb\nc')).toEqual([
27
+ { kind: 'same', text: 'a' },
28
+ { kind: 'added', text: 'b' },
29
+ { kind: 'same', text: 'c' },
30
+ ]);
31
+ expect(diffLines('a\nb\nc', 'a\nc')).toEqual([
32
+ { kind: 'same', text: 'a' },
33
+ { kind: 'removed', text: 'b' },
34
+ { kind: 'same', text: 'c' },
35
+ ]);
36
+ });
37
+
38
+ it('keeps unrelated equal lines matched across a multi-line rewrite', () => {
39
+ const before = '# title\nstep 1\nstep 2\nstep 3\nfooter';
40
+ const after = '# title\nstep 1 tightened\nstep 3\nnew step 4\nfooter';
41
+ const d = diffLines(before, after);
42
+ expect(d.filter((l) => l.kind === 'same').map((l) => l.text)).toEqual([
43
+ '# title',
44
+ 'step 3',
45
+ 'footer',
46
+ ]);
47
+ expect(d.filter((l) => l.kind === 'removed').map((l) => l.text)).toEqual([
48
+ 'step 1',
49
+ 'step 2',
50
+ ]);
51
+ expect(d.filter((l) => l.kind === 'added').map((l) => l.text)).toEqual([
52
+ 'step 1 tightened',
53
+ 'new step 4',
54
+ ]);
55
+ });
56
+
57
+ it('handles empty sides and trailing newlines', () => {
58
+ expect(diffLines('', 'a\n')).toEqual([{ kind: 'added', text: 'a' }]);
59
+ expect(diffLines('a\n', '')).toEqual([{ kind: 'removed', text: 'a' }]);
60
+ expect(diffLines('', '')).toEqual([]);
61
+ });
62
+ });
@@ -0,0 +1,72 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { renderHook, act } from '@testing-library/react';
3
+ import type { ReactNode } from 'react';
4
+ import { LoadoutProvider, useLoadout, LOADOUT_STORAGE_KEY } from '../state/loadout';
5
+
6
+ const wrapper = ({ children }: { children: ReactNode }) => (
7
+ <LoadoutProvider>{children}</LoadoutProvider>
8
+ );
9
+
10
+ describe('loadout (client-side stub)', () => {
11
+ it('starts empty and adds/removes on toggle', () => {
12
+ const { result } = renderHook(() => useLoadout(), { wrapper });
13
+ expect(result.current.total).toBe(0);
14
+
15
+ let added = false;
16
+ act(() => {
17
+ added = result.current.toggle('skill', 'newsletter');
18
+ });
19
+ expect(added).toBe(true);
20
+ expect(result.current.isIn('skill', 'newsletter')).toBe(true);
21
+ expect(result.current.total).toBe(1);
22
+
23
+ act(() => {
24
+ result.current.toggle('integration', 'slack');
25
+ });
26
+ expect(result.current.total).toBe(2);
27
+ expect(result.current.integrations).toEqual(['slack']);
28
+
29
+ act(() => {
30
+ added = result.current.toggle('skill', 'newsletter');
31
+ });
32
+ expect(added).toBe(false);
33
+ expect(result.current.isIn('skill', 'newsletter')).toBe(false);
34
+ expect(result.current.total).toBe(1);
35
+ });
36
+
37
+ it('remove drops only the targeted item', () => {
38
+ const { result } = renderHook(() => useLoadout(), { wrapper });
39
+ act(() => {
40
+ result.current.toggle('skill', 'a');
41
+ result.current.toggle('skill', 'b');
42
+ });
43
+ act(() => {
44
+ result.current.remove('skill', 'a');
45
+ });
46
+ expect(result.current.skills).toEqual(['b']);
47
+ });
48
+
49
+ it('persists to localStorage under bevel-library-loadout-v1 and survives a remount', () => {
50
+ const first = renderHook(() => useLoadout(), { wrapper });
51
+ act(() => {
52
+ first.result.current.toggle('skill', 'rfi');
53
+ first.result.current.toggle('integration', 'github');
54
+ });
55
+ const raw = localStorage.getItem(LOADOUT_STORAGE_KEY);
56
+ expect(raw).not.toBeNull();
57
+ expect(JSON.parse(raw!)).toEqual({ skills: ['rfi'], integrations: ['github'] });
58
+ first.unmount();
59
+
60
+ // A fresh provider (new session) reads the persisted loadout back.
61
+ const second = renderHook(() => useLoadout(), { wrapper });
62
+ expect(second.result.current.isIn('skill', 'rfi')).toBe(true);
63
+ expect(second.result.current.isIn('integration', 'github')).toBe(true);
64
+ expect(second.result.current.total).toBe(2);
65
+ });
66
+
67
+ it('tolerates corrupted stored state', () => {
68
+ localStorage.setItem(LOADOUT_STORAGE_KEY, '{not json');
69
+ const { result } = renderHook(() => useLoadout(), { wrapper });
70
+ expect(result.current.total).toBe(0);
71
+ });
72
+ });
@@ -0,0 +1,117 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
3
+ import {
4
+ filterLibraryItems,
5
+ neededToolsFor,
6
+ skillStatus,
7
+ toolStatus,
8
+ type LibraryFilterable,
9
+ } from '../utils/status';
10
+
11
+ function tool(overrides: Partial<ToolSecrets>): ToolSecrets {
12
+ return {
13
+ slug: 'slack',
14
+ name: 'slack',
15
+ path: 'Tools/slack.tool',
16
+ type: 'http',
17
+ setup: null,
18
+ canWrite: false,
19
+ variables: [],
20
+ ...overrides,
21
+ };
22
+ }
23
+
24
+ describe('toolStatus', () => {
25
+ it('is ok when every variable is satisfied', () => {
26
+ const t = tool({
27
+ variables: [
28
+ { name: 'API_KEY', scope: 'admin', label: null, key: 'slack_API_KEY', adminConfigured: true, userConfigured: false },
29
+ { name: 'TOKEN', scope: 'user', label: null, key: 'slack_TOKEN', adminConfigured: false, userConfigured: true },
30
+ ],
31
+ });
32
+ expect(toolStatus(t).state).toBe('ok');
33
+ });
34
+
35
+ it('flags a missing user sign-in as warn (oauth) and an expired one as err', () => {
36
+ const pending = tool({
37
+ variables: [
38
+ { name: 'SIGNIN', scope: 'user', label: null, key: 'k', adminConfigured: true, userConfigured: false, oauth: true, authorized: false },
39
+ ],
40
+ });
41
+ expect(toolStatus(pending)).toEqual({ state: 'warn', text: 'Needs your sign-in' });
42
+
43
+ const expired = tool({
44
+ variables: [
45
+ { name: 'SIGNIN', scope: 'user', label: null, key: 'k', adminConfigured: true, userConfigured: true, oauth: true, authorized: true, needsReauth: true },
46
+ ],
47
+ });
48
+ expect(toolStatus(expired).state).toBe('err');
49
+ });
50
+
51
+ it('flags a missing shared value as off (not set up yet)', () => {
52
+ const t = tool({
53
+ variables: [
54
+ { name: 'API_KEY', scope: 'admin', label: null, key: 'k', adminConfigured: false, userConfigured: false },
55
+ ],
56
+ });
57
+ expect(toolStatus(t)).toEqual({ state: 'off', text: 'Not set up yet' });
58
+ expect(toolStatus(tool({ ...t, canWrite: true })).text).toContain('you maintain');
59
+ });
60
+ });
61
+
62
+ describe('neededToolsFor / skillStatus', () => {
63
+ const slack = tool({ name: 'slack', slug: 'slack' });
64
+ const notion = tool({
65
+ name: 'notion',
66
+ slug: 'notion',
67
+ variables: [
68
+ { name: 'SIGNIN', scope: 'user', label: null, key: 'k', adminConfigured: true, userConfigured: false, oauth: true, authorized: false },
69
+ ],
70
+ });
71
+
72
+ it('matches manual-namespaced allowed-tools entries and ignores generic agent tools', () => {
73
+ const needed = neededToolsFor({ allowedTools: ['Bash', 'slack_post_message', 'notion.notion_search'] }, [slack, notion]);
74
+ expect(needed.map((t) => t.name)).toEqual(['slack', 'notion']);
75
+ expect(neededToolsFor({ allowedTools: ['Read', 'Bash'] }, [slack, notion])).toEqual([]);
76
+ });
77
+
78
+ it('skill is ready only when every needed integration is connected', () => {
79
+ expect(skillStatus([slack]).state).toBe('ok');
80
+ expect(skillStatus([slack, notion])).toEqual({ state: 'warn', text: 'Needs setup' });
81
+ expect(skillStatus([]).state).toBe('ok');
82
+ });
83
+ });
84
+
85
+ describe('filterLibraryItems (category chips + search)', () => {
86
+ const items: LibraryFilterable[] = [
87
+ { kind: 'skill', name: 'Weekly newsletter', description: 'drafts the Friday newsletter', owned: true },
88
+ { kind: 'skill', name: 'RFI responder', description: 'answers requests', owned: false },
89
+ { kind: 'integration', name: 'Slack', description: 'messages', owned: false },
90
+ { kind: 'integration', name: 'GitHub', description: 'code and change requests', owned: true },
91
+ ];
92
+
93
+ it('narrows by category', () => {
94
+ expect(filterLibraryItems(items, 'skills', '').map((i) => i.name)).toEqual([
95
+ 'Weekly newsletter',
96
+ 'RFI responder',
97
+ ]);
98
+ expect(filterLibraryItems(items, 'integrations', '').map((i) => i.name)).toEqual([
99
+ 'Slack',
100
+ 'GitHub',
101
+ ]);
102
+ expect(filterLibraryItems(items, 'owned', '').map((i) => i.name)).toEqual([
103
+ 'Weekly newsletter',
104
+ 'GitHub',
105
+ ]);
106
+ });
107
+
108
+ it('search matches name or description within the category, case-insensitively', () => {
109
+ expect(filterLibraryItems(items, 'skills', 'friday').map((i) => i.name)).toEqual([
110
+ 'Weekly newsletter',
111
+ ]);
112
+ expect(filterLibraryItems(items, 'integrations', 'CHANGE').map((i) => i.name)).toEqual([
113
+ 'GitHub',
114
+ ]);
115
+ expect(filterLibraryItems(items, 'skills', 'slack')).toEqual([]);
116
+ });
117
+ });
@@ -0,0 +1,47 @@
1
+ import type { PullRequestSummary } from '@bevel-software/platform-shared';
2
+
3
+ interface ChangeRequestDockProps {
4
+ crs: PullRequestSummary[];
5
+ onSelect(cr: PullRequestSummary): void;
6
+ }
7
+
8
+ /**
9
+ * Owner-only panel docked left of the detail dialog: a minimal name-list of
10
+ * the open change requests touching this skill — nothing else (approved
11
+ * design). Selecting one opens the side-by-side compare. Rendered `fixed`
12
+ * from inside the Dialog so it escapes the panel's overflow (the Dialog panel
13
+ * carries no transform, so fixed positioning stays viewport-relative).
14
+ */
15
+ export function ChangeRequestDock({ crs, onSelect }: ChangeRequestDockProps) {
16
+ return (
17
+ <div
18
+ className="lib-cr-dock fixed top-1/2 z-[55] flex max-h-[72vh] w-[232px] -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-[0_20px_60px_rgba(22,35,58,0.20)]"
19
+ style={{ right: 'calc(50% + 22.5rem)' }}
20
+ aria-label="Change requests for this skill"
21
+ >
22
+ <div className="flex items-center gap-2 px-4 pb-2.5 pt-3.5 text-[11px] font-bold uppercase tracking-[.08em] text-slate-500">
23
+ Change requests
24
+ <span className="rounded-full bg-[#e6f7f4] px-2 text-[10.5px] text-[#0f766e]">{crs.length}</span>
25
+ </div>
26
+ <div className="flex flex-col gap-2 overflow-y-auto px-2.5 pb-3">
27
+ {crs.length === 0 ? (
28
+ <div className="p-3 text-center text-xs text-slate-400">No open change requests</div>
29
+ ) : (
30
+ crs.map((cr) => (
31
+ <button
32
+ key={cr.number}
33
+ type="button"
34
+ className="rounded-[10px] border border-slate-200 bg-[#fafbfd] px-3 py-2.5 text-left text-[12.5px] font-semibold text-slate-700 transition-colors hover:border-[#7fd0c4]"
35
+ onClick={() => onSelect(cr)}
36
+ >
37
+ {cr.title}
38
+ <span className="mt-0.5 block text-[10px] font-normal text-slate-400">
39
+ {cr.appAuthor?.name ?? cr.author.name ?? cr.author.login}
40
+ </span>
41
+ </button>
42
+ ))
43
+ )}
44
+ </div>
45
+ </div>
46
+ );
47
+ }
@@ -0,0 +1,357 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+ import {
4
+ DEFAULT_BRANCH,
5
+ protectedBranchDisplayName,
6
+ type PullRequestDetail,
7
+ type PullRequestSummary,
8
+ } from '@bevel-software/platform-shared';
9
+ import { useModalLayer } from '../../../shared/components/useModalLayer';
10
+ import { useWorkspace } from '../../workspace/state/workspace.context';
11
+ import { kbFileUrl } from '../../workspace/routing/kb-routes';
12
+ import { fetchPrDetail } from '../../pr/services/pr-detail.api';
13
+ import { mergePullRequest } from '../../pr/services/pr-merge.api';
14
+ import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
15
+ import { postPrComment } from '../../pr/services/pr-comments.api';
16
+ import { readFileOnBranch, type LibrarySkill } from '../services/library.api';
17
+ import { diffLines, type DiffLine } from '../utils/diff';
18
+
19
+ interface CompareViewProps {
20
+ skill: LibrarySkill;
21
+ /** Content of a main-side file (SKILL.md body included), null while loading. */
22
+ mainContent(relFile: string): string | null;
23
+ loadMainFile(relFile: string): void;
24
+ cr: PullRequestSummary;
25
+ onClose(): void;
26
+ onResolved(kind: 'applied' | 'sent-back'): void;
27
+ }
28
+
29
+ /**
30
+ * Owner review = compare, not overlay: two panels side by side — left is the
31
+ * skill on the default branch, right is the change-request branch. Removed
32
+ * text tints red on the left, added text green on the right (via the module's
33
+ * line differ over real per-branch file contents); changed files get an amber
34
+ * dot in both lists, files new on the branch get a NEW row. Apply / Send back
35
+ * act through the existing change-request services. Esc exits the compare
36
+ * (registered as its own modal layer so the detail dialog beneath survives).
37
+ */
38
+ export function CompareView({
39
+ skill,
40
+ mainContent,
41
+ loadMainFile,
42
+ cr,
43
+ onClose,
44
+ onResolved,
45
+ }: CompareViewProps) {
46
+ const navigate = useNavigate();
47
+ const { kbDirName } = useWorkspace();
48
+ const [detail, setDetail] = useState<PullRequestDetail | null>(null);
49
+ const [error, setError] = useState<string | null>(null);
50
+ const [branchContents, setBranchContents] = useState<Record<string, string | null>>({});
51
+ const [busy, setBusy] = useState(false);
52
+ const [sendBackOpen, setSendBackOpen] = useState(false);
53
+ const [sendBackNote, setSendBackNote] = useState('');
54
+
55
+ const isTop = useModalLayer(true);
56
+ useEffect(() => {
57
+ function onKeyDown(e: KeyboardEvent) {
58
+ if (e.key === 'Escape' && isTop()) {
59
+ e.stopPropagation();
60
+ onClose();
61
+ }
62
+ }
63
+ document.addEventListener('keydown', onKeyDown);
64
+ return () => document.removeEventListener('keydown', onKeyDown);
65
+ }, [isTop, onClose]);
66
+
67
+ useEffect(() => {
68
+ let cancelled = false;
69
+ fetchPrDetail(cr.number)
70
+ .then((d) => {
71
+ if (!cancelled) setDetail(d);
72
+ })
73
+ .catch((err) => {
74
+ if (!cancelled) setError(err instanceof Error ? err.message : "Couldn't load this change request.");
75
+ });
76
+ return () => {
77
+ cancelled = true;
78
+ };
79
+ }, [cr.number]);
80
+
81
+ const prefix = `${skill.path}/`;
82
+ const mainFiles = useMemo(
83
+ () => ['SKILL.md', ...skill.files.map((f) => f.slice(prefix.length))],
84
+ [skill.files, prefix],
85
+ );
86
+ const changedFiles = useMemo(() => {
87
+ const set = new Set<string>();
88
+ for (const f of detail?.files ?? []) {
89
+ if (f.path.startsWith(prefix)) set.add(f.path.slice(prefix.length));
90
+ }
91
+ return set;
92
+ }, [detail, prefix]);
93
+ const addedFiles = useMemo(
94
+ () =>
95
+ (detail?.files ?? [])
96
+ .filter((f) => f.status === 'added' && f.path.startsWith(prefix))
97
+ .map((f) => f.path.slice(prefix.length)),
98
+ [detail, prefix],
99
+ );
100
+ const outsideCount = useMemo(
101
+ () => (detail?.files ?? []).filter((f) => !f.path.startsWith(prefix)).length,
102
+ [detail, prefix],
103
+ );
104
+ const branchFiles = useMemo(
105
+ () => [...mainFiles, ...addedFiles.filter((f) => !mainFiles.includes(f))],
106
+ [mainFiles, addedFiles],
107
+ );
108
+
109
+ // Land on the first changed (or added) file once the detail is in.
110
+ const [selected, setSelected] = useState<string>('SKILL.md');
111
+ const landed = useRef(false);
112
+ useEffect(() => {
113
+ if (!detail || landed.current) return;
114
+ landed.current = true;
115
+ const first = branchFiles.find((f) => changedFiles.has(f));
116
+ if (first) setSelected(first);
117
+ }, [detail, branchFiles, changedFiles]);
118
+
119
+ const loadBranchFile = useCallback(
120
+ (rel: string) => {
121
+ if (branchContents[rel] !== undefined) return;
122
+ setBranchContents((c) => ({ ...c, [rel]: null }));
123
+ readFileOnBranch(cr.branch, `${skill.path}/${rel}`)
124
+ .then((content) => setBranchContents((c) => ({ ...c, [rel]: content })))
125
+ .catch(() => setBranchContents((c) => ({ ...c, [rel]: '' })));
126
+ },
127
+ [branchContents, cr.branch, skill.path],
128
+ );
129
+
130
+ useEffect(() => {
131
+ loadBranchFile(selected);
132
+ if (!addedFiles.includes(selected)) loadMainFile(selected);
133
+ }, [selected, loadBranchFile, loadMainFile, addedFiles]);
134
+
135
+ const isAdded = addedFiles.includes(selected);
136
+ const mainRaw = isAdded ? null : mainContent(selected);
137
+ const branchRaw = branchContents[selected] ?? null;
138
+ const diff: DiffLine[] | null =
139
+ !isAdded && mainRaw !== null && branchRaw !== null ? diffLines(mainRaw, branchRaw) : null;
140
+
141
+ async function applyChanges() {
142
+ setBusy(true);
143
+ setError(null);
144
+ try {
145
+ await mergePullRequest(cr.number);
146
+ onResolved('applied');
147
+ } catch (err) {
148
+ setError(err instanceof Error ? err.message : "Couldn't apply this change request.");
149
+ setBusy(false);
150
+ }
151
+ }
152
+
153
+ async function sendBack() {
154
+ setBusy(true);
155
+ setError(null);
156
+ try {
157
+ const note = sendBackNote.trim();
158
+ if (note) await postPrComment(cr.number, { body: note });
159
+ await cancelPullRequest(cr.number);
160
+ onResolved('sent-back');
161
+ } catch (err) {
162
+ setError(err instanceof Error ? err.message : "Couldn't send this change request back.");
163
+ setBusy(false);
164
+ }
165
+ }
166
+
167
+ const fileRow = (rel: string, side: 'main' | 'branch') => {
168
+ const added = addedFiles.includes(rel);
169
+ const active = selected === rel;
170
+ return (
171
+ <button
172
+ key={rel}
173
+ type="button"
174
+ className={`flex w-full items-center gap-2 rounded-[9px] border px-2.5 py-1.5 text-left transition-colors ${
175
+ active
176
+ ? 'border-[#0d9488] bg-[#e6f7f4]'
177
+ : added
178
+ ? 'border-[#a9e8cd] bg-[#f2fcf8] hover:border-[#7fd0c4]'
179
+ : 'border-slate-200 bg-[#fafbfd] hover:border-[#7fd0c4]'
180
+ }`}
181
+ onClick={() => setSelected(rel)}
182
+ >
183
+ <span className={`font-mono text-[11.5px] font-semibold ${active ? 'text-[#0f766e]' : 'text-slate-600'}`}>
184
+ {rel}
185
+ </span>
186
+ {rel === 'SKILL.md' && (
187
+ <span className="rounded-full bg-white px-1.5 text-[9.5px] font-bold tracking-[.04em] text-[#0f766e] shadow-[inset_0_0_0_1px_#d2e9e4]">
188
+ MAIN
189
+ </span>
190
+ )}
191
+ {added && side === 'branch' && (
192
+ <span className="rounded-full bg-[#e0f8ee] px-1.5 text-[9.5px] font-bold tracking-[.04em] text-[#0a8f60]">
193
+ NEW
194
+ </span>
195
+ )}
196
+ {!added && changedFiles.has(rel) && (
197
+ <span
198
+ className="h-[7px] w-[7px] shrink-0 rounded-full bg-[#f59e0b]"
199
+ title="Changed in this request"
200
+ />
201
+ )}
202
+ </button>
203
+ );
204
+ };
205
+
206
+ const lineView = (lines: DiffLine[] | null, raw: string | null, hide: 'added' | 'removed') => {
207
+ if (raw === null && lines === null) {
208
+ return <div className="p-3 text-xs text-slate-400">Loading…</div>;
209
+ }
210
+ const rendered = lines
211
+ ? lines.filter((l) => l.kind !== hide)
212
+ : (raw ?? '').split('\n').map((text) => ({ kind: 'same' as const, text }));
213
+ return (
214
+ <pre className="whitespace-pre-wrap break-words rounded-[13px] border border-slate-200 bg-[#f7f9fb] p-3 font-mono text-[11.5px] leading-relaxed text-slate-600">
215
+ {rendered.map((l, i) => (
216
+ <div
217
+ key={i}
218
+ className={
219
+ l.kind === 'removed'
220
+ ? 'lib-line-removed rounded px-1'
221
+ : l.kind === 'added'
222
+ ? 'lib-line-added rounded px-1'
223
+ : 'px-1'
224
+ }
225
+ >
226
+ {l.text || ' '}
227
+ </div>
228
+ ))}
229
+ </pre>
230
+ );
231
+ };
232
+
233
+ return (
234
+ <div className="fixed inset-0 z-[60]" role="dialog" aria-modal="true" aria-label={`Compare change request: ${cr.title}`}>
235
+ <div className="absolute inset-0 bg-slate-950/40" onClick={onClose} />
236
+ <div className="absolute inset-x-4 bottom-[5vh] top-[5vh] flex gap-3.5">
237
+ {/* left: the default branch */}
238
+ <section className="relative flex min-w-0 flex-1 flex-col overflow-hidden rounded-[20px] border border-slate-200 bg-white shadow-[0_30px_80px_rgba(22,35,58,0.30)]">
239
+ <div className="absolute left-6 right-6 top-0 h-[3px] rounded-full bg-gradient-to-r from-transparent via-[#10b981] to-transparent" />
240
+ <div className="flex items-center gap-3 px-5 pb-3 pt-5">
241
+ <div className="min-w-0">
242
+ <div className="truncate text-[17px] font-bold text-slate-800">{skill.name}</div>
243
+ <div className="text-[11px] uppercase tracking-[.08em] text-slate-400">
244
+ Skill · {protectedBranchDisplayName(DEFAULT_BRANCH)}
245
+ </div>
246
+ </div>
247
+ </div>
248
+ <div className="flex-1 overflow-y-auto px-5 pb-5">
249
+ <h4 className="mb-2 text-[10.5px] font-bold uppercase tracking-[.09em] text-slate-400">
250
+ Files on {protectedBranchDisplayName(DEFAULT_BRANCH)}
251
+ </h4>
252
+ <div className="mb-4 flex flex-col gap-1.5">{mainFiles.map((f) => fileRow(f, 'main'))}</div>
253
+ <h4 className="mb-2 font-mono text-[11px] text-slate-500">{selected}</h4>
254
+ {isAdded ? (
255
+ <div className="rounded-[13px] border border-dashed border-slate-200 p-4 text-center text-xs text-slate-400">
256
+ This file doesn't exist here yet
257
+ </div>
258
+ ) : (
259
+ lineView(diff, mainRaw, 'added')
260
+ )}
261
+ </div>
262
+ </section>
263
+
264
+ {/* right: the change-request branch */}
265
+ <section className="relative flex min-w-0 flex-1 flex-col overflow-hidden rounded-[20px] border border-slate-200 bg-white shadow-[0_30px_80px_rgba(22,35,58,0.30)]">
266
+ <div className="absolute left-6 right-6 top-0 h-[3px] rounded-full bg-gradient-to-r from-transparent via-[#0d9488] to-transparent" />
267
+ <div className="flex items-center gap-3 px-5 pb-3 pt-5">
268
+ <div className="min-w-0">
269
+ <div className="truncate text-[17px] font-bold text-slate-800">{cr.title}</div>
270
+ <div className="truncate text-[11px] text-slate-400">
271
+ <span className="font-mono">{cr.branch}</span>
272
+ {' · by '}
273
+ {cr.appAuthor?.name ?? cr.author.name ?? cr.author.login}
274
+ </div>
275
+ </div>
276
+ <div className="relative ml-auto flex shrink-0 items-center gap-2">
277
+ <button
278
+ type="button"
279
+ disabled={busy}
280
+ className="rounded-[10px] border border-[#f5c2c2] bg-[#fdecec] px-3.5 py-2 text-[12.5px] font-bold text-[#c53030] transition-transform hover:-translate-y-px disabled:opacity-60"
281
+ onClick={() => setSendBackOpen((o) => !o)}
282
+ >
283
+ Send back
284
+ </button>
285
+ <button
286
+ type="button"
287
+ disabled={busy}
288
+ className="rounded-[10px] bg-gradient-to-br from-[#0d9488] to-[#0f766e] px-3.5 py-2 text-[12.5px] font-bold text-white shadow-[0_4px_14px_rgba(13,148,136,0.22)] transition-transform hover:-translate-y-px disabled:opacity-60"
289
+ onClick={() => void applyChanges()}
290
+ >
291
+ {busy ? 'Working…' : 'Apply changes'}
292
+ </button>
293
+ <button
294
+ type="button"
295
+ aria-label="Close compare"
296
+ className="flex h-[30px] w-[30px] items-center justify-center rounded-full border border-slate-200 bg-white text-[13px] text-slate-500 hover:border-[#7fd0c4] hover:text-slate-800"
297
+ onClick={onClose}
298
+ >
299
+ ✕
300
+ </button>
301
+ {sendBackOpen && (
302
+ <div className="absolute right-0 top-full z-10 mt-2 w-72 rounded-[14px] border border-slate-200 bg-white p-3.5 shadow-[0_16px_44px_rgba(22,35,58,0.24)]">
303
+ <label className="block text-[10px] font-bold uppercase tracking-[.07em] text-slate-400">
304
+ Note for the author (optional)
305
+ <textarea
306
+ rows={3}
307
+ 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]"
308
+ value={sendBackNote}
309
+ onChange={(e) => setSendBackNote(e.target.value)}
310
+ />
311
+ </label>
312
+ <div className="mt-2 flex justify-end">
313
+ <button
314
+ type="button"
315
+ disabled={busy}
316
+ className="rounded-[10px] bg-[#fdecec] px-3.5 py-2 text-[12.5px] font-bold text-[#c53030] shadow-[inset_0_0_0_1px_#f3c4c4] disabled:opacity-60"
317
+ onClick={() => void sendBack()}
318
+ >
319
+ Send back
320
+ </button>
321
+ </div>
322
+ </div>
323
+ )}
324
+ </div>
325
+ </div>
326
+ {error && <div className="mx-5 mb-2 rounded-lg bg-[#fdecec] px-3 py-2 text-xs text-[#c53030]">{error}</div>}
327
+ <div className="flex-1 overflow-y-auto px-5 pb-5">
328
+ <h4 className="mb-2 text-[10.5px] font-bold uppercase tracking-[.09em] text-slate-400">
329
+ Files on this draft
330
+ {outsideCount > 0 && (
331
+ <span className="ml-2 normal-case tracking-normal text-[#6d28d9]">
332
+ +{outsideCount} file{outsideCount === 1 ? '' : 's'} outside this skill
333
+ </span>
334
+ )}
335
+ </h4>
336
+ <div className="mb-4 flex flex-col gap-1.5">{branchFiles.map((f) => fileRow(f, 'branch'))}</div>
337
+ <div className="mb-2 flex items-center justify-between">
338
+ <h4 className="font-mono text-[11px] text-slate-500">{selected}</h4>
339
+ <button
340
+ type="button"
341
+ className="rounded-lg bg-[#e0f8ee] px-3.5 py-1 text-[11.5px] font-bold text-[#0a8f60] shadow-[inset_0_0_0_1px_#a9e8cd] transition-transform hover:-translate-y-px"
342
+ onClick={() => {
343
+ if (kbDirName) {
344
+ navigate(kbFileUrl(cr.branch, `${kbDirName}/${skill.path}/${selected}`));
345
+ }
346
+ }}
347
+ >
348
+ Edit
349
+ </button>
350
+ </div>
351
+ {lineView(diff, branchRaw, 'removed')}
352
+ </div>
353
+ </section>
354
+ </div>
355
+ </div>
356
+ );
357
+ }