sandbox-agent/gigacode/src/main.rs
Nathan Flurry e7656d78f0
perf: improve startup instrumentation and replace npx with npm install (#208)
Add comprehensive tracing instrumentation across the entire agent startup path (gigacode CLI, ACP HTTP adapter, agent installation, and process spawning) to enable detailed performance profiling. Replace npm-based agent process launchers that use npx (incurring resolution overhead on every spawn) with pre-installed npm packages, reducing startup latency. Improve error diagnostics when agent processes crash by capturing exit codes and stderr tails. Update error handling to map exited processes to dedicated error variants with actionable error messages.

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-06 12:05:19 -08:00

52 lines
1.5 KiB
Rust

use clap::Parser;
use sandbox_agent::cli::{
init_logging, run_command, CliConfig, CliError, Command, GigacodeCli, OpencodeArgs,
};
fn main() {
if let Err(err) = run() {
tracing::error!(error = %err, "gigacode failed");
std::process::exit(1);
}
}
fn run() -> Result<(), CliError> {
let started = std::time::Instant::now();
let cli = GigacodeCli::parse();
let config = CliConfig {
token: cli.token,
no_token: cli.no_token,
gigacode: true,
};
let yolo = cli.yolo;
let command = match cli.command {
Some(Command::Opencode(mut args)) => {
args.yolo = args.yolo || yolo;
Command::Opencode(args)
}
Some(other) => other,
None => {
let mut args = OpencodeArgs::default();
args.yolo = yolo;
Command::Opencode(args)
}
};
if let Err(err) = init_logging(&command) {
eprintln!("failed to init logging: {err}");
return Err(err);
}
tracing::info!(
command = ?command,
startup_ms = started.elapsed().as_millis() as u64,
"gigacode.run: command starting"
);
let command_started = std::time::Instant::now();
let result = run_command(&command, &config);
tracing::info!(
command = ?command,
command_ms = command_started.elapsed().as_millis() as u64,
total_ms = started.elapsed().as_millis() as u64,
"gigacode.run: command exited"
);
result
}