mod commands;
mod config;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "phago")]
#[command(author, version, about = "Phago - Self-evolving knowledge substrates", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, global = true)]
verbose: bool,
}
#[derive(Subcommand)]
enum Commands {
Init {
#[arg(short, long)]
path: Option<String>,
},
Ingest {
path: String,
#[arg(short, long, default_value = "30")]
ticks: u64,
#[arg(short, long, default_value = "txt,md")]
extensions: String,
},
Run {
#[arg(short, long, default_value = "50")]
ticks: u64,
},
Query {
query: String,
#[arg(short, long, default_value = "10")]
max_results: usize,
#[arg(short, long, default_value = "0.5")]
alpha: f64,
},
Explore {
#[command(subcommand)]
command: ExploreCommands,
},
Export {
output: String,
#[arg(short, long, default_value = "json")]
format: String,
},
Session {
#[command(subcommand)]
command: SessionCommands,
},
Stats,
#[cfg(feature = "distributed")]
Cluster {
#[command(subcommand)]
command: ClusterCommands,
},
}
#[derive(Subcommand)]
enum ExploreCommands {
Centrality {
#[arg(short, long, default_value = "10")]
top: usize,
},
Bridges {
#[arg(short, long, default_value = "10")]
top: usize,
},
Path {
from: String,
to: String,
},
Components,
}
#[cfg(feature = "distributed")]
#[derive(Subcommand)]
enum ClusterCommands {
StartCoordinator {
#[arg(short, long, default_value = "9000")]
port: u16,
#[arg(short, long, default_value = "3")]
num_shards: u32,
},
StartShard {
#[arg(short, long)]
port: u16,
#[arg(short, long, default_value = "127.0.0.1:9000")]
coordinator: String,
#[arg(short, long)]
id: u32,
},
Status {
#[arg(short, long, default_value = "127.0.0.1:9000")]
coordinator: String,
},
Bench {
#[arg(default_value = "quick")]
mode: String,
},
}
#[derive(Subcommand)]
enum SessionCommands {
Save {
name: String,
},
Load {
name: String,
},
List,
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Init { path } => commands::init::run(path),
Commands::Ingest { path, ticks, extensions } => {
commands::ingest::run(&path, ticks, &extensions, cli.verbose)
}
Commands::Run { ticks } => commands::run::run(ticks, cli.verbose),
Commands::Query { query, max_results, alpha } => {
commands::query::run(&query, max_results, alpha)
}
Commands::Explore { command } => match command {
ExploreCommands::Centrality { top } => commands::explore::centrality(top),
ExploreCommands::Bridges { top } => commands::explore::bridges(top),
ExploreCommands::Path { from, to } => commands::explore::path(&from, &to),
ExploreCommands::Components => commands::explore::components(),
},
Commands::Export { output, format } => commands::export::run(&output, &format),
Commands::Session { command } => match command {
SessionCommands::Save { name } => commands::session::save(&name),
SessionCommands::Load { name } => commands::session::load(&name),
SessionCommands::List => commands::session::list(),
},
Commands::Stats => commands::stats::run(),
#[cfg(feature = "distributed")]
Commands::Cluster { command } => match command {
ClusterCommands::StartCoordinator { port, num_shards } => {
commands::cluster::start_coordinator(port, num_shards)
}
ClusterCommands::StartShard {
port,
coordinator,
id,
} => commands::cluster::start_shard(port, &coordinator, id),
ClusterCommands::Status { coordinator } => {
commands::cluster::status(&coordinator)
}
ClusterCommands::Bench { mode } => commands::cluster::bench(&mode),
},
}
}