Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions apps/cli/ai/block-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ export async function validateBlocks(
};
}

// Block validation logs console-style messages: a format string whose
// %s / %o / %d placeholders take the arguments that follow it.
function formatIssue( args: any[] ): string {
const show = ( value: any ) =>
typeof value === 'object' ? JSON.stringify( value ) : String( value );
const rest = args.slice( 1 );
const text = String( args[ 0 ] ?? '' ).replace( /%[sodif]/g, ( placeholder ) =>
rest.length ? show( rest.shift() ) : placeholder
);
return [ text, ...rest.map( show ) ].join( ' ' ).slice( 0, 600 );
}

function extractIssues( validationIssues: any[] ): string[] {
const issues: string[] = [];
for ( const issue of validationIssues ) {
Expand All @@ -80,15 +92,7 @@ export async function validateBlocks(
// Skip the verbose "Block validation failed for `name`" summary —
// the per-attribute messages that follow are more useful.
if ( ! msg.startsWith( 'Block validation failed' ) ) {
issues.push(
issue.args
.map( ( a: any ) =>
typeof a === 'object'
? JSON.stringify( a ).slice( 0, 200 )
: String( a ).slice( 0, 500 )
)
.join( ' ' )
);
issues.push( formatIssue( issue.args ) );
}
}
}
Expand Down
Loading