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
//! The `visdom` command line.
use clap::{Parser, Subcommand};
use tracevault_cli::agent::Agent;
use tracevault_cli::cli::{Command, InitArgs, LoginArgs};
use crate::mode::TracingMode;
#[derive(Parser)]
#[command(
name = "visdom",
version,
about = "Visdom developer CLI",
long_about = "Visdom developer CLI.\n\nWithout a subcommand: checks that this project is wired \
for the coding agent (tracing, bazaar MCP), offers to fix what is not, and \
launches the agent — with hooks tracing, or through the AI Gateway (--mode). \
Arguments after `--` go to the agent."
)]
pub struct VisdomCli {
/// The agent to check and launch: claude-code or codex. Default: the
/// VISDOM_AGENT variable, then `.visdom/config.toml` in the repository,
/// then the user config, then claude-code.
#[arg(long, value_enum)]
pub agent: Option<Agent>,
/// How the session is traced: by hooks, or through the AI Gateway.
/// Default: the VISDOM_TRACING_MODE variable, then `.visdom/config.toml`
/// in the repository, then the user config (`tracing_mode`), then hooks.
/// The workspace's AI traffic policy may require one of them.
#[arg(long, value_enum)]
pub mode: Option<TracingMode>,
/// Apply every offered fix without asking.
#[arg(long)]
pub yes: bool,
/// Start the agent without telling it about Visdom's tools (see `visdom
/// instructions`). To leave them out always: `agent_instructions = false`
/// in the user config.
#[arg(long)]
pub no_instructions: bool,
#[command(subcommand)]
pub command: Option<VisdomCommand>,
/// Arguments passed to the agent unchanged.
#[arg(last = true)]
pub agent_args: Vec<String>,
}
#[derive(Subcommand)]
pub enum VisdomCommand {
/// Check this project's Visdom wiring without launching an agent. Exits
/// with 1 when a check fails.
Doctor {
/// Offer the fixes (asking for each; with --yes, apply all).
#[arg(long)]
fix: bool,
/// Print the findings as JSON.
#[arg(long)]
json: bool,
/// With --fix: apply every fix without asking.
#[arg(long)]
yes: bool,
/// The agent to check (see `visdom --help`).
#[arg(long, value_enum)]
agent: Option<Agent>,
/// The tracing mode to check (see `visdom --help`).
#[arg(long, value_enum)]
mode: Option<TracingMode>,
},
/// Print the developer's AI Gateway key for a project: what a launched
/// agent runs to get, and renew, its key.
#[command(hide = true)]
GatewayKey {
/// The gateway console's address.
#[arg(long)]
console: String,
/// The gateway project's id.
#[arg(long)]
project: String,
},
/// Print shell commands that send an agent started without `visdom`
/// through the AI Gateway: `source <(visdom env)`. The key is not in the
/// output, only the command that gets it.
Env {
/// The agent the commands are for (see `visdom --help`).
#[arg(long, value_enum)]
agent: Option<Agent>,
},
/// Print what an agent started here with `visdom` is told about Visdom's
/// tools: the tracing commands, the bazaar MCP server, the AI Gateway —
/// each only if this session has it. Prints nothing when it has none.
Instructions {
/// The agent the text is for (see `visdom --help`).
#[arg(long, value_enum)]
agent: Option<Agent>,
/// The tracing mode it is for (see `visdom --help`).
#[arg(long, value_enum)]
mode: Option<TracingMode>,
},
/// Log in to Visdom
Login(LoginArgs),
/// Log out from Visdom
Logout,
/// Set up this repository for Visdom: tracing, and
/// the bazaar MCP server for the agent.
Init {
#[command(flatten)]
args: InitArgs,
},
/// Tracing commands: status, check, repo, project, context and the rest.
Trace {
#[command(subcommand)]
command: Command,
},
}
#[cfg(test)]
mod tests {
use super::*;
fn parse(args: &[&str]) -> VisdomCli {
match VisdomCli::try_parse_from(args) {
Ok(cli) => cli,
Err(e) => panic!("{args:?} must parse: {e}"),
}
}
#[test]
fn the_mode_is_an_option_of_the_launch_and_of_doctor() {
let cli = parse(&["visdom", "--mode", "gateway", "--", "--verbose"]);
assert_eq!(cli.mode, Some(TracingMode::Gateway));
assert_eq!(cli.agent_args, ["--verbose"]);
let cli = parse(&["visdom", "doctor", "--mode", "hooks"]);
assert!(matches!(
cli.command,
Some(VisdomCommand::Doctor {
mode: Some(TracingMode::Hooks),
..
})
));
assert!(VisdomCli::try_parse_from(["visdom", "--mode", "proxy"]).is_err());
}
#[test]
fn the_key_helper_takes_a_console_and_a_project() {
let cli = parse(&[
"visdom",
"gateway-key",
"--console",
"https://gw.example.com",
"--project",
"p-1",
]);
match cli.command {
Some(VisdomCommand::GatewayKey { console, project }) => {
assert_eq!(
(console.as_str(), project.as_str()),
("https://gw.example.com", "p-1")
);
}
_ => panic!("expected gateway-key"),
}
}
#[test]
fn command_definition_is_consistent() {
use clap::CommandFactory;
VisdomCli::command().debug_assert();
}
#[test]
fn parses_trace_status() {
let cli = parse(&["visdom", "trace", "status"]);
assert!(matches!(
cli.command,
Some(VisdomCommand::Trace {
command: Command::Status { .. }
})
));
}
#[test]
fn parses_hidden_trace_stream() {
let cli = parse(&["visdom", "trace", "stream", "--event", "stop"]);
assert!(matches!(
cli.command,
Some(VisdomCommand::Trace {
command: Command::Stream { .. }
})
));
}
#[test]
fn bare_visdom_with_agent_args() {
let cli = parse(&["visdom", "--agent", "codex", "--", "--model", "x"]);
assert!(cli.command.is_none());
assert_eq!(cli.agent, Some(Agent::Codex));
assert_eq!(cli.agent_args, ["--model", "x"]);
}
#[test]
fn bare_visdom_without_arguments() {
let cli = parse(&["visdom"]);
assert!(cli.command.is_none());
assert!(cli.agent.is_none() && !cli.yes && cli.agent_args.is_empty());
}
#[test]
fn parses_doctor_json() {
let cli = parse(&["visdom", "doctor", "--json"]);
assert!(matches!(
cli.command,
Some(VisdomCommand::Doctor {
json: true,
fix: false,
yes: false,
agent: None,
mode: None
})
));
}
#[test]
fn init_takes_tracevault_init_flags() {
let cli = parse(&["visdom", "init", "--agent", "codex", "--no-gitignore"]);
match cli.command {
Some(VisdomCommand::Init { args }) => {
assert_eq!(args.agent, Agent::Codex);
assert!(args.no_gitignore);
}
_ => panic!("expected init"),
}
}
}