@@ -171,16 +171,28 @@ function safeTargetPath(value) {
171171 return path ? `workspace/${ path } ` : undefined
172172}
173173
174+ function omittedText ( value ) {
175+ if ( typeof value !== "string" ) return undefined
176+ const bytes = Buffer . byteLength ( value )
177+ return { bytes, sha256 : digest ( Buffer . from ( value ) ) }
178+ }
179+
180+ function projectArguments ( value ) {
181+ const entry = record ( value )
182+ const paths = [ entry . path , ...( Array . isArray ( entry . paths ) ? entry . paths : [ ] ) ] . map ( safeTargetPath ) . filter ( Boolean ) . slice ( 0 , 32 )
183+ const counts = Object . fromEntries ( [ "bytes" , "byte_count" , "match_count" , "matches" , "change_count" , "changes" , "count" ] . flatMap ( ( key ) => typeof entry [ key ] === "number" ? [ [ key , entry [ key ] ] ] : [ ] ) )
184+ const payloads = Object . fromEntries ( [ "content" , "patch" , "diff" , "write" , "old_string" , "new_string" , "text" ] . flatMap ( ( key ) => omittedText ( entry [ key ] ) ? [ [ key , omittedText ( entry [ key ] ) ] ] : [ ] ) )
185+ return Object . fromEntries ( Object . entries ( { paths : paths . length ? paths : undefined , counts : Object . keys ( counts ) . length ? counts : undefined , omitted_payloads : Object . keys ( payloads ) . length ? payloads : undefined } ) . filter ( ( [ , item ] ) => item !== undefined ) )
186+ }
187+
174188function projectToolCall ( value ) {
175189 const entry = record ( value )
176190 const tool = boundedText ( entry . tool_id ?? entry . toolId ?? entry . name ?? entry . tool_name )
177- const path = safeTargetPath ( record ( entry . args ?? entry . arguments ) . path ?? entry . path )
191+ const args = projectArguments ( entry . args ?? entry . arguments )
192+ const paths = [ ...( args . paths ?? [ ] ) , ...[ safeTargetPath ( entry . path ) ] . filter ( Boolean ) ] . slice ( 0 , 32 )
178193 const result = record ( entry . result ?? entry . output )
179- const rawContent = result . content ?? entry . content
180- const content = path && / w o r k s p a c e / i. test ( tool ?? "" ) && typeof rawContent === "string"
181- ? redact ( sanitizeText ( rawContent ) ) . slice ( 0 , MAX_REVIEW_TEXT_BYTES )
182- : undefined
183- return Object . fromEntries ( Object . entries ( { tool, path, status : boundedText ( entry . status ) , arguments : path ? { path } : undefined , content, error : boundedText ( record ( entry . error ) . message ?? entry . error ) } ) . filter ( ( [ , item ] ) => item !== undefined ) )
194+ const resultSummary = projectArguments ( { ...result , content : result . content ?? entry . content , path : result . path ?? entry . path } )
195+ return Object . fromEntries ( Object . entries ( { tool, paths : paths . length ? paths : undefined , status : boundedText ( entry . status ) , arguments : Object . keys ( args ) . length ? args : undefined , result : Object . keys ( resultSummary ) . length ? resultSummary : undefined , error_code : boundedText ( record ( entry . error ) . code ?? entry . error_code ) , error : boundedText ( record ( entry . error ) . message ?? entry . error ) } ) . filter ( ( [ , item ] ) => item !== undefined ) )
184196}
185197
186198function projectParsed ( value ) {
0 commit comments