@bevel-software/platform-core-frontend 0.25.2 → 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 (193) 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/__tests__/ToolPage.test.tsx +53 -0
  66. package/src/modules/library/components/LibraryPage.tsx +22 -0
  67. package/src/modules/library/components/PluginExtras.tsx +23 -6
  68. package/src/modules/library/components/PluginPage.tsx +6 -1
  69. package/src/modules/library/components/tool-page/ToolPage.tsx +45 -1
  70. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  71. package/src/modules/library/services/plugins.api.ts +4 -1
  72. package/src/modules/library/services/tools.api.ts +27 -0
  73. package/src/modules/library/state/plugins-revision.ts +28 -0
  74. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  75. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  76. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  77. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  78. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  79. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  80. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  81. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  82. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  83. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  84. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  85. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  86. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  87. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  88. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  89. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  90. package/src/modules/onboarding/invite-emails.ts +175 -0
  91. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  92. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  93. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  94. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  95. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  96. package/src/modules/onboarding/state/onboarding.ts +133 -59
  97. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  98. package/src/modules/settings/settings-nav-items.tsx +8 -3
  99. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  100. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  101. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  102. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  103. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  104. package/src/modules/setup/__tests__/setup.test.tsx +65 -81
  105. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  106. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  107. package/src/modules/setup/components/SetupGate.tsx +46 -1
  108. package/src/modules/setup/components/SetupScreen.tsx +92 -152
  109. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  110. package/src/modules/setup/services/setup.api.ts +3 -3
  111. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  112. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  113. package/src/modules/toolbar/commands/actions.tsx +324 -0
  114. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  115. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  116. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  117. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  118. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  119. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  120. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  121. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  122. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  123. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +4 -4
  124. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  125. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  126. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  127. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  128. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  129. package/src/modules/toolbar/search/rank.ts +111 -0
  130. package/src/modules/toolbar/search/sources.ts +169 -0
  131. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  132. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  133. package/src/modules/workflow/services/lock.api.ts +17 -2
  134. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  135. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  136. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  137. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  138. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  139. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  140. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  141. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  142. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +101 -11
  143. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  144. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  145. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  146. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  147. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  148. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  149. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  150. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  151. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  152. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  153. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  154. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  155. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  156. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  157. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  158. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  159. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  160. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  161. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  162. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  163. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  164. package/src/modules/workspace/components/renderers/index.ts +26 -0
  165. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  166. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  167. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  168. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  169. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  170. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  171. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  172. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  173. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  174. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  175. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  176. package/src/modules/workspace/state/editable-page.ts +42 -0
  177. package/src/modules/workspace/state/workspace.context.ts +13 -4
  178. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  179. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  180. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +26 -14
  181. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  182. package/src/modules/workspace/utils/fileTree.ts +49 -14
  183. package/src/modules/workspace/utils/treeConfirm.ts +22 -5
  184. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  185. package/src/shared/components/ConfirmProvider.tsx +156 -0
  186. package/src/shared/components/Dialog.tsx +7 -0
  187. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  188. package/src/shared/components/confirm-context.ts +94 -0
  189. package/src/shared/components/index.ts +3 -0
  190. package/src/shared/mcp/__tests__/connect-snippets.test.ts +2 -2
  191. package/src/shared/mcp/connect-snippets.ts +8 -5
  192. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  193. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -1,15 +1,22 @@
1
1
  import { useMemo, useCallback, useContext, useEffect, useRef, useState } from 'react';
2
- import { Check, XCircle, Lock, AlertTriangle, ArrowLeft, FileText, History } from 'lucide-react';
3
- import type { FileTreeEntry, PullRequestSummary } from '@bevel-software/platform-shared';
2
+ import { Check, XCircle, Pencil, AlertTriangle, ArrowLeft, FileText, History, Users } from 'lucide-react';
3
+ import {
4
+ KNOWLEDGE_BASE_DIR,
5
+ currentBranchModel,
6
+ type FileTreeEntry,
7
+ type PullRequestSummary,
8
+ } from '@bevel-software/platform-shared';
4
9
  import { useWorkspace } from '../state/workspace.context';
10
+ import { publishEditablePage, withdrawEditablePage } from '../state/editable-page';
5
11
  import { EditorTabs } from './EditorTabs';
6
12
  import { KbPageHeader } from './KbPageHeader';
7
13
  import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
8
14
  import { Banner, Button, IconButton, Surface, useFocusHandoff } from '../../../shared/components';
15
+ import { displayFileName, fileNameTooltip, isAccessRulesFile } from '../utils/display-file-name';
9
16
  import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
10
17
  import { useGit } from '../../git/state/git.context';
11
18
  import { LayoutContext } from '../../layout/state/layout.context';
12
- import { useParams } from 'react-router-dom';
19
+ import { useLocation, useNavigate, useParams } from 'react-router-dom';
13
20
  import { useCanonicalFileUrl, useFileNav } from '../routing/kb-routes';
14
21
  import { PullNeededBanner } from '../../git/components/PullNeededBanner';
15
22
  import { GitSyncFailedBanner } from '../../git/components/GitSyncFailedBanner';
@@ -38,12 +45,14 @@ import { ChangeRequestDialog } from '../../change-requests/components/ChangeRequ
38
45
  import { formatEligible } from '../../access/hooks/useFileAccess';
39
46
  import { PR_STALE_EVENT } from '../../../core/events';
40
47
  import { suggestedPages } from '../utils/fileTree';
41
- import { getFileRenderer, getRendererLayout, isViewOnlyFile } from './renderers';
48
+ import { getRendererLayout, isViewOnlyFile, pickFileRenderer } from './renderers';
42
49
  import { READ_PANE } from './renderers/readPane';
43
50
  import { CanDownloadContext } from './renderers/DownloadFileButton';
44
51
  import type { RendererSaveState } from './renderers';
45
52
  import { KbDocumentShell } from './KbDocumentShell';
46
53
  import { FilePaneCard } from './FilePaneCard';
54
+ import { StarterPackCard } from '../../onboarding/components/StarterPackCard';
55
+ import { useStarterPacks } from '../../onboarding/state/starter-packs';
47
56
 
48
57
  /**
49
58
  * How many pages the empty viewer offers. Enough to look like a starting
@@ -53,8 +62,20 @@ import { FilePaneCard } from './FilePaneCard';
53
62
  const SUGGESTION_LIMIT = 4;
54
63
 
55
64
  /** What a page is called, without the extension the reader did not choose. */
56
- function pageTitle(fileName: string): string {
57
- return fileName.replace(/\.(md|markdown)$/i, '');
65
+ function pageTitle(path: string, kbDirName: string | null): string {
66
+ return displayFileName(path, kbDirName).replace(/\.(md|markdown)$/i, '');
67
+ }
68
+
69
+ /**
70
+ * What an access rules file governs, said the way the explorer names it: the
71
+ * folder's own name, "Knowledge" for the knowledge section, and the whole
72
+ * knowledge base for the one at its top.
73
+ */
74
+ function governedFolderLabel(folder: string, kbDirName: string | null): string {
75
+ if (kbDirName && folder === kbDirName) return 'everything in this knowledge base';
76
+ const rel = kbDirName && folder.startsWith(`${kbDirName}/`) ? folder.slice(kbDirName.length + 1) : folder;
77
+ if (rel === KNOWLEDGE_BASE_DIR) return 'everything in Knowledge';
78
+ return rel.slice(rel.lastIndexOf('/') + 1);
58
79
  }
59
80
 
60
81
  /** The folder a page sits in, or '' for one that sits at a root. */
@@ -67,6 +88,7 @@ export function FileViewer() {
67
88
  workspaceId,
68
89
  kbDirName,
69
90
  fileTree,
91
+ workspaceBranch,
70
92
  openFilePath,
71
93
  openFileContent,
72
94
  openFileSavedContent,
@@ -146,12 +168,10 @@ export function FileViewer() {
146
168
  // Registry renderer overrides win over the built-in extension map — the
147
169
  // enterprise registry swaps in its own `.html` renderer (vendored d3/mermaid
148
170
  // + KB graph client) this way.
149
- const Renderer = useMemo(() => {
150
- if (!openFilePath) return null;
151
- const ext = openFilePath.slice(openFilePath.lastIndexOf('.')).toLowerCase();
152
- const override = renderers.find((r) => r.extensions.includes(ext));
153
- return override?.Component ?? getFileRenderer(openFilePath);
154
- }, [openFilePath, renderers]);
171
+ const Renderer = useMemo(
172
+ () => (openFilePath ? pickFileRenderer(openFilePath, renderers) : null),
173
+ [openFilePath, renderers],
174
+ );
155
175
 
156
176
  const [isSubmitting, setIsSubmitting] = useState(false);
157
177
  const [activeTab, setActiveTab] = useState<'content' | 'history' | 'compare'>('content');
@@ -470,7 +490,18 @@ export function FileViewer() {
470
490
  // one, an old request's `.finally(() => setIsEnteringEdit(false))`
471
491
  // would clobber the new request's "Loading…" state on the new file.
472
492
  const enterEditRequestRef = useRef(0);
473
- const handleEnterEditMode = useCallback(() => {
493
+ // The file whose editor should open with the caret at the end — see the
494
+ // effect beside `editorContainerRef`. Set only at the moment an enter-edit
495
+ // flow that asked for it SUCCEEDS, so a request the lock, the branch or the
496
+ // reload turned away leaves nothing behind for a later Edit by hand to trip.
497
+ const caretToEndForRef = useRef<string | null>(null);
498
+ /**
499
+ * Enter edit mode, the way the Edit button does. `caretToEnd` is the
500
+ * `startEditing` request's: put the caret at the end of the page once the
501
+ * editor is up (see the caret effect). The button itself goes through
502
+ * `handleEnterEditMode`, which never asks for that.
503
+ */
504
+ const enterEditMode = useCallback((caretToEnd: boolean) => {
474
505
  if (editMode || isEnteringEdit || !openFilePath || onProtectedBranch || isReviewingPending) return;
475
506
  // **Non-optimistic on entry.** We acquire the lock + reload disk
476
507
  // bytes FIRST, then flip into edit mode. The optimistic path —
@@ -489,8 +520,9 @@ export function FileViewer() {
489
520
  .then(async ({ acquired, contended, error }) => {
490
521
  if (!acquired) {
491
522
  // Two failure shapes:
492
- // - Contention (`contended`): held by someone else → the "Locked
493
- // by X" banner (below) already explains it; don't double-report.
523
+ // - Contention (`contended`): held by someone else → the "X is
524
+ // editing this page" banner (below) already explains it; don't
525
+ // double-report.
494
526
  // - Access-denied 403 / network (`error`, not contended): surface
495
527
  // it. `useFileAccess` default-allows on a transient lookup
496
528
  // failure, so the editor lets the user click Edit even when the
@@ -528,6 +560,7 @@ export function FileViewer() {
528
560
  // Stale-request check — file may have switched while we were
529
561
  // reloading. Don't flip editMode for the wrong file.
530
562
  if (!isStillCurrent()) return;
563
+ caretToEndForRef.current = caretToEnd ? targetPath : null;
531
564
  setEditMode(true);
532
565
  })
533
566
  .catch((err) => {
@@ -543,6 +576,92 @@ export function FileViewer() {
543
576
  }
544
577
  });
545
578
  }, [editMode, isEnteringEdit, openFilePath, onProtectedBranch, isReviewingPending, fileLock, reloadTabFromDisk]);
579
+ const handleEnterEditMode = useCallback(() => enterEditMode(false), [enterEditMode]);
580
+
581
+ /**
582
+ * Opening straight into edit mode, when the navigation asked for it
583
+ * (`openWorkspacePath(path, { edit: true })` — a page just created, there
584
+ * to be written). The request is router state (`startEditing`, the key the
585
+ * skill page already answers to), so no URL ever carries it.
586
+ *
587
+ * It is honoured the way a click on Edit would be, through
588
+ * `enterEditMode` — the lock and the fresh read are not skipped — and
589
+ * only once the request can be judged: the file it was made for is the one
590
+ * open, with bytes, on a known branch, and the access lookup has answered
591
+ * (`canWrite` null is "not asked yet", and acting on it would be a guess).
592
+ *
593
+ * "The file it was made for" is `startEditingPath` when the request names
594
+ * one, and the URL's path otherwise. The URL alone is not enough: a path
595
+ * URL is canonicalised to the node's id URL (`FileRoute`), sometimes before
596
+ * the file's bytes land, and from then on the URL names the id, not the
597
+ * path that is open.
598
+ *
599
+ * Then it is CONSUMED — replaced out of the history entry, other state
600
+ * kept — whether or not editing was allowed, so a refresh or a Back to this
601
+ * entry opens the page for reading like any other. The ref covers the beat
602
+ * before the replace lands (and StrictMode's second effect pass).
603
+ */
604
+ const location = useLocation();
605
+ const navigate = useNavigate();
606
+ const routePath = useParams<{ '*': string }>()['*'] ?? '';
607
+ const editRequest = location.state as { startEditing?: boolean; startEditingPath?: string } | null;
608
+ const startEditingRequested = editRequest?.startEditing === true;
609
+ const startEditingPath = editRequest?.startEditingPath ?? routePath;
610
+ const consumedEditRequestRef = useRef<string | null>(null);
611
+ useEffect(() => {
612
+ if (!startEditingRequested || consumedEditRequestRef.current === location.key) return;
613
+ if (!openFilePath || openFilePath !== startEditingPath || openFileContent === null || !Renderer) return;
614
+ if (currentBranch === null || access.canWrite === null) return;
615
+ consumedEditRequestRef.current = location.key;
616
+ const rest = { ...(location.state as Record<string, unknown>) };
617
+ delete rest.startEditing;
618
+ delete rest.startEditingPath;
619
+ navigate(
620
+ { pathname: location.pathname, search: location.search, hash: location.hash },
621
+ { replace: true, state: Object.keys(rest).length > 0 ? rest : null },
622
+ );
623
+ if (!isViewOnlyFile(openFilePath)) {
624
+ // A one-shot reaction to the router's state, not derived state: this is
625
+ // the Edit click the navigation asked for, made once its file is ready.
626
+ // eslint-disable-next-line react-hooks/set-state-in-effect
627
+ enterEditMode(true);
628
+ }
629
+ }, [
630
+ startEditingRequested,
631
+ location,
632
+ navigate,
633
+ startEditingPath,
634
+ openFilePath,
635
+ openFileContent,
636
+ Renderer,
637
+ currentBranch,
638
+ access.canWrite,
639
+ enterEditMode,
640
+ ]);
641
+
642
+ // Tell the command menu whether "Edit this page" would do anything — the
643
+ // same conditions the Edit button is drawn and enabled by (see
644
+ // `editable-page.ts`), the content tab included: over History or Compare
645
+ // the button is not drawn, and the menu offers nothing the page does not.
646
+ // `canWrite` null is the button's optimistic Edit too.
647
+ const lockHolder = fileLock.externalLock?.holderName ?? null;
648
+ const editableNow =
649
+ openFilePath !== null &&
650
+ openFileContent !== null &&
651
+ !!Renderer &&
652
+ !isViewOnlyFile(openFilePath) &&
653
+ activeTab === 'content' &&
654
+ !editMode &&
655
+ !isEnteringEdit &&
656
+ !proposeMode &&
657
+ !isReviewingPending &&
658
+ access.canWrite !== false &&
659
+ lockHolder === null;
660
+ useEffect(() => {
661
+ if (!editableNow || !openFilePath) return;
662
+ publishEditablePage(openFilePath);
663
+ return () => withdrawEditablePage(openFilePath);
664
+ }, [editableNow, openFilePath]);
546
665
 
547
666
  const handleExitEditMode = useCallback(() => {
548
667
  if (!editMode) return;
@@ -758,7 +877,7 @@ export function FileViewer() {
758
877
  // Read the message off the resolved outcome, not `fileLock.lockError`
759
878
  // — that's React state and is stale in this closure right after the
760
879
  // await. Covers both the access-denied 403 and lock-contention cases.
761
- throw new Error(error ?? 'File is locked by another user.');
880
+ throw new Error(error ?? 'Someone else is editing this page.');
762
881
  }
763
882
  try {
764
883
  await fileLock.saveAndRelease();
@@ -804,6 +923,20 @@ export function FileViewer() {
804
923
  return () => el.removeEventListener('scroll', onScroll, { capture: true } as EventListenerOptions);
805
924
  }, [editMode, recordActivity]);
806
925
 
926
+ // A page opened for writing (the `startEditing` request above) gets the
927
+ // caret at its END — under the title it was created with — rather than
928
+ // where a freshly focused textarea puts it, in front of the `#`. Only for
929
+ // that request: Edit on an existing page by hand leaves the caret alone,
930
+ // since jumping to the end of a long document would scroll the reader away.
931
+ useEffect(() => {
932
+ if (!editMode || !openFilePath || caretToEndForRef.current !== openFilePath) return;
933
+ caretToEndForRef.current = null;
934
+ const textarea = editorContainerRef.current?.querySelector('textarea');
935
+ if (!textarea) return;
936
+ textarea.focus();
937
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
938
+ }, [editMode, openFilePath]);
939
+
807
940
  // No-op save when previewing pending content — don't let edits go through during review
808
941
  const handlePendingSave = useCallback(async () => {}, []);
809
942
 
@@ -862,6 +995,23 @@ export function FileViewer() {
862
995
  });
863
996
  }, [openFilePath]);
864
997
 
998
+ // An access rules file is its FOLDER's access, written down. Its page says
999
+ // so, and hands over the sheet that edits it: Manage access on the folder,
1000
+ // the same sheet the folder's row in the tree opens. (Share in the header
1001
+ // stays what it is on every page, access to this one file.)
1002
+ const accessFolder =
1003
+ openFilePath && isAccessRulesFile(openFilePath) && openFilePath.includes('/')
1004
+ ? openFilePath.slice(0, openFilePath.lastIndexOf('/'))
1005
+ : null;
1006
+ const handleManageFolderAccess = useCallback(() => {
1007
+ if (!accessFolder) return;
1008
+ setShareTarget({
1009
+ name: accessFolder.slice(accessFolder.lastIndexOf('/') + 1),
1010
+ relativePath: accessFolder,
1011
+ type: 'directory',
1012
+ });
1013
+ }, [accessFolder]);
1014
+
865
1015
  // Where to start, for a viewer with nothing open. Computed here rather than
866
1016
  // in the empty branch below because that branch is a `return` and this is a
867
1017
  // hook — and it costs nothing while a file IS open, which is the common case.
@@ -869,6 +1019,26 @@ export function FileViewer() {
869
1019
  () => suggestedPages(fileTree, kbDirName, SUGGESTION_LIMIT),
870
1020
  [fileTree, kbDirName],
871
1021
  );
1022
+ // A new knowledge base's admin is asked "What does your team do?" here in
1023
+ // place of the empty state, for as long as the server offers it (admins
1024
+ // only, until somebody answers, while the knowledge base is still new).
1025
+ // What the chosen pack added is said once, above the ordinary empty state
1026
+ // that then suggests its pages.
1027
+ //
1028
+ // Only on the default branch: the server lands the pack on the default
1029
+ // branch whatever branch the viewer shows, so asked from a draft the card
1030
+ // would promise pages here and put them somewhere else. The ordinary empty
1031
+ // state stands in on every other branch, and the question waits on the
1032
+ // default one.
1033
+ const starterPacks = useStarterPacks();
1034
+ const [starterNote, setStarterNote] = useState<string | null>(null);
1035
+ const onDefaultBranch = workspaceBranch !== null && workspaceBranch === currentBranchModel().defaultBranch;
1036
+ const starterOffer = starterPacks.answer?.offered && onDefaultBranch ? starterPacks.answer.packs : [];
1037
+ // Until the server has answered (and, when it offers the question, until
1038
+ // the branch is known) the pane shows neither: the reading empty state
1039
+ // would flash under an admin for the length of one request, suggestions
1040
+ // and all, before the question replaced it.
1041
+ const starterPending = !starterPacks.settled || (starterPacks.answer?.offered === true && workspaceBranch === null);
872
1042
  // Opening a suggestion is NAVIGATION, the same as clicking the file in the
873
1043
  // explorer or a tab: the URL is the canonical record of what is open, and a
874
1044
  // refresh, share or back-press must land on the page — not on the empty
@@ -904,57 +1074,68 @@ export function FileViewer() {
904
1074
  <GitSyncFailedBanner />
905
1075
  <EditorTabs />
906
1076
  <div className="flex-1 flex items-center justify-center px-6">
907
- <div className="w-full max-w-md text-center">
908
- <h2 className="mb-2 text-head text-ink">Open a page to start reading.</h2>
909
- <p className="mb-6 text-ui text-ink-muted">
910
- {suggestions.length > 0
911
- ? 'Pick anything from the file tree, or start with one of these.'
912
- : 'Pick anything from the file tree.'}
913
- </p>
914
- {/* Real pages, not prompts. Whoever lands here has a file tree and
915
- a blank pane, and "browse until something looks right" is the
916
- one instruction the tree already gives — so the suggestions are
917
- documents that open, drawn from the top of the knowledge the
918
- deployment actually holds. */}
919
- {suggestions.length > 0 && (
920
- <div className="flex flex-col gap-2 text-left">
921
- {suggestions.map((page) => {
922
- const folder = parentFolder(page.relativePath);
923
- return (
924
- <Surface
925
- key={page.relativePath}
926
- as="button"
927
- tone="sunken"
928
- radius="lg"
929
- elevation="none"
930
- interactive
931
- type="button"
932
- onClick={() => openWorkspacePath(page.relativePath)}
933
- disabled={!navReady}
934
- className="flex items-center gap-2.5 px-3 py-2"
935
- >
936
- <FileText size={15} className="shrink-0 text-ink-faint" aria-hidden />
937
- <span className="min-w-0 flex-1 truncate text-ui text-ink">
938
- {pageTitle(page.name)}
939
- </span>
940
- {/* The folder it sits in — two pages can share a name,
941
- and the one thing that tells them apart is where they
942
- live. */}
943
- {/* Capped so a long folder name truncates instead of
944
- squeezing out the page title it is there to
945
- disambiguate — same contract as the comparison
946
- panel's path label. */}
947
- {folder && (
948
- <span className="max-w-[40%] shrink-0 truncate text-meta text-ink-faint">
949
- {folder}
1077
+ {starterOffer.length > 0 ? (
1078
+ <div className="w-full max-w-md">
1079
+ <StarterPackCard packs={starterOffer} onDone={(applied) => setStarterNote(applied.summary || null)} />
1080
+ </div>
1081
+ ) : starterPending ? null : (
1082
+ <div className="w-full max-w-md text-center">
1083
+ {starterNote && (
1084
+ <p role="status" className="mb-4 text-ui text-ok">
1085
+ {starterNote}
1086
+ </p>
1087
+ )}
1088
+ <h2 className="mb-2 text-head text-ink">Open a page to start reading.</h2>
1089
+ <p className="mb-6 text-ui text-ink-muted">
1090
+ {suggestions.length > 0
1091
+ ? 'Pick anything from the file tree, or start with one of these.'
1092
+ : 'Pick anything from the file tree.'}
1093
+ </p>
1094
+ {/* Real pages, not prompts. Whoever lands here has a file tree and
1095
+ a blank pane, and "browse until something looks right" is the
1096
+ one instruction the tree already gives — so the suggestions are
1097
+ documents that open, drawn from the top of the knowledge the
1098
+ deployment actually holds. */}
1099
+ {suggestions.length > 0 && (
1100
+ <div className="flex flex-col gap-2 text-left">
1101
+ {suggestions.map((page) => {
1102
+ const folder = parentFolder(page.relativePath);
1103
+ return (
1104
+ <Surface
1105
+ key={page.relativePath}
1106
+ as="button"
1107
+ tone="sunken"
1108
+ radius="lg"
1109
+ elevation="none"
1110
+ interactive
1111
+ type="button"
1112
+ onClick={() => openWorkspacePath(page.relativePath)}
1113
+ disabled={!navReady}
1114
+ className="flex items-center gap-2.5 px-3 py-2"
1115
+ >
1116
+ <FileText size={15} className="shrink-0 text-ink-faint" aria-hidden />
1117
+ <span className="min-w-0 flex-1 truncate text-ui text-ink">
1118
+ {pageTitle(page.relativePath, kbDirName)}
950
1119
  </span>
951
- )}
952
- </Surface>
953
- );
954
- })}
955
- </div>
956
- )}
957
- </div>
1120
+ {/* The folder it sits in — two pages can share a name,
1121
+ and the one thing that tells them apart is where they
1122
+ live. */}
1123
+ {/* Capped so a long folder name truncates instead of
1124
+ squeezing out the page title it is there to
1125
+ disambiguate — same contract as the comparison
1126
+ panel's path label. */}
1127
+ {folder && (
1128
+ <span className="max-w-[40%] shrink-0 truncate text-meta text-ink-faint">
1129
+ {folder}
1130
+ </span>
1131
+ )}
1132
+ </Surface>
1133
+ );
1134
+ })}
1135
+ </div>
1136
+ )}
1137
+ </div>
1138
+ )}
958
1139
  </div>
959
1140
  {registeredPanels}
960
1141
  </div>
@@ -981,8 +1162,9 @@ export function FileViewer() {
981
1162
 
982
1163
  // What the pane card's bar names — extension kept, unlike the `<h1>` above,
983
1164
  // because the bar is the technical label (`SKILL.md`, `How to get
984
- // started.md`) exactly as the skill page's file bar renders it.
985
- const fileBaseName = openFilePath.slice(openFilePath.lastIndexOf('/') + 1);
1165
+ // started.md`) exactly as the skill page's file bar renders it. A platform
1166
+ // file is the exception: it reads by its plain name, its real one on hover.
1167
+ const fileBaseName = displayFileName(openFilePath, kbDirName);
986
1168
 
987
1169
  // The repo-relative path (kbDirName stripped) — what the change-request
988
1170
  // machinery speaks. Null for files outside the KB clone, which cannot have
@@ -1006,8 +1188,8 @@ export function FileViewer() {
1006
1188
  // above — not a component created during render. The provider hands the
1007
1189
  // open file's `download:` verdict to any DownloadFileButton inside the
1008
1190
  // renderer without widening the renderer contract.
1009
- // eslint-disable-next-line react-hooks/static-components
1010
1191
  <CanDownloadContext.Provider value={access.canDownload}>
1192
+ {/* eslint-disable-next-line react-hooks/static-components */}
1011
1193
  <Renderer
1012
1194
  // **Why we key on `openFileSavedContent` (read-only mode only).**
1013
1195
  // When a teammate's save lands, the workspace state updates the
@@ -1119,9 +1301,9 @@ export function FileViewer() {
1119
1301
  onClick={handleEnterEditMode}
1120
1302
  title={
1121
1303
  lockedBy
1122
- ? `Locked by ${lockedBy}`
1304
+ ? `${lockedBy} is editing this page`
1123
1305
  : isEnteringEdit
1124
- ? 'Acquiring lock and fetching latest content…'
1306
+ ? 'Getting the latest version…'
1125
1307
  : 'Click to edit this file'
1126
1308
  }
1127
1309
  >
@@ -1188,6 +1370,7 @@ export function FileViewer() {
1188
1370
  header={
1189
1371
  <KbPageHeader
1190
1372
  path={openFilePath}
1373
+ kbDirName={kbDirName}
1191
1374
  canWrite={access.canWrite}
1192
1375
  editMode={editMode}
1193
1376
  entering={isEnteringEdit}
@@ -1276,6 +1459,20 @@ export function FileViewer() {
1276
1459
  </div>
1277
1460
  </Banner>
1278
1461
  )}
1462
+ {accessFolder && (
1463
+ <Banner role="note" tone="neutral" icon={<Users size={14} />} className="mb-4 flex-none">
1464
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-2">
1465
+ <span className="flex-1">
1466
+ This file controls who can see and change{' '}
1467
+ <span className="font-medium">{governedFolderLabel(accessFolder, kbDirName)}</span>.
1468
+ Change it with Manage access.
1469
+ </span>
1470
+ <Button variant="outline" size="sm" onClick={handleManageFolderAccess}>
1471
+ Manage access
1472
+ </Button>
1473
+ </div>
1474
+ </Banner>
1475
+ )}
1279
1476
  {/* Propose mode's one-line contract: where the text goes, and that
1280
1477
  nothing on this page changes until someone with write access
1281
1478
  says yes. Shown INSTEAD of the access-restricted banner. */}
@@ -1367,12 +1564,12 @@ export function FileViewer() {
1367
1564
  <Banner
1368
1565
  role="status"
1369
1566
  tone="wait"
1370
- icon={<Lock size={14} />}
1567
+ icon={<Pencil size={14} />}
1371
1568
  aria-live="polite"
1372
1569
  aria-atomic="true"
1373
1570
  className="mb-4 flex-none"
1374
1571
  >
1375
- Locked by <span className="font-medium">{fileLock.externalLock.holderName}</span>. The editor is read-only until they finish.
1572
+ <span className="font-medium">{fileLock.externalLock.holderName}</span> is editing this page. You can edit it when they finish.
1376
1573
  </Banner>
1377
1574
  )}
1378
1575
 
@@ -1440,7 +1637,7 @@ export function FileViewer() {
1440
1637
  >
1441
1638
  {shellVariant === 'prose' ? (
1442
1639
  <>
1443
- <FilePaneCard file={fileBaseName} actions={paneActions}>
1640
+ <FilePaneCard file={fileBaseName} fileTitle={fileNameTooltip(openFilePath, kbDirName)} actions={paneActions}>
1444
1641
  {rendererElement}
1445
1642
  </FilePaneCard>
1446
1643
  {/* Every open proposal on this file, under the file it is
@@ -16,6 +16,7 @@ import { Badge, Button, IconButton, MenuItem, MenuPanel } from '../../../shared/
16
16
  import { useDismissableMenu } from '../../../shared/components';
17
17
  import { HEADER_BAND, PAGE_HEADER_TESTID } from '../../../shared/theme/header';
18
18
  import { rootAnchoredPath } from '../utils/pasteLink';
19
+ import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
19
20
 
20
21
  /**
21
22
  * The document's title, and the page's actions beside it.
@@ -36,7 +37,9 @@ import { rootAnchoredPath } from '../utils/pasteLink';
36
37
  const KNOWN_EXTENSIONS =
37
38
  /\.(md|markdown|txt|csv|tsv|json|yaml|yml|html|htm|pdf|docx|xlsx|pptx|doc|ppt|xls|odt|odp|ods|eml|msg|tool|png|jpe?g|gif|webp|svg)$/i;
38
39
 
39
- function titleOf(path: string): string {
40
+ /** A platform file keeps its plain name whole: "Plugin settings", not a stripped file name. */
41
+ function titleOf(path: string, kbDirName: string | null): string {
42
+ if (fileNameTooltip(path, kbDirName) !== undefined) return displayFileName(path, kbDirName);
40
43
  const base = path.slice(path.lastIndexOf('/') + 1);
41
44
  return base.replace(KNOWN_EXTENSIONS, '');
42
45
  }
@@ -44,6 +47,8 @@ function titleOf(path: string): string {
44
47
  export interface KbPageHeaderProps {
45
48
  /** Workspace-relative. */
46
49
  path: string;
50
+ /** The clone folder `path` starts with; what tells a plugin's own manifest from any other `plugin.json`. */
51
+ kbDirName: string | null;
47
52
  /**
48
53
  * `boolean | null` — NOT boolean. `useFileAccess` returns null while the
49
54
  * lookup is in flight, null when there is no path / kbDirName / workspaceId,
@@ -145,6 +150,7 @@ const COPY_FEEDBACK_MS = 1800;
145
150
 
146
151
  export function KbPageHeader({
147
152
  path,
153
+ kbDirName,
148
154
  canWrite,
149
155
  editMode,
150
156
  entering,
@@ -243,11 +249,12 @@ export function KbPageHeader({
243
249
  ref={titleRef}
244
250
  tabIndex={-1}
245
251
  // `title` because `truncate` hides the rest of a long file name, and
246
- // a heading you cannot finish reading needs somewhere to say it.
247
- title={titleOf(path)}
252
+ // a heading you cannot finish reading needs somewhere to say it. A
253
+ // platform file shown by its plain name hovers its real one.
254
+ title={fileNameTooltip(path, kbDirName) ?? titleOf(path, kbDirName)}
248
255
  className="min-w-0 truncate text-display font-semibold text-ink focus:outline-none"
249
256
  >
250
- {titleOf(path)}
257
+ {titleOf(path, kbDirName)}
251
258
  </h1>
252
259
 
253
260
  {/* The three chips the deleted strip used to carry. */}
@@ -420,9 +427,9 @@ export function KbPageHeader({
420
427
  disabled={!!lockedBy || entering}
421
428
  title={
422
429
  lockedBy
423
- ? `Locked by ${lockedBy}`
430
+ ? `${lockedBy} is editing this page`
424
431
  : entering
425
- ? 'Acquiring lock and fetching latest content…'
432
+ ? 'Getting the latest version…'
426
433
  : 'Click to edit this file'
427
434
  }
428
435
  onClick={onEdit}