@@ -11,14 +11,22 @@ use api::{
1111use plugins:: PluginTool ;
1212use reqwest:: blocking:: Client ;
1313use runtime:: {
14- edit_file, execute_bash, glob_search, grep_search, load_system_prompt, read_file, write_file,
15- ApiClient , ApiRequest , AssistantEvent , BashCommandInput , ContentBlock , ConversationMessage ,
16- ConversationRuntime , GrepSearchInput , MessageRole , PermissionMode , PermissionPolicy ,
17- PromptCacheEvent , RuntimeError , Session , ToolError , ToolExecutor ,
14+ edit_file, execute_bash, glob_search, grep_search, load_system_prompt, read_file,
15+ task_registry:: TaskRegistry , write_file, ApiClient , ApiRequest , AssistantEvent ,
16+ BashCommandInput , ContentBlock , ConversationMessage , ConversationRuntime , GrepSearchInput ,
17+ MessageRole , PermissionMode , PermissionPolicy , PromptCacheEvent , RuntimeError , Session ,
18+ ToolError , ToolExecutor ,
1819} ;
1920use serde:: { Deserialize , Serialize } ;
2021use serde_json:: { json, Value } ;
2122
23+ /// Global task registry shared across tool invocations within a session.
24+ fn global_task_registry ( ) -> & ' static TaskRegistry {
25+ use std:: sync:: OnceLock ;
26+ static REGISTRY : OnceLock < TaskRegistry > = OnceLock :: new ( ) ;
27+ REGISTRY . get_or_init ( TaskRegistry :: new)
28+ }
29+
2230#[ derive( Debug , Clone , PartialEq , Eq ) ]
2331pub struct ToolManifestEntry {
2432 pub name : String ,
@@ -905,60 +913,96 @@ fn run_ask_user_question(input: AskUserQuestionInput) -> Result<String, String>
905913
906914#[ allow( clippy:: needless_pass_by_value) ]
907915fn run_task_create ( input : TaskCreateInput ) -> Result < String , String > {
908- let secs = std:: time:: SystemTime :: now ( )
909- . duration_since ( std:: time:: UNIX_EPOCH )
910- . unwrap_or_default ( )
911- . as_secs ( ) ;
912- let task_id = format ! ( "task_{secs:08x}" ) ;
916+ let registry = global_task_registry ( ) ;
917+ let task = registry. create ( & input. prompt , input. description . as_deref ( ) ) ;
913918 to_pretty_json ( json ! ( {
914- "task_id" : task_id,
915- "status" : "created" ,
916- "prompt" : input. prompt,
917- "description" : input. description
919+ "task_id" : task. task_id,
920+ "status" : task. status,
921+ "prompt" : task. prompt,
922+ "description" : task. description,
923+ "created_at" : task. created_at
918924 } ) )
919925}
920926
921927#[ allow( clippy:: needless_pass_by_value) ]
922928fn run_task_get ( input : TaskIdInput ) -> Result < String , String > {
923- to_pretty_json ( json ! ( {
924- "task_id" : input. task_id,
925- "status" : "unknown" ,
926- "message" : "Task runtime not yet implemented"
927- } ) )
929+ let registry = global_task_registry ( ) ;
930+ match registry. get ( & input. task_id ) {
931+ Some ( task) => to_pretty_json ( json ! ( {
932+ "task_id" : task. task_id,
933+ "status" : task. status,
934+ "prompt" : task. prompt,
935+ "description" : task. description,
936+ "created_at" : task. created_at,
937+ "updated_at" : task. updated_at,
938+ "messages" : task. messages,
939+ "team_id" : task. team_id
940+ } ) ) ,
941+ None => Err ( format ! ( "task not found: {}" , input. task_id) ) ,
942+ }
928943}
929944
930945fn run_task_list ( _input : Value ) -> Result < String , String > {
946+ let registry = global_task_registry ( ) ;
947+ let tasks: Vec < _ > = registry
948+ . list ( None )
949+ . into_iter ( )
950+ . map ( |t| {
951+ json ! ( {
952+ "task_id" : t. task_id,
953+ "status" : t. status,
954+ "prompt" : t. prompt,
955+ "description" : t. description,
956+ "created_at" : t. created_at,
957+ "updated_at" : t. updated_at,
958+ "team_id" : t. team_id
959+ } )
960+ } )
961+ . collect ( ) ;
931962 to_pretty_json ( json ! ( {
932- "tasks" : [ ] ,
933- "message " : "No tasks found"
963+ "tasks" : tasks ,
964+ "count " : tasks. len ( )
934965 } ) )
935966}
936967
937968#[ allow( clippy:: needless_pass_by_value) ]
938969fn run_task_stop ( input : TaskIdInput ) -> Result < String , String > {
939- to_pretty_json ( json ! ( {
940- "task_id" : input. task_id,
941- "status" : "stopped" ,
942- "message" : "Task stop requested"
943- } ) )
970+ let registry = global_task_registry ( ) ;
971+ match registry. stop ( & input. task_id ) {
972+ Ok ( task) => to_pretty_json ( json ! ( {
973+ "task_id" : task. task_id,
974+ "status" : task. status,
975+ "message" : "Task stopped"
976+ } ) ) ,
977+ Err ( e) => Err ( e) ,
978+ }
944979}
945980
946981#[ allow( clippy:: needless_pass_by_value) ]
947982fn run_task_update ( input : TaskUpdateInput ) -> Result < String , String > {
948- to_pretty_json ( json ! ( {
949- "task_id" : input. task_id,
950- "status" : "updated" ,
951- "message" : input. message
952- } ) )
983+ let registry = global_task_registry ( ) ;
984+ match registry. update ( & input. task_id , & input. message ) {
985+ Ok ( task) => to_pretty_json ( json ! ( {
986+ "task_id" : task. task_id,
987+ "status" : task. status,
988+ "message_count" : task. messages. len( ) ,
989+ "last_message" : input. message
990+ } ) ) ,
991+ Err ( e) => Err ( e) ,
992+ }
953993}
954994
955995#[ allow( clippy:: needless_pass_by_value) ]
956996fn run_task_output ( input : TaskIdInput ) -> Result < String , String > {
957- to_pretty_json ( json ! ( {
958- "task_id" : input. task_id,
959- "output" : "" ,
960- "message" : "No output available"
961- } ) )
997+ let registry = global_task_registry ( ) ;
998+ match registry. output ( & input. task_id ) {
999+ Ok ( output) => to_pretty_json ( json ! ( {
1000+ "task_id" : input. task_id,
1001+ "output" : output,
1002+ "has_output" : !output. is_empty( )
1003+ } ) ) ,
1004+ Err ( e) => Err ( e) ,
1005+ }
9621006}
9631007
9641008#[ allow( clippy:: needless_pass_by_value) ]
0 commit comments