@@ -42,6 +42,15 @@ import {
4242
4343const logger = createLogger ( 'CopilotToolHandler' )
4444
45+ function applyToolDisplay (
46+ toolCall : ToolCallState | undefined ,
47+ ui : { title ?: string ; phaseLabel ?: string }
48+ ) : void {
49+ if ( ! toolCall ) return
50+ if ( ui . title ) toolCall . displayTitle = ui . title
51+ if ( ui . phaseLabel ) toolCall . phaseLabel = ui . phaseLabel
52+ }
53+
4554/**
4655 * Unified tool event handler for both main and subagent scopes.
4756 *
@@ -148,11 +157,13 @@ async function handleCallPhase(
148157 const isPartial = data . partial === true || isGenerating
149158 const existing = context . toolCalls . get ( toolCallId )
150159 const isSubagent = scope === 'subagent'
160+ const ui = getToolCallUI ( data )
151161
152162 if ( isSubagent ) {
153163 if ( wasToolResultSeen ( toolCallId ) || existing ?. endTime ) {
154164 if ( existing && ! existing . name && toolName ) existing . name = toolName
155165 if ( existing && ! existing . params && args ) existing . params = args
166+ applyToolDisplay ( existing , ui )
156167 return
157168 }
158169 } else {
@@ -162,14 +173,15 @@ async function handleCallPhase(
162173 ) {
163174 if ( ! existing . name && toolName ) existing . name = toolName
164175 if ( ! existing . params && args ) existing . params = args
176+ applyToolDisplay ( existing , ui )
165177 return
166178 }
167179 }
168180
169181 if ( isSubagent ) {
170- registerSubagentToolCall ( context , toolCallId , toolName , args , parentToolCallId ! )
182+ registerSubagentToolCall ( context , toolCallId , toolName , args , parentToolCallId ! , ui )
171183 } else {
172- registerMainToolCall ( context , toolCallId , toolName , args , existing )
184+ registerMainToolCall ( context , toolCallId , toolName , args , existing , ui )
173185 }
174186
175187 if ( isPartial ) return
@@ -184,7 +196,7 @@ async function handleCallPhase(
184196 const readPath = typeof args ?. path === 'string' ? args . path : undefined
185197 if ( toolName === 'read' && readPath ?. startsWith ( 'internal/' ) ) return
186198
187- const { clientExecutable, simExecutable, internal } = getToolCallUI ( data )
199+ const { clientExecutable, simExecutable, internal } = ui
188200 const catalogEntry = getToolEntry ( toolName )
189201 const isInternal = internal || catalogEntry ?. internal === true
190202 const staticSimExecuted = isSimExecuted ( toolName )
@@ -225,7 +237,8 @@ function registerSubagentToolCall(
225237 toolCallId : string ,
226238 toolName : string ,
227239 args : Record < string , unknown > | undefined ,
228- parentToolCallId : string
240+ parentToolCallId : string ,
241+ ui : { title ?: string ; phaseLabel ?: string }
229242) : void {
230243 if ( ! context . subAgentToolCalls [ parentToolCallId ] ) {
231244 context . subAgentToolCalls [ parentToolCallId ] = [ ]
@@ -235,6 +248,7 @@ function registerSubagentToolCall(
235248 if ( toolCall ) {
236249 if ( ! toolCall . name && toolName ) toolCall . name = toolName
237250 if ( args && ! toolCall . params ) toolCall . params = args
251+ applyToolDisplay ( toolCall , ui )
238252 } else {
239253 toolCall = {
240254 id : toolCallId ,
@@ -243,6 +257,7 @@ function registerSubagentToolCall(
243257 params : args ,
244258 startTime : Date . now ( ) ,
245259 }
260+ applyToolDisplay ( toolCall , ui )
246261 context . toolCalls . set ( toolCallId , toolCall )
247262 const parentToolCall = context . toolCalls . get ( parentToolCallId )
248263 if ( ! hideFromUi ) {
@@ -259,6 +274,7 @@ function registerSubagentToolCall(
259274 if ( existingSubagentToolCall ) {
260275 if ( ! existingSubagentToolCall . name && toolName ) existingSubagentToolCall . name = toolName
261276 if ( args && ! existingSubagentToolCall . params ) existingSubagentToolCall . params = args
277+ applyToolDisplay ( existingSubagentToolCall , ui )
262278 } else {
263279 subagentToolCalls . push ( toolCall )
264280 }
@@ -269,11 +285,13 @@ function registerMainToolCall(
269285 toolCallId : string ,
270286 toolName : string ,
271287 args : Record < string , unknown > | undefined ,
272- existing : ToolCallState | undefined
288+ existing : ToolCallState | undefined ,
289+ ui : { title ?: string ; phaseLabel ?: string }
273290) : void {
274291 const hideFromUi = isToolHiddenInUi ( toolName )
275292 if ( existing ) {
276293 if ( args && ! existing . params ) existing . params = args
294+ applyToolDisplay ( existing , ui )
277295 if (
278296 ! hideFromUi &&
279297 ! context . contentBlocks . some ( ( b ) => b . type === 'tool_call' && b . toolCall ?. id === toolCallId )
@@ -288,6 +306,7 @@ function registerMainToolCall(
288306 params : args ,
289307 startTime : Date . now ( ) ,
290308 }
309+ applyToolDisplay ( created , ui )
291310 context . toolCalls . set ( toolCallId , created )
292311 if ( ! hideFromUi ) {
293312 addContentBlock ( context , { type : 'tool_call' , toolCall : created } )
0 commit comments