Skip to content

Commit a02c0c6

Browse files
authored
chore: rename context to os (#297)
* rename context to os * fix bad tests
1 parent 2732fbf commit a02c0c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+739
-903
lines changed

crates/chat-cli/src/cli/chat/cli/compact.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::cli::chat::{
66
ChatState,
77
};
88
use crate::database::Database;
9-
use crate::platform::Context;
9+
use crate::os::Os;
1010
use crate::telemetry::TelemetryThread;
1111

1212
#[deny(missing_docs)]
@@ -38,13 +38,13 @@ pub struct CompactArgs {
3838
impl CompactArgs {
3939
pub async fn execute(
4040
self,
41-
ctx: &Context,
41+
os: &Os,
4242
database: &mut Database,
4343
telemetry: &TelemetryThread,
4444
session: &mut ChatSession,
4545
) -> Result<ChatState, ChatError> {
4646
session
47-
.compact_history(ctx, database, telemetry, self.prompt, self.show_summary)
47+
.compact_history(os, database, telemetry, self.prompt, self.show_summary)
4848
.await
4949
}
5050
}

crates/chat-cli/src/cli/chat/cli/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::cli::chat::{
1818
ChatSession,
1919
ChatState,
2020
};
21-
use crate::platform::Context;
21+
use crate::os::Os;
2222

2323
#[deny(missing_docs)]
2424
#[derive(Debug, PartialEq, Subcommand)]
@@ -68,7 +68,7 @@ pub enum ContextSubcommand {
6868
}
6969

7070
impl ContextSubcommand {
71-
pub async fn execute(self, ctx: &Context, session: &mut ChatSession) -> Result<ChatState, ChatError> {
71+
pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
7272
let Some(context_manager) = &mut session.conversation.context_manager else {
7373
execute!(
7474
session.stderr,
@@ -104,7 +104,7 @@ impl ContextSubcommand {
104104
} else {
105105
for path in &context_manager.global_config.paths {
106106
execute!(session.stderr, style::Print(format!(" {} ", path)))?;
107-
if let Ok(context_files) = context_manager.get_context_files_by_path(ctx, path).await {
107+
if let Ok(context_files) = context_manager.get_context_files_by_path(os, path).await {
108108
execute!(
109109
session.stderr,
110110
style::SetForegroundColor(Color::Green),
@@ -140,7 +140,7 @@ impl ContextSubcommand {
140140
} else {
141141
for path in &context_manager.profile_config.paths {
142142
execute!(session.stderr, style::Print(format!(" {} ", path)))?;
143-
if let Ok(context_files) = context_manager.get_context_files_by_path(ctx, path).await {
143+
if let Ok(context_files) = context_manager.get_context_files_by_path(os, path).await {
144144
execute!(
145145
session.stderr,
146146
style::SetForegroundColor(Color::Green),
@@ -304,7 +304,7 @@ impl ContextSubcommand {
304304
}
305305
},
306306
Self::Add { global, force, paths } => {
307-
match context_manager.add_paths(ctx, paths.clone(), global, force).await {
307+
match context_manager.add_paths(os, paths.clone(), global, force).await {
308308
Ok(_) => {
309309
let target = if global { "global" } else { "profile" };
310310
execute!(
@@ -324,7 +324,7 @@ impl ContextSubcommand {
324324
},
325325
}
326326
},
327-
Self::Remove { global, paths } => match context_manager.remove_paths(ctx, paths.clone(), global).await {
327+
Self::Remove { global, paths } => match context_manager.remove_paths(os, paths.clone(), global).await {
328328
Ok(_) => {
329329
let target = if global { "global" } else { "profile" };
330330
execute!(
@@ -347,7 +347,7 @@ impl ContextSubcommand {
347347
)?;
348348
},
349349
},
350-
Self::Clear { global } => match context_manager.clear(ctx, global).await {
350+
Self::Clear { global } => match context_manager.clear(os, global).await {
351351
Ok(_) => {
352352
let target = if global {
353353
"global".to_string()

crates/chat-cli/src/cli/chat/cli/hooks.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::cli::chat::{
4747
ChatSession,
4848
ChatState,
4949
};
50-
use crate::platform::Context;
50+
use crate::os::Os;
5151

5252
const DEFAULT_TIMEOUT_MS: u64 = 30_000;
5353
const DEFAULT_MAX_OUTPUT_SIZE: usize = 1024 * 10;
@@ -404,9 +404,9 @@ pub struct HooksArgs {
404404
}
405405

406406
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> {
408408
if let Some(subcommand) = self.subcommand {
409-
return subcommand.execute(ctx, session).await;
409+
return subcommand.execute(os, session).await;
410410
}
411411

412412
let Some(context_manager) = &mut session.conversation.context_manager else {
@@ -530,7 +530,7 @@ pub enum HooksSubcommand {
530530
}
531531

532532
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> {
534534
let Some(context_manager) = &mut session.conversation.context_manager else {
535535
return Ok(ChatState::PromptUser {
536536
skip_printing_tools: true,
@@ -553,7 +553,7 @@ impl HooksSubcommand {
553553
};
554554

555555
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)
557557
.await;
558558
match result {
559559
Ok(_) => {
@@ -575,7 +575,7 @@ impl HooksSubcommand {
575575
}
576576
},
577577
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;
579579
match result {
580580
Ok(_) => {
581581
execute!(
@@ -596,7 +596,7 @@ impl HooksSubcommand {
596596
}
597597
},
598598
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;
600600
match result {
601601
Ok(_) => {
602602
execute!(
@@ -617,7 +617,7 @@ impl HooksSubcommand {
617617
}
618618
},
619619
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;
621621
match result {
622622
Ok(_) => {
623623
execute!(
@@ -639,7 +639,7 @@ impl HooksSubcommand {
639639
},
640640
Self::EnableAll { global } => {
641641
context_manager
642-
.set_all_hooks_disabled(ctx, global, false)
642+
.set_all_hooks_disabled(os, global, false)
643643
.await
644644
.map_err(map_chat_error)?;
645645
execute!(
@@ -651,7 +651,7 @@ impl HooksSubcommand {
651651
},
652652
Self::DisableAll { global } => {
653653
context_manager
654-
.set_all_hooks_disabled(ctx, global, true)
654+
.set_all_hooks_disabled(os, global, true)
655655
.await
656656
.map_err(map_chat_error)?;
657657
execute!(
@@ -782,26 +782,26 @@ mod tests {
782782

783783
#[tokio::test]
784784
async fn test_add_hook() -> Result<()> {
785-
let ctx = Context::new();
785+
let os = Os::new();
786786
let mut manager = create_test_context_manager(None).await?;
787787
let hook = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
788788

789789
// Test adding hook to profile config
790790
manager
791-
.add_hook(&ctx, "test_hook".to_string(), hook.clone(), false)
791+
.add_hook(&os, "test_hook".to_string(), hook.clone(), false)
792792
.await?;
793793
assert!(manager.profile_config.hooks.contains_key("test_hook"));
794794

795795
// Test adding hook to global config
796796
manager
797-
.add_hook(&ctx, "global_hook".to_string(), hook.clone(), true)
797+
.add_hook(&os, "global_hook".to_string(), hook.clone(), true)
798798
.await?;
799799
assert!(manager.global_config.hooks.contains_key("global_hook"));
800800

801801
// Test adding duplicate hook name
802802
assert!(
803803
manager
804-
.add_hook(&ctx, "test_hook".to_string(), hook, false)
804+
.add_hook(&os, "test_hook".to_string(), hook, false)
805805
.await
806806
.is_err()
807807
);
@@ -811,42 +811,42 @@ mod tests {
811811

812812
#[tokio::test]
813813
async fn test_remove_hook() -> Result<()> {
814-
let ctx = Context::new();
814+
let os = Os::new();
815815
let mut manager = create_test_context_manager(None).await?;
816816
let hook = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
817817

818-
manager.add_hook(&ctx, "test_hook".to_string(), hook, false).await?;
818+
manager.add_hook(&os, "test_hook".to_string(), hook, false).await?;
819819

820820
// Test removing existing hook
821-
manager.remove_hook(&ctx, "test_hook", false).await?;
821+
manager.remove_hook(&os, "test_hook", false).await?;
822822
assert!(!manager.profile_config.hooks.contains_key("test_hook"));
823823

824824
// 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());
826826

827827
Ok(())
828828
}
829829

830830
#[tokio::test]
831831
async fn test_set_hook_disabled() -> Result<()> {
832-
let ctx = Context::new();
832+
let os = Os::new();
833833
let mut manager = create_test_context_manager(None).await?;
834834
let hook = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
835835

836-
manager.add_hook(&ctx, "test_hook".to_string(), hook, false).await?;
836+
manager.add_hook(&os, "test_hook".to_string(), hook, false).await?;
837837

838838
// 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?;
840840
assert!(manager.profile_config.hooks.get("test_hook").unwrap().disabled);
841841

842842
// 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?;
844844
assert!(!manager.profile_config.hooks.get("test_hook").unwrap().disabled);
845845

846846
// Test with non-existent hook
847847
assert!(
848848
manager
849-
.set_hook_disabled(&ctx, "nonexistent", false, true)
849+
.set_hook_disabled(&os, "nonexistent", false, true)
850850
.await
851851
.is_err()
852852
);
@@ -856,34 +856,34 @@ mod tests {
856856

857857
#[tokio::test]
858858
async fn test_set_all_hooks_disabled() -> Result<()> {
859-
let ctx = Context::new();
859+
let os = Os::new();
860860
let mut manager = create_test_context_manager(None).await?;
861861
let hook1 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
862862
let hook2 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
863863

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?;
866866

867867
// Test disabling all hooks
868-
manager.set_all_hooks_disabled(&ctx, false, true).await?;
868+
manager.set_all_hooks_disabled(&os, false, true).await?;
869869
assert!(manager.profile_config.hooks.values().all(|h| h.disabled));
870870

871871
// Test enabling all hooks
872-
manager.set_all_hooks_disabled(&ctx, false, false).await?;
872+
manager.set_all_hooks_disabled(&os, false, false).await?;
873873
assert!(manager.profile_config.hooks.values().all(|h| !h.disabled));
874874

875875
Ok(())
876876
}
877877

878878
#[tokio::test]
879879
async fn test_run_hooks() -> Result<()> {
880-
let ctx = Context::new();
880+
let os = Os::new();
881881
let mut manager = create_test_context_manager(None).await?;
882882
let hook1 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
883883
let hook2 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
884884

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?;
887887

888888
// Run the hooks
889889
let results = manager.run_hooks(&mut vec![]).await.unwrap();
@@ -894,20 +894,20 @@ mod tests {
894894

895895
#[tokio::test]
896896
async fn test_hooks_across_profiles() -> Result<()> {
897-
let ctx = Context::new();
897+
let os = Os::new();
898898
let mut manager = create_test_context_manager(None).await?;
899899
let hook1 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
900900
let hook2 = Hook::new_inline_hook(HookTrigger::ConversationStart, "echo test".to_string());
901901

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?;
904904

905905
let results = manager.run_hooks(&mut vec![]).await.unwrap();
906906
assert_eq!(results.len(), 2); // Should include both hooks
907907

908908
// 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?;
911911

912912
let results = manager.run_hooks(&mut vec![]).await.unwrap();
913913
assert_eq!(results.len(), 1); // Should include global hook

0 commit comments

Comments
 (0)