@songsid/agend 2.3.4-beta.6 → 2.3.4-beta.8

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 (111) hide show
  1. package/dist/agend-home.d.ts +13 -0
  2. package/dist/agend-home.js +42 -0
  3. package/dist/agend-home.js.map +1 -1
  4. package/dist/auth-api.js +2 -2
  5. package/dist/auth-api.js.map +1 -1
  6. package/dist/backend/kiro-identity.d.ts +2 -0
  7. package/dist/backend/kiro-identity.js +13 -6
  8. package/dist/backend/kiro-identity.js.map +1 -1
  9. package/dist/backend/kiro.d.ts +3 -0
  10. package/dist/backend/kiro.js +57 -4
  11. package/dist/backend/kiro.js.map +1 -1
  12. package/dist/backend/types.d.ts +6 -1
  13. package/dist/backend/types.js +3 -0
  14. package/dist/backend/types.js.map +1 -1
  15. package/dist/backend-availability.d.ts +6 -0
  16. package/dist/backend-availability.js +13 -5
  17. package/dist/backend-availability.js.map +1 -1
  18. package/dist/channel/mcp-tools.js +1 -1
  19. package/dist/channel/mcp-tools.js.map +1 -1
  20. package/dist/cli.js +4 -6
  21. package/dist/cli.js.map +1 -1
  22. package/dist/daemon.d.ts +40 -0
  23. package/dist/daemon.js +354 -15
  24. package/dist/daemon.js.map +1 -1
  25. package/dist/delivery-consumed-watch.d.ts +23 -1
  26. package/dist/delivery-consumed-watch.js +30 -3
  27. package/dist/delivery-consumed-watch.js.map +1 -1
  28. package/dist/delivery-reconciliation.d.ts +7 -0
  29. package/dist/delivery-reconciliation.js +9 -1
  30. package/dist/delivery-reconciliation.js.map +1 -1
  31. package/dist/fleet-manager.d.ts +33 -7
  32. package/dist/fleet-manager.js +196 -67
  33. package/dist/fleet-manager.js.map +1 -1
  34. package/dist/fleet-yaml-patch.d.ts +3 -0
  35. package/dist/fleet-yaml-patch.js +103 -0
  36. package/dist/fleet-yaml-patch.js.map +1 -0
  37. package/dist/general-knowledge/skills/concepts/SKILL.md +390 -0
  38. package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +3 -1
  39. package/dist/general-knowledge/skills/kiro-engine-migration/SKILL.md +41 -4
  40. package/dist/general-knowledge/skills/model-discovery/SKILL.md +2 -0
  41. package/dist/instance-lifecycle.d.ts +2 -0
  42. package/dist/instance-lifecycle.js +38 -4
  43. package/dist/instance-lifecycle.js.map +1 -1
  44. package/dist/kiro-engine-status.d.ts +11 -0
  45. package/dist/kiro-engine-status.js +6 -0
  46. package/dist/kiro-engine-status.js.map +1 -1
  47. package/dist/kiro-resume-summary.d.ts +37 -0
  48. package/dist/kiro-resume-summary.js +85 -0
  49. package/dist/kiro-resume-summary.js.map +1 -0
  50. package/dist/locale.js +32 -0
  51. package/dist/locale.js.map +1 -1
  52. package/dist/login-controller.js +9 -1
  53. package/dist/login-controller.js.map +1 -1
  54. package/dist/login-flows.d.ts +2 -0
  55. package/dist/login-flows.js +5 -2
  56. package/dist/login-flows.js.map +1 -1
  57. package/dist/needs-you-hub.js +1 -1
  58. package/dist/needs-you-hub.js.map +1 -1
  59. package/dist/needs-you.d.ts +6 -0
  60. package/dist/needs-you.js +8 -2
  61. package/dist/needs-you.js.map +1 -1
  62. package/dist/package-preimage.js +27 -2
  63. package/dist/package-preimage.js.map +1 -1
  64. package/dist/queued-handoffs.d.ts +33 -0
  65. package/dist/queued-handoffs.js +75 -0
  66. package/dist/queued-handoffs.js.map +1 -0
  67. package/dist/reply-buttons-controller.js +10 -0
  68. package/dist/reply-buttons-controller.js.map +1 -1
  69. package/dist/stall-reporter.d.ts +21 -0
  70. package/dist/stall-reporter.js +82 -0
  71. package/dist/stall-reporter.js.map +1 -0
  72. package/dist/tmux-control.d.ts +2 -2
  73. package/dist/tmux-control.js +4 -2
  74. package/dist/tmux-control.js.map +1 -1
  75. package/dist/tmux-exec-helper.d.ts +6 -3
  76. package/dist/tmux-exec-helper.js +115 -53
  77. package/dist/tmux-exec-helper.js.map +1 -1
  78. package/dist/tool-permissions.d.ts +5 -2
  79. package/dist/tool-permissions.js +6 -5
  80. package/dist/tool-permissions.js.map +1 -1
  81. package/dist/tunnel/cloudflared-install.d.ts +4 -0
  82. package/dist/tunnel/cloudflared-install.js +20 -1
  83. package/dist/tunnel/cloudflared-install.js.map +1 -1
  84. package/dist/tunnel/cloudflared.d.ts +8 -1
  85. package/dist/tunnel/cloudflared.js +34 -6
  86. package/dist/tunnel/cloudflared.js.map +1 -1
  87. package/dist/tunnel/lease.d.ts +3 -3
  88. package/dist/tunnel/lease.js +23 -19
  89. package/dist/tunnel/lease.js.map +1 -1
  90. package/dist/tunnel/manager.js +6 -7
  91. package/dist/tunnel/manager.js.map +1 -1
  92. package/dist/ui/panel-needs.js +4 -3
  93. package/dist/ui/shared/app-i18n.js +2 -2
  94. package/dist/ui/shared/app-needs.js +1 -1
  95. package/dist/ui/shared/app.css +16 -1
  96. package/dist/ui/shared/panel-view.js +266 -17
  97. package/dist/ui/shared/view-strings.js +26 -0
  98. package/dist/unattended-install.d.ts +1 -1
  99. package/dist/unattended-install.js +19 -5
  100. package/dist/unattended-install.js.map +1 -1
  101. package/dist/view-api.d.ts +15 -0
  102. package/dist/view-api.js +94 -33
  103. package/dist/view-api.js.map +1 -1
  104. package/dist/web-login.d.ts +4 -3
  105. package/dist/web-login.js +23 -14
  106. package/dist/web-login.js.map +1 -1
  107. package/dist/web-session.d.ts +5 -0
  108. package/dist/web-session.js +20 -8
  109. package/dist/web-session.js.map +1 -1
  110. package/launcher/agend-install.cjs +16 -2
  111. package/package.json +1 -1
@@ -26,7 +26,7 @@ import { viewStore } from "./view-roster-store.js";
26
26
  /** #1580: the app's stream says the fleet is not answering (a restart): the View's polls skip their turn until it is. */
27
27
  const fleetUnreachable = () => appStore.get().connection === "reconnecting";
28
28
  import { navigate } from "./app-nav.js";
29
- import { viewPath } from "./app-route.js";
29
+ import { logPath, sectionPath, viewPath } from "./app-route.js";
30
30
  import { Dialog } from "./ui-dialog.js";
31
31
  import { Empty, ErrorState, Skeleton } from "./ui-states.js";
32
32
  import { Icon } from "./ui-icons.js";
@@ -41,6 +41,44 @@ function tn(key, values = {}) {
41
41
  for (const [k, v] of Object.entries(values)) s = s.split(`{${k}}`).join(String(v));
42
42
  return s;
43
43
  }
44
+ /**
45
+ * v2.3.4-beta.4 P1 (hmsg-985db235, hmsg-5ab1997d): this module is loaded on first use, so a tab opened before an upgrade
46
+ * runs the new View with the stylesheet and the View's words it loaded at its start. Without the View's layout rules
47
+ * (.v-term-box) the terminal box grew with its text: the text shrank every second (fit() measured the box its own text
48
+ * sized), a normal-buffer CLI's View showed its whole history from the top, and new words showed as raw keys. Each is
49
+ * found by a mark the current files carry — VIEW_REV in app.css (the --v-term-rev property) and view-strings.js (the
50
+ * view.rev word) — and a stale one is read again, once per page: the stylesheet re-linked after the one in force, the
51
+ * words imported again (register() replaces them). The query only makes it a new request: /assets/ serves the file.
52
+ */
53
+ export const VIEW_REV = "2";
54
+ const healed = { css: false, words: false };
55
+ export function healStalePage(doc = typeof document !== "undefined" ? document : null, load = (u) => import(u), onWords = () => {}) {
56
+ if (!doc) return { css: false, words: false };
57
+ const out = { css: false, words: false };
58
+ try {
59
+ const box = doc.querySelector && doc.querySelector(".v-term-box");
60
+ // Only a page that has the stylesheet linked (the app; never a test's page without one) and an older one in force.
61
+ const linked = [...(doc.querySelectorAll ? doc.querySelectorAll('link[rel="stylesheet"]') : [])]
62
+ .some((l) => String(l.getAttribute("href") || "").split("?")[0] === "/assets/app.css");
63
+ if (box && linked && !healed.css) {
64
+ const cs = typeof getComputedStyle === "function" ? getComputedStyle(box) : null;
65
+ const rev = cs && typeof cs.getPropertyValue === "function" ? String(cs.getPropertyValue("--v-term-rev")).trim().replace(/^"|"$/g, "") : VIEW_REV;
66
+ if (rev !== VIEW_REV) {
67
+ healed.css = true; out.css = true;
68
+ const link = doc.createElement("link");
69
+ link.setAttribute("rel", "stylesheet"); link.setAttribute("href", `/assets/app.css?rev=${VIEW_REV}-${Date.now().toString(36)}`);
70
+ doc.head.appendChild(link);
71
+ }
72
+ }
73
+ } catch { /* never in the View's way */ }
74
+ if (t("view.rev") !== VIEW_REV && !healed.words) {
75
+ healed.words = true; out.words = true;
76
+ Promise.resolve(load(`./view-strings.js?rev=${VIEW_REV}-${Date.now().toString(36)}`)).then(() => onWords(), () => {});
77
+ }
78
+ return out;
79
+ }
80
+ /** For tests: as on a fresh page. */
81
+ export function resetHealed() { healed.css = false; healed.words = false; }
44
82
  const stored = (k) => { try { return localStorage.getItem(k); } catch { return null; } };
45
83
  const store = (k, v) => { try { localStorage.setItem(k, v); } catch { /* this page only */ } };
46
84
 
@@ -198,8 +236,8 @@ export function ViewPanel({ route, navKey }) {
198
236
  else if (!it) body = html`<div data-trust="panel-content" class="panel-body center"><${Empty} icon="alert" title=${tn("notFound", { name })} hint=${tn("notFoundHint")} /></div>`;
199
237
  else if (guest && !trusted) body = html`<div data-trust="panel-content" class="panel-body center"><${Empty} icon="view" title=${tn("guestNeedsTrusted")} hint=${tn("guestNeedsTrustedHint")} /></div>`;
200
238
  else if (guest) body = html`<p data-trust="panel-content" class="v-watching" role="note">${tn("guestWatching")}</p>
201
- <${Terminal} key=${name} name=${name} lease=${lease} density=${density} every=${GUEST_PANE_MS} />`;
202
- else body = html`<${Terminal} key=${name} name=${name} lease=${lease} density=${density} />
239
+ <${Terminal} key=${name} name=${name} lease=${lease} density=${density} every=${GUEST_PANE_MS} backend=${it.backend || ""} signedIn=${false} />`;
240
+ else body = html`<${Terminal} key=${name} name=${name} lease=${lease} density=${density} backend=${it.backend || ""} signedIn=${!viewOnly} />
203
241
  <${ViewIdentity} it=${it} viewOnly=${viewOnly} onEdit=${() => setDialog("edit")} />`;
204
242
 
205
243
  return html`<div data-effect-panel="view" class="panel p-view">
@@ -214,11 +252,74 @@ export function ViewPanel({ route, navKey }) {
214
252
 
215
253
  /** #2855: how often a guest's View reads the pane (the server allows it two reads a second). */
216
254
  const GUEST_PANE_MS = 1000;
217
- /** The live terminal: the pane every 800 ms (passive), drawn as escaped markup, its font fitted to the pane's grid. */
218
- function Terminal({ name, lease, density, every = 800 }) {
255
+ /**
256
+ * The live terminal: the pane every 800 ms (passive), drawn as escaped markup, its font fitted to the pane's grid.
257
+ *
258
+ * M-2262 (the user, hmsg-435f6df6): scrolling back. Following (the default), it shows the pane's screen as it is now.
259
+ * Scrolling up — the wheel, a touch drag, PageUp/↑/Home, or "Earlier output" — reads the pane's scrollback once
260
+ * (`?history=1`: tmux's history above the screen, bounded) and shows it: reading. While reading, nothing moves the
261
+ * person: the refresh keeps reading the screen only to say "New output below", and never redraws. "Jump to latest"
262
+ * (or End), or scrolling to the bottom, follows again. Everything happens in this page, over text tmux was asked to
263
+ * capture: never copy-mode and never a key to the pane (hmsg-b8a170c0 — scrolling must never affect delivery).
264
+ */
265
+ /** How long a scrollback note stays (it covers the terminal's bottom rows). */
266
+ const NOTE_MS = 6000;
267
+ /** A scroll this soon after the person's own wheel, touch, key or pointer is theirs (not one this page made). */
268
+ const GESTURE_MS = 1000;
269
+ /**
270
+ * #2969 review (Prism P3): is `live` (a screen read) still what `shown` ends with — the screen as it was when reading
271
+ * began (the scrollback's last lines, or the screen itself)? Trailing blank rows are not content.
272
+ */
273
+ export function sameScreen(shown, live) {
274
+ if (shown == null || live == null) return shown === live;
275
+ const trim = (t) => String(t).replace(/\n+$/, "");
276
+ const s = trim(shown).split("\n"), l = trim(live).split("\n");
277
+ return s.length >= l.length && s.slice(s.length - l.length).join("\n") === l.join("\n");
278
+ }
279
+ /** M-2262 survey: CLIs that redraw their whole window (no tmux scrollback even outside the alternate screen). */
280
+ const REDRAWS_IN_PLACE = new Set(["grok"]);
281
+ /** M-2262 survey: the full-screen CLIs (the alternate screen, or redrawn in place) — tmux keeps nothing above their screen. */
282
+ const FULL_SCREEN = new Set(["claude-code", "opencode", "grok"]); // agy: its chat UI unverified — found by the read
283
+ /** The full-screen CLIs whose earlier output the Log tab shows (it reads their transcript: log-service.ts). */
284
+ const LOG_HAS_HISTORY = new Set(["claude-code"]);
285
+ /**
286
+ * M-2267 option (2), the leader's safe default: where a full-screen CLI's earlier output is — its Log tab (or that the
287
+ * Log tab is off, and where to turn it on). Only for whom the Log tab is (a signed-in session on the full app; never a
288
+ * guest or a View-only reader: they get the plain words), and only for a CLI the Log tab reads.
289
+ */
290
+ function logLinkFor(name, backend, signedIn) {
291
+ if (!signedIn || !LOG_HAS_HISTORY.has(backend)) return null;
292
+ const on = typeof document !== "undefined" && document.body?.dataset?.logTab === "1";
293
+ return on ? { href: logPath(name), text: tn("earlierInLog") } : { href: sectionPath("web-dashboard"), text: tn("logTabOff") };
294
+ }
295
+ function Terminal({ name, lease, density, every = 800, backend = "", signedIn = false }) {
219
296
  const term = useRef(null), pre = useRef(null);
220
- const grid = useRef({ cols: 0, rows: 0, applied: 0, key: "" });
297
+ const grid = useRef({ cols: 0, rows: 0, applied: 0, key: "", follows: false });
221
298
  const [problem, setProblem] = useState(null);
299
+ const [, setWordsRev] = useState(0);
300
+ // "follow" | "loading" | "reading"; the screen's text when reading began, the newest read since; a note about history.
301
+ const [mode, setModeState] = useState("follow");
302
+ const modeRef = useRef("follow");
303
+ const setMode = (m) => { modeRef.current = m; setModeState(m); };
304
+ const [newBelow, setNewBelow] = useState(false);
305
+ const [historyNote, setHistoryNoteState] = useState(null);
306
+ // A CLI found to keep no scrollback (full screen): nothing is offered or read again for it; the note says why, briefly.
307
+ const [noScrollback, setNoScrollback] = useState(FULL_SCREEN.has(backend));
308
+ const noScrollbackRef = useRef(FULL_SCREEN.has(backend));
309
+ const logLink = logLinkFor(name, backend, signedIn);
310
+ const noteTimer = useRef(null);
311
+ const setHistoryNote = (note, brief = false) => {
312
+ lease.clear(noteTimer.current); noteTimer.current = null;
313
+ setHistoryNoteState(note);
314
+ if (note && brief) noteTimer.current = lease.timeout(() => setHistoryNoteState(null), NOTE_MS);
315
+ };
316
+ // `reading`: the text shown while reading (the scrollback, or the screen as it was when the person left the bottom);
317
+ // `latest`: the newest screen read; `history`: whether what is shown has the scrollback in it.
318
+ // `drawn` (#2969 review P3): the text actually on the page now — what reading starts from, never a newer read not drawn.
319
+ const screenAt = useRef({ reading: null, latest: null, history: false, drawn: null });
320
+ // #2969 review (Prism P2): when the person last moved the terminal themselves (wheel, touch, key, pointer).
321
+ const gestureAt = useRef(-Infinity);
322
+ const recentGesture = () => performance.now() - gestureAt.current < GESTURE_MS;
222
323
  // #1674: the text size as of this render. The pane refresh and the resize handlers below are set up once per mount
223
324
  // and keep the fit() of that render; reading the size here, not from that render's props, keeps them on the current
224
325
  // choice (they used to put the mount-time size back within one 800 ms refresh).
@@ -236,16 +337,71 @@ function Terminal({ name, lease, density, every = 800 }) {
236
337
  const pcs = getComputedStyle(p);
237
338
  const lh = parseFloat(pcs.lineHeight) / parseFloat(pcs.fontSize);
238
339
  const lineH = Number.isFinite(lh) && lh > 0 ? lh : 1.2;
239
- let size = Math.min(innerW / (g.cols * glyphRatio(p)), innerH / (g.rows * lineH)) * 0.995;
240
- if (density === "fit") size = Math.max(FIT_FLOOR_PX, Math.min(size, MAX_PX));
241
- else size = Math.max(8, Math.min(Math.max(MIN_PX, Math.min(size, MAX_PX)) * (VIEW_SCALE[density] || 1), 32));
340
+ const byW = innerW / (g.cols * glyphRatio(p)), byH = innerH / (g.rows * lineH);
341
+ const sizeFor = (limit) => (density === "fit" ? Math.max(FIT_FLOOR_PX, Math.min(limit * 0.995, MAX_PX))
342
+ : Math.max(8, Math.min(Math.max(MIN_PX, Math.min(limit * 0.995, MAX_PX)) * (VIEW_SCALE[density] || 1), 32)));
343
+ const size = sizeFor(g.follows ? byW : Math.min(byW, byH));
242
344
  g.key = key;
243
345
  // A small change is skipped only when growing (the size applied still fits); a smaller box always shrinks it.
244
346
  if (size >= g.applied && size - g.applied < 0.75) return;
245
- g.applied = size;
246
- p.style.fontSize = `${size.toFixed(2)}px`; // CSSOM, never a style attribute (#1300)
347
+ const padH = (parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom)) || 0;
348
+ const was = g.applied || parseFloat(pcs.fontSize) || 0, before = box.clientHeight - padH;
349
+ const apply = (px) => { g.applied = px; p.style.fontSize = `${px.toFixed(2)}px`; }; // CSSOM, never a style attribute (#1300)
350
+ apply(size);
351
+ // v2.3.4-beta.4 P1: the box's height is a limit only while it is the box's own. Read again right after the text took
352
+ // its new size (the read lays the page out), a box whose height moved with it, by the same factor, is following its
353
+ // text — a stale stylesheet, or any container that grows with its content: measured next time it would shrink the
354
+ // text 0.5% each refresh, for ever. Then the width alone decides, at once and from then on (until the choice or the
355
+ // stylesheet changes). Cause and effect within this one call: a resize between calls (#2991 review: the box made
356
+ // shorter step by step, where a height-limited size moves in proportion too) never counts. The move must match the
357
+ // expected one closely for its size (#2991 review r2: not ±5% of the whole), and a second probe in the same call —
358
+ // 10% smaller, then back, before any frame is painted — must move it in proportion again: a one-off fixed drop (a
359
+ // scrollbar coming) never does.
360
+ if (!g.follows && was > 0 && before > 0) {
361
+ const height = () => box.clientHeight - padH;
362
+ const moves = (from, to, ratio) => {
363
+ const expect = from * (ratio - 1), got = to - from;
364
+ return got !== 0 && Math.sign(got) === Math.sign(expect) && Math.abs(got - expect) <= Math.max(1.5, 0.25 * Math.abs(expect));
365
+ };
366
+ const after = height();
367
+ if (moves(before, after, size / was)) {
368
+ p.style.fontSize = `${(size * 0.9).toFixed(2)}px`;
369
+ const probed = height();
370
+ p.style.fontSize = `${size.toFixed(2)}px`;
371
+ if (moves(after, probed, 0.9)) {
372
+ g.follows = true;
373
+ const byWidth = sizeFor(byW);
374
+ if (byWidth !== size) apply(byWidth);
375
+ }
376
+ }
377
+ }
378
+ };
379
+ /** Keep a following view on the newest line (a grid taller than the box at the larger sizes scrolls). */
380
+ const toBottom = () => { const box = term.current; if (box) box.scrollTop = box.scrollHeight; };
381
+ const draw = (text) => {
382
+ pre.current.innerHTML = ansiToHtml(text); // escaped by construction: markup only from ansiToHtml's own spans
383
+ paintAnsi(pre.current);
384
+ screenAt.current.drawn = text;
247
385
  };
248
- useEffect(() => { grid.current.key = ""; fit(); }, [density]);
386
+ useEffect(() => { grid.current.key = ""; grid.current.follows = false; fit(); }, [density]);
387
+ // A tab opened before an upgrade: its stylesheet and the View's words read again (healStalePage), then fitted anew.
388
+ useEffect(() => {
389
+ const h = healStalePage(document, (u) => import(u), () => { setWordsRev((n) => n + 1); });
390
+ if (h.css) lease.timeout(() => { grid.current.key = ""; grid.current.follows = false; fit(); }, 300);
391
+ }, []);
392
+ const atBottom = () => { const box = term.current; return !box || box.scrollHeight - box.scrollTop - box.clientHeight <= 2; };
393
+ /** Reading what is shown now (`text`, with or without the scrollback): the refresh only says whether there is more. */
394
+ const startReading = (text, history) => {
395
+ screenAt.current.reading = text; screenAt.current.history = history;
396
+ setNewBelow(false); setMode("reading");
397
+ };
398
+ const grid1 = (r) => {
399
+ const c = Number(r.headers.get("X-Pane-Cols")), rw = Number(r.headers.get("X-Pane-Rows"));
400
+ if (c >= 1 && rw >= 1 && (c !== grid.current.cols || rw !== grid.current.rows)) { grid.current.cols = c; grid.current.rows = rw; grid.current.key = ""; }
401
+ };
402
+ // The person asked for what scrolled off: one bounded read, then reading (or why there is nothing to read).
403
+ const loadEarlier = useRef(null);
404
+ const follow = useRef(null);
249
405
  useEffect(() => {
250
406
  const reads = readStream(lease);
251
407
  const refresh = async () => {
@@ -263,15 +419,72 @@ function Terminal({ name, lease, density, every = 800 }) {
263
419
  if (!r.ok) { setProblem(r.status === 404 ? tn("paneUnavailable") : r.status === 403 && guestPage() ? tn("guestNeedsTrusted") : tn("paneFailed", { name, status: r.status })); return; }
264
420
  const text = await r.text();
265
421
  if (!reads.live(token) || !pre.current) return;
266
- const c = Number(r.headers.get("X-Pane-Cols")), rw = Number(r.headers.get("X-Pane-Rows"));
267
- if (c >= 1 && rw >= 1 && (c !== grid.current.cols || rw !== grid.current.rows)) { grid.current.cols = c; grid.current.rows = rw; grid.current.key = ""; }
268
422
  setProblem(null);
269
- pre.current.innerHTML = ansiToHtml(text); // escaped by construction: markup only from ansiToHtml's own spans
270
- paintAnsi(pre.current);
423
+ screenAt.current.latest = text;
424
+ // Reading earlier output: nothing is redrawn under the person — the read only says whether there is more.
425
+ if (modeRef.current !== "follow") { if (modeRef.current === "reading") setNewBelow(!sameScreen(screenAt.current.reading, text)); return; }
426
+ // #2969 review (Prism P2): the person is moving a screen taller than its box away from the bottom right now —
427
+ // this is them leaving it, not the latest to follow: read on, nothing redrawn.
428
+ // Reading starts from what is drawn; this newer read (not drawn) is then the new output below.
429
+ if (recentGesture() && !atBottom()) { startReading(screenAt.current.drawn, false); setNewBelow(!sameScreen(screenAt.current.drawn, text)); return; }
430
+ grid1(r);
431
+ draw(text);
271
432
  fit();
433
+ toBottom();
272
434
  } catch { /* a transient error keeps the last frame */ }
273
435
  finally { reads.end(token); }
274
436
  };
437
+ loadEarlier.current = async () => {
438
+ // From following, or from reading what was on the screen (the person reached its top): never twice, never over it.
439
+ const from = modeRef.current;
440
+ if (from !== "follow" && !(from === "reading" && !screenAt.current.history)) return;
441
+ if (noScrollbackRef.current) { setHistoryNote(tn("noEarlier"), true); return; } // known: nothing to read
442
+ const box0 = term.current;
443
+ // Where the person is, measured from the end: the screen's lines stay where they are under the scrollback added.
444
+ const fromEnd = box0 ? box0.scrollHeight - box0.scrollTop : 0;
445
+ const back = () => { setMode(from); if (from === "follow") toBottom(); };
446
+ setMode("loading"); setHistoryNote(tn("loadingEarlier"));
447
+ try {
448
+ const r = await lease.fetch(`/api/pane/${encodeURIComponent(name)}?history=1`);
449
+ if (!lease.current() || modeRef.current !== "loading") return;
450
+ // #2969 review (Prism P2): a scrollback read that failed — or answered without its facts — changes nothing shown.
451
+ if (!r.ok || r.headers.get("X-Pane-History-Lines") == null) { back(); setHistoryNote(r.status === 429 ? null : tn("earlierFailed"), true); return; }
452
+ const text = await r.text();
453
+ if (!lease.current() || modeRef.current !== "loading" || !pre.current) return;
454
+ // A full-screen CLI (the alternate screen, or one that redraws its whole window) leaves nothing above its screen;
455
+ // any other with no history yet has simply not scrolled: say which, keep following.
456
+ if (r.headers.get("X-Pane-Alternate") === "1" || REDRAWS_IN_PLACE.has(backend)) {
457
+ noScrollbackRef.current = true; setNoScrollback(true);
458
+ back(); setHistoryNote(tn("noEarlier"), true); return;
459
+ }
460
+ if (r.headers.get("X-Pane-History-Lines") === "0") { back(); setHistoryNote(tn("nothingEarlier"), true); return; }
461
+ grid1(r);
462
+ const lines = text.split("\n").length, rows = grid.current.rows || 0;
463
+ // #2969 review (Prism P3): new output is judged against what is shown — the scrollback's own last screen — and
464
+ // a screen read while this one was out already counts.
465
+ screenAt.current.reading = text; screenAt.current.history = true;
466
+ setNewBelow(screenAt.current.latest != null && !sameScreen(text, screenAt.current.latest));
467
+ setMode("reading"); setHistoryNote(null);
468
+ draw(text);
469
+ fit();
470
+ const box = term.current;
471
+ if (box) {
472
+ const lineH = lines > 0 ? pre.current.scrollHeight / lines : 16;
473
+ // From following (at the bottom): a few lines up — the earlier output right above. From reading: the same lines.
474
+ box.scrollTop = from === "follow"
475
+ ? Math.max(0, box.scrollHeight - box.clientHeight - lineH * Math.min(3, Math.max(1, lines - rows)))
476
+ : Math.max(0, box.scrollHeight - fromEnd);
477
+ }
478
+ } catch { if (lease.current()) { back(); setHistoryNote(tn("earlierFailed"), true); } }
479
+ };
480
+ follow.current = () => {
481
+ if (modeRef.current === "follow") return;
482
+ setMode("follow"); setNewBelow(false); setHistoryNote(null); screenAt.current.history = false;
483
+ const latest = screenAt.current.latest;
484
+ if (latest != null && pre.current) { draw(latest); fit(); }
485
+ toBottom();
486
+ refresh();
487
+ };
275
488
  refresh();
276
489
  lease.interval(refresh, every);
277
490
  let timer = null;
@@ -282,8 +495,44 @@ function Terminal({ name, lease, density, every = 800 }) {
282
495
  ro.observe(term.current);
283
496
  lease.hold(() => ro.disconnect());
284
497
  }
498
+ // Scrolling up asks for the earlier output; reaching the bottom while reading follows again.
499
+ const box = term.current;
500
+ if (box) {
501
+ // Asking for the earlier output: from following, or from reading the screen as it was — at the top.
502
+ const mayLoad = () => (modeRef.current === "follow" || (modeRef.current === "reading" && !screenAt.current.history)) && box.scrollTop <= 0;
503
+ const gesture = () => { gestureAt.current = performance.now(); };
504
+ lease.on(box, "wheel", (e) => { gesture(); if (e.deltaY < 0 && mayLoad()) loadEarlier.current(); }, { passive: true });
505
+ let touchY = null;
506
+ lease.on(box, "touchstart", (e) => { gesture(); touchY = e.touches && e.touches[0] ? e.touches[0].clientY : null; }, { passive: true });
507
+ lease.on(box, "touchmove", (e) => {
508
+ gesture();
509
+ const y = e.touches && e.touches[0] ? e.touches[0].clientY : null;
510
+ if (touchY == null || y == null) return;
511
+ if (y - touchY > 24 && mayLoad()) { touchY = null; loadEarlier.current(); }
512
+ }, { passive: true });
513
+ lease.on(box, "pointerdown", gesture, { passive: true }); // the scrollbar, dragged
514
+ lease.on(box, "keydown", (e) => {
515
+ gesture();
516
+ if ((e.key === "PageUp" || e.key === "ArrowUp" || e.key === "Home") && mayLoad()) { e.preventDefault(); loadEarlier.current(); }
517
+ else if (modeRef.current === "reading" && e.key === "End") { e.preventDefault(); follow.current(); }
518
+ });
519
+ lease.on(box, "scroll", () => {
520
+ if (modeRef.current === "reading") { if (atBottom()) follow.current(); return; }
521
+ // #2969 review (Prism P2): a screen taller than its box (a larger Aa), moved up from the bottom by the person:
522
+ // reading what is on it — the refresh no longer pulls them back down.
523
+ if (modeRef.current === "follow" && recentGesture() && !atBottom()) startReading(screenAt.current.drawn, false);
524
+ }, { passive: true });
525
+ }
285
526
  }, [lease, name]);
286
- return html`<div data-trust="panel-content" class="v-term" ref=${term}>${problem ? html`<p class="v-term-note" role="status">${problem}</p>` : null}<pre ref=${pre} class="v-pre"></pre></div>`;
527
+ const reading = mode === "reading";
528
+ // A full-screen CLI's Log link is a bar above the terminal, not over it: its first row is never covered.
529
+ return html`<div class="v-term-box">
530
+ ${noScrollback && logLink ? html`<p class="v-term-logbar"><a class="v-term-log" href=${logLink.href}>${logLink.text}<${Icon} name="forward" size=${14} /></a></p>` : null}
531
+ <div data-trust="panel-content" class=${`v-term${reading ? " is-reading" : ""}`} ref=${term} tabindex="0" aria-label=${tn(reading ? "readingEarlier" : "earlierHint")}>${problem ? html`<p class="v-term-note" role="status">${problem}</p>` : null}<pre ref=${pre} class="v-pre"></pre></div>
532
+ ${historyNote ? html`<p class="v-term-history-note" role="status">${historyNote}</p>` : null}
533
+ ${mode === "follow" && !noScrollback ? html`<button type="button" class="v-term-earlier btn btn-sm" title=${tn("earlierHint")} onClick=${() => loadEarlier.current && loadEarlier.current()}><${Icon} name="up" size=${14} />${tn("earlier")}</button>` : null}
534
+ ${reading ? html`<button type="button" class=${`v-term-latest btn btn-sm${newBelow ? " has-new" : ""}`} onClick=${() => follow.current && follow.current()}>${newBelow ? html`<span class="v-term-new">${tn("newBelow")} · </span>` : null}${tn("jumpLatest")}<${Icon} name="down" size=${14} /></button>` : null}
535
+ </div>`;
287
536
  }
288
537
 
289
538
  // The advance of one monospace cell as a fraction of font-size, measured once on this page.
@@ -215,6 +215,20 @@ register("view", {
215
215
  "guestNeedsTrustedHint": "Your host gave you chat access to this agent. Ask them to make you Trusted in Settings → Guests.",
216
216
  "noInstances": "No instances yet",
217
217
  "paneUnavailable": "This instance's terminal is not available (is it stopped?)",
218
+ // M-2262: the terminal's scrollback.
219
+ "earlier": "Earlier output",
220
+ "earlierHint": "Scroll up to read what has scrolled off. Live output keeps coming in below.",
221
+ "loadingEarlier": "Loading earlier output…",
222
+ "earlierFailed": "Could not load earlier output.",
223
+ "noEarlier": "This CLI redraws its whole screen, so the terminal keeps no earlier output to scroll back to.",
224
+ "nothingEarlier": "Nothing has scrolled off the screen yet.",
225
+ // The words' mark (panel-view.js VIEW_REV, the same in both languages): a tab with older words reads these again.
226
+ "rev": "2",
227
+ "earlierInLog": "Earlier output is in the Log tab",
228
+ "logTabOff": "Earlier output: the Log tab is off. Turn it on in Settings",
229
+ "readingEarlier": "Reading earlier output. Live output continues; scroll to the bottom to follow it again.",
230
+ "jumpLatest": "Jump to latest",
231
+ "newBelow": "New output below",
218
232
  "rosterFailedShort": "The instance list could not be loaded.",
219
233
  "collapseGroup": "Fold {group}",
220
234
  "expandGroup": "Open {group}",
@@ -461,6 +475,18 @@ register("view", {
461
475
  "guestNeedsTrustedHint": "主人給你的是這個 agent 的聊天權限。請他在設定 → 訪客把你改成「信任」。",
462
476
  "noInstances": "還沒有 instance",
463
477
  "paneUnavailable": "無法取得這個 instance 的終端畫面(它是否已停止?)",
478
+ "earlier": "較早的輸出",
479
+ "earlierHint": "往上捲動可以看到已經捲走的內容,新的輸出會繼續出現在下方。",
480
+ "loadingEarlier": "正在載入較早的輸出…",
481
+ "earlierFailed": "無法載入較早的輸出。",
482
+ "noEarlier": "這個 CLI 會重繪整個畫面,終端沒有保留可以往上捲動的較早輸出。",
483
+ "nothingEarlier": "還沒有內容捲出畫面。",
484
+ "rev": "2",
485
+ "earlierInLog": "較早的輸出在「紀錄」分頁",
486
+ "logTabOff": "較早的輸出:「紀錄」分頁目前關閉,請到設定開啟",
487
+ "readingEarlier": "正在看較早的輸出。新的輸出仍會繼續;捲到最下面即可再次跟著最新內容。",
488
+ "jumpLatest": "跳到最新",
489
+ "newBelow": "下方有新的輸出",
464
490
  "rosterFailedShort": "無法載入 instance 清單。",
465
491
  "collapseGroup": "收合 {group}",
466
492
  "expandGroup": "展開 {group}",
@@ -1,6 +1,6 @@
1
1
  /** Runs `$1` detached from any terminal, at low priority; HUP/INT/TERM on this shell reach its whole process group. */
2
2
  export declare const UNATTENDED_INSTALL_SCRIPT: string;
3
3
  /** The account's login shell, when it is an absolute path to an executable; else undefined (keep the inherited one). */
4
- export declare function loginShell(read?: () => string | null | undefined): string | undefined;
4
+ export declare function loginShell(read?: () => string | null | undefined): Promise<string | undefined>;
5
5
  /** The window's command for an install command. `shell`: the $SHELL to give it; null keeps the inherited one. */
6
6
  export declare function unattendedInstallCommand(command: string, shell?: string | null): string;
@@ -19,10 +19,10 @@
19
19
  *
20
20
  * The exit code is the install's own: the session judges success by it.
21
21
  */
22
- import { accessSync, constants as fsConstants } from "node:fs";
23
22
  import { userInfo } from "node:os";
24
23
  import { isAbsolute } from "node:path";
25
24
  import { shellQuote } from "./backend/types.js";
25
+ import { spawnProbeCommand, PROBE_DEADLINE_MS } from "./binary-probe.js";
26
26
  /** Runs `$1` detached from any terminal, at low priority; HUP/INT/TERM on this shell reach its whole process group. */
27
27
  export const UNATTENDED_INSTALL_SCRIPT = [
28
28
  // In a tmux pane, start only once AgEnD has set remain-on-exit on the window (at most ~10 s): an install that fails
@@ -39,7 +39,7 @@ export const UNATTENDED_INSTALL_SCRIPT = [
39
39
  'wait "$pid"',
40
40
  ].join("\n");
41
41
  /** The account's login shell, when it is an absolute path to an executable; else undefined (keep the inherited one). */
42
- export function loginShell(read = () => userInfo().shell) {
42
+ export async function loginShell(read = () => userInfo().shell) {
43
43
  let shell;
44
44
  try {
45
45
  shell = read();
@@ -49,16 +49,30 @@ export function loginShell(read = () => userInfo().shell) {
49
49
  }
50
50
  if (!shell || !isAbsolute(shell))
51
51
  return undefined;
52
+ // Child `sh` `[ -f && -x ]`, same as resolveBackendBinary's install-dir probe: an accessSync on a dead mount
53
+ // can hang a pool thread forever (#3009); a child can be killed (binary-probe.ts).
54
+ const child = spawnProbeCommand("sh", ["-c", '[ -f "$1" ] && [ -x "$1" ] && echo "$1"', "sh", shell]);
55
+ let timer;
52
56
  try {
53
- accessSync(shell, fsConstants.X_OK);
54
- return shell;
57
+ const found = await Promise.race([
58
+ child.answer,
59
+ new Promise((r) => {
60
+ timer = setTimeout(() => { child.kill(); r(undefined); }, PROBE_DEADLINE_MS);
61
+ timer.unref?.();
62
+ }),
63
+ ]);
64
+ return found ?? undefined;
55
65
  }
56
66
  catch {
57
67
  return undefined;
58
68
  }
69
+ finally {
70
+ if (timer)
71
+ clearTimeout(timer);
72
+ }
59
73
  }
60
74
  /** The window's command for an install command. `shell`: the $SHELL to give it; null keeps the inherited one. */
61
- export function unattendedInstallCommand(command, shell = loginShell() ?? null) {
75
+ export function unattendedInstallCommand(command, shell = null) {
62
76
  const env = shell ? `SHELL=${shellQuote(shell)} ` : "";
63
77
  return `${env}sh -c ${shellQuote(UNATTENDED_INSTALL_SCRIPT)} agend-install ${shellQuote(command)}`;
64
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unattended-install.js","sourceRoot":"","sources":["../src/unattended-install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,uHAAuH;AACvH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,oHAAoH;IACpH,qHAAqH;IACrH,oFAAoF;IACpF,uNAAuN;IACvN,MAAM;IACN,0GAA0G;IAC1G,0IAA0I;IAC1I,QAAQ;IACR,uHAAuH;IACvH,uDAAuD;IACvD,2FAA2F;IAC3F,aAAa;CACd,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,wHAAwH;AACxH,MAAM,UAAU,UAAU,CAAC,IAAI,GAAoC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK;IACvF,IAAI,KAAgC,CAAC;IACrC,IAAI,CAAC;QAAC,KAAK,GAAG,IAAI,EAAE,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;IACnD,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,IAAI,CAAC;QAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AACxF,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,wBAAwB,CAAC,OAAe,EAAE,KAAK,GAAkB,UAAU,EAAE,IAAI,IAAI;IACnG,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACvD,OAAO,GAAG,GAAG,SAAS,UAAU,CAAC,yBAAyB,CAAC,kBAAkB,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;AACrG,CAAC"}
1
+ {"version":3,"file":"unattended-install.js","sourceRoot":"","sources":["../src/unattended-install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,uHAAuH;AACvH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,oHAAoH;IACpH,qHAAqH;IACrH,oFAAoF;IACpF,uNAAuN;IACvN,MAAM;IACN,0GAA0G;IAC1G,0IAA0I;IAC1I,QAAQ;IACR,uHAAuH;IACvH,uDAAuD;IACvD,2FAA2F;IAC3F,aAAa;CACd,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,wHAAwH;AACxH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAI,GAAoC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK;IAC7F,IAAI,KAAgC,CAAC;IACrC,IAAI,CAAC;QAAC,KAAK,GAAG,IAAI,EAAE,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;IACnD,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,6GAA6G;IAC7G,mFAAmF;IACnF,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,yCAAyC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACtG,IAAI,KAAgD,CAAC;IACrD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YAC/B,KAAK,CAAC,MAAM;YACZ,IAAI,OAAO,CAAY,CAAC,CAAC,EAAE,EAAE;gBAC3B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;gBAC7E,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAClB,CAAC,CAAC;SACH,CAAC,CAAC;QACH,OAAO,KAAK,IAAI,SAAS,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,wBAAwB,CAAC,OAAe,EAAE,KAAK,GAAkB,IAAI;IACnF,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACvD,OAAO,GAAG,GAAG,SAAS,UAAU,CAAC,yBAAyB,CAAC,kBAAkB,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;AACrG,CAAC"}
@@ -137,11 +137,26 @@ export declare function cardPicture(ctx: {
137
137
  export declare function humanCards(dataDir: string): ReturnType<typeof HumanCardStore.all>;
138
138
  /** For tests: forget the guests' read counts and shared captures. */
139
139
  export declare function resetGuestPanes(): void;
140
+ /**
141
+ * M-2262 (the user, hmsg-435f6df6): the View's scrollback — the pane's history above its screen, read only when the
142
+ * person scrolls up (never on the 800 ms refresh), at most `lines` lines (tmux's own default history-limit) and at most
143
+ * `maxBytes` (its end, from a whole line). A viewer's tabs asking at once share one read.
144
+ */
145
+ export declare const VIEW_HISTORY: {
146
+ readonly lines: 2000;
147
+ readonly maxBytes: number;
148
+ };
140
149
  /** A pane's logical grid size in cells, as tmux sees it. */
141
150
  export interface PaneSize {
142
151
  cols: number;
143
152
  rows: number;
144
153
  }
154
+ /** M-2262: whether the pane shows its alternate screen, and how many lines tmux keeps above it. */
155
+ export interface PaneScrollback {
156
+ alternate: boolean;
157
+ lines: number;
158
+ }
159
+ export declare function parsePaneScrollback(alternate: string | undefined, lines: string | undefined): PaneScrollback | null;
145
160
  /** Parse `display-message`'s `<cols>x<rows>` output. Returns null if unusable. */
146
161
  export declare function parsePaneSize(out: string): PaneSize | null;
147
162
  /** True if the path belongs to the view feature (so the caller can skip the