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;
18mod qwen_testing;
19pub mod resources;
20pub mod science;
21mod service;
22pub mod shader;
23pub mod solve;
24pub mod telemetry_server;
25
26use clap::Parser;
27use cli::{Cli, Commands};
28
29#[tokio::main]
30async fn main() -> Result<(), Box<dyn std::error::Error>> {
31    if std::env::var_os("QUALIA_DEVICE_BENCHMARK_OUTPUT").is_some() {
32        qualia_core_db::platform::device_benchmark::run_worker_from_env()
33            .map_err(std::io::Error::other)?;
34        return Ok(());
35    }
36    let cli = Cli::parse();
37
38    let log_level = match cli.verbose {
39        0 => "info",
40        1 => "debug",
41        _ => "trace",
42    };
43    std::env::set_var("RUST_LOG", log_level);
44    let _ = env_logger::try_init();
45
46    if cli.verbose >= 1 {
47        llm_lifecycle::init_log_stream(true);
48    }
49
50    match &cli.command {
51        Commands::InferencePolicy { profile, action } => {
52            handlers::inference_policy::handle(profile, action)?;
53        }
54        Commands::App { action } => {
55            handlers::app::handle(action)?;
56        }
57        Commands::Llm { action } => {
58            handlers::llm::handle(action).await?;
59        }
60        Commands::Shader { action } => {
61            shader::run(action)?;
62        }
63        Commands::MeshProbe { action } => {
64            mesh::run(action)?;
65        }
66        Commands::Capabilities { list } => {
67            handlers::misc::handle_capabilities(*list);
68        }
69        Commands::Shacl { action } => {
70            handlers::misc::handle_shacl(action);
71        }
72        Commands::Vault { init } => {
73            handlers::misc::handle_vault(*init);
74        }
75        Commands::Migrate { action } => {
76            handlers::misc::handle_migrate(action)?;
77        }
78        Commands::Mem { inspect } => {
79            handlers::misc::handle_mem(*inspect);
80        }
81        Commands::Inspect { file_path } => {
82            handlers::misc::handle_inspect(file_path)?;
83        }
84        Commands::Q42 { action } => {
85            handlers::misc::handle_q42(action)?;
86        }
87        Commands::Hmc { action } => {
88            handlers::misc::handle_hmc(action)?;
89        }
90        Commands::Dump { out_path } => {
91            handlers::misc::handle_dump(out_path)?;
92        }
93        Commands::Daemon { action, opts } => {
94            let resolved = action.clone().unwrap_or(daemon::DaemonAction::Serve {
95                service_child: false,
96            });
97            daemon::handle(&resolved, opts).await;
98        }
99        Commands::Mcp { action } => {
100            mcp::handle(action, cli.enable_qpu).await;
101        }
102        Commands::Service { action } => {
103            service::handle(action, cli.enable_qpu).await;
104        }
105        Commands::ExportSolid { input, output } => {
106            handlers::misc::handle_export_solid(input, output);
107        }
108        Commands::Solid { action } => {
109            handlers::solid::handle(action.clone()).await;
110        }
111        Commands::Ingest { format } => {
112            handlers::misc::handle_ingest(format);
113        }
114        Commands::VerifyIntegrity { input, dataset } => {
115            handlers::misc::handle_verify_integrity(input, dataset);
116        }
117        Commands::VerifyGraph {
118            input,
119            dataset,
120            memory_mib,
121            temp_gib,
122            encoder,
123            omit_predicates,
124            omit_preset,
125            require_isomorphism,
126        } => {
127            handlers::misc::handle_verify_graph(
128                input,
129                dataset,
130                *memory_mib,
131                *temp_gib,
132                encoder,
133                omit_predicates.as_deref(),
134                omit_preset.as_deref(),
135                *require_isomorphism,
136            )?;
137        }
138        Commands::Import {
139            input,
140            output,
141            strip_literals,
142            segment_mib,
143            progress,
144            url,
145            job_dir,
146            resume,
147            omit_predicates,
148            omit_preset,
149        } => {
150            handlers::misc::handle_import(
151                input.as_ref(),
152                output.as_ref(),
153                *strip_literals,
154                *segment_mib,
155                *progress,
156                cli.verbose,
157                url.as_deref(),
158                job_dir.as_ref(),
159                *resume,
160                omit_predicates.as_deref(),
161                omit_preset.as_deref(),
162            );
163        }
164        Commands::IngestJob { action } => {
165            handlers::misc::handle_ingest_job(action)?;
166        }
167        Commands::Query { dialect } => {
168            handlers::misc::handle_query(dialect);
169        }
170        Commands::Compress { input, output } => {
171            handlers::misc::handle_compress(input, output);
172        }
173        Commands::Resources { subcommand, arg } => {
174            resources::handle(subcommand, arg.as_deref()).await;
175        }
176        Commands::Profile { action } => {
177            handlers::misc::handle_profile(action);
178        }
179        Commands::Benchmark { action } => {
180            handlers::bench::handle_benchmark(action).await;
181        }
182        Commands::Bench { suite } => {
183            handlers::bench::handle_bench(suite).await?;
184        }
185        Commands::Webizen { action } => {
186            handlers::webizen::handle(action).await?;
187        }
188        Commands::Qpu { action } => {
189            handlers::qpu::handle(action, cli.enable_qpu);
190        }
191        Commands::Extension { action } => {
192            handlers::misc::handle_extension(action);
193        }
194        Commands::Evaluate { modality } => {
195            handlers::evaluate::handle(modality);
196        }
197        Commands::Solve { action } => {
198            handlers::solve::handle(action);
199        }
200        Commands::Science { action } => {
201            handlers::science::handle(action);
202        }
203        Commands::Governance { action } => {
204            handlers::misc::handle_governance(action);
205        }
206        Commands::Compile { action } => {
207            handlers::misc::handle_compile(action);
208        }
209        Commands::EntityCompile(args) => {
210            handlers::entity_compile::handle(args)?;
211        }
212        Commands::TwinCompile(args) => {
213            handlers::twin_compile::handle(args)?;
214        }
215        Commands::EntityVerify(args) => {
216            handlers::entity_verify::handle(args)?;
217        }
218        Commands::TwinVerify(args) => {
219            handlers::twin_verify::handle(args)?;
220        }
221    }
222
223    Ok(())
224}