- 1
//! CLI handlers for `vak agents` (managing specialist agents & domain templates). - 2
- 3
use std::path::PathBuf; - 4
- 5
use vak_server::agents; - 6
- 7
use crate::cli::AgentsAction; - 8
- 9
pub fn run_agents(cwd: PathBuf, action: Option<AgentsAction>) -> i32 { - 10
let shared = vak_config::paths::default_workspace(); - 11
- 12
match action.unwrap_or(AgentsAction::List { global: false }) { - 13
AgentsAction::List { global } => { - 14
let root = if global { - 15
shared.as_path() - 16
} else { - 17
cwd.as_path() - 18
}; - 19
let list = match agents::load(root) { - 20
Ok(l) => l, - 21
Err(e) => { - 22
eprintln!("error reading agents: {e}"); - 23
return 1; - 24
} - 25
}; - 26
if list.is_empty() { - 27
println!( - 28
"No agents configured in {} scope.", - 29
if global { "global" } else { "workspace" } - 30
); - 31
println!( - 32
"Hint: run 'vak agents templates' or 'vak agents init --template <name> --id <id>' to create one." - 33
); - 34
return 0; - 35
} - 36
println!( - 37
"Configured Agents in {} scope ({} total):\n", - 38
if global { "global" } else { "workspace" }, - 39
list.len() - 40
); - 41
for a in list { - 42
println!("- `{}` ({}): {}", a.id, a.name, a.behaviour); - 43
if !a.personality.is_empty() { - 44
println!(" personality: {}", a.personality); - 45
} - 46
if !a.responsibilities.is_empty() { - 47
println!(" focus: {}", a.responsibilities); - 48
} - 49
} - 50
0 - 51
} - 52
AgentsAction::Templates => { - 53
let templates = agents::builtin_templates(); - 54
println!( - 55
"Available Universal Domain Specialist Templates ({} total):\n", - 56
templates.len() - 57
); - 58
for t in templates { - 59
println!("- `{}` — {} [Domain: {}]", t.template_id, t.name, t.domain); - 60
println!(" {}", t.description); - 61
println!( - 62
" Character: {} | Voice: {} | Animation: {}", - 63
t.character, t.voice, t.animation - 64
); - 65
println!(" Focus: {}", t.responsibilities); - 66
println!(); - 67
} - 68
println!("To instantiate an agent from a template:"); - 69
println!( - 70
" vak agents init --template <template_id> --id <unique_agent_id> [--name <display_name>] [--global]" - 71
); - 72
0 - 73
} - 74
AgentsAction::Init { - 75
template, - 76
id, - 77
name, - 78
global, - 79
} => { - 80
let Some(tmpl) = agents::find_template(&template) else { - 81
eprintln!("error: unknown template '{template}'"); - 82
eprintln!("Run 'vak agents templates' to view available archetypes."); - 83
return 1; - 84
}; - 85
- 86
let root = if global { - 87
shared.as_path() - 88
} else { - 89
cwd.as_path() - 90
}; - 91
let mut existing = match agents::load(root) { - 92
Ok(l) => l, - 93
Err(e) => { - 94
eprintln!("error reading agents: {e}"); - 95
return 1; - 96
} - 97
}; - 98
- 99
if existing.iter().any(|a| a.id == id) { - 100
eprintln!( - 101
"error: agent with id '{id}' already exists in {} scope", - 102
if global { "global" } else { "workspace" } - 103
); - 104
return 1; - 105
} - 106
- 107
let new_agent = tmpl.to_agent_definition(&id, name.as_deref()); - 108
existing.push(new_agent.clone()); - 109
- 110
match agents::save(root, &existing, vak_core::trust::is_trusted(root)) { - 111
Ok(_) => { - 112
println!( - 113
"Created agent '{}' ({}) in {} scope.", - 114
new_agent.id, - 115
new_agent.name, - 116
if global { "global" } else { "workspace" } - 117
); - 118
0 - 119
} - 120
Err(e) => { - 121
eprintln!("error saving agent: {e}"); - 122
1 - 123
} - 124
} - 125
} - 126
} - 127
} - 128
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.