zidane-ui 9.3.1 → 9.4.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 (255) hide show
  1. package/dist/adapters/live.d.ts +2 -0
  2. package/dist/adapters/live.js +3 -0
  3. package/dist/adapters/server-git-host.js +5 -2
  4. package/dist/adapters/server-host.js +17 -11
  5. package/dist/adapters/server-machines-host.js +7 -0
  6. package/dist/adapters/server-session-host.js +49 -0
  7. package/dist/adapters/server-settings-sections.js +4 -1
  8. package/dist/adapters/sse-host.js +3 -0
  9. package/dist/adapters/sse-protocol.d.ts +10 -0
  10. package/dist/appearance/ZoomIndicator.js +5 -8
  11. package/dist/chat/HostTranscript.js +15 -1
  12. package/dist/chat/SessionStreamsProvider.d.ts +1 -1
  13. package/dist/chat/Transcript.d.ts +3 -2
  14. package/dist/chat/Transcript.js +26 -7
  15. package/dist/chat/composer/ComposerEditor.js +1 -1
  16. package/dist/chat/composer/ModelOptionsPicker.js +6 -2
  17. package/dist/chat/composer/ModelPicker.d.ts +1 -1
  18. package/dist/chat/composer/PlacePicker.d.ts +3 -1
  19. package/dist/chat/composer/PlacePicker.js +5 -1
  20. package/dist/chat/composer/use-draft-target.js +15 -3
  21. package/dist/chat/headless/block-runs.js +26 -1
  22. package/dist/chat/headless/chip-views.js +1 -1
  23. package/dist/chat/headless/draft-target.d.ts +28 -1
  24. package/dist/chat/headless/draft-target.js +22 -1
  25. package/dist/chat/headless/hosts.d.ts +4 -0
  26. package/dist/chat/headless/index.d.ts +25 -25
  27. package/dist/chat/headless/index.js +6 -6
  28. package/dist/chat/headless/markdown-scan.d.ts +0 -2
  29. package/dist/chat/headless/markdown-scan.js +3 -8
  30. package/dist/chat/headless/markdown-stream.js +3 -3
  31. package/dist/chat/headless/prompt-origin.d.ts +2 -0
  32. package/dist/chat/headless/prompt-origin.js +6 -2
  33. package/dist/chat/headless/sidebar/directory.d.ts +10 -1
  34. package/dist/chat/headless/sidebar/directory.js +9 -1
  35. package/dist/chat/headless/sidebar/environment.d.ts +15 -4
  36. package/dist/chat/headless/sidebar/environment.js +27 -9
  37. package/dist/chat/headless/sidebar/index.d.ts +2 -2
  38. package/dist/chat/headless/sidebar/index.js +2 -2
  39. package/dist/chat/headless/sidebar/labels.d.ts +9 -2
  40. package/dist/chat/headless/sidebar/labels.js +8 -1
  41. package/dist/chat/headless/streams/actions.d.ts +2 -2
  42. package/dist/chat/headless/streams/actions.js +1 -1
  43. package/dist/chat/headless/streams/event-bytes.d.ts +12 -1
  44. package/dist/chat/headless/streams/event-bytes.js +13 -1
  45. package/dist/chat/headless/streams/store.d.ts +21 -5
  46. package/dist/chat/headless/streams/store.js +36 -7
  47. package/dist/chat/headless/streams/transcript-map.js +2 -5
  48. package/dist/chat/headless/streams/types.d.ts +2 -1
  49. package/dist/chat/headless/transcript/collapse.js +3 -0
  50. package/dist/chat/index.d.ts +2 -2
  51. package/dist/chat/index.js +2 -2
  52. package/dist/chat/sidebar/ProjectIcon.js +1 -1
  53. package/dist/chat/sidebar/RowChips.js +2 -2
  54. package/dist/chat/sidebar/SessionSidebar.d.ts +6 -0
  55. package/dist/chat/sidebar/SessionSidebar.js +23 -16
  56. package/dist/chat/sidebar/SidebarFilterMenu.js +0 -1
  57. package/dist/chat/sidebar/SidebarFold.js +17 -16
  58. package/dist/chat/sidebar/SidebarSessionRow.d.ts +7 -1
  59. package/dist/chat/sidebar/SidebarSessionRow.js +11 -8
  60. package/dist/chat/sidebar/session-menu.d.ts +4 -0
  61. package/dist/chat/sidebar/session-menu.js +14 -2
  62. package/dist/chat/sidebar/sidebar-live.js +28 -4
  63. package/dist/chat/sidebar/useInboxRows.js +6 -6
  64. package/dist/chat/sidebar/useInboxTriage.js +50 -47
  65. package/dist/chat/sidebar/useSessionSearch.js +19 -18
  66. package/dist/chat/transcript/FileChip.js +28 -0
  67. package/dist/chat/transcript/LazyRow.d.ts +1 -1
  68. package/dist/chat/transcript/LazyRow.js +3 -4
  69. package/dist/chat/transcript/PromptEcho.js +3 -11
  70. package/dist/chat/transcript/SessionChip.d.ts +11 -0
  71. package/dist/chat/transcript/SessionChip.js +34 -0
  72. package/dist/chat/transcript/TranscriptRail.d.ts +1 -1
  73. package/dist/chat/transcript/chip-details.d.ts +11 -0
  74. package/dist/chat/transcript/chip-details.js +17 -1
  75. package/dist/chat/transcript/fold-worker.js +2 -1
  76. package/dist/chat/transcript/fold.js +11 -3
  77. package/dist/chat/transcript/index.d.ts +2 -2
  78. package/dist/chat/transcript/index.js +2 -2
  79. package/dist/chat/transcript/markdown-cache.d.ts +10 -1
  80. package/dist/chat/transcript/markdown-cache.js +37 -4
  81. package/dist/chat/transcript/markdown.js +27 -34
  82. package/dist/chat/transcript/media-gallery.js +13 -16
  83. package/dist/chat/transcript/messages.js +5 -4
  84. package/dist/chat/transcript/prompt.d.ts +1 -1
  85. package/dist/chat/transcript/row-mount.d.ts +27 -8
  86. package/dist/chat/transcript/row-mount.js +114 -80
  87. package/dist/chat/transcript/row-parking.d.ts +27 -0
  88. package/dist/chat/transcript/row-parking.js +37 -1
  89. package/dist/chat/transcript/script-input.d.ts +1 -1
  90. package/dist/chat/transcript/tool-parts.js +0 -1
  91. package/dist/chat/transcript/use-transcript-rows.d.ts +1 -1
  92. package/dist/chat/transcript/useHistoryBackfill.d.ts +42 -0
  93. package/dist/chat/transcript/useHistoryBackfill.js +170 -0
  94. package/dist/chat/transcript/useTranscriptFind.js +2 -4
  95. package/dist/chat/transcript/useTranscriptScroll.d.ts +7 -4
  96. package/dist/chat/transcript/useTranscriptScroll.js +12 -1
  97. package/dist/chat/transcript/useTranscriptSearch.d.ts +2 -2
  98. package/dist/chat/transcript/useTranscriptSearch.js +6 -6
  99. package/dist/chat/transcript/useTranscriptSelectionCopy.d.ts +5 -5
  100. package/dist/chat/transcript/useTranscriptSelectionCopy.js +28 -7
  101. package/dist/code/editor/FileTree.d.ts +2 -0
  102. package/dist/code/editor/FileTree.js +1 -1
  103. package/dist/code/editor/FileView.js +16 -25
  104. package/dist/code/editor/find/useFind.js +17 -17
  105. package/dist/code/editor/useCodeDocument.js +22 -19
  106. package/dist/code/editor/useDetachCleanup.js +4 -3
  107. package/dist/code/use-highlighted-html.js +12 -13
  108. package/dist/components/IconButton.d.ts +3 -1
  109. package/dist/components/IconButton.js +7 -2
  110. package/dist/components/IconButtonTip.d.ts +3 -1
  111. package/dist/components/IconButtonTip.js +2 -1
  112. package/dist/components/RowActionsMenu.js +7 -14
  113. package/dist/components/Tooltip.d.ts +4 -1
  114. package/dist/components/Tooltip.js +8 -6
  115. package/dist/components/assign-ref.d.ts +8 -0
  116. package/dist/components/assign-ref.js +12 -0
  117. package/dist/components/floating/FloatingSurface.js +2 -2
  118. package/dist/components/floating/HoverCard.js +32 -14
  119. package/dist/components/floating/Popover.js +4 -7
  120. package/dist/components/floating/useAnchoredPosition.d.ts +5 -3
  121. package/dist/components/floating/useAnchoredPosition.js +7 -7
  122. package/dist/components/object-key.d.ts +7 -0
  123. package/dist/components/object-key.js +18 -0
  124. package/dist/components/palette/PaletteList.js +2 -7
  125. package/dist/components/tooltip-arming.d.ts +3 -0
  126. package/dist/components/tooltip-arming.js +8 -1
  127. package/dist/core.css +3 -3
  128. package/dist/dist/{index-C6-t1SS9.d.ts → index-BheVJOLc.d.ts} +1 -0
  129. package/dist/dist/index.d.ts +2 -2
  130. package/dist/files/FilesTab.js +0 -1
  131. package/dist/files/TreeColumn.d.ts +2 -4
  132. package/dist/files/TreeColumn.js +0 -5
  133. package/dist/files/headless/host.d.ts +3 -7
  134. package/dist/files/headless/labels.d.ts +0 -1
  135. package/dist/files/headless/labels.js +0 -1
  136. package/dist/files/headless/workspace-diff.js +1 -1
  137. package/dist/files/useCodeReview.js +1 -3
  138. package/dist/files/useFilesDiagnostics.d.ts +1 -1
  139. package/dist/files/useFilesDiagnostics.js +4 -11
  140. package/dist/files/useOpenFiles.js +9 -12
  141. package/dist/files/useWorkspace.d.ts +5 -7
  142. package/dist/files/useWorkspace.js +4 -15
  143. package/dist/git/GitBar.js +5 -3
  144. package/dist/git/MoveSessionDialog.d.ts +18 -8
  145. package/dist/git/MoveSessionDialog.js +32 -53
  146. package/dist/git/MoveToDialog.d.ts +61 -0
  147. package/dist/git/MoveToDialog.js +240 -0
  148. package/dist/git/SandboxManager.js +9 -4
  149. package/dist/git/SyncChip.js +11 -4
  150. package/dist/git/TeleportSessionDialog.d.ts +69 -0
  151. package/dist/git/TeleportSessionDialog.js +440 -0
  152. package/dist/git/headless/host.d.ts +14 -0
  153. package/dist/git/headless/index.d.ts +2 -1
  154. package/dist/git/headless/index.js +2 -1
  155. package/dist/git/headless/labels.d.ts +44 -1
  156. package/dist/git/headless/labels.js +50 -0
  157. package/dist/git/headless/sandboxes.d.ts +1 -1
  158. package/dist/git/headless/sandboxes.js +4 -3
  159. package/dist/git/headless/teleport.d.ts +76 -0
  160. package/dist/git/headless/teleport.js +19 -0
  161. package/dist/git/index.d.ts +4 -2
  162. package/dist/git/index.js +4 -2
  163. package/dist/git/useEnvironmentChoices.d.ts +5 -2
  164. package/dist/git/useEnvironmentChoices.js +12 -4
  165. package/dist/hooks/useLatest.d.ts +8 -0
  166. package/dist/hooks/useLatest.js +17 -0
  167. package/dist/hooks/useMinuteTick.d.ts +6 -2
  168. package/dist/hooks/useMinuteTick.js +12 -6
  169. package/dist/hooks/useNearViewport.js +11 -8
  170. package/dist/index.d.ts +3 -2
  171. package/dist/index.js +2 -1
  172. package/dist/keybindings/KeybindingsProvider.js +3 -4
  173. package/dist/keybindings/headless/catalog.d.ts +1 -1
  174. package/dist/keybindings/headless/catalog.js +18 -0
  175. package/dist/machines/AddServerForm.js +55 -3
  176. package/dist/machines/Banners.d.ts +2 -2
  177. package/dist/machines/Banners.js +3 -3
  178. package/dist/machines/DaemonMenu.js +1 -3
  179. package/dist/machines/HostsSection.js +5 -1
  180. package/dist/machines/OrganizationPanel.d.ts +25 -0
  181. package/dist/machines/OrganizationPanel.js +266 -0
  182. package/dist/machines/PersonalLayerPanel.d.ts +32 -0
  183. package/dist/machines/PersonalLayerPanel.js +360 -0
  184. package/dist/machines/headless/fixture-host.d.ts +10 -0
  185. package/dist/machines/headless/fixture-host.js +44 -0
  186. package/dist/machines/headless/host.d.ts +21 -1
  187. package/dist/machines/headless/index.d.ts +3 -1
  188. package/dist/machines/headless/index.js +3 -1
  189. package/dist/machines/headless/labels.d.ts +55 -0
  190. package/dist/machines/headless/labels.js +58 -1
  191. package/dist/machines/headless/layer.d.ts +64 -0
  192. package/dist/machines/headless/layer.js +56 -0
  193. package/dist/machines/headless/organization.d.ts +38 -0
  194. package/dist/machines/headless/organization.js +44 -0
  195. package/dist/machines/index.d.ts +3 -1
  196. package/dist/machines/index.js +3 -1
  197. package/dist/machines/testing/contract.d.ts +25 -1
  198. package/dist/machines/testing/contract.js +97 -1
  199. package/dist/motion/grow.js +12 -13
  200. package/dist/motion/swap.js +2 -5
  201. package/dist/motion/use-flip-list.d.ts +14 -0
  202. package/dist/motion/use-flip-list.js +17 -12
  203. package/dist/palette/headless/app-sources.js +37 -0
  204. package/dist/palette/headless/labels.js +3 -0
  205. package/dist/server/sse-handler.js +25 -2
  206. package/dist/session/DiffFileTree.js +1 -4
  207. package/dist/session/OpenSessionsDialog.d.ts +46 -0
  208. package/dist/session/OpenSessionsDialog.js +170 -0
  209. package/dist/session/PlanTracker.js +1 -2
  210. package/dist/session/ProjectHome.js +10 -9
  211. package/dist/session/RemindersPanel.js +10 -12
  212. package/dist/session/SecretsPanel.js +2 -1
  213. package/dist/session/SessionPeopleStack.d.ts +23 -0
  214. package/dist/session/SessionPeopleStack.js +65 -0
  215. package/dist/session/SessionPlaceMenu.js +5 -4
  216. package/dist/session/ShareSessionDialog.d.ts +32 -0
  217. package/dist/session/ShareSessionDialog.js +342 -0
  218. package/dist/session/TypingLine.d.ts +22 -0
  219. package/dist/session/TypingLine.js +31 -0
  220. package/dist/session/headless/host.d.ts +40 -1
  221. package/dist/session/headless/index.d.ts +4 -2
  222. package/dist/session/headless/index.js +3 -1
  223. package/dist/session/headless/labels.d.ts +49 -0
  224. package/dist/session/headless/labels.js +56 -0
  225. package/dist/session/headless/people.d.ts +29 -0
  226. package/dist/session/headless/people.js +53 -0
  227. package/dist/session/headless/place.d.ts +5 -0
  228. package/dist/session/headless/place.js +5 -1
  229. package/dist/session/headless/typing.d.ts +37 -0
  230. package/dist/session/headless/typing.js +60 -0
  231. package/dist/session/index.d.ts +5 -1
  232. package/dist/session/index.js +5 -1
  233. package/dist/settings/headless/search.d.ts +1 -1
  234. package/dist/settings/headless/sections-host.d.ts +7 -2
  235. package/dist/settings/section.d.ts +15 -3
  236. package/dist/settings/section.js +15 -3
  237. package/dist/settings/sections/environments/EnvironmentsSection.js +30 -6
  238. package/dist/settings/sections/keybindings/labels.d.ts +3 -0
  239. package/dist/settings/sections/keybindings/labels.js +3 -0
  240. package/dist/settings/sections/keybindings/rows.js +12 -0
  241. package/dist/settings/sections/logs/LogsSection.js +5 -8
  242. package/dist/styles.css +32 -7
  243. package/dist/terminal/HostTerminalSurface.js +28 -30
  244. package/dist/terminal/TerminalPanel.js +4 -12
  245. package/dist/terminal/TerminalProvider.d.ts +10 -2
  246. package/dist/terminal/TerminalProvider.js +10 -2
  247. package/dist/terminal/headless/labels.d.ts +0 -1
  248. package/dist/terminal/headless/labels.js +1 -2
  249. package/dist/terminal/headless/store.js +5 -1
  250. package/dist/workspace/LayoutBudget.js +1 -7
  251. package/package.json +2 -2
  252. package/src/styles/chat.css +3 -1
  253. package/src/styles/palette.css +3 -3
  254. package/src/styles/transcript.css +17 -3
  255. /package/dist/dist/{index-De9AbmxS.d.ts → index-ttmMvjgM.d.ts} +0 -0
@@ -1,13 +1,11 @@
1
1
  import { scrollRootOf } from "../../hooks/useNearViewport.js";
2
2
  import { createRecentMap } from "./recent-map.js";
3
- import { PARK_IDLE_MS, idleWait, keepsSize, parkCandidates, parkPlan, pumpOrder } from "./row-parking.js";
3
+ import { PARK_IDLE_MS, idleWait, keepsSize, parkCandidates, parkPlan, pumpOrder, rowsInRange } from "./row-parking.js";
4
4
  import { createContext } from "react";
5
5
  import { flushSync } from "react-dom";
6
6
  // src/chat/transcript/row-mount.ts
7
- /** Far enough ahead that a fast flick finds rows mounted before they arrive. */
8
- const MARGIN = "2500px 0px";
9
- /** Within this, a row mounts right away (and, without state events, counts as rendered). */
10
- const NEAR_MARGIN = "100% 0px";
7
+ /** Far enough ahead (each way) that a fast flick finds rows mounted before they arrive. */
8
+ const MARGIN_PX = 2500;
11
9
  /** Main-thread time a frame may spend mounting rows ahead of the view. */
12
10
  const BUDGET_MS = 6;
13
11
  /** Rows parked per commit inside a slice. */
@@ -48,16 +46,22 @@ var RowMounter = class {
48
46
  skipped = /* @__PURE__ */ new WeakMap();
49
47
  /** Each mounted row's height as last laid out (its ResizeObserver entry): what a parked placeholder keeps. */
50
48
  boxes = /* @__PURE__ */ new WeakMap();
51
- near = /* @__PURE__ */ new WeakSet();
52
- queue = /* @__PURE__ */ new Map();
49
+ /** The rows within a view of the view, as the last range check found them. */
50
+ near = /* @__PURE__ */ new Set();
51
+ /** Rows within the far margin waiting to mount, in order. */
52
+ queue = [];
53
+ /** The wrappers in document order (rebuilt after rows come or go). */
54
+ order = [];
55
+ orderDirty = false;
53
56
  mountedCount = 0;
54
57
  timeline = null;
55
58
  scroller = null;
56
- far = null;
57
- close = null;
58
59
  ro = null;
59
60
  cvEvents = hasCvEvents();
60
- io = typeof IntersectionObserver !== "undefined";
61
+ /** A browser (jsdom has no IntersectionObserver, and no layout): without one every row mounts. */
62
+ browser = typeof IntersectionObserver !== "undefined";
63
+ checkScheduled = false;
64
+ lateScheduled = false;
61
65
  pumpScheduled = false;
62
66
  lastActivity = -Infinity;
63
67
  direction = 0;
@@ -108,7 +112,7 @@ var RowMounter = class {
108
112
  const last = this.phases.get(key);
109
113
  const eager = this.eager.has(key);
110
114
  return {
111
- mounted: !this.io || this.all || this.held.has(key) || eager || last === "mounted",
115
+ mounted: !this.browser || this.all || this.held.has(key) || eager || last === "mounted",
112
116
  eager,
113
117
  seen: last !== void 0
114
118
  };
@@ -183,14 +187,12 @@ var RowMounter = class {
183
187
  this.byEl.set(slot.el, slot);
184
188
  this.phases.set(slot.key, slot.phase);
185
189
  if (slot.phase === "mounted") this.mounted(slot);
186
- else this.observeApproach(slot);
187
- if (!this.cvEvents) this.close?.observe(slot.el);
190
+ this.orderDirty = true;
191
+ this.checkAfterLayout();
188
192
  return () => {
189
193
  if (this.slots.get(slot.key) === slot) this.slots.delete(slot.key);
190
194
  if (slot.phase === "mounted") this.mountedCount--;
191
- this.queue.delete(slot.el);
192
- this.far?.unobserve(slot.el);
193
- this.close?.unobserve(slot.el);
195
+ this.orderDirty = true;
194
196
  this.ro?.unobserve(slot.el);
195
197
  };
196
198
  }
@@ -205,16 +207,10 @@ var RowMounter = class {
205
207
  const scroller = scrollRootOf(el);
206
208
  this.timeline = timeline;
207
209
  this.scroller = scroller;
208
- if (typeof ResizeObserver !== "undefined") this.ro = new ResizeObserver((entries) => this.onResize(entries));
209
- if (this.io) {
210
- this.far = new IntersectionObserver((entries) => this.onFar(entries), {
211
- root: scroller,
212
- rootMargin: MARGIN
213
- });
214
- this.close = new IntersectionObserver((entries) => this.onNear(entries), {
215
- root: scroller,
216
- rootMargin: NEAR_MARGIN
217
- });
210
+ if (typeof ResizeObserver !== "undefined") {
211
+ this.ro = new ResizeObserver((entries) => this.onResize(entries));
212
+ if (scroller) this.ro.observe(scroller);
213
+ if (timeline) this.ro.observe(timeline);
218
214
  }
219
215
  const onCv = (e) => this.onCvState(e);
220
216
  const activity = () => {
@@ -230,6 +226,7 @@ var RowMounter = class {
230
226
  if (top !== this.lastTop) this.direction = Math.sign(top - this.lastTop);
231
227
  this.lastTop = top;
232
228
  if (sc.scrollHeight - top - sc.clientHeight > 2) activity();
229
+ this.scheduleCheck();
233
230
  };
234
231
  timeline?.addEventListener("contentvisibilityautostatechange", onCv, true);
235
232
  const target = scroller ?? (typeof window !== "undefined" ? window : null);
@@ -253,26 +250,19 @@ var RowMounter = class {
253
250
  ]) target?.removeEventListener(type, activity);
254
251
  if (typeof window !== "undefined") window.removeEventListener("keydown", onKey, true);
255
252
  if (scroller && mounters.get(scroller) === this) mounters.delete(scroller);
256
- this.far?.disconnect();
257
- this.close?.disconnect();
258
253
  this.ro?.disconnect();
259
- this.far = this.close = this.ro = null;
260
- this.queue.clear();
254
+ this.ro = null;
255
+ this.queue = [];
256
+ this.order = [];
257
+ this.near.clear();
261
258
  if (this.parkTimer) clearTimeout(this.parkTimer);
262
259
  this.parkTimer = null;
263
260
  this.timeline = this.scroller = null;
264
261
  };
265
262
  }
266
- observeApproach(slot) {
267
- this.far?.observe(slot.el);
268
- if (this.cvEvents) this.close?.observe(slot.el);
269
- }
270
263
  mounted(slot) {
271
264
  this.mountedCount++;
272
265
  this.ro?.observe(slot.el);
273
- this.far?.unobserve(slot.el);
274
- if (this.cvEvents) this.close?.unobserve(slot.el);
275
- this.queue.delete(slot.el);
276
266
  this.dirty = true;
277
267
  this.scheduleParking();
278
268
  }
@@ -286,32 +276,86 @@ var RowMounter = class {
286
276
  else if (was === "mounted") {
287
277
  this.mountedCount--;
288
278
  this.ro?.unobserve(slot.el);
289
- this.observeApproach(slot);
290
279
  }
291
280
  slot.set(phase, background, parkedPx);
292
281
  }
293
- onFar(entries) {
294
- for (const entry of entries) {
295
- const slot = this.byEl.get(entry.target);
296
- if (entry.isIntersecting && slot && slot.phase !== "mounted") this.queue.set(entry.target, slot);
297
- else if (!entry.isIntersecting) this.queue.delete(entry.target);
298
- }
299
- this.schedulePump();
282
+ /**
283
+ * One range check in the coming frame's animation callbacks, before its paint. From a scroll event, that is the
284
+ * scroll's own frame; from a ResizeObserver callback (after the frame's layout), the next one.
285
+ */
286
+ scheduleCheck() {
287
+ if (this.checkScheduled || !this.browser || !this.timeline) return;
288
+ this.checkScheduled = true;
289
+ requestAnimationFrame(() => this.check());
300
290
  }
301
- onNear(entries) {
302
- const now = [];
303
- for (const entry of entries) {
304
- const slot = this.byEl.get(entry.target);
305
- if (!slot) continue;
306
- if (!this.cvEvents) {
307
- if (entry.isIntersecting) {
308
- this.near.add(entry.target);
309
- this.remeasure(slot);
310
- } else this.near.delete(entry.target);
291
+ /**
292
+ * One range check in the frame after the coming one: rows committed now get their place first (a transcript
293
+ * opening at its bottom scrolls there after the coming frame's animation callbacks).
294
+ */
295
+ checkAfterLayout() {
296
+ if (this.lateScheduled || !this.browser || !this.timeline) return;
297
+ this.lateScheduled = true;
298
+ requestAnimationFrame(() => {
299
+ this.lateScheduled = false;
300
+ this.scheduleCheck();
301
+ });
302
+ }
303
+ /**
304
+ * Finds the rows near the view: those within a view of it mount now, those within the far margin queue for the
305
+ * pump. Reads the layout first (clean after a scroll), writes after.
306
+ */
307
+ check() {
308
+ this.checkScheduled = false;
309
+ const timeline = this.timeline;
310
+ if (!timeline) return;
311
+ const view = this.scroller?.getBoundingClientRect() ?? {
312
+ top: 0,
313
+ bottom: window.innerHeight
314
+ };
315
+ const viewPx = view.bottom - view.top;
316
+ if (viewPx <= 0) return;
317
+ if (this.orderDirty) {
318
+ this.orderDirty = false;
319
+ this.order = [];
320
+ for (const child of timeline.children) {
321
+ const slot = this.byEl.get(child);
322
+ if (slot && this.slots.get(slot.key) === slot) this.order.push(slot);
311
323
  }
312
- if (entry.isIntersecting && slot.phase !== "mounted") now.push(slot);
313
324
  }
325
+ const order = this.order;
326
+ if (order.length === 0) return;
327
+ const first = order[0].el;
328
+ const shift = first.getBoundingClientRect().top - first.offsetTop;
329
+ const range = rowsInRange(order.length, (i) => {
330
+ const el = order[i].el;
331
+ const top = el.offsetTop + shift;
332
+ return {
333
+ top,
334
+ bottom: top + el.offsetHeight
335
+ };
336
+ }, {
337
+ top: view.top,
338
+ bottom: view.bottom
339
+ }, MARGIN_PX, this.direction);
340
+ const near = /* @__PURE__ */ new Set();
341
+ const queued = [];
342
+ for (const { index, distance, ahead } of range) {
343
+ const slot = order[index];
344
+ if (distance <= viewPx) {
345
+ near.add(slot.el);
346
+ if (!this.cvEvents && !this.near.has(slot.el)) this.remeasure(slot);
347
+ }
348
+ if (slot.phase !== "mounted") queued.push({
349
+ row: slot,
350
+ distance,
351
+ ahead
352
+ });
353
+ }
354
+ this.near = near;
355
+ const { now, later } = pumpOrder(queued, viewPx);
314
356
  if (now.length > 0) flushSync(() => now.forEach((slot) => this.transition(slot, "mounted", false)));
357
+ this.queue = later;
358
+ this.schedulePump();
315
359
  }
316
360
  onCvState(e) {
317
361
  const slot = this.byEl.get(e.target);
@@ -327,6 +371,7 @@ var RowMounter = class {
327
371
  this.ro?.observe(slot.el);
328
372
  }
329
373
  onResize(entries) {
374
+ this.scheduleCheck();
330
375
  for (const entry of entries) {
331
376
  const slot = this.byEl.get(entry.target);
332
377
  if (!slot) continue;
@@ -343,37 +388,26 @@ var RowMounter = class {
343
388
  }
344
389
  }
345
390
  schedulePump() {
346
- if (this.pumpScheduled || this.queue.size === 0) return;
391
+ if (this.pumpScheduled || this.queue.length === 0) return;
347
392
  this.pumpScheduled = true;
348
- requestAnimationFrame(() => setTimeout(() => this.pump(), 0));
393
+ setTimeout(() => this.pump(), 0);
349
394
  }
395
+ /** Mounts queued rows, nearest first, until the budget is spent; what is left waits for the next check. */
350
396
  pump() {
351
397
  this.pumpScheduled = false;
352
- const rect = this.scroller?.getBoundingClientRect();
353
- const [top, bottom] = rect ? [rect.top, rect.bottom] : [0, window.innerHeight];
354
- const queued = [];
355
- for (const [el, slot] of this.queue) {
356
- if (!el.isConnected || slot.phase === "mounted") {
357
- this.queue.delete(el);
358
- continue;
359
- }
360
- const r = el.getBoundingClientRect();
361
- const distance = r.bottom >= top && r.top <= bottom ? 0 : r.top > bottom ? r.top - bottom : top - r.bottom;
362
- const ahead = this.direction === 0 || (this.direction < 0 ? r.bottom <= top : r.top >= bottom);
363
- queued.push({
364
- row: slot,
365
- distance,
366
- ahead
367
- });
368
- }
369
- const { now, later } = pumpOrder(queued, bottom - top);
370
- if (now.length > 0) flushSync(() => now.forEach((slot) => this.transition(slot, "mounted", false)));
398
+ const queue = this.queue;
399
+ this.queue = [];
371
400
  const start = performance.now();
372
- for (const slot of later) {
373
- if (performance.now() - start > BUDGET_MS) break;
401
+ let left = false;
402
+ for (const slot of queue) {
403
+ if (slot.phase === "mounted" || !slot.el.isConnected) continue;
404
+ if (performance.now() - start > BUDGET_MS) {
405
+ left = true;
406
+ break;
407
+ }
374
408
  flushSync(() => this.transition(slot, "mounted", true));
375
409
  }
376
- this.schedulePump();
410
+ if (left) this.scheduleCheck();
377
411
  }
378
412
  scheduleParking(delay = PARK_IDLE_MS) {
379
413
  if (this.parkTimer !== null || this.parking || !this.timeline) return;
@@ -2,6 +2,8 @@
2
2
  * The pure rules of how transcript rows mount (`row-mount.ts`), numbers in
3
3
  * and decisions out, so a test drives them without a layout:
4
4
  *
5
+ * - which rows are near the view (`rowsInRange`): a binary search over the
6
+ * rows in order, so a frame reads the rows near the view, never them all;
5
7
  * - which queued row mounts first (`pumpOrder`): the nearest, the rows
6
8
  * ahead of the scroll before the rows behind it;
7
9
  * - when a row's measured height is its true height (`keepsSize`): only
@@ -47,6 +49,31 @@ export interface SizeSample {
47
49
  * @param s - The {@link SizeSample}.
48
50
  */
49
51
  export declare function keepsSize(s: SizeSample): boolean;
52
+ /** A root row's box, in the view's coordinates. */
53
+ export interface RowBox {
54
+ top: number;
55
+ bottom: number;
56
+ }
57
+ /** A row within the margin of the view, and where it is. */
58
+ export interface RangeRow {
59
+ /** Its index in the rows' order. */
60
+ index: number;
61
+ /** Px between the row and the view (0: in it). */
62
+ distance: number;
63
+ /** The row lies in the direction the view is scrolling (or the view is still). */
64
+ ahead: boolean;
65
+ }
66
+ /**
67
+ * The rows within `margin` px of the view (edges included), nearest the top first. The rows are in document order,
68
+ * stacked top to bottom, so a binary search finds the first: it reads O(log rows + rows in range) boxes.
69
+ *
70
+ * @param count - How many rows.
71
+ * @param boxOf - A row's box by index.
72
+ * @param view - The view's box.
73
+ * @param margin - How far past the view each way.
74
+ * @param direction - The scroll's direction: -1 up, 1 down, 0 still.
75
+ */
76
+ export declare function rowsInRange(count: number, boxOf: (index: number) => RowBox, view: RowBox, margin: number, direction: number): RangeRow[];
50
77
  /** A row waiting to mount, and where it is. */
51
78
  export interface QueuedRow<T> {
52
79
  row: T;
@@ -3,6 +3,8 @@
3
3
  * The pure rules of how transcript rows mount (`row-mount.ts`), numbers in
4
4
  * and decisions out, so a test drives them without a layout:
5
5
  *
6
+ * - which rows are near the view (`rowsInRange`): a binary search over the
7
+ * rows in order, so a frame reads the rows near the view, never them all;
6
8
  * - which queued row mounts first (`pumpOrder`): the nearest, the rows
7
9
  * ahead of the scroll before the rows behind it;
8
10
  * - when a row's measured height is its true height (`keepsSize`): only
@@ -40,6 +42,40 @@ function keepsSize(s) {
40
42
  if (s.skipped !== null) return !s.skipped;
41
43
  return !s.cvEvents && s.nearView;
42
44
  }
45
+ /**
46
+ * The rows within `margin` px of the view (edges included), nearest the top first. The rows are in document order,
47
+ * stacked top to bottom, so a binary search finds the first: it reads O(log rows + rows in range) boxes.
48
+ *
49
+ * @param count - How many rows.
50
+ * @param boxOf - A row's box by index.
51
+ * @param view - The view's box.
52
+ * @param margin - How far past the view each way.
53
+ * @param direction - The scroll's direction: -1 up, 1 down, 0 still.
54
+ */
55
+ function rowsInRange(count, boxOf, view, margin, direction) {
56
+ const from = view.top - margin;
57
+ const to = view.bottom + margin;
58
+ let lo = 0;
59
+ let hi = count;
60
+ while (lo < hi) {
61
+ const mid = lo + hi >> 1;
62
+ if (boxOf(mid).bottom < from) lo = mid + 1;
63
+ else hi = mid;
64
+ }
65
+ const out = [];
66
+ for (let index = lo; index < count; index++) {
67
+ const box = boxOf(index);
68
+ if (box.top > to) break;
69
+ const distance = box.bottom < view.top ? view.top - box.bottom : box.top > view.bottom ? box.top - view.bottom : 0;
70
+ const ahead = direction === 0 || (direction < 0 ? box.bottom <= view.top : box.top >= view.bottom);
71
+ out.push({
72
+ index,
73
+ distance,
74
+ ahead
75
+ });
76
+ }
77
+ return out;
78
+ }
43
79
  /** Rows behind the scroll count as this many times farther than they are. */
44
80
  const BEHIND_FACTOR = 3;
45
81
  /**
@@ -132,4 +168,4 @@ function parkPlan(candidates, mounted, nodes, nodesOf, budget = PARK_BUDGET) {
132
168
  function idleWait(lastActivity, now) {
133
169
  return Math.max(0, lastActivity + PARK_IDLE_MS - now);
134
170
  }
135
- export { PARK_BUDGET, PARK_FAR_VIEWS, PARK_IDLE_MS, PARK_KEEP_BOTTOM_VIEWS, PARK_MAX_NODES, PARK_MAX_ROWS, PARK_SLICE_MS, PARK_TARGET, idleWait, keepsSize, overBudget, parkCandidates, parkPlan, pumpOrder };
171
+ export { PARK_BUDGET, PARK_FAR_VIEWS, PARK_IDLE_MS, PARK_KEEP_BOTTOM_VIEWS, PARK_MAX_NODES, PARK_MAX_ROWS, PARK_SLICE_MS, PARK_TARGET, idleWait, keepsSize, overBudget, parkCandidates, parkPlan, pumpOrder, rowsInRange };
@@ -1,5 +1,5 @@
1
1
  /** What a Codemode script's input panel reads besides its input. Internal to the transcript. */
2
- import { aj as ScriptProgress } from "../../dist/index-C6-t1SS9.js";
2
+ import { aj as ScriptProgress } from "../../dist/index-BheVJOLc.js";
3
3
  import { ToolRowModel } from "../headless/transcript/rows.js";
4
4
  import "../headless/transcript/index.js";
5
5
  /**
@@ -216,7 +216,6 @@ function useElapsedMs(startedAt) {
216
216
  const [now, setNow] = useState(() => Date.now());
217
217
  useEffect(() => {
218
218
  if (startedAt === void 0) return;
219
- setNow(Date.now());
220
219
  const timer = setInterval(() => setNow(Date.now()), 250);
221
220
  return () => clearInterval(timer);
222
221
  }, [startedAt]);
@@ -1,6 +1,6 @@
1
- import { ChatEvent } from "../headless/host.js";
2
1
  import { Cluster, Row } from "../headless/transcript/rows.js";
3
2
  import { SelectStops } from "../headless/transcript/select-stops.js";
3
+ import { ChatEvent } from "../headless/host.js";
4
4
  import "../headless/transcript/index.js";
5
5
  import { TranscriptRowsSlice } from "../headless/transcript/incremental.js";
6
6
  import { RunReceipt, TranscriptEvents } from "zidane/chat/pure";
@@ -0,0 +1,42 @@
1
+ /** The reader counts as idle after this long without scrolling. */
2
+ export declare const BACKFILL_QUIET_MS = 1000;
3
+ /** Rows of one session (`eventBytes`) past which pages load only on demand: prewarm's budget. */
4
+ export declare const BACKFILL_MAX_BYTES: number;
5
+ /** Runs one offered load at a time, once the reader has held still. */
6
+ export interface HistoryBackfill {
7
+ /** The load to run once the reader is idle (it runs once); `null`: nothing to load now. */
8
+ offer: (load: (() => void) | null) => void;
9
+ /** Waits a quiet period from now (a conversation opened). */
10
+ restart: () => void;
11
+ dispose: () => void;
12
+ }
13
+ /**
14
+ * Creates the scheduler of {@link useHistoryBackfill}.
15
+ *
16
+ * @param target - Where the reader's input is heard (the document).
17
+ * @param quietMs - How long the reader holds still before a load runs.
18
+ */
19
+ export declare function createHistoryBackfill(target: EventTarget, quietMs?: number): HistoryBackfill;
20
+ /** What {@link useHistoryBackfill} reads of the conversation shown. */
21
+ export interface HistoryBackfillInputs {
22
+ /** Its events are hydrated. */
23
+ ready: boolean;
24
+ /** Older pages exist (and can be loaded). */
25
+ hasMore: boolean;
26
+ /** A page is loading. */
27
+ loading: boolean;
28
+ /** How much is loaded: changes when a page lands (the window's first position, or its length). */
29
+ loaded: number;
30
+ /** Loads the next older page. */
31
+ load: () => void;
32
+ /** About how many bytes its rows hold (`eventBytes`). Absent: nothing loads in the background. */
33
+ bytes: (() => number) | undefined;
34
+ }
35
+ /**
36
+ * Loads the conversation's older pages in the background while the reader is idle (see the module comment).
37
+ *
38
+ * @param sessionId - The conversation shown.
39
+ * @param inputs - The {@link HistoryBackfillInputs}.
40
+ * @param maxBytes - The byte budget. Default {@link BACKFILL_MAX_BYTES}.
41
+ */
42
+ export declare function useHistoryBackfill(sessionId: string | null, inputs: HistoryBackfillInputs, maxBytes?: number): void;
@@ -0,0 +1,170 @@
1
+ import { useEffect, useRef } from "react";
2
+ // src/chat/transcript/useHistoryBackfill.ts
3
+ /**
4
+ * Background scrollback: once a conversation has opened and the reader holds
5
+ * still, its older pages load one at a time in idle time, until the history
6
+ * is complete or its rows reach a byte budget. The scrollbar then measures
7
+ * the whole conversation, and its top is there without a wait.
8
+ *
9
+ * Loading waits while the reader scrolls: a wheel, a touch, a press, a scroll
10
+ * key, and the scroll events that carry a gesture on (momentum, a scrollbar
11
+ * drag) restart a quiet period of {@link BACKFILL_QUIET_MS}. A scroll event
12
+ * alone never starts one: the view's own corrections (a page held in place, a
13
+ * live run followed at the bottom) are not the reader. A page lands as
14
+ * unmounted placeholders (`row-mount.ts`), and the view keeps its place
15
+ * (`useStickToBottom`, or the browser's scroll anchoring). Past the budget,
16
+ * scroll-to-load and Load earlier reach the rest.
17
+ */
18
+ /** The reader counts as idle after this long without scrolling. */
19
+ const BACKFILL_QUIET_MS = 1e3;
20
+ /** Rows of one session (`eventBytes`) past which pages load only on demand: prewarm's budget. */
21
+ const BACKFILL_MAX_BYTES = 25165824;
22
+ /** Keys that scroll the view. */
23
+ const SCROLL_KEYS = /* @__PURE__ */ new Set([
24
+ "ArrowUp",
25
+ "ArrowDown",
26
+ "PageUp",
27
+ "PageDown",
28
+ "Home",
29
+ "End",
30
+ " "
31
+ ]);
32
+ const INPUTS = [
33
+ "wheel",
34
+ "touchstart",
35
+ "touchmove",
36
+ "touchend",
37
+ "pointerdown"
38
+ ];
39
+ function requestIdle(run) {
40
+ if (typeof requestIdleCallback === "function") {
41
+ const id = requestIdleCallback(run);
42
+ return () => cancelIdleCallback(id);
43
+ }
44
+ const id = setTimeout(run, 0);
45
+ return () => clearTimeout(id);
46
+ }
47
+ /**
48
+ * Creates the scheduler of {@link useHistoryBackfill}.
49
+ *
50
+ * @param target - Where the reader's input is heard (the document).
51
+ * @param quietMs - How long the reader holds still before a load runs.
52
+ */
53
+ function createHistoryBackfill(target, quietMs = BACKFILL_QUIET_MS) {
54
+ let quiet = false;
55
+ let timer;
56
+ let cancelIdle;
57
+ let pending = null;
58
+ const kick = () => {
59
+ if (!quiet || !pending || cancelIdle) return;
60
+ cancelIdle = requestIdle(() => {
61
+ cancelIdle = void 0;
62
+ const load = pending;
63
+ pending = null;
64
+ load?.();
65
+ });
66
+ };
67
+ const restart = () => {
68
+ quiet = false;
69
+ cancelIdle?.();
70
+ cancelIdle = void 0;
71
+ clearTimeout(timer);
72
+ timer = setTimeout(() => {
73
+ timer = void 0;
74
+ quiet = true;
75
+ kick();
76
+ }, quietMs);
77
+ };
78
+ const onKey = (e) => {
79
+ if (SCROLL_KEYS.has(e.key)) restart();
80
+ };
81
+ const onScroll = (e) => {
82
+ const el = e.target;
83
+ if (quiet || !(el instanceof Element) || el.scrollHeight - el.scrollTop - el.clientHeight <= 2) return;
84
+ restart();
85
+ };
86
+ for (const type of INPUTS) target.addEventListener(type, restart, {
87
+ capture: true,
88
+ passive: true
89
+ });
90
+ target.addEventListener("keydown", onKey, { capture: true });
91
+ target.addEventListener("scroll", onScroll, {
92
+ capture: true,
93
+ passive: true
94
+ });
95
+ restart();
96
+ return {
97
+ offer(load) {
98
+ pending = load;
99
+ if (!load) {
100
+ cancelIdle?.();
101
+ cancelIdle = void 0;
102
+ }
103
+ kick();
104
+ },
105
+ restart,
106
+ dispose() {
107
+ for (const type of INPUTS) target.removeEventListener(type, restart, { capture: true });
108
+ target.removeEventListener("keydown", onKey, { capture: true });
109
+ target.removeEventListener("scroll", onScroll, { capture: true });
110
+ clearTimeout(timer);
111
+ cancelIdle?.();
112
+ cancelIdle = void 0;
113
+ pending = null;
114
+ }
115
+ };
116
+ }
117
+ /**
118
+ * Loads the conversation's older pages in the background while the reader is idle (see the module comment).
119
+ *
120
+ * @param sessionId - The conversation shown.
121
+ * @param inputs - The {@link HistoryBackfillInputs}.
122
+ * @param maxBytes - The byte budget. Default {@link BACKFILL_MAX_BYTES}.
123
+ */
124
+ function useHistoryBackfill(sessionId, inputs, maxBytes = BACKFILL_MAX_BYTES) {
125
+ const { ready, hasMore, loading, loaded, load, bytes } = inputs;
126
+ const backfill = useRef(null);
127
+ const latest = useRef({
128
+ load,
129
+ bytes
130
+ });
131
+ useEffect(() => {
132
+ latest.current = {
133
+ load,
134
+ bytes
135
+ };
136
+ });
137
+ useEffect(() => {
138
+ const created = createHistoryBackfill(document);
139
+ backfill.current = created;
140
+ return () => {
141
+ created.dispose();
142
+ backfill.current = null;
143
+ };
144
+ }, []);
145
+ useEffect(() => {
146
+ if (sessionId && ready) backfill.current?.restart();
147
+ }, [sessionId, ready]);
148
+ const measured = bytes !== void 0;
149
+ useEffect(() => {
150
+ const b = backfill.current;
151
+ if (!b) return;
152
+ if (!sessionId || !ready || !hasMore || loading || !measured) {
153
+ b.offer(null);
154
+ return;
155
+ }
156
+ b.offer(() => {
157
+ const { load, bytes } = latest.current;
158
+ if (bytes && bytes() < maxBytes) load();
159
+ });
160
+ }, [
161
+ sessionId,
162
+ ready,
163
+ hasMore,
164
+ loading,
165
+ loaded,
166
+ measured,
167
+ maxBytes
168
+ ]);
169
+ }
170
+ export { BACKFILL_MAX_BYTES, BACKFILL_QUIET_MS, createHistoryBackfill, useHistoryBackfill };
@@ -1,5 +1,5 @@
1
1
  import { useTranscriptFindKey } from "./useTranscriptFindKey.js";
2
- import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { useCallback, useMemo, useState } from "react";
3
3
  // src/chat/transcript/useTranscriptFind.ts
4
4
  /**
5
5
  * The find in the conversation's state: which session it is open on and the
@@ -25,9 +25,7 @@ function useTranscriptFind({ sessionId, blocked }) {
25
25
  onFind,
26
26
  ...blocked ? { blocked } : {}
27
27
  });
28
- useEffect(() => {
29
- if (target && target.sessionId !== sessionId) setTarget(null);
30
- }, [sessionId, target]);
28
+ if (target && target.sessionId !== sessionId) setTarget(null);
31
29
  const close = useCallback(() => setTarget(null), []);
32
30
  const findIn = useCallback((next) => setTarget(next), []);
33
31
  const open = target !== null && target.sessionId === sessionId;
@@ -2,9 +2,10 @@
2
2
  * The conversation's transcript scroll: stick-to-bottom (paused while
3
3
  * select-turn mode drives the cursor), where a conversation opens (back where
4
4
  * it was left, or at the bottom), the scrolled-from-top signal for the
5
- * footer's fade, and lazy scrollback. The container hands it the session's
6
- * page state and loader, whether select-turn drives the view, and the
7
- * Keep scroll position setting.
5
+ * footer's fade, lazy scrollback, and the rest of the history loading in the
6
+ * background while the reader is idle (`useHistoryBackfill`). The container
7
+ * hands it the session's page state, loader and row size, whether
8
+ * select-turn drives the view, and the Keep scroll position setting.
8
9
  */
9
10
  import { SessionPageState } from "../headless/streams/types.js";
10
11
  /** What {@link useTranscriptScroll} reads from its container. */
@@ -19,6 +20,8 @@ export interface TranscriptScrollInputs<K extends string = string> {
19
20
  selecting: boolean;
20
21
  /** Reopen a conversation where it was left (Keep scroll position). */
21
22
  keepPosition: boolean;
23
+ /** About how many bytes the session's rows hold (the stream store's `eventBytes`): what background loading budgets by. Absent: older pages load only on demand. */
24
+ eventBytes?: (sessionId: K) => number;
22
25
  }
23
26
  /**
24
27
  * The transcript's scroll: stick-to-bottom, where a conversation opens, the from-top signal and lazy scrollback (see the module comment).
@@ -27,7 +30,7 @@ export interface TranscriptScrollInputs<K extends string = string> {
27
30
  * @param hydrated - Its events have loaded.
28
31
  * @param inputs - The {@link TranscriptScrollInputs}.
29
32
  */
30
- export declare function useTranscriptScroll<K extends string>(sessionId: K | null, hydrated: boolean, { page, loadEarlier, selecting, keepPosition }: TranscriptScrollInputs<K>): {
33
+ export declare function useTranscriptScroll<K extends string>(sessionId: K | null, hydrated: boolean, { page, loadEarlier, selecting, keepPosition, eventBytes }: TranscriptScrollInputs<K>): {
31
34
  scrollRef: import("react").RefObject<HTMLElement | null>;
32
35
  pinned: boolean;
33
36
  scrolledFromTop: boolean;