Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: show a running agent's newest output instead of its first 80 blocks

[._.]/ Adam Eivye716f432e2b0
diff --git a/client/src/components/cos/OutputBlocks.jsx b/client/src/components/cos/OutputBlocks.jsx
index 166ae0e1a0..0e9293756b 100644
--- a/client/src/components/cos/OutputBlocks.jsx
+++ b/client/src/components/cos/OutputBlocks.jsx
@@ -36,9 +36,19 @@ function renderBlock(block, i, linkifyText) {
return <MarkdownOutput key={i} content={block.content} linkifyText={linkifyText} preserveLineBreaks />;
}
+const PAGE_BUTTON_CLASS = 'w-full py-2 text-xs text-port-accent hover:text-white bg-port-border/30 hover:bg-port-border/50 rounded transition-colors min-h-[40px]';
+
// `linkifyText` is forwarded to MarkdownOutput so a caller that knows the
// record (a CoS run and its tracker) can link the bare `#7640` in its prose.
-export default function OutputBlocks({ output, linkifyText = null }) {
+//
+// `anchor` picks which end of a long transcript the bounded window shows.
+// `head` (finished transcripts) pages forward from the start. `tail` is for a
+// RUNNING agent, whose caller feeds a sliding buffer that appends at the end
+// and drops from the front: a head window stopped changing after the first
+// page and hid every new line under "Show more", so a working agent read as
+// stalled (#12028). The tail window always holds the newest blocks and pages
+// backwards with "Show earlier".
+export default function OutputBlocks({ output, linkifyText = null, anchor = 'head' }) {
const [visibleCount, setVisibleCount] = useState(INITIAL_BLOCKS);
// Group consecutive lines: tool lines render as monospace, lifecycle markers
@@ -72,16 +82,25 @@ export default function OutputBlocks({ output, linkifyText = null }) {
}, [output]);
const hasMore = blocks.length > visibleCount;
+ const tail = anchor === 'tail';
+ const start = tail && hasMore ? blocks.length - visibleCount : 0;
+ const visible = tail ? blocks.slice(start) : blocks.slice(0, visibleCount);
+ const hidden = blocks.length - visible.length;
+ const revealMore = () => setVisibleCount(prev => prev + LOAD_MORE_BLOCKS);
return (
<div className="space-y-0.5 min-w-0 overflow-hidden">
- {blocks.slice(0, visibleCount).map((block, i) => renderBlock(block, i, linkifyText))}
- {hasMore && (
- <button
- onClick={() => setVisibleCount(prev => prev + LOAD_MORE_BLOCKS)}
- className="w-full py-2 text-xs text-port-accent hover:text-white bg-port-border/30 hover:bg-port-border/50 rounded transition-colors min-h-[40px]"
- >
- Show more ({blocks.length - visibleCount} remaining)
+ {tail && hasMore && (
+ <button type="button" onClick={revealMore} className={PAGE_BUTTON_CLASS}>
+ Show earlier ({hidden})
+ </button>
+ )}
+ {/* Keyed by absolute block index so a sliding tail window keeps each
+ block's element rather than remounting the whole page per line. */}
+ {visible.map((block, i) => renderBlock(block, start + i, linkifyText))}
+ {!tail && hasMore && (
+ <button type="button" onClick={revealMore} className={PAGE_BUTTON_CLASS}>
+ Show more ({hidden} remaining)
</button>
)}
</div>
diff --git a/client/src/components/cos/OutputBlocks.test.jsx b/client/src/components/cos/OutputBlocks.test.jsx
new file mode 100644
index 0000000000..0ed49f241b
--- /dev/null
+++ b/client/src/components/cos/OutputBlocks.test.jsx
@@ -0,0 +1,43 @@
+import { describe, expect, it } from 'vitest';
+import { fireEvent, render, screen } from '@testing-library/react';
+import OutputBlocks from './OutputBlocks';
+
+// Tool lines render one block each, so block counts equal line counts here.
+const toolLines = (count, from = 0) => Array.from({ length: count }, (_, i) => ({ line: `🔧 step ${from + i}` }));
+
+describe('OutputBlocks paging windows', () => {
+ it('shows a live transcript tail-first and pages backwards', () => {
+ const { rerender } = render(<OutputBlocks output={toolLines(200)} anchor="tail" />);
+
+ expect(screen.getByText('🔧 step 199')).toBeInTheDocument();
+ expect(screen.getByText('🔧 step 120')).toBeInTheDocument();
+ expect(screen.queryByText('🔧 step 119')).not.toBeInTheDocument();
+ expect(screen.queryByText(/Show more/)).not.toBeInTheDocument();
+
+ // A line the agent writes now lands in view; the window slides, not freezes.
+ rerender(<OutputBlocks output={[...toolLines(200), { line: '🔧 step 200' }]} anchor="tail" />);
+ expect(screen.getByText('🔧 step 200')).toBeInTheDocument();
+ expect(screen.queryByText('🔧 step 120')).not.toBeInTheDocument();
+
+ // Paging backwards grows the window by a page; the tail stays in view.
+ fireEvent.click(screen.getByRole('button', { name: 'Show earlier (121)' }));
+ expect(screen.getByText('🔧 step 1')).toBeInTheDocument();
+ expect(screen.getByText('🔧 step 200')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Show earlier (1)' }));
+ expect(screen.getByText('🔧 step 0')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: /Show earlier/ })).not.toBeInTheDocument();
+ });
+
+ it('keeps finished transcripts head-first with forward paging', () => {
+ render(<OutputBlocks output={toolLines(200)} />);
+
+ expect(screen.getByText('🔧 step 0')).toBeInTheDocument();
+ expect(screen.getByText('🔧 step 79')).toBeInTheDocument();
+ expect(screen.queryByText('🔧 step 80')).not.toBeInTheDocument();
+ expect(screen.queryByText(/Show earlier/)).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Show more (120 remaining)' }));
+ expect(screen.getByText('🔧 step 199')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: /Show more/ })).not.toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/cos/tabs/AgentCard.jsx b/client/src/components/cos/tabs/AgentCard.jsx
index 53d1d33735..c4d196ada4 100644
--- a/client/src/components/cos/tabs/AgentCard.jsx
+++ b/client/src/components/cos/tabs/AgentCard.jsx
@@ -38,6 +38,7 @@ import { DEFAULT_REVIEWER, normalizeReviewers } from '../constants';
import { formatBytes, formatCount, formatDurationMs, formatDateTime, formatTimeOfDay, shortClaudeModelName } from '../../../utils/formatters';
import { useSocketResource } from '../../../hooks/useSocketResource';
import { useTimeTick } from '../../../hooks/useTimeTick';
+import useStickToBottom from '../../../hooks/useStickToBottom';
import ConfirmButtonPair from '../../ui/ConfirmButtonPair';
import { useConfirmDelete } from '../../../hooks/useConfirmDelete';
@@ -622,6 +623,11 @@ export default function AgentCard({ agent, onPause, onKill, onDelete, onResume,
? (fullOutput?.lines || agent.output || [])
: (liveOutput || agent.output || [])
), [inactive, fullOutput, liveOutput, agent.output]);
+ // Live output renders tail-first (see OutputBlocks `anchor`), so the panel
+ // follows the newest line until the reader scrolls up. The array identity is
+ // the revision: the live buffer is capped, so its length stops moving.
+ const outputPanelRef = useRef(null);
+ useStickToBottom(outputPanelRef, { enabled: expanded && !inactive, revision: output });
const taskSummary = completed && (fullMetadata && Object.hasOwn(fullMetadata, 'taskSummary')
? fullMetadata.taskSummary : agent.metadata?.taskSummary);
const lastOutput = output.length > 0 ? output[output.length - 1]?.line : null;
@@ -1290,7 +1296,7 @@ export default function AgentCard({ agent, onPause, onKill, onDelete, onResume,
{/* Expanded output view */}
{expanded && (
- <div className="border-t border-port-border bg-port-bg/50 p-3 min-w-0 overflow-y-auto max-h-dvh-cap [--dvh-cap:60dvh]">
+ <div ref={outputPanelRef} className="border-t border-port-border bg-port-bg/50 p-3 min-w-0 overflow-y-auto max-h-dvh-cap [--dvh-cap:60dvh]">
{taskSummary && (
<div className="mt-2 bg-port-bg/50 border border-port-border/50 rounded p-2.5">
<div className="text-[11px] text-gray-500 mb-1 flex items-center gap-1">
@@ -1397,7 +1403,7 @@ export default function AgentCard({ agent, onPause, onKill, onDelete, onResume,
return (
<>
{truncated && <TranscriptTruncationNotice transcript={fullOutput} />}
- {output.length > 0 && <OutputBlocks output={output} linkifyText={linkifyIssues} />}
+ {output.length > 0 && <OutputBlocks output={output} linkifyText={linkifyIssues} anchor={inactive ? 'head' : 'tail'} />}
</>
);
}
diff --git a/client/src/components/cos/tabs/AgentCard.test.jsx b/client/src/components/cos/tabs/AgentCard.test.jsx
index 4d7649a80d..ae80088336 100644
--- a/client/src/components/cos/tabs/AgentCard.test.jsx
+++ b/client/src/components/cos/tabs/AgentCard.test.jsx
@@ -132,6 +132,31 @@ describe('AgentCard runtime presentation', () => {
intervalSpy.mockRestore();
});
+ // A running agent's panel is fed a sliding buffer, so it must show the newest
+ // lines and page backwards; a finished transcript keeps head-first paging
+ // (#12028).
+ it('windows live output from the tail and finished transcripts from the head', async () => {
+ const toolLines = (count) => Array.from({ length: count }, (_, i) => ({ line: `🔧 step ${i}` }));
+ const { unmount } = render(
+ <MemoryRouter>
+ <AgentCard agent={runningAt(30_000)} liveOutput={toolLines(200)} initiallyExpanded />
+ </MemoryRouter>
+ );
+ // The newest line also appears in the card's one-line "last output"
+ // preview, hence getAll.
+ expect(screen.getAllByText('🔧 step 199').length).toBeGreaterThan(0);
+ expect(screen.queryByText('🔧 step 0')).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Show earlier (120)' })).toBeInTheDocument();
+ unmount();
+
+ api.getCosAgent.mockResolvedValue({ ...agent, output: toolLines(200) });
+ render(<MemoryRouter><AgentCard agent={agent} completed initiallyExpanded /></MemoryRouter>);
+ await userEvent.setup().click(screen.getByRole('button', { name: 'Show full transcript' }));
+ expect(await screen.findByText('🔧 step 0')).toBeInTheDocument();
+ expect(screen.queryByText('🔧 step 199')).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Show more (120 remaining)' })).toBeInTheDocument();
+ });
+
// The run this card is for, and the execution-scoped history that describes it
// (#8001). Same task type as `durationHistory` above, but four times slower —
// so a card that fell back to the task-type average would show the wrong ETA.
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index f043125976..1441058f67 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -153,6 +153,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `usePersistedOptions` | Registry for "saved default + per-run override" form options: one spec row per option (`{ defaultValue, read, clamp, persistOnEdit }`) owns the state, per-field dirty flag, hydrate-if-untouched pass and edited-only override collection. Returns `{ values, edit, hydrate, collectOverrides, inputProps }`, all identity-stable and ref-backed so a caller's `useCallback` needs one dep instead of one per option. | Any panel where each option must load a saved default, persist edits, and send ONLY edited fields as per-run overrides (AutopilotPanel) — use this instead of hand-copying the state/editedRef/hydrate/collect scaffold per option. |
| `usePopoverPosition` | Viewport-clamped `{ left, top, width }` for a fixed-position portal popover anchored to a trigger; re-measures on open and rAF-coalesced on capture-phase scroll/resize. Returns `{ triggerRef, popoverRef, style, reposition }`; pass `anchorRef` to follow a parent-owned trigger and `align` for start/center/end (default end); opt into `constrainHeight` to cap scrollable help to the roomier side of its trigger. | Any portal-into-`<body>` menu/popover placed relative to a button (ThemeSwitcher, CollectionPickerShell) — use this instead of re-rolling the measure/flip/clamp/reflow plumbing. |
| `useScrollLock` | Body-scroll lock with ref-count. | Modals, drawers, lightboxes. |
+| `useStickToBottom` | `useStickToBottom(containerRef, { enabled, revision })` keeps an `overflow-y-auto` container pinned to its bottom as content grows; a user scroll up unpins, scrolling back to the bottom re-pins, and enabling opens at the tail. | A live log or transcript panel (the CoS agent card's running output). Pass the growing array as `revision`. |
| `useSidebarResize` | Drag-to-resize split-pane width persisted to `localStorage`; returns `{ containerRef, width, maxWidth, onMouseDown, reset }` and caps the drag at `maxFraction` of the measured container. | A desktop sidebar/split pane with a draggable divider (WorkEditor's storyboard sidebar). |
| `useSwipeNav` | Horizontal swipe prev/next. | Mobile swipe between siblings. |
| `useTokenPopover` | Hover/click/pin state machine for an anchored token popover (200ms open, 150ms grace close) plus the `hotRef` cross-link highlight; returns `{ pop, hotRef, onTokenEnter/Leave/Click, onPopoverEnter/Leave, closePopover }`. | Prose (or any) tokens that open a detail popover on hover and pin on click (WorkEditor ↔ ProseTokenPopover). |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index 42f34e1cde..c8fad7c032 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -223,6 +223,7 @@ export * from './useLockToggle.js';
export { default as usePersistedOptions } from './usePersistedOptions.js';
export * from './usePersistedOptions.js';
export * from './useScrollLock.js';
+export { default as useStickToBottom } from './useStickToBottom.js';
export { default as useStoryImportIntake } from './useStoryImportIntake.js';
export * from './useStoryImportIntake.js';
export * from './useSwipeNav.js';
diff --git a/client/src/hooks/useStickToBottom.js b/client/src/hooks/useStickToBottom.js
new file mode 100644
index 0000000000..01d772d242
--- /dev/null
+++ b/client/src/hooks/useStickToBottom.js
@@ -0,0 +1,46 @@
+import { useLayoutEffect, useRef } from 'react';
+
+// Within this many pixels of the bottom still counts as "at the bottom", so a
+// fractional layout height or a momentum-scroll overshoot does not unpin.
+const BOTTOM_SLACK_PX = 24;
+
+/**
+ * Keep a scrollable container pinned to its bottom while content grows, until
+ * the user scrolls up — the live-log contract: new lines keep the newest text
+ * in view, but a reader who scrolled back to inspect something is not yanked
+ * down by every line that lands. Scrolling back to the bottom re-pins.
+ *
+ * @param {import('react').RefObject<HTMLElement>} containerRef - the element
+ * with `overflow-y: auto`. It may be conditionally rendered: pass the same
+ * condition as `enabled` so the listener attaches to the mounted element.
+ * @param {{ enabled?: boolean, revision?: unknown }} [options]
+ * `enabled` false detaches entirely (a finished transcript scrolls freely);
+ * `revision` is any value that changes when content is appended (the output
+ * array itself works, since a buffer that is capped at N entries keeps its
+ * length while its contents move). Each change re-pins when still pinned.
+ */
+export default function useStickToBottom(containerRef, { enabled = true, revision } = {}) {
+ const pinnedRef = useRef(true);
+
+ // Layout effects, not passive ones: the pin runs before paint so the user
+ // never sees the panel open at the top and then jump.
+ useLayoutEffect(() => {
+ const el = containerRef.current;
+ if (!enabled || !el) return undefined;
+ // A freshly enabled surface opens at its tail; the user's own scrolling
+ // decides from there.
+ pinnedRef.current = true;
+ el.scrollTop = el.scrollHeight;
+ const onScroll = () => {
+ pinnedRef.current = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_SLACK_PX;
+ };
+ el.addEventListener('scroll', onScroll, { passive: true });
+ return () => el.removeEventListener('scroll', onScroll);
+ }, [containerRef, enabled]);
+
+ useLayoutEffect(() => {
+ const el = containerRef.current;
+ if (!enabled || !el || !pinnedRef.current) return;
+ el.scrollTop = el.scrollHeight;
+ }, [containerRef, enabled, revision]);
+}
diff --git a/client/src/hooks/useStickToBottom.test.jsx b/client/src/hooks/useStickToBottom.test.jsx
new file mode 100644
index 0000000000..9fe2285624
--- /dev/null
+++ b/client/src/hooks/useStickToBottom.test.jsx
@@ -0,0 +1,70 @@
+import { describe, it, expect } from 'vitest';
+import { renderHook } from '@testing-library/react';
+import useStickToBottom from './useStickToBottom.js';
+
+// A fake scroll container: `scrollHeight` is set by the test, `scrollTop` is
+// whatever the hook (or a simulated user) last wrote, and the registered
+// scroll listener is invoked by hand.
+const makeContainer = (scrollHeight) => {
+ const listeners = new Set();
+ const el = {
+ scrollTop: 0,
+ scrollHeight,
+ clientHeight: 200,
+ addEventListener: (type, fn) => { if (type === 'scroll') listeners.add(fn); },
+ removeEventListener: (_type, fn) => { listeners.delete(fn); },
+ };
+ const userScrollTo = (top) => {
+ el.scrollTop = top;
+ for (const fn of listeners) fn();
+ };
+ return { el, listeners, userScrollTo };
+};
+
+describe('useStickToBottom', () => {
+ it('follows appended content until the user scrolls up, and re-pins at the bottom', () => {
+ const { el, userScrollTo } = makeContainer(1000);
+ const ref = { current: el };
+ const { rerender } = renderHook(({ revision }) => useStickToBottom(ref, { revision }), {
+ initialProps: { revision: 0 },
+ });
+ expect(el.scrollTop).toBe(1000);
+
+ el.scrollHeight = 1500;
+ rerender({ revision: 1 });
+ expect(el.scrollTop).toBe(1500);
+
+ // The reader scrolls back to inspect something: new content must not yank
+ // them down.
+ userScrollTo(200);
+ el.scrollHeight = 2000;
+ rerender({ revision: 2 });
+ expect(el.scrollTop).toBe(200);
+
+ // Back within the slack of the bottom: pinned again.
+ userScrollTo(2000 - 200 - 10);
+ el.scrollHeight = 2500;
+ rerender({ revision: 3 });
+ expect(el.scrollTop).toBe(2500);
+ });
+
+ it('attaches nothing and leaves the scroll position alone while disabled', () => {
+ const { el, listeners } = makeContainer(1000);
+ el.scrollTop = 120;
+ const ref = { current: el };
+ const { rerender } = renderHook(
+ ({ enabled, revision }) => useStickToBottom(ref, { enabled, revision }),
+ { initialProps: { enabled: false, revision: 0 } },
+ );
+ expect(listeners.size).toBe(0);
+ expect(el.scrollTop).toBe(120);
+
+ // Enabling opens at the tail regardless of where the user had left it.
+ rerender({ enabled: true, revision: 0 });
+ expect(listeners.size).toBe(1);
+ expect(el.scrollTop).toBe(1000);
+
+ rerender({ enabled: false, revision: 1 });
+ expect(listeners.size).toBe(0);
+ });
+});