-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.rs
More file actions
500 lines (454 loc) · 16.2 KB
/
types.rs
File metadata and controls
500 lines (454 loc) · 16.2 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
//! Common types for the agentic pipeline compiler.
//!
//! This module defines the front matter grammar that is shared across all compile targets.
use serde::Deserialize;
use std::collections::HashMap;
/// Target platform for compiled pipeline
#[derive(Debug, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum CompileTarget {
/// Standalone pipeline with full feature set (default)
#[default]
Standalone,
/// 1ES Pipeline Template integration using agencyJob
#[serde(rename = "1es")]
OneES,
}
/// Pool configuration - accepts both string and object formats
///
/// Examples:
/// ```yaml
/// # Simple string format (works for both targets)
/// pool: AZS-1ES-L-MMS-ubuntu-22.04
///
/// # Object format (required for 1ES if specifying os)
/// pool:
/// name: AZS-1ES-L-MMS-ubuntu-22.04
/// os: linux
/// ```
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum PoolConfig {
/// Simple pool name string
Name(String),
/// Full pool configuration object
Full(PoolConfigFull),
}
impl Default for PoolConfig {
fn default() -> Self {
PoolConfig::Name("AZS-1ES-L-MMS-ubuntu-22.04".to_string())
}
}
impl PoolConfig {
/// Get the pool name
pub fn name(&self) -> &str {
match self {
PoolConfig::Name(name) => name,
PoolConfig::Full(full) => &full.name,
}
}
/// Get the OS (defaults to "linux" if not specified)
pub fn os(&self) -> &str {
match self {
PoolConfig::Name(_) => "linux",
PoolConfig::Full(full) => full.os.as_deref().unwrap_or("linux"),
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct PoolConfigFull {
pub name: String,
#[serde(default)]
pub os: Option<String>,
}
/// Schedule configuration - accepts both string and object formats
///
/// Examples:
/// ```yaml
/// # Simple string format (defaults to main branch only)
/// schedule: daily around 14:00
///
/// # Object format (with custom branch filtering)
/// schedule:
/// run: daily around 14:00
/// branches:
/// - main
/// - release/*
/// ```
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum ScheduleConfig {
/// Simple schedule expression string
Simple(String),
/// Schedule with options (branch filtering)
WithOptions(ScheduleOptions),
}
impl ScheduleConfig {
/// Get the schedule expression string
pub fn expression(&self) -> &str {
match self {
ScheduleConfig::Simple(s) => s,
ScheduleConfig::WithOptions(opts) => &opts.run,
}
}
/// Get the branches filter (empty means default to "main" branch)
pub fn branches(&self) -> &[String] {
match self {
ScheduleConfig::Simple(_) => &[],
ScheduleConfig::WithOptions(opts) => &opts.branches,
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct ScheduleOptions {
/// Fuzzy schedule expression (e.g., "daily around 14:00")
pub run: String,
/// Branches to restrict the schedule to (empty = defaults to "main")
#[serde(default)]
pub branches: Vec<String>,
}
/// Engine configuration - accepts both string and object formats
///
/// Examples:
/// ```yaml
/// # Simple string format (just a model name)
/// engine: claude-opus-4.5
///
/// # Object format (with additional options)
/// engine:
/// model: claude-opus-4.5
/// max-turns: 50
/// timeout-minutes: 30
/// ```
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum EngineConfig {
/// Simple model name string
Simple(String),
/// Full engine configuration object
Full(EngineOptions),
}
impl Default for EngineConfig {
fn default() -> Self {
EngineConfig::Simple(default_model())
}
}
impl EngineConfig {
/// Get the model name
pub fn model(&self) -> &str {
match self {
EngineConfig::Simple(s) => s,
EngineConfig::Full(opts) => opts.model.as_deref().unwrap_or("claude-opus-4.5"),
}
}
/// Get the max turns setting
pub fn max_turns(&self) -> Option<u32> {
match self {
EngineConfig::Simple(_) => None,
EngineConfig::Full(opts) => opts.max_turns,
}
}
/// Get the timeout in minutes
pub fn timeout_minutes(&self) -> Option<u32> {
match self {
EngineConfig::Simple(_) => None,
EngineConfig::Full(opts) => opts.timeout_minutes,
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct EngineOptions {
/// AI model to use (defaults to claude-opus-4.5)
#[serde(default)]
pub model: Option<String>,
/// Maximum number of chat iterations per run
#[serde(default, rename = "max-turns")]
pub max_turns: Option<u32>,
/// Workflow timeout in minutes
#[serde(default, rename = "timeout-minutes")]
pub timeout_minutes: Option<u32>,
}
/// Tools configuration for the agent
///
/// Controls which tools are available and their settings.
/// If not specified, defaults are used.
#[derive(Debug, Deserialize, Clone, Default)]
pub struct ToolsConfig {
/// Bash command allow-list. If empty/not set, defaults to safe commands.
/// Use [":*"] for unrestricted access.
#[serde(default)]
pub bash: Option<Vec<String>>,
/// Enable the file editing tool (default: true)
#[serde(default)]
pub edit: Option<bool>,
}
/// Front matter configuration from the input markdown file
#[derive(Debug, Deserialize)]
pub struct FrontMatter {
/// Agent name (required)
pub name: String,
/// One-line description (required)
pub description: String,
/// Target platform: "standalone" (default) or "1es"
#[serde(default)]
pub target: CompileTarget,
/// Fuzzy schedule configuration
#[serde(default)]
pub schedule: Option<ScheduleConfig>,
/// Workspace setting: "root" or "repo" (auto-computed if not set)
#[serde(default)]
pub workspace: Option<String>,
/// Agent pool configuration
#[serde(default)]
pub pool: Option<PoolConfig>,
/// AI engine configuration (defaults to claude-opus-4.5)
#[serde(default)]
pub engine: EngineConfig,
/// Tools configuration
#[serde(default)]
pub tools: Option<ToolsConfig>,
/// Additional repository resources
#[serde(default)]
pub repositories: Vec<Repository>,
/// Repositories to checkout (subset of repositories)
#[serde(default)]
pub checkout: Vec<String>,
/// MCP server configurations
#[serde(default, rename = "mcp-servers")]
pub mcp_servers: HashMap<String, McpConfig>,
/// Per-tool configuration for safe outputs
#[serde(default, rename = "safe-outputs")]
pub safe_outputs: HashMap<String, serde_json::Value>,
/// Pipeline trigger configuration
#[serde(default)]
pub triggers: Option<TriggerConfig>,
/// Network policy for standalone target (ignored in 1ES)
#[serde(default)]
pub network: Option<NetworkConfig>,
/// Custom steps before agent runs (same job)
#[serde(default)]
pub steps: Vec<serde_yaml::Value>,
/// Custom steps after agent runs (same job)
#[serde(default, rename = "post-steps")]
pub post_steps: Vec<serde_yaml::Value>,
/// Separate setup job before agentic task
#[serde(default)]
pub setup: Vec<serde_yaml::Value>,
/// Separate teardown job after safe outputs
#[serde(default)]
pub teardown: Vec<serde_yaml::Value>,
/// Azure Resource Manager service connection for read-only ADO token
/// When set, uses AzureCLI@2 to mint an ADO-scoped token from this connection.
/// When unset, ADO access tokens are omitted from the copilot invocation.
#[serde(default, rename = "read-only-service-connection")]
pub read_only_service_connection: Option<String>,
/// Workflow-level environment variables
#[serde(default)]
pub env: HashMap<String, String>,
}
fn default_model() -> String {
"claude-opus-4.5".to_string()
}
/// Network policy configuration (standalone target only)
///
/// Network isolation uses AWF (Agentic Workflow Firewall) for L7 domain whitelisting.
/// The domain allowlist is dynamically generated based on:
/// - Core Azure DevOps/GitHub endpoints (always included)
/// - MCP-specific endpoints for each enabled MCP
/// - User-specified additional hosts from `allow` field
#[derive(Debug, Deserialize, Clone, Default)]
pub struct NetworkConfig {
/// Additional allowed host patterns (supports wildcards like *.example.com)
/// Core Azure DevOps and GitHub hosts are always allowed.
#[serde(default)]
pub allow: Vec<String>,
/// Blocked host patterns (takes precedence over allow)
#[serde(default)]
pub blocked: Vec<String>,
}
/// Repository resource definition
#[derive(Debug, Deserialize, Clone)]
pub struct Repository {
pub repository: String,
#[serde(rename = "type")]
pub repo_type: String,
pub name: String,
#[serde(default = "default_ref")]
#[serde(rename = "ref")]
pub repo_ref: String,
}
fn default_ref() -> String {
"refs/heads/main".to_string()
}
/// MCP configuration - can be `true` for simple enablement or an object with options
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum McpConfig {
Enabled(bool),
WithOptions(McpOptions),
}
/// Detailed MCP options
#[derive(Debug, Deserialize, Clone, Default)]
pub struct McpOptions {
/// Custom command (if present, it's a custom MCP - standalone only)
#[serde(default)]
pub command: Option<String>,
/// Command arguments
#[serde(default)]
pub args: Vec<String>,
/// Allowed tool names (for firewall filtering)
#[serde(default)]
pub allowed: Vec<String>,
/// Environment variables
#[serde(default)]
pub env: HashMap<String, String>,
/// Service connection name (1ES only, auto-generated if not specified)
#[serde(default, rename = "service-connection")]
pub service_connection: Option<String>,
}
/// Trigger configuration for the pipeline
#[derive(Debug, Deserialize, Clone, Default)]
pub struct TriggerConfig {
/// Pipeline completion trigger
#[serde(default)]
pub pipeline: Option<PipelineTrigger>,
}
/// Pipeline completion trigger configuration
#[derive(Debug, Deserialize, Clone)]
pub struct PipelineTrigger {
/// The name of the source pipeline that triggers this one
pub name: String,
/// Optional project name if the pipeline is in a different project
#[serde(default)]
pub project: Option<String>,
/// Branches to trigger on (empty = any branch)
#[serde(default)]
pub branches: Vec<String>,
}
#[cfg(test)]
mod tests {
use super::*;
// ─── PoolConfig deserialization ──────────────────────────────────────────
#[test]
fn test_pool_config_string_form() {
let yaml = "pool: MyPool";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let pool: PoolConfig = serde_yaml::from_value(fm["pool"].clone()).unwrap();
assert_eq!(pool.name(), "MyPool");
assert_eq!(pool.os(), "linux"); // default
}
#[test]
fn test_pool_config_object_form_with_os() {
let yaml = "pool:\n name: WinPool\n os: windows";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let pool: PoolConfig = serde_yaml::from_value(fm["pool"].clone()).unwrap();
assert_eq!(pool.name(), "WinPool");
assert_eq!(pool.os(), "windows");
}
#[test]
fn test_pool_config_object_form_default_os() {
let yaml = "pool:\n name: LinuxPool";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let pool: PoolConfig = serde_yaml::from_value(fm["pool"].clone()).unwrap();
assert_eq!(pool.name(), "LinuxPool");
assert_eq!(pool.os(), "linux");
}
#[test]
fn test_pool_config_default() {
let pool = PoolConfig::default();
assert_eq!(pool.name(), "AZS-1ES-L-MMS-ubuntu-22.04");
assert_eq!(pool.os(), "linux");
}
// ─── ScheduleConfig deserialization ─────────────────────────────────────
#[test]
fn test_schedule_config_simple_has_empty_branches() {
let sc = ScheduleConfig::Simple("daily around 14:00".to_string());
assert_eq!(sc.expression(), "daily around 14:00");
assert!(sc.branches().is_empty());
}
#[test]
fn test_schedule_config_with_options_returns_branches() {
let yaml = "run: weekly on monday\nbranches:\n - main\n - release/*";
let opts: ScheduleOptions = serde_yaml::from_str(yaml).unwrap();
let sc = ScheduleConfig::WithOptions(opts);
assert_eq!(sc.expression(), "weekly on monday");
assert_eq!(sc.branches(), &["main", "release/*"]);
}
#[test]
fn test_schedule_config_with_options_empty_branches() {
let yaml = "run: hourly";
let opts: ScheduleOptions = serde_yaml::from_str(yaml).unwrap();
let sc = ScheduleConfig::WithOptions(opts);
assert_eq!(sc.expression(), "hourly");
assert!(sc.branches().is_empty());
}
#[test]
fn test_schedule_config_deserialized_as_simple_string() {
let yaml = "schedule: daily around 14:00";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let sc: ScheduleConfig = serde_yaml::from_value(fm["schedule"].clone()).unwrap();
assert_eq!(sc.expression(), "daily around 14:00");
assert!(sc.branches().is_empty());
}
#[test]
fn test_schedule_config_deserialized_as_object() {
let yaml = "schedule:\n run: weekly on friday\n branches:\n - main\n - develop";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let sc: ScheduleConfig = serde_yaml::from_value(fm["schedule"].clone()).unwrap();
assert_eq!(sc.expression(), "weekly on friday");
assert_eq!(sc.branches(), &["main", "develop"]);
}
// ─── EngineConfig deserialization ────────────────────────────────────────
#[test]
fn test_engine_config_simple_string() {
let ec = EngineConfig::Simple("gpt-5.1".to_string());
assert_eq!(ec.model(), "gpt-5.1");
assert_eq!(ec.max_turns(), None);
assert_eq!(ec.timeout_minutes(), None);
}
#[test]
fn test_engine_config_full_object() {
let yaml = "model: claude-sonnet-4.5\nmax-turns: 50\ntimeout-minutes: 30";
let opts: EngineOptions = serde_yaml::from_str(yaml).unwrap();
let ec = EngineConfig::Full(opts);
assert_eq!(ec.model(), "claude-sonnet-4.5");
assert_eq!(ec.max_turns(), Some(50));
assert_eq!(ec.timeout_minutes(), Some(30));
}
#[test]
fn test_engine_config_full_object_partial_fields() {
let yaml = "max-turns: 10";
let opts: EngineOptions = serde_yaml::from_str(yaml).unwrap();
let ec = EngineConfig::Full(opts);
// model defaults to claude-opus-4.5 when not specified
assert_eq!(ec.model(), "claude-opus-4.5");
assert_eq!(ec.max_turns(), Some(10));
assert_eq!(ec.timeout_minutes(), None);
}
#[test]
fn test_engine_config_default() {
let ec = EngineConfig::default();
assert_eq!(ec.model(), "claude-opus-4.5");
assert_eq!(ec.max_turns(), None);
assert_eq!(ec.timeout_minutes(), None);
}
#[test]
fn test_engine_config_deserialized_as_string() {
let yaml = "engine: my-custom-model";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let ec: EngineConfig = serde_yaml::from_value(fm["engine"].clone()).unwrap();
assert_eq!(ec.model(), "my-custom-model");
assert_eq!(ec.max_turns(), None);
assert_eq!(ec.timeout_minutes(), None);
}
#[test]
fn test_engine_config_deserialized_as_object() {
let yaml =
"engine:\n model: claude-opus-4.5\n max-turns: 50\n timeout-minutes: 30";
let fm: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
let ec: EngineConfig = serde_yaml::from_value(fm["engine"].clone()).unwrap();
assert_eq!(ec.model(), "claude-opus-4.5");
assert_eq!(ec.max_turns(), Some(50));
assert_eq!(ec.timeout_minutes(), Some(30));
}
}