@@ -544,6 +544,8 @@ function extractAntigravityToolOutputText(toolCall: AcpToolCallState): string |
544544 return undefined ;
545545}
546546
547+ const ANTIGRAVITY_BACKGROUND_COMMAND_TITLES = new Set ( [ "run_command" , "schedule" , "run command" ] ) ;
548+
547549export function extractAntigravityBackgroundTaskId ( toolCall : AcpToolCallState ) : string | undefined {
548550 const title = toolCall . title ?. toLowerCase ( ) ?? "" ;
549551 const command = toolCall . command ?. toLowerCase ( ) ?? "" ;
@@ -559,15 +561,22 @@ export function extractAntigravityBackgroundTaskId(toolCall: AcpToolCallState):
559561 ( typeof record . TaskId === "string" && record . TaskId . trim ( ) ) ;
560562 if ( directId ) return directId ;
561563 }
564+ // Only inspect output text for commands that can spawn background tasks
565+ const isCommandOrSchedule =
566+ ANTIGRAVITY_BACKGROUND_COMMAND_TITLES . has ( title ) ||
567+ toolCall . kind === "execute" ||
568+ ( typeof toolCall . command === "string" && Boolean ( toolCall . command ) ) ;
569+ if ( ! isCommandOrSchedule ) return undefined ;
570+
562571 const outputText = extractAntigravityToolOutputText ( toolCall ) ;
563572 if ( outputText !== undefined ) {
564573 const match =
565574 / r u n n i n g a s a b a c k g r o u n d t a s k w i t h t a s k i d : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ??
566575 / s c h e d u l e d t a s k w i t h (?: t a s k ) ? i d : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ??
567- / b a c k g r o u n d t a s k w i t h t a s k i d : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ??
568- / T a s k I D : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ;
576+ / b a c k g r o u n d t a s k w i t h t a s k i d : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ;
569577 if ( match ?. [ 1 ] ) {
570- return match [ 1 ] . replace ( / [ " ' , . ] / g, "" ) . trim ( ) ;
578+ // Strip only trailing punctuation such as quotes, commas, dots
579+ return match [ 1 ] . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ;
571580 }
572581 }
573582 return undefined ;
@@ -591,52 +600,68 @@ export function extractAntigravityBackgroundTaskCompletion(
591600
592601 const title = toolCall . title ?. toLowerCase ( ) ?? "" ;
593602 const isManageTask =
603+ title === "manage_task" ||
594604 title . includes ( "manage_task" ) ||
595605 ( typeof toolCall . command === "string" &&
596606 toolCall . command . toLowerCase ( ) . includes ( "manage_task" ) ) ;
597607
608+ if ( ! isManageTask ) {
609+ return [ ] ;
610+ }
611+
598612 const outputText = extractAntigravityToolOutputText ( toolCall ) ?? "" ;
613+ const action = typeof rawInput ?. Action === "string" ? rawInput . Action . toLowerCase ( ) : "" ;
599614
600- if ( isManageTask ) {
601- const action = typeof rawInput ?. Action === "string" ? rawInput . Action . toLowerCase ( ) : "" ;
602- if ( action === "kill" || title . includes ( "kill" ) ) {
603- if ( toolCall . status === "completed" || / c a n c e l l e d | k i l l e d / i. test ( outputText ) ) {
604- const taskId =
605- taskIdFromInput ??
606- / T a s k " ( [ ^ " ] + ) " \s + (?: c a n c e l l e d | k i l l e d ) / i. exec ( outputText ) ?. [ 1 ] ??
607- / T a s k i d " ( [ ^ " ] + ) " \s + (?: w a s c a n c e l e d | f i n i s h e d ) / i. exec ( outputText ) ?. [ 1 ] ;
608- if ( taskId ) {
609- return [ { taskId, status : "completed" , appendOutput : outputText } ] ;
610- }
611- }
612- } else if ( action === "status" || title . includes ( "status" ) ) {
615+ if ( action === "kill" || / k i l l / i. test ( title ) ) {
616+ if ( toolCall . status === "completed" || / c a n c e l l e d | k i l l e d / i. test ( outputText ) ) {
613617 const taskId =
614618 taskIdFromInput ??
615- / T a s k : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ?. [ 1 ] ??
616- / T a s k i d " ( [ ^ " ] + ) " / i. exec ( outputText ) ?. [ 1 ] ;
619+ / T a s k " ( [ ^ " ] + ) " \s + (?: c a n c e l l e d | k i l l e d ) / i. exec ( outputText ) ?. [ 1 ] ??
620+ / T a s k i d " ( [ ^ " ] + ) " \s + (?: w a s c a n c e l e d | f i n i s h e d ) / i. exec ( outputText ) ?. [ 1 ] ;
617621 if ( taskId ) {
618- if (
619- / S t a t u s : \s * (?: C O M P L E T E D | S T O P P E D ) / i. test ( outputText ) ||
620- / c o m m a n d e x i t e d w i t h c o d e \s + 0 \b / i. test ( outputText )
621- ) {
622- return [ { taskId, status : "completed" , appendOutput : outputText } ] ;
623- }
624- if (
625- / S t a t u s : \s * F A I L E D / i. test ( outputText ) ||
626- / c o m m a n d e x i t e d w i t h c o d e \s + [ 1 - 9 ] \d * / i. test ( outputText )
627- ) {
628- return [ { taskId, status : "failed" , appendOutput : outputText } ] ;
629- }
630- if ( / S t a t u s : \s * R U N N I N G / i. test ( outputText ) ) {
631- return [ { taskId, status : "running" , appendOutput : outputText } ] ;
632- }
622+ return [
623+ {
624+ taskId : taskId . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ,
625+ status : "completed" ,
626+ appendOutput : outputText ,
627+ } ,
628+ ] ;
629+ }
630+ }
631+ } else if ( action === "status" || / s t a t u s / i. test ( title ) ) {
632+ const taskId =
633+ taskIdFromInput ??
634+ / T a s k : \s * ( [ ^ \s \r \n ] + ) / i. exec ( outputText ) ?. [ 1 ] ??
635+ / T a s k i d " ( [ ^ " ] + ) " / i. exec ( outputText ) ?. [ 1 ] ;
636+ if ( taskId ) {
637+ const cleanId = taskId . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ;
638+ if (
639+ / S t a t u s : \s * (?: C O M P L E T E D | S T O P P E D ) / i. test ( outputText ) ||
640+ / c o m m a n d e x i t e d w i t h c o d e \s + 0 \b / i. test ( outputText )
641+ ) {
642+ return [ { taskId : cleanId , status : "completed" , appendOutput : outputText } ] ;
643+ }
644+ if (
645+ / S t a t u s : \s * F A I L E D / i. test ( outputText ) ||
646+ / c o m m a n d e x i t e d w i t h c o d e \s + [ 1 - 9 ] \d * / i. test ( outputText )
647+ ) {
648+ return [ { taskId : cleanId , status : "failed" , appendOutput : outputText } ] ;
649+ }
650+ if ( / S t a t u s : \s * R U N N I N G / i. test ( outputText ) ) {
651+ return [ { taskId : cleanId , status : "running" , appendOutput : outputText } ] ;
633652 }
634653 }
635654 }
636655
637656 const cancelMatch = / T a s k " ( [ ^ " ] + ) " \s + (?: c a n c e l l e d | k i l l e d ) \b / i. exec ( outputText ) ;
638657 if ( cancelMatch ?. [ 1 ] ) {
639- return [ { taskId : cancelMatch [ 1 ] , status : "completed" , appendOutput : outputText } ] ;
658+ return [
659+ {
660+ taskId : cancelMatch [ 1 ] . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ,
661+ status : "completed" ,
662+ appendOutput : outputText ,
663+ } ,
664+ ] ;
640665 }
641666
642667 return [ ] ;
@@ -654,10 +679,11 @@ export function extractAntigravityBackgroundToolMutation(text: string): Readonly
654679 readonly appendOutput : string ;
655680 } > = [ ] ;
656681
682+ // Antigravity injected system notification patterns start with `Task id "..."` or `Task "..."`
657683 const taskFinishedMatch =
658- / T a s k i d " ( [ ^ " ] + ) " \s + ( f i n i s h e d | w a s c a n c e l e d | f a i l e d ) \s + w i t h r e s u l t : / i. exec ( text ) ;
684+ / (?: ^ | \n ) T a s k i d " ( [ ^ " ] + ) " \s + ( f i n i s h e d | w a s c a n c e l e d | f a i l e d ) \s + w i t h r e s u l t : / i. exec ( text ) ;
659685 if ( taskFinishedMatch ?. [ 1 ] && taskFinishedMatch [ 2 ] ) {
660- const taskId = taskFinishedMatch [ 1 ] ;
686+ const taskId = taskFinishedMatch [ 1 ] . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ;
661687 const kind = taskFinishedMatch [ 2 ] . toLowerCase ( ) ;
662688 const hasFailedExitCode = / c o m m a n d e x i t e d w i t h c o d e \s + ( [ 1 - 9 ] \d * ) / i. test ( text ) ;
663689 const status : "completed" | "failed" =
@@ -666,9 +692,13 @@ export function extractAntigravityBackgroundToolMutation(text: string): Readonly
666692 return results ;
667693 }
668694
669- const taskCancelledMatch = / T a s k " ( [ ^ " ] + ) " \s + (?: c a n c e l l e d | k i l l e d ) \b / i. exec ( text ) ;
695+ const taskCancelledMatch = / (?: ^ | \n ) T a s k " ( [ ^ " ] + ) " \s + (?: c a n c e l l e d | k i l l e d ) \b / i. exec ( text ) ;
670696 if ( taskCancelledMatch ?. [ 1 ] ) {
671- results . push ( { taskId : taskCancelledMatch [ 1 ] , status : "completed" , appendOutput : text } ) ;
697+ results . push ( {
698+ taskId : taskCancelledMatch [ 1 ] . replace ( / [ " ' , . ] + $ / , "" ) . trim ( ) ,
699+ status : "completed" ,
700+ appendOutput : text ,
701+ } ) ;
672702 return results ;
673703 }
674704
0 commit comments