@bevel-software/platform-core-frontend 0.26.0 → 0.27.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 (187) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  5. package/src/core/__tests__/core-contributions.test.ts +16 -0
  6. package/src/core/core-contributions.ts +17 -0
  7. package/src/core/registry.ts +51 -1
  8. package/src/index.css +23 -5
  9. package/src/index.ts +5 -0
  10. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  11. package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
  12. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  13. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  14. package/src/modules/auth/components/LoginScreen.tsx +4 -1
  15. package/src/modules/auth/services/account.api.ts +28 -1
  16. package/src/modules/auth/services/sso.ts +1 -2
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  19. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  20. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  21. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  22. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  23. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  24. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  25. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  26. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  27. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  28. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  29. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  30. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  31. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  32. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  33. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  34. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  35. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  36. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  37. package/src/modules/embed/components/EmbedView.tsx +545 -0
  38. package/src/modules/embed/embed-config.ts +132 -0
  39. package/src/modules/embed/embed-host.ts +120 -0
  40. package/src/modules/embed/mount.tsx +80 -0
  41. package/src/modules/embed/services/embed-token.ts +22 -0
  42. package/src/modules/embed/services/embed.api.ts +158 -0
  43. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  44. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  45. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  46. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  47. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  48. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  49. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  50. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  51. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  52. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  53. package/src/modules/git/index.ts +15 -0
  54. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  55. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  56. package/src/modules/git/services/error-messages.ts +58 -1
  57. package/src/modules/git/services/pull-failure.ts +68 -0
  58. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  59. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  60. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  61. package/src/modules/layout/breakpoints.ts +8 -0
  62. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  63. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  64. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  65. package/src/modules/library/components/LibraryPage.tsx +22 -0
  66. package/src/modules/library/components/PluginExtras.tsx +23 -6
  67. package/src/modules/library/components/PluginPage.tsx +6 -1
  68. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  69. package/src/modules/library/services/plugins.api.ts +4 -1
  70. package/src/modules/library/state/plugins-revision.ts +28 -0
  71. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  72. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  73. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  74. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  75. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  76. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  77. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  78. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  79. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  80. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  81. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  82. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  83. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  84. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  85. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  86. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  87. package/src/modules/onboarding/invite-emails.ts +175 -0
  88. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  89. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  90. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  91. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  92. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  93. package/src/modules/onboarding/state/onboarding.ts +133 -59
  94. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  95. package/src/modules/settings/settings-nav-items.tsx +8 -3
  96. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  97. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  98. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  99. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  100. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  101. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  102. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  103. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  104. package/src/modules/setup/components/SetupGate.tsx +46 -1
  105. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  106. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  107. package/src/modules/setup/services/setup.api.ts +3 -3
  108. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  109. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  110. package/src/modules/toolbar/commands/actions.tsx +324 -0
  111. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  112. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  113. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  114. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  115. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  116. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  117. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  118. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  119. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  120. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  121. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  122. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  123. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  124. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  125. package/src/modules/toolbar/search/rank.ts +111 -0
  126. package/src/modules/toolbar/search/sources.ts +169 -0
  127. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  128. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  129. package/src/modules/workflow/services/lock.api.ts +17 -2
  130. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  131. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  132. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  133. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  134. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  135. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  136. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  137. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  138. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  139. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  140. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  141. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  142. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  143. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  144. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  145. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  146. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  147. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  148. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  149. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  150. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  151. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  152. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  153. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  154. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  155. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  156. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  157. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  158. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  159. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  160. package/src/modules/workspace/components/renderers/index.ts +26 -0
  161. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  162. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  163. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  164. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  165. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  166. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  167. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  168. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  169. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  170. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  171. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  172. package/src/modules/workspace/state/editable-page.ts +42 -0
  173. package/src/modules/workspace/state/workspace.context.ts +13 -4
  174. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  175. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  176. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  177. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  178. package/src/modules/workspace/utils/fileTree.ts +49 -14
  179. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  180. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  181. package/src/shared/components/ConfirmProvider.tsx +156 -0
  182. package/src/shared/components/Dialog.tsx +7 -0
  183. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  184. package/src/shared/components/confirm-context.ts +94 -0
  185. package/src/shared/components/index.ts +3 -0
  186. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  187. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { EDITING_ENDED_MESSAGE, LockApiError, releaseLock } from '../lock.api';
3
+
4
+ const fetchMock = vi.fn();
5
+
6
+ beforeEach(() => {
7
+ fetchMock.mockReset();
8
+ vi.stubGlobal('fetch', fetchMock);
9
+ localStorage.clear();
10
+ });
11
+
12
+ function refusal(status: number, body: unknown): Response {
13
+ return new Response(JSON.stringify(body), {
14
+ status,
15
+ headers: { 'Content-Type': 'application/json' },
16
+ });
17
+ }
18
+
19
+ describe('lock.api', () => {
20
+ it('says a lapsed editing session in plain words, not the server sentence', async () => {
21
+ fetchMock.mockResolvedValueOnce(
22
+ refusal(400, {
23
+ kind: 'lock-not-held',
24
+ branch: 'main',
25
+ path: 'kb/Knowledge/Foo.md',
26
+ error: 'Cannot release lock on "kb/Knowledge/Foo.md": not held by you (or no longer exists).',
27
+ }),
28
+ );
29
+ const err = await releaseLock('ws', 'main', 'kb/Knowledge/Foo.md').catch((e: unknown) => e);
30
+ expect(err).toBeInstanceOf(LockApiError);
31
+ expect((err as LockApiError).message).toBe(EDITING_ENDED_MESSAGE);
32
+ expect((err as LockApiError).message).not.toMatch(/lock/i);
33
+ expect((err as LockApiError).status).toBe(400);
34
+ });
35
+
36
+ it('passes any other refusal through as the server wrote it', async () => {
37
+ fetchMock.mockResolvedValueOnce(refusal(409, { error: '"Foo.md" is being edited by Dana. Try again in a moment.' }));
38
+ const err = await releaseLock('ws', 'main', 'kb/Knowledge/Foo.md').catch((e: unknown) => e);
39
+ expect((err as LockApiError).message).toBe('"Foo.md" is being edited by Dana. Try again in a moment.');
40
+ });
41
+ });
@@ -26,6 +26,18 @@ export class LockApiError extends Error {
26
26
  }
27
27
  }
28
28
 
29
+ /**
30
+ * What a person reads when the server says they no longer hold the file —
31
+ * it went idle, or expired, before a save or a heartbeat landed. The
32
+ * server's own sentence ("Cannot release lock on …: not held by you")
33
+ * names the mechanism; the person only needs to know their editing
34
+ * stopped and what to do about it. Said without naming a save: every call
35
+ * here answers with it, the heartbeat included, and a heartbeat that finds
36
+ * the session gone attempted no save at all.
37
+ */
38
+ export const EDITING_ENDED_MESSAGE =
39
+ 'Your editing session ended. Check the page and edit it again if anything is missing.';
40
+
29
41
  async function unwrap<T>(res: Response): Promise<T> {
30
42
  if (res.ok) return (await res.json()) as T;
31
43
  let body: unknown;
@@ -35,6 +47,9 @@ async function unwrap<T>(res: Response): Promise<T> {
35
47
  if (body && typeof body === 'object' && 'error' in body) {
36
48
  message = String((body as { error: unknown }).error);
37
49
  }
50
+ if (body && typeof body === 'object' && (body as { kind?: unknown }).kind === 'lock-not-held') {
51
+ message = EDITING_ENDED_MESSAGE;
52
+ }
38
53
  } catch {
39
54
  // non-JSON body — fall through with default message
40
55
  }
@@ -45,8 +60,8 @@ async function unwrap<T>(res: Response): Promise<T> {
45
60
  * Try to acquire the lock for `(branch, path)`. Resolves with the
46
61
  * `AcquireLockResult` payload — `acquired: true` when the caller now
47
62
  * holds the lock, `acquired: false` when someone else does (the
48
- * holder's lock state is included so the UI can render "Locked by X"
49
- * without a follow-up call).
63
+ * holder's lock state is included so the UI can render "X is editing
64
+ * this page" without a follow-up call).
50
65
  */
51
66
  export async function acquireLock(
52
67
  workspaceId: string,
@@ -3,7 +3,9 @@ import { renderHook, act, waitFor } from '@testing-library/react';
3
3
 
4
4
  // Mock the workspace API before importing the hook — the hook's top-level import
5
5
  // binds to the mocked module.
6
- vi.mock('../services/workspace.api', () => ({
6
+ vi.mock('../services/workspace.api', async (importOriginal) => ({
7
+ // The real error class, so a test can reject with the shape callers read.
8
+ WorkspaceApiError: (await importOriginal<typeof import('../services/workspace.api')>()).WorkspaceApiError,
7
9
  getOrCreateWorkspace: vi.fn().mockResolvedValue({
8
10
  workspace: { id: 'ws-1' },
9
11
  fileTree: { name: '.', relativePath: '.', type: 'directory', children: [] },
@@ -89,3 +91,49 @@ describe('useWorkspaceState fsRevision', () => {
89
91
  expect(result.current.fsRevision).toBeGreaterThan(start);
90
92
  });
91
93
  });
94
+
95
+ /**
96
+ * `createFile` writes unconditionally unless asked for an exclusive create —
97
+ * the explorer's New file keeps its old call, and a caller that picked a name
98
+ * from a possibly stale tree can have the backend refuse an existing file.
99
+ */
100
+ describe('useWorkspaceState createFile', () => {
101
+ beforeEach(() => {
102
+ vi.clearAllMocks();
103
+ });
104
+
105
+ async function mountReady() {
106
+ const { result } = renderHook(() => useWorkspaceState());
107
+ await waitFor(() => expect(result.current.workspaceId).toBe('ws-1'));
108
+ return result;
109
+ }
110
+
111
+ it('writes unconditionally by default', async () => {
112
+ const result = await mountReady();
113
+ await act(async () => { await result.current.createFile('a.md', '# A'); });
114
+ expect(api.writeFile).toHaveBeenCalledTimes(1);
115
+ expect(vi.mocked(api.writeFile).mock.calls[0]![3]?.ifAbsent).toBeUndefined();
116
+ });
117
+
118
+ it('passes ifAbsent through to the write', async () => {
119
+ const result = await mountReady();
120
+ await act(async () => { await result.current.createFile('a.md', '# A', { ifAbsent: true }); });
121
+ expect(api.writeFile).toHaveBeenCalledWith('ws-1', 'a.md', '# A', { ifAbsent: true });
122
+ });
123
+
124
+ it('rejects with the refusal, and leaves the tree and revision alone', async () => {
125
+ const result = await mountReady();
126
+ const start = result.current.fsRevision;
127
+ const tree = result.current.fileTree;
128
+ const listCalls = vi.mocked(api.listFiles).mock.calls.length;
129
+ vi.mocked(api.writeFile).mockRejectedValueOnce(new api.WorkspaceApiError(409, '"a.md" already exists.'));
130
+ await act(async () => {
131
+ await expect(result.current.createFile('a.md', '', { ifAbsent: true })).rejects.toMatchObject({ status: 409 });
132
+ });
133
+ expect(result.current.fsRevision).toBe(start);
134
+ // No refresh (the list count) AND no local edit (the same tree object):
135
+ // the refused file was never added to the tree on screen.
136
+ expect(vi.mocked(api.listFiles).mock.calls.length).toBe(listCalls);
137
+ expect(result.current.fileTree).toBe(tree);
138
+ });
139
+ });
@@ -2,11 +2,12 @@ import { useEffect, useRef, useState } from 'react';
2
2
  import { X } from 'lucide-react';
3
3
  import { cn } from '../../../lib/utils';
4
4
  import { MenuPanel, MenuItem } from '../../../shared/components';
5
- import { useDismissableMenu, usePointerMenuPosition } from '../../../shared/components';
5
+ import { useConfirm, useDismissableMenu, useLatestRef, usePointerMenuPosition } from '../../../shared/components';
6
6
  import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
7
7
  import { useWorkspace } from '../state/workspace.context';
8
8
  import { useFileNav } from '../routing/kb-routes';
9
9
  import type { OpenTab } from '../state/workspace.context';
10
+ import { displayFileName } from '../utils/display-file-name';
10
11
  import '../workspace.css';
11
12
 
12
13
  const DRAG_MIME = 'application/x-bevel-tab-path';
@@ -14,11 +15,6 @@ const DRAG_MIME = 'application/x-bevel-tab-path';
14
15
  const UNSAVED_TABS_BULK_WARNING = (filenames: string[]) =>
15
16
  `You have unsaved changes in:\n - ${filenames.join('\n - ')}\nClose anyway?`;
16
17
 
17
- function basename(path: string): string {
18
- const i = path.lastIndexOf('/');
19
- return i >= 0 ? path.slice(i + 1) : path;
20
- }
21
-
22
18
  interface MenuState {
23
19
  tab: OpenTab;
24
20
  x: number;
@@ -31,8 +27,14 @@ export function EditorTabs() {
31
27
  activeTab,
32
28
  closeTab,
33
29
  reorderTab,
30
+ kbDirName,
31
+ workspaceId,
34
32
  } = useWorkspace();
35
33
  const { openFile: navigateToFile, closeFile: navigateToBranchRoot } = useFileNav();
34
+ const confirm = useConfirm();
35
+ // The live workspace, for a bulk close that awaits: the render that started
36
+ // it has gone stale by the time it navigates.
37
+ const workspaceIdRef = useLatestRef(workspaceId);
36
38
 
37
39
  const [draggingPath, setDraggingPath] = useState<string | null>(null);
38
40
  const [dragOverPath, setDragOverPath] = useState<string | null>(null);
@@ -142,12 +144,18 @@ export function EditorTabs() {
142
144
  else navigateToBranchRoot();
143
145
  }}
144
146
  onCloseMany={async (tabs) => {
147
+ // The workspace these tabs were picked in. `closeTab` closes
148
+ // nothing if the question below outlives it.
149
+ const askedInWorkspaceId = workspaceId;
145
150
  const dirty = tabs.filter((t) => t.isDirty);
146
151
  if (dirty.length > 0) {
147
- const ok = window.confirm(
148
- UNSAVED_TABS_BULK_WARNING(dirty.map((t) => basename(t.path))),
149
- );
150
- if (!ok) return;
152
+ const { confirmed } = await confirm({
153
+ title: 'Unsaved changes',
154
+ message: UNSAVED_TABS_BULK_WARNING(dirty.map((t) => displayFileName(t.path, kbDirName))),
155
+ confirmLabel: 'Close anyway',
156
+ destructive: true,
157
+ });
158
+ if (!confirmed) return;
151
159
  }
152
160
  // Pass skipConfirm so the per-tab dirty prompt doesn't fire again
153
161
  // (we already collected one bulk confirm). Run each close in a
@@ -157,21 +165,36 @@ export function EditorTabs() {
157
165
  const activePath = activeTab?.path ?? null;
158
166
  const closingActive = activePath !== null && tabs.some((t) => t.path === activePath);
159
167
  let lastActivePath = activePath;
168
+ let closedAny = false;
169
+ // With skipConfirm, a close is refused only because the workspace
170
+ // moved on; after that, every path computed here is the old branch's.
171
+ let movedOn = false;
160
172
  // Store only the path + error metadata — the full OpenTab carries
161
173
  // file content/pendingFileContent which we don't want in logs or
162
174
  // any future telemetry sink.
163
175
  const failures: { path: string; message: string; stack?: string }[] = [];
164
176
  for (const t of tabs) {
165
177
  try {
166
- const { closed, newActivePath } = await closeTab(t, { skipConfirm: true });
167
- if (closed) lastActivePath = newActivePath;
178
+ const { closed, newActivePath } = await closeTab(t, {
179
+ skipConfirm: true,
180
+ workspaceId: askedInWorkspaceId,
181
+ });
182
+ if (closed) {
183
+ lastActivePath = newActivePath;
184
+ closedAny = true;
185
+ } else {
186
+ movedOn = true;
187
+ }
168
188
  } catch (err) {
169
189
  const message = err instanceof Error ? err.message : String(err);
170
190
  const stack = err instanceof Error ? err.stack : undefined;
171
191
  failures.push({ path: t.path, message, stack });
172
192
  }
173
193
  }
174
- if (closingActive) {
194
+ // The workspace moved on (while asked, or partway through): the URL
195
+ // belongs to the new branch now, leave it alone.
196
+ const stillHere = !movedOn && workspaceIdRef.current === askedInWorkspaceId;
197
+ if (closingActive && closedAny && stillHere) {
175
198
  if (lastActivePath) navigateToFile(lastActivePath);
176
199
  else navigateToBranchRoot();
177
200
  }
@@ -179,7 +202,7 @@ export function EditorTabs() {
179
202
  console.error('[EditorTabs] Failed to close tabs', failures);
180
203
  window.alert(
181
204
  `Failed to close ${failures.length} tab(s): ${failures
182
- .map((f) => basename(f.path))
205
+ .map((f) => displayFileName(f.path, kbDirName))
183
206
  .join(', ')}`,
184
207
  );
185
208
  }
@@ -223,7 +246,8 @@ function TabPill(props: TabPillProps) {
223
246
  onDragEnd,
224
247
  } = props;
225
248
 
226
- const filename = basename(tab.path);
249
+ const { kbDirName } = useWorkspace();
250
+ const filename = displayFileName(tab.path, kbDirName);
227
251
  const hasPending = tab.pendingFileContent !== null;
228
252
  const hasChangeRequest = useOpenChangeRequests().paths.has(tab.path);
229
253
  const ref = useRef<HTMLDivElement>(null);
@@ -70,6 +70,7 @@ import { downloadViaBlob } from './renderers/downloadFile';
70
70
  import { cn } from '../../../lib/utils';
71
71
  import { Banner, MenuPanel, MenuItem, TextField, IconButton } from '../../../shared/components';
72
72
  import { useDismissableMenu, usePointerMenuPosition } from '../../../shared/components';
73
+ import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
73
74
  import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
74
75
  import { AdminContext } from '../../admin/state/admin.context';
75
76
  import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
@@ -92,6 +93,7 @@ import {
92
93
  ACCESS_LOOKUP_TIMEOUT_MS,
93
94
  accessChangeOf,
94
95
  moveWarnings,
96
+ platformFileDeleteRefusal,
95
97
  platformFileDragRefusal,
96
98
  platformFileMoveRefusal,
97
99
  } from '../utils/treeConfirm';
@@ -395,16 +397,24 @@ function useDownloadVerdict(entry: FileTreeEntry | null): boolean | null {
395
397
 
396
398
  // ── Context Menu ──
397
399
 
400
+ /** The proposed row's hover text, with the real file name when the row shows a plain one. */
401
+ function proposedRowTitle(path: string, kbDirName: string | null): string {
402
+ const real = fileNameTooltip(path, kbDirName);
403
+ return real ? `Proposed by you: opens the change request (${real})` : 'Proposed by you: opens the change request';
404
+ }
405
+
398
406
  function ContextMenu({
399
407
  x,
400
408
  y,
401
409
  entry,
410
+ label,
402
411
  isRoot,
403
412
  onClose,
404
413
  onCreateFile,
405
414
  onCreateFolder,
406
415
  onRename,
407
416
  renameRefusal = null,
417
+ deleteRefusal = null,
408
418
  onDownload,
409
419
  onWithdraw,
410
420
  returnFocusTo,
@@ -415,6 +425,8 @@ function ContextMenu({
415
425
  x: number;
416
426
  y: number;
417
427
  entry: FileTreeEntry;
428
+ /** What the menu is named for: a file's shown name, a folder's own. */
429
+ label: string;
418
430
  isRoot: boolean;
419
431
  /**
420
432
  * The entry exists only on a change request's branch. Nothing that acts on
@@ -434,6 +446,12 @@ function ContextMenu({
434
446
  * reachable: an affordance that vanishes teaches nobody why.
435
447
  */
436
448
  renameRefusal?: string | null;
449
+ /**
450
+ * Why Delete is not on offer for this row — the repository's own files
451
+ * (the root's `access.md` and `roles.yaml`) are deleted by nobody. Drawn
452
+ * disabled with the reason, as a refused Rename is.
453
+ */
454
+ deleteRefusal?: string | null;
437
455
  onDownload?: () => void;
438
456
  /**
439
457
  * Take this suggestion back. Supplied ONLY by a proposed row whose change
@@ -711,7 +729,7 @@ function ContextMenu({
711
729
  style={{ left: pos.left, top: pos.top }}
712
730
  onMouseDown={(e) => e.stopPropagation()}
713
731
  >
714
- <MenuPanel role="menu" aria-label={`Actions for ${entry.name}`} className="min-w-[180px]">
732
+ <MenuPanel role="menu" aria-label={`Actions for ${label}`} className="min-w-[180px]">
715
733
  {onCreateFile && (
716
734
  <MenuItem role="menuitem" onClick={() => { onCreateFile(); onClose(); }}>
717
735
  <span className="flex items-center gap-2"><FilePlus size={14} />New file</span>
@@ -799,7 +817,17 @@ function ContextMenu({
799
817
  )}
800
818
  {!isRoot && deletable && (
801
819
  // Danger tone comes from the primitive, not from a hand-written red.
802
- <MenuItem role="menuitem" tone="danger" onClick={handleDelete}>
820
+ // A refused Delete keeps its place and says why, as Rename does.
821
+ <MenuItem
822
+ role="menuitem"
823
+ tone="danger"
824
+ aria-disabled={deleteRefusal ? true : undefined}
825
+ title={deleteRefusal ?? undefined}
826
+ onClick={() => {
827
+ if (deleteRefusal) return;
828
+ handleDelete();
829
+ }}
830
+ >
803
831
  <span className="flex items-center gap-2"><Trash2 size={14} />Delete</span>
804
832
  </MenuItem>
805
833
  )}
@@ -1598,6 +1626,7 @@ export function FileTreeNode({
1598
1626
  x={contextMenu.x}
1599
1627
  y={contextMenu.y}
1600
1628
  entry={entry}
1629
+ label={entry.type === 'directory' ? entry.name : displayFileName(entry.relativePath, kbDirName)}
1601
1630
  isRoot={isRoot}
1602
1631
  onClose={() => setContextMenu(null)}
1603
1632
  onCreateFile={() => { setUserIntent(true); setCreating('file'); }}
@@ -1683,10 +1712,10 @@ export function FileTreeNode({
1683
1712
  style={{ paddingLeft }}
1684
1713
  onClick={() => suggestions.open(entry.relativePath, suggestedCr)}
1685
1714
  onContextMenu={handleContextMenu}
1686
- title="Proposed by you: opens the change request"
1715
+ title={proposedRowTitle(entry.relativePath, kbDirName)}
1687
1716
  >
1688
1717
  <CaretSlot show={false} />
1689
- <FileName name={entry.name} />
1718
+ <FileName name={displayFileName(entry.relativePath, kbDirName)} />
1690
1719
  <span
1691
1720
  aria-hidden
1692
1721
  className="ml-auto h-1.5 w-1.5 flex-none rounded-full bg-accent"
@@ -1697,6 +1726,7 @@ export function FileTreeNode({
1697
1726
  x={contextMenu.x}
1698
1727
  y={contextMenu.y}
1699
1728
  entry={entry}
1729
+ label={displayFileName(entry.relativePath, kbDirName)}
1700
1730
  isRoot={false}
1701
1731
  proposed
1702
1732
  deletable={false}
@@ -1730,7 +1760,8 @@ export function FileTreeNode({
1730
1760
  onDragEnd={handleDragEnd}
1731
1761
  onClick={() => { if (!renaming && !isPending) nav.open(entry.relativePath); }}
1732
1762
  onContextMenu={handleContextMenu}
1733
- title={isPending ? 'Adding…' : undefined}
1763
+ // A platform file shows its plain name; hovering gives the real one.
1764
+ title={isPending ? 'Adding…' : fileNameTooltip(entry.relativePath, kbDirName)}
1734
1765
  >
1735
1766
  {/* The pending spinner is the one glyph that survives the icon cull,
1736
1767
  because it says something no other part of the row says. It takes
@@ -1750,7 +1781,7 @@ export function FileTreeNode({
1750
1781
  onCancel={() => setRenaming(false)}
1751
1782
  />
1752
1783
  ) : (
1753
- <FileName name={entry.name} />
1784
+ <FileName name={displayFileName(entry.relativePath, kbDirName)} />
1754
1785
  )}
1755
1786
  {/* News about a file you are not looking at (proto:692). Amber, not
1756
1787
  the tab dot's accent: on a tab the dot marks the file you have
@@ -1769,10 +1800,12 @@ export function FileTreeNode({
1769
1800
  x={contextMenu.x}
1770
1801
  y={contextMenu.y}
1771
1802
  entry={entry}
1803
+ label={displayFileName(entry.relativePath, kbDirName)}
1772
1804
  isRoot={false}
1773
1805
  onClose={() => setContextMenu(null)}
1774
1806
  onRename={() => setRenaming(true)}
1775
1807
  renameRefusal={platformRefusal}
1808
+ deleteRefusal={platformFileDeleteRefusal(entry.relativePath, kbDirName)}
1776
1809
  onDownload={handleDownload}
1777
1810
  extraItems={nav.menuItems?.(entry)}
1778
1811
  returnFocusTo={rowRef}
@@ -19,6 +19,8 @@ import { Surface } from '../../../shared/components';
19
19
  export interface FilePaneCardProps {
20
20
  /** What the bar names — the file, e.g. `SKILL.md` or `How to get started.md`. */
21
21
  file: string;
22
+ /** The bar's hover text: the real file name, when `file` is a platform file's plain name. */
23
+ fileTitle?: string;
22
24
  /**
23
25
  * The bar's TRAILING slot — the pane's write action (`Edit` / `Propose
24
26
  * changes` / `Done`…), flush right. The filename leads: the bar names the
@@ -31,7 +33,7 @@ export interface FilePaneCardProps {
31
33
  children: ReactNode;
32
34
  }
33
35
 
34
- export function FilePaneCard({ file, actions, notice, className, children }: FilePaneCardProps) {
36
+ export function FilePaneCard({ file, fileTitle, actions, notice, className, children }: FilePaneCardProps) {
35
37
  return (
36
38
  <Surface
37
39
  tone="surface"
@@ -41,7 +43,9 @@ export function FilePaneCard({ file, actions, notice, className, children }: Fil
41
43
  className={cn('overflow-hidden', className)}
42
44
  >
43
45
  <div className="flex min-h-11 items-center gap-3 border-b border-line px-3.5 py-2">
44
- <span className="mr-auto truncate font-mono text-meta text-ink-muted">{file}</span>
46
+ <span className="mr-auto truncate font-mono text-meta text-ink-muted" title={fileTitle}>
47
+ {file}
48
+ </span>
45
49
  {actions}
46
50
  </div>
47
51
 
@@ -13,7 +13,7 @@ import {
13
13
  fetchNodeWorkspacePath,
14
14
  fetchNodeId,
15
15
  } from '../routing/kb-routes';
16
- import { Banner, Button, Surface } from '../../../shared/components';
16
+ import { Banner, Button, Surface, useLatestRef } from '../../../shared/components';
17
17
  import { FileViewer } from './FileViewer';
18
18
 
19
19
  type SyncError =
@@ -129,6 +129,12 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
129
129
  // Guarded by `segmentIsId` so an already-canonical id URL no-ops and this can't
130
130
  // ping-pong; gated on `openFilePath === segment` so the subsequent id→path
131
131
  // load reuses the already-open tab instead of racing a second fetch.
132
+ //
133
+ // The swap is the SAME history entry under its canonical name, so it keeps
134
+ // the entry's router state — a `startEditing` request (or `rawFile`) not yet
135
+ // acted on must survive it. Read through a ref, at the moment of the swap,
136
+ // so a request the viewer has consumed in the meantime is not put back.
137
+ const routerStateRef = useLatestRef<unknown>(location.state);
132
138
  useEffect(() => {
133
139
  if (!canonicalize || segmentIsId || !segment || !branchFromUrl) return;
134
140
  if (openFilePath !== segment) return;
@@ -136,13 +142,13 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
136
142
  (async () => {
137
143
  const nodeId = await fetchNodeId(branchFromUrl, segment);
138
144
  if (!cancelled && nodeId) {
139
- navigate(kbNodeUrl(branchFromUrl, nodeId) + location.hash, { replace: true });
145
+ navigate(kbNodeUrl(branchFromUrl, nodeId) + location.hash, { replace: true, state: routerStateRef.current });
140
146
  }
141
147
  })();
142
148
  return () => {
143
149
  cancelled = true;
144
150
  };
145
- }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate]);
151
+ }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate, routerStateRef]);
146
152
 
147
153
  // ── Branch sync + hydrate + URL → state (forward direction) ──────────────
148
154
 
@@ -561,8 +567,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
561
567
  unsaved changes on{' '}
562
568
  <span className="font-mono text-ink">{error.current}</span>. Save the
563
569
  files below first (Ctrl/Cmd+S, or click <span className="font-medium">Save</span>{' '}
564
- in the editor toolbar). That releases the lock and auto-commits and auto-pushes
565
- your changes: then this link will open.
570
+ in the editor toolbar), and then this link will open.
566
571
  </p>
567
572
  {error.dirtyFilenames.length > 0 && (
568
573
  <Surface tone="sunken" radius="md" elevation="none" className="px-3 py-2 text-left text-detail text-ink">
@@ -583,7 +588,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
583
588
  <ErrorScreen title="This branch no longer exists">
584
589
  <p className="text-ui text-ink-muted">
585
590
  <span className="font-mono text-ink">{goneBranch}</span> was deleted in the git
586
- repository. Anything merged from it lives on{' '}
591
+ repository. Anything published from it lives on{' '}
587
592
  <span className="font-mono text-ink">{DEFAULT_BRANCH}</span>.
588
593
  </p>
589
594
  <Button onClick={() => navigate(kbFileUrl(DEFAULT_BRANCH))}>Go to {DEFAULT_BRANCH}</Button>
@@ -599,7 +604,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
599
604
  <span className="font-mono text-ink">{unknownBranch}</span>.
600
605
  </p>
601
606
  <p className="text-meta text-ink-faint">
602
- It may never have been pushed, or this link may have the name wrong.
607
+ It may never have been published, or this link may have the name wrong.
603
608
  </p>
604
609
  <Button onClick={() => navigate(kbFileUrl(DEFAULT_BRANCH))}>Go to {DEFAULT_BRANCH}</Button>
605
610
  </ErrorScreen>