@@ -91,14 +91,35 @@ function projectCommandData(data: Record<string, unknown>): Record<string, unkno
9191 projectedItem . command = item . command ;
9292 }
9393
94+ const aggregatedOutput = asTrimmedString ( item . aggregatedOutput ) ;
95+ if ( aggregatedOutput ) {
96+ const summary = summarizeToolTextOutput ( aggregatedOutput ) ;
97+ if ( summary ) {
98+ projectedItem . aggregatedOutput = summary ;
99+ }
100+ }
101+
94102 const input = asRecord ( item . input ) ;
95103 if ( input && "command" in input ) {
96104 projectedItem . input = { command : input . command } ;
97105 }
98106
99107 const result = asRecord ( item . result ) ;
100- if ( result && "command" in result ) {
101- projectedItem . result = { command : result . command } ;
108+ if ( result ) {
109+ const projectedResult : Record < string , unknown > = { } ;
110+ if ( "command" in result ) {
111+ projectedResult . command = result . command ;
112+ }
113+ const content = asTrimmedString ( result . content ) ;
114+ if ( content ) {
115+ const summary = summarizeToolTextOutput ( content ) ;
116+ if ( summary ) {
117+ projectedResult . content = summary ;
118+ }
119+ }
120+ if ( Object . keys ( projectedResult ) . length > 0 ) {
121+ projectedItem . result = projectedResult ;
122+ }
102123 }
103124
104125 return Object . keys ( projectedItem ) . length > 0 ? projectedItem : undefined ;
@@ -232,6 +253,12 @@ function projectMcpToolCallData(data: Record<string, unknown>): Record<string, u
232253}
233254
234255function projectRawOutput ( value : unknown ) : Record < string , unknown > | undefined {
256+ const direct = asTrimmedString ( value ) ;
257+ if ( direct ) {
258+ const summary = summarizeToolTextOutput ( direct ) ;
259+ return summary ? { content : summary } : undefined ;
260+ }
261+
235262 const rawOutput = asRecord ( value ) ;
236263 if ( ! rawOutput ) {
237264 return undefined ;
@@ -256,9 +283,34 @@ function projectRawOutput(value: unknown): Record<string, unknown> | undefined {
256283 return summary ? { content : summary } : undefined ;
257284 }
258285
286+ const stderr = asTrimmedString ( rawOutput . stderr ) ;
287+ if ( stderr ) {
288+ const summary = summarizeToolTextOutput ( stderr ) ;
289+ return summary ? { content : summary } : undefined ;
290+ }
291+
259292 return undefined ;
260293}
261294
295+ function projectAcpContent ( value : unknown ) : Record < string , unknown > | undefined {
296+ if ( ! Array . isArray ( value ) ) {
297+ return undefined ;
298+ }
299+
300+ const text = value
301+ . map ( ( entryValue ) => {
302+ const entry = asRecord ( entryValue ) ;
303+ const content = asRecord ( entry ?. content ) ;
304+ return entry ?. type === "content" && content ?. type === "text"
305+ ? asTrimmedString ( content . text )
306+ : null ;
307+ } )
308+ . filter ( ( entry ) : entry is string => entry !== null )
309+ . join ( "\n" ) ;
310+ const summary = summarizeToolTextOutput ( text ) ;
311+ return summary ? { content : summary } : undefined ;
312+ }
313+
262314/**
263315 * Removes activity payload fields that no current client reads while retaining
264316 * the full payload in persistence and the event store.
@@ -305,7 +357,7 @@ export function projectActivityPayload(
305357 projectedData . kind = data . kind ;
306358 }
307359
308- const rawOutput = projectRawOutput ( data . rawOutput ) ;
360+ const rawOutput = projectRawOutput ( data . rawOutput ) ?? projectAcpContent ( data . content ) ;
309361 if ( rawOutput ) {
310362 projectedData . rawOutput = rawOutput ;
311363 }
0 commit comments