@@ -743,10 +743,12 @@ function buildToolDetail(state: any, toolName: string): string | undefined {
743743 }
744744
745745 // For completed tools with output, show a very short summary
746- const output = typeof state ?. output === "string" && state . output . trim ( ) ? state . output . trim ( ) : null ;
747- if ( output ) {
746+ const outputRaw = typeof state ?. output === "string" ? state . output . trim ( ) : "" ;
747+ if ( outputRaw ) {
748748 if ( lower === "read" ) return undefined ;
749749
750+ const output = outputRaw . length > 3000 ? outputRaw . slice ( 0 , 3000 ) : outputRaw ;
751+
750752 // Extract just the first meaningful line (skip line numbers and raw file markers)
751753 const lines = output . split ( "\n" ) . filter ( ( l : string ) => {
752754 const trimmed = l . trim ( ) ;
@@ -776,6 +778,15 @@ function buildToolDetail(state: any, toolName: string): string | undefined {
776778 return undefined ;
777779}
778780
781+ const ARTIFACT_PATH_PATTERN =
782+ / (?: ^ | [ \s " ' ` ( [ { ] ) ( (?: [ a - z A - Z ] : [ / \\ ] | \. { 1 , 2 } [ / \\ ] | ~ [ / \\ ] | [ / \\ ] ) [ \w . / \\ \- ] * \. [ a - z ] [ a - z 0 - 9 ] { 0 , 9 } | [ \w . \- ] + [ / \\ ] [ \w . / \\ \- ] * \. [ a - z ] [ a - z 0 - 9 ] { 0 , 9 } ) / gi;
783+ const ARTIFACT_OUTPUT_SCAN_LIMIT = 4000 ;
784+ const ARTIFACT_OUTPUT_SKIP_TOOLS = new Set ( [ "webfetch" ] ) ;
785+
786+ type DeriveArtifactsOptions = {
787+ maxMessages ?: number ;
788+ } ;
789+
779790export function summarizeStep ( part : Part ) : { title : string ; detail ?: string ; isSkill ?: boolean ; skillName ?: string ; toolCategory ?: string ; status ?: string } {
780791 if ( part . type === "tool" ) {
781792 const record = part as any ;
@@ -817,10 +828,15 @@ export function summarizeStep(part: Part): { title: string; detail?: string; isS
817828 return { title : "Step" , toolCategory : "tool" } ;
818829}
819830
820- export function deriveArtifacts ( list : MessageWithParts [ ] ) : ArtifactItem [ ] {
831+ export function deriveArtifacts ( list : MessageWithParts [ ] , options : DeriveArtifactsOptions = { } ) : ArtifactItem [ ] {
821832 const results = new Map < string , ArtifactItem > ( ) ;
833+ const maxMessages =
834+ typeof options . maxMessages === "number" && Number . isFinite ( options . maxMessages ) && options . maxMessages > 0
835+ ? Math . floor ( options . maxMessages )
836+ : null ;
837+ const source = maxMessages && list . length > maxMessages ? list . slice ( list . length - maxMessages ) : list ;
822838
823- list . forEach ( ( message ) => {
839+ source . forEach ( ( message ) => {
824840 const messageId = String ( ( message . info as any ) ?. id ?? "" ) ;
825841
826842 message . parts . forEach ( ( part ) => {
@@ -849,15 +865,23 @@ export function deriveArtifacts(list: MessageWithParts[]): ArtifactItem[] {
849865 }
850866 } ) ;
851867
852- const text = [ state . title , state . output ]
853- . filter ( ( v ) : v is string => typeof v === "string" )
868+ const toolName =
869+ typeof record . tool === "string" && record . tool . trim ( )
870+ ? record . tool . trim ( ) . toLowerCase ( )
871+ : "" ;
872+ const titleText = typeof state . title === "string" ? state . title : "" ;
873+ const outputText =
874+ typeof state . output === "string" && ! ARTIFACT_OUTPUT_SKIP_TOOLS . has ( toolName )
875+ ? state . output . slice ( 0 , ARTIFACT_OUTPUT_SCAN_LIMIT )
876+ : "" ;
877+
878+ const text = [ titleText , outputText ]
879+ . filter ( ( v ) : v is string => Boolean ( v ) )
854880 . join ( " " ) ;
855881
856882 if ( text ) {
857- const pathPattern =
858- / (?: ^ | [ \s " ' ` ( [ { ] ) ( (?: [ a - z A - Z ] : [ / \\ ] | \. { 1 , 2 } [ / \\ ] | ~ [ / \\ ] | [ / \\ ] ) [ \w . / \\ \- ] * \. [ a - z ] [ a - z 0 - 9 ] { 0 , 9 } | [ \w . \- ] + [ / \\ ] [ \w . / \\ \- ] * \. [ a - z ] [ a - z 0 - 9 ] { 0 , 9 } ) / gi;
859-
860- Array . from ( text . matchAll ( pathPattern ) )
883+ ARTIFACT_PATH_PATTERN . lastIndex = 0 ;
884+ Array . from ( text . matchAll ( ARTIFACT_PATH_PATTERN ) )
861885 . map ( ( m ) => m [ 1 ] )
862886 . filter ( ( f ) => f && f . length <= 500 )
863887 . forEach ( ( f ) => matches . add ( f ) ) ;
0 commit comments