@@ -631,7 +631,7 @@ export class Cline {
631631
632632 let newUserContent : UserContent = [ ...modifiedOldUserContent ]
633633
634- const agoText = ( ( ) => {
634+ const agoText = ( ( ) : string => {
635635 const timestamp = lastClineMessage ?. ts ?? Date . now ( )
636636 const now = Date . now ( )
637637 const diff = now - timestamp
@@ -996,7 +996,7 @@ export class Cline {
996996 break
997997 }
998998 case "tool_use" :
999- const toolDescription = ( ) => {
999+ const toolDescription = ( ) : string => {
10001000 switch ( block . name ) {
10011001 case "execute_command" :
10021002 return `[${ block . name } for '${ block . params . command } ']`
@@ -1030,6 +1030,12 @@ export class Cline {
10301030 return `[${ block . name } ]`
10311031 case "switch_mode" :
10321032 return `[${ block . name } to '${ block . params . mode_slug } '${ block . params . reason ? ` because: ${ block . params . reason } ` : "" } ]`
1033+ case "new_task" : {
1034+ const mode = block . params . mode ?? defaultModeSlug
1035+ const message = block . params . message ?? "(no message)"
1036+ const modeName = getModeBySlug ( mode , customModes ) ?. name ?? mode
1037+ return `[${ block . name } in ${ modeName } mode: '${ message } ']`
1038+ }
10331039 }
10341040 }
10351041
@@ -2402,6 +2408,74 @@ export class Cline {
24022408 }
24032409 }
24042410
2411+ case "new_task" : {
2412+ const mode : string | undefined = block . params . mode
2413+ const message : string | undefined = block . params . message
2414+ try {
2415+ if ( block . partial ) {
2416+ const partialMessage = JSON . stringify ( {
2417+ tool : "newTask" ,
2418+ mode : removeClosingTag ( "mode" , mode ) ,
2419+ message : removeClosingTag ( "message" , message ) ,
2420+ } )
2421+ await this . ask ( "tool" , partialMessage , block . partial ) . catch ( ( ) => { } )
2422+ break
2423+ } else {
2424+ if ( ! mode ) {
2425+ this . consecutiveMistakeCount ++
2426+ pushToolResult ( await this . sayAndCreateMissingParamError ( "new_task" , "mode" ) )
2427+ break
2428+ }
2429+ if ( ! message ) {
2430+ this . consecutiveMistakeCount ++
2431+ pushToolResult ( await this . sayAndCreateMissingParamError ( "new_task" , "message" ) )
2432+ break
2433+ }
2434+ this . consecutiveMistakeCount = 0
2435+
2436+ // Verify the mode exists
2437+ const targetMode = getModeBySlug (
2438+ mode ,
2439+ ( await this . providerRef . deref ( ) ?. getState ( ) ) ?. customModes ,
2440+ )
2441+ if ( ! targetMode ) {
2442+ pushToolResult ( formatResponse . toolError ( `Invalid mode: ${ mode } ` ) )
2443+ break
2444+ }
2445+
2446+ // Show what we're about to do
2447+ const toolMessage = JSON . stringify ( {
2448+ tool : "newTask" ,
2449+ mode : targetMode . name ,
2450+ content : message ,
2451+ } )
2452+
2453+ const didApprove = await askApproval ( "tool" , toolMessage )
2454+ if ( ! didApprove ) {
2455+ break
2456+ }
2457+
2458+ // Switch mode first, then create new task instance
2459+ const provider = this . providerRef . deref ( )
2460+ if ( provider ) {
2461+ await provider . handleModeSwitch ( mode )
2462+ await provider . initClineWithTask ( message )
2463+ pushToolResult (
2464+ `Successfully created new task in ${ targetMode . name } mode with message: ${ message } ` ,
2465+ )
2466+ } else {
2467+ pushToolResult (
2468+ formatResponse . toolError ( "Failed to create new task: provider not available" ) ,
2469+ )
2470+ }
2471+ break
2472+ }
2473+ } catch ( error ) {
2474+ await handleError ( "creating new task" , error )
2475+ break
2476+ }
2477+ }
2478+
24052479 case "attempt_completion" : {
24062480 /*
24072481 this.consecutiveMistakeCount = 0
0 commit comments