j_agent/agent/
thread_identity.rs1use crate::permission::queue::AgentType;
7use std::cell::RefCell;
8use std::path::{Path, PathBuf};
9
10thread_local! {
13 static CURRENT_AGENT_NAME: RefCell<String> = RefCell::new("Main".to_string());
15 static CURRENT_AGENT_TYPE: RefCell<AgentType> = const { RefCell::new(AgentType::Main) };
17 static THREAD_CWD: RefCell<Option<PathBuf>> = const { RefCell::new(None) };
19}
20
21pub fn set_current_agent_name(name: &str) {
28 CURRENT_AGENT_NAME.with(|cell| {
29 *cell.borrow_mut() = name.to_string();
30 });
31}
32
33pub fn set_current_agent_type(agent_type: AgentType) {
35 CURRENT_AGENT_TYPE.with(|cell: &RefCell<AgentType>| {
36 *cell.borrow_mut() = agent_type;
37 });
38}
39
40pub fn current_agent_name() -> String {
45 CURRENT_AGENT_NAME.with(|cell| cell.borrow().clone())
46}
47
48pub fn current_agent_type() -> AgentType {
50 CURRENT_AGENT_TYPE.with(|cell: &RefCell<AgentType>| cell.borrow().clone())
51}
52
53pub fn set_thread_cwd(path: &Path) {
57 THREAD_CWD.with(|cell| {
58 *cell.borrow_mut() = Some(path.to_path_buf());
59 });
60}
61
62pub fn thread_cwd() -> Option<PathBuf> {
64 THREAD_CWD.with(|cell| cell.borrow().clone())
65}
66
67pub fn clear_thread_cwd() {
69 THREAD_CWD.with(|cell| {
70 *cell.borrow_mut() = None;
71 });
72}