@@ -375,23 +375,20 @@ export class WorkspaceProvider
375
375
agentMetadataText : string ;
376
376
} {
377
377
// Handle null/undefined workspace data safely
378
- const workspaceName = ( workspace . workspace . name || "" ) . toLowerCase ( ) ;
379
- const ownerName = ( workspace . workspace . owner_name || "" ) . toLowerCase ( ) ;
378
+ const workspaceName = workspace . workspace . name . toLowerCase ( ) ;
379
+ const ownerName = workspace . workspace . owner_name . toLowerCase ( ) ;
380
380
const templateName = (
381
381
workspace . workspace . template_display_name ||
382
- workspace . workspace . template_name ||
383
- ""
382
+ workspace . workspace . template_name
384
383
) . toLowerCase ( ) ;
385
384
const status = (
386
- workspace . workspace . latest_build ? .status || ""
385
+ workspace . workspace . latest_build . status || ""
387
386
) . toLowerCase ( ) ;
388
387
389
388
// Extract agent names with null safety
390
- const agents = extractAgents (
391
- workspace . workspace . latest_build ?. resources || [ ] ,
392
- ) ;
389
+ const agents = extractAgents ( workspace . workspace . latest_build . resources ) ;
393
390
const agentNames = agents
394
- . map ( ( agent ) => ( agent . name || "" ) . toLowerCase ( ) )
391
+ . map ( ( agent ) => agent . name . toLowerCase ( ) )
395
392
. filter ( ( name ) => name . length > 0 ) ;
396
393
397
394
// Extract and cache agent metadata with error handling
@@ -402,13 +399,16 @@ export class WorkspaceProvider
402
399
agentMetadataText = this . metadataCache [ metadataCacheKey ] ;
403
400
} else {
404
401
const metadataStrings : string [ ] = [ ] ;
402
+ let hasSerializationErrors = false ;
403
+
405
404
agents . forEach ( ( agent ) => {
406
405
const watcher = this . agentWatchers [ agent . id ] ;
407
406
if ( watcher ?. metadata ) {
408
407
watcher . metadata . forEach ( ( metadata ) => {
409
408
try {
410
409
metadataStrings . push ( JSON . stringify ( metadata ) . toLowerCase ( ) ) ;
411
410
} catch ( error ) {
411
+ hasSerializationErrors = true ;
412
412
// Handle JSON serialization errors gracefully
413
413
this . storage . output . warn (
414
414
`Failed to serialize metadata for agent ${ agent . id } : ${ error } ` ,
@@ -417,8 +417,13 @@ export class WorkspaceProvider
417
417
} ) ;
418
418
}
419
419
} ) ;
420
+
420
421
agentMetadataText = metadataStrings . join ( " " ) ;
421
- this . metadataCache [ metadataCacheKey ] = agentMetadataText ;
422
+
423
+ // Only cache if all metadata serialized successfully
424
+ if ( ! hasSerializationErrors ) {
425
+ this . metadataCache [ metadataCacheKey ] = agentMetadataText ;
426
+ }
422
427
}
423
428
424
429
return {
@@ -454,18 +459,8 @@ export class WorkspaceProvider
454
459
455
460
const regexPatterns : RegExp [ ] = [ ] ;
456
461
for ( const word of searchWords ) {
457
- try {
458
- // Escape special regex characters to prevent injection
459
- const escapedWord = word . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
460
- regexPatterns . push ( new RegExp ( `\\b${ escapedWord } \\b` , "i" ) ) ;
461
- } catch ( error ) {
462
- // Handle invalid regex patterns
463
- this . storage . output . warn (
464
- `Invalid regex pattern for search word "${ word } ": ${ error } ` ,
465
- ) ;
466
- // Fall back to simple substring matching for this word
467
- continue ;
468
- }
462
+ // Simple word boundary search
463
+ regexPatterns . push ( new RegExp ( `\\b${ word } \\b` , "i" ) ) ;
469
464
}
470
465
471
466
// Combine all text for exact word matching
@@ -481,27 +476,11 @@ export class WorkspaceProvider
481
476
// Check for exact word matches (higher priority)
482
477
const hasExactWordMatch =
483
478
regexPatterns . length > 0 &&
484
- regexPatterns . some ( ( pattern ) => {
485
- try {
486
- return pattern . test ( allText ) ;
487
- } catch ( error ) {
488
- // Handle regex test errors gracefully
489
- this . storage . output . warn (
490
- `Regex test failed for pattern ${ pattern } : ${ error } ` ,
491
- ) ;
492
- return false ;
493
- }
494
- } ) ;
479
+ regexPatterns . some ( ( pattern ) => pattern . test ( allText ) ) ;
495
480
496
481
// Check for substring matches (lower priority) - only if no exact word match
497
482
const hasSubstringMatch =
498
- ! hasExactWordMatch &&
499
- ( fields . workspaceName . includes ( searchTerm ) ||
500
- fields . ownerName . includes ( searchTerm ) ||
501
- fields . templateName . includes ( searchTerm ) ||
502
- fields . status . includes ( searchTerm ) ||
503
- fields . agentNames . some ( ( agentName ) => agentName . includes ( searchTerm ) ) ||
504
- fields . agentMetadataText . includes ( searchTerm ) ) ;
483
+ ! hasExactWordMatch && allText . includes ( searchTerm ) ;
505
484
506
485
// Return true if either exact word match or substring match
507
486
return hasExactWordMatch || hasSubstringMatch ;
0 commit comments