@bevel-software/platform-core-frontend 0.7.5 → 0.9.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 (132) hide show
  1. package/LICENSE +202 -202
  2. package/THIRD-PARTY-NOTICES.md +344 -988
  3. package/package.json +5 -5
  4. package/src/core/CoreAppShell.tsx +4 -4
  5. package/src/core/__tests__/ShellRoutes.test.tsx +1 -1
  6. package/src/core/__tests__/bootstrap.test.ts +47 -2
  7. package/src/core/bootstrap.ts +20 -0
  8. package/src/core/registry.ts +16 -4
  9. package/src/css-side-effect-imports.d.ts +7 -7
  10. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +1 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +5 -5
  12. package/src/modules/access/api.ts +5 -5
  13. package/src/modules/access/components/ManageAccessDialog.tsx +21 -20
  14. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  15. package/src/modules/admin/components/AdminRolesPage.tsx +1 -1
  16. package/src/modules/admin/state/admin.context.tsx +15 -0
  17. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +2 -2
  18. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
  19. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
  20. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +4 -4
  21. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +4 -4
  22. package/src/modules/layout/__tests__/breakpoints.test.ts +1 -1
  23. package/src/modules/layout/components/SidebarFrame.tsx +2 -2
  24. package/src/modules/library/__tests__/{AddToGroupDialog.test.tsx → AddToPluginDialog.test.tsx} +34 -34
  25. package/src/modules/library/__tests__/LibraryCard.test.tsx +30 -11
  26. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +84 -59
  27. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +51 -51
  28. package/src/modules/library/__tests__/{LockedGroupView.test.tsx → LockedPluginView.test.tsx} +33 -33
  29. package/src/modules/library/__tests__/McpServerSection.test.tsx +138 -0
  30. package/src/modules/library/__tests__/{NewGroupDialog.test.tsx → NewPluginDialog.test.tsx} +22 -22
  31. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +7 -7
  32. package/src/modules/library/__tests__/PluginExtras.test.tsx +131 -0
  33. package/src/modules/library/__tests__/{GroupJoinRequests.test.tsx → PluginJoinRequests.test.tsx} +24 -24
  34. package/src/modules/library/__tests__/{GroupPage.test.tsx → PluginPage.test.tsx} +197 -106
  35. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +363 -0
  36. package/src/modules/library/__tests__/{GroupsSidebar.contextmenu.test.tsx → PluginsSidebar.contextmenu.test.tsx} +32 -31
  37. package/src/modules/library/__tests__/{GroupsSidebar.locked.test.tsx → PluginsSidebar.locked.test.tsx} +29 -28
  38. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +171 -0
  39. package/src/modules/library/__tests__/{GroupsSidebarMenu.test.tsx → PluginsSidebarMenu.test.tsx} +18 -18
  40. package/src/modules/library/__tests__/SkillPage.test.tsx +8 -8
  41. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +2 -2
  42. package/src/modules/library/__tests__/ToolPage.test.tsx +41 -12
  43. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +1 -1
  44. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +57 -57
  45. package/src/modules/library/__tests__/auth-harness.tsx +4 -4
  46. package/src/modules/library/__tests__/library-data.test.ts +82 -0
  47. package/src/modules/library/__tests__/status.test.ts +19 -19
  48. package/src/modules/library/__tests__/tools.api.test.ts +70 -0
  49. package/src/modules/library/__tests__/useToolPage.test.tsx +4 -4
  50. package/src/modules/library/components/AccessRequestsBanner.tsx +8 -8
  51. package/src/modules/library/components/{AddToGroupDialog.tsx → AddToPluginDialog.tsx} +11 -11
  52. package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
  53. package/src/modules/library/components/{DeleteGroupDialog.tsx → DeletePluginDialog.tsx} +9 -9
  54. package/src/modules/library/components/LibraryCard.tsx +26 -2
  55. package/src/modules/library/components/LibraryLayout.tsx +80 -71
  56. package/src/modules/library/components/LibraryPage.tsx +8 -8
  57. package/src/modules/library/components/LockGlyph.tsx +1 -1
  58. package/src/modules/library/components/{LockedGroupView.tsx → LockedPluginView.tsx} +35 -35
  59. package/src/modules/library/components/{ManagedGroupRequests.tsx → ManagedPluginRequests.tsx} +13 -13
  60. package/src/modules/library/components/{NewGroupDialog.tsx → NewPluginDialog.tsx} +24 -24
  61. package/src/modules/library/components/NewSkillPanel.tsx +23 -5
  62. package/src/modules/library/components/PageActions.tsx +34 -11
  63. package/src/modules/library/components/PersonalAddDialog.tsx +5 -5
  64. package/src/modules/library/components/{PersonalGroupPage.tsx → PersonalPluginPage.tsx} +29 -19
  65. package/src/modules/library/components/PluginExtras.tsx +195 -0
  66. package/src/modules/library/components/{GroupIndexRow.tsx → PluginIndexRow.tsx} +6 -6
  67. package/src/modules/library/components/PluginJoinRequests.tsx +77 -0
  68. package/src/modules/library/components/{GroupPage.tsx → PluginPage.tsx} +112 -72
  69. package/src/modules/library/components/{GroupsIndexPage.tsx → PluginsIndexPage.tsx} +91 -48
  70. package/src/modules/library/components/{GroupsSidebar.tsx → PluginsSidebar.tsx} +105 -55
  71. package/src/modules/library/components/{GroupsSidebarMenu.tsx → PluginsSidebarMenu.tsx} +15 -15
  72. package/src/modules/library/components/{group-page-parts.tsx → plugin-page-parts.tsx} +218 -27
  73. package/src/modules/library/components/skill-page/SkillPage.tsx +12 -12
  74. package/src/modules/library/components/tool-page/McpServerSection.tsx +380 -0
  75. package/src/modules/library/components/tool-page/ToolPage.tsx +22 -5
  76. package/src/modules/library/hooks/useJoinRequests.ts +8 -8
  77. package/src/modules/library/routes/LibraryRoutes.tsx +32 -19
  78. package/src/modules/library/routes/WorkspaceItemRoute.tsx +24 -24
  79. package/src/modules/library/routes/library-paths.ts +36 -36
  80. package/src/modules/library/services/library.api.ts +9 -9
  81. package/src/modules/library/services/{groups.api.ts → plugins.api.ts} +43 -43
  82. package/src/modules/library/services/tools.api.ts +54 -0
  83. package/src/modules/library/state/library-data.tsx +67 -46
  84. package/src/modules/library/utils/names.ts +1 -1
  85. package/src/modules/library/utils/{personal-group.ts → personal-plugin.ts} +8 -8
  86. package/src/modules/library/utils/{group-summary.ts → plugin-summary.ts} +14 -14
  87. package/src/modules/library/utils/status.ts +17 -17
  88. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +318 -0
  89. package/src/modules/onboarding/__tests__/onboarding.test.tsx +86 -8
  90. package/src/modules/onboarding/agent-clients.ts +18 -14
  91. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +143 -0
  92. package/src/modules/onboarding/components/WelcomePage.tsx +30 -22
  93. package/src/modules/onboarding/components/WelcomeRoute.tsx +57 -0
  94. package/src/modules/onboarding/welcome-state.ts +36 -0
  95. package/src/modules/review/components/MarkdownDiffViewer.tsx +1 -1
  96. package/src/modules/review/components/ReviewPanel.tsx +11 -11
  97. package/src/modules/review/components/__tests__/{isGroupItemPath.test.ts → isPluginItemPath.test.ts} +24 -24
  98. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +3 -3
  99. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +1 -1
  100. package/src/modules/settings/components/SettingsLayout.tsx +1 -1
  101. package/src/modules/settings/components/SettingsNav.tsx +5 -5
  102. package/src/modules/setup/__tests__/setup.test.tsx +203 -0
  103. package/src/modules/setup/components/SetupScreen.tsx +235 -68
  104. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +29 -107
  105. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +1 -1
  106. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +228 -0
  107. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +3 -3
  108. package/src/modules/workspace/components/FileExplorer.tsx +12 -12
  109. package/src/modules/workspace/components/FileRoute.tsx +8 -1
  110. package/src/modules/workspace/components/FileViewer.tsx +95 -38
  111. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +14 -14
  112. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +20 -0
  113. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +227 -18
  114. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +7 -2
  115. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +25 -0
  116. package/src/modules/workspace/routing/kb-routes.ts +23 -1
  117. package/src/modules/workspace/utils/__tests__/diff.test.ts +1 -1
  118. package/src/modules/workspace/utils/fileTree.ts +54 -3
  119. package/src/shared/components/Surface.tsx +15 -0
  120. package/src/shared/mcp/ClaudeInstallLink.tsx +88 -0
  121. package/src/shared/mcp/ConnectionInstructions.tsx +51 -0
  122. package/src/shared/mcp/CopyBlock.tsx +42 -0
  123. package/src/shared/mcp/__tests__/ClaudeInstallLink.test.tsx +40 -0
  124. package/src/shared/mcp/__tests__/connect-snippets.test.ts +431 -0
  125. package/src/shared/mcp/__tests__/useCopyFeedback.test.ts +112 -0
  126. package/src/shared/mcp/connect-snippets.ts +353 -0
  127. package/src/shared/mcp/index.ts +28 -0
  128. package/src/shared/mcp/useCopyFeedback.ts +46 -0
  129. package/src/test-setup.ts +11 -0
  130. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +0 -283
  131. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +0 -142
  132. package/src/modules/library/components/GroupJoinRequests.tsx +0 -56
@@ -86,6 +86,31 @@ describe('useFileNav.openFile', () => {
86
86
  );
87
87
  });
88
88
 
89
+ it('treats # in a filename as part of the path when told it IS a path', () => {
90
+ navigateMock.mockClear();
91
+ const { result } = renderNav('alice/draft');
92
+ // `openFile` parses link-shaped input, so `#` means "anchor" there.
93
+ // `openWorkspacePath` is for real tree paths, where `#` is a character in
94
+ // a filename and must be encoded, not split off.
95
+ result.current.openWorkspacePath('knowledge-base/Knowledge/Q#A.md');
96
+ expect(navigateMock).toHaveBeenCalledWith(
97
+ '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Q%23A.md',
98
+ );
99
+ });
100
+
101
+ it('opens a tree path verbatim even when a folder inside it is named like the kbDirName', () => {
102
+ navigateMock.mockClear();
103
+ const { result } = renderNav('alice/draft');
104
+ // A tree whose root is not the KB dir, holding a folder that happens to be
105
+ // named like it. The junk-segment repair drops everything before that
106
+ // segment, rewriting this to `knowledge-base/notes.md` — a different file.
107
+ // A path that came from the tree is already correct and needs no repair.
108
+ result.current.openWorkspacePath('Knowledge/knowledge-base/notes.md');
109
+ expect(navigateMock).toHaveBeenCalledWith(
110
+ '/workspace/alice%2Fdraft/Knowledge/knowledge-base/notes.md',
111
+ );
112
+ });
113
+
89
114
  it('leaves a well-formed path untouched and ignores a kbDirName substring match', () => {
90
115
  navigateMock.mockClear();
91
116
  const { result } = renderNav('alice/draft');
@@ -218,12 +218,34 @@ export function useFileNav() {
218
218
  [branch, kbDirName, navigate],
219
219
  );
220
220
 
221
+ /**
222
+ * Navigate to a KNOWN workspace-relative path, verbatim. `openFile` parses
223
+ * link-shaped input — it splits off `#heading` anchors and unwraps absolute
224
+ * workspace URLs — which is right for hrefs and wrong for a path that came
225
+ * from the file tree, where `#` is just a character in a filename. Callers
226
+ * holding a real path (suggestions, explorers) use this; callers holding a
227
+ * link destination keep `openFile`.
228
+ *
229
+ * VERBATIM means verbatim: no `stripJunkBeforeKbDir` either. That repair
230
+ * exists for paths an LLM may have mangled, and it rewrites any path whose
231
+ * later segment happens to equal `kbDirName` — which a real folder inside
232
+ * the tree is allowed to be. A path that came from the tree needs no
233
+ * repair, so applying one could only ever open the wrong file.
234
+ */
235
+ const openWorkspacePath = useCallback(
236
+ (path: string) => {
237
+ if (!branch) return;
238
+ navigate(kbFileUrl(branch, path));
239
+ },
240
+ [branch, navigate],
241
+ );
242
+
221
243
  const closeFile = useCallback(() => {
222
244
  if (!branch) return;
223
245
  navigate(kbFileUrl(branch));
224
246
  }, [branch, navigate]);
225
247
 
226
- return { openFile, closeFile };
248
+ return { openFile, openWorkspacePath, closeFile };
227
249
  }
228
250
 
229
251
  /**
@@ -8,7 +8,7 @@ import { computeDiff } from '../diff';
8
8
  */
9
9
  describe('computeDiff', () => {
10
10
  it('emits removed before added within one change run', () => {
11
- // `groupDiffBlocks` in MarkdownDiffViewer bundles consecutive
11
+ // `pluginDiffBlocks` in MarkdownDiffViewer bundles consecutive
12
12
  // removed+added runs into one red/green block — interleaving would split
13
13
  // a single edit into several blocks.
14
14
  const out = computeDiff('a\nold line\nz', 'a\nnew line\nz');
@@ -3,13 +3,13 @@ import {
3
3
  DATA_DIR,
4
4
  KNOWLEDGE_BASE_DIR,
5
5
  PIPELINES_DIR,
6
- GROUPS_DIR,
6
+ PLUGINS_DIR,
7
7
  type FileTreeEntry,
8
8
  } from '@bevel-software/platform-shared';
9
9
  import type { PendingEntry } from '../state/workspace.context';
10
10
 
11
11
  // RESERVED is not the same as CREATED (see kb-layout.ts): core only seeds
12
- // KnowledgeBase/ and Groups/, but every reserved name renders as its own root
12
+ // KnowledgeBase/ and Plugins/, but every reserved name renders as its own root
13
13
  // when present — a distribution that owns the execution layer seeds Data/,
14
14
  // Agents/ and Pipelines/, and a KB that has them must not see them folded
15
15
  // into Knowledge as stray content.
@@ -18,7 +18,7 @@ export const KB_ROOT_DIRS = new Set([
18
18
  DATA_DIR,
19
19
  AGENTS_DIR,
20
20
  PIPELINES_DIR,
21
- GROUPS_DIR,
21
+ PLUGINS_DIR,
22
22
  ]);
23
23
 
24
24
  /**
@@ -42,6 +42,57 @@ export function findKbRoot(node: FileTreeEntry | null): FileTreeEntry | null {
42
42
  return null;
43
43
  }
44
44
 
45
+ /** Documents, as opposed to the data, config and archives beside them. */
46
+ const READABLE_PAGE = /\.(md|markdown)$/i;
47
+
48
+ /**
49
+ * Pages worth offering to someone who has nothing open: the documents nearest
50
+ * the top of the knowledge tree, breadth-first, so the opening suggestion is a
51
+ * section heading rather than the fifth file inside the first folder.
52
+ *
53
+ * Scoped to exactly what the explorer browses under "Knowledge" —
54
+ * `KnowledgeBase/` plus any stray content folder. `Plugins/` is the Skills &
55
+ * Tools app's storage and is not a browsing destination here, and the loose
56
+ * files at the root (`access.md`, `roles.yaml`) are how the deployment is
57
+ * configured, not something to read. A clone that predates the split has no
58
+ * named roots to scope to, so its whole tree is the knowledge.
59
+ *
60
+ * Fewer than `limit` — including none at all — is a legitimate answer for a
61
+ * knowledge base that is still empty; the caller says so rather than padding.
62
+ */
63
+ export function suggestedPages(tree: FileTreeEntry | null, limit: number): FileTreeEntry[] {
64
+ const kbRoot = findKbRoot(tree);
65
+ const roots = kbRoot?.children
66
+ ? [
67
+ ...kbRoot.children.filter((c) => c.type === 'directory' && c.name === KNOWLEDGE_BASE_DIR),
68
+ ...kbRoot.children.filter((c) => c.type === 'directory' && !KB_ROOT_DIRS.has(c.name)),
69
+ ]
70
+ : tree
71
+ ? [tree]
72
+ : [];
73
+
74
+ const pages: FileTreeEntry[] = [];
75
+ let level = roots;
76
+ while (level.length > 0 && pages.length < limit) {
77
+ const next: FileTreeEntry[] = [];
78
+ for (const entry of level) {
79
+ // Enough pages is enough work: without this, the last level scanned is
80
+ // walked to its end — every remaining sibling tested and pushed — for
81
+ // pages the final slice would throw away.
82
+ if (pages.length >= limit) break;
83
+ // Dot-prefixed entries are the repository's own bookkeeping.
84
+ if (entry.name.startsWith('.')) continue;
85
+ if (entry.type === 'file') {
86
+ if (READABLE_PAGE.test(entry.name)) pages.push(entry);
87
+ } else if (entry.name !== PLUGINS_DIR) {
88
+ next.push(...(entry.children ?? []));
89
+ }
90
+ }
91
+ level = next;
92
+ }
93
+ return pages.slice(0, limit);
94
+ }
95
+
45
96
  function findEntryByPath(tree: FileTreeEntry | null, relativePath: string): FileTreeEntry | null {
46
97
  if (!tree) return null;
47
98
  if (tree.relativePath === relativePath) return tree;
@@ -46,6 +46,13 @@ export interface SurfaceProps extends HTMLAttributes<HTMLElement> {
46
46
  * submit the form it happens to sit in.
47
47
  */
48
48
  type?: 'button' | 'submit' | 'reset';
49
+ /**
50
+ * Also only meaningful with `as="button"`, and declared for the same reason
51
+ * `type` is: `HTMLAttributes` has no `disabled`. A disabled interactive
52
+ * surface drops the hover/press affordance too — a card that still lifts
53
+ * under the cursor reads as one that would do something.
54
+ */
55
+ disabled?: boolean;
49
56
  tone?: SurfaceTone;
50
57
  radius?: SurfaceRadius;
51
58
  elevation?: SurfaceElevation;
@@ -62,10 +69,12 @@ export function Surface({
62
69
  elevation = 'card',
63
70
  interactive = false,
64
71
  padded = false,
72
+ disabled = false,
65
73
  className,
66
74
  children,
67
75
  ...rest
68
76
  }: SurfaceProps) {
77
+ const isDisabled = disabled && Tag === 'button';
69
78
  return (
70
79
  <Tag
71
80
  className={cn(
@@ -75,9 +84,15 @@ export function Surface({
75
84
  ELEVATION[elevation],
76
85
  padded && 'px-4 pt-3.5 pb-3',
77
86
  interactive &&
87
+ !isDisabled &&
78
88
  'cursor-pointer transition-[border-color,background-color,transform] hover:border-line-strong hover:bg-surface-hover active:scale-[.995]',
89
+ // Gated on the SAME condition as the attribute below: on a non-button
90
+ // tag nothing enforces the state, and a surface that looks disabled
91
+ // while still firing onClick is worse than one that looks live.
92
+ isDisabled && 'cursor-not-allowed opacity-60',
79
93
  className,
80
94
  )}
95
+ disabled={isDisabled || undefined}
81
96
  {...rest}
82
97
  >
83
98
  {children}
@@ -0,0 +1,88 @@
1
+ import { ExternalLink } from 'lucide-react';
2
+ import { cn } from '../../lib/utils';
3
+ import { buttonClasses } from '../components';
4
+ import { canDeepLink, claudeInstallUrl, connectorName } from './connect-snippets';
5
+
6
+ /**
7
+ * One click instead of "copy this, open claude.ai, find Settings, find
8
+ * Connectors, find Add custom connector, paste".
9
+ *
10
+ * Anthropic publishes an install link that opens the add-custom-connector
11
+ * dialog with the name and URL prefilled. It only PREFILLS — the person still
12
+ * reviews and confirms, and Claude marks the values as having come from an
13
+ * external link. So this is a shortcut through a menu, not a grant of
14
+ * anything, which is why it needs no warning of its own.
15
+ *
16
+ * It renders nothing when the endpoint cannot possibly be reached from
17
+ * Anthropic's side (see `canDeepLink` — plain http, localhost, private
18
+ * ranges). That is the default configuration, not an edge case, and a bright
19
+ * button that always fails is worse on a first-run screen than no button.
20
+ *
21
+ * `showHint` is for the surface whose audience can DO something about it. On
22
+ * the settings page the reader is plausibly the person holding the env file,
23
+ * so the dead state names the variable to set. On the welcome page the reader
24
+ * is an employee who cannot change deployment config, and telling them about
25
+ * `PUBLIC_BACKEND_URL` is noise — they just get the copy-paste URL, which
26
+ * works regardless.
27
+ */
28
+ /**
29
+ * The address with any userinfo removed, for rendering. `configureMcpUrl`
30
+ * strips credentials at the boot boundary, but this component is exported and
31
+ * takes `mcpUrl` as a prop — a caller that bypasses that door must not get a
32
+ * password printed into the hint. An unparseable value passes through: it is
33
+ * not a URL, so it has no userinfo component to strip.
34
+ */
35
+ function withoutCredentials(mcpUrl: string): string {
36
+ try {
37
+ const parsed = new URL(mcpUrl);
38
+ parsed.username = '';
39
+ parsed.password = '';
40
+ return parsed.toString();
41
+ } catch {
42
+ return mcpUrl;
43
+ }
44
+ }
45
+
46
+ export function ClaudeInstallLink({
47
+ mcpUrl,
48
+ showHint = false,
49
+ className,
50
+ }: {
51
+ mcpUrl: string;
52
+ showHint?: boolean;
53
+ /**
54
+ * Spacing belongs to the caller, ON the element — a wrapping `<div>` with a
55
+ * margin would leave a gap behind on the surface where this renders
56
+ * nothing.
57
+ */
58
+ className?: string;
59
+ }) {
60
+ if (!canDeepLink(mcpUrl)) {
61
+ if (!showHint) return null;
62
+ return (
63
+ /* `text-meta`, not the arbitrary pixel size its neighbours use: those
64
+ predate the token scale and the ratchet counts every one of them, so
65
+ new copy goes on-scale even when it sits beside copy that is not. */
66
+ <p className={cn('text-meta text-ink-muted leading-snug', className)}>
67
+ One-click connect is off because this deployment&rsquo;s public address is{' '}
68
+ <code className="font-mono">{withoutCredentials(mcpUrl)}</code>, which Claude cannot reach from the
69
+ internet. Set <code className="font-mono">PUBLIC_BACKEND_URL</code> to the https
70
+ address people actually use to turn it on. The URL below works either way.
71
+ </p>
72
+ );
73
+ }
74
+
75
+ return (
76
+ <a
77
+ href={claudeInstallUrl(mcpUrl, connectorName(mcpUrl))}
78
+ target="_blank"
79
+ rel="noopener noreferrer"
80
+ className={buttonClasses({ variant: 'primary', size: 'sm', className })}
81
+ >
82
+ Add to Claude
83
+ {/* Decoration: the link's own text is its accessible name, and a second
84
+ reading of "external link" adds nothing for a screen reader. */}
85
+ <ExternalLink size={12} className="opacity-70" aria-hidden="true" />
86
+ </a>
87
+ );
88
+ }
@@ -0,0 +1,51 @@
1
+ import { CopyBlock } from './CopyBlock';
2
+ import { ClaudeInstallLink } from './ClaudeInstallLink';
3
+ import { claudeCodeCommand, jsonConfigSnippet } from './connect-snippets';
4
+
5
+ /**
6
+ * How to point an interactive agent at this workspace: the three
7
+ * no-key connection configs, plus the one-click Claude install link when the
8
+ * deployment is reachable enough for it to work.
9
+ *
10
+ * Its own component rather than a block inside `ExternalAgentAccessPage`
11
+ * because that page fetches external API keys on mount. Testing "does the
12
+ * install button appear" by rendering the whole page meant mocking the
13
+ * credential API first — a test coupled to code it does not care about, which
14
+ * breaks whenever that API changes. This takes a URL and renders; there is
15
+ * nothing to mock.
16
+ *
17
+ * Every URL here comes from the one `mcpUrl` prop. That is the point: the
18
+ * six sites this replaced each rebuilt the address from
19
+ * `window.location.origin`, which is the browser's idea of where we are
20
+ * rather than the deployment's.
21
+ */
22
+ export function ConnectionInstructions({ mcpUrl }: { mcpUrl: string }) {
23
+ return (
24
+ <>
25
+ <CopyBlock label="Connect Claude Code" value={claudeCodeCommand(mcpUrl)} rows={2} />
26
+ <div>
27
+ <div className="text-xs font-medium text-ink mb-1">claude.ai / Claude Desktop</div>
28
+ {/* The button first, then the manual route underneath — the fallback
29
+ has to stay visible, because one-click is unavailable on any
30
+ deployment Claude cannot reach and the copy-paste URL is the only
31
+ thing that always works. */}
32
+ <div className="mb-1.5">
33
+ <ClaudeInstallLink mcpUrl={mcpUrl} showHint />
34
+ </div>
35
+ <p className="text-[11px] text-ink-muted mb-1 leading-snug">
36
+ Or add it by hand: Settings → Connectors → Add custom connector, then paste this
37
+ URL. When asked to authorize, your browser opens this app to finish connecting.
38
+ </p>
39
+ <CopyBlock label={null} value={mcpUrl} rows={1} />
40
+ </div>
41
+ <div>
42
+ <div className="text-xs font-medium text-ink mb-1">Other agents (JSON config)</div>
43
+ <p className="text-[11px] text-ink-muted mb-1 leading-snug">
44
+ Works with Cursor, Windsurf, Cline, and most clients that load servers from a JSON
45
+ config and support signing in.
46
+ </p>
47
+ <CopyBlock label={null} value={jsonConfigSnippet(mcpUrl)} rows={9} />
48
+ </div>
49
+ </>
50
+ );
51
+ }
@@ -0,0 +1,42 @@
1
+ import { Check, Copy } from 'lucide-react';
2
+ import { useCopyFeedback } from './useCopyFeedback';
3
+
4
+ /** Read-only snippet with a copy button, for the no-key connection configs. */
5
+ export function CopyBlock({
6
+ label,
7
+ value,
8
+ rows,
9
+ }: {
10
+ label: string | null;
11
+ value: string;
12
+ rows: number;
13
+ }) {
14
+ const { copied, copy } = useCopyFeedback();
15
+
16
+ return (
17
+ <div>
18
+ <div className="flex items-center justify-between mb-1">
19
+ {label !== null && <div className="text-xs font-medium text-ink">{label}</div>}
20
+ <button
21
+ // Explicit: a bare <button> inside a <form> defaults to `submit`,
22
+ // and this is a shared component now — it does not get to assume
23
+ // which tree it renders in.
24
+ type="button"
25
+ onClick={() => copy(value)}
26
+ className="ml-auto p-1 rounded hover:bg-hover text-ink-muted"
27
+ aria-label={label ? `Copy: ${label}` : 'Copy to clipboard'}
28
+ title="Copy to clipboard"
29
+ >
30
+ {copied ? <Check size={14} /> : <Copy size={14} />}
31
+ </button>
32
+ </div>
33
+ <textarea
34
+ readOnly
35
+ value={value}
36
+ rows={rows}
37
+ className="w-full font-mono text-[11px] bg-sunken border border-line rounded px-2 py-1.5 resize-none"
38
+ onFocus={(e) => e.currentTarget.select()}
39
+ />
40
+ </div>
41
+ );
42
+ }
@@ -0,0 +1,40 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ClaudeInstallLink } from '../ClaudeInstallLink';
4
+
5
+ /**
6
+ * The three states of the connect affordance: a live button on a reachable
7
+ * address, nothing on a dead one, and the operator hint when asked for — plus
8
+ * the rule that the hint never prints a credential, whatever it was handed.
9
+ */
10
+ describe('ClaudeInstallLink', () => {
11
+ it('renders the install link for a reachable https address', () => {
12
+ render(<ClaudeInstallLink mcpUrl="https://kb.acme.com/api/mcp" />);
13
+ const link = screen.getByRole('link', { name: 'Add to Claude' });
14
+ expect(link).toHaveAttribute('href', expect.stringContaining('claude.ai'));
15
+ });
16
+
17
+ it('renders nothing for an unreachable address without the hint', () => {
18
+ const { container } = render(<ClaudeInstallLink mcpUrl="http://localhost:3001/api/mcp" />);
19
+ expect(container).toBeEmptyDOMElement();
20
+ });
21
+
22
+ it('names the dead address in the hint', () => {
23
+ render(<ClaudeInstallLink mcpUrl="http://localhost:3001/api/mcp" showHint />);
24
+ expect(screen.getByText('http://localhost:3001/api/mcp')).toBeInTheDocument();
25
+ expect(screen.getByText(/PUBLIC_BACKEND_URL/)).toBeInTheDocument();
26
+ });
27
+
28
+ /**
29
+ * `configureMcpUrl` strips credentials at the boot boundary, but `mcpUrl`
30
+ * is a prop — a caller that bypasses that door must not get the password
31
+ * printed on screen. (`canDeepLink` already refuses such a URL, which is
32
+ * exactly what routes it INTO the hint branch.)
33
+ */
34
+ it('strips credentials from the URL it prints, rather than leaking a bypass caller’s secret', () => {
35
+ render(<ClaudeInstallLink mcpUrl="http://someone:hunter2@kb.acme.com/api/mcp" showHint />);
36
+ expect(screen.getByText('http://kb.acme.com/api/mcp')).toBeInTheDocument();
37
+ expect(screen.queryByText(/hunter2/)).not.toBeInTheDocument();
38
+ expect(screen.queryByText(/someone/)).not.toBeInTheDocument();
39
+ });
40
+ });