Skip to main content

tracevault_cli/commands/
proxy.rs

1//! `tracevault proxy info` — print the TraceVault LLM proxy configuration
2//! a user needs to point their AI tool (Claude Code, GSD2, Cursor, etc.) at
3//! the proxy.
4//!
5//! Read-only and purely local: never calls the network. Output is intended
6//! to be copy-pasted directly into a shell or tool config.
7
8use crate::credentials::Credentials;
9
10const ANSI_BOLD: &str = "\x1b[1m";
11const ANSI_DIM: &str = "\x1b[2m";
12const ANSI_RESET: &str = "\x1b[0m";
13
14/// Print the proxy configuration. Returns process exit code: 0 on success,
15/// 1 when no credentials are available (user has not logged in).
16pub fn run_proxy_info() -> i32 {
17    let creds = match Credentials::load() {
18        Some(c) => c,
19        None => {
20            eprintln!(
21                "Not logged in. Run `tracevault login --server-url <url>` first \
22                 to obtain a TraceVault session token, then try again."
23            );
24            eprintln!(
25                "Credentials file expected at: {}",
26                Credentials::path().display()
27            );
28            return 1;
29        }
30    };
31
32    let server_url = creds.server_url.trim_end_matches('/');
33    let proxy_url = format!("{server_url}/proxy/anthropic");
34    let creds_path = Credentials::path();
35
36    println!("{ANSI_BOLD}TraceVault LLM Proxy{ANSI_RESET}");
37    println!();
38    println!("  Server:           {server_url}");
39    println!("  Proxy base URL:   {ANSI_BOLD}{proxy_url}{ANSI_RESET}");
40    println!("  Credentials file: {}", creds_path.display());
41    println!();
42    println!("{ANSI_BOLD}Setup{ANSI_RESET}");
43    println!();
44    println!("  1. Configure your Anthropic API key once at:");
45    println!("       {server_url}/me/proxy");
46    println!();
47    println!("  2. Set these environment variables for your AI tool:");
48    println!();
49    println!("       {ANSI_BOLD}export ANTHROPIC_BASE_URL=\"{proxy_url}\"{ANSI_RESET}");
50    println!(
51        "       {ANSI_BOLD}export ANTHROPIC_API_KEY=\"<your TraceVault session token>\"{ANSI_RESET}"
52    );
53    println!();
54    println!(
55        "     {ANSI_DIM}Your TraceVault session token lives in {} as the \"token\" field.{ANSI_RESET}",
56        creds_path.display()
57    );
58    println!();
59    println!("  3. Run your AI tool as usual. Requests go through TraceVault and are");
60    println!("     forwarded to api.anthropic.com using the Anthropic key you stored");
61    println!("     in step 1.");
62
63    0
64}