Skip to content

Commit ba8b525

Browse files
committed
cli: delete scrollToAgent & agentRefsMap
1 parent 803a897 commit ba8b525

File tree

7 files changed

+2
-83
lines changed

7 files changed

+2
-83
lines changed

cli/knowledge.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,7 @@ This prevents invalid children from reaching `TextNodeRenderable` while preservi
555555

556556
**Related**: `cli/src/hooks/use-message-renderer.tsx` ensures toggle headers render within a single `<text>` block for StyledText compatibility.
557557

558-
### Scroll Behavior
559558

560-
Toggling any agent/tool branch calls `scrollToAgent`, with each branch registering its container via `registerAgentRef`. This anchors the toggled item in the top third of the scrollbox for better navigation in long sessions.
561559

562560
## Command Menus
563561

cli/src/chat.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ export const App = ({
465465
// Track main agent streaming elapsed time
466466
const mainAgentTimer = useElapsedTime()
467467

468-
const agentRefsMap = useRef<Map<string, any>>(new Map())
469468
const hasAutoSubmittedRef = useRef(false)
470469
const activeSubagentsRef = useRef<Set<string>>(activeSubagents)
471470

@@ -486,16 +485,8 @@ export const App = ({
486485

487486
const abortControllerRef = useRef<AbortController | null>(null)
488487

489-
const registerAgentRef = useCallback((agentId: string, element: any) => {
490-
if (element) {
491-
agentRefsMap.current.set(agentId, element)
492-
} else {
493-
agentRefsMap.current.delete(agentId)
494-
}
495-
}, [])
496-
497-
const { scrollToLatest, scrollToAgent, scrollboxProps, isAtBottom } =
498-
useChatScrollbox(scrollRef, messages, agentRefsMap)
488+
const { scrollToLatest, scrollboxProps, isAtBottom } =
489+
useChatScrollbox(scrollRef, messages)
499490

500491
const inertialScrollAcceleration = useMemo(
501492
() => new QuadraticScrollAccel(),
@@ -1008,8 +999,6 @@ export const App = ({
1008999
timer: mainAgentTimer,
10091000
setCollapsedAgents,
10101001
setFocusedAgentId,
1011-
registerAgentRef,
1012-
scrollToAgent,
10131002
})
10141003

10151004
const virtualizationNotice =

cli/src/components/__tests__/message-block.completion.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const baseProps = {
4646
collapsedAgents: new Set<string>(),
4747
streamingAgents: new Set<string>(),
4848
onToggleCollapsed: () => {},
49-
registerAgentRef: () => {},
5049
}
5150

5251
describe('MessageBlock completion time', () => {

cli/src/components/__tests__/message-block.streaming.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const baseProps = {
3939
collapsedAgents: new Set<string>(),
4040
streamingAgents: new Set<string>(),
4141
onToggleCollapsed: () => {},
42-
registerAgentRef: () => {},
4342
}
4443

4544
const createTimer = (elapsedSeconds: number) => ({

cli/src/components/message-block.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ interface MessageBlockProps {
4545
collapsedAgents: Set<string>
4646
streamingAgents: Set<string>
4747
onToggleCollapsed: (id: string) => void
48-
registerAgentRef: (id: string, element: any) => void
4948
}
5049

5150
export const MessageBlock = ({
@@ -68,7 +67,6 @@ export const MessageBlock = ({
6867
collapsedAgents,
6968
streamingAgents,
7069
onToggleCollapsed,
71-
registerAgentRef,
7270
}: MessageBlockProps): ReactNode => {
7371
const theme = useTheme()
7472
const resolvedTextColor = textColor ?? theme.foreground
@@ -270,7 +268,6 @@ export const MessageBlock = ({
270268
return (
271269
<box
272270
key={keyPrefix}
273-
ref={(el: any) => registerAgentRef(toolBlock.toolCallId, el)}
274271
>
275272
{toolRenderConfig.content ? (
276273
toolRenderConfig.content
@@ -348,7 +345,6 @@ export const MessageBlock = ({
348345
return (
349346
<box
350347
key={keyPrefix}
351-
ref={(el: any) => registerAgentRef(agentBlock.agentId, el)}
352348
style={{ flexDirection: 'column', gap: 0 }}
353349
>
354350
<AgentBranchItem
@@ -440,7 +436,6 @@ export const MessageBlock = ({
440436
return (
441437
<box
442438
key={keyPrefix}
443-
ref={(el: any) => registerAgentRef(agentListBlock.id, el)}
444439
>
445440
<AgentBranchItem
446441
name={headerText}

cli/src/hooks/use-message-renderer.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ interface UseMessageRendererProps {
2727
timer: ElapsedTimeTracker
2828
setCollapsedAgents: React.Dispatch<React.SetStateAction<Set<string>>>
2929
setFocusedAgentId: React.Dispatch<React.SetStateAction<string | null>>
30-
registerAgentRef: (agentId: string, element: any) => void
31-
scrollToAgent: (agentId: string, retries?: number) => void
3230
}
3331

3432
export const useMessageRenderer = (
@@ -47,8 +45,6 @@ export const useMessageRenderer = (
4745
timer,
4846
setCollapsedAgents,
4947
setFocusedAgentId,
50-
registerAgentRef,
51-
scrollToAgent,
5248
} = props
5349

5450
return useMemo(() => {
@@ -119,7 +115,6 @@ export const useMessageRenderer = (
119115
})
120116

121117
setFocusedAgentId(message.id)
122-
scrollToAgent(message.id)
123118
}
124119

125120
const handleContentClick = (e: any): void => {
@@ -141,13 +136,11 @@ export const useMessageRenderer = (
141136
})
142137

143138
setFocusedAgentId(message.id)
144-
scrollToAgent(message.id)
145139
}
146140

147141
return (
148142
<box
149143
key={message.id}
150-
ref={(el: any) => registerAgentRef(message.id, el)}
151144
style={{
152145
flexDirection: 'column',
153146
gap: 0,
@@ -378,9 +371,7 @@ export const useMessageRenderer = (
378371
}
379372
return next
380373
})
381-
scrollToAgent(id)
382374
}}
383-
registerAgentRef={registerAgentRef}
384375
/>
385376
</box>
386377
</box>
@@ -428,9 +419,7 @@ export const useMessageRenderer = (
428419
}
429420
return next
430421
})
431-
scrollToAgent(id)
432422
}}
433-
registerAgentRef={registerAgentRef}
434423
/>
435424
</box>
436425
)}
@@ -469,7 +458,5 @@ export const useMessageRenderer = (
469458
isWaitingForResponse,
470459
setCollapsedAgents,
471460
setFocusedAgentId,
472-
registerAgentRef,
473-
scrollToAgent,
474461
])
475462
}

cli/src/hooks/use-scroll-management.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const easeOutCubic = (t: number): number => {
99
export const useChatScrollbox = (
1010
scrollRef: React.RefObject<ScrollBoxRenderable | null>,
1111
messages: any[],
12-
agentRefsMap: React.MutableRefObject<Map<string, any>>,
1312
) => {
1413
const autoScrollEnabledRef = useRef<boolean>(true)
1514
const programmaticScrollRef = useRef<boolean>(false)
@@ -67,53 +66,7 @@ export const useChatScrollbox = (
6766
animateScrollTo(maxScroll)
6867
}, [scrollRef, animateScrollTo])
6968

70-
const scrollToAgent = useCallback(
71-
(agentId: string, retries = 5) => {
72-
setTimeout(() => {
73-
const scrollbox = scrollRef.current
74-
if (!scrollbox) return
75-
76-
const agentElement = agentRefsMap.current.get(agentId)
77-
if (!agentElement) {
78-
if (retries > 0) {
79-
scrollToAgent(agentId, retries - 1)
80-
}
81-
return
82-
}
83-
84-
const agentViewportY = agentElement.y ?? 0
85-
const agentHeight = agentElement.height ?? 0
86-
const viewportHeight = scrollbox.viewport.height
87-
const scrollHeight = scrollbox.scrollHeight
88-
const currentScroll = scrollbox.scrollTop
89-
90-
const agentY = agentViewportY + currentScroll
91-
const absoluteMaxScroll = Math.max(0, scrollHeight - viewportHeight)
92-
const minScroll = Math.max(0, agentY + agentHeight - viewportHeight)
93-
const maxScrollBound = Math.min(agentY, absoluteMaxScroll)
94-
95-
if (currentScroll >= minScroll && currentScroll <= maxScrollBound) {
96-
return
97-
}
98-
99-
const idealViewportY = Math.floor(viewportHeight / 3)
100-
const idealScroll = agentY - idealViewportY
10169

102-
let targetScroll: number
103-
if (minScroll > maxScrollBound) {
104-
targetScroll = Math.min(agentY, absoluteMaxScroll)
105-
} else {
106-
targetScroll = Math.max(
107-
minScroll,
108-
Math.min(idealScroll, maxScrollBound),
109-
)
110-
}
111-
112-
animateScrollTo(targetScroll)
113-
}, 100)
114-
},
115-
[scrollRef, agentRefsMap, animateScrollTo],
116-
)
11770

11871
useEffect(() => {
11972
const scrollbox = scrollRef.current
@@ -177,7 +130,6 @@ export const useChatScrollbox = (
177130

178131
return {
179132
scrollToLatest,
180-
scrollToAgent,
181133
scrollboxProps: {},
182134
isAtBottom,
183135
}

0 commit comments

Comments
 (0)