-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.rs
More file actions
176 lines (162 loc) · 6.6 KB
/
Copy pathschema.rs
File metadata and controls
176 lines (162 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! The serde/clap schema shared by the three config sources.
//!
//! The same nested shape (`{ checks: { provider, model, effort, providers } }`)
//! is produced by the file loader, figment's `Env` provider, and the CLI
//! overrides, so figment can merge them by key path with `flag > env > file`
//! precedence. See [`super::load`].
use std::path::PathBuf;
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
/// A model provider. Serialises to its lowercase name (`anthropic`, `openai`,
/// `gemini`) in every source — TOML, `MULTI_CHECKS_PROVIDER`, and `--provider`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, ValueEnum)]
#[serde(rename_all = "lowercase")]
pub enum ProviderKind {
Anthropic,
#[value(name = "openai")]
OpenAi,
Gemini,
}
impl ProviderKind {
/// The canonical lowercase provider name, used as the registry key and as
/// the `[checks.providers.<name>]` table name.
pub const fn as_str(self) -> &'static str {
match self {
ProviderKind::Anthropic => "anthropic",
ProviderKind::OpenAi => "openai",
ProviderKind::Gemini => "gemini",
}
}
}
/// The agent effort level. Carried through configuration and consumed by the
/// executor, where it maps to a thinking-token budget.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ValueEnum)]
#[serde(rename_all = "lowercase")]
pub enum Effort {
Low,
Medium,
High,
}
/// Which execution engine runs each check. The default is the in-process
/// [`cersei`](crate::checks::executor::cersei) agent; `claude` selects the
/// legacy `claude -p` shell-out fallback, kept selectable during the migration
/// (MULTI-1367) so verdicts from both can be compared before the fallback is
/// retired.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ValueEnum)]
#[serde(rename_all = "lowercase")]
pub enum ExecutorKind {
/// The in-process `cersei-agent` executor (default).
Cersei,
/// The legacy `claude -p` shell-out fallback.
Claude,
}
/// The whole config file, of which only the `[checks]` table concerns us. Other
/// top-level keys (the legacy manifest's `workspace`/`application`/`config`) are
/// ignored rather than rejected, so a single `MultiTool.toml` can carry both.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RootFileConfig {
#[serde(default)]
pub checks: ChecksSection,
}
/// The `[checks]` table. Every selectable field is optional so an unset value in
/// a higher-precedence layer contributes nothing to the merge.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChecksSection {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub provider: Option<ProviderKind>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub effort: Option<Effort>,
/// Which execution engine runs each check (`cersei` by default).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub executor: Option<ExecutorKind>,
/// Maximum number of checks executed concurrently (default: the number of
/// available CPU cores).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub concurrency: Option<usize>,
/// Where to write the opt-in session-trace archive. When set, every check
/// execution's agent session is captured and bundled into this `.tar.gz`
/// (see [`crate::checks::trace_archive`]); unset (the default) disables
/// capture entirely.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trace_archive: Option<PathBuf>,
/// Optional, non-secret per-provider base-URL overrides.
#[serde(default)]
pub providers: ProvidersSection,
}
/// `[checks.providers]` — at most one table per provider, each carrying an
/// optional `base_url`. Credentials never live here (env-only).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProvidersSection {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub anthropic: Option<ProviderOverrides>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub openai: Option<ProviderOverrides>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gemini: Option<ProviderOverrides>,
}
impl ProvidersSection {
/// The configured base-URL override for `provider`, if any.
pub fn base_url(&self, provider: ProviderKind) -> Option<&str> {
let table = match provider {
ProviderKind::Anthropic => &self.anthropic,
ProviderKind::OpenAi => &self.openai,
ProviderKind::Gemini => &self.gemini,
};
table.as_ref().and_then(|t| t.base_url.as_deref())
}
}
/// The non-secret overrides for one provider.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProviderOverrides {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub base_url: Option<String>,
}
/// The flag layer, fed into figment via `Serialized::defaults`. Only the values
/// the user actually passed are serialised (`skip_serializing_if`), so unset
/// flags don't clobber the env/file layers — the clap-defaults gotcha the
/// ticket calls out. This is why the corresponding CLI fields carry no
/// `default_value`.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CliOverrides {
pub checks: CliChecksOverrides,
}
/// The `[checks]` subset settable from flags.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CliChecksOverrides {
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<ProviderKind>,
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<Effort>,
#[serde(skip_serializing_if = "Option::is_none")]
pub executor: Option<ExecutorKind>,
#[serde(skip_serializing_if = "Option::is_none")]
pub concurrency: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trace_archive: Option<PathBuf>,
}
impl CliOverrides {
/// Build the flag layer from the individual CLI values.
pub fn new(
provider: Option<ProviderKind>,
model: Option<String>,
effort: Option<Effort>,
executor: Option<ExecutorKind>,
concurrency: Option<usize>,
trace_archive: Option<PathBuf>,
) -> Self {
Self {
checks: CliChecksOverrides {
provider,
model,
effort,
executor,
concurrency,
trace_archive,
},
}
}
}