@bevel-software/platform-core-frontend 0.3.2 → 0.4.1

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 (30) hide show
  1. package/package.json +2 -2
  2. package/src/core/__tests__/ShellRoutes.test.tsx +95 -95
  3. package/src/lib/utils.ts +138 -138
  4. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +156 -156
  5. package/src/modules/admin/components/UserAccountsPage.tsx +353 -353
  6. package/src/modules/layout/components/MaintenanceOverlay.tsx +104 -104
  7. package/src/modules/library/__tests__/DetailDialog.test.tsx +200 -200
  8. package/src/modules/library/__tests__/loadout.test.tsx +72 -72
  9. package/src/modules/library/__tests__/status.test.ts +117 -117
  10. package/src/modules/library/components/ChangeRequestDock.tsx +47 -47
  11. package/src/modules/library/components/CompareView.tsx +357 -357
  12. package/src/modules/library/components/DetailDialog.tsx +566 -566
  13. package/src/modules/library/components/GearIcon.tsx +12 -12
  14. package/src/modules/library/components/LibraryCard.tsx +132 -132
  15. package/src/modules/library/components/LibraryPage.tsx +254 -254
  16. package/src/modules/library/components/LoadoutSidebar.tsx +156 -156
  17. package/src/modules/library/components/StatusGem.tsx +21 -21
  18. package/src/modules/library/components/SuggestChange.tsx +171 -171
  19. package/src/modules/library/components/particles.ts +50 -50
  20. package/src/modules/library/library.css +320 -320
  21. package/src/modules/library/state/loadout.tsx +129 -129
  22. package/src/modules/library/utils/status.ts +116 -116
  23. package/src/modules/secrets-vault/components/SecretsPage.tsx +276 -276
  24. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +51 -51
  25. package/src/modules/toolbar/components/AppSwitcher.tsx +108 -108
  26. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +548 -548
  27. package/src/modules/workspace/components/FileExplorer.tsx +1068 -1068
  28. package/src/modules/workspace/components/FileViewer.tsx +906 -906
  29. package/src/modules/workspace/utils/fileTree.ts +179 -179
  30. package/src/shared/components/PageShell.tsx +51 -51
@@ -1,179 +1,179 @@
1
- import {
2
- AGENTS_DIR,
3
- DATA_DIR,
4
- KNOWLEDGE_BASE_DIR,
5
- PIPELINES_DIR,
6
- SKILLS_DIR,
7
- TOOLS_DIR,
8
- type FileTreeEntry,
9
- } from '@bevel-software/platform-shared';
10
- import type { PendingEntry } from '../state/workspace.context';
11
-
12
- export const KB_ROOT_DIRS = new Set([
13
- KNOWLEDGE_BASE_DIR,
14
- DATA_DIR,
15
- AGENTS_DIR,
16
- PIPELINES_DIR,
17
- SKILLS_DIR,
18
- TOOLS_DIR,
19
- ]);
20
-
21
- /**
22
- * Descend past the workspace / KB-clone wrapper levels to the node that holds
23
- * the well-known KB root dirs (`KnowledgeBase/`, `Data/`, `Agents/`, …), or
24
- * null when the tree predates the split. Shared by the explorer's sectioning
25
- * and registry-contributed explorer items (e.g. the enterprise Graph view).
26
- */
27
- export function findKbRoot(node: FileTreeEntry | null): FileTreeEntry | null {
28
- if (!node?.children) return null;
29
- const holdsSplit = node.children.some(
30
- (c) => c.type === 'directory' && KB_ROOT_DIRS.has(c.name),
31
- );
32
- if (holdsSplit) return node;
33
- for (const child of node.children) {
34
- if (child.type === 'directory') {
35
- const found = findKbRoot(child);
36
- if (found) return found;
37
- }
38
- }
39
- return null;
40
- }
41
-
42
- function findEntryByPath(tree: FileTreeEntry | null, relativePath: string): FileTreeEntry | null {
43
- if (!tree) return null;
44
- if (tree.relativePath === relativePath) return tree;
45
- if (tree.children) {
46
- for (const child of tree.children) {
47
- const found = findEntryByPath(child, relativePath);
48
- if (found) return found;
49
- }
50
- }
51
- return null;
52
- }
53
-
54
- export function pathExistsInTree(tree: FileTreeEntry | null, relativePath: string): boolean {
55
- return findEntryByPath(tree, relativePath) !== null;
56
- }
57
-
58
- function collectFilesByBasename(tree: FileTreeEntry | null, basename: string, acc: string[]): void {
59
- if (!tree) return;
60
- if (tree.type === 'file' && tree.name === basename) acc.push(tree.relativePath);
61
- if (tree.children) {
62
- for (const child of tree.children) collectFilesByBasename(child, basename, acc);
63
- }
64
- }
65
-
66
- /**
67
- * Resolve a candidate path to a concrete workspace-relative path.
68
- * - Multi-segment candidates (contain `/`) must match an existing entry exactly.
69
- * - Single-segment candidates (e.g. `positioning.md`) also match if exactly one
70
- * file in the tree has that basename — handles agent shorthand after a full
71
- * path was already mentioned in the same turn. Ambiguous basenames stay null.
72
- */
73
- /**
74
- * Merge optimistic pending-upload entries into a server-sourced file tree
75
- * so the FileExplorer can render dropped/picked files within one frame of
76
- * the user's action — well before their server commits have echoed back.
77
- *
78
- * Pending entries whose paths already exist on the server are skipped (the
79
- * real entry wins). Missing parent directories along the way are
80
- * synthesized as directory entries so a single dropped file inside a brand
81
- * new folder renders the folder too.
82
- *
83
- * Returns a freshly-allocated tree; the input is not mutated. Children at
84
- * each level are re-sorted so synthesized entries appear in the same order
85
- * a server refresh would render them: directories first, then files,
86
- * alphabetical within each group.
87
- */
88
- export function mergePendingIntoTree(
89
- tree: FileTreeEntry,
90
- pending: Map<string, PendingEntry>,
91
- ): FileTreeEntry {
92
- if (pending.size === 0) return tree;
93
-
94
- const cloneNode = (node: FileTreeEntry): FileTreeEntry => ({
95
- name: node.name,
96
- relativePath: node.relativePath,
97
- type: node.type,
98
- children: node.children ? node.children.map(cloneNode) : undefined,
99
- });
100
- const root = cloneNode(tree);
101
-
102
- // Walk to (and create) the directory at `path`. Returns null if `path`
103
- // collides with an existing file along the way.
104
- const ensureDir = (path: string): FileTreeEntry | null => {
105
- if (!path || path === '.') return root;
106
- const parts = path.split('/');
107
- let node = root;
108
- for (let i = 0; i < parts.length; i++) {
109
- const segPath = parts.slice(0, i + 1).join('/');
110
- if (!node.children) node.children = [];
111
- let child = node.children.find((c) => c.relativePath === segPath);
112
- if (!child) {
113
- child = {
114
- name: parts[i],
115
- relativePath: segPath,
116
- type: 'directory',
117
- children: [],
118
- };
119
- node.children.push(child);
120
- } else if (child.type !== 'directory') {
121
- return null;
122
- } else if (!child.children) {
123
- child.children = [];
124
- }
125
- node = child;
126
- }
127
- return node;
128
- };
129
-
130
- for (const [fullPath, entry] of pending) {
131
- const parts = fullPath.split('/');
132
- const name = parts[parts.length - 1];
133
- const parentPath = parts.slice(0, -1).join('/');
134
- const parent = ensureDir(parentPath);
135
- if (!parent) continue;
136
- if (!parent.children) parent.children = [];
137
- if (parent.children.some((c) => c.relativePath === fullPath)) continue;
138
- parent.children.push({
139
- name,
140
- relativePath: fullPath,
141
- type: entry.type,
142
- children: entry.type === 'directory' ? [] : undefined,
143
- });
144
- }
145
-
146
- // Re-sort every level so synthesized entries appear in tree order.
147
- const sort = (node: FileTreeEntry) => {
148
- if (!node.children) return;
149
- node.children.sort((a, b) => {
150
- if (a.type !== b.type) return a.type === 'directory' ? -1 : 1;
151
- return a.name.localeCompare(b.name);
152
- });
153
- for (const c of node.children) sort(c);
154
- };
155
- sort(root);
156
-
157
- return root;
158
- }
159
-
160
- export function resolveWorkspacePath(tree: FileTreeEntry | null, candidate: string): string | null {
161
- if (!tree || !candidate) return null;
162
- // The agent may emit either raw paths (`Knowledge/0. Current Truth/x.md`) or
163
- // percent-encoded ones (`Knowledge/0.%20Current%20Truth/x.md`) — react-markdown
164
- // hands us whatever was inside the link destination, so decode defensively.
165
- let decoded = candidate;
166
- try {
167
- decoded = decodeURIComponent(candidate);
168
- } catch {
169
- // Malformed escape sequence — fall back to the raw candidate.
170
- }
171
- const normalized = decoded.trim().replace(/^\.\//, '').replace(/^\//, '');
172
- if (!normalized) return null;
173
- const entry = findEntryByPath(tree, normalized);
174
- if (entry?.type === 'file') return normalized;
175
- if (normalized.includes('/')) return null;
176
- const matches: string[] = [];
177
- collectFilesByBasename(tree, normalized, matches);
178
- return matches.length === 1 ? matches[0] : null;
179
- }
1
+ import {
2
+ AGENTS_DIR,
3
+ DATA_DIR,
4
+ KNOWLEDGE_BASE_DIR,
5
+ PIPELINES_DIR,
6
+ SKILLS_DIR,
7
+ TOOLS_DIR,
8
+ type FileTreeEntry,
9
+ } from '@bevel-software/platform-shared';
10
+ import type { PendingEntry } from '../state/workspace.context';
11
+
12
+ export const KB_ROOT_DIRS = new Set([
13
+ KNOWLEDGE_BASE_DIR,
14
+ DATA_DIR,
15
+ AGENTS_DIR,
16
+ PIPELINES_DIR,
17
+ SKILLS_DIR,
18
+ TOOLS_DIR,
19
+ ]);
20
+
21
+ /**
22
+ * Descend past the workspace / KB-clone wrapper levels to the node that holds
23
+ * the well-known KB root dirs (`KnowledgeBase/`, `Data/`, `Agents/`, …), or
24
+ * null when the tree predates the split. Shared by the explorer's sectioning
25
+ * and registry-contributed explorer items (e.g. the enterprise Graph view).
26
+ */
27
+ export function findKbRoot(node: FileTreeEntry | null): FileTreeEntry | null {
28
+ if (!node?.children) return null;
29
+ const holdsSplit = node.children.some(
30
+ (c) => c.type === 'directory' && KB_ROOT_DIRS.has(c.name),
31
+ );
32
+ if (holdsSplit) return node;
33
+ for (const child of node.children) {
34
+ if (child.type === 'directory') {
35
+ const found = findKbRoot(child);
36
+ if (found) return found;
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+
42
+ function findEntryByPath(tree: FileTreeEntry | null, relativePath: string): FileTreeEntry | null {
43
+ if (!tree) return null;
44
+ if (tree.relativePath === relativePath) return tree;
45
+ if (tree.children) {
46
+ for (const child of tree.children) {
47
+ const found = findEntryByPath(child, relativePath);
48
+ if (found) return found;
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+
54
+ export function pathExistsInTree(tree: FileTreeEntry | null, relativePath: string): boolean {
55
+ return findEntryByPath(tree, relativePath) !== null;
56
+ }
57
+
58
+ function collectFilesByBasename(tree: FileTreeEntry | null, basename: string, acc: string[]): void {
59
+ if (!tree) return;
60
+ if (tree.type === 'file' && tree.name === basename) acc.push(tree.relativePath);
61
+ if (tree.children) {
62
+ for (const child of tree.children) collectFilesByBasename(child, basename, acc);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Resolve a candidate path to a concrete workspace-relative path.
68
+ * - Multi-segment candidates (contain `/`) must match an existing entry exactly.
69
+ * - Single-segment candidates (e.g. `positioning.md`) also match if exactly one
70
+ * file in the tree has that basename — handles agent shorthand after a full
71
+ * path was already mentioned in the same turn. Ambiguous basenames stay null.
72
+ */
73
+ /**
74
+ * Merge optimistic pending-upload entries into a server-sourced file tree
75
+ * so the FileExplorer can render dropped/picked files within one frame of
76
+ * the user's action — well before their server commits have echoed back.
77
+ *
78
+ * Pending entries whose paths already exist on the server are skipped (the
79
+ * real entry wins). Missing parent directories along the way are
80
+ * synthesized as directory entries so a single dropped file inside a brand
81
+ * new folder renders the folder too.
82
+ *
83
+ * Returns a freshly-allocated tree; the input is not mutated. Children at
84
+ * each level are re-sorted so synthesized entries appear in the same order
85
+ * a server refresh would render them: directories first, then files,
86
+ * alphabetical within each group.
87
+ */
88
+ export function mergePendingIntoTree(
89
+ tree: FileTreeEntry,
90
+ pending: Map<string, PendingEntry>,
91
+ ): FileTreeEntry {
92
+ if (pending.size === 0) return tree;
93
+
94
+ const cloneNode = (node: FileTreeEntry): FileTreeEntry => ({
95
+ name: node.name,
96
+ relativePath: node.relativePath,
97
+ type: node.type,
98
+ children: node.children ? node.children.map(cloneNode) : undefined,
99
+ });
100
+ const root = cloneNode(tree);
101
+
102
+ // Walk to (and create) the directory at `path`. Returns null if `path`
103
+ // collides with an existing file along the way.
104
+ const ensureDir = (path: string): FileTreeEntry | null => {
105
+ if (!path || path === '.') return root;
106
+ const parts = path.split('/');
107
+ let node = root;
108
+ for (let i = 0; i < parts.length; i++) {
109
+ const segPath = parts.slice(0, i + 1).join('/');
110
+ if (!node.children) node.children = [];
111
+ let child = node.children.find((c) => c.relativePath === segPath);
112
+ if (!child) {
113
+ child = {
114
+ name: parts[i],
115
+ relativePath: segPath,
116
+ type: 'directory',
117
+ children: [],
118
+ };
119
+ node.children.push(child);
120
+ } else if (child.type !== 'directory') {
121
+ return null;
122
+ } else if (!child.children) {
123
+ child.children = [];
124
+ }
125
+ node = child;
126
+ }
127
+ return node;
128
+ };
129
+
130
+ for (const [fullPath, entry] of pending) {
131
+ const parts = fullPath.split('/');
132
+ const name = parts[parts.length - 1];
133
+ const parentPath = parts.slice(0, -1).join('/');
134
+ const parent = ensureDir(parentPath);
135
+ if (!parent) continue;
136
+ if (!parent.children) parent.children = [];
137
+ if (parent.children.some((c) => c.relativePath === fullPath)) continue;
138
+ parent.children.push({
139
+ name,
140
+ relativePath: fullPath,
141
+ type: entry.type,
142
+ children: entry.type === 'directory' ? [] : undefined,
143
+ });
144
+ }
145
+
146
+ // Re-sort every level so synthesized entries appear in tree order.
147
+ const sort = (node: FileTreeEntry) => {
148
+ if (!node.children) return;
149
+ node.children.sort((a, b) => {
150
+ if (a.type !== b.type) return a.type === 'directory' ? -1 : 1;
151
+ return a.name.localeCompare(b.name);
152
+ });
153
+ for (const c of node.children) sort(c);
154
+ };
155
+ sort(root);
156
+
157
+ return root;
158
+ }
159
+
160
+ export function resolveWorkspacePath(tree: FileTreeEntry | null, candidate: string): string | null {
161
+ if (!tree || !candidate) return null;
162
+ // The agent may emit either raw paths (`Knowledge/0. Current Truth/x.md`) or
163
+ // percent-encoded ones (`Knowledge/0.%20Current%20Truth/x.md`) — react-markdown
164
+ // hands us whatever was inside the link destination, so decode defensively.
165
+ let decoded = candidate;
166
+ try {
167
+ decoded = decodeURIComponent(candidate);
168
+ } catch {
169
+ // Malformed escape sequence — fall back to the raw candidate.
170
+ }
171
+ const normalized = decoded.trim().replace(/^\.\//, '').replace(/^\//, '');
172
+ if (!normalized) return null;
173
+ const entry = findEntryByPath(tree, normalized);
174
+ if (entry?.type === 'file') return normalized;
175
+ if (normalized.includes('/')) return null;
176
+ const matches: string[] = [];
177
+ collectFilesByBasename(tree, normalized, matches);
178
+ return matches.length === 1 ? matches[0] : null;
179
+ }
@@ -1,51 +1,51 @@
1
- import type { ReactNode } from 'react';
2
-
3
- const WIDTH_CLASS = {
4
- '3xl': 'max-w-3xl',
5
- '4xl': 'max-w-4xl',
6
- } as const;
7
-
8
- export type PageShellWidth = keyof typeof WIDTH_CLASS;
9
-
10
- /**
11
- * Minimal shared chrome for the shell's standalone routed pages (Secrets,
12
- * External agent access, Roles & Members): a full-height scrolling canvas
13
- * with a centered max-width column, a page-title row and a white content
14
- * card. Deliberately tiny — it mirrors the Tailwind idioms the tools
15
- * explorer page already uses; it is not a design system.
16
- *
17
- * `padded` drops the card's default padding for pages that own their inner
18
- * layout (e.g. a tab strip flush against the card's top edge).
19
- */
20
- export function PageShell({
21
- title,
22
- actions,
23
- width = '3xl',
24
- padded = true,
25
- children,
26
- }: {
27
- title: string;
28
- /** Rendered right-aligned in the title row (e.g. a refresh button). */
29
- actions?: ReactNode;
30
- width?: PageShellWidth;
31
- padded?: boolean;
32
- children: ReactNode;
33
- }) {
34
- return (
35
- <div className="h-full overflow-y-auto bg-slate-50">
36
- <div className={`${WIDTH_CLASS[width]} mx-auto px-6 py-8`}>
37
- <header className="mb-4 flex items-center justify-between gap-3">
38
- <h1 className="text-lg font-semibold text-slate-800">{title}</h1>
39
- {actions && <div className="flex items-center gap-2">{actions}</div>}
40
- </header>
41
- <section
42
- className={`bg-white border border-slate-200 rounded-lg ${
43
- padded ? 'p-4' : 'overflow-hidden'
44
- }`}
45
- >
46
- {children}
47
- </section>
48
- </div>
49
- </div>
50
- );
51
- }
1
+ import type { ReactNode } from 'react';
2
+
3
+ const WIDTH_CLASS = {
4
+ '3xl': 'max-w-3xl',
5
+ '4xl': 'max-w-4xl',
6
+ } as const;
7
+
8
+ export type PageShellWidth = keyof typeof WIDTH_CLASS;
9
+
10
+ /**
11
+ * Minimal shared chrome for the shell's standalone routed pages (Secrets,
12
+ * External agent access, Roles & Members): a full-height scrolling canvas
13
+ * with a centered max-width column, a page-title row and a white content
14
+ * card. Deliberately tiny — it mirrors the Tailwind idioms the tools
15
+ * explorer page already uses; it is not a design system.
16
+ *
17
+ * `padded` drops the card's default padding for pages that own their inner
18
+ * layout (e.g. a tab strip flush against the card's top edge).
19
+ */
20
+ export function PageShell({
21
+ title,
22
+ actions,
23
+ width = '3xl',
24
+ padded = true,
25
+ children,
26
+ }: {
27
+ title: string;
28
+ /** Rendered right-aligned in the title row (e.g. a refresh button). */
29
+ actions?: ReactNode;
30
+ width?: PageShellWidth;
31
+ padded?: boolean;
32
+ children: ReactNode;
33
+ }) {
34
+ return (
35
+ <div className="h-full overflow-y-auto bg-slate-50">
36
+ <div className={`${WIDTH_CLASS[width]} mx-auto px-6 py-8`}>
37
+ <header className="mb-4 flex items-center justify-between gap-3">
38
+ <h1 className="text-lg font-semibold text-slate-800">{title}</h1>
39
+ {actions && <div className="flex items-center gap-2">{actions}</div>}
40
+ </header>
41
+ <section
42
+ className={`bg-white border border-slate-200 rounded-lg ${
43
+ padded ? 'p-4' : 'overflow-hidden'
44
+ }`}
45
+ >
46
+ {children}
47
+ </section>
48
+ </div>
49
+ </div>
50
+ );
51
+ }