@opengeni/react 3.5.1-canary.0 → 3.7.0-canary.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 (52) hide show
  1. package/dist/artifacts.d.ts +1 -1
  2. package/dist/artifacts.js +229 -6
  3. package/dist/artifacts.js.map +1 -1
  4. package/dist/{chunk-IB27C53Y.js → chunk-C6WDLHBA.js} +31 -23
  5. package/dist/chunk-C6WDLHBA.js.map +1 -0
  6. package/dist/{chunk-WY3MELVJ.js → chunk-DOK4KZF2.js} +119 -8
  7. package/dist/chunk-DOK4KZF2.js.map +1 -0
  8. package/dist/{chunk-TJFMMDQU.js → chunk-FJBOU2TH.js} +112 -6
  9. package/dist/chunk-FJBOU2TH.js.map +1 -0
  10. package/dist/{chunk-UNCXXIQR.js → chunk-R55HFTT3.js} +66 -24
  11. package/dist/chunk-R55HFTT3.js.map +1 -0
  12. package/dist/client.d.ts +1 -1
  13. package/dist/components/artifacts/index.d.ts +1 -1
  14. package/dist/components/artifacts/published-html-artifact-frame.d.ts +45 -3
  15. package/dist/components/composer.d.ts +2 -0
  16. package/dist/components/session-chrome.d.ts +1 -1
  17. package/dist/composer.js +1 -1
  18. package/dist/{fleet-decision-row-GGCAT4E4.js → fleet-decision-row-YZ3ZKWMM.js} +2 -1
  19. package/dist/fleet-decision-row-YZ3ZKWMM.js.map +1 -0
  20. package/dist/hooks/use-file-attachments.d.ts +6 -0
  21. package/dist/hooks/use-sandbox-files.d.ts +4 -1
  22. package/dist/hooks/use-workspace-edit.d.ts +4 -0
  23. package/dist/index.js +114 -58
  24. package/dist/index.js.map +1 -1
  25. package/dist/session-ui.js +2 -2
  26. package/dist/session.js +2 -2
  27. package/dist/timeline/registry.d.ts +2 -0
  28. package/dist/timeline/types.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/src/artifacts.ts +3 -0
  31. package/src/client.ts +2 -1
  32. package/src/components/artifacts/index.ts +3 -0
  33. package/src/components/artifacts/published-html-artifact-frame.tsx +284 -4
  34. package/src/components/composer.tsx +89 -25
  35. package/src/components/message-timeline.tsx +32 -8
  36. package/src/components/sandbox-workspace.tsx +11 -1
  37. package/src/components/session-chrome.tsx +3 -3
  38. package/src/hooks/use-file-attachments.ts +34 -0
  39. package/src/hooks/use-sandbox-files.ts +68 -20
  40. package/src/hooks/use-session-events.ts +21 -26
  41. package/src/hooks/use-workspace-edit.ts +23 -5
  42. package/src/timeline/fleet-decision-projection.ts +2 -1
  43. package/src/timeline/fleet-decision-row.tsx +1 -0
  44. package/src/timeline/projection.ts +151 -7
  45. package/src/timeline/registry.ts +15 -3
  46. package/src/timeline/tool-renderers.tsx +117 -1
  47. package/src/timeline/types.ts +8 -1
  48. package/dist/chunk-IB27C53Y.js.map +0 -1
  49. package/dist/chunk-TJFMMDQU.js.map +0 -1
  50. package/dist/chunk-UNCXXIQR.js.map +0 -1
  51. package/dist/chunk-WY3MELVJ.js.map +0 -1
  52. package/dist/fleet-decision-row-GGCAT4E4.js.map +0 -1
@@ -102,6 +102,12 @@ function isWorkbenchSurface(value: string): value is SandboxWorkspaceSurface {
102
102
  return (WORKBENCH_SURFACES as readonly string[]).includes(value);
103
103
  }
104
104
 
105
+ function isCanonicalAbsoluteSandboxPath(value: string | null | undefined): boolean {
106
+ if (!value) return false;
107
+ const portable = value.replaceAll("\\", "/");
108
+ return portable.startsWith("/") || /^[A-Za-z]:\//u.test(portable);
109
+ }
110
+
105
111
  function sourceDrivenDefaultTab(
106
112
  hasChanges: boolean,
107
113
  changesEnabled: boolean,
@@ -468,6 +474,9 @@ export function useSandboxWorkspaceTabs(
468
474
  // is still pending.
469
475
  const liveIoLiveness = liveness ?? null;
470
476
  const fileSystemOn = capabilities?.FileSystem.available ?? false;
477
+ const fileSystemRoute = capabilities
478
+ ? { epoch: capabilities.leaseEpoch, root: capabilities.FileSystem.root }
479
+ : undefined;
471
480
  // The FS is writable only when it's live AND not read-only. A self-hosted box
472
481
  // that's offline (or any read-only advertisement) or a capture-served cold tree
473
482
  // must not offer create/rename/delete/edit affordances — you cannot mutate a
@@ -575,9 +584,10 @@ export function useSandboxWorkspaceTabs(
575
584
  active: filesActive && !turnInFlight,
576
585
  // A deliberate canonical absolute-path open browses in the selected target's
577
586
  // advertised namespace, so the authoritative tree and link share exact paths.
578
- ...(requestedFilePath?.startsWith("/") && capabilities?.FileSystem.root
587
+ ...(isCanonicalAbsoluteSandboxPath(requestedFilePath) && capabilities?.FileSystem.root
579
588
  ? { rootPath: capabilities.FileSystem.root }
580
589
  : {}),
590
+ ...(fileSystemRoute ? { route: fileSystemRoute } : {}),
581
591
  repoPaths,
582
592
  liveness: liveIoLiveness,
583
593
  capture: captureState.capture,
@@ -159,7 +159,7 @@ export function sessionChromeGoalPillLabel(
159
159
 
160
160
  /**
161
161
  * One human sentence explaining WHY the goal is not pursuing right now: the
162
- * pause reason, the agent's own `goal_wait` hold (reason + deadline), or the
162
+ * pause reason, the agent's own `wait_for_input` hold (reason + deadline), or the
163
163
  * next idle-backoff check time. Null when the state needs no explanation.
164
164
  */
165
165
  export function sessionChromeGoalPillExplanation(
@@ -182,7 +182,7 @@ export function sessionChromeGoalPillExplanation(
182
182
  const until = continuation.nextAttemptAt
183
183
  ? ` until ${formatClockTime(continuation.nextAttemptAt)}`
184
184
  : "";
185
- return `Waiting for input${reason ? `: ${reason}` : ""}${until}. A child result, an agent message, or your prompt wakes it sooner.`;
185
+ return `Waiting for input${reason ? `: ${reason}` : ""}${until}. Relevant session input—including a child result, background-command result, agent message, schedule, or your promptwakes it sooner.`;
186
186
  }
187
187
  return null;
188
188
  }
@@ -228,7 +228,7 @@ export function sessionChromeGoalPillState(
228
228
  // next evaluation at `nextAttemptAt`) is an ordinary scheduled state.
229
229
  if (continuation.state === "scheduled") return "scheduled";
230
230
  if (continuation.state === "blocked") {
231
- // `held_for_input` is the agent's own goal_wait hold (waiting for child
231
+ // `held_for_input` is the agent's own wait_for_input hold (waiting for child
232
232
  // results / external input until a deadline); it shares the Held pill.
233
233
  return continuation.reason === "workstream_paused" || continuation.reason === "held_for_input"
234
234
  ? "held"
@@ -52,6 +52,12 @@ export type UseFileAttachmentsResult = {
52
52
  addFromPaste: (event: { clipboardData: DataTransfer | null }) => void;
53
53
  /** Restore already-ready server assets without recreating browser-local bytes. */
54
54
  restoreReadyFiles: (files: Iterable<FileAsset>) => void;
55
+ /**
56
+ * Resolve a ready image's short-lived server preview URL on demand. Optional
57
+ * for upload-only embedded clients; local object-URL previews remain usable
58
+ * without it.
59
+ */
60
+ loadPreview?: ((id: string, signal?: AbortSignal) => Promise<string | undefined>) | undefined;
55
61
  /**
56
62
  * Re-run the upload for a `failed` attachment, in place (same id, same
57
63
  * source file). No-op for an id that isn't a known failed upload.
@@ -114,6 +120,8 @@ export function useFileAttachments(
114
120
  const { client, workspaceId } = useEmbeddedFileAttachments(options);
115
121
  const pasteFilter = options.pasteFilter ?? isImage;
116
122
  const [attachments, setAttachments] = useState<FileAttachment[]>([]);
123
+ const attachmentsRef = useRef(attachments);
124
+ attachmentsRef.current = attachments;
117
125
  // Keep the source File per attachment id so a failed upload can be retried
118
126
  // in place. Cleared on remove/clear so it never outlives its attachment.
119
127
  const sources = useRef<Map<string, File>>(new Map());
@@ -353,6 +361,31 @@ export function useFileAttachments(
353
361
  [workspaceId],
354
362
  );
355
363
 
364
+ const loadPreview = useCallback(
365
+ async (id: string, signal?: AbortSignal): Promise<string | undefined> => {
366
+ const generation = scopeGeneration.current;
367
+ const attachment = attachmentsRef.current.find((candidate) => candidate.id === id);
368
+ const createDownloadUrl = client.createFileDownloadUrl;
369
+ if (
370
+ !attachment ||
371
+ attachment.status !== "ready" ||
372
+ !attachment.file ||
373
+ !attachment.contentType.startsWith("image/") ||
374
+ typeof createDownloadUrl !== "function" ||
375
+ signal?.aborted
376
+ ) {
377
+ return undefined;
378
+ }
379
+ const fileId = attachment.file.id;
380
+ const signed = await createDownloadUrl.call(client, workspaceId, fileId, { signal });
381
+ if (scopeGeneration.current !== generation || signal?.aborted) return undefined;
382
+ const current = attachmentsRef.current.find((candidate) => candidate.id === id);
383
+ if (current?.status !== "ready" || current.file?.id !== fileId) return undefined;
384
+ return signed.url;
385
+ },
386
+ [client, workspaceId],
387
+ );
388
+
356
389
  const remove = useCallback(
357
390
  (id: string) => {
358
391
  sources.current.delete(id);
@@ -394,6 +427,7 @@ export function useFileAttachments(
394
427
  addFiles,
395
428
  addFromPaste,
396
429
  restoreReadyFiles,
430
+ ...(typeof client.createFileDownloadUrl === "function" ? { loadPreview } : {}),
397
431
  retry,
398
432
  retainPreview,
399
433
  remove,
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ FileSystemRouteIdentity,
2
3
  FsChangedPayload,
3
4
  FsReadResponse,
4
5
  FsTreeNode,
@@ -84,6 +85,9 @@ export type UseSandboxFilesOptions = ClientOverride & {
84
85
  events?: SessionEvent[] | undefined;
85
86
  /** Initial path to list (workspace root by default). */
86
87
  rootPath?: string | undefined;
88
+ /** Exact capability identity for the selected filesystem route. A route/root
89
+ * change resets this hook and makes stale provider requests fail retryably. */
90
+ route?: FileSystemRouteIdentity | undefined;
87
91
  /** Hold off the initial list (e.g. panel collapsed). Default true. */
88
92
  enabled?: boolean | undefined;
89
93
  /** Pause live reads/invalidation while preserving the last rendered result. */
@@ -169,8 +173,12 @@ function normalizeRoot(root: string): string {
169
173
  return normalized === "." ? "" : normalized;
170
174
  }
171
175
 
176
+ function isAbsoluteTreePath(path: string): boolean {
177
+ return path.startsWith("/") || /^[A-Za-z]:\//u.test(path);
178
+ }
179
+
172
180
  function joinTreeRoot(root: string, path: string): string {
173
- if (!root || path.startsWith("/")) return path;
181
+ if (!root || isAbsoluteTreePath(path)) return path;
174
182
  return root === "/" ? `/${path}` : `${root}/${path}`;
175
183
  }
176
184
 
@@ -301,6 +309,7 @@ const FS_LIST_BATCH_REQUEST_LIMIT = 16;
301
309
  function initialDirectoryFrontier(rootPath: string, repoPaths: readonly string[]): string[] {
302
310
  const root = normalizeRoot(rootPath);
303
311
  const rootParts = root.split("/").filter(Boolean);
312
+ const rootPrefix = root.startsWith("//") ? "//" : root.startsWith("/") ? "/" : "";
304
313
  const paths = new Set<string>();
305
314
  for (const repoPath of repoPaths) {
306
315
  const canonicalRepoPath = joinTreeRoot(root, normalizeRoot(repoPath));
@@ -308,7 +317,7 @@ function initialDirectoryFrontier(rootPath: string, repoPaths: readonly string[]
308
317
  if (rootParts.some((part, index) => parts[index] !== part)) continue;
309
318
  for (let depth = rootParts.length + 1; depth <= parts.length; depth += 1) {
310
319
  const path = parts.slice(0, depth).join("/");
311
- paths.add(root.startsWith("/") ? `/${path}` : path);
320
+ paths.add(`${rootPrefix}${path}`);
312
321
  }
313
322
  }
314
323
  // A workspace with hundreds of repositories should remain lazy. This still
@@ -491,6 +500,15 @@ export function useSandboxFiles(
491
500
  const enabled = (options.enabled ?? true) && Boolean(sessionId);
492
501
  const active = options.active ?? true;
493
502
  const rootPath = options.rootPath ?? "";
503
+ const routeEpoch = options.route?.epoch ?? null;
504
+ const routeRoot = options.route?.root ?? null;
505
+ const route = useMemo<FileSystemRouteIdentity | undefined>(
506
+ () =>
507
+ routeEpoch !== null && routeRoot !== null
508
+ ? { epoch: routeEpoch, root: routeRoot }
509
+ : undefined,
510
+ [routeEpoch, routeRoot],
511
+ );
494
512
  const repoPathsKey = [
495
513
  ...new Set((options.repoPaths?.length ? options.repoPaths : [rootPath]).map(normalizeRoot)),
496
514
  ].join("\u0000");
@@ -503,7 +521,7 @@ export function useSandboxFiles(
503
521
  const acceptsEventReadsRef = useRef(acceptsEventReads);
504
522
  acceptsEventReadsRef.current = acceptsEventReads;
505
523
  const hasLiveIoFence = options.liveness !== undefined;
506
- const identityKey = `${workspaceId}\u0000${sessionId ?? ""}\u0000${rootPath}\u0000${repoPathsKey}`;
524
+ const identityKey = `${workspaceId}\u0000${sessionId ?? ""}\u0000${rootPath}\u0000${repoPathsKey}\u0000${routeEpoch ?? ""}\u0000${routeRoot ?? ""}`;
507
525
 
508
526
  const [tree, setTree] = useState<FileTreeNode[]>([]);
509
527
  // A ref mirror of the current tree — lets the optimistic path snapshot the
@@ -597,6 +615,7 @@ export function useSandboxFiles(
597
615
  const listRequests = [rootPath, ...frontierPaths].map((path) => ({
598
616
  path,
599
617
  depth: 1,
618
+ ...(route ? { route } : {}),
600
619
  }));
601
620
  // Root plus the bounded repository frontier share one API request, one
602
621
  // direct holder, and one provider attach. The old per-directory fan-out
@@ -677,7 +696,7 @@ export function useSandboxFiles(
677
696
  if (refreshGenerationRef.current === generation) setGitLoading(false);
678
697
  if (refreshAbortRef.current === refreshAbort) refreshAbortRef.current = null;
679
698
  }
680
- }, [client, workspaceId, sessionId, rootPath, repoPaths, applyStatus]);
699
+ }, [client, workspaceId, sessionId, rootPath, repoPaths, route, applyStatus]);
681
700
 
682
701
  // Seed (or re-seed) the tree from a turn-end capture — the COLD/offline paint,
683
702
  // zero Channel-A calls. The tree index is workspace-relative (`treeIndex`); the
@@ -737,7 +756,7 @@ export function useSandboxFiles(
737
756
  const listed = await client.fsList(
738
757
  workspaceId,
739
758
  sessionId,
740
- { path, depth: 1 },
759
+ { path, depth: 1, ...(route ? { route } : {}) },
741
760
  { signal: identitySignal },
742
761
  );
743
762
  if (identityGenerationRef.current !== identityGeneration) return;
@@ -757,7 +776,7 @@ export function useSandboxFiles(
757
776
  }
758
777
  }
759
778
  },
760
- [client, workspaceId, sessionId, capture, source, applyStatus],
779
+ [client, workspaceId, sessionId, capture, source, route, applyStatus],
761
780
  );
762
781
 
763
782
  const readFile = useCallback(
@@ -850,9 +869,14 @@ export function useSandboxFiles(
850
869
  }
851
870
  throw new Error("Captured file download failed after refreshing its URL.");
852
871
  }
853
- return await client.fsRead(workspaceId, sessionId, { path }, { signal });
872
+ return await client.fsRead(
873
+ workspaceId,
874
+ sessionId,
875
+ { path, ...(route ? { route } : {}) },
876
+ { signal },
877
+ );
854
878
  },
855
- [client, workspaceId, sessionId, capture, source],
879
+ [client, workspaceId, sessionId, capture, source, route],
856
880
  );
857
881
 
858
882
  // TARGETED reconcile of a single directory — re-list ONE parent at depth 1 and
@@ -874,7 +898,12 @@ export function useSandboxFiles(
874
898
  // visible to update; they re-list fresh on the next expand).
875
899
  if (!parentIsLoaded(treeRef.current, path, rootPath)) return;
876
900
  try {
877
- const listed = await client.fsList(workspaceId, sessionId, { path, depth: 1 }, { signal });
901
+ const listed = await client.fsList(
902
+ workspaceId,
903
+ sessionId,
904
+ { path, depth: 1, ...(route ? { route } : {}) },
905
+ { signal },
906
+ );
878
907
  if (identityGenerationRef.current !== identityGeneration) return;
879
908
  const children = (listed.root.children ?? []).map((node) => fsNodeToTree(node));
880
909
  if (path === normalizeRoot(rootPath)) {
@@ -892,7 +921,7 @@ export function useSandboxFiles(
892
921
  // root-refresh here (that would collapse the tree the user is working in).
893
922
  }
894
923
  },
895
- [client, workspaceId, sessionId, rootPath, applyStatus],
924
+ [client, workspaceId, sessionId, rootPath, route, applyStatus],
896
925
  );
897
926
 
898
927
  // Reconcile the visible directory frontier through bounded batch requests.
@@ -915,7 +944,13 @@ export function useSandboxFiles(
915
944
  const listed = await client.fsListBatch(
916
945
  workspaceId,
917
946
  sessionId,
918
- { requests: chunk.map((path) => ({ path, depth: 1 })) },
947
+ {
948
+ requests: chunk.map((path) => ({
949
+ path,
950
+ depth: 1,
951
+ ...(route ? { route } : {}),
952
+ })),
953
+ },
919
954
  { signal },
920
955
  );
921
956
  if (identityGenerationRef.current !== identityGeneration) return;
@@ -943,7 +978,7 @@ export function useSandboxFiles(
943
978
  }
944
979
  }
945
980
  },
946
- [client, workspaceId, sessionId, rootPath, applyStatus],
981
+ [client, workspaceId, sessionId, rootPath, route, applyStatus],
947
982
  );
948
983
 
949
984
  // Run a Channel-A op behind an OPTIMISTIC tree edit. `apply` splices the change
@@ -1027,7 +1062,7 @@ export function useSandboxFiles(
1027
1062
  const live = await client.fsRead(
1028
1063
  workspaceId,
1029
1064
  sessionId,
1030
- { path },
1065
+ { path, ...(route ? { route } : {}) },
1031
1066
  { signal: identitySignal },
1032
1067
  );
1033
1068
  if (identityGenerationRef.current !== identityGeneration) {
@@ -1046,12 +1081,13 @@ export function useSandboxFiles(
1046
1081
  path,
1047
1082
  content,
1048
1083
  overwrite: true,
1084
+ ...(route ? { route } : {}),
1049
1085
  });
1050
1086
  },
1051
1087
  exists ? [] : [parent],
1052
1088
  );
1053
1089
  },
1054
- [client, workspaceId, sessionId, tree, rootPath, runOptimistic],
1090
+ [client, workspaceId, sessionId, tree, rootPath, route, runOptimistic],
1055
1091
  );
1056
1092
 
1057
1093
  const createFile = useCallback(
@@ -1072,11 +1108,12 @@ export function useSandboxFiles(
1072
1108
  path,
1073
1109
  content: "",
1074
1110
  overwrite: false,
1111
+ ...(route ? { route } : {}),
1075
1112
  }),
1076
1113
  [parent],
1077
1114
  );
1078
1115
  },
1079
- [client, workspaceId, sessionId, rootPath, runOptimistic],
1116
+ [client, workspaceId, sessionId, rootPath, route, runOptimistic],
1080
1117
  );
1081
1118
 
1082
1119
  const createDir = useCallback(
@@ -1094,11 +1131,16 @@ export function useSandboxFiles(
1094
1131
  await runOptimistic(
1095
1132
  "create folder",
1096
1133
  (nodes) => insertNode(nodes, parent, node, rootPath),
1097
- () => client.fsMkdir(workspaceId, sessionId, { path, recursive: true }),
1134
+ () =>
1135
+ client.fsMkdir(workspaceId, sessionId, {
1136
+ path,
1137
+ recursive: true,
1138
+ ...(route ? { route } : {}),
1139
+ }),
1098
1140
  [parent],
1099
1141
  );
1100
1142
  },
1101
- [client, workspaceId, sessionId, rootPath, runOptimistic],
1143
+ [client, workspaceId, sessionId, rootPath, route, runOptimistic],
1102
1144
  );
1103
1145
 
1104
1146
  const deleteEntry = useCallback(
@@ -1107,11 +1149,16 @@ export function useSandboxFiles(
1107
1149
  await runOptimistic(
1108
1150
  "delete",
1109
1151
  (nodes) => removeNode(nodes, path, rootPath),
1110
- () => client.fsDelete(workspaceId, sessionId, { path, recursive }),
1152
+ () =>
1153
+ client.fsDelete(workspaceId, sessionId, {
1154
+ path,
1155
+ recursive,
1156
+ ...(route ? { route } : {}),
1157
+ }),
1111
1158
  [parentWithinTree(path, rootPath)],
1112
1159
  );
1113
1160
  },
1114
- [client, workspaceId, sessionId, rootPath, runOptimistic],
1161
+ [client, workspaceId, sessionId, rootPath, route, runOptimistic],
1115
1162
  );
1116
1163
 
1117
1164
  const moveEntry = useCallback(
@@ -1133,11 +1180,12 @@ export function useSandboxFiles(
1133
1180
  path,
1134
1181
  newPath,
1135
1182
  overwrite: opts?.overwrite ?? false,
1183
+ ...(route ? { route } : {}),
1136
1184
  }),
1137
1185
  to === from ? [from] : [from, to],
1138
1186
  );
1139
1187
  },
1140
- [client, workspaceId, sessionId, rootPath, runOptimistic],
1188
+ [client, workspaceId, sessionId, rootPath, route, runOptimistic],
1141
1189
  );
1142
1190
 
1143
1191
  // Initial paint + reset on identity change. Source selection:
@@ -74,10 +74,10 @@ export type UseSessionEventsResult = {
74
74
  error: Error | null;
75
75
  };
76
76
 
77
- const INITIAL_TAIL_PAGE_SIZE = 1000;
78
- const OLDER_PAGE_SIZE = 5000;
79
- const NEWER_PAGE_SIZE = 5000;
80
- const OLDEST_PAGE_SIZE = 1000;
77
+ // Keep every browser history read inside one database batch, including the
78
+ // server's one-row continuation lookahead. A large total session must never
79
+ // turn one lazy page into dozens of sequential database round trips.
80
+ const SESSION_HISTORY_PAGE_SIZE = 255;
81
81
  const INITIAL_FETCH_CAP = 1;
82
82
  const OLDER_GROUP_TARGET = 32;
83
83
  const OLDER_FETCH_CAP = 2;
@@ -85,13 +85,16 @@ const NEWER_GROUP_TARGET = 32;
85
85
  const NEWER_FETCH_CAP = 2;
86
86
  const OLDEST_GROUP_TARGET = 32;
87
87
  const OLDEST_FETCH_CAP = 2;
88
- const BOUNDARY_PAGE_CAP = 4;
88
+ // A tail page may land inside one unusually dense turn. Permit exactly one
89
+ // additional bounded page to find its user/session boundary without turning a
90
+ // fresh open into an unbounded history walk.
91
+ const BOUNDARY_PAGE_CAP = 1;
89
92
  // Foreground reconciliation is intentionally semantic, not merely time-based:
90
93
  // tiny raw gaps can stay on SSE; medium raw gaps get one compact probe so a
91
94
  // token-heavy single answer is not mistaken for hundreds of visible messages;
92
95
  // only a large/complex missed window reloads the latest tail.
93
96
  const FOREGROUND_DIRECT_REPLAY_MAX_SEQUENCES = 16;
94
- const FOREGROUND_COMPACT_PROBE_MAX_SEQUENCES = 5_000;
97
+ const FOREGROUND_COMPACT_PROBE_MAX_SEQUENCES = SESSION_HISTORY_PAGE_SIZE;
95
98
  const FOREGROUND_COMPACT_CATCHUP_MAX_EVENTS = 128;
96
99
  const FOREGROUND_COMPACT_CATCHUP_MAX_GROUPS = 16;
97
100
  const FOREGROUND_COMPACT_CATCHUP_MAX_BYTES = 512 * 1024;
@@ -387,19 +390,10 @@ export function useSessionEvents(
387
390
  }
388
391
  } else if (plan.kind === "reload") {
389
392
  // A large/complex missed window would make the foreground timeline
390
- // and pinned camera chase many rapid commits. Clear once so the
391
- // normal bottom-anchored bulk-load path can paint one latest tail.
392
- eventWindowRef.current = EMPTY_EVENT_WINDOW;
393
- oldestSequenceRef.current = null;
394
- newestSequenceRef.current = null;
395
- hasOlderRef.current = false;
396
- hasNewerRef.current = false;
393
+ // and pinned camera chase many rapid commits. Keep the last known
394
+ // complete window visible until the bounded latest replacement is
395
+ // ready, then install that replacement atomically below.
397
396
  initialWindowLoadedRef.current = false;
398
- streamResumeSequenceRef.current = after;
399
- setEventWindow(EMPTY_EVENT_WINDOW);
400
- setHasOlder(false);
401
- setHasNewer(false);
402
- setInitialLoading(true);
403
397
  setError(null);
404
398
  }
405
399
  }
@@ -410,9 +404,10 @@ export function useSessionEvents(
410
404
  // reader actually scrolls up (the sentinel drives loadOlder).
411
405
  const window = await loadEventWindow(client, workspaceId, sessionId, {
412
406
  before: Number.MAX_SAFE_INTEGER,
413
- pageSize: INITIAL_TAIL_PAGE_SIZE,
407
+ pageSize: SESSION_HISTORY_PAGE_SIZE,
414
408
  targetGroups: Number.POSITIVE_INFINITY,
415
409
  maxFetches: INITIAL_FETCH_CAP,
410
+ boundaryPageCap: BOUNDARY_PAGE_CAP,
416
411
  signal: controller.signal,
417
412
  });
418
413
  if (!isCurrent()) {
@@ -555,7 +550,7 @@ export function useSessionEvents(
555
550
  try {
556
551
  const window = await loadEventWindow(client, workspaceId, sessionId, {
557
552
  before,
558
- pageSize: OLDER_PAGE_SIZE,
553
+ pageSize: SESSION_HISTORY_PAGE_SIZE,
559
554
  targetGroups: OLDER_GROUP_TARGET,
560
555
  maxFetches: OLDER_FETCH_CAP,
561
556
  });
@@ -660,7 +655,7 @@ export function useSessionEvents(
660
655
  try {
661
656
  const window = await loadForwardEventWindow(client, workspaceId, sessionId, {
662
657
  after: 0,
663
- pageSize: OLDEST_PAGE_SIZE,
658
+ pageSize: SESSION_HISTORY_PAGE_SIZE,
664
659
  targetGroups: OLDEST_GROUP_TARGET,
665
660
  maxFetches: OLDEST_FETCH_CAP,
666
661
  });
@@ -729,7 +724,7 @@ export function useSessionEvents(
729
724
  try {
730
725
  const window = await loadForwardEventWindow(client, workspaceId, sessionId, {
731
726
  after: afterSequence,
732
- pageSize: NEWER_PAGE_SIZE,
727
+ pageSize: SESSION_HISTORY_PAGE_SIZE,
733
728
  targetGroups: NEWER_GROUP_TARGET,
734
729
  maxFetches: NEWER_FETCH_CAP,
735
730
  });
@@ -1266,6 +1261,7 @@ async function loadEventWindow(
1266
1261
  pageSize: number;
1267
1262
  targetGroups: number;
1268
1263
  maxFetches: number;
1264
+ boundaryPageCap?: number;
1269
1265
  signal?: AbortSignal;
1270
1266
  },
1271
1267
  ): Promise<LoadedEventWindow> {
@@ -1300,14 +1296,13 @@ async function loadEventWindow(
1300
1296
  // turn boundary already in the buffer — the dropped fragment is refetched by
1301
1297
  // the next loadOlder (everything below the new oldest sequence), whose own
1302
1298
  // window snaps the same way, so every seam lands on a turn start. Extra
1303
- // pages are fetched only when the buffer holds no boundary at all (one
1304
- // monster turn); past the cap a mid-turn top is accepted.
1299
+ // page is fetched only when the buffer holds no boundary at all (one dense
1300
+ // turn); past the cap the existing truncation/hasOlder signal remains true.
1305
1301
  let snapPages = 0;
1306
1302
  while (
1307
1303
  !reachedStart &&
1308
1304
  findBoundaryIndex(buffer) === -1 &&
1309
- snapPages < BOUNDARY_PAGE_CAP &&
1310
- fetches < options.maxFetches
1305
+ snapPages < (options.boundaryPageCap ?? 0)
1311
1306
  ) {
1312
1307
  const page = await loadPreviousPage(client, workspaceId, sessionId, cursor, {
1313
1308
  pageSize: options.pageSize,
@@ -1,4 +1,5 @@
1
- import { useCallback, useEffect, useRef, useState } from "react";
1
+ import type { FileSystemRouteIdentity } from "@opengeni/sdk";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
3
  import { useOpenGeni, type ClientOverride } from "../provider";
3
4
  import { sandboxAcceptsLiveIo } from "../lib/sandbox-liveness";
4
5
 
@@ -39,6 +40,9 @@ export type UseWorkspaceEditOptions = ClientOverride & {
39
40
  path?: string | null | undefined;
40
41
  /** The capture-served content loaded into the editor — the flush base (C2). */
41
42
  baseContent?: string | null | undefined;
43
+ /** Exact capability identity for the selected filesystem route. A route/root
44
+ * change discards the buffered edit and makes stale flushes fail retryably. */
45
+ route?: FileSystemRouteIdentity | undefined;
42
46
  /** `capabilities.liveness` — "warm" | "draining" | "cold". Drives the flush. */
43
47
  liveness?: string | undefined;
44
48
  /** True while the host is actively warming the box (attach in flight, not warm
@@ -95,9 +99,18 @@ export function useWorkspaceEdit(
95
99
  const { client, workspaceId } = useOpenGeni(options);
96
100
  const path = options.path ?? null;
97
101
  const baseContent = options.baseContent ?? null;
102
+ const routeEpoch = options.route?.epoch;
103
+ const routeRoot = options.route?.root;
104
+ const route = useMemo<FileSystemRouteIdentity | undefined>(
105
+ () =>
106
+ routeEpoch !== undefined && routeRoot !== undefined
107
+ ? { epoch: routeEpoch, root: routeRoot }
108
+ : undefined,
109
+ [routeEpoch, routeRoot],
110
+ );
98
111
  const live = isLive(options.liveness);
99
112
  const offline = options.offline === true;
100
- const identityKey = `${workspaceId}\u0000${sessionId ?? ""}\u0000${path ?? ""}`;
113
+ const identityKey = `${workspaceId}\u0000${sessionId ?? ""}\u0000${path ?? ""}\u0000${routeEpoch ?? ""}\u0000${routeRoot ?? ""}`;
101
114
 
102
115
  const [buffer, setBuffer] = useState<string | null>(null);
103
116
  const [wantsWarm, setWantsWarm] = useState(false);
@@ -178,7 +191,7 @@ export function useWorkspaceEdit(
178
191
  const liveRead = await client.fsRead(
179
192
  workspaceId,
180
193
  sessionId,
181
- { path },
194
+ { path, ...(route ? { route } : {}) },
182
195
  { signal: readAbort.signal },
183
196
  );
184
197
  if (readAbortRef.current === readAbort) readAbortRef.current = null;
@@ -190,7 +203,12 @@ export function useWorkspaceEdit(
190
203
  return;
191
204
  }
192
205
  }
193
- await client.fsWrite(workspaceId, sessionId, { path, content, overwrite: true });
206
+ await client.fsWrite(workspaceId, sessionId, {
207
+ path,
208
+ content,
209
+ overwrite: true,
210
+ ...(route ? { route } : {}),
211
+ });
194
212
  if (identityGenerationRef.current !== identityGeneration) return;
195
213
  setConflict(null);
196
214
  setFlush("flushed");
@@ -207,7 +225,7 @@ export function useWorkspaceEdit(
207
225
  }
208
226
  }
209
227
  },
210
- [client, workspaceId, sessionId, path, baseContent, stateIdentity, identityKey],
228
+ [client, workspaceId, sessionId, path, baseContent, route, stateIdentity, identityKey],
211
229
  );
212
230
 
213
231
  // Auto-flush once the box is warm and a buffer is pending (the wake completed).
@@ -8,6 +8,7 @@ const FLEET_ACTUAL_REASONS = [
8
8
  "rotation",
9
9
  "active",
10
10
  "all_capped",
11
+ "allocator_disabled",
11
12
  "none",
12
13
  ] as const;
13
14
  const FLEET_SHADOW_OUTCOMES = ["selected", "paced", "none"] as const;
@@ -334,7 +335,7 @@ function fleetDecisionSemanticsAreConsistent(input: {
334
335
  input.actualOutcome === "selected"
335
336
  ? ["lease_reused", "pin", "rotation", "active"].includes(input.actualReason)
336
337
  : input.actualOutcome === "waiting"
337
- ? input.actualReason === "all_capped"
338
+ ? ["all_capped", "allocator_disabled"].includes(input.actualReason)
338
339
  : input.actualReason === "none";
339
340
  const shadowConsistent =
340
341
  input.shadowOutcome === "selected"
@@ -28,6 +28,7 @@ const FLEET_ACTUAL_REASON_LABEL: Record<FleetDecisionItem["actualReason"], strin
28
28
  rotation: "Rotated for capacity",
29
29
  active: "Used the active subscription",
30
30
  all_capped: "All observed subscriptions were capped",
31
+ allocator_disabled: "The policy-selected subscription was disabled for new allocations",
31
32
  none: "No production candidate was selected",
32
33
  };
33
34