@@ -47,7 +47,7 @@ use crate::cli::chat::{
47
47
ChatSession ,
48
48
ChatState ,
49
49
} ;
50
- use crate :: platform :: Context ;
50
+ use crate :: os :: Os ;
51
51
52
52
const DEFAULT_TIMEOUT_MS : u64 = 30_000 ;
53
53
const DEFAULT_MAX_OUTPUT_SIZE : usize = 1024 * 10 ;
@@ -404,9 +404,9 @@ pub struct HooksArgs {
404
404
}
405
405
406
406
impl HooksArgs {
407
- pub async fn execute ( self , ctx : & Context , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
407
+ pub async fn execute ( self , os : & Os , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
408
408
if let Some ( subcommand) = self . subcommand {
409
- return subcommand. execute ( ctx , session) . await ;
409
+ return subcommand. execute ( os , session) . await ;
410
410
}
411
411
412
412
let Some ( context_manager) = & mut session. conversation . context_manager else {
@@ -530,7 +530,7 @@ pub enum HooksSubcommand {
530
530
}
531
531
532
532
impl HooksSubcommand {
533
- pub async fn execute ( self , ctx : & Context , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
533
+ pub async fn execute ( self , os : & Os , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
534
534
let Some ( context_manager) = & mut session. conversation . context_manager else {
535
535
return Ok ( ChatState :: PromptUser {
536
536
skip_printing_tools : true ,
@@ -553,7 +553,7 @@ impl HooksSubcommand {
553
553
} ;
554
554
555
555
let result = context_manager
556
- . add_hook ( ctx , name. clone ( ) , Hook :: new_inline_hook ( trigger, command) , global)
556
+ . add_hook ( os , name. clone ( ) , Hook :: new_inline_hook ( trigger, command) , global)
557
557
. await ;
558
558
match result {
559
559
Ok ( _) => {
@@ -575,7 +575,7 @@ impl HooksSubcommand {
575
575
}
576
576
} ,
577
577
Self :: Remove { name, global } => {
578
- let result = context_manager. remove_hook ( ctx , & name, global) . await ;
578
+ let result = context_manager. remove_hook ( os , & name, global) . await ;
579
579
match result {
580
580
Ok ( _) => {
581
581
execute ! (
@@ -596,7 +596,7 @@ impl HooksSubcommand {
596
596
}
597
597
} ,
598
598
Self :: Enable { name, global } => {
599
- let result = context_manager. set_hook_disabled ( ctx , & name, global, false ) . await ;
599
+ let result = context_manager. set_hook_disabled ( os , & name, global, false ) . await ;
600
600
match result {
601
601
Ok ( _) => {
602
602
execute ! (
@@ -617,7 +617,7 @@ impl HooksSubcommand {
617
617
}
618
618
} ,
619
619
Self :: Disable { name, global } => {
620
- let result = context_manager. set_hook_disabled ( ctx , & name, global, true ) . await ;
620
+ let result = context_manager. set_hook_disabled ( os , & name, global, true ) . await ;
621
621
match result {
622
622
Ok ( _) => {
623
623
execute ! (
@@ -639,7 +639,7 @@ impl HooksSubcommand {
639
639
} ,
640
640
Self :: EnableAll { global } => {
641
641
context_manager
642
- . set_all_hooks_disabled ( ctx , global, false )
642
+ . set_all_hooks_disabled ( os , global, false )
643
643
. await
644
644
. map_err ( map_chat_error) ?;
645
645
execute ! (
@@ -651,7 +651,7 @@ impl HooksSubcommand {
651
651
} ,
652
652
Self :: DisableAll { global } => {
653
653
context_manager
654
- . set_all_hooks_disabled ( ctx , global, true )
654
+ . set_all_hooks_disabled ( os , global, true )
655
655
. await
656
656
. map_err ( map_chat_error) ?;
657
657
execute ! (
@@ -782,26 +782,26 @@ mod tests {
782
782
783
783
#[ tokio:: test]
784
784
async fn test_add_hook ( ) -> Result < ( ) > {
785
- let ctx = Context :: new ( ) ;
785
+ let os = Os :: new ( ) ;
786
786
let mut manager = create_test_context_manager ( None ) . await ?;
787
787
let hook = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
788
788
789
789
// Test adding hook to profile config
790
790
manager
791
- . add_hook ( & ctx , "test_hook" . to_string ( ) , hook. clone ( ) , false )
791
+ . add_hook ( & os , "test_hook" . to_string ( ) , hook. clone ( ) , false )
792
792
. await ?;
793
793
assert ! ( manager. profile_config. hooks. contains_key( "test_hook" ) ) ;
794
794
795
795
// Test adding hook to global config
796
796
manager
797
- . add_hook ( & ctx , "global_hook" . to_string ( ) , hook. clone ( ) , true )
797
+ . add_hook ( & os , "global_hook" . to_string ( ) , hook. clone ( ) , true )
798
798
. await ?;
799
799
assert ! ( manager. global_config. hooks. contains_key( "global_hook" ) ) ;
800
800
801
801
// Test adding duplicate hook name
802
802
assert ! (
803
803
manager
804
- . add_hook( & ctx , "test_hook" . to_string( ) , hook, false )
804
+ . add_hook( & os , "test_hook" . to_string( ) , hook, false )
805
805
. await
806
806
. is_err( )
807
807
) ;
@@ -811,42 +811,42 @@ mod tests {
811
811
812
812
#[ tokio:: test]
813
813
async fn test_remove_hook ( ) -> Result < ( ) > {
814
- let ctx = Context :: new ( ) ;
814
+ let os = Os :: new ( ) ;
815
815
let mut manager = create_test_context_manager ( None ) . await ?;
816
816
let hook = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
817
817
818
- manager. add_hook ( & ctx , "test_hook" . to_string ( ) , hook, false ) . await ?;
818
+ manager. add_hook ( & os , "test_hook" . to_string ( ) , hook, false ) . await ?;
819
819
820
820
// Test removing existing hook
821
- manager. remove_hook ( & ctx , "test_hook" , false ) . await ?;
821
+ manager. remove_hook ( & os , "test_hook" , false ) . await ?;
822
822
assert ! ( !manager. profile_config. hooks. contains_key( "test_hook" ) ) ;
823
823
824
824
// Test removing non-existent hook
825
- assert ! ( manager. remove_hook( & ctx , "test_hook" , false ) . await . is_err( ) ) ;
825
+ assert ! ( manager. remove_hook( & os , "test_hook" , false ) . await . is_err( ) ) ;
826
826
827
827
Ok ( ( ) )
828
828
}
829
829
830
830
#[ tokio:: test]
831
831
async fn test_set_hook_disabled ( ) -> Result < ( ) > {
832
- let ctx = Context :: new ( ) ;
832
+ let os = Os :: new ( ) ;
833
833
let mut manager = create_test_context_manager ( None ) . await ?;
834
834
let hook = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
835
835
836
- manager. add_hook ( & ctx , "test_hook" . to_string ( ) , hook, false ) . await ?;
836
+ manager. add_hook ( & os , "test_hook" . to_string ( ) , hook, false ) . await ?;
837
837
838
838
// Test disabling hook
839
- manager. set_hook_disabled ( & ctx , "test_hook" , false , true ) . await ?;
839
+ manager. set_hook_disabled ( & os , "test_hook" , false , true ) . await ?;
840
840
assert ! ( manager. profile_config. hooks. get( "test_hook" ) . unwrap( ) . disabled) ;
841
841
842
842
// Test enabling hook
843
- manager. set_hook_disabled ( & ctx , "test_hook" , false , false ) . await ?;
843
+ manager. set_hook_disabled ( & os , "test_hook" , false , false ) . await ?;
844
844
assert ! ( !manager. profile_config. hooks. get( "test_hook" ) . unwrap( ) . disabled) ;
845
845
846
846
// Test with non-existent hook
847
847
assert ! (
848
848
manager
849
- . set_hook_disabled( & ctx , "nonexistent" , false , true )
849
+ . set_hook_disabled( & os , "nonexistent" , false , true )
850
850
. await
851
851
. is_err( )
852
852
) ;
@@ -856,34 +856,34 @@ mod tests {
856
856
857
857
#[ tokio:: test]
858
858
async fn test_set_all_hooks_disabled ( ) -> Result < ( ) > {
859
- let ctx = Context :: new ( ) ;
859
+ let os = Os :: new ( ) ;
860
860
let mut manager = create_test_context_manager ( None ) . await ?;
861
861
let hook1 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
862
862
let hook2 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
863
863
864
- manager. add_hook ( & ctx , "hook1" . to_string ( ) , hook1, false ) . await ?;
865
- manager. add_hook ( & ctx , "hook2" . to_string ( ) , hook2, false ) . await ?;
864
+ manager. add_hook ( & os , "hook1" . to_string ( ) , hook1, false ) . await ?;
865
+ manager. add_hook ( & os , "hook2" . to_string ( ) , hook2, false ) . await ?;
866
866
867
867
// Test disabling all hooks
868
- manager. set_all_hooks_disabled ( & ctx , false , true ) . await ?;
868
+ manager. set_all_hooks_disabled ( & os , false , true ) . await ?;
869
869
assert ! ( manager. profile_config. hooks. values( ) . all( |h| h. disabled) ) ;
870
870
871
871
// Test enabling all hooks
872
- manager. set_all_hooks_disabled ( & ctx , false , false ) . await ?;
872
+ manager. set_all_hooks_disabled ( & os , false , false ) . await ?;
873
873
assert ! ( manager. profile_config. hooks. values( ) . all( |h| !h. disabled) ) ;
874
874
875
875
Ok ( ( ) )
876
876
}
877
877
878
878
#[ tokio:: test]
879
879
async fn test_run_hooks ( ) -> Result < ( ) > {
880
- let ctx = Context :: new ( ) ;
880
+ let os = Os :: new ( ) ;
881
881
let mut manager = create_test_context_manager ( None ) . await ?;
882
882
let hook1 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
883
883
let hook2 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
884
884
885
- manager. add_hook ( & ctx , "hook1" . to_string ( ) , hook1, false ) . await ?;
886
- manager. add_hook ( & ctx , "hook2" . to_string ( ) , hook2, false ) . await ?;
885
+ manager. add_hook ( & os , "hook1" . to_string ( ) , hook1, false ) . await ?;
886
+ manager. add_hook ( & os , "hook2" . to_string ( ) , hook2, false ) . await ?;
887
887
888
888
// Run the hooks
889
889
let results = manager. run_hooks ( & mut vec ! [ ] ) . await . unwrap ( ) ;
@@ -894,20 +894,20 @@ mod tests {
894
894
895
895
#[ tokio:: test]
896
896
async fn test_hooks_across_profiles ( ) -> Result < ( ) > {
897
- let ctx = Context :: new ( ) ;
897
+ let os = Os :: new ( ) ;
898
898
let mut manager = create_test_context_manager ( None ) . await ?;
899
899
let hook1 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
900
900
let hook2 = Hook :: new_inline_hook ( HookTrigger :: ConversationStart , "echo test" . to_string ( ) ) ;
901
901
902
- manager. add_hook ( & ctx , "profile_hook" . to_string ( ) , hook1, false ) . await ?;
903
- manager. add_hook ( & ctx , "global_hook" . to_string ( ) , hook2, true ) . await ?;
902
+ manager. add_hook ( & os , "profile_hook" . to_string ( ) , hook1, false ) . await ?;
903
+ manager. add_hook ( & os , "global_hook" . to_string ( ) , hook2, true ) . await ?;
904
904
905
905
let results = manager. run_hooks ( & mut vec ! [ ] ) . await . unwrap ( ) ;
906
906
assert_eq ! ( results. len( ) , 2 ) ; // Should include both hooks
907
907
908
908
// Create and switch to a new profile
909
- manager. create_profile ( & ctx , "test_profile" ) . await ?;
910
- manager. switch_profile ( & ctx , "test_profile" ) . await ?;
909
+ manager. create_profile ( & os , "test_profile" ) . await ?;
910
+ manager. switch_profile ( & os , "test_profile" ) . await ?;
911
911
912
912
let results = manager. run_hooks ( & mut vec ! [ ] ) . await . unwrap ( ) ;
913
913
assert_eq ! ( results. len( ) , 1 ) ; // Should include global hook
0 commit comments