Skip to main content

agent_engine/tools/shell/
config.rs

1//! Shell session configuration: the fixed limits interactive shell sessions
2//! run with. Not configurable (the `shell.*` config keys were removed in
3//! 0.12.0; they were never read).
4
5use std::time::Duration;
6
7/// Configuration for interactive shell sessions.
8#[derive(Debug, Clone)]
9pub struct ShellConfig {
10    pub max_sessions: usize,
11    pub idle_timeout: Duration,
12    pub readiness_timeout_ms: u64,
13    pub max_readiness_timeout_ms: u64,
14    pub default_rows: u16,
15    pub default_cols: u16,
16    pub prompt_patterns: Vec<String>,
17    pub readiness_strategy: String,
18    pub max_output: usize,
19}
20
21impl Default for ShellConfig {
22    fn default() -> Self {
23        Self {
24            max_sessions: 5,
25            idle_timeout: Duration::from_secs(600),
26            readiness_timeout_ms: 300,
27            max_readiness_timeout_ms: 10_000,
28            default_rows: 24,
29            default_cols: 80,
30            prompt_patterns: default_prompt_patterns(),
31            readiness_strategy: "hybrid".to_string(),
32            max_output: 30000,
33        }
34    }
35}
36
37fn default_prompt_patterns() -> Vec<String> {
38    vec![
39        r"[$#%»] $".into(),
40        r"[$#%»]\s*$".into(),
41        r"\(gdb\)\s*$".into(),
42        r">>>\s*$".into(),
43        r"\.\.\.\:\s*$".into(),
44        r"In \[\d+\]:\s*$".into(),
45        r"irb.*>\s*$".into(),
46        r"mysql>\s*$".into(),
47        r"postgres[=#]>\s*$".into(),
48        r"Password:\s*$".into(),
49        r"\[Y/n\]\s*$".into(),
50        r"\(yes/no.*\)\?\s*$".into(),
51        r"% $".into(),
52        r"% \s*$".into(),
53        r"root@[\w.-]+:[/~].*# $".into(),
54        r"[\w.-]+@[\w.-]+:[/~].*\$ $".into(),
55        r"Enter passphrase.*:\s*$".into(),
56        r"Token:\s*$".into(),
57        r"Verification code:\s*$".into(),
58    ]
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_shell_config_default() {
67        let config = ShellConfig::default();
68        assert_eq!(config.max_sessions, 5);
69        assert_eq!(config.idle_timeout, Duration::from_secs(600));
70        assert_eq!(config.readiness_timeout_ms, 300);
71        assert_eq!(config.max_readiness_timeout_ms, 10_000);
72        assert_eq!(config.default_rows, 24);
73        assert_eq!(config.default_cols, 80);
74        assert_eq!(config.prompt_patterns.len(), 19);
75    }
76}