diff --git a/docs/dashboard-guide.md b/docs/dashboard-guide.md index d11d9c225d..b3b37e775a 100644 --- a/docs/dashboard-guide.md +++ b/docs/dashboard-guide.md @@ -760,7 +760,7 @@ Recommended workflow: ordinary chains stay as `Blocks N` so noise stays low, hig ### Logs → Agent Log view -The **Chat** tab sits between Definition and Logs and presents a live, chat-styled transcript of task agent output. Consecutive entries are grouped by role and labeled as Planner, Executor, Reviewer, or Merger; legacy log rows without an agent role use the neutral Agent fallback. Consecutive text/message chunks inside a role group render as one continuous markdown bubble, while consecutive tool/tool-result/tool-error rows collapse into one expandable, compact tool-call summary that stays collapsed by default; the summary counts tool invocations, lists deduped tool names with overflow, and shows an error count when failures are present, while the expanded body pairs each call with its result or error in dense entry cards. Thinking entries render in a collapsible block that starts expanded. The transcript opens at the latest output whenever the tab loads or becomes active, then follows new live output when you are already near the bottom while preserving your scroll position when you review older messages. When you scroll away from the bottom of a populated transcript, a sticky **Latest** button appears inside the transcript so you can jump back to the newest message and resume live follow. For non-`done` tasks, the composer sends guidance through the same steering path used by comments, including active assigned `in-progress`/`in-review` sessions and messages queued when no session is currently live. On a `done` task, sending a Chat message starts a refinement task using the typed text as feedback and shows a success toast with the new task ID; the current task detail modal remains on the completed task. The task-detail Chat tab keeps the composer pinned and visible on mobile and desktop while the transcript scrolls internally; its textarea placeholder reads “Steer the currently executing agent” for steering mode and switches to refinement copy for completed tasks, with the same inline, icon-only send affordance to the right of the input at every breakpoint. In the composer, plain **Enter** sends, **Shift+Enter** inserts a newline, and **Cmd/Ctrl+Enter** remains a supported send shortcut. +The **Chat** tab sits between Definition and Logs and presents a live, chat-styled transcript of task agent output. Consecutive entries are grouped by role and labeled as Planner, Executor, Reviewer, or Merger; legacy log rows without an agent role use the neutral Agent fallback. Consecutive text/message chunks inside a role group render as one continuous markdown bubble, while consecutive tool/tool-result/tool-error rows collapse into one expandable, compact tool-call summary that stays collapsed by default; the summary counts tool invocations, lists deduped tool names with overflow, and shows an error count when failures are present, while the expanded body pairs each call with its result or error in dense entry cards. Thinking entries render in a collapsible block that starts expanded. The transcript opens at the latest output whenever the tab loads or becomes active, then follows new live output when you are already near the bottom while preserving your scroll position when you review older messages. When older task-agent history exists, scrolling to the top or selecting **Load previous messages** prepends earlier transcript entries without moving the message you were reading. When you scroll away from the bottom of a populated transcript, a sticky **Latest** button appears inside the transcript so you can jump back to the newest message and resume live follow. For non-`done` tasks, the composer sends guidance through the same steering path used by comments, including active assigned `in-progress`/`in-review` sessions and messages queued when no session is currently live. On a `done` task, sending a Chat message starts a refinement task using the typed text as feedback and shows a success toast with the new task ID; the current task detail modal remains on the completed task. The task-detail Chat tab keeps the composer pinned and visible on mobile and desktop while the transcript scrolls internally; its textarea placeholder reads “Steer the currently executing agent” for steering mode and switches to refinement copy for completed tasks, with the same inline, icon-only send affordance to the right of the input at every breakpoint. In the composer, plain **Enter** sends, **Shift+Enter** inserts a newline, and **Cmd/Ctrl+Enter** remains a supported send shortcut. The **Logs** tab includes an **Agent Log** subview designed for debugging long-running and tool-heavy sessions: diff --git a/packages/dashboard/app/components/TaskChatTab.css b/packages/dashboard/app/components/TaskChatTab.css index de32654e2f..1567aa80c9 100644 --- a/packages/dashboard/app/components/TaskChatTab.css +++ b/packages/dashboard/app/components/TaskChatTab.css @@ -57,6 +57,25 @@ FN-6425 requires the chat expand control to stay inside the chat view as an icon text-align: center; } +.task-chat-load-previous-row { + display: flex; + justify-content: center; + min-block-size: calc(var(--space-2xl) + var(--space-sm)); +} + +.task-chat-load-previous, +.task-chat-load-previous-status { + min-block-size: calc(var(--space-2xl) + var(--space-sm)); +} + +.task-chat-load-previous-status { + display: inline-flex; + align-items: center; + gap: var(--space-xs); + padding: var(--space-xs) var(--space-sm); + color: var(--text-muted); +} + .task-chat-jump-to-bottom { position: sticky; right: var(--space-md); @@ -377,6 +396,15 @@ FN-6507 requires the Task Detail chat send glyph to scale with the larger square min-block-size: calc(var(--space-2xl) + var(--space-sm)); } + .task-chat-load-previous-row { + min-block-size: calc(var(--space-2xl) + var(--space-sm)); + } + + .task-chat-load-previous, + .task-chat-load-previous-status { + min-block-size: calc(var(--space-2xl) + var(--space-sm)); + } + .task-chat-group { grid-template-columns: 1fr; } diff --git a/packages/dashboard/app/components/TaskChatTab.tsx b/packages/dashboard/app/components/TaskChatTab.tsx index cb85c0a6b5..cef21ec2a1 100644 --- a/packages/dashboard/app/components/TaskChatTab.tsx +++ b/packages/dashboard/app/components/TaskChatTab.tsx @@ -51,6 +51,7 @@ const STEERING_BLOCKED_STATUSES = new Set([ ]); const REVIEW_STEERABLE_STATUSES = new Set(["reviewing", "merging", "merging-fix", "fixing"]); const BOTTOM_FOLLOW_THRESHOLD = 48; +const TOP_LOAD_THRESHOLD = 48; function isTranscriptNearBottom(container: HTMLElement): boolean { return container.scrollHeight - (container.scrollTop + container.clientHeight) <= BOTTOM_FOLLOW_THRESHOLD; @@ -410,7 +411,7 @@ function TaskChatUserMessage({ message }: { message: UserChatMessage }) { } export function TaskChatTab({ task, projectId, active, addToast, sessionLive, onTaskUpdated, expanded = false, onToggleExpanded }: TaskChatTabProps) { - const { entries, loading } = useAgentLogs(task.id, active, projectId); + const { entries, loading, loadMore, hasMore, loadingMore } = useAgentLogs(task.id, active, projectId); const [draft, setDraft] = useState(""); const [sending, setSending] = useState(false); const [optimisticMessages, setOptimisticMessages] = useState([]); @@ -418,6 +419,11 @@ export function TaskChatTab({ task, projectId, active, addToast, sessionLive, on const transcriptRef = useRef(null); const previousEntryCountRef = useRef(0); const previousScrollHeightRef = useRef(0); + const previousFirstEntryKeyRef = useRef(null); + const previousAgentEntryCountRef = useRef(0); + const pendingPrependScrollHeightRef = useRef(null); + const pendingPrependScrollTopRef = useRef(0); + const loadMoreInFlightRef = useRef(false); const previousActiveRef = useRef(false); const anchorFrameRef = useRef(null); const textareaRef = useRef(null); @@ -428,6 +434,7 @@ export function TaskChatTab({ task, projectId, active, addToast, sessionLive, on ); const transcriptItems = useMemo(() => buildTranscriptItems(entries, userMessages), [entries, userMessages]); const transcriptItemCount = entries.length + userMessages.length; + const firstEntryKey = entries[0] ? getEntryKey(entries[0], 0) : null; const activeSession = isActiveAgentSession(task, { sessionLive }); const isDoneTask = task.column === "done"; const sessionHint = isDoneTask @@ -524,18 +531,43 @@ export function TaskChatTab({ task, projectId, active, addToast, sessionLive, on if (!active) { previousEntryCountRef.current = transcriptItemCount; previousScrollHeightRef.current = container.scrollHeight; + previousFirstEntryKeyRef.current = firstEntryKey; + previousAgentEntryCountRef.current = entries.length; return; } if (transcriptItemCount === 0) { previousEntryCountRef.current = transcriptItemCount; previousScrollHeightRef.current = container.scrollHeight; + previousFirstEntryKeyRef.current = firstEntryKey; + previousAgentEntryCountRef.current = entries.length; return; } const previousCount = previousEntryCountRef.current; const previousScrollHeight = previousScrollHeightRef.current || container.scrollHeight; - if (transcriptItemCount > previousCount) { + const previousFirstEntryKey = previousFirstEntryKeyRef.current; + const previousAgentEntryCount = previousAgentEntryCountRef.current; + const prependedOlderEntries = Boolean( + pendingPrependScrollHeightRef.current !== null + && transcriptItemCount > previousCount + && entries.length > previousAgentEntryCount + && firstEntryKey + && (!previousFirstEntryKey || firstEntryKey !== previousFirstEntryKey), + ); + + if (prependedOlderEntries) { + /* + * FNXC:TaskDetailChat 2026-06-16-23:03: + * Task-detail chat must load older paginated agent history at the top without disturbing the reader's viewport. Treat a changed first agent-log key as a prepend so bottom-follow remains reserved for live appends at the transcript tail. + */ + const previousTop = pendingPrependScrollTopRef.current; + const previousHeight = pendingPrependScrollHeightRef.current ?? previousScrollHeight; + const heightDelta = container.scrollHeight - previousHeight; + container.scrollTop = previousTop + Math.max(0, heightDelta); + pendingPrependScrollHeightRef.current = null; + setIsTranscriptAtBottom(isTranscriptNearBottom(container)); + } else if (transcriptItemCount > previousCount) { const shouldFollow = previousCount === 0 || previousScrollHeight - (container.scrollTop + container.clientHeight) <= BOTTOM_FOLLOW_THRESHOLD; if (shouldFollow) { container.scrollTop = container.scrollHeight; @@ -543,20 +575,42 @@ export function TaskChatTab({ task, projectId, active, addToast, sessionLive, on } else { setIsTranscriptAtBottom(isTranscriptNearBottom(container)); } + if (pendingPrependScrollHeightRef.current !== null) { + pendingPrependScrollHeightRef.current = container.scrollHeight; + pendingPrependScrollTopRef.current = container.scrollTop; + } } else { setIsTranscriptAtBottom(isTranscriptNearBottom(container)); } previousEntryCountRef.current = transcriptItemCount; previousScrollHeightRef.current = container.scrollHeight; - }, [active, transcriptItemCount]); + previousFirstEntryKeyRef.current = firstEntryKey; + previousAgentEntryCountRef.current = entries.length; + }, [active, entries.length, firstEntryKey, transcriptItemCount]); + + const loadPreviousMessages = useCallback(async () => { + const container = transcriptRef.current; + if (!container || !active || !hasMore || loadingMore || loadMoreInFlightRef.current) return; + pendingPrependScrollHeightRef.current = container.scrollHeight; + pendingPrependScrollTopRef.current = container.scrollTop; + loadMoreInFlightRef.current = true; + try { + await loadMore(); + } finally { + loadMoreInFlightRef.current = false; + } + }, [active, hasMore, loadMore, loadingMore]); const handleTranscriptScroll = useCallback(() => { const container = transcriptRef.current; if (!container) return; previousScrollHeightRef.current = container.scrollHeight; setIsTranscriptAtBottom(isTranscriptNearBottom(container)); - }, []); + if (container.scrollTop <= TOP_LOAD_THRESHOLD) { + void loadPreviousMessages(); + } + }, [loadPreviousMessages]); const scrollTranscriptToBottom = useCallback(() => { const container = transcriptRef.current; @@ -641,6 +695,26 @@ export function TaskChatTab({ task, projectId, active, addToast, sessionLive, on aria-live="polite" data-testid="task-chat-transcript" > + {hasMore || loadingMore ? ( +
+ {loadingMore ? ( +
+
+ ) : ( + + )} +
+ ) : null} {loading && transcriptItemCount === 0 ? (