@bevel-software/platform-core-frontend 0.34.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +40 -97
  3. package/src/core/KnowledgeSurface.tsx +92 -0
  4. package/src/core/__tests__/CoreAppShell.root-claims.test.tsx +280 -0
  5. package/src/core/registry.ts +110 -2
  6. package/src/index.ts +3 -0
  7. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +1 -1
  8. package/src/modules/access/api.ts +24 -4
  9. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  10. package/src/modules/access/index.ts +1 -1
  11. package/src/modules/admin/index.ts +1 -1
  12. package/src/modules/agents/components/ConnectAsChoice.tsx +7 -0
  13. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +4 -3
  14. package/src/modules/audit/components/AuditLogPage.tsx +6 -4
  15. package/src/modules/audit/components/principal-grouping.ts +49 -49
  16. package/src/modules/auth/index.ts +1 -1
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +1 -1
  18. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +6 -6
  19. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +8 -8
  20. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
  21. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
  22. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +1 -1
  23. package/src/modules/git/__tests__/pr.api.test.ts +3 -3
  24. package/src/modules/git/components/FileHistoryPanel.tsx +1 -1
  25. package/src/modules/git/components/GitSyncFailedBanner.tsx +1 -1
  26. package/src/modules/git/services/git.api.ts +1 -1
  27. package/src/modules/git/services/pr-prompts.ts +1 -1
  28. package/src/modules/layout/state/layout.context.ts +8 -0
  29. package/src/modules/library/__tests__/SkillPage.test.tsx +5 -5
  30. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +11 -0
  31. package/src/modules/library/__tests__/ToolVarRow.test.tsx +160 -5
  32. package/src/modules/library/components/tool-page/ToolVarRow.tsx +103 -28
  33. package/src/modules/library/services/library.api.ts +2 -2
  34. package/src/modules/onboarding/__tests__/onboarding.test.tsx +8 -8
  35. package/src/modules/onboarding/state/agent-connection.ts +1 -1
  36. package/src/modules/pr/services/pr-merge.api.ts +1 -1
  37. package/src/modules/pr/services/pr-open.api.ts +1 -1
  38. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +96 -30
  39. package/src/modules/secrets-vault/components/IncludeToggle.tsx +29 -0
  40. package/src/modules/secrets-vault/components/ManagedConnectorCard.tsx +189 -0
  41. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.managed.test.tsx +212 -0
  42. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +10 -0
  43. package/src/modules/secrets-vault/components/__tests__/ManagedConnectorCard.test.tsx +182 -0
  44. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +3 -0
  45. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +1 -0
  46. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -0
  47. package/src/modules/secrets-vault/index.ts +2 -0
  48. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +1 -0
  49. package/src/modules/secrets-vault/services/connect.api.ts +46 -5
  50. package/src/modules/secrets-vault/services/tool-secrets.api.ts +21 -3
  51. package/src/modules/secrets-vault/utils/managed-card-state.ts +61 -0
  52. package/src/modules/setup/utils/__tests__/root-folders.test.ts +5 -1
  53. package/src/modules/setup/utils/root-folders.ts +2 -2
  54. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +8 -1
  55. package/src/modules/toolbar/components/Toolbar.tsx +1 -1
  56. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +39 -13
  57. package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.test.tsx +10 -10
  58. package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.wire.test.tsx +1 -1
  59. package/src/modules/{workflow → version-control}/hooks/useEventBusSubscription.ts +2 -2
  60. package/src/modules/{workflow → version-control}/hooks/useFileLock.ts +1 -1
  61. package/src/modules/{workflow → version-control}/index.ts +2 -2
  62. package/src/modules/{workflow → version-control}/services/__tests__/lock.api.test.ts +1 -1
  63. package/src/modules/{workflow → version-control}/state/EventBusProvider.tsx +6 -6
  64. package/src/modules/{workflow → version-control}/state/event-bus.context.ts +4 -4
  65. package/src/modules/workspace/components/FileExplorer.tsx +96 -41
  66. package/src/modules/workspace/components/FileRoute.tsx +24 -1
  67. package/src/modules/workspace/components/FileViewer.tsx +2 -2
  68. package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
  69. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +191 -21
  70. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +50 -2
  71. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +5 -5
  72. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +5 -5
  73. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +9 -9
  74. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +7 -7
  75. package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
  76. package/src/modules/workspace/hooks/useWorkspaceState.ts +2 -2
  77. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +9 -9
  78. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +9 -1
  79. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +32 -48
  80. package/src/modules/workspace/utils/fileTree.ts +10 -2
  81. package/src/modules/workspace/utils/treeConfirm.ts +25 -29
  82. /package/src/modules/{workflow → version-control}/services/lock.api.ts +0 -0
  83. /package/src/modules/{workflow → version-control}/state/ChangeRequestStaleBinder.tsx +0 -0
  84. /package/src/modules/{workflow → version-control}/state/EventBusFocusBinder.tsx +0 -0
  85. /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.storage.test.tsx +0 -0
  86. /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.watch.test.tsx +0 -0
@@ -13,16 +13,17 @@ import {
13
13
  type WorkspaceContextValue,
14
14
  } from '../../state/workspace.context';
15
15
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
16
- import { GitContext, type GitContextValue } from '../../../git/state/git.context';
17
- import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
16
+ import { GitContext, type GitContextValue } from '../../../git';
17
+ import { AuthContext, type AuthContextValue } from '../../../auth';
18
18
  import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
19
- import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
19
+ import { AdminContext, type AdminContextValue } from '../../../admin';
20
20
  import { PR_STALE_EVENT } from '../../../../core/events';
21
- import { EventBusProvider } from '../../../workflow';
22
- import type { WorkflowEvent } from '@bevel-software/platform-shared';
21
+ import { EventBusProvider } from '../../../version-control';
22
+ import type { VersionControlEvent } from '@bevel-software/platform-shared';
23
23
  import {
24
24
  AppRegistryContext,
25
25
  makeRegistry,
26
+ type AppDef,
26
27
  type FolderMenuContext,
27
28
  type FolderMenuItemDef,
28
29
  type FolderMenuTools,
@@ -44,10 +45,14 @@ const cancelMocks = vi.hoisted(() => ({
44
45
  cancelPullRequest: vi.fn(),
45
46
  deleteChangeRequest: vi.fn(),
46
47
  }));
47
- vi.mock('../../../pr/services/pr-cancel.api', () => cancelMocks);
48
+ vi.mock('../../../pr', async (importOriginal) => ({ ...(await importOriginal<typeof import('../../../pr')>()), ...cancelMocks }));
48
49
 
49
50
  // The sheet itself is covered by the access module's own tests; here only
50
51
  // WHICH workspace and proposal the tree hands it matters.
52
+ // A component is composed by importing its file, never through a module's
53
+ // index (the Module Map's one allowance for React components), so the
54
+ // component's file is the surface the tree reaches it through, and the one a
55
+ // mock stands in for.
51
56
  vi.mock('../../../access/components/ManageAccessDialog', () => ({
52
57
  ManageAccessDialog: (props: {
53
58
  entry: FileTreeEntry;
@@ -196,6 +201,10 @@ interface RenderOptions {
196
201
  * empty, which is what every other test in this file renders against.
197
202
  */
198
203
  folderMenuItems?: FolderMenuItemDef[];
204
+ /** Apps in the registry — the ones whose `roots` claim top-level folders. */
205
+ apps?: AppDef[];
206
+ /** Render the narrowed tree an app mounts for its roots. */
207
+ roots?: string[];
199
208
  /** The workspace id — the encoded branch name, so it decides "protected". */
200
209
  workspaceId?: string;
201
210
  openFilePath?: string | null;
@@ -281,7 +290,7 @@ function renderExplorer(opts: RenderOptions = {}) {
281
290
  // the fixture must not hand out a pair that cannot exist.
282
291
  workspaceBranch: decodeURIComponent(opts.workspaceId ?? 'ws-1'),
283
292
  });
284
- const registry = makeRegistry({ folderMenuItems: opts.folderMenuItems ?? [] });
293
+ const registry = makeRegistry({ folderMenuItems: opts.folderMenuItems ?? [], apps: opts.apps ?? [] });
285
294
  const ui = (ws: WorkspaceContextValue, mine: Map<string, number>) => (
286
295
  <MemoryRouter initialEntries={opts.initialEntries ?? ['/']}>
287
296
  <AppRegistryContext.Provider value={registry}>
@@ -318,7 +327,7 @@ function renderExplorer(opts: RenderOptions = {}) {
318
327
  mineNumbers: new Set(opts.mineNumbers ?? [...mine.values()]),
319
328
  }}
320
329
  >
321
- <FileExplorer />
330
+ <FileExplorer roots={opts.roots} />
322
331
  <LocationProbe />
323
332
  </OpenChangeRequestsContext.Provider>
324
333
  </GitContext.Provider>
@@ -1159,6 +1168,17 @@ describe('FileExplorer sections: root folders', () => {
1159
1168
  cleanup();
1160
1169
  });
1161
1170
 
1171
+ /**
1172
+ * The root names on screen, in document order. Knowledge renders open, so
1173
+ * a folder folded into it shows between it and the next section.
1174
+ */
1175
+ const sectionNames = () =>
1176
+ ['Knowledge', 'Data', 'Agents', 'Workflows', 'Pipelines', 'Legal']
1177
+ .map((name) => screen.queryByText(name))
1178
+ .filter((el): el is HTMLElement => el !== null)
1179
+ .sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1))
1180
+ .map((el) => el.textContent);
1181
+
1162
1182
  const dir = (name: string): FileTreeEntry => ({
1163
1183
  name,
1164
1184
  relativePath: name,
@@ -1167,23 +1187,111 @@ describe('FileExplorer sections: root folders', () => {
1167
1187
  });
1168
1188
 
1169
1189
  /**
1170
- * `Data/`, `Agents/` and `Pipelines/` are never created by core — a
1190
+ * `Data/`, `Agents/` and `Workflows/` are never created by core — a
1171
1191
  * deployment that owns the agentic execution layer seeds them. When they ARE
1172
1192
  * there they get their own sections, and in particular must not fold into
1173
1193
  * Knowledge the way a stray content folder does.
1174
1194
  */
1175
- it('renders Data, Agents and Pipelines as their own sections when present', () => {
1195
+ it('renders Data, Agents and Workflows as their own sections when present, in that order', () => {
1176
1196
  const tree: FileTreeEntry = {
1177
1197
  name: '.',
1178
1198
  relativePath: '.',
1179
1199
  type: 'directory',
1180
- children: [dir('KnowledgeBase'), dir('Data'), dir('Agents'), dir('Pipelines')],
1200
+ children: [dir('Workflows'), dir('KnowledgeBase'), dir('Agents'), dir('Data')],
1181
1201
  };
1182
1202
  renderExplorer({ fileTree: tree });
1183
- expect(screen.getByText('Knowledge')).toBeInTheDocument();
1184
- expect(screen.getByText('Data')).toBeInTheDocument();
1185
- expect(screen.getByText('Agents')).toBeInTheDocument();
1186
- expect(screen.getByText('Pipelines')).toBeInTheDocument();
1203
+ expect(sectionNames()).toEqual(['Knowledge', 'Data', 'Agents', 'Workflows']);
1204
+ });
1205
+
1206
+ /** `Pipelines` is not a name core knows: a stray folder like any other. */
1207
+ it('folds a Pipelines folder into Knowledge', () => {
1208
+ const tree: FileTreeEntry = {
1209
+ name: '.',
1210
+ relativePath: '.',
1211
+ type: 'directory',
1212
+ children: [dir('Data'), dir('Pipelines'), dir('KnowledgeBase')],
1213
+ };
1214
+ renderExplorer({ fileTree: tree });
1215
+ expect(sectionNames()).toEqual(['Knowledge', 'Pipelines', 'Data']);
1216
+ });
1217
+
1218
+ const agentsApp = (roots: string[]): AppDef => ({
1219
+ id: 'agents',
1220
+ label: 'Agents',
1221
+ path: '/agents',
1222
+ element: <div />,
1223
+ roots,
1224
+ });
1225
+
1226
+ /**
1227
+ * A root an app claims is that app's to show. Left out of Knowledge
1228
+ * whether core reserves the name or not, and folded nowhere.
1229
+ */
1230
+ it('leaves out the roots an app claims, reserved or not', () => {
1231
+ const tree: FileTreeEntry = {
1232
+ name: '.',
1233
+ relativePath: '.',
1234
+ type: 'directory',
1235
+ children: [dir('KnowledgeBase'), dir('Data'), dir('Agents'), dir('Workflows'), dir('Pipelines'), dir('Legal')],
1236
+ };
1237
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['Agents', 'Workflows', 'Data', 'Pipelines'])] });
1238
+ // The stray folder still folds in; the claimed ones show nowhere.
1239
+ expect(sectionNames()).toEqual(['Knowledge', 'Legal']);
1240
+ });
1241
+
1242
+ /**
1243
+ * A tree with none of core's roots falls back to the flat tree: the
1244
+ * checkout row, with its own path and actions. A claimed root is left out
1245
+ * of it, and no other folder stands in for a Knowledge section.
1246
+ */
1247
+ it('keeps a claimed root out of a tree with none of core’s roots', () => {
1248
+ const tree: FileTreeEntry = {
1249
+ name: '.',
1250
+ relativePath: '.',
1251
+ type: 'directory',
1252
+ children: [dir('Pipelines'), dir('Legal')],
1253
+ };
1254
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['Pipelines'])] });
1255
+ expect(screen.getByText('Legal')).toBeInTheDocument();
1256
+ expect(screen.queryByText('Pipelines')).not.toBeInTheDocument();
1257
+ expect(screen.queryByText('Knowledge')).not.toBeInTheDocument();
1258
+ });
1259
+
1260
+ /** Root names compare case-insensitively, as the layout's do. */
1261
+ it('leaves out a root claimed in another case', () => {
1262
+ const tree: FileTreeEntry = {
1263
+ name: '.',
1264
+ relativePath: '.',
1265
+ type: 'directory',
1266
+ children: [dir('KnowledgeBase'), dir('Agents'), dir('Legal')],
1267
+ };
1268
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['agents', 'LEGAL'])] });
1269
+ expect(sectionNames()).toEqual(['Knowledge']);
1270
+ });
1271
+
1272
+ /** The narrowed tree: its roots, in its order, and nothing else of the knowledge base. */
1273
+ it('shows only its roots when narrowed', () => {
1274
+ const tree: FileTreeEntry = {
1275
+ name: '.',
1276
+ relativePath: '.',
1277
+ type: 'directory',
1278
+ children: [
1279
+ dir('KnowledgeBase'),
1280
+ dir('Data'),
1281
+ dir('Agents'),
1282
+ dir('Workflows'),
1283
+ dir('Legal'),
1284
+ { name: 'roles.yaml', relativePath: 'roles.yaml', type: 'file' },
1285
+ ],
1286
+ };
1287
+ renderExplorer({
1288
+ fileTree: tree,
1289
+ apps: [agentsApp(['Agents', 'Workflows'])],
1290
+ roots: ['Workflows', 'Agents'],
1291
+ });
1292
+ expect(sectionNames()).toEqual(['Workflows', 'Agents']);
1293
+ expect(screen.queryByText('Knowledge')).not.toBeInTheDocument();
1294
+ expect(screen.queryByText('roles.yaml')).not.toBeInTheDocument();
1187
1295
  });
1188
1296
 
1189
1297
  /**
@@ -2056,16 +2164,36 @@ describe('FileExplorer: delete and move ask first', () => {
2056
2164
  const person = (name: string, email: string) => ({ kind: 'person', name, email });
2057
2165
 
2058
2166
  /**
2059
- * Answer the move dialog's access lookup with these before/after holders,
2060
- * and everything else (the destination-writable preflight) with a writable
2061
- * verdict — the warnings suite covers that one on its own.
2167
+ * Answer the move dialog's access lookup with these before/after holders —
2168
+ * and the `changes` the server derives from the resolver, which this stand-in
2169
+ * derives from the two sides, since no rule here denies anyone by name — and
2170
+ * everything else (the destination-writable preflight) with a writable
2171
+ * verdict; the warnings suite covers that one on its own.
2062
2172
  */
2063
2173
  function answerAccess(before: Side, after: Side, opts: { canWrite?: boolean } = {}) {
2064
2174
  const side = (s: Side) => ({ read: s.read ?? [], write: s.write ?? [] });
2175
+ const keyOf = (p: unknown) => {
2176
+ const { kind, name, email } = p as { kind: string; name: string; email?: string };
2177
+ return kind === 'person' ? `person:${(email ?? name).toLowerCase()}` : `${kind}:${name.toLowerCase()}`;
2178
+ };
2179
+ const changesOf = (b: Side, a: Side) => {
2180
+ const lose: unknown[] = [];
2181
+ const gain: unknown[] = [];
2182
+ for (const verb of ['read', 'write'] as const) {
2183
+ const had = new Set((b[verb] ?? []).map(keyOf));
2184
+ const has = new Set((a[verb] ?? []).map(keyOf));
2185
+ for (const p of b[verb] ?? []) if (!has.has(keyOf(p))) lose.push({ ...(p as object), verb });
2186
+ for (const p of a[verb] ?? []) if (!had.has(keyOf(p))) gain.push({ ...(p as object), verb });
2187
+ }
2188
+ return { lose, gain };
2189
+ };
2065
2190
  mockAuthFetch.mockImplementation(async (url: string) => {
2066
2191
  const u = String(url);
2067
2192
  if (u.includes('/access/prospective')) {
2068
- return { ok: true, json: async () => ({ before: side(before), after: side(after) }) };
2193
+ return {
2194
+ ok: true,
2195
+ json: async () => ({ before: side(before), after: side(after), changes: changesOf(before, after) }),
2196
+ };
2069
2197
  }
2070
2198
  if (u.includes('/access?')) {
2071
2199
  return { ok: true, json: async () => ({ canWrite: opts.canWrite ?? true }) };
@@ -3147,6 +3275,48 @@ describe('FileExplorer: an empty tree says why', () => {
3147
3275
  renderExplorer({ fileTree: null });
3148
3276
  expect(screen.queryByTestId('tree-empty-notice')).not.toBeInTheDocument();
3149
3277
  });
3278
+
3279
+ /**
3280
+ * A root an app claims is not in Knowledge's tree, so what it holds does
3281
+ * not make that tree non-empty: the notice and its hint still show.
3282
+ */
3283
+ const hostingApp = (roots: string[]): AppDef => ({
3284
+ id: 'agents',
3285
+ label: 'Agents',
3286
+ path: '/agents',
3287
+ element: <div />,
3288
+ roots,
3289
+ });
3290
+
3291
+ it('says "empty" when the only content is under a claimed root', () => {
3292
+ renderExplorer({
3293
+ fileTree: seeded([], {}, [dirAt(`${KBD}/Agents`, [fileAt(`${KBD}/Agents/Planner.md`)])]),
3294
+ apps: [hostingApp(['Agents'])],
3295
+ workspaceId: 'alice%2Fdraft',
3296
+ });
3297
+ expect(screen.getByTestId('tree-empty-notice')).toHaveTextContent('This knowledge base is empty.');
3298
+ expect(screen.getByTestId('tree-empty-create-hint')).toBeInTheDocument();
3299
+ });
3300
+
3301
+ it('says "empty" for a tree that predates the split whose only folder is claimed', () => {
3302
+ renderExplorer({
3303
+ fileTree: rootedAtCheckout(
3304
+ dirAt('.', [dirAt(KBD, [dirAt(`${KBD}/Pipelines`, [fileAt(`${KBD}/Pipelines/run.workflow`)])])]),
3305
+ ),
3306
+ apps: [hostingApp(['Pipelines'])],
3307
+ workspaceId: 'alice%2Fdraft',
3308
+ });
3309
+ expect(screen.queryByText('Pipelines')).not.toBeInTheDocument();
3310
+ expect(screen.getByTestId('tree-empty-notice')).toHaveTextContent('This knowledge base is empty.');
3311
+ expect(screen.getByTestId('tree-empty-create-hint')).toBeInTheDocument();
3312
+ });
3313
+
3314
+ it('still counts that content when no app claims the root', () => {
3315
+ renderExplorer({
3316
+ fileTree: seeded([], {}, [dirAt(`${KBD}/Agents`, [fileAt(`${KBD}/Agents/Planner.md`)])]),
3317
+ });
3318
+ expect(screen.queryByTestId('tree-empty-notice')).not.toBeInTheDocument();
3319
+ });
3150
3320
  });
3151
3321
 
3152
3322
  // The sidebar refuses a platform file's drag and its rename itself, with the
@@ -4237,7 +4407,7 @@ describe('FileExplorer: a document the server could not read', () => {
4237
4407
  this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
4238
4408
  }
4239
4409
  close() {}
4240
- deliver(event: WorkflowEvent) {
4410
+ deliver(event: VersionControlEvent) {
4241
4411
  for (const fn of [...(this.listeners.get('message') ?? [])]) {
4242
4412
  fn(new MessageEvent('message', { data: JSON.stringify(event) }));
4243
4413
  }
@@ -4274,7 +4444,7 @@ describe('FileExplorer: a document the server could not read', () => {
4274
4444
  let id = 1;
4275
4445
  const push = (payload: { workspaceId: string; path: string; reason: string }) =>
4276
4446
  act(() => {
4277
- const event = { id: id++, ts: new Date().toISOString(), kind: 'document-unreadable', ...payload } as WorkflowEvent;
4447
+ const event = { id: id++, ts: new Date().toISOString(), kind: 'document-unreadable', ...payload } as VersionControlEvent;
4278
4448
  FakeEventSource.current!.deliver(event);
4279
4449
  });
4280
4450
  return { push };
@@ -20,7 +20,7 @@ vi.mock('../../routing/kb-routes', async (importOriginal) => {
20
20
  import type { WorkingTreeStatus } from '@bevel-software/platform-shared';
21
21
  import { FileRoute } from '../FileRoute';
22
22
  import { WorkspaceApiError } from '../../services/workspace.api';
23
- import { GitContext, type GitContextValue } from '../../../git/state/git.context';
23
+ import { GitContext, type GitContextValue } from '../../../git';
24
24
  import {
25
25
  WorkspaceContext,
26
26
  type WorkspaceContextValue,
@@ -29,7 +29,8 @@ import {
29
29
  } from '../../state/workspace.context';
30
30
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
31
31
  import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
32
- import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
32
+ import { AuthContext, type AuthContextValue } from '../../../auth';
33
+ import { AppRegistryContext, makeRegistry, type AppDef } from '../../../../core/registry';
33
34
 
34
35
  function makeStatus(branch = 'alice/draft'): WorkingTreeStatus {
35
36
  return { branch, hasUpstream: true, unmergedFromUpstream: false };
@@ -145,6 +146,8 @@ function renderAt(
145
146
  canonicalize?: boolean;
146
147
  /** Router state on the first entry, as a navigation would have left it. */
147
148
  state?: unknown;
149
+ /** Apps in the registry — the ones whose `roots` claim top-level folders. */
150
+ apps?: AppDef[];
148
151
  } = {},
149
152
  ): {
150
153
  workspace: WorkspaceContextValue;
@@ -189,8 +192,10 @@ function renderAt(
189
192
  logout: () => {},
190
193
  };
191
194
 
195
+ const registry = makeRegistry({ apps: opts.apps ?? [] });
192
196
  function Tree({ children }: { children: ReactNode }) {
193
197
  return (
198
+ <AppRegistryContext.Provider value={registry}>
194
199
  <AuthContext.Provider value={auth}>
195
200
  <WorkspaceContext.Provider value={workspace}>
196
201
  <GitContext.Provider value={git}>
@@ -200,6 +205,7 @@ function renderAt(
200
205
  </GitContext.Provider>
201
206
  </WorkspaceContext.Provider>
202
207
  </AuthContext.Provider>
208
+ </AppRegistryContext.Provider>
203
209
  );
204
210
  }
205
211
 
@@ -288,6 +294,48 @@ describe('FileRoute: the canonical id URL', () => {
288
294
  });
289
295
  });
290
296
 
297
+ /**
298
+ * A file under a root an app claims opens in that app by its PATH URL, so the
299
+ * route never trades it for the id URL, and an id URL that resolves to one is
300
+ * traded for the path URL instead.
301
+ */
302
+ describe('FileRoute: a file under a claimed root', () => {
303
+ const PATH = 'knowledge-base/Data/Tickets/T-1.md';
304
+ const apps: AppDef[] = [{ id: 'agents', label: 'Agents', path: '/agents', element: <div />, roots: ['Data'] }];
305
+ function openOn(): { workspace: WorkspaceContextValue; git: GitContextValue } {
306
+ const tab = makeTab({ path: PATH });
307
+ const workspace = makeWorkspace({
308
+ openTabs: [tab],
309
+ activeTab: tab,
310
+ hydrateTabs: vi.fn<WorkspaceContextValue['hydrateTabs']>(async () => makeHydrateResult({ surviving: [PATH] })),
311
+ });
312
+ return { workspace, git: makeGit({ status: makeStatus('main') }) };
313
+ }
314
+
315
+ it('keeps the path URL of an id-bearing file', async () => {
316
+ routesMock.fetchNodeId.mockResolvedValue('t-1');
317
+ renderAt(`/workspace/main/${PATH}`, { ...openOn(), apps });
318
+ await settle();
319
+ expect(screen.getByLabelText('pathname')).toHaveTextContent(`/workspace/main/${PATH}`);
320
+ expect(routesMock.fetchNodeId).not.toHaveBeenCalled();
321
+ });
322
+
323
+ it('replaces an id URL that resolves to it with its path URL, keeping the query', async () => {
324
+ routesMock.fetchNodeWorkspacePath.mockResolvedValue(PATH);
325
+ renderAt('/workspace/main/t-1?fullscreen=1', { ...openOn(), apps });
326
+ await waitFor(() =>
327
+ expect(screen.getByLabelText('pathname')).toHaveTextContent(`/workspace/main/${PATH}`),
328
+ );
329
+ expect(screen.getByLabelText('search')).toHaveTextContent('?fullscreen=1');
330
+ });
331
+
332
+ it('canonicalises as before when no app claims the root', async () => {
333
+ routesMock.fetchNodeId.mockResolvedValue('t-1');
334
+ renderAt(`/workspace/main/${PATH}`, openOn());
335
+ await waitFor(() => expect(screen.getByLabelText('pathname')).toHaveTextContent('/workspace/main/t-1'));
336
+ });
337
+ });
338
+
291
339
  describe('FileRoute', () => {
292
340
  it('hydrates tabs with the URL path when branch matches', async () => {
293
341
  const hydrateTabs = vi.fn<WorkspaceContextValue['hydrateTabs']>(
@@ -38,9 +38,9 @@ vi.mock('../../../access/api', () => ({
38
38
  // real endpoints. In these tests we just need the acquire to succeed so the
39
39
  // save flow can finish; lock contention paths are exercised in lock-specific
40
40
  // tests, not here.
41
- vi.mock('../../../workflow/services/lock.api', async (importOriginal) => ({
41
+ vi.mock('../../../version-control/services/lock.api', async (importOriginal) => ({
42
42
  // The sentences (SELF_HOLD_MESSAGE, EDITING_ENDED_MESSAGE) stay real.
43
- ...(await importOriginal<typeof import('../../../workflow/services/lock.api')>()),
43
+ ...(await importOriginal<typeof import('../../../version-control/services/lock.api')>()),
44
44
  acquireLock: vi.fn(async () => ({
45
45
  acquired: true,
46
46
  lock: {
@@ -108,8 +108,8 @@ vi.mock('../../../access/components/ManageAccessDialog', () => ({
108
108
  // `recordActivity`, which has no other visible effect (it resets a timer), so
109
109
  // there is no way to assert the scroll→lock wiring without a spy on it.
110
110
  const lockActivity = vi.hoisted(() => ({ recordActivity: vi.fn() }));
111
- vi.mock('../../../workflow/hooks/useFileLock', async (importOriginal) => {
112
- const actual = await importOriginal<typeof import('../../../workflow/hooks/useFileLock')>();
111
+ vi.mock('../../../version-control/hooks/useFileLock', async (importOriginal) => {
112
+ const actual = await importOriginal<typeof import('../../../version-control/hooks/useFileLock')>();
113
113
  const { useCallback } = await import('react');
114
114
  return {
115
115
  ...actual,
@@ -148,7 +148,7 @@ import {
148
148
  releaseLock as releaseLockMock,
149
149
  LockApiError,
150
150
  SELF_HOLD_MESSAGE,
151
- } from '../../../workflow/services/lock.api';
151
+ } from '../../../version-control/services/lock.api';
152
152
  import { WorkspaceContext, type WorkspaceContextValue } from '../../state/workspace.context';
153
153
  import { GitContext, type GitContextValue } from '../../../git/state/git.context';
154
154
  import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
2
  import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
3
- import type { WorkflowEvent } from '@bevel-software/platform-shared';
3
+ import type { VersionControlEvent } from '@bevel-software/platform-shared';
4
4
  import {
5
5
  WorkspaceContext,
6
6
  type WorkspaceContextValue,
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  EventBusContext,
10
10
  type EventBusContextValue,
11
- } from '../../../../workflow/state/event-bus.context';
11
+ } from '../../../../version-control/state/event-bus.context';
12
12
 
13
13
  const apiMock = vi.hoisted(() => ({ authFetch: vi.fn() }));
14
14
  vi.mock('../../../../../lib/api', () => ({ authFetch: apiMock.authFetch }));
@@ -75,9 +75,9 @@ describe('ImageRenderer', () => {
75
75
  * to.
76
76
  */
77
77
  it('refetches when an image in the workspace changes', async () => {
78
- const handlers: ((e: WorkflowEvent) => void)[] = [];
78
+ const handlers: ((e: VersionControlEvent) => void)[] = [];
79
79
  const bus = {
80
- subscribe: (_kind: string, handler: (e: WorkflowEvent) => void) => {
80
+ subscribe: (_kind: string, handler: (e: VersionControlEvent) => void) => {
81
81
  handlers.push(handler);
82
82
  return () => {};
83
83
  },
@@ -109,7 +109,7 @@ describe('ImageRenderer', () => {
109
109
  workspaceId: 'ws-1',
110
110
  branch: 'ws-1',
111
111
  path: 'Knowledge/assets/shot.png',
112
- } as unknown as WorkflowEvent),
112
+ } as unknown as VersionControlEvent),
113
113
  ),
114
114
  );
115
115
 
@@ -1,20 +1,20 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { act, renderHook } from '@testing-library/react';
3
3
  import type { ReactNode } from 'react';
4
- import type { WorkflowEvent } from '@bevel-software/platform-shared';
5
- import { EventBusContext, type EventBusContextValue } from '../../../workflow/state/event-bus.context';
4
+ import type { VersionControlEvent } from '@bevel-software/platform-shared';
5
+ import { EventBusContext, type EventBusContextValue } from '../../../version-control/state/event-bus.context';
6
6
  import { useImageRevision, isImagePath } from '../useImageRevision';
7
7
 
8
8
  function makeFakeBus() {
9
- const handlers: Record<string, ((e: WorkflowEvent) => void)[]> = {};
9
+ const handlers: Record<string, ((e: VersionControlEvent) => void)[]> = {};
10
10
  // The workspaces the hook has ASKED to be delivered. Without a watch the
11
11
  // real stream sends nothing for a workspace the session isn't focused on,
12
12
  // so "did it subscribe" and "will anything arrive" are separate facts and
13
13
  // the fake tracks both.
14
14
  const watched: string[] = [];
15
- const bus: EventBusContextValue & { emit(e: WorkflowEvent): void; watched: string[] } = {
15
+ const bus: EventBusContextValue & { emit(e: VersionControlEvent): void; watched: string[] } = {
16
16
  subscribe(kind, handler) {
17
- (handlers[kind] ??= []).push(handler as (e: WorkflowEvent) => void);
17
+ (handlers[kind] ??= []).push(handler as (e: VersionControlEvent) => void);
18
18
  return () => {
19
19
  handlers[kind] = (handlers[kind] ?? []).filter((h) => h !== handler);
20
20
  };
@@ -35,18 +35,18 @@ function makeFakeBus() {
35
35
  return bus;
36
36
  }
37
37
 
38
- function fileChanged(workspaceId: string, path: string): WorkflowEvent {
38
+ function fileChanged(workspaceId: string, path: string): VersionControlEvent {
39
39
  return {
40
40
  kind: 'file-changed',
41
41
  workspaceId,
42
42
  branch: workspaceId,
43
43
  path,
44
44
  newSha: 'abc123',
45
- } as unknown as WorkflowEvent;
45
+ } as unknown as VersionControlEvent;
46
46
  }
47
47
 
48
- function treeChanged(workspaceId: string): WorkflowEvent {
49
- return { kind: 'fs-tree-changed', workspaceId, branch: workspaceId } as unknown as WorkflowEvent;
48
+ function treeChanged(workspaceId: string): VersionControlEvent {
49
+ return { kind: 'fs-tree-changed', workspaceId, branch: workspaceId } as unknown as VersionControlEvent;
50
50
  }
51
51
 
52
52
  function renderRevision(bus: ReturnType<typeof makeFakeBus>, workspaceId: string | null) {
@@ -1,18 +1,18 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { act, renderHook } from '@testing-library/react';
3
3
  import type { ReactNode } from 'react';
4
- import type { WorkflowEvent } from '@bevel-software/platform-shared';
5
- import { EventBusContext, type EventBusContextValue } from '../../../workflow/state/event-bus.context';
4
+ import type { VersionControlEvent } from '@bevel-software/platform-shared';
5
+ import { EventBusContext, type EventBusContextValue } from '../../../version-control/state/event-bus.context';
6
6
  import { WorkspaceContext } from '../../state/workspace.context';
7
7
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
8
8
  import { useWorkspaceImageResolver } from '../useWorkspaceImageResolver';
9
9
 
10
10
  function makeFakeBus() {
11
- const handlers: Record<string, ((e: WorkflowEvent) => void)[]> = {};
11
+ const handlers: Record<string, ((e: VersionControlEvent) => void)[]> = {};
12
12
  const watched: string[] = [];
13
- const bus: EventBusContextValue & { emit(e: WorkflowEvent): void; watched: string[] } = {
13
+ const bus: EventBusContextValue & { emit(e: VersionControlEvent): void; watched: string[] } = {
14
14
  subscribe(kind, handler) {
15
- (handlers[kind] ??= []).push(handler as (e: WorkflowEvent) => void);
15
+ (handlers[kind] ??= []).push(handler as (e: VersionControlEvent) => void);
16
16
  return () => {
17
17
  handlers[kind] = (handlers[kind] ?? []).filter((h) => h !== handler);
18
18
  };
@@ -33,14 +33,14 @@ function makeFakeBus() {
33
33
  return bus;
34
34
  }
35
35
 
36
- function imageChanged(workspaceId: string, path: string): WorkflowEvent {
36
+ function imageChanged(workspaceId: string, path: string): VersionControlEvent {
37
37
  return {
38
38
  kind: 'file-changed',
39
39
  workspaceId,
40
40
  branch: workspaceId,
41
41
  path,
42
42
  newSha: 'abc123',
43
- } as unknown as WorkflowEvent;
43
+ } as unknown as VersionControlEvent;
44
44
  }
45
45
 
46
46
  function renderResolver(
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { useEventBus, canonicalizeWorkspaceId } from '../../workflow';
2
+ import { useEventBus, canonicalizeWorkspaceId } from '../../version-control';
3
3
 
4
4
  /**
5
5
  * The extensions the raw file route serves as pictures, which is what a
@@ -5,7 +5,7 @@ import {
5
5
  isProtectedBranch,
6
6
  type FileTreeEntry,
7
7
  } from '@bevel-software/platform-shared';
8
- import { useEventBus, canonicalizeWorkspaceId } from '../../workflow';
8
+ import { useEventBus, canonicalizeWorkspaceId } from '../../version-control';
9
9
  import { AuthContext } from '../../auth';
10
10
  import { fetchFileAccess } from '../../access';
11
11
  import {
@@ -1578,7 +1578,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1578
1578
 
1579
1579
  // ── Live updates: react to other users' / agent's edits ───────────────────
1580
1580
  //
1581
- // When the backend's lock-release commits + pushes a file, the workflow
1581
+ // When the backend's lock-release commits + pushes a file, the version-control service
1582
1582
  // event bus pushes a `file-changed` event to every session focused on
1583
1583
  // this workspace+branch. We:
1584
1584
  //
@@ -3,8 +3,8 @@ import { renderHook, waitFor, act } from '@testing-library/react';
3
3
  import type { ReactNode } from 'react';
4
4
  import type {
5
5
  PullRequestSummary,
6
- WorkflowEvent,
7
- WorkflowEventPayload,
6
+ VersionControlEvent,
7
+ VersionControlEventPayload,
8
8
  } from '@bevel-software/platform-shared';
9
9
 
10
10
  const api = vi.hoisted(() => ({
@@ -20,11 +20,11 @@ vi.mock('../../../change-requests/services/change-requests.api', () => ({
20
20
  import { OpenChangeRequestsProvider } from '../open-change-requests';
21
21
  import { useOpenChangeRequests } from '../../hooks/useOpenChangeRequests';
22
22
  import { WorkspaceContext, type WorkspaceContextValue } from '../workspace.context';
23
- import { ChangeRequestStaleBinder } from '../../../workflow/state/ChangeRequestStaleBinder';
23
+ import { ChangeRequestStaleBinder } from '../../../version-control/state/ChangeRequestStaleBinder';
24
24
  import {
25
25
  EventBusContext,
26
26
  type EventBusContextValue,
27
- } from '../../../workflow/state/event-bus.context';
27
+ } from '../../../version-control/state/event-bus.context';
28
28
  import { PR_STALE_COALESCE_MS, PR_STALE_FALLBACK_MS } from '../../../../core/events';
29
29
 
30
30
  /**
@@ -67,20 +67,20 @@ function pr(over: Partial<PullRequestSummary> = {}): PullRequestSummary {
67
67
  }
68
68
 
69
69
  function fakeBus() {
70
- const handlers = new Map<string, Set<(e: WorkflowEvent) => void>>();
70
+ const handlers = new Map<string, Set<(e: VersionControlEvent) => void>>();
71
71
  const value: EventBusContextValue = {
72
72
  subscribe: (kind, handler) => {
73
73
  const set = handlers.get(kind) ?? new Set();
74
- set.add(handler as (e: WorkflowEvent) => void);
74
+ set.add(handler as (e: VersionControlEvent) => void);
75
75
  handlers.set(kind, set);
76
- return () => set.delete(handler as (e: WorkflowEvent) => void);
76
+ return () => set.delete(handler as (e: VersionControlEvent) => void);
77
77
  },
78
78
  setFocus: () => {},
79
79
  watchWorkspace: () => () => {},
80
80
  };
81
- const emit = (event: WorkflowEventPayload) => {
81
+ const emit = (event: VersionControlEventPayload) => {
82
82
  for (const h of handlers.get(event.kind) ?? []) {
83
- h({ id: 1, ts: new Date().toISOString(), ...event } as WorkflowEvent);
83
+ h({ id: 1, ts: new Date().toISOString(), ...event } as VersionControlEvent);
84
84
  }
85
85
  };
86
86
  return { value, emit };