vtcode_core/tools/registry/
pty.rs1use anyhow::{Result, anyhow};
2
3use super::ToolRegistry;
4
5impl ToolRegistry {
6 pub fn pty_config(&self) -> &crate::config::PtyConfig {
7 &self.pty_config
8 }
9
10 pub fn can_start_pty_session(&self) -> bool {
11 if !self.pty_config.enabled {
12 return false;
13 }
14 self.active_pty_sessions
15 .load(std::sync::atomic::Ordering::SeqCst)
16 < self.pty_config.max_sessions
17 }
18
19 pub fn start_pty_session(&self) -> Result<()> {
20 if !self.can_start_pty_session() {
21 return Err(anyhow!(
22 "Maximum PTY sessions ({}) exceeded. Current active sessions: {}",
23 self.pty_config.max_sessions,
24 self.active_pty_sessions
25 .load(std::sync::atomic::Ordering::SeqCst)
26 ));
27 }
28 self.active_pty_sessions
29 .fetch_add(1, std::sync::atomic::Ordering::SeqCst);
30 Ok(())
31 }
32
33 pub fn end_pty_session(&self) {
34 let current = self
35 .active_pty_sessions
36 .load(std::sync::atomic::Ordering::SeqCst);
37 if current > 0 {
38 self.active_pty_sessions
39 .fetch_sub(1, std::sync::atomic::Ordering::SeqCst);
40 }
41 }
42
43 pub fn active_pty_sessions(&self) -> usize {
44 self.active_pty_sessions
45 .load(std::sync::atomic::Ordering::SeqCst)
46 }
47}