@bevel-software/platform-core-frontend 0.4.0 → 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,129 +1,129 @@
1
- import {
2
- createContext,
3
- useCallback,
4
- useContext,
5
- useMemo,
6
- useRef,
7
- useState,
8
- type ReactNode,
9
- } from 'react';
10
-
11
- /**
12
- * The loadout — the skills and integrations this user has explicitly
13
- * activated (Hearthstone-deck-tracker sidebar in the approved mock).
14
- *
15
- * DELIBERATE STUB: there is no backend for per-user skill activation yet, so
16
- * the loadout lives client-side in localStorage under
17
- * `bevel-library-loadout-v1`. It survives reloads on this browser but does not
18
- * roam across devices and nothing server-side consumes it yet. When a backend
19
- * feature lands (e.g. the MCP session registering only loadout tools), this
20
- * provider is the single place to swap the persistence.
21
- */
22
-
23
- export const LOADOUT_STORAGE_KEY = 'bevel-library-loadout-v1';
24
-
25
- export type LoadoutKind = 'skill' | 'integration';
26
-
27
- interface LoadoutState {
28
- skills: string[];
29
- integrations: string[];
30
- }
31
-
32
- export interface LoadoutContextValue {
33
- skills: string[];
34
- integrations: string[];
35
- total: number;
36
- isIn(kind: LoadoutKind, id: string): boolean;
37
- /** Toggle membership; returns true when the item was ADDED. */
38
- toggle(kind: LoadoutKind, id: string): boolean;
39
- remove(kind: LoadoutKind, id: string): void;
40
- }
41
-
42
- const LoadoutContext = createContext<LoadoutContextValue | null>(null);
43
-
44
- function load(): LoadoutState {
45
- try {
46
- const raw = localStorage.getItem(LOADOUT_STORAGE_KEY);
47
- if (!raw) return { skills: [], integrations: [] };
48
- const parsed = JSON.parse(raw) as Partial<LoadoutState>;
49
- return {
50
- skills: Array.isArray(parsed.skills) ? parsed.skills.filter((s) => typeof s === 'string') : [],
51
- integrations: Array.isArray(parsed.integrations)
52
- ? parsed.integrations.filter((s) => typeof s === 'string')
53
- : [],
54
- };
55
- } catch {
56
- return { skills: [], integrations: [] };
57
- }
58
- }
59
-
60
- function persist(state: LoadoutState): void {
61
- try {
62
- localStorage.setItem(LOADOUT_STORAGE_KEY, JSON.stringify(state));
63
- } catch {
64
- // Storage full/unavailable — the in-memory loadout still works this session.
65
- }
66
- }
67
-
68
- export function LoadoutProvider({ children }: { children: ReactNode }) {
69
- const [state, setState] = useState<LoadoutState>(load);
70
- // Ref mirror so two mutations in one React batch (e.g. add skill + add
71
- // integration from the same event) compose instead of clobbering each other.
72
- const current = useRef(state);
73
-
74
- const update = useCallback((next: LoadoutState) => {
75
- current.current = next;
76
- persist(next);
77
- setState(next);
78
- }, []);
79
-
80
- const isIn = useCallback(
81
- (kind: LoadoutKind, id: string) =>
82
- (kind === 'skill' ? state.skills : state.integrations).includes(id),
83
- [state],
84
- );
85
-
86
- const toggle = useCallback(
87
- (kind: LoadoutKind, id: string): boolean => {
88
- const prev = current.current;
89
- const key = kind === 'skill' ? 'skills' : 'integrations';
90
- const list = prev[key];
91
- const added = !list.includes(id);
92
- update({
93
- ...prev,
94
- [key]: added ? [...list, id] : list.filter((x) => x !== id),
95
- });
96
- return added;
97
- },
98
- [update],
99
- );
100
-
101
- const remove = useCallback(
102
- (kind: LoadoutKind, id: string) => {
103
- const prev = current.current;
104
- const key = kind === 'skill' ? 'skills' : 'integrations';
105
- update({ ...prev, [key]: prev[key].filter((x) => x !== id) });
106
- },
107
- [update],
108
- );
109
-
110
- const value = useMemo<LoadoutContextValue>(
111
- () => ({
112
- skills: state.skills,
113
- integrations: state.integrations,
114
- total: state.skills.length + state.integrations.length,
115
- isIn,
116
- toggle,
117
- remove,
118
- }),
119
- [state, isIn, toggle, remove],
120
- );
121
-
122
- return <LoadoutContext.Provider value={value}>{children}</LoadoutContext.Provider>;
123
- }
124
-
125
- export function useLoadout(): LoadoutContextValue {
126
- const ctx = useContext(LoadoutContext);
127
- if (!ctx) throw new Error('useLoadout must be used within LoadoutProvider');
128
- return ctx;
129
- }
1
+ import {
2
+ createContext,
3
+ useCallback,
4
+ useContext,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ type ReactNode,
9
+ } from 'react';
10
+
11
+ /**
12
+ * The loadout — the skills and integrations this user has explicitly
13
+ * activated (Hearthstone-deck-tracker sidebar in the approved mock).
14
+ *
15
+ * DELIBERATE STUB: there is no backend for per-user skill activation yet, so
16
+ * the loadout lives client-side in localStorage under
17
+ * `bevel-library-loadout-v1`. It survives reloads on this browser but does not
18
+ * roam across devices and nothing server-side consumes it yet. When a backend
19
+ * feature lands (e.g. the MCP session registering only loadout tools), this
20
+ * provider is the single place to swap the persistence.
21
+ */
22
+
23
+ export const LOADOUT_STORAGE_KEY = 'bevel-library-loadout-v1';
24
+
25
+ export type LoadoutKind = 'skill' | 'integration';
26
+
27
+ interface LoadoutState {
28
+ skills: string[];
29
+ integrations: string[];
30
+ }
31
+
32
+ export interface LoadoutContextValue {
33
+ skills: string[];
34
+ integrations: string[];
35
+ total: number;
36
+ isIn(kind: LoadoutKind, id: string): boolean;
37
+ /** Toggle membership; returns true when the item was ADDED. */
38
+ toggle(kind: LoadoutKind, id: string): boolean;
39
+ remove(kind: LoadoutKind, id: string): void;
40
+ }
41
+
42
+ const LoadoutContext = createContext<LoadoutContextValue | null>(null);
43
+
44
+ function load(): LoadoutState {
45
+ try {
46
+ const raw = localStorage.getItem(LOADOUT_STORAGE_KEY);
47
+ if (!raw) return { skills: [], integrations: [] };
48
+ const parsed = JSON.parse(raw) as Partial<LoadoutState>;
49
+ return {
50
+ skills: Array.isArray(parsed.skills) ? parsed.skills.filter((s) => typeof s === 'string') : [],
51
+ integrations: Array.isArray(parsed.integrations)
52
+ ? parsed.integrations.filter((s) => typeof s === 'string')
53
+ : [],
54
+ };
55
+ } catch {
56
+ return { skills: [], integrations: [] };
57
+ }
58
+ }
59
+
60
+ function persist(state: LoadoutState): void {
61
+ try {
62
+ localStorage.setItem(LOADOUT_STORAGE_KEY, JSON.stringify(state));
63
+ } catch {
64
+ // Storage full/unavailable — the in-memory loadout still works this session.
65
+ }
66
+ }
67
+
68
+ export function LoadoutProvider({ children }: { children: ReactNode }) {
69
+ const [state, setState] = useState<LoadoutState>(load);
70
+ // Ref mirror so two mutations in one React batch (e.g. add skill + add
71
+ // integration from the same event) compose instead of clobbering each other.
72
+ const current = useRef(state);
73
+
74
+ const update = useCallback((next: LoadoutState) => {
75
+ current.current = next;
76
+ persist(next);
77
+ setState(next);
78
+ }, []);
79
+
80
+ const isIn = useCallback(
81
+ (kind: LoadoutKind, id: string) =>
82
+ (kind === 'skill' ? state.skills : state.integrations).includes(id),
83
+ [state],
84
+ );
85
+
86
+ const toggle = useCallback(
87
+ (kind: LoadoutKind, id: string): boolean => {
88
+ const prev = current.current;
89
+ const key = kind === 'skill' ? 'skills' : 'integrations';
90
+ const list = prev[key];
91
+ const added = !list.includes(id);
92
+ update({
93
+ ...prev,
94
+ [key]: added ? [...list, id] : list.filter((x) => x !== id),
95
+ });
96
+ return added;
97
+ },
98
+ [update],
99
+ );
100
+
101
+ const remove = useCallback(
102
+ (kind: LoadoutKind, id: string) => {
103
+ const prev = current.current;
104
+ const key = kind === 'skill' ? 'skills' : 'integrations';
105
+ update({ ...prev, [key]: prev[key].filter((x) => x !== id) });
106
+ },
107
+ [update],
108
+ );
109
+
110
+ const value = useMemo<LoadoutContextValue>(
111
+ () => ({
112
+ skills: state.skills,
113
+ integrations: state.integrations,
114
+ total: state.skills.length + state.integrations.length,
115
+ isIn,
116
+ toggle,
117
+ remove,
118
+ }),
119
+ [state, isIn, toggle, remove],
120
+ );
121
+
122
+ return <LoadoutContext.Provider value={value}>{children}</LoadoutContext.Provider>;
123
+ }
124
+
125
+ export function useLoadout(): LoadoutContextValue {
126
+ const ctx = useContext(LoadoutContext);
127
+ if (!ctx) throw new Error('useLoadout must be used within LoadoutProvider');
128
+ return ctx;
129
+ }
@@ -1,116 +1,116 @@
1
- import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
-
3
- /**
4
- * Status derivation for the Library. Everything the cards, gems and loadout
5
- * rows show is computed from the secrets-vault browser surface
6
- * (`GET /api/secrets/tools` — see `tool-secrets.api.ts`), which exposes per
7
- * variable: adminConfigured / userConfigured / oauth / authorized /
8
- * needsReauth, plus per-tool `canWrite`. Design rule from the approved mock:
9
- * status is only shown when something needs attention — healthy items render
10
- * clean.
11
- */
12
-
13
- export type GemState = 'ok' | 'warn' | 'err' | 'off';
14
-
15
- export interface AttentionStatus {
16
- state: GemState;
17
- /** User-facing state line (glossary-compliant plain words). */
18
- text: string;
19
- }
20
-
21
- const OK: AttentionStatus = { state: 'ok', text: 'Connected' };
22
-
23
- /** Severity order for aggregation: broken sign-in > not set up > user action pending. */
24
- const RANK: Record<GemState, number> = { ok: 0, warn: 1, off: 2, err: 3 };
25
-
26
- function varStatus(v: ToolVarStatus, canWrite: boolean): AttentionStatus {
27
- if (v.oauth) {
28
- if (!v.adminConfigured) {
29
- return {
30
- state: 'off',
31
- text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
32
- };
33
- }
34
- if (v.authorized && v.needsReauth) return { state: 'err', text: 'Sign in again to keep this working' };
35
- if (!v.authorized) return { state: 'warn', text: 'Needs your sign-in' };
36
- return OK;
37
- }
38
- if (v.scope === 'user') {
39
- return v.userConfigured ? OK : { state: 'warn', text: 'Needs a key from you' };
40
- }
41
- return v.adminConfigured
42
- ? OK
43
- : {
44
- state: 'off',
45
- text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
46
- };
47
- }
48
-
49
- /** Aggregate connection state of one integration for the current user. */
50
- export function toolStatus(tool: ToolSecrets): AttentionStatus {
51
- let worst = OK;
52
- for (const v of tool.variables) {
53
- const s = varStatus(v, tool.canWrite);
54
- if (RANK[s.state] > RANK[worst.state]) worst = s;
55
- }
56
- return worst;
57
- }
58
-
59
- /** Per-variable status rows for the integration detail dialog. */
60
- export function toolVariableStatuses(tool: ToolSecrets): { v: ToolVarStatus; status: AttentionStatus }[] {
61
- return tool.variables.map((v) => ({ v, status: varStatus(v, tool.canWrite) }));
62
- }
63
-
64
- /**
65
- * Which integrations a skill needs, derived from the skill's `allowed-tools`
66
- * frontmatter. Entries are agent tool names, typically namespaced by the
67
- * manual (`slack_post_message`, `slack.slack_post_message`) or the bare manual
68
- * name; generic agent tools (`Bash`, `Read`) match no manual and are ignored.
69
- * Best-effort by design — there is no dedicated skill→integration link in the
70
- * backend contract today.
71
- */
72
- export function neededToolsFor(
73
- skill: { allowedTools?: string[] },
74
- tools: ToolSecrets[],
75
- ): ToolSecrets[] {
76
- const entries = (skill.allowedTools ?? []).map((e) => e.toLowerCase());
77
- if (entries.length === 0) return [];
78
- return tools.filter((t) => {
79
- const n = t.name.toLowerCase();
80
- return entries.some((e) => e === n || e.startsWith(`${n}_`) || e.startsWith(`${n}.`));
81
- });
82
- }
83
-
84
- /** A skill is ready when every integration it needs is fully connected. */
85
- export function skillStatus(neededTools: ToolSecrets[]): AttentionStatus {
86
- const broken = neededTools.some((t) => toolStatus(t).state !== 'ok');
87
- return broken ? { state: 'warn', text: 'Needs setup' } : { state: 'ok', text: 'Ready' };
88
- }
89
-
90
- /* ── gallery filtering ── */
91
-
92
- export type LibraryCategory = 'skills' | 'integrations' | 'owned';
93
-
94
- export interface LibraryFilterable {
95
- kind: 'skill' | 'integration';
96
- name: string;
97
- description: string;
98
- owned: boolean;
99
- }
100
-
101
- /** The chip + search filter from the mock: category narrows, query matches name/description. */
102
- export function filterLibraryItems<T extends LibraryFilterable>(
103
- items: T[],
104
- category: LibraryCategory,
105
- query: string,
106
- ): T[] {
107
- const q = query.trim().toLowerCase();
108
- return items.filter((item) => {
109
- if (q && !item.name.toLowerCase().includes(q) && !item.description.toLowerCase().includes(q)) {
110
- return false;
111
- }
112
- if (category === 'skills') return item.kind === 'skill';
113
- if (category === 'integrations') return item.kind === 'integration';
114
- return item.owned;
115
- });
116
- }
1
+ import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
+
3
+ /**
4
+ * Status derivation for the Library. Everything the cards, gems and loadout
5
+ * rows show is computed from the secrets-vault browser surface
6
+ * (`GET /api/secrets/tools` — see `tool-secrets.api.ts`), which exposes per
7
+ * variable: adminConfigured / userConfigured / oauth / authorized /
8
+ * needsReauth, plus per-tool `canWrite`. Design rule from the approved mock:
9
+ * status is only shown when something needs attention — healthy items render
10
+ * clean.
11
+ */
12
+
13
+ export type GemState = 'ok' | 'warn' | 'err' | 'off';
14
+
15
+ export interface AttentionStatus {
16
+ state: GemState;
17
+ /** User-facing state line (glossary-compliant plain words). */
18
+ text: string;
19
+ }
20
+
21
+ const OK: AttentionStatus = { state: 'ok', text: 'Connected' };
22
+
23
+ /** Severity order for aggregation: broken sign-in > not set up > user action pending. */
24
+ const RANK: Record<GemState, number> = { ok: 0, warn: 1, off: 2, err: 3 };
25
+
26
+ function varStatus(v: ToolVarStatus, canWrite: boolean): AttentionStatus {
27
+ if (v.oauth) {
28
+ if (!v.adminConfigured) {
29
+ return {
30
+ state: 'off',
31
+ text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
32
+ };
33
+ }
34
+ if (v.authorized && v.needsReauth) return { state: 'err', text: 'Sign in again to keep this working' };
35
+ if (!v.authorized) return { state: 'warn', text: 'Needs your sign-in' };
36
+ return OK;
37
+ }
38
+ if (v.scope === 'user') {
39
+ return v.userConfigured ? OK : { state: 'warn', text: 'Needs a key from you' };
40
+ }
41
+ return v.adminConfigured
42
+ ? OK
43
+ : {
44
+ state: 'off',
45
+ text: canWrite ? 'Not set up yet — you maintain this integration' : 'Not set up yet',
46
+ };
47
+ }
48
+
49
+ /** Aggregate connection state of one integration for the current user. */
50
+ export function toolStatus(tool: ToolSecrets): AttentionStatus {
51
+ let worst = OK;
52
+ for (const v of tool.variables) {
53
+ const s = varStatus(v, tool.canWrite);
54
+ if (RANK[s.state] > RANK[worst.state]) worst = s;
55
+ }
56
+ return worst;
57
+ }
58
+
59
+ /** Per-variable status rows for the integration detail dialog. */
60
+ export function toolVariableStatuses(tool: ToolSecrets): { v: ToolVarStatus; status: AttentionStatus }[] {
61
+ return tool.variables.map((v) => ({ v, status: varStatus(v, tool.canWrite) }));
62
+ }
63
+
64
+ /**
65
+ * Which integrations a skill needs, derived from the skill's `allowed-tools`
66
+ * frontmatter. Entries are agent tool names, typically namespaced by the
67
+ * manual (`slack_post_message`, `slack.slack_post_message`) or the bare manual
68
+ * name; generic agent tools (`Bash`, `Read`) match no manual and are ignored.
69
+ * Best-effort by design — there is no dedicated skill→integration link in the
70
+ * backend contract today.
71
+ */
72
+ export function neededToolsFor(
73
+ skill: { allowedTools?: string[] },
74
+ tools: ToolSecrets[],
75
+ ): ToolSecrets[] {
76
+ const entries = (skill.allowedTools ?? []).map((e) => e.toLowerCase());
77
+ if (entries.length === 0) return [];
78
+ return tools.filter((t) => {
79
+ const n = t.name.toLowerCase();
80
+ return entries.some((e) => e === n || e.startsWith(`${n}_`) || e.startsWith(`${n}.`));
81
+ });
82
+ }
83
+
84
+ /** A skill is ready when every integration it needs is fully connected. */
85
+ export function skillStatus(neededTools: ToolSecrets[]): AttentionStatus {
86
+ const broken = neededTools.some((t) => toolStatus(t).state !== 'ok');
87
+ return broken ? { state: 'warn', text: 'Needs setup' } : { state: 'ok', text: 'Ready' };
88
+ }
89
+
90
+ /* ── gallery filtering ── */
91
+
92
+ export type LibraryCategory = 'skills' | 'integrations' | 'owned';
93
+
94
+ export interface LibraryFilterable {
95
+ kind: 'skill' | 'integration';
96
+ name: string;
97
+ description: string;
98
+ owned: boolean;
99
+ }
100
+
101
+ /** The chip + search filter from the mock: category narrows, query matches name/description. */
102
+ export function filterLibraryItems<T extends LibraryFilterable>(
103
+ items: T[],
104
+ category: LibraryCategory,
105
+ query: string,
106
+ ): T[] {
107
+ const q = query.trim().toLowerCase();
108
+ return items.filter((item) => {
109
+ if (q && !item.name.toLowerCase().includes(q) && !item.description.toLowerCase().includes(q)) {
110
+ return false;
111
+ }
112
+ if (category === 'skills') return item.kind === 'skill';
113
+ if (category === 'integrations') return item.kind === 'integration';
114
+ return item.owned;
115
+ });
116
+ }