vtcode_ui/tui/core_tui/app/session/
trust.rs1use crate::tui::core_tui::app::types::TrustMode;
2use hashbrown::{HashMap, HashSet};
3
4#[derive(Debug, Clone)]
5pub struct TrustSetting {
6 mode: TrustMode,
7 updated_at: String,
8}
9
10pub struct TrustManager {
11 settings: HashMap<String, TrustSetting>,
12 session_cache: HashSet<String>,
13}
14
15impl TrustManager {
16 fn new() -> Self {
17 Self {
18 settings: HashMap::new(),
19 session_cache: HashSet::new(),
20 }
21 }
22
23 pub fn check_auto_approve(&self, file_path: &str) -> bool {
24 if let Some(setting) = self.settings.get(file_path)
25 && matches!(setting.mode, TrustMode::AutoTrust)
26 {
27 return true;
28 }
29 self.session_cache.contains(file_path)
30 }
31
32 pub fn update_trust(&mut self, file_path: String, mode: TrustMode) {
33 let timestamp = chrono::Utc::now().to_rfc3339();
34 let setting = TrustSetting { mode, updated_at: timestamp };
35
36 match mode {
37 TrustMode::AutoTrust | TrustMode::Always => {
38 self.settings.insert(file_path, setting);
39 }
40 TrustMode::Session => {
41 self.session_cache.insert(file_path);
42 }
43 TrustMode::Once => {}
44 }
45 }
46
47 pub fn get_trust_mode(&self, file_path: &str) -> Option<TrustMode> {
48 self.settings.get(file_path).map(|s| s.mode)
49 }
50}
51
52impl Default for TrustManager {
53 fn default() -> Self {
54 Self::new()
55 }
56}