Skip to main content

qualia_cli/
main.rs

1mod cli;
2mod handlers;
3mod sparql;
4
5pub mod bench;
6mod benchmark_env;
7pub mod compress;
8pub mod daemon;
9pub mod evaluate;
10pub mod ingest;
11mod llm_lifecycle;
12mod llm_raw_bench;
13mod llm_testing;
14pub mod mcp;
15pub mod mesh;
16pub mod qpu;
17pub mod query;
18pub mod resources;
19pub mod science;
20mod service;
21pub mod shader;
22pub mod solve;
23pub mod telemetry_server;
24
25use clap::Parser;
26use cli::{Cli, Commands};
27
28#[tokio::main]
29async fn main() -> Result<(), Box<dyn std::error::Error>> {
30    if std::env::var_os("QUALIA_DEVICE_BENCHMARK_OUTPUT").is_some() {
31        qualia_core_db::platform::device_benchmark::run_worker_from_env()
32            .map_err(std::io::Error::other)?;
33        return Ok(());
34    }
35    let cli = Cli::parse();
36
37    let log_level = match cli.verbose {
38        0 => "info",
39        1 => "debug",
40        _ => "trace",
41    };
42    std::env::set_var("RUST_LOG", log_level);
43    let _ = env_logger::try_init();
44
45    if cli.verbose >= 1 {
46        llm_lifecycle::init_log_stream(true);
47    }
48
49    match &cli.command {
50        Commands::Llm { action } => {
51            handlers::llm::handle(action).await?;
52        }
53        Commands::Shader { action } => {
54            shader::run(action)?;
55        }
56        Commands::MeshProbe { action } => {
57            mesh::run(action)?;
58        }
59        Commands::Capabilities { list } => {
60            handlers::misc::handle_capabilities(*list);
61        }
62        Commands::Shacl { action } => {
63            handlers::misc::handle_shacl(action);
64        }
65        Commands::Vault { init } => {
66            handlers::misc::handle_vault(*init);
67        }
68        Commands::Migrate { action } => {
69            handlers::misc::handle_migrate(action)?;
70        }
71        Commands::Mem { inspect } => {
72            handlers::misc::handle_mem(*inspect);
73        }
74        Commands::Inspect { file_path } => {
75            handlers::misc::handle_inspect(file_path)?;
76        }
77        Commands::Q42 { action } => {
78            handlers::misc::handle_q42(action)?;
79        }
80        Commands::Dump { out_path } => {
81            handlers::misc::handle_dump(out_path)?;
82        }
83        Commands::Daemon { action, opts } => {
84            let resolved = action.clone().unwrap_or(daemon::DaemonAction::Serve {
85                service_child: false,
86            });
87            daemon::handle(&resolved, opts).await;
88        }
89        Commands::Mcp { action } => {
90            mcp::handle(action, cli.enable_qpu).await;
91        }
92        Commands::Service { action } => {
93            service::handle(action, cli.enable_qpu).await;
94        }
95        Commands::ExportSolid { input, output } => {
96            handlers::misc::handle_export_solid(input, output);
97        }
98        Commands::Solid { action } => {
99            handlers::solid::handle(action.clone()).await;
100        }
101        Commands::Ingest { format } => {
102            handlers::misc::handle_ingest(format);
103        }
104        Commands::VerifyIntegrity { input, dataset } => {
105            handlers::misc::handle_verify_integrity(input, dataset);
106        }
107        Commands::VerifyGraph {
108            input,
109            dataset,
110            memory_mib,
111            temp_gib,
112        } => {
113            handlers::misc::handle_verify_graph(input, dataset, *memory_mib, *temp_gib)?;
114        }
115        Commands::Import {
116            input,
117            output,
118            strip_literals,
119            segment_mib,
120        } => {
121            handlers::misc::handle_import(input, output, *strip_literals, *segment_mib);
122        }
123        Commands::Query { dialect } => {
124            handlers::misc::handle_query(dialect);
125        }
126        Commands::Compress { input, output } => {
127            handlers::misc::handle_compress(input, output);
128        }
129        Commands::Resources { subcommand, arg } => {
130            resources::handle(subcommand, arg.as_deref()).await;
131        }
132        Commands::Profile { action } => {
133            handlers::misc::handle_profile(action);
134        }
135        Commands::Benchmark { action } => {
136            handlers::bench::handle_benchmark(action).await;
137        }
138        Commands::Bench { suite } => {
139            handlers::bench::handle_bench(suite).await?;
140        }
141        Commands::Webizen { action } => {
142            handlers::webizen::handle(action).await?;
143        }
144        Commands::Qpu { action } => {
145            handlers::qpu::handle(action, cli.enable_qpu);
146        }
147        Commands::Extension { action } => {
148            handlers::misc::handle_extension(action);
149        }
150        Commands::Evaluate { modality } => {
151            handlers::evaluate::handle(modality);
152        }
153        Commands::Solve { action } => {
154            handlers::solve::handle(action);
155        }
156        Commands::Science { action } => {
157            handlers::science::handle(action);
158        }
159        Commands::Governance { action } => {
160            handlers::misc::handle_governance(action);
161        }
162        Commands::Compile { action } => {
163            handlers::misc::handle_compile(action);
164        }
165    }
166
167    Ok(())
168}