bom-pi 0.0.0-stage → 0.0.2

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 (131) hide show
  1. package/README.md +33 -2
  2. package/apps/README.md +7 -0
  3. package/apps/web/README.md +21 -0
  4. package/apps/web/pocket-adapter.mjs +323 -0
  5. package/apps/web/public/LICENSE.pocket +21 -0
  6. package/apps/web/public/activity-fold.js +28 -0
  7. package/apps/web/public/agent-now.js +37 -0
  8. package/apps/web/public/agent-tile.js +79 -0
  9. package/apps/web/public/app.js +975 -0
  10. package/apps/web/public/apple-touch-icon.png +0 -0
  11. package/apps/web/public/artifact-bridge.js +687 -0
  12. package/apps/web/public/avatar.js +87 -0
  13. package/apps/web/public/back.js +554 -0
  14. package/apps/web/public/box-keys.js +216 -0
  15. package/apps/web/public/browser-panel.js +1097 -0
  16. package/apps/web/public/browser.js +68 -0
  17. package/apps/web/public/calls.js +139 -0
  18. package/apps/web/public/chat.js +919 -0
  19. package/apps/web/public/clock.js +34 -0
  20. package/apps/web/public/commands.js +578 -0
  21. package/apps/web/public/composer.js +2068 -0
  22. package/apps/web/public/diff-parse.js +672 -0
  23. package/apps/web/public/diff.js +1646 -0
  24. package/apps/web/public/dock.js +299 -0
  25. package/apps/web/public/extension-ui.js +2734 -0
  26. package/apps/web/public/files-panel.js +775 -0
  27. package/apps/web/public/files.js +368 -0
  28. package/apps/web/public/fonts/FiraCode-VF.woff2 +0 -0
  29. package/apps/web/public/fonts/Geist.woff2 +0 -0
  30. package/apps/web/public/fonts/IBMPlexMono-Variable-Italic.woff2 +0 -0
  31. package/apps/web/public/fonts/IBMPlexMono-Variable.woff2 +0 -0
  32. package/apps/web/public/fonts/InterVariable-Italic.woff2 +0 -0
  33. package/apps/web/public/fonts/InterVariable.woff2 +0 -0
  34. package/apps/web/public/fonts/Iosevka-Bold.woff2 +0 -0
  35. package/apps/web/public/fonts/Iosevka-BoldItalic.woff2 +0 -0
  36. package/apps/web/public/fonts/Iosevka-Italic.woff2 +0 -0
  37. package/apps/web/public/fonts/Iosevka-Regular.woff2 +0 -0
  38. package/apps/web/public/fonts/Iosevka-SemiBold.woff2 +0 -0
  39. package/apps/web/public/fonts/Iosevka-SemiBoldItalic.woff2 +0 -0
  40. package/apps/web/public/fonts/JetBrainsMono-Italic.woff2 +0 -0
  41. package/apps/web/public/fonts/JetBrainsMono.woff2 +0 -0
  42. package/apps/web/public/fonts/NerdFontsSymbolsMono.woff2 +0 -0
  43. package/apps/web/public/fonts/SOURCES.md +69 -0
  44. package/apps/web/public/gestures.js +610 -0
  45. package/apps/web/public/highlight.js +480 -0
  46. package/apps/web/public/history.js +70 -0
  47. package/apps/web/public/home.js +169 -0
  48. package/apps/web/public/icon-192.png +0 -0
  49. package/apps/web/public/icon-512.png +0 -0
  50. package/apps/web/public/icon-maskable-512.png +0 -0
  51. package/apps/web/public/icon.svg +16 -0
  52. package/apps/web/public/index.html +71 -0
  53. package/apps/web/public/launcher.js +1293 -0
  54. package/apps/web/public/linked-sessions.js +55 -0
  55. package/apps/web/public/live.js +39 -0
  56. package/apps/web/public/manifest.webmanifest +32 -0
  57. package/apps/web/public/model-refresh.js +73 -0
  58. package/apps/web/public/notify.js +251 -0
  59. package/apps/web/public/peeks.js +920 -0
  60. package/apps/web/public/pip-attachments.js +182 -0
  61. package/apps/web/public/pip-window.js +141 -0
  62. package/apps/web/public/pip.js +1217 -0
  63. package/apps/web/public/quote-reply.js +109 -0
  64. package/apps/web/public/quote-text.js +31 -0
  65. package/apps/web/public/rich.js +403 -0
  66. package/apps/web/public/run-frame.js +106 -0
  67. package/apps/web/public/safe-mode.js +71 -0
  68. package/apps/web/public/seen.js +169 -0
  69. package/apps/web/public/session-tree.js +117 -0
  70. package/apps/web/public/sessions.js +2695 -0
  71. package/apps/web/public/share.js +126 -0
  72. package/apps/web/public/sheets/appearance.js +820 -0
  73. package/apps/web/public/sheets/branch.js +353 -0
  74. package/apps/web/public/sheets/extensions.js +818 -0
  75. package/apps/web/public/sheets/file.js +318 -0
  76. package/apps/web/public/sheets/find.js +250 -0
  77. package/apps/web/public/sheets/folder.js +680 -0
  78. package/apps/web/public/sheets/gallery.js +2340 -0
  79. package/apps/web/public/sheets/hooks.js +350 -0
  80. package/apps/web/public/sheets/memory.js +531 -0
  81. package/apps/web/public/sheets/menu.js +580 -0
  82. package/apps/web/public/sheets/message.js +220 -0
  83. package/apps/web/public/sheets/model.js +412 -0
  84. package/apps/web/public/sheets/people.js +414 -0
  85. package/apps/web/public/sheets/pi-sessions.js +264 -0
  86. package/apps/web/public/sheets/providers.js +525 -0
  87. package/apps/web/public/sheets/running.js +130 -0
  88. package/apps/web/public/sheets/schedules.js +71 -0
  89. package/apps/web/public/sheets/session.js +249 -0
  90. package/apps/web/public/sheets/shortcuts.js +101 -0
  91. package/apps/web/public/sheets/spend.js +150 -0
  92. package/apps/web/public/sheets/text.js +53 -0
  93. package/apps/web/public/sheets/viewers.js +363 -0
  94. package/apps/web/public/sheets/worktree.js +50 -0
  95. package/apps/web/public/sheets.js +410 -0
  96. package/apps/web/public/signin.js +57 -0
  97. package/apps/web/public/slots.js +208 -0
  98. package/apps/web/public/store.js +1760 -0
  99. package/apps/web/public/style.css +18625 -0
  100. package/apps/web/public/subagents-board.js +879 -0
  101. package/apps/web/public/subagents.js +273 -0
  102. package/apps/web/public/sw.js +169 -0
  103. package/apps/web/public/taps.js +26 -0
  104. package/apps/web/public/theme-surface.d.ts +4 -0
  105. package/apps/web/public/theme-surface.js +266 -0
  106. package/apps/web/public/theme.js +845 -0
  107. package/apps/web/public/themes/lantern/colors.toml +25 -0
  108. package/apps/web/public/themes/lantern/direction.css +60 -0
  109. package/apps/web/public/themes/lantern/frame.css +254 -0
  110. package/apps/web/public/themes/lantern/theme.css +10 -0
  111. package/apps/web/public/themes/lantern/theme.json +7 -0
  112. package/apps/web/public/themes/pocket/theme.css +189 -0
  113. package/apps/web/public/themes/pocket/theme.json +6 -0
  114. package/apps/web/public/themes.js +556 -0
  115. package/apps/web/public/transcript.js +3348 -0
  116. package/apps/web/public/trust.js +295 -0
  117. package/apps/web/public/turns.js +507 -0
  118. package/apps/web/public/ui.js +1910 -0
  119. package/apps/web/public/voice.js +345 -0
  120. package/apps/web/server.mjs +774 -0
  121. package/package.json +43 -4
  122. package/packages/cli/src/bom-pi.mjs +452 -0
  123. package/packages/cli/templates/blank.factory.json +7 -0
  124. package/packages/cli/templates/dev.factory.json +11 -0
  125. package/packages/cli/templates/docs.factory.json +12 -0
  126. package/packages/cli/templates/ops.factory.json +14 -0
  127. package/packages/cli/templates/triage.factory.json +10 -0
  128. package/packages/core/src/daemon.mjs +2047 -0
  129. package/packages/core/src/limit-gate.mjs +192 -0
  130. package/packages/core/src/rpc-client.mjs +66 -0
  131. package/systemd/README.md +11 -0
@@ -0,0 +1,610 @@
1
+ // Touch gestures for phones, for one hand. A sheet follows a finger dragging it down and closes when let go far or fast
2
+ // enough, as the drawer does dragged to the left. On the conversation, a swipe right goes back and a swipe left opens
3
+ // the Files tile; a swipe up from the message box opens the places. On an iPhone's home screen app, which has no back
4
+ // gesture of its own, a swipe in from the left edge goes back (back.js). Each swipe shows a mark that follows the finger.
5
+
6
+ import { useEffect, useRef } from "preact/hooks";
7
+ import { canGoBack, goBack } from "./back.js";
8
+
9
+ /** How far a finger moves before a drag takes it, or leaves it to scrolling. */
10
+ const SLOP = 8;
11
+ /** A drag closes what it drags past this share of its size, or flicked faster than this (px per ms). */
12
+ const CLOSE_SHARE = 0.28;
13
+ const CLOSE_SPEED = 0.45;
14
+ /** How long a spring back takes. */
15
+ const SPRING_MS = 260;
16
+
17
+ /**
18
+ * The finger a gesture follows, among a touch event's: by its identifier, so another finger on the glass (a thumb
19
+ * resting, a second one coming down) neither moves nor ends it.
20
+ */
21
+ const fingerOf = (list, id) => [...list].find((touch) => touch.identifier === id);
22
+
23
+ /**
24
+ * Something from `target` up to `root` that a drag `dir` would scroll first: scrolled away from its top, for a drag
25
+ * down; with more below, for a drag up.
26
+ */
27
+ function scrollsFirst(target, root, dir) {
28
+ for (let node = target; node && node !== root.parentElement; node = node.parentElement) {
29
+ const more =
30
+ dir === "down"
31
+ ? node.scrollTop > 0
32
+ : node.scrollTop + node.clientHeight < node.scrollHeight - 1;
33
+
34
+ if (more && node.scrollHeight > node.clientHeight) {
35
+ return true;
36
+ }
37
+ }
38
+
39
+ return false;
40
+ }
41
+
42
+ /** Fields and sliders keep their own drags. */
43
+ const ownDrag = (target) => target.closest?.("input, textarea, select, [contenteditable]") !== null;
44
+
45
+ /** Where a finger was when: the last few, for how fast it moved as it let go. */
46
+ function speedOf(samples) {
47
+ const last = samples.at(-1);
48
+ const first = samples.find((each) => last.time - each.time < 100) ?? samples[0];
49
+ const time = last.time - first.time;
50
+
51
+ return time > 0 ? (last.offset - first.offset) / time : 0;
52
+ }
53
+
54
+ /**
55
+ * Drag `ref`'s element to close it: `"down"` for a sheet from the bottom edge, `"up"` for a menu down from the top
56
+ * bar, `"left"` for the drawer. It follows the finger and dims the scrim behind it (its parent, or the `scrim` ref's
57
+ * element) as it goes. Let go far or fast enough,
58
+ * it calls `onClose` and stays where the finger left it, for its closing animation to go on from there; otherwise it
59
+ * springs back. Only on touch.
60
+ */
61
+ export function useDragToClose(ref, { dir, onClose, enabled = true, scrim: scrimRef }) {
62
+ const close = useRef(onClose);
63
+
64
+ close.current = onClose;
65
+ useEffect(() => {
66
+ const element = ref.current;
67
+
68
+ if (!element || !enabled) {
69
+ return undefined;
70
+ }
71
+
72
+ const vertical = dir === "down" || dir === "up";
73
+ // PiP's sheet has a scrim beside it, not around it: dimming its parent would dim the whole app.
74
+ const scrim = scrimRef?.current ?? element.parentElement;
75
+ // Around the element (a sheet's overlay), the scrim's color fades, so the sheet in it stays solid; beside it
76
+ // (PiP's), or the element itself (a notice), the whole of it does.
77
+ const around = scrim !== element && scrim.contains(element);
78
+ const fading = around ? "background-color" : "opacity";
79
+ let ground = null;
80
+ let start = null;
81
+ let dragging = false;
82
+ let samples = [];
83
+
84
+ const size = () => (vertical ? element.offsetHeight : element.offsetWidth) || 1;
85
+
86
+ const dim = (share) => {
87
+ if (around) {
88
+ ground ??= getComputedStyle(scrim).backgroundColor;
89
+ scrim.style.backgroundColor = `color-mix(in srgb, ${ground} ${Math.round((1 - share) * 100)}%, transparent)`;
90
+ } else {
91
+ scrim.style.opacity = String(1 - share);
92
+ }
93
+ };
94
+
95
+ const place = (offset) => {
96
+ element.style.transform =
97
+ dir === "down"
98
+ ? `translateY(${offset}px)`
99
+ : dir === "up"
100
+ ? `translateY(${-offset}px)`
101
+ : dir === "right"
102
+ ? `translateX(${offset}px)`
103
+ : `translateX(${-offset}px)`;
104
+ dim(Math.min(1, offset / size()) * 0.8);
105
+ };
106
+
107
+ const springBack = () => {
108
+ const spring = `${SPRING_MS}ms var(--ease-out)`;
109
+
110
+ // What fades as it goes may be the element itself (a notice): one transition for both.
111
+ scrim.style.transition = `${fading} ${spring}`;
112
+ element.style.transition =
113
+ scrim === element
114
+ ? `transform ${spring}, opacity ${spring}`
115
+ : `transform ${spring}`;
116
+ element.style.transform = "";
117
+ scrim.style.opacity = "";
118
+ scrim.style.backgroundColor = "";
119
+ setTimeout(() => {
120
+ element.style.transition = "";
121
+ scrim.style.transition = "";
122
+ }, SPRING_MS);
123
+ };
124
+
125
+ const onStart = (event) => {
126
+ const target = event.target;
127
+
128
+ // A second finger comes down mid-drag: the drag lets go, as a pinch or a slip is not a close.
129
+ if (dragging) {
130
+ springBack();
131
+ }
132
+
133
+ ground = null;
134
+
135
+ start =
136
+ event.touches.length === 1 &&
137
+ !ownDrag(target) &&
138
+ !(vertical && scrollsFirst(target, element, dir))
139
+ ? {
140
+ x: event.touches[0].clientX,
141
+ y: event.touches[0].clientY,
142
+ id: event.touches[0].identifier,
143
+ }
144
+ : null;
145
+ dragging = false;
146
+ samples = [];
147
+ };
148
+
149
+ const onMove = (event) => {
150
+ const touch = start && fingerOf(event.touches, start.id);
151
+
152
+ if (!touch) {
153
+ return;
154
+ }
155
+
156
+ const offset =
157
+ dir === "down"
158
+ ? touch.clientY - start.y
159
+ : dir === "up"
160
+ ? start.y - touch.clientY
161
+ : dir === "right"
162
+ ? touch.clientX - start.x
163
+ : start.x - touch.clientX;
164
+ const across = Math.abs(vertical ? touch.clientX - start.x : touch.clientY - start.y);
165
+
166
+ if (!dragging) {
167
+ if (Math.max(Math.abs(offset), across) < SLOP) {
168
+ return;
169
+ }
170
+
171
+ // The other way, or more across than along: a scroll, not this drag.
172
+ if (offset <= 0 || across > offset) {
173
+ start = null;
174
+
175
+ return;
176
+ }
177
+
178
+ dragging = true;
179
+ element.style.transition = "none";
180
+ scrim.style.transition = "none";
181
+ }
182
+
183
+ event.preventDefault();
184
+ const at = Math.max(0, offset - SLOP);
185
+
186
+ samples.push({ offset: at, time: event.timeStamp });
187
+ samples = samples.slice(-6);
188
+ place(at);
189
+ };
190
+
191
+ const onEnd = (event) => {
192
+ if (!start || !fingerOf(event.changedTouches, start.id)) {
193
+ return;
194
+ }
195
+
196
+ if (!dragging) {
197
+ start = null;
198
+
199
+ return;
200
+ }
201
+
202
+ const at = samples.at(-1)?.offset ?? 0;
203
+ const speed = speedOf(samples);
204
+
205
+ start = null;
206
+ dragging = false;
207
+
208
+ if (at > size() * CLOSE_SHARE || (speed > CLOSE_SPEED && at > SLOP)) {
209
+ close.current();
210
+ // Still here after its closing animation would have ended: it did not close after all.
211
+ setTimeout(() => element.isConnected && springBack(), 600);
212
+ } else {
213
+ springBack();
214
+ }
215
+ };
216
+
217
+ const onCancel = (event) => {
218
+ if (!start || !fingerOf(event.changedTouches, start.id)) {
219
+ return;
220
+ }
221
+
222
+ if (dragging) {
223
+ springBack();
224
+ }
225
+
226
+ start = null;
227
+ dragging = false;
228
+ };
229
+
230
+ element.addEventListener("touchstart", onStart, { passive: true });
231
+ element.addEventListener("touchmove", onMove, { passive: false });
232
+ element.addEventListener("touchend", onEnd);
233
+ element.addEventListener("touchcancel", onCancel);
234
+
235
+ return () => {
236
+ element.removeEventListener("touchstart", onStart);
237
+ element.removeEventListener("touchmove", onMove);
238
+ element.removeEventListener("touchend", onEnd);
239
+ element.removeEventListener("touchcancel", onCancel);
240
+
241
+ // Let go mid-drag (the element swapped, the drag turned off): it does not stay where the finger left it.
242
+ if (dragging) {
243
+ element.style.transform = "";
244
+ element.style.transition = "";
245
+ }
246
+
247
+ // The scrim may outlive the element: it never stays dimmed by a drag that closed it.
248
+ scrim.style.opacity = "";
249
+ scrim.style.backgroundColor = "";
250
+ scrim.style.transition = "";
251
+ };
252
+ }, [ref.current, dir, enabled, scrimRef?.current]);
253
+ }
254
+
255
+ // ─── Marks that follow a swipe ────────────────────────────────────────────────────
256
+
257
+ const BACK_PATH = "M15 18l-6-6 6-6";
258
+
259
+ let mark = null;
260
+
261
+ /**
262
+ * The mark a swipe shows, coming in from `side` as the finger goes (`offset`), lit once letting go would act: an icon
263
+ * (an SVG path) and an optional label, at height `y`.
264
+ */
265
+ function showMark({ side, y, offset, armed, path = BACK_PATH, label = "" }) {
266
+ if (!mark) {
267
+ mark = document.createElement("div");
268
+ mark.className = "swipe-mark";
269
+ mark.setAttribute("aria-hidden", "true");
270
+ document.body.append(mark);
271
+ }
272
+
273
+ const key = `${side}|${path}|${label}`;
274
+
275
+ if (mark.dataset.key !== key) {
276
+ mark.dataset.key = key;
277
+ mark.dataset.side = side;
278
+ mark.innerHTML = `<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="${path}"/></svg>`;
279
+
280
+ if (label) {
281
+ mark.append(label);
282
+ }
283
+ }
284
+
285
+ const width = mark.offsetWidth;
286
+ const shift = Math.min(offset * 0.75, width + 16);
287
+
288
+ mark.classList.remove("going");
289
+ mark.classList.toggle("armed", armed);
290
+ mark.style.top = `${Math.round(y) - 22}px`;
291
+ mark.style.transform = `translateX(${side === "left" ? shift - width : width - shift}px)`;
292
+ mark.style.opacity = String(Math.min(1, offset / 40));
293
+ }
294
+
295
+ function hideMark() {
296
+ if (mark) {
297
+ const width = mark.offsetWidth + 8;
298
+
299
+ mark.classList.add("going");
300
+ mark.style.transform = `translateX(${mark.dataset.side === "left" ? -width : width}px)`;
301
+ mark.style.opacity = "0";
302
+ }
303
+ }
304
+
305
+ // ─── Back from the left edge ──────────────────────────────────────────────────────
306
+
307
+ /** How near the left edge a swipe back starts, and how far it goes before letting go goes back. */
308
+ const EDGE = 22;
309
+ const ARM = 72;
310
+
311
+ /** An iPhone or iPad home screen app: no browser around it, and no back gesture of the system's. */
312
+ const edgeBackWanted = () => navigator.standalone === true;
313
+
314
+ /**
315
+ * Swipe in from the left edge to go back, where nothing else does it. Passive, as the conversation's swipes are: the
316
+ * page has nothing to scroll sideways there, and scrolling never waits on it. Not from what is marked `data-no-swipe`
317
+ * (an extension's page that keeps its swipes, or a part of one), as the other swipes.
318
+ */
319
+ export function startEdgeBack() {
320
+ if (!edgeBackWanted()) {
321
+ return;
322
+ }
323
+
324
+ let start = null;
325
+ let dragging = false;
326
+ let offset = 0;
327
+
328
+ document.addEventListener(
329
+ "touchstart",
330
+ (event) => {
331
+ const touch = event.touches[0];
332
+
333
+ if (dragging) {
334
+ hideMark();
335
+ }
336
+
337
+ start =
338
+ event.touches.length === 1 &&
339
+ touch.clientX <= EDGE &&
340
+ canGoBack() &&
341
+ !event.target.closest?.("[data-no-swipe]")
342
+ ? { x: touch.clientX, y: touch.clientY, id: touch.identifier }
343
+ : null;
344
+ dragging = false;
345
+ offset = 0;
346
+ },
347
+ { passive: true, capture: true },
348
+ );
349
+ document.addEventListener(
350
+ "touchmove",
351
+ (event) => {
352
+ const touch = start && fingerOf(event.touches, start.id);
353
+
354
+ if (!touch) {
355
+ return;
356
+ }
357
+
358
+ const across = Math.abs(touch.clientY - start.y);
359
+
360
+ offset = touch.clientX - start.x;
361
+
362
+ if (!dragging) {
363
+ if (Math.max(Math.abs(offset), across) < SLOP) {
364
+ return;
365
+ }
366
+
367
+ if (offset <= 0 || across > offset) {
368
+ start = null;
369
+
370
+ return;
371
+ }
372
+
373
+ dragging = true;
374
+ }
375
+
376
+ showMark({ side: "left", y: touch.clientY, offset, armed: offset >= ARM });
377
+ },
378
+ { passive: true, capture: true },
379
+ );
380
+
381
+ const end = (event, going) => {
382
+ if (!start || !fingerOf(event.changedTouches, start.id)) {
383
+ return;
384
+ }
385
+
386
+ if (dragging && going && offset >= ARM) {
387
+ goBack();
388
+ }
389
+
390
+ if (dragging) {
391
+ hideMark();
392
+ }
393
+
394
+ start = null;
395
+ dragging = false;
396
+ };
397
+
398
+ document.addEventListener("touchend", (event) => end(event, true), { capture: true });
399
+ document.addEventListener("touchcancel", (event) => end(event, false), { capture: true });
400
+ }
401
+
402
+ // ─── Swipes on the conversation ───────────────────────────────────────────────────
403
+
404
+ /** Where the conversation's swipes work: below the sidebar's width, where the top bar is a stretch for a thumb. */
405
+ const NARROW = matchMedia("(max-width: 959px)");
406
+ /** Where the subagents board, and an extension's page, are a phone's screen of their own (`subagents-board.js`). */
407
+ const PHONE = matchMedia("(max-width: 699px)");
408
+ /** Swipes start this far from the screen's sides, which belong to the system's back gesture (and `startEdgeBack`). */
409
+ const SIDES = 24;
410
+ /** How far up from the message box a swipe goes before it opens what it opens. */
411
+ const UP = 44;
412
+ /** How far a sideways swipe may drift up or down before it counts as scrolling after all. */
413
+ const DRIFT = 56;
414
+
415
+ /** Something between `target` and `root` scrolls sideways (a wide code block, a table): a swipe there scrolls it. */
416
+ function scrollsSideways(target, root) {
417
+ for (let node = target; node && node !== root; node = node.parentElement) {
418
+ if (node.scrollWidth > node.clientWidth + 1) {
419
+ const overflow = getComputedStyle(node).overflowX;
420
+
421
+ if (overflow === "auto" || overflow === "scroll") {
422
+ return true;
423
+ }
424
+ }
425
+ }
426
+
427
+ return false;
428
+ }
429
+
430
+ /**
431
+ * One-handed swipes on a phone, with passive listeners so scrolling never waits on them. On the conversation, sideways:
432
+ * right goes back, left opens a place (the Files tile), each with a mark that follows the finger and lights when
433
+ * letting go would act; the conversation leans a little the same way. In the Files tile, right goes back too. Up from
434
+ * the message box (not its text, nor the queue and bars above it) opens the places; on the subagents board, right goes
435
+ * back, and on an extension's page too (`"board"` as well), both at a phone's width only. `swipes(where)` says, when a
436
+ * touch starts on `"conversation"`, `"files"`, or `"board"`, what each does now: `{ right, left }` as
437
+ * `{ path, label, run }`, and `up` as a function, or none. No swipe starts in a field, nor in anything marked
438
+ * `data-no-swipe` (what an extension's page keeps its sideways swipes for, or the whole page).
439
+ */
440
+ export function startSwipes(swipes) {
441
+ let swipe = null;
442
+
443
+ const lean = (offset) => {
444
+ if (swipe?.root) {
445
+ swipe.root.style.transition =
446
+ offset === 0 ? `transform ${SPRING_MS}ms var(--ease-out)` : "none";
447
+ swipe.root.style.transform =
448
+ offset === 0 ? "" : `translateX(${Math.max(-28, Math.min(28, offset * 0.18))}px)`;
449
+ }
450
+ };
451
+
452
+ const stop = (act) => {
453
+ if (swipe?.dir === "left" || swipe?.dir === "right") {
454
+ hideMark();
455
+ lean(0);
456
+
457
+ if (act && swipe.armed) {
458
+ swipe.acts[swipe.dir].run();
459
+ }
460
+ }
461
+
462
+ swipe = null;
463
+ };
464
+
465
+ document.addEventListener(
466
+ "touchstart",
467
+ (event) => {
468
+ // A second finger coming down lets go of a swipe under way.
469
+ stop(false);
470
+
471
+ if (event.touches.length !== 1 || !NARROW.matches) {
472
+ return;
473
+ }
474
+
475
+ const target = event.target;
476
+ const touch = event.touches[0];
477
+
478
+ if (
479
+ target.closest?.(
480
+ "input, textarea, select, [contenteditable], .commands, [data-no-swipe]",
481
+ )
482
+ ) {
483
+ return;
484
+ }
485
+
486
+ const root = target.closest?.(
487
+ ".pane > .scroller, .files-tile:not(.leaving), .board.phone, .ext-page",
488
+ );
489
+
490
+ // An extension's page swipes back only at a phone's width, where it fills the screen, as the board does.
491
+ if (root?.classList.contains("ext-page") && !PHONE.matches) {
492
+ return;
493
+ }
494
+
495
+ const acts = swipes(
496
+ root?.classList.contains("files-tile")
497
+ ? "files"
498
+ : root?.classList.contains("board") || root?.classList.contains("ext-page")
499
+ ? "board"
500
+ : "conversation",
501
+ );
502
+ const at = {
503
+ x: touch.clientX,
504
+ y: touch.clientY,
505
+ id: touch.identifier,
506
+ acts,
507
+ dir: null,
508
+ armed: false,
509
+ };
510
+
511
+ if (
512
+ root &&
513
+ touch.clientX > SIDES &&
514
+ touch.clientX < innerWidth - SIDES &&
515
+ (acts.left || acts.right) &&
516
+ !scrollsSideways(target, root) &&
517
+ !getSelection()?.toString()
518
+ ) {
519
+ swipe = { ...at, root };
520
+ } else if (
521
+ acts.up &&
522
+ target.closest?.(".composer-wrap") &&
523
+ // Above the box, the queue and the subagents list scroll: a finger there scrolls them.
524
+ !target.closest(".dock")
525
+ ) {
526
+ swipe = { ...at, root: null, up: true };
527
+ }
528
+ },
529
+ { passive: true },
530
+ );
531
+ document.addEventListener(
532
+ "touchmove",
533
+ (event) => {
534
+ const touch = swipe && fingerOf(event.touches, swipe.id);
535
+
536
+ if (!touch) {
537
+ return;
538
+ }
539
+
540
+ const dx = touch.clientX - swipe.x;
541
+ const dy = touch.clientY - swipe.y;
542
+
543
+ if (!swipe.dir) {
544
+ if (Math.max(Math.abs(dx), Math.abs(dy)) < SLOP) {
545
+ return;
546
+ }
547
+
548
+ const dir = swipe.up
549
+ ? dy < 0 && -dy > Math.abs(dx)
550
+ ? "up"
551
+ : null
552
+ : Math.abs(dx) > Math.abs(dy) * 1.5
553
+ ? dx < 0
554
+ ? "left"
555
+ : "right"
556
+ : null;
557
+
558
+ if (dir === null || (dir !== "up" && !swipe.acts[dir])) {
559
+ swipe = null;
560
+
561
+ return;
562
+ }
563
+
564
+ swipe.dir = dir;
565
+ }
566
+
567
+ if (swipe.dir === "up") {
568
+ if (-dy >= UP) {
569
+ const open = swipe.acts.up;
570
+
571
+ swipe = null;
572
+ open();
573
+ }
574
+
575
+ return;
576
+ }
577
+
578
+ // Drifted into a scroll after all.
579
+ if (Math.abs(dy) > DRIFT) {
580
+ stop(false);
581
+
582
+ return;
583
+ }
584
+
585
+ const offset = Math.max(0, swipe.dir === "left" ? -dx : dx);
586
+ const act = swipe.acts[swipe.dir];
587
+
588
+ swipe.armed = offset >= ARM;
589
+ showMark({
590
+ side: swipe.dir === "left" ? "right" : "left",
591
+ y: swipe.y,
592
+ offset,
593
+ armed: swipe.armed,
594
+ path: act.path,
595
+ label: act.label,
596
+ });
597
+ lean(dx);
598
+ },
599
+ { passive: true },
600
+ );
601
+
602
+ const ended = (event, act) => {
603
+ if (swipe && fingerOf(event.changedTouches, swipe.id)) {
604
+ stop(act);
605
+ }
606
+ };
607
+
608
+ document.addEventListener("touchend", (event) => ended(event, true));
609
+ document.addEventListener("touchcancel", (event) => ended(event, false));
610
+ }