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
use clap::Parser;
use std::env;
mod api_client;
mod commands;
mod config;
mod credentials;
mod hooks;
#[derive(Parser)]
#[command(name = "tracevault", version, about = "AI code governance platform")]
enum Cli {
/// Initialize TraceVault in current repository
Init {
/// TraceVault server URL for repo registration
#[arg(long)]
server_url: Option<String>,
/// Where to install Claude Code hooks: `shared` (.claude/settings.json,
/// typically committed) or `local` (.claude/settings.local.json,
/// personal/git-ignored). When omitted, prompts interactively if stdin
/// is a TTY, otherwise defaults to `shared`.
#[arg(long, value_enum)]
claude_settings: Option<commands::init::ClaudeSettingsTarget>,
/// Skip updating .gitignore. Use this when your project manages
/// .gitignore separately or you want to commit the Claude settings files.
#[arg(long)]
no_gitignore: bool,
},
/// Show current session status
Status,
/// Stream hook events to server in real-time.
/// Installed into .claude/settings.json by `tracevault init` and invoked
/// by Claude Code on every tool event — not intended to be run manually.
#[command(hide = true)]
Stream {
#[arg(long)]
event: String,
},
/// Check session policies before pushing
Check,
/// Sync repo remote URL with the TraceVault server
Sync,
/// Show local session statistics
Stats,
/// Log in to a TraceVault server
Login {
/// TraceVault server URL
#[arg(long)]
server_url: String,
/// Do not try to open a browser; just print the URL.
/// Useful inside Docker / CI / SSH without X11.
#[arg(long)]
no_browser: bool,
},
/// Log out from the TraceVault server
Logout,
/// Push commit metadata to the server.
/// Installed into .git/hooks/post-commit by `tracevault init` and
/// invoked by git after every commit — not intended to be run manually.
#[command(hide = true)]
CommitPush,
/// Force-sync all pending events to server
Flush,
/// Verify commits are registered and sealed on the TraceVault server
Verify {
/// Comma-separated list of commit SHAs
#[arg(long)]
commits: Option<String>,
/// Git commit range (e.g. abc1234..def5678)
#[arg(long)]
range: Option<String>,
},
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
match cli {
Cli::Init {
server_url,
claude_settings,
no_gitignore,
} => {
let cwd = env::current_dir().expect("Cannot determine current directory");
match commands::init::init_in_directory(
&cwd,
server_url.as_deref(),
claude_settings,
no_gitignore,
)
.await
{
Ok(target) => {
let entry = target.gitignore_entry();
println!("TraceVault initialized in {}", cwd.display());
println!("Claude Code hooks installed ({entry})");
println!("Git hooks installed (pre-push, post-commit)");
println!("Added .tracevault/ and {entry} to .gitignore");
println!(
"Nothing needs to be committed — all TraceVault files are local only."
);
println!(
"Other contributors run `tracevault init` to set up their own local hooks."
);
}
Err(e) => eprintln!("Error: {e}"),
}
}
Cli::Status => {
let cwd = env::current_dir().expect("Cannot determine current directory");
let code = commands::status::run_status(&cwd).await;
if code != 0 {
std::process::exit(code);
}
}
Cli::Stream { event } => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::stream::run_stream(&cwd, &event).await {
eprintln!("Stream error: {e}");
}
}
Cli::Check => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::check::check_policies(&cwd).await {
eprintln!("Check error: {e}");
std::process::exit(1);
}
}
Cli::Sync => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::sync::sync_repo(&cwd).await {
eprintln!("Sync error: {e}");
}
}
Cli::Stats => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::stats::show_stats(&cwd) {
eprintln!("Stats error: {e}");
}
}
Cli::Login {
server_url,
no_browser,
} => {
if let Err(e) = commands::login::login(&server_url, no_browser).await {
eprintln!("Login error: {e}");
}
}
Cli::Logout => {
if let Err(e) = commands::logout::logout().await {
eprintln!("Logout error: {e}");
}
}
Cli::CommitPush => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::commit_push::run_commit_push(&cwd).await {
eprintln!("Commit push error: {e}");
}
}
Cli::Flush => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::flush::run_flush(&cwd).await {
eprintln!("Flush error: {e}");
}
}
Cli::Verify { commits, range } => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) =
commands::verify::verify(&cwd, commits.as_deref(), range.as_deref()).await
{
eprintln!("Verify error: {e}");
std::process::exit(1);
}
}
}
}