Skip to main content

scv_tools/
config.rs

1//! What a session's built-in tools are configured with: limits, the
2//! delegation context, and each delegated agent's adapter settings.
3
4use std::{collections::HashMap, ffi::OsString, path::PathBuf, sync::Arc, time::Duration};
5
6use crate::{
7    builtin::chat_attach,
8    delegate::{
9        adapters::{OutputFormat, Resume, Transport},
10        background,
11        conversation::ConversationLimits,
12        records::DelegationRegistry,
13    },
14};
15
16/// Limits and shared state for one session's tools.
17#[derive(Debug, Clone)]
18pub struct ToolsConfig {
19    /// Default `bash` timeout when a call does not choose one.
20    pub command_timeout: Duration,
21    /// Default native-agent timeout when a call does not choose one.
22    pub agent_timeout: Duration,
23    /// The longest timeout any single call may request.
24    pub max_timeout: Duration,
25    pub output_limit_bytes: usize,
26    pub max_read_bytes: usize,
27    pub max_write_bytes: usize,
28    /// Agent tools are offered only below this delegation depth.
29    pub max_delegation_depth: u32,
30    /// How many delegated conversations a session remembers, and for how long.
31    pub conversations: ConversationLimits,
32    /// Records delegated runs for listing and cleanup; `None` runs them untracked.
33    pub delegation: Option<DelegationContext>,
34    /// Background jobs an agent call may start at once (`background: true`);
35    /// 0 turns background calls and `agent_wait` / `agent_status` /
36    /// `agent_cancel` off.
37    pub max_background: usize,
38    /// The session's background job store, when the server reports finished
39    /// jobs; otherwise the registry makes its own.
40    pub background: Option<Arc<background::BackgroundJobs>>,
41    /// Offers `chat_attach` when the session answers on a chat channel.
42    pub chat_attach: Option<chat_attach::ChatAttachConfig>,
43}
44
45impl Default for ToolsConfig {
46    fn default() -> Self {
47        Self {
48            command_timeout: Duration::from_secs(600),
49            agent_timeout: Duration::from_secs(3600),
50            max_timeout: Duration::from_secs(14400),
51            output_limit_bytes: 64 * 1024,
52            max_read_bytes: 256 * 1024,
53            max_write_bytes: 1024 * 1024,
54            max_delegation_depth: 2,
55            conversations: ConversationLimits {
56                max: 8,
57                idle: Duration::from_secs(86400),
58            },
59            delegation: None,
60            max_background: 2,
61            background: None,
62            chat_attach: None,
63        }
64    }
65}
66
67/// The registry and parent session that delegated runs are recorded under.
68#[derive(Debug, Clone)]
69pub struct DelegationContext {
70    pub registry: Arc<DelegationRegistry>,
71    pub session: String,
72    /// Delegation depth the session's client declared (0 for a direct
73    /// client). Runs count from the larger of this and the process's own.
74    pub depth: u32,
75}
76
77impl DelegationContext {
78    /// The depth delegated runs of this session start from.
79    pub(crate) fn owner_depth(&self) -> u32 {
80        self.registry.depth().max(self.depth)
81    }
82}
83
84#[derive(Debug, Clone)]
85pub struct AgentAdapterConfig {
86    pub command: String,
87    pub args: Vec<String>,
88    /// Arguments placed immediately before the prompt, for CLIs that take the
89    /// prompt as a flag value.
90    pub prompt_args: Vec<String>,
91    /// The CLI's own full-autonomy arguments, placed after `args`, when the
92    /// user configured `permissions = "full"`; the approval summary says so.
93    pub full_permission_args: Option<Vec<String>>,
94    /// Arguments appended for a per-call model; `{model}` is substituted.
95    /// Empty means the adapter does not offer model selection.
96    pub model_args: Vec<String>,
97    /// Arguments appended for a per-call effort; `{effort}` is substituted.
98    /// Empty means the adapter does not offer effort selection.
99    pub effort_args: Vec<String>,
100    /// Describes the `model` argument for the calling model.
101    pub model_hint: String,
102    /// Environment for the nested process. SCV supplies an instance-private home.
103    pub environment: Vec<(OsString, OsString)>,
104    /// Per-user install directories searched when `command` is not on `PATH`.
105    pub search_dirs: Vec<PathBuf>,
106    /// What the CLI prints, and so how its reply is read.
107    pub output: OutputFormat,
108    /// How a conversation with the CLI is continued, if it can be.
109    pub resume: Resume,
110    /// SCV's private home for this agent, for files SCV hands the CLI.
111    pub home: Option<PathBuf>,
112    /// How SCV talks to the agent.
113    pub transport: Transport,
114    /// The agent's ACP server, when `[agents.<name>] transport` allows it and
115    /// the adapter table has one.
116    pub acp: Option<AcpAgentLaunch>,
117    /// The user's note on when to choose this agent (`[agents.<name>]
118    /// use_for`), added to its tool description.
119    pub use_for: Option<String>,
120    /// Default model to pass when the work matches `use_for` (or on every
121    /// call to this agent, when `use_for` is unset).
122    pub model: Option<String>,
123    /// Default effort to pass the same way as `model`.
124    pub effort: Option<String>,
125}
126
127/// An agent's Agent Client Protocol server, resolved from its adapter-table
128/// entry and `[agents.<name>] transport`.
129#[derive(Debug, Clone)]
130pub struct AcpAgentLaunch {
131    pub command: String,
132    /// Arguments with the `permissions = "full"` switches already applied.
133    pub args: Vec<String>,
134    /// The ACP session mode that grants full permissions, selected in every
135    /// new session when `permissions = "full"`.
136    pub full_mode: Option<String>,
137    /// Extra environment for the ACP server, such as permission settings the
138    /// server reads only from its environment.
139    pub environment: Vec<(OsString, OsString)>,
140    /// `transport = "acp"`: never fall back to one CLI process per turn, so
141    /// the agent is not offered while its ACP server is missing.
142    pub required: bool,
143}
144
145pub type SkillMap = HashMap<String, PathBuf>;