Skip to main content

qualia_cli/cli/
misc.rs

1use clap::Subcommand;
2use std::path::PathBuf;
3
4#[derive(Subcommand, Debug)]
5pub enum ExtensionAction {
6    Register { manifest_path: PathBuf },
7    List,
8    Dispatch { id: String, input: String },
9}
10
11#[derive(Subcommand, Debug)]
12pub enum ShaclAction {
13    List,
14    Validate { dataset: PathBuf, shapes: PathBuf },
15}
16
17#[derive(Subcommand, Debug)]
18pub enum GovernanceAction {
19    WalAppend {
20        #[arg(long)]
21        quin: String,
22        #[arg(long)]
23        sign: String,
24    },
25    Ratify {
26        agreement_did: String,
27    },
28}
29
30#[derive(Subcommand, Debug, Clone)]
31pub enum CompileAction {
32    N3ToDeontic { file: PathBuf },
33    /// Compile and seal an ontological entity bundle (.hmc) in Reverse-LOD order with CBOR-LD manifest
34    EntityCompile(EntityCompileArgs),
35    /// Legacy alias for EntityCompile
36    TwinCompile(EntityCompileArgs),
37    /// Verify and validate an ontological entity (.10d or .hmc bundle)
38    EntityVerify(EntityVerifyArgs),
39    /// Legacy alias for EntityVerify
40    TwinVerify(EntityVerifyArgs),
41}
42
43#[derive(clap::Args, Debug, Clone)]
44pub struct EntityCompileArgs {
45    /// Hero mesh input file (.10d, .glb, or binary)
46    #[arg(short, long)]
47    pub hero: PathBuf,
48
49    /// Output bundle path (.hmc)
50    #[arg(short, long)]
51    pub output: PathBuf,
52
53    /// Decimated mesh input file (optional)
54    #[arg(long)]
55    pub decimated: Option<PathBuf>,
56
57    /// Octahedral impostor atlas input file (optional)
58    #[arg(long)]
59    pub impostor: Option<PathBuf>,
60
61    /// Hierarchical surfel input file (optional)
62    #[arg(long)]
63    pub surfel: Option<PathBuf>,
64
65    /// Subject ID / URN / DID (e.g. urn:qualia:taxon:eucalyptus_regnans_01 or did:key:...)
66    #[arg(long, default_value = "urn:qualia:taxon:eucalyptus_regnans_01")]
67    pub subject_id: String,
68
69    /// Ontological entity class (DarwinianTaxon -> Specimen, NaturalPerson -> Persona, ManufacturedProperty -> Construct)
70    #[arg(long, default_value = "DarwinianTaxon")]
71    pub entity_type: String,
72
73    /// Issuer DID
74    #[arg(long, default_value = "did:web:trustfactory.org:compiler")]
75    pub issuer: String,
76
77    /// Procedural seed URI
78    #[arg(long, default_value = "hmc://seeds/voronoi_bark")]
79    pub procedural_seed: String,
80
81    /// Acoustic low anchor Hz
82    #[arg(long, default_value_t = 200)]
83    pub acoustic_low: u32,
84
85    /// Acoustic mid anchor Hz
86    #[arg(long, default_value_t = 1000)]
87    pub acoustic_mid: u32,
88
89    /// Acoustic high anchor Hz
90    #[arg(long, default_value_t = 8000)]
91    pub acoustic_high: u32,
92
93    /// Verification method key URI
94    #[arg(long, default_value = "did:web:trustfactory.org:compiler#key-1")]
95    pub verification_method: String,
96
97    /// Permissive Commons / SPC licence class ("SocialPermissiveCommons", "CC0-1.0", "CC-BY-4.0")
98    #[arg(long, default_value = "SocialPermissiveCommons")]
99    pub licence_class: String,
100
101    /// Finite production obligation cost in cents (0 if donated commons)
102    #[arg(long, default_value_t = 0)]
103    pub production_cost_cents: u64,
104
105    /// Allowed carrier/bandwidth transaction recovery cost in minor cents per MiB
106    #[arg(long, default_value_t = 0)]
107    pub transaction_cost_per_mib_cents: u64,
108
109    /// Dump CBOR-LD manifest as pretty JSON alongside bundle
110    #[arg(long)]
111    pub dump_json: bool,
112}
113
114pub type TwinCompileArgs = EntityCompileArgs;
115
116/// Arguments for `qualia-cli entity-verify`.
117#[derive(clap::Args, Debug, Clone)]
118pub struct EntityVerifyArgs {
119    /// Path to a `.10d` living container, `.hmc` bundle, or directory
120    pub path: PathBuf,
121
122    /// Batch mode: search directories recursively for all `.10d` and `.hmc` files
123    #[arg(short, long)]
124    pub batch: bool,
125
126    /// Output report in structured JSON format
127    #[arg(long)]
128    pub json: bool,
129
130    /// Suppress verbose logging and only output final verdict
131    #[arg(short, long)]
132    pub quiet: bool,
133}
134
135pub type TwinVerifyArgs = EntityVerifyArgs;
136
137#[derive(Subcommand, Debug)]
138pub enum ProfileAction {
139    Compile {
140        input: PathBuf,
141        #[arg(long)]
142        out: Option<PathBuf>,
143    },
144    List,
145    Inspect {
146        file: PathBuf,
147    },
148}
149
150#[derive(Subcommand, Debug)]
151pub enum Q42Action {
152    /// Header, sections, lexicon cardinality, PIDX/FIDX/root.
153    Inspect { path: PathBuf },
154    /// Layered verification. A volume-set root walks every data child and
155    /// lexicon shard. `full` cannot PASS if a required check was skipped.
156    Verify {
157        path: PathBuf,
158        #[arg(long, default_value = "full")]
159        level: String,
160    },
161    /// SHA-1 magnet (`urn:btih:`) with optional daemon web-seed.
162    ///
163    /// Denied for Sanctuary, medical, bilateral, mixed, and unmarked personal
164    /// volumes. Catalog ontologies require `--commons`.
165    Magnet {
166        path: PathBuf,
167        #[arg(long)]
168        name: Option<String>,
169        #[arg(long, default_value_t = 4242)]
170        port: u16,
171        #[arg(long)]
172        webseed: Option<String>,
173        /// Also emit magnets for every child of a volume root.
174        #[arg(long)]
175        set: bool,
176        /// Assert this is a Permissive Commons catalog (not a person's file).
177        /// Still rejected if any Quin is restricted, classified, medical, legal,
178        /// fiduciary, or bilateral.
179        #[arg(long)]
180        commons: bool,
181    },
182    /// Compact a logical volume set (or a single-file volume) into a new generation.
183    ///
184    /// SuperBlocks stream through the existing rollover / streaming writer.
185    /// Output is a new root (or single `.q42`) under `--out`, never an in-place rewrite.
186    Compact {
187        root: PathBuf,
188        /// Directory for the compacted generation. Defaults to `<root-parent>/compacted`.
189        #[arg(long)]
190        out: Option<PathBuf>,
191    },
192    /// Register this `.q42` with the in-process WebTorrent seeder (daemon).
193    ///
194    /// Same publication gate as `magnet`. Personal/medical volumes stay local.
195    Seed {
196        path: PathBuf,
197        #[arg(long)]
198        name: Option<String>,
199        #[arg(long)]
200        id: Option<String>,
201        /// Assert this is a Permissive Commons catalog (not a person's file).
202        #[arg(long)]
203        commons: bool,
204    },
205    /// Pre-ingest RDF scan: triples, oversize terms, top predicates.
206    AuditSource {
207        /// Single RDF/OWL/TTL/NT file.
208        path: Option<PathBuf>,
209        /// Walk an ontology library root (chebi.owl, OEWN dir, datasources/).
210        #[arg(long)]
211        source_root: Option<PathBuf>,
212        /// How many predicates to list in the histogram.
213        #[arg(long, default_value_t = 20)]
214        top: usize,
215        /// Write JSON to this path (library matrix or single-file report).
216        #[arg(long)]
217        json_out: Option<PathBuf>,
218    },
219}
220
221#[derive(Subcommand, Debug)]
222pub enum HmcAction {
223    /// List HMC (QBDL) entries and header flags.
224    Inspect { path: PathBuf },
225    /// Verify whole-file CRC-32C and per-entry SHA-256 digests.
226    Verify {
227        path: PathBuf,
228        /// Also run import-aligned verify-graph on an embedded `.q42` entry key.
229        #[arg(long)]
230        q42_entry: Option<String>,
231        #[arg(long)]
232        rdf_source: Option<PathBuf>,
233    },
234}
235
236#[derive(Subcommand, Debug)]
237pub enum IngestJobAction {
238    /// Show checkpoint, run counts, and whether continue is possible.
239    Status {
240        dir: PathBuf,
241        /// Poll progress.json until the job completes or the process is gone.
242        #[arg(long)]
243        watch: bool,
244    },
245    /// Review a job directory, a legacy scratch tree, or a volume root.
246    Inspect { path: PathBuf },
247    /// Re-stream a file or URL and compare SHA-256 to a recorded attestation.
248    Compare {
249        attestation: PathBuf,
250        #[arg(long)]
251        against: String,
252    },
253    /// Continue an incomplete job (re-reads the source and skips accepted triples).
254    Continue {
255        dir: PathBuf,
256        /// Spawn a detached child (break away from a session job object) and return.
257        #[arg(long)]
258        detach: bool,
259    },
260    /// Merge already-hashed quin/lex runs into the job's `.q42` (no source re-read).
261    Publish {
262        dir: PathBuf,
263        #[arg(long)]
264        detach: bool,
265    },
266    /// Copy a pre-job scratch (chunk_*.tmp) into a new job directory.
267    AdoptScratch {
268        scratch: PathBuf,
269        #[arg(long)]
270        out_job: PathBuf,
271        #[arg(long)]
272        source: PathBuf,
273        #[arg(long)]
274        output: PathBuf,
275        #[arg(long)]
276        segment_mib: Option<u64>,
277    },
278    /// Ingest more RDF and graft segments onto an existing volume-set root.
279    Append {
280        root: PathBuf,
281        extra: Option<PathBuf>,
282        #[arg(long)]
283        url: Option<String>,
284    },
285}
286
287#[derive(Subcommand, Debug)]
288pub enum MigrateAction {
289    Meta {
290        path: PathBuf,
291        #[arg(long)]
292        dry_run: bool,
293    },
294}
295
296#[derive(Subcommand, Debug)]
297pub enum BenchmarkAction {
298    SparqlStar { path: PathBuf },
299    RssScan { path: PathBuf, percent: u8 },
300    LazyInference { path: PathBuf },
301    Incremental { path: PathBuf },
302    P2pSwarm { path: PathBuf },
303}
304
305#[derive(Subcommand, Debug)]
306pub enum QueryDialect {
307    Sparql {
308        vault: PathBuf,
309        query_string: Option<String>,
310        #[arg(short, long)]
311        file: Option<PathBuf>,
312    },
313    SparqlStar {
314        vault: PathBuf,
315        query_string: Option<String>,
316        #[arg(short, long)]
317        file: Option<PathBuf>,
318    },
319}
320
321#[derive(Subcommand, Debug)]
322pub enum IngestFormat {
323    Semantic {
324        file: PathBuf,
325        /// Mandatory publication / access policy (QW-10).
326        /// One of: restricted | project-internal | public-not-for-redistribution
327        /// (`public-redistributable` is refused on this path — use catalog publish).
328        #[arg(long = "access-policy")]
329        access_policy: String,
330        #[arg(long)]
331        mapping_version: Option<String>,
332        #[arg(long)]
333        context_digest: Option<String>,
334        #[arg(long)]
335        compiler_build_digest: Option<String>,
336    },
337    Csv {
338        file: PathBuf,
339        #[arg(long)]
340        map: PathBuf,
341    },
342    Json {
343        file: PathBuf,
344        #[arg(long)]
345        map: PathBuf,
346    },
347}