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
Merge main into feat/chat-scroll-to-bottom
review3d61ccefb1bc
diff --cc src/renderer/nodes/ChatPanel.paging.test.tsxindex f9a5cc0d8,a190b658a..9fdef4d0d--- a/src/renderer/nodes/ChatPanel.paging.test.tsx+++ b/src/renderer/nodes/ChatPanel.paging.test.tsx@@@ -370,64 -370,43 +370,105 @@@ describe('ChatPanel progressive loading})})+ 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 })+ await act(async () => {+ target.dispatchEvent(e)+ })+ return e+ }+ const composer = (): HTMLTextAreaElement =>+ host.querySelector('.term-chat__composer-input') as HTMLTextAreaElement++ it('pages the thread from the composer', async () => {+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), say(20, 'c')] })+ const bottom = msgs().scrollTop++ const up = await press(composer(), 'PageUp')++ expect(up.defaultPrevented).toBe(true)+ expect(msgs().scrollTop).toBe(bottom - 350)++ await press(composer(), 'PageDown')++ expect(msgs().scrollTop).toBe(bottom)+ })++ it('leaves Shift+Page Up to the composer (selection), without scrolling the thread', async () => {+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), say(20, 'c')] })+ const bottom = msgs().scrollTop+ const e = new KeyboardEvent('keydown', { key: 'PageUp', shiftKey: true, bubbles: true, cancelable: true })++ await act(async () => {+ composer().dispatchEvent(e)+ })++ expect(e.defaultPrevented).toBe(false)+ expect(msgs().scrollTop).toBe(bottom)+ })+ })+++describe('ChatPanel scroll-to-latest button', () => {+ const button = (): HTMLButtonElement | null => host.querySelector<HTMLButtonElement>('.term-chat__to-latest')+ const three = [say(0, 'a'), say(10, 'b'), say(20, 'c')]++ it('is hidden while the view follows the newest message', async () => {+ await render()++ await settle(0, { messages: three })++ expect(button()).toBeNull()+ })++ it('appears once the user scrolls up, and brings the view back to the bottom', async () => {+ await render()+ await settle(0, { messages: three })+ const bottom = msgs().scrollTop++ await scrollTo(100)++ expect(button()?.textContent).toBe('↓')+ expect(button()?.getAttribute('aria-label')).toBe('Scroll to the latest message')++ await act(async () => button()!.click())++ expect(msgs().scrollTop).toBe(bottom)+ expect(button()).toBeNull()+ })++ it('stays while the user reads history and a new message lands below', async () => {+ await render()+ await settle(0, { messages: three })+ await scrollTo(100)+ await act(async () => host.querySelector<HTMLButtonElement>('.term-chat__refresh')!.click())++ await settle(1, { messages: [...three, say(30, 'd')] })++ expect(msgs().scrollTop).toBe(100)+ expect(button()?.textContent).toBe('1 new message ↓')+ })++ it('does not appear for a thread shorter than the panel', async () => {+ geo.perMsg = 100+ await render()+ await settle(0, { messages: three })++ await scrollTo(0)++ expect(button()).toBeNull()+ })++ it('keeps the keyboard where it was when pressed', async () => {+ await render()+ await settle(0, { messages: three })+ await scrollTo(100)+ const down = new MouseEvent('mousedown', { bubbles: true, cancelable: true })++ button()!.dispatchEvent(down)++ expect(down.defaultPrevented).toBe(true)+ })+})diff --cc src/renderer/nodes/ChatPanel.tsxindex d22e9edc6,231b0562d..04b4053d7--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@@ -820,13 -808,17 +823,24 @@@ export function ChatPanel(maybeLoadOlder()}+ // Page Up / Page Down page the thread from anywhere in the panel, the composer included+ // (lib/chatPageKeys.ts). `contains`: a React portal's keydown bubbles here too.+ const onPageKey = (e: KeyboardEvent<HTMLDivElement>) => {+ const el = msgsRef.current+ if (!el || e.defaultPrevented || !(e.target instanceof Element) || !e.currentTarget.contains(e.target)) return+ const direction = chatPageDirection(e, e.target)+ if (direction === null) return+ e.preventDefault()+ pageChatThread(el, direction)+ }++ const scrollToLatest = () => {+ const el = msgsRef.current+ if (!el) return+ el.scrollTop = el.scrollHeight+ markFollowing(true)+ }+// The optimistic bubbles sent into the CLI's queue mid-turn, drawn as "Queued" until the transcript// has them. Object identity is enough: `applyTail` carries an unconfirmed send as the same object.const queuedRef = useRef(new WeakSet<ChatMessage>())@@@ -998,152 -989,135 +1012,152 @@@{FALLBACK_SESSION_NOTE}</div>)}- <div className="term-chat__msgs" ref={msgsRef} onScroll={onScroll}>- {initialLoading && (- <ChatLoadingStatus text={EMPTY_TEXT.loading.title} />- )}- {messages.length > 0 && olderState === 'loading' && (- <div className="term-chat__older" role="status">- <Spinner />- <span>Loading earlier messages…</span>- </div>- )}- {olderState === 'error' && (- <div className="term-chat__older term-chat__older--error">- <span>Couldn't load earlier messages.</span>- <button className="term-chat__retry" onClick={loadOlder}>- Retry- </button>- </div>- )}- {/* Only a PAGED thread (keyed messages) can know it reached the start; grok's capped- whole-file read says nothing about what lies before it. */}- {olderState === 'idle' && thread.olderCursor === null && messages.some((m) => m.key !== undefined) && (- <div className="term-chat__older term-chat__older--start">Beginning of conversation</div>- )}- {showEmpty && (- <div className="term-chat__empty">- <div>{EMPTY_TEXT[loadState].title.replace('{agent}', agentLabel)}</div>- {EMPTY_TEXT[loadState].detail && (- <div className="term-chat__empty-detail">{EMPTY_TEXT[loadState].detail}</div>- )}- {loadState !== 'unsupported' && loadState !== 'remoteUnsupported' && loadState !== 'ambiguous' && loadState !== 'ok' && (- <button className="term-chat__retry" onClick={() => load()}>+ <div className="term-chat__thread">+ <div className="term-chat__msgs" ref={msgsRef} onScroll={onScroll}>+ {initialLoading && (+ <ChatLoadingStatus text={EMPTY_TEXT.loading.title} />+ )}+ {messages.length > 0 && olderState === 'loading' && (+ <div className="term-chat__older" role="status">+ <Spinner />+ <span>Loading earlier messages…</span>+ </div>+ )}+ {olderState === 'error' && (+ <div className="term-chat__older term-chat__older--error">+ <span>Couldn't load earlier messages.</span>+ <button className="term-chat__retry" onClick={loadOlder}>Retry</button>- )}- </div>- )}- {messages.map((m, i) => (- // Keyed by the source line's byte offset: a prepended page does not re-key (and so does- // not re-render) a single existing bubble. Unkeyed ones (grok, the optimistic sent- // bubble) fall back to their position.- <div- key={m.key !== undefined ? `k${m.key}` : `i${i}`}- className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}${- queuedRef.current.has(m) ? ' term-chat__msg--queued' : ''- }`}- >- {m.parts.map((p, j) =>- p.kind === 'text' ? (- <MarkdownText key={j} text={p.text} />- ) : p.kind === 'thinking' ? (- // Claude's thinking summary — the "thinking out loud" line its TUI prints between- // tool calls. Shown inline like the TUI does, dimmed so it never reads as the answer.- <div key={j} className="term-chat__thinking">- <MarkdownText text={p.text} />- </div>- ) : p.body ? (- // A plan / question is the content itself, not plumbing: shown expanded, in full,- // flowing with the thread (no inner scroll box). The answer stays under it.- <div key={j} className="term-chat__tool-card">- <div className="term-chat__tool-card-title">{toolCardTitle(p.name)}</div>- <MarkdownText text={p.body} />- {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}- {answerCard && answerCard.card.message === i && answerCard.card.part === j && (- // Keyed by the BOUND ticket: a new hold on the same card starts from a clean- // state, and every answer names the request this card was drawn for.- p.name === 'AskUserQuestion' && p.questions ? (- <QuestionAnswerControls- key={answerCard.pendingId}- questions={p.questions}- agentLabel={agentLabel}- chip={mdChip}- onSubmit={(a) => answerHeld(answerCard.pendingId, a)}- />- ) : (- <PlanAnswerControls- key={answerCard.pendingId}- agentLabel={agentLabel}- chip={mdChip}- onSubmit={(a) => answerHeld(answerCard.pendingId, a)}- />- )- )}- {updatingCard && updatingCard.message === i && updatingCard.part === j && (- <AnswerControlsUpdating chip={mdChip} />- )}- </div>- ) : (- <details key={j} className="term-chat__tool">- <summary>- <span className="term-chat__tool-name">{p.name}</span>- {p.arg && <span className="term-chat__tool-arg">{p.arg}</span>}- </summary>- {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}- </details>- )- )}- {queuedRef.current.has(m) && <div className="term-chat__queued-label">Queued</div>}- {turnEnds.has(i) && (- <ChatTurnActions- copyText={turnEnds.get(i)!.copyText}- at={turnEnds.get(i)!.at}- now={now}- latest={i === latestTurnEnd}- />- )}- </div>- ))}- {screenBlock && (- <div className="term-chat__screen-block" role="status" aria-live="polite">- <div className="term-chat__screen-block-title">- {screenBlockedSentence(screenBlock.kind, agentLabel, mdChip)}</div>- {screenBlock.text !== null && <pre className="term-chat__screen-block-text">{screenBlock.text}</pre>}- </div>- )}- {activity && (- // One live region for both sentences, so working → waiting changes its text instead of- // remounting it (a remounted role=status is announced again). The words are the- // composer placeholder's own (`chatComposerPlaceholder`), so the two never disagree.- <div className="term-chat__activity" role="status" aria-live="polite">- {activity === 'working' && <Spinner />}- {chatComposerPlaceholder({- readonly: false,- refusal: activity,- agentLabel,- chip: mdChip,- answerOnCard: answerCard !== null- })}- </div>+ )}+ {/* Only a PAGED thread (keyed messages) can know it reached the start; grok's capped+ whole-file read says nothing about what lies before it. */}+ {olderState === 'idle' && thread.olderCursor === null && messages.some((m) => m.key !== undefined) && (+ <div className="term-chat__older term-chat__older--start">Beginning of conversation</div>+ )}+ {showEmpty && (+ <div className="term-chat__empty">+ <div>{EMPTY_TEXT[loadState].title.replace('{agent}', agentLabel)}</div>+ {EMPTY_TEXT[loadState].detail && (+ <div className="term-chat__empty-detail">{EMPTY_TEXT[loadState].detail}</div>+ )}+ {loadState !== 'unsupported' && loadState !== 'remoteUnsupported' && loadState !== 'ambiguous' && loadState !== 'ok' && (+ <button className="term-chat__retry" onClick={() => load()}>+ Retry+ </button>+ )}+ </div>+ )}+ {messages.map((m, i) => (+ // Keyed by the source line's byte offset: a prepended page does not re-key (and so does+ // not re-render) a single existing bubble. Unkeyed ones (grok, the optimistic sent+ // bubble) fall back to their position.+ <div+ key={m.key !== undefined ? `k${m.key}` : `i${i}`}+ className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}${+ queuedRef.current.has(m) ? ' term-chat__msg--queued' : ''+ }`}+ >+ {m.parts.map((p, j) =>+ p.kind === 'text' ? (+ <MarkdownText key={j} text={p.text} />+ ) : p.kind === 'thinking' ? (- // Reasoning, not the answer: collapsed by default so it cannot be mistaken for it.- <details key={j} className="term-chat__thinking">- <summary>Thinking</summary>++ // Claude's thinking summary — the "thinking out loud" line its TUI prints between++ // tool calls. Shown inline like the TUI does, dimmed so it never reads as the answer.++ <div key={j} className="term-chat__thinking">+ <MarkdownText text={p.text} />- </details>++ </div>+ ) : p.body ? (+ // A plan / question is the content itself, not plumbing: shown expanded, in full,+ // flowing with the thread (no inner scroll box). The answer stays under it.+ <div key={j} className="term-chat__tool-card">+ <div className="term-chat__tool-card-title">{toolCardTitle(p.name)}</div>+ <MarkdownText text={p.body} />+ {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}+ {answerCard && answerCard.card.message === i && answerCard.card.part === j && (+ // Keyed by the BOUND ticket: a new hold on the same card starts from a clean+ // state, and every answer names the request this card was drawn for.+ p.name === 'AskUserQuestion' && p.questions ? (+ <QuestionAnswerControls+ key={answerCard.pendingId}+ questions={p.questions}+ agentLabel={agentLabel}+ chip={mdChip}+ onSubmit={(a) => answerHeld(answerCard.pendingId, a)}+ />+ ) : (+ <PlanAnswerControls+ key={answerCard.pendingId}+ agentLabel={agentLabel}+ chip={mdChip}+ onSubmit={(a) => answerHeld(answerCard.pendingId, a)}+ />+ )+ )}+ {updatingCard && updatingCard.message === i && updatingCard.part === j && (+ <AnswerControlsUpdating chip={mdChip} />+ )}+ </div>+ ) : (+ <details key={j} className="term-chat__tool">+ <summary>+ <span className="term-chat__tool-name">{p.name}</span>+ {p.arg && <span className="term-chat__tool-arg">{p.arg}</span>}+ </summary>+ {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}+ </details>+ )+ )}+ {queuedRef.current.has(m) && <div className="term-chat__queued-label">Queued</div>}+ {turnEnds.has(i) && (+ <ChatTurnActions+ copyText={turnEnds.get(i)!.copyText}+ at={turnEnds.get(i)!.at}+ now={now}+ latest={i === latestTurnEnd}+ />+ )}+ </div>+ ))}+ {screenBlock && (+ <div className="term-chat__screen-block" role="status" aria-live="polite">+ <div className="term-chat__screen-block-title">+ {screenBlockedSentence(screenBlock.kind, agentLabel, mdChip)}+ </div>+ {screenBlock.text !== null && <pre className="term-chat__screen-block-text">{screenBlock.text}</pre>}+ </div>+ )}+ {activity && (+ // One live region for both sentences, so working → waiting changes its text instead of+ // remounting it (a remounted role=status is announced again). The words are the+ // composer placeholder's own (`chatComposerPlaceholder`), so the two never disagree.+ <div className="term-chat__activity" role="status" aria-live="polite">+ {activity === 'working' && <Spinner />}+ {chatComposerPlaceholder({+ readonly: false,+ refusal: activity,+ agentLabel,+ chip: mdChip,+ answerOnCard: answerCard !== null+ })}+ </div>+ )}+ </div>+ {!following && messages.length > 0 && (+ // The Live chat drawer's "N new messages ↓" pill (LiveChatDrawer.tsx), plus a bare "↓" while+ // nothing new has come in: here the thread is also read back from deep in its history.+ <button+ type="button"+ className="confirm__btn primary term-chat__to-latest"+ title="Scroll to the latest message"+ aria-label={unseen > 0 ? undefined : 'Scroll to the latest message'}+ // Keep the keyboard where it was (the composer): a click here is not a reason to leave it.+ onMouseDown={(e) => e.preventDefault()}+ onClick={scrollToLatest}+ >+ {unseen > 0 ? `${newMessagesLabel(unseen)} ↓` : '↓'}+ </button>)}</div>{!readOnly && (