pi-pocket 0.28.2 → 0.29.0-beta.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 (46) hide show
  1. package/docs/architecture.md +4 -3
  2. package/docs/customizing.md +1 -1
  3. package/docs/extensions/linked-sessions.md +2 -0
  4. package/docs/extensions/policies/api-stability.md +1 -1
  5. package/docs/extensions/reference/api-versions.md +3 -0
  6. package/docs/extensions/reference/host.md +18 -4
  7. package/docs/extensions/reference/pocket.md +12 -1
  8. package/docs/extensions/reference/types.md +19 -1
  9. package/docs/extensions/tools.md +18 -0
  10. package/docs/features.md +5 -5
  11. package/docs/map.md +6 -4
  12. package/npm-shrinkwrap.json +2 -2
  13. package/package.json +1 -1
  14. package/src/server/app.ts +2 -7
  15. package/src/server/browser/cdp.ts +6 -0
  16. package/src/server/browser/identity.ts +55 -0
  17. package/src/server/browser/page.ts +12 -1
  18. package/src/server/browser.ts +1 -0
  19. package/src/server/commands.ts +26 -5
  20. package/src/server/config.ts +10 -0
  21. package/src/server/custom-providers.ts +304 -23
  22. package/src/server/docs.ts +10 -3
  23. package/src/server/extensions/agent-teams.ts +9 -1
  24. package/src/server/extensions/subagents.ts +51 -3
  25. package/src/server/host.ts +13 -4
  26. package/src/server/http/assets.ts +26 -3
  27. package/src/server/http/io.ts +11 -1
  28. package/src/server/http/link-routes.ts +4 -1
  29. package/src/server/http.ts +29 -3
  30. package/src/server/linked-sessions.ts +92 -9
  31. package/src/server/project-model.ts +17 -1
  32. package/types/pocket.d.ts +40 -6
  33. package/web/app.js +3 -2
  34. package/web/back.js +27 -6
  35. package/web/browser-panel.js +23 -12
  36. package/web/browser-paste.js +13 -0
  37. package/web/composer.js +7 -3
  38. package/web/extension-ui.js +17 -2
  39. package/web/index.html +2 -0
  40. package/web/pip.js +65 -0
  41. package/web/running-board.js +38 -36
  42. package/web/sheets/custom-providers.js +420 -21
  43. package/web/sheets/memory.js +76 -40
  44. package/web/store.js +117 -22
  45. package/web/style.css +176 -13
  46. package/web/transcript.js +57 -11
package/web/back.js CHANGED
@@ -6,9 +6,10 @@
6
6
  // above them stay in order. This module knows nothing of the app's state: store.js asks for routes and hears when back
7
7
  // changes one, and components register their layers with `useBack` (or `addLayer` and `removeLayer`).
8
8
  //
9
- // Each entry this module writes says how many layers it stands for (`history.state.pocket.layers`), and how many steps
10
- // back the session list's entry is (`back`), when known. A home screen app keeps an entry of the list's under the list
11
- // itself: the system's swipe back there has no browser page to land on, and would otherwise leave the app blank.
9
+ // Each entry this module writes says how many layers it stands for (`history.state.pocket.layers`), how many steps
10
+ // back the session list's entry is (`back`), when known, and the route whose entry is under its route's (`from`), when
11
+ // known. A home screen app keeps an entry of the list's under the list itself: the system's swipe back there has no
12
+ // browser page to land on, and would otherwise leave the app blank.
12
13
  // The app is the truth and history follows it: a layer closed by a tap takes its entry back off; one opened adds an
13
14
  // entry. Going back (the person's own) closes the layers above the entry it lands on.
14
15
 
@@ -328,6 +329,13 @@ export const goBack = () => history.back();
328
329
  /** What `pushRoute` kept on the route's entry under `key`, or undefined. */
329
330
  export const routeState = (key) => history.state?.pocket?.[key];
330
331
 
332
+ /**
333
+ * The route this one was opened over (a path), whose entry is under this route's, so `popRoute` goes back there.
334
+ * Undefined when not known, or while history has not caught up with the route the app shows.
335
+ */
336
+ export const routeUnder = () =>
337
+ location.pathname === shown ? history.state?.pocket?.from : undefined;
338
+
331
339
  // ─── Routes ───────────────────────────────────────────────────────────────────────
332
340
 
333
341
  /** The session list's route. */
@@ -405,6 +413,9 @@ export function pushRoute(path, { replace = false, state: kept = {} } = {}) {
405
413
  return;
406
414
  }
407
415
 
416
+ // The route it opens over: history follows in order, so that route's entry is the one under the new entry.
417
+ const under = shown;
418
+
408
419
  homeRequest++;
409
420
  heading(path === HOME ? "back" : "forward");
410
421
  moved();
@@ -414,10 +425,20 @@ export function pushRoute(path, { replace = false, state: kept = {} } = {}) {
414
425
  await traverse(-depth());
415
426
  }
416
427
 
417
- const here = history.state?.pocket?.back;
428
+ const here = history.state?.pocket;
418
429
  const back =
419
- path === HOME ? 0 : replace ? here : typeof here === "number" ? here + 1 : undefined;
420
- const state = { pocket: { ...kept, layers: 0, back } };
430
+ path === HOME
431
+ ? 0
432
+ : replace
433
+ ? here?.back
434
+ : typeof here?.back === "number"
435
+ ? here.back + 1
436
+ : undefined;
437
+ // In this route's place, it is over what this route was over.
438
+ const from = replace ? here?.from : under;
439
+ const state = {
440
+ pocket: { ...kept, layers: 0, back, ...(from === undefined ? {} : { from }) },
441
+ };
421
442
 
422
443
  shownBack = back;
423
444
 
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { useEffect, useRef, useState } from "preact/hooks";
6
6
  import { useBack } from "./back.js";
7
+ import { screenPaste } from "./browser-paste.js";
7
8
  import {
8
9
  browserApi,
9
10
  browserAvailable,
@@ -293,6 +294,28 @@ function Screen({ frame, interactive, send }) {
293
294
  return () => element.removeEventListener("wheel", wheel);
294
295
  }, [interactive, send]);
295
296
 
297
+ // Firefox gives a paste to the element it last edited, not the focused screen: take it on the document, in
298
+ // the capture phase, before that element's own paste handler (the composer's) can act on it.
299
+ useEffect(() => {
300
+ if (!interactive) {
301
+ return undefined;
302
+ }
303
+
304
+ const paste = (event) => {
305
+ const text = screenPaste(event, ref.current, document.activeElement);
306
+
307
+ if (text !== null) {
308
+ event.preventDefault();
309
+ event.stopPropagation();
310
+ send({ type: "text", text });
311
+ }
312
+ };
313
+
314
+ document.addEventListener("paste", paste, true);
315
+
316
+ return () => document.removeEventListener("paste", paste, true);
317
+ }, [interactive, send]);
318
+
296
319
  if (!interactive) {
297
320
  return html`<img
298
321
  class="browser-screen"
@@ -428,17 +451,6 @@ function Screen({ frame, interactive, send }) {
428
451
  send({ type: "key", key: event.key, modifiers });
429
452
  };
430
453
 
431
- const paste = (event) => {
432
- const text = event.clipboardData?.getData("text") ?? "";
433
-
434
- if (text === "") {
435
- return;
436
- }
437
-
438
- event.preventDefault();
439
- send({ type: "text", text });
440
- };
441
-
442
454
  return html`<img
443
455
  ref=${ref}
444
456
  class="browser-screen live"
@@ -452,7 +464,6 @@ function Screen({ frame, interactive, send }) {
452
464
  onPointerCancel=${() => (drag.current = null)}
453
465
  onContextMenu=${(event) => event.preventDefault()}
454
466
  onKeyDown=${key}
455
- onPaste=${paste}
456
467
  />`;
457
468
  }
458
469
 
@@ -0,0 +1,13 @@
1
+ // Pasting into the Browser panel's screen. Firefox gives a paste to the element it last edited, so the screen never
2
+ // hears it: the panel listens on the document instead. No imports, so Node tests it.
3
+
4
+ /** The text to send to the page for a paste, or null when the paste is not the screen's or holds no text. */
5
+ export function screenPaste(event, screen, active) {
6
+ if (!screen || active !== screen) {
7
+ return null;
8
+ }
9
+
10
+ const text = event.clipboardData?.getData("text") ?? "";
11
+
12
+ return text === "" ? null : text;
13
+ }
package/web/composer.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  canSteer,
22
22
  collab,
23
23
  drafts,
24
- navigate,
24
+ navigateUp,
25
25
  notify,
26
26
  openSheet,
27
27
  dropQuote,
@@ -54,7 +54,10 @@ import {
54
54
  Spinner,
55
55
  } from "./ui.js";
56
56
 
57
- /** The explicit route to the parent on every layout, outside the dock and the scrolling conversation. */
57
+ /**
58
+ * The explicit route to the parent on every layout, outside the dock and the scrolling conversation. Up, not forward:
59
+ * back from the parent does not open the subagent again.
60
+ */
58
61
  function ParentSessionButton() {
59
62
  const parent = store.state.view.conversation?.parent;
60
63
 
@@ -66,7 +69,7 @@ function ParentSessionButton() {
66
69
  class="parent-session"
67
70
  aria-label=${`Back to main session: ${parent.title}`}
68
71
  title=${`Return to ${parent.title}`}
69
- onClick=${() => navigate(parent.id)}
72
+ onClick=${() => navigateUp(parent.id)}
70
73
  >
71
74
  <${Icon} name="back" size=${16} />
72
75
  <span>Back to main session</span>
@@ -1026,6 +1029,7 @@ export function Composer() {
1026
1029
  const filled = text.trim() !== "" || files.length > 0;
1027
1030
  const uploading = files.some((file) => file.state === "uploading");
1028
1031
  const canSend =
1032
+ store.state.me != null &&
1029
1033
  !sending &&
1030
1034
  !uploading &&
1031
1035
  (text.trim() !== "" ||
@@ -1156,7 +1156,7 @@ function pocketFor(record) {
1156
1156
  return undefined;
1157
1157
  },
1158
1158
  /** Open through the app's normal navigation; the server checks access on connection. */
1159
- openConversation: (id) => {
1159
+ openConversation: (id, options) => {
1160
1160
  tick(record);
1161
1161
 
1162
1162
  const value = typeof id === "string" && /^[1-9]\d*$/.test(id) ? Number(id) : id;
@@ -1165,7 +1165,22 @@ function pocketFor(record) {
1165
1165
  throw new Error("pocket.openConversation: give a positive conversation id");
1166
1166
  }
1167
1167
 
1168
- navigate(value);
1168
+ // The artifact option names one of that session's artifacts; anything else in it is ignored.
1169
+ const artifact = typeof options?.artifact === "string" ? options.artifact : "";
1170
+ const version = options?.version;
1171
+
1172
+ navigate(
1173
+ value,
1174
+ artifact === ""
1175
+ ? undefined
1176
+ : {
1177
+ sheet: {
1178
+ type: "viewer",
1179
+ id: artifact,
1180
+ ...(Number.isSafeInteger(version) && version > 0 ? { version } : {}),
1181
+ },
1182
+ },
1183
+ );
1169
1184
  },
1170
1185
  /**
1171
1186
  * Call one of the module's routes: `api("status")` gets, `api("items", { name })` posts, and
package/web/index.html CHANGED
@@ -131,6 +131,8 @@
131
131
  return;
132
132
  }
133
133
 
134
+ // A signed-in page waits out its device-cache check hidden. A startup failure must still show.
135
+ boot.parentElement.hidden = false;
134
136
  boot.classList.add("failed");
135
137
  boot.querySelector(".boot-caption").textContent = "could not start";
136
138
 
package/web/pip.js CHANGED
@@ -1422,6 +1422,69 @@ function PipPanel({ leaving, scrim }) {
1422
1422
  }
1423
1423
 
1424
1424
  /** The mark in the corner: only while PiP works, or has something new. */
1425
+ /**
1426
+ * How far the session's message box rises above the bottom of the window, as it grows (a held-messages bar, a queue,
1427
+ * a long draft) and as the window changes; null while there is none. The mark keeps above it.
1428
+ */
1429
+ function useComposerRise(on) {
1430
+ const [rise, setRise] = useState(null);
1431
+
1432
+ useEffect(() => {
1433
+ if (!on) {
1434
+ return undefined;
1435
+ }
1436
+
1437
+ let box = null;
1438
+ let frame = 0;
1439
+
1440
+ const measure = () => {
1441
+ frame = 0;
1442
+ const top = box?.getBoundingClientRect().top;
1443
+
1444
+ setRise(top === undefined ? null : Math.max(0, Math.round(window.innerHeight - top)));
1445
+ };
1446
+
1447
+ const later = () => {
1448
+ frame ||= requestAnimationFrame(measure);
1449
+ };
1450
+
1451
+ const resized = new ResizeObserver(later);
1452
+
1453
+ // The box comes and goes with the session in view: found again when the page changes.
1454
+ const find = () => {
1455
+ const found = document.querySelector('footer.composer-wrap[data-part="composer"]');
1456
+
1457
+ if (found !== box) {
1458
+ resized.disconnect();
1459
+ box = found;
1460
+
1461
+ if (box) {
1462
+ resized.observe(box);
1463
+ }
1464
+
1465
+ later();
1466
+ }
1467
+ };
1468
+
1469
+ const changes = new MutationObserver(find);
1470
+
1471
+ find();
1472
+ changes.observe(document.body, { childList: true, subtree: true });
1473
+ window.addEventListener("resize", later);
1474
+ window.visualViewport?.addEventListener("resize", later);
1475
+
1476
+ return () => {
1477
+ cancelAnimationFrame(frame);
1478
+ resized.disconnect();
1479
+ changes.disconnect();
1480
+ window.removeEventListener("resize", later);
1481
+ window.visualViewport?.removeEventListener("resize", later);
1482
+ };
1483
+ }, [on]);
1484
+
1485
+ return rise;
1486
+ }
1487
+
1425
1488
  function PipBubble() {
1426
1489
  const { pip } = store.state;
1427
1490
  const unread = pipUnread();
@@ -1430,6 +1493,7 @@ function PipBubble() {
1430
1493
  pip && !pipBoard() && (pip.busy || unread) ? (pip.busy ? "busy" : "news") : null,
1431
1494
  150,
1432
1495
  );
1496
+ const rise = useComposerRise(kept !== null);
1433
1497
 
1434
1498
  if (kept === null) {
1435
1499
  return null;
@@ -1437,6 +1501,7 @@ function PipBubble() {
1437
1501
 
1438
1502
  return html`<button
1439
1503
  class=${`pip-bubble ${kept} ${leaving ? "leaving" : ""}`}
1504
+ style=${rise === null ? undefined : `--composer-rise: ${rise}px`}
1440
1505
  aria-label=${kept === "busy" ? "PiP is working: open PiP" : "PiP has something new: open PiP"}
1441
1506
  title="PiP (Alt+A)"
1442
1507
  onClick=${() => openPip()}
@@ -1171,44 +1171,46 @@ function Detail({ schedule, now, steer, color, onClose, onOpen, onCancel }) {
1171
1171
  Held: ${schedule.held}. At its time it is cancelled, unless that changes first.
1172
1172
  </div>`
1173
1173
  }
1174
- <pre class="rb-message">${schedule.text}</pre>
1175
- <dl class="rb-facts">
1176
- <dt>Repeats</dt>
1177
- <dd>${schedule.repeat ?? "no, once"}</dd>
1178
- <dt>Next</dt>
1179
- <dd>
1180
- ${clock(schedule.next, schedule.zone, now, { day: "always" })}
1181
- ${zone && ` ${zone}`}
1182
- ${" · "}
1183
- ${relative(schedule.next, now)}
1184
- </dd>
1185
- <dt>Zone</dt>
1186
- <dd>${schedule.zone}</dd>
1187
- <dt>Set by</dt>
1188
- <dd>${setBy(schedule)}</dd>
1189
- <dt>Set up</dt>
1190
- <dd>${relative(schedule.createdAt, now)}</dd>
1174
+ <div class="rb-detail-body">
1175
+ <pre class="rb-message">${schedule.text}</pre>
1176
+ <dl class="rb-facts">
1177
+ <dt>Repeats</dt>
1178
+ <dd>${schedule.repeat ?? "no, once"}</dd>
1179
+ <dt>Next</dt>
1180
+ <dd>
1181
+ ${clock(schedule.next, schedule.zone, now, { day: "always" })}
1182
+ ${zone && ` ${zone}`}
1183
+ ${" · "}
1184
+ ${relative(schedule.next, now)}
1185
+ </dd>
1186
+ <dt>Zone</dt>
1187
+ <dd>${schedule.zone}</dd>
1188
+ <dt>Set by</dt>
1189
+ <dd>${setBy(schedule)}</dd>
1190
+ <dt>Set up</dt>
1191
+ <dd>${relative(schedule.createdAt, now)}</dd>
1192
+ ${
1193
+ schedule.every &&
1194
+ html`<dt>Went out</dt>
1195
+ <dd>${schedule.runs} ${schedule.runs === 1 ? "time" : "times"}</dd>`
1196
+ }
1197
+ <dt>Id</dt>
1198
+ <dd class="mono">${schedule.id}</dd>
1199
+ </dl>
1191
1200
  ${
1192
- schedule.every &&
1193
- html`<dt>Went out</dt>
1194
- <dd>${schedule.runs} ${schedule.runs === 1 ? "time" : "times"}</dd>`
1201
+ schedule.upcoming.length > 1 &&
1202
+ html`<div class="rb-sub">Coming up</div>
1203
+ <div class="rb-upcoming">
1204
+ ${schedule.upcoming.slice(0, 5).map(
1205
+ (t) =>
1206
+ html`<span key=${t}>
1207
+ ${clock(t, schedule.zone, now, { day: "always" })}
1208
+ ${zone && ` ${zone}`}
1209
+ </span>`,
1210
+ )}
1211
+ </div>`
1195
1212
  }
1196
- <dt>Id</dt>
1197
- <dd class="mono">${schedule.id}</dd>
1198
- </dl>
1199
- ${
1200
- schedule.upcoming.length > 1 &&
1201
- html`<div class="rb-sub">Coming up</div>
1202
- <div class="rb-upcoming">
1203
- ${schedule.upcoming.slice(0, 5).map(
1204
- (t) =>
1205
- html`<span key=${t}>
1206
- ${clock(t, schedule.zone, now, { day: "always" })}
1207
- ${zone && ` ${zone}`}
1208
- </span>`,
1209
- )}
1210
- </div>`
1211
- }
1213
+ </div>
1212
1214
  <div class="rb-actions">
1213
1215
  <button class="button" onClick=${() => onOpen(schedule.session)}>Open session</button>
1214
1216
  ${