Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agentsight/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# Dashboard 前端嵌入产物 — 由 `npm run build:embed` 在 dashboard/ 目录下生成。
# webpack output.clean=true 每次构建都会覆盖。开发者本地按需重建,不提交。
/frontend-dist/
coverage.xml
2 changes: 1 addition & 1 deletion src/agentsight/component.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ anolisa_min_version = "0.1.0"

[component]
name = "agentsight"
version = "0.6.1"
version = "0.7.0"
layer = "runtime"
domain = "observability"
description = "eBPF-based AI agent observability tool"
Expand Down
15 changes: 12 additions & 3 deletions src/agentsight/src/bin/cli/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ impl AuditCommand {

match store.query_since(since_ns, event_type) {
Ok(records) => self.output_records(&records, &format!("Last {hours} hours")),
Err(e) => eprintln!("Query failed: {e}"),
Err(e) => {
eprintln!("Query failed: {e}");
std::process::exit(1);
}
}
}

fn query_by_pid(&self, store: &AuditStore, pid: u32, event_type: Option<AuditEventType>) {
match store.query_by_pid(pid, event_type) {
Ok(records) => self.output_records(&records, &format!("PID {pid}")),
Err(e) => eprintln!("Query failed: {e}"),
Err(e) => {
eprintln!("Query failed: {e}");
std::process::exit(1);
}
}
}

Expand Down Expand Up @@ -198,7 +204,10 @@ impl AuditCommand {
}
}
}
Err(e) => eprintln!("Summary query failed: {e}"),
Err(e) => {
eprintln!("Summary query failed: {e}");
std::process::exit(1);
}
}
}
}
Expand Down
48 changes: 36 additions & 12 deletions src/agentsight/src/bin/cli/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct DiscoverCommand {
/// List all known agents without scanning
#[structopt(long)]
pub list_known: bool,

/// Output as JSON
#[structopt(long)]
pub json: bool,
}

impl DiscoverCommand {
Expand All @@ -31,22 +35,32 @@ impl DiscoverCommand {
/// List all known agents that can be detected
fn list_known_agents(&self) {
let rules = agentsight::default_cmdline_rules();
let scanner = AgentScanner::from_rules(&rules, &[]);
let count = scanner.matcher_count();
let infos: Vec<_> = rules
.iter()
.filter_map(CmdlineGlobMatcher::from_config)
.map(|m| m.info().clone())
.collect();

if self.json {
match serde_json::to_string_pretty(&infos) {
Ok(json) => println!("{}", json),
Err(e) => {
eprintln!("JSON serialization failed: {e}");
std::process::exit(1);
}
}
return;
}

let count = infos.len();
println!("Known AI Agents ({count} total):");
println!("{}", "=".repeat(60));
println!();

// Use CmdlineGlobMatcher to list agent info
for matcher in agentsight::default_cmdline_rules()
.iter()
.filter_map(CmdlineGlobMatcher::from_config)
{
let agent = matcher.info();
println!(" {} ({})", agent.name, agent.category);
println!(" Process names: {}", agent.process_names.join(", "));
println!(" {}", agent.description);
for info in &infos {
println!(" {} ({})", info.name, info.category);
println!(" Process names: {}", info.process_names.join(", "));
println!(" {}", info.description);
println!();
}
}
Expand All @@ -56,6 +70,17 @@ impl DiscoverCommand {
let mut scanner = AgentScanner::from_rules(&agentsight::default_cmdline_rules(), &[]);
let agents = scanner.scan();

if self.json {
match serde_json::to_string_pretty(&agents) {
Ok(json) => println!("{}", json),
Err(e) => {
eprintln!("JSON serialization failed: {e}");
std::process::exit(1);
}
}
return;
}

if agents.is_empty() {
println!("No AI agents found running on this system.");
println!();
Expand All @@ -71,7 +96,6 @@ impl DiscoverCommand {
println!(" {} [PID: {}]", agent.agent_info.name, agent.pid);
println!(" Category: {}", agent.agent_info.category);

// Truncate long command lines
let cmdline_str = agent.cmdline_args.join(" ");
let cmdline = if cmdline_str.len() > 80 && !self.verbose {
format!("{}...", &cmdline_str[..77])
Expand Down
24 changes: 22 additions & 2 deletions src/agentsight/src/bin/cli/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,22 @@ impl TokenCommand {
}

fn execute_summary(&self, data_path: &std::path::Path) {
// Validate custom data file exists
if self.data_file.is_some()
&& let Err(e) = agentsight::check_data_file(data_path)
{
eprintln!("{e}");
std::process::exit(1);
}

// Open token store
let store = TokenStore::new(data_path);
let store = match TokenStore::new(data_path) {
Ok(s) => s,
Err(e) => {
eprintln!("Failed to open token database: {e}");
std::process::exit(1);
}
};
let query = agentsight::TokenQuery::new(&store);

// Execute query
Expand All @@ -70,7 +84,13 @@ impl TokenCommand {

// Output result
if self.json {
println!("{}", serde_json::to_string_pretty(&result).unwrap());
match serde_json::to_string_pretty(&result) {
Ok(json) => println!("{}", json),
Err(e) => {
eprintln!("JSON serialization failed: {e}");
std::process::exit(1);
}
}
} else {
print_human_readable(&result, self.compare);
}
Expand Down
4 changes: 2 additions & 2 deletions src/agentsight/src/discovery/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
///
/// This struct contains metadata about a specific AI agent product,
/// including the process names that can be used to identify it.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize)]
pub struct AgentInfo {
/// Agent name (e.g., "Claude Code", "Aider", "GitHub Copilot")
pub name: String,
Expand Down Expand Up @@ -40,7 +40,7 @@ impl AgentInfo {
///
/// This struct represents an actual running process that has been
/// identified as an AI agent based on matching against known agent types.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize)]
pub struct DiscoveredAgent {
/// The corresponding agent type information
pub agent_info: AgentInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/agentsight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub use parser::{
pub use storage::{
AuditStore, HttpStore, SqliteConfig, SqliteStore, Storage, StorageBackend, TimePeriod,
TokenBreakdown, TokenComparison, TokenQuery, TokenQueryResult, TokenStore, Trend,
format_tokens, format_tokens_with_commas,
check_data_file, format_tokens, format_tokens_with_commas,
};

// Re-export unified entry point
Expand Down
Loading
Loading