@kabmo-labs/kabmo 0.28.0 → 0.30.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 (232) hide show
  1. package/bunfig.toml +6 -0
  2. package/dist/client/index.html +2 -2
  3. package/dist/client/index.js +481 -472
  4. package/dist/client/static/js/{index-xzvyrxya.js → index-5vjbp04s.js} +1193 -1049
  5. package/dist/client/static/js/index-naa91727.css +1 -0
  6. package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
  7. package/package.json +3 -2
  8. package/public/manifest.webmanifest +1 -0
  9. package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
  10. package/src/client/components/common/ComposerTextarea.tsx +6 -0
  11. package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
  12. package/src/client/components/common/ReloadPageButton.tsx +11 -2
  13. package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
  14. package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
  15. package/src/client/components/common/file-icon/index.tsx +7 -1
  16. package/src/client/components/common/harness-glyph/brands.ts +7 -1
  17. package/src/client/components/common/image-viewer/index.tsx +37 -165
  18. package/src/client/components/common/picker-search/index.tsx +70 -0
  19. package/src/client/components/common/search-select/index.tsx +2 -7
  20. package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
  21. package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
  22. package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
  23. package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
  26. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
  28. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
  29. package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
  30. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
  31. package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
  32. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
  33. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
  34. package/src/client/components/settings/Sidebar.tsx +6 -8
  35. package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
  36. package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
  37. package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
  38. package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
  39. package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
  40. package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
  41. package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
  42. package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
  43. package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
  44. package/src/client/components/settings/groups.test.tsx +2 -2
  45. package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
  46. package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
  47. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
  48. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
  49. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
  50. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
  51. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
  52. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
  53. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
  54. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
  55. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
  56. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
  57. package/src/client/components/workspace/editor/FilePane.tsx +32 -0
  58. package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
  59. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
  60. package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
  61. package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
  62. package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
  63. package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
  64. package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
  65. package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
  66. package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
  67. package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
  68. package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
  69. package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
  70. package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
  71. package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
  72. package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
  73. package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
  74. package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
  75. package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
  76. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
  77. package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
  78. package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
  79. package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
  80. package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
  81. package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
  82. package/src/client/components/workspace/file-explorer/index.tsx +53 -29
  83. package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
  84. package/src/client/data/settings/omp-schema.json +169 -22
  85. package/src/client/glass-palette.test.ts +72 -0
  86. package/src/client/glass.css +39 -14
  87. package/src/client/glass.test.ts +28 -67
  88. package/src/client/hooks/chat/composer/history.test.ts +267 -0
  89. package/src/client/hooks/chat/composer/history.ts +146 -0
  90. package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
  91. package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
  92. package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
  93. package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
  94. package/src/client/hooks/editor/file-editor-types.ts +15 -0
  95. package/src/client/hooks/editor/save-bytes.ts +79 -0
  96. package/src/client/hooks/editor/use-dirty-tracking.test.ts +73 -0
  97. package/src/client/hooks/editor/use-dirty-tracking.ts +96 -0
  98. package/src/client/hooks/editor/use-file-cache.ts +1 -0
  99. package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
  100. package/src/client/hooks/editor/use-file-editor.ts +20 -17
  101. package/src/client/hooks/editor/use-file-read.ts +21 -2
  102. package/src/client/hooks/editor/use-grid-selection.ts +160 -0
  103. package/src/client/hooks/models/use-harness-update.test.ts +35 -2
  104. package/src/client/hooks/models/use-harness-update.ts +49 -10
  105. package/src/client/hooks/workspace/diff-file.test.ts +72 -0
  106. package/src/client/hooks/workspace/diff-file.ts +12 -6
  107. package/src/client/hooks/workspace/file-archive.ts +220 -0
  108. package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
  109. package/src/client/hooks/workspace/file-clipboard.ts +37 -26
  110. package/src/client/hooks/workspace/file-selection.test.ts +67 -0
  111. package/src/client/hooks/workspace/file-selection.ts +156 -0
  112. package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
  113. package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
  114. package/src/client/lib/editor/workbook-drafts.ts +42 -0
  115. package/src/client/lib/launch/file-handlers.ts +2 -2
  116. package/src/client/lib/scrollbar-activity.test.ts +21 -88
  117. package/src/client/lib/scrollbar-activity.ts +71 -73
  118. package/src/client/lib/scrollbar-events.ts +143 -0
  119. package/src/client/lib/scrollbar-input.test.ts +126 -0
  120. package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
  121. package/src/client/tailwind.css +32 -1
  122. package/src/server/db.server.test.ts +50 -1
  123. package/src/server/db.server.ts +36 -3
  124. package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
  125. package/src/server/lib/chat/prompt-history.server.ts +65 -0
  126. package/src/server/lib/chat/schema.server.ts +35 -0
  127. package/src/server/lib/db/schema.ts +3 -0
  128. package/src/server/lib/fs/archive.test.ts +198 -0
  129. package/src/server/lib/fs/archive.ts +278 -0
  130. package/src/server/lib/fs/git-diff.test.ts +26 -1
  131. package/src/server/lib/fs/git-diff.ts +43 -15
  132. package/src/server/lib/harness/launch-table.ts +19 -0
  133. package/src/server/lib/harness/provider-entry.ts +1 -1
  134. package/src/server/lib/harness/provider-file.server.ts +1 -1
  135. package/src/server/lib/harness/provider-sources.server.ts +2 -1
  136. package/src/server/lib/harness/provider-write.server.ts +2 -1
  137. package/src/server/lib/harness/update-job-store.ts +12 -0
  138. package/src/server/lib/harness/update-queue.server.ts +15 -10
  139. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
  140. package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
  141. package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
  142. package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
  143. package/src/server/lib/omp/session/delete.server.ts +1 -0
  144. package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
  145. package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
  146. package/src/server/lib/panels/auto-update.server.test.ts +5 -2
  147. package/src/server/lib/panels/git-update.server.test.ts +5 -2
  148. package/src/server/lib/panels/install.server.test.ts +5 -2
  149. package/src/server/lib/panels/remove.server.test.ts +5 -2
  150. package/src/server/routes/agent/command.ts +11 -0
  151. package/src/server/routes/agent/new.ts +5 -0
  152. package/src/server/routes/chat/index.ts +5 -0
  153. package/src/server/routes/chat/prompt-history.test.ts +67 -0
  154. package/src/server/routes/chat/prompt-history.ts +31 -0
  155. package/src/server/routes/chat/stream.test.ts +21 -0
  156. package/src/server/routes/chat/stream.ts +5 -0
  157. package/src/server/routes/fs/action-archive.test.ts +128 -0
  158. package/src/server/routes/fs/action-bulk.ts +106 -0
  159. package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
  160. package/src/server/routes/fs/action-transfer.test.ts +26 -0
  161. package/src/server/routes/fs/action.ts +91 -11
  162. package/src/server/routes/fs/archive.ts +20 -0
  163. package/src/server/routes/fs/grant.test.ts +5 -2
  164. package/src/server/routes/fs/index.ts +2 -0
  165. package/src/server/routes/fs/scope.test.ts +6 -2
  166. package/src/server/routes/harness/import-action.ts +1 -1
  167. package/src/server/routes/harness/root.ts +6 -1
  168. package/src/server/routes/harness/summary.test.ts +50 -0
  169. package/src/server/routes/harness/update-status.ts +41 -2
  170. package/src/server/routes/harness/update.test.ts +56 -2
  171. package/src/server/routes/sessions/delete.test.ts +4 -0
  172. package/src/shared/lib/chat/ask-form/index.ts +39 -31
  173. package/src/shared/lib/chat/ask-form/labels.ts +46 -0
  174. package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
  175. package/src/shared/lib/chat/ask-form.test.ts +57 -0
  176. package/src/shared/lib/chat/ask-questions.ts +31 -0
  177. package/src/shared/lib/chat/composer/history.test.ts +67 -0
  178. package/src/shared/lib/chat/composer/history.ts +61 -0
  179. package/src/shared/lib/chat/irc-notice.ts +42 -0
  180. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
  181. package/src/shared/lib/chat/todo/parser.ts +6 -4
  182. package/src/shared/lib/fs/archive.test.ts +101 -0
  183. package/src/shared/lib/fs/archive.ts +191 -0
  184. package/src/shared/lib/fs/clipboard.test.ts +32 -7
  185. package/src/shared/lib/fs/clipboard.ts +59 -14
  186. package/src/shared/lib/fs/csv.test.ts +50 -0
  187. package/src/shared/lib/fs/csv.ts +40 -0
  188. package/src/shared/lib/fs/document-kind.test.ts +13 -6
  189. package/src/shared/lib/fs/document-kind.ts +18 -6
  190. package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
  191. package/src/shared/lib/fs/file-kind.test.ts +2 -7
  192. package/src/shared/lib/fs/file-kind.ts +4 -2
  193. package/src/shared/lib/fs/grid-edit.test.ts +24 -0
  194. package/src/shared/lib/fs/grid-edit.ts +29 -0
  195. package/src/shared/lib/fs/grid-selection.test.ts +137 -0
  196. package/src/shared/lib/fs/grid-selection.ts +138 -0
  197. package/src/shared/lib/harness/brand-color.ts +5 -0
  198. package/src/shared/lib/harness/catalog.test.ts +22 -0
  199. package/src/shared/lib/harness/catalog.ts +12 -1
  200. package/src/shared/lib/harness/config-fields.test.ts +25 -0
  201. package/src/shared/lib/harness/config-fields.ts +33 -3
  202. package/src/shared/lib/harness/dialects.ts +1 -1
  203. package/src/shared/lib/harness/mcp-facts.ts +4 -0
  204. package/src/shared/lib/harness/provider-contracts.ts +109 -0
  205. package/src/shared/lib/harness/provider-facts.test.ts +2 -1
  206. package/src/shared/lib/harness/provider-facts.ts +24 -115
  207. package/src/shared/lib/harness/provider-lookup.ts +37 -0
  208. package/src/shared/lib/harness/providers.ts +2 -1
  209. package/src/shared/lib/harness/updates.ts +10 -0
  210. package/src/shared/lib/icons/tint-hues.generated.ts +14 -13
  211. package/src/shared/lib/omp/session/mapper.test.ts +31 -0
  212. package/src/shared/lib/omp/session/mapper.ts +17 -0
  213. package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
  214. package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
  215. package/src/shared/lib/omp/session/messages-map.ts +17 -0
  216. package/src/shared/lib/omp/session/wait.ts +10 -1
  217. package/src/shared/lib/settings/sections.ts +8 -4
  218. package/src/shared/lib/ui/picker-filter.test.ts +23 -0
  219. package/src/shared/lib/ui/picker-filter.ts +20 -0
  220. package/src/shared/types/chat.ts +4 -0
  221. package/src/shared/types/harness.ts +5 -1
  222. package/src/shared/types/omp/session.ts +18 -0
  223. package/src/shared/types/settings/state.ts +6 -6
  224. package/src/shared/types/todo.ts +3 -1
  225. package/src/test-support/file-actions.test-util.ts +4 -0
  226. package/src/test-support/file-archive.test-util.ts +41 -0
  227. package/src/test-support/file-clipboard.test-util.ts +9 -6
  228. package/src/test-support/file-editor.test-util.ts +3 -2
  229. package/src/test-support/glass-css.ts +30 -0
  230. package/src/test-support/harness-table.test-util.ts +2 -0
  231. package/src/test-support/preload.ts +46 -0
  232. package/dist/client/static/js/index-81f7berm.css +0 -1
@@ -16,6 +16,17 @@
16
16
  * timeline and the sidebar faded. Nothing about that is a per-component
17
17
  * decision, so nothing about it should be wired per component.
18
18
  *
19
+ * ## Painted on the INPUT, not on the scroll it causes
20
+ *
21
+ * The bar is painted by the `wheel`/`touch*` handler itself, on the nearest
22
+ * ancestor under the pointer that can overflow. Waiting for the `scroll` event
23
+ * means painting a frame late at best and not at all at worst — a browser
24
+ * dispatches `scroll` at its own frame boundary, and the gate below declines
25
+ * the scrolls it cannot attribute to a user. The `scroll` path is still wired,
26
+ * and it is the one that covers a scrollbar-thumb drag and the document's own
27
+ * scroll; the input path is what makes "the bar appears the moment you scroll"
28
+ * true without depending on either.
29
+ *
19
30
  * ## Why one document listener is enough
20
31
  *
21
32
  * `scroll` does not bubble, so a bubble-phase listener on `document` would only
@@ -80,6 +91,14 @@
80
91
  * on `documentElement`.
81
92
  */
82
93
 
94
+ import {
95
+ belongsTo,
96
+ eventMoment,
97
+ isScrollKey,
98
+ nearestScroller,
99
+ scrolledElement,
100
+ } from '@/client/lib/scrollbar-events';
101
+
83
102
  /** The attribute `tailwind.css` selects on. One name, two files. */
84
103
  export const SCROLLBAR_ACTIVE_ATTRIBUTE = 'data-scrollbar-active';
85
104
 
@@ -115,68 +134,6 @@ interface ScrollbarActivityHost {
115
134
  * and Bun/Node typings disagree on what `setTimeout` returns. */
116
135
  type FadeTimer = ReturnType<typeof setTimeout>;
117
136
 
118
- /** The element whose scrollbar the event describes. */
119
- function scrolledElement(target: EventTarget | null): Element | null {
120
- if (target === document || target === window || target === null) {
121
- // The viewport's own scroll: the bar that is painted belongs to the root
122
- // element, not to the document the event names.
123
- return document.documentElement;
124
- }
125
- return target instanceof Element ? target : null;
126
- }
127
-
128
- /**
129
- * WHEN an event happened, on the one clock the arm is compared on.
130
- *
131
- * `Date.now()` read inside a handler is when the handler RAN, and the two are
132
- * not the same moment: scroll events are coalesced and delivered at the next
133
- * frame, so a main thread busy with a long task (a streamed markdown render, a
134
- * 36 000px transcript re-layout) can delay delivery by hundreds of milliseconds.
135
- * `Event.timeStamp` is stamped when the event is CREATED, which is what makes
136
- * the arm's expiry mean "this input is old" rather than "this handler is late".
137
- *
138
- * Engines disagree about the scroll stamp — Chrome stamps at creation, WebKit
139
- * at dispatch — so this clock cannot decide whether a scroll was the user's.
140
- * That is why the gate is an ARM (did any input happen since the last reveal?)
141
- * and not a gap: the arm only has to bound how stale an input may be, and both
142
- * engines answer that.
143
- *
144
- * The fallback covers synthetic events and engines that report a non-positive
145
- * stamp (`0` is what a hand-built `new Event('scroll')` carries). It answers
146
- * `performance.now()` and not `Date.now()`: `Event.timeStamp` is a
147
- * `DOMHighResTimeStamp`, so mixing in wall time would make the subtraction a
148
- * difference of two different clocks — measured as a negative gap, which would
149
- * make every programmatic scroll look armed.
150
- */
151
- function eventMoment(event: Event): number {
152
- const stamp = event.timeStamp;
153
- return Number.isFinite(stamp) && stamp > 0 ? stamp : performance.now();
154
- }
155
-
156
- /**
157
- * Whether an input happened INSIDE the container that scrolled.
158
- *
159
- * An arm is spent by the first scroll that follows it, which is what stops a
160
- * stream from pinning a bar — but "first scroll anywhere" was too loose: a
161
- * wheel that cannot move its container (already at the top) produces no scroll
162
- * event, so its arm stayed unspent for the rest of its life and the next
163
- * PROGRAMMATIC scroll in any other panel could spend it. Measured: wheel up at
164
- * `scrollTop = 0`, then `scrollTop = 500` 250ms later, and the bar lit for a
165
- * scroll nobody made.
166
- *
167
- * Binding the arm to the subtree the input happened in closes that without
168
- * adding a layout read: `contains` is a tree walk, not a `getComputedStyle`,
169
- * and the wheel's target is already the element under the pointer.
170
- *
171
- * An input that names the document or the window itself (a keydown with nothing
172
- * focused) is deliberately NOT bound — the scroller it drives is the focused
173
- * one, which no target reveals, so it keeps the unbound behaviour.
174
- */
175
- function belongsTo(element: Element, inputTarget: EventTarget | null): boolean {
176
- if (inputTarget === null || inputTarget === document || inputTarget === window) return true;
177
- if (inputTarget === element) return true;
178
- return inputTarget instanceof Node ? element.contains(inputTarget) : false;
179
- }
180
137
 
181
138
  /**
182
139
  * Wire the reveal rule for one document. Idempotent per document.
@@ -225,6 +182,45 @@ export function installScrollbarActivity(
225
182
  armedAt = eventMoment(event);
226
183
  armedIn = event.target;
227
184
  };
185
+
186
+ /** Paint `element`'s bar and start its idle window over. */
187
+ const reveal = (element: Element) => {
188
+ element.setAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE, '');
189
+ clearTimeout(timers.get(element));
190
+ timers.set(
191
+ element,
192
+ setTimeout(() => {
193
+ timers.delete(element);
194
+ element.removeAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE);
195
+ }, idleMs),
196
+ );
197
+ };
198
+
199
+ /**
200
+ * Reveal the surface the user's input is aimed at, AT INPUT TIME.
201
+ *
202
+ * Waiting for the `scroll` event means the bar is painted on the frame after
203
+ * the input — and a scroll the gate declines (a programmatic follow, an
204
+ * engine that dispatches the scroll after the frame budget) paints nothing at
205
+ * all. Painting here makes "the bar appears the moment you scroll" true by
206
+ * construction, and it costs no layout: the walk stops at the first ancestor
207
+ * that can actually overflow.
208
+ *
209
+ * Only input paints, so a stream's auto-follow still cannot light a bar. Each
210
+ * wheel event of a gesture restarts the idle window, which is what makes the
211
+ * bar stay up for as long as the user keeps scrolling instead of for 5s after
212
+ * the first tick of the gesture.
213
+ */
214
+ const revealUnderPointer = (event: Event) => {
215
+ const element = nearestScroller(event.target);
216
+ if (element) reveal(element);
217
+ };
218
+
219
+ const noteScrollingInput = (event: Event) => {
220
+ noteInput(event);
221
+ revealUnderPointer(event);
222
+ };
223
+
228
224
  const pressPointer = (event: Event) => {
229
225
  heldPointer = true;
230
226
  noteInput(event);
@@ -238,9 +234,19 @@ export function installScrollbarActivity(
238
234
  // Every one of these is passive: none of them ever calls `preventDefault`,
239
235
  // and a non-passive wheel listener is a documented cause of scroll jank.
240
236
  const INPUT_OPTIONS = { capture: true, passive: true } as const;
241
- for (const type of ['wheel', 'touchstart', 'touchmove', 'keydown'] as const) {
242
- document.addEventListener(type, noteInput, INPUT_OPTIONS);
237
+ for (const type of ['wheel', 'touchstart', 'touchmove'] as const) {
238
+ document.addEventListener(type, noteScrollingInput, INPUT_OPTIONS);
243
239
  }
240
+ // Only the keys that scroll arm the gate. A keydown that types a character
241
+ // says nothing about scrolling, and arming on it let a stream's next
242
+ // auto-follow paint a bar while the reader was typing in the composer.
243
+ document.addEventListener(
244
+ 'keydown',
245
+ (event) => {
246
+ if (isScrollKey(event as KeyboardEvent)) noteInput(event);
247
+ },
248
+ INPUT_OPTIONS,
249
+ );
244
250
  // `mousedown`/`mouseup` ride along with the pointer pair so an engine that
245
251
  // synthesizes no pointer events for a native scrollbar still counts the drag.
246
252
  document.addEventListener('pointerdown', pressPointer, INPUT_OPTIONS);
@@ -282,15 +288,7 @@ export function installScrollbarActivity(
282
288
  armedAt = null;
283
289
  armedIn = null;
284
290
  }
285
- element.setAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE, '');
286
- clearTimeout(timers.get(element));
287
- timers.set(
288
- element,
289
- setTimeout(() => {
290
- timers.delete(element);
291
- element.removeAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE);
292
- }, idleMs),
293
- );
291
+ reveal(element);
294
292
  },
295
293
  // Passive for the same reason the input listeners are.
296
294
  { capture: true, passive: true },
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The DOM questions the scrollbar reveal rule asks, split from the rule itself
8
+ * so each file stays readable: WHICH element a scroll is about, WHICH element
9
+ * an input is aimed at, WHEN an event happened, and whether a key scrolls.
10
+ *
11
+ * Nothing here keeps state. `scrollbar-activity.ts` owns the listener, the arm
12
+ * and the fade timer; these are the pure answers it consults, kept separate so
13
+ * they can be reasoned about (and changed) without reading the gate.
14
+ */
15
+
16
+ /** The element whose scrollbar the event describes. */
17
+ export function scrolledElement(target: EventTarget | null): Element | null {
18
+ if (target === document || target === window || target === null) {
19
+ // The viewport's own scroll: the bar that is painted belongs to the root
20
+ // element, not to the document the event names.
21
+ return document.documentElement;
22
+ }
23
+ return target instanceof Element ? target : null;
24
+ }
25
+
26
+ /**
27
+ * WHEN an event happened, on the one clock the arm is compared on.
28
+ *
29
+ * `Date.now()` read inside a handler is when the handler RAN, and the two are
30
+ * not the same moment: scroll events are coalesced and delivered at the next
31
+ * frame, so a main thread busy with a long task (a streamed markdown render, a
32
+ * 36 000px transcript re-layout) can delay delivery by hundreds of milliseconds.
33
+ * `Event.timeStamp` is stamped when the event is CREATED, which is what makes
34
+ * the arm's expiry mean "this input is old" rather than "this handler is late".
35
+ *
36
+ * Engines disagree about the scroll stamp — Chrome stamps at creation, WebKit
37
+ * at dispatch — so this clock cannot decide whether a scroll was the user's.
38
+ * That is why the gate is an ARM (did any input happen since the last reveal?)
39
+ * and not a gap: the arm only has to bound how stale an input may be, and both
40
+ * engines answer that.
41
+ *
42
+ * The fallback covers synthetic events and engines that report a non-positive
43
+ * stamp (`0` is what a hand-built `new Event('scroll')` carries). It answers
44
+ * `performance.now()` and not `Date.now()`: `Event.timeStamp` is a
45
+ * `DOMHighResTimeStamp`, so mixing in wall time would make the subtraction a
46
+ * difference of two different clocks — measured as a negative gap, which would
47
+ * make every programmatic scroll look armed.
48
+ */
49
+ export function eventMoment(event: Event): number {
50
+ const stamp = event.timeStamp;
51
+ return Number.isFinite(stamp) && stamp > 0 ? stamp : performance.now();
52
+ }
53
+
54
+ /** The `overflow` values that make an element a surface the USER can scroll. */
55
+ const SCROLLABLE_OVERFLOW: Readonly<Record<string, true>> = { auto: true, scroll: true, overlay: true };
56
+
57
+ /**
58
+ * The nearest ancestor of `target` that the user's input would scroll.
59
+ *
60
+ * This answers, at INPUT time, the question the `scroll` event answers a frame
61
+ * later — which is what lets the bar be painted the moment the wheel turns
62
+ * instead of after the scroll lands. `target` itself is checked first, since a
63
+ * wheel over a scroller's own padding targets the scroller.
64
+ *
65
+ * No fallback to the document: an input over an element that names no scroller
66
+ * leaves the page's own reveal to the `scroll` path (where the root element is
67
+ * known to be the painted surface). Returning the root here would light the
68
+ * page's bar for a wheel that moved a panel.
69
+ */
70
+ export function nearestScroller(target: EventTarget | null): Element | null {
71
+ let node: Element | null = target instanceof Element ? target : null;
72
+ for (; node && node !== document.body; node = node.parentElement) {
73
+ // The size test runs first: a node that cannot overflow is not a scroll
74
+ // surface whatever its `overflow` says, and reading it costs no style pass.
75
+ if (node.scrollHeight <= node.clientHeight + 1 && node.scrollWidth <= node.clientWidth + 1) continue;
76
+ // Through the node's own window rather than the global: the same tree is
77
+ // mounted in a document this module did not capture, and `getComputedStyle`
78
+ // is not a global in every host that runs it (the unit tests included).
79
+ const view = node.ownerDocument?.defaultView;
80
+ if (!view) continue;
81
+ const style = view.getComputedStyle(node);
82
+ if (SCROLLABLE_OVERFLOW[style.overflowY] || SCROLLABLE_OVERFLOW[style.overflowX]) return node;
83
+ }
84
+ return null;
85
+ }
86
+
87
+ /** The keys that scroll the focused surface (never a typing key). */
88
+ const SCROLL_KEYS: Readonly<Record<string, true>> = {
89
+ ArrowUp: true,
90
+ ArrowDown: true,
91
+ ArrowLeft: true,
92
+ ArrowRight: true,
93
+ PageUp: true,
94
+ PageDown: true,
95
+ Home: true,
96
+ End: true,
97
+ ' ': true,
98
+ Spacebar: true,
99
+ };
100
+
101
+ /**
102
+ * Whether an input happened INSIDE the container that scrolled.
103
+ *
104
+ * An arm is spent by the first scroll that follows it, which is what stops a
105
+ * stream from pinning a bar — but "first scroll anywhere" was too loose: a
106
+ * wheel that cannot move its container (already at the top) produces no scroll
107
+ * event, so its arm stayed unspent for the rest of its life and the next
108
+ * PROGRAMMATIC scroll in any other panel could spend it. Measured: wheel up at
109
+ * `scrollTop = 0`, then `scrollTop = 500` 250ms later, and the bar lit for a
110
+ * scroll nobody made.
111
+ *
112
+ * Binding the arm to the subtree the input happened in closes that without
113
+ * adding a layout read: `contains` is a tree walk, not a `getComputedStyle`,
114
+ * and the wheel's target is already the element under the pointer.
115
+ *
116
+ * An input that names the document or the window itself (a keydown with nothing
117
+ * focused) is deliberately NOT bound — the scroller it drives is the focused
118
+ * one, which no target reveals, so it keeps the unbound behaviour. `body` and
119
+ * the root element are the same case in practice: a keydown with nothing
120
+ * focused targets `body`, and MEASURED in Chromium and WebKit 27.2, PageDown
121
+ * there scrolls the panel the reader last clicked — a container `body` neither
122
+ * contains nor is contained by. Treating `body` as bound is what made keyboard
123
+ * scrolling reveal no bar at all.
124
+ */
125
+ export function belongsTo(element: Element, inputTarget: EventTarget | null): boolean {
126
+ if (
127
+ inputTarget === null
128
+ || inputTarget === document
129
+ || inputTarget === window
130
+ || inputTarget === document.body
131
+ || inputTarget === document.documentElement
132
+ ) {
133
+ return true;
134
+ }
135
+ if (inputTarget === element) return true;
136
+ return inputTarget instanceof Node ? element.contains(inputTarget) : false;
137
+ }
138
+
139
+ /** Whether a key press is a scroll of the focused surface (never a typing key). */
140
+ export function isScrollKey(event: KeyboardEvent): boolean {
141
+ if (event.metaKey || event.ctrlKey || event.altKey) return false;
142
+ return SCROLL_KEYS[event.key] === true;
143
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { afterAll, afterEach, beforeAll, describe, expect, jest, test } from 'bun:test';
7
+
8
+ import { SCROLLBAR_ACTIVE_ATTRIBUTE } from '@/client/lib/scrollbar-activity';
9
+ import {
10
+ IDLE_MS,
11
+ freshPage,
12
+ inputAt,
13
+ keyAt,
14
+ restoreNativeGlobals,
15
+ saveNativeGlobals,
16
+ scrollAt,
17
+ scrollSurface,
18
+ scroller,
19
+ } from '@/client/lib/scrollbar-probe.test-util';
20
+
21
+ beforeAll(saveNativeGlobals);
22
+ afterAll(restoreNativeGlobals);
23
+ afterEach(() => {
24
+ jest.useRealTimers();
25
+ });
26
+
27
+ /**
28
+ * The bar appears the moment the reader scrolls.
29
+ *
30
+ * Every case here asserts paint WITHOUT a `scroll` event: the reveal is driven
31
+ * by the input itself, so these fail if the rule goes back to waiting for the
32
+ * frame the browser dispatches `scroll` on (the reported "the scrollbar does
33
+ * not show up immediately when I scroll"). Measured before this rule: the
34
+ * attribute landed 13-27ms after a wheel, on the scroll frame, and a scroll
35
+ * the gate declined painted nothing at all.
36
+ */
37
+
38
+ describe('the scrollbar reveal on input', () => {
39
+ test('a wheel paints the surface it is over, before any scroll event', () => {
40
+ jest.useFakeTimers();
41
+ freshPage();
42
+ const box = scrollSurface();
43
+
44
+ // No `scrollAt()`: this is the whole point. The bar is painted by the
45
+ // input, not by a scroll event the browser dispatches a frame later (or
46
+ // never, when the gate declines it). Measured before this rule: the
47
+ // attribute landed 13-27ms after the wheel, i.e. on the scroll frame, and
48
+ // a scroll the gate refused painted nothing at all.
49
+ inputAt(box);
50
+
51
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
52
+ });
53
+
54
+ test('a wheel over a child paints the scroller that holds it', () => {
55
+ jest.useFakeTimers();
56
+ freshPage();
57
+ const box = scrollSurface();
58
+ const row = document.createElement('p');
59
+ box.appendChild(row);
60
+
61
+ inputAt(row);
62
+
63
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
64
+ expect(row.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
65
+ });
66
+
67
+ test('a wheel over something that cannot scroll paints nothing', () => {
68
+ jest.useFakeTimers();
69
+ freshPage();
70
+ const plain = scroller();
71
+
72
+ inputAt(plain);
73
+
74
+ // The page's own reveal belongs to its `scroll` event, where the painted
75
+ // surface is the root element. Lighting it here would paint the page's bar
76
+ // for a wheel that moved nothing at all.
77
+ expect(plain.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
78
+ expect(document.documentElement.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
79
+ });
80
+
81
+ test('every wheel of a gesture restarts the idle window', () => {
82
+ jest.useFakeTimers();
83
+ freshPage();
84
+ const box = scrollSurface();
85
+
86
+ inputAt(box);
87
+ jest.advanceTimersByTime(IDLE_MS - 100);
88
+ inputAt(box);
89
+ jest.advanceTimersByTime(IDLE_MS - 100);
90
+
91
+ // The user is STILL scrolling: a bar that faded here would disappear from
92
+ // under a hand that never stopped.
93
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
94
+
95
+ jest.advanceTimersByTime(100);
96
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
97
+ });
98
+
99
+ test('a keyboard scroll reveals the surface the engine scrolled', () => {
100
+ jest.useFakeTimers();
101
+ freshPage();
102
+ const box = scroller();
103
+
104
+ // MEASURED in Chromium and WebKit 27.2: PageDown with nothing focused walks
105
+ // the focused scroll chain, so the keydown's target is `body` while the
106
+ // panel that moves is a sibling subtree. Binding the arm to `body` refused
107
+ // every keyboard scroll, so the bar never appeared for them.
108
+ keyAt('PageDown');
109
+ scrollAt(box);
110
+
111
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(true);
112
+ });
113
+
114
+ test('a key that cannot scroll does not arm a reveal', () => {
115
+ jest.useFakeTimers();
116
+ freshPage();
117
+ const box = scroller();
118
+
119
+ // Typing in the composer must not let a stream's next auto-follow paint a
120
+ // bar: the key says nothing about scrolling.
121
+ keyAt('a');
122
+ scrollAt(box);
123
+
124
+ expect(box.hasAttribute(SCROLLBAR_ACTIVE_ATTRIBUTE)).toBe(false);
125
+ });
126
+ });
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The scaffolding both scrollbar suites mount against.
8
+ *
9
+ * Every case gets its OWN document and its own install, because the module is
10
+ * idempotent per document and its input clock is per install: a shared document
11
+ * would make every case inherit the previous one's wheel (and would make a
12
+ * `useFakeTimers` clock that restarts at real time read as recent input).
13
+ *
14
+ * Mounted against happy-dom, the same way the other client tests are.
15
+ */
16
+
17
+ import { Window } from 'happy-dom';
18
+ import { SCROLLBAR_INPUT_ARM_MS, installScrollbarActivity } from '@/client/lib/scrollbar-activity';
19
+
20
+ const DOM_GLOBALS = [
21
+ 'window',
22
+ 'document',
23
+ 'navigator',
24
+ 'Node',
25
+ 'Element',
26
+ 'HTMLElement',
27
+ 'Event',
28
+ 'CustomEvent',
29
+ ] as const;
30
+
31
+ /** Short enough to drive in a test, long enough that the two windows do not overlap. */
32
+ export const IDLE_MS = 1_000;
33
+ /** The production arm; its real value is what the gate is about. */
34
+ export const ARM_MS = SCROLLBAR_INPUT_ARM_MS;
35
+
36
+ /** The runner's own globals, restored on teardown so later files still see native Event/CustomEvent/window. */
37
+ const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
38
+
39
+ export function saveNativeGlobals(): void {
40
+ const target = globalThis as unknown as Record<string, unknown>;
41
+ for (const key of DOM_GLOBALS) {
42
+ if (!(key in nativeGlobals)) nativeGlobals[key] = target[key];
43
+ }
44
+ }
45
+
46
+ export function restoreNativeGlobals(): void {
47
+ const target = globalThis as unknown as Record<string, unknown>;
48
+ for (const key of DOM_GLOBALS) {
49
+ if (nativeGlobals[key] === undefined) delete target[key];
50
+ else target[key] = nativeGlobals[key];
51
+ }
52
+ }
53
+
54
+ /** A fresh document with the reveal rule installed on it. */
55
+ export function freshPage(): void {
56
+ const win = new Window({ url: 'http://localhost' });
57
+ const target = globalThis as unknown as Record<string, unknown>;
58
+ for (const key of DOM_GLOBALS) target[key] = (win as unknown as Record<string, unknown>)[key];
59
+ installScrollbarActivity(IDLE_MS, ARM_MS);
60
+ }
61
+
62
+ /** A scroll container in the live document. */
63
+ export function scroller(): HTMLElement {
64
+ const element = document.createElement('div');
65
+ document.body.appendChild(element);
66
+ return element;
67
+ }
68
+
69
+ /**
70
+ * A container that MEASURES as scrollable.
71
+ *
72
+ * happy-dom lays nothing out, so every `scrollHeight`/`clientHeight` is 0 and
73
+ * the "can this overflow" test the input path uses would skip every node. The
74
+ * numbers are what Chromium reports for the same DOM shape.
75
+ */
76
+ export function scrollSurface(): HTMLElement {
77
+ const element = document.createElement('div');
78
+ element.style.overflowY = 'auto';
79
+ Object.defineProperties(element, {
80
+ scrollHeight: { value: 900, configurable: true },
81
+ clientHeight: { value: 300, configurable: true },
82
+ scrollWidth: { value: 100, configurable: true },
83
+ clientWidth: { value: 100, configurable: true },
84
+ });
85
+ document.body.appendChild(element);
86
+ return element;
87
+ }
88
+
89
+ /** The event a browser dispatches at a scroller — it does not bubble. */
90
+ export function scrollAt(element: Element): void {
91
+ element.dispatchEvent(new Event('scroll'));
92
+ }
93
+
94
+ /** The input a browser delivers before a scroll the USER caused.
95
+ *
96
+ * Dispatched ON the scroller, because that is what a wheel does: it is targeted
97
+ * at the element under the pointer, and the arm is bound to that subtree so a
98
+ * wheel that could not move its container cannot later vouch for a programmatic
99
+ * scroll somewhere else. */
100
+ export function inputAt(element: Element = document.body): void {
101
+ element.dispatchEvent(new Event('wheel'));
102
+ }
103
+
104
+ /** The keydown a browser delivers when the reader presses a scrolling key. */
105
+ export function keyAt(key: string): void {
106
+ document.body.dispatchEvent(new window.KeyboardEvent('keydown', { key, bubbles: true }));
107
+ }
@@ -372,6 +372,36 @@
372
372
  background-color: color-mix(in srgb, var(--theme-error) 75%, var(--theme-ink));
373
373
  }
374
374
 
375
+ /* MONOCHROME: the composer's action pair (Stop / Send) is INK, not red/blue.
376
+ *
377
+ * The pair differs by hue in the colour mode — `bg-error-text` against
378
+ * `bg-info-text` — because that mode is the one place a user asks for chroma.
379
+ * Monochrome is the DEFAULT and it states itself as "every icon in the palette
380
+ * ink" (`icon-paint-ink.ts`), so two filled signal buttons were the only
381
+ * saturated objects left in a window that said it had no colour; reported as
382
+ * "btn send dan btn stop di mode monochrome kenapa masih berwarna?".
383
+ *
384
+ * The fill follows the app's own inverted surface (`bg-ink text-canvas`, used by
385
+ * every primary button), so the pair keeps the same geometry and the glyph's
386
+ * `text-canvas` stays the house pair — the palette's ink/canvas relationship,
387
+ * which is the one every body text already relies on.
388
+ *
389
+ * These rules are UNLAYERED and scoped to `:root:not([data-icon-style="color"])`
390
+ * for two reasons: a rule inside `@layer utilities` would sit at the same layer
391
+ * as the caller's `bg-info-text` and win only by source order, and the
392
+ * `:not(:disabled)` on hover keeps a disabled Send from re-stating the colour
393
+ * fill it was just moved off. The glyph itself is already handled by
394
+ * `monochromeSolidFillRules`, which keys on the very `bg-info-text` /
395
+ * `bg-error-text` classes this rule repaints.
396
+ */
397
+ :root:not([data-icon-style="color"]) .composer-action {
398
+ background-color: var(--theme-ink);
399
+ }
400
+
401
+ :root:not([data-icon-style="color"]) .composer-action:hover:not(:disabled) {
402
+ background-color: color-mix(in srgb, var(--theme-ink) 90%, transparent);
403
+ }
404
+
375
405
  /* (The hero card's dot-grain texture lived here and was used by nothing: the
376
406
  deploy hero it decorated is not part of this product. A texture with no
377
407
  consumer is a rule that only drifts.) */
@@ -396,7 +426,8 @@
396
426
  * The thumb is TRANSPARENT at rest and painted only while the user is
397
427
  * scrolling that element. `installScrollbarActivity()` (see
398
428
  * `src/client/lib/scrollbar-activity.ts`) puts `data-scrollbar-active` on the
399
- * scroller itself for 5s after each of its own `scroll` events, and this
429
+ * scroller itself: on the input that starts a scroll, and again on each of its
430
+ * own `scroll` events, keeping it there for 5s after the last one. This
400
431
  * stylesheet is the other half of that contract: a global `scroll` listener is
401
432
  * one listener for every scroll container in the document, including ones that
402
433
  * do not exist yet, which is why no component has to opt in.
@@ -200,7 +200,9 @@ describe('closeDb', () => {
200
200
  // slot while `getDb()` was still opening, so the continuation assigned
201
201
  // `resolved` on the DROPPED slot object. Nothing could reach that handle
202
202
  // again, and on Windows its temp directory stayed locked — `EBUSY … a
203
- // handle outlived its test`, reported against the two PRECEDING cases.
203
+ // handle outlived its test`, reported against the two PRECEDING cases. A
204
+ // retirement in this window never reaches `createDb`; the `disposed` check
205
+ // after it still closes a handle retired DURING initialisation.
204
206
  const savedSlot = globalThis.__kabmoDb;
205
207
  try {
206
208
  Bun.env.KABMO_DB_PATH = path.join(tempRoot(), 'in-flight', 'db.sqlite');
@@ -244,6 +246,53 @@ describe('closeDb', () => {
244
246
  }
245
247
  });
246
248
 
249
+ test('an open uses the path configured when it was requested', async () => {
250
+ // A fire-and-forget `getDb()` can still be resolving while its suite tears
251
+ // down and deletes `KABMO_DB_PATH`. Re-reading the environment at resolution
252
+ // time then opens the DEFAULT path — the developer's real database — so the
253
+ // path is snapshotted when the open is requested.
254
+ const savedSlot = globalThis.__kabmoDb;
255
+ try {
256
+ const requested = path.join(tempRoot(), 'snapshot', 'db.sqlite');
257
+ Bun.env.KABMO_DB_PATH = requested;
258
+ globalThis.__kabmoDb = undefined;
259
+
260
+ const pending = getDb();
261
+ // The teardown that used to redirect this open.
262
+ delete Bun.env.KABMO_DB_PATH;
263
+
264
+ const db = await pending;
265
+ expect(existsSync(requested)).toBe(true);
266
+ await closeDb();
267
+ expect(db).toBeDefined();
268
+ } finally {
269
+ globalThis.__kabmoDb = savedSlot;
270
+ }
271
+ });
272
+
273
+ test('a retired open never creates the file it would have opened', async () => {
274
+ // The leak this pins: an open still resolving its path while the slot is
275
+ // retired used to reach `createDb` and leave a database file behind, then
276
+ // close it and reject. A fire-and-forget caller whose suite had already
277
+ // restored its environment resolved the DEFAULT path, so the file it
278
+ // created was the developer's real `~/.kabmo/db.sqlite` (measured on a full
279
+ // `bun test`, from an ACP child-outcome write finishing after teardown).
280
+ const savedSlot = globalThis.__kabmoDb;
281
+ try {
282
+ const dbPath = path.join(tempRoot(), 'never-opened', 'db.sqlite');
283
+ Bun.env.KABMO_DB_PATH = dbPath;
284
+ globalThis.__kabmoDb = undefined;
285
+
286
+ const pending = getDb();
287
+ await closeDb();
288
+
289
+ await expect(pending).rejects.toThrow(/retired/);
290
+ expect(existsSync(dbPath)).toBe(false);
291
+ } finally {
292
+ globalThis.__kabmoDb = savedSlot;
293
+ }
294
+ });
295
+
247
296
  test('the returned promise settles only once the in-flight handle is closed', async () => {
248
297
  // The bug this pins is a RACE, and it is the one the Release gate hit:
249
298
  // retiring the slot is synchronous, but an open already in flight still