Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(chat): the Focus toggle re-runs the follow and older-page checks
review48088b34923a
diff --git a/src/renderer/nodes/ChatPanel.paging.test.tsx b/src/renderer/nodes/ChatPanel.paging.test.tsxindex 9c4d24cfd..6a083cd5a 100644--- a/src/renderer/nodes/ChatPanel.paging.test.tsx+++ b/src/renderer/nodes/ChatPanel.paging.test.tsx@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { ChatMessage, ChatTranscriptResult } from '@shared/types'import type { ChatTranscriptPageRequest } from '@shared/chat-page'import { useAgentStatus } from '../state/agentStatus'+import { useSettings } from '../state/settings'import { CHAT_OLDER_PAGE_BYTES, CHAT_TAIL_PAGE_BYTES } from '../lib/chatPaging'/**@@ -125,6 +126,7 @@ beforeEach(() => {afterEach(async () => {await act(async () => root.unmount())host.remove()+ useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: false } }))useAgentStatus.setState((s) => {const byId = { ...s.byId }delete byId[NODE]@@ -370,6 +372,60 @@ describe('ChatPanel progressive loading', () => {})})+// Focus view (the bar toggle) hides whole messages, so flipping it changes the thread's height with+// no new message and no scroll event: the follow and paging checks must run on the flip itself.+describe('ChatPanel Focus toggle re-runs follow and paging', () => {+ const think = (key: number): ChatMessage => ({ role: 'assistant', key, parts: [{ kind: 'thinking', text: 'hmm' }] })+ const focus = async (on: boolean): Promise<void> => {+ await act(async () => {+ useSettings.setState((s) => ({ settings: { ...s.settings, chatFocusView: on } }))+ })+ }++ it('turning Focus on pages back when the filtered thread now fits the viewport', async () => {+ geo.perMsg = 300 // three bubbles overflow the 400px viewport; one does not+ await render()+ await settle(0, { messages: [think(1000), think(1100), say(1200, 'answer')], olderCursor: 1000 })+ expect(msgs().scrollTop).toBe(500) // pinned to the bottom, far from the top: no fetch+ expect(pending).toHaveLength(1)++ await focus(true)++ expect(bubbles()).toEqual(['answer'])+ expect(pending).toHaveLength(2)+ expect(pending[1].page).toEqual({ before: 1000, maxBytes: CHAT_OLDER_PAGE_BYTES, thinking: true, rich: true })+ })++ it('turning Focus off while following lands at the new bottom', async () => {+ geo.perMsg = 300+ await focus(true)+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), think(20), think(30), say(40, 'c')] })+ expect(bubbles()).toEqual(['a', 'b', 'c'])+ // Three bubbles and the "Beginning of conversation" row, scrolled to the bottom.+ expect(msgs().scrollTop).toBe(3 * 300 + ROW - 400)++ await focus(false)++ expect(host.querySelectorAll('.term-chat__msg')).toHaveLength(5)+ expect(msgs().scrollTop).toBe(5 * 300 + ROW - 400)+ expect(host.querySelector('.term-chat__to-latest')).toBeNull()+ })++ it('a reader scrolled up keeps their place across the flip', async () => {+ geo.perMsg = 300+ await focus(true)+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), think(20), think(30), say(40, 'c')] })+ await scrollTo(100)++ await focus(false)++ expect(msgs().scrollTop).toBe(100)+ expect(host.querySelector('.term-chat__to-latest')).not.toBeNull()+ })+})+describe('ChatPanel Page Up / Page Down', () => {const press = async (target: Element, key: string): Promise<KeyboardEvent> => {const e = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true })diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex 3a2f768b1..655d80d58 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -273,6 +273,10 @@ export function ChatPanel({// the same object across same-ticket events, so this selector re-renders only on a new hold.const held = useAgentStatus((s) => s.byId[nodeId]?.held)const customAgents = useSettings((s) => s.settings.customAgents)+ // Focus view (the bar toggle; lib/chatFocus.ts): tool chips and thinking are left out. Strict, as+ // the setting is hand-editable. Flipping it changes the thread's height with no new message, so+ // the follow and older-page checks below re-run on it.+ const focusView = useSettings((s) => s.settings.chatFocusView === true)// Not just `working`: a TUI dialog (`waiting`/`blocked`) would be ANSWERED by sendText's Enter,// and a pane whose CLI is gone (hibernated/paused/dropped/exited) is a SHELL that would execute it.const refusal = chatSendRefusal(agentId, { state, hibernated, paused, dropped, sessionEnded })@@ -780,7 +784,9 @@ export function ChatPanel({}justSentRef.current = false// `activity` / `screenBlock`: a row appearing at the end grows the thread like a message does.- }, [messages, olderState, activity, screenBlock, markFollowing])+ // `focusView`: the Focus toggle shows or hides whole messages — a user following the bottom+ // stays there (turned off, it would leave them mid-thread); a reader scrolled up is left alone.+ }, [messages, olderState, activity, screenBlock, focusView, markFollowing])const maybeLoadOlder = useCallback(() => {const el = msgsRef.current@@ -801,10 +807,11 @@ export function ChatPanel({}, [thread.identity, thread.olderCursor, identity, olderState, loadState, tailLoading, loadOlder])// After every thread change too, not only on scroll: a thread shorter than the viewport cannot- // scroll, so without this its older history would be unreachable.+ // scroll, so without this its older history would be unreachable. The Focus toggle is such a+ // change: turned on, a thread can shrink below the viewport with no scroll event to page it.useEffect(() => {maybeLoadOlder()- }, [maybeLoadOlder])+ }, [maybeLoadOlder, focusView])// The panel's box changing size — above all a collapsed node being EXPANDED (display:none → a// real box). Nothing else re-runs the checks then: while hidden, follow and anchor had zero@@ -1001,9 +1008,7 @@ export function ChatPanel({}, [])// A divider at the first message of each local day; the same `now`, so Today rolls to Yesterday.const days = useMemo(() => dayDividers(messages, now), [messages, now])- // Focus view (the bar toggle; lib/chatFocus.ts): tool chips and thinking are left out. Strict, as- // the setting is hand-editable. Only the latest todo list is a card, in both views.- const focusView = useSettings((s) => s.settings.chatFocusView === true)+ // Only the latest todo list is a card, in both views (Focus: `focusView`, above).const latestTodo = useMemo(() => latestTodoIndex(messages), [messages])// Whether the part at (i, j) draws anything at its own place: not when an earlier tool block holds// it, nor in Focus view when it is hidden — or, for a block's first member, when its every member is.