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