sqlite_graphrag/cli.rs
1//! CLI argument structs and command surface (clap-based).
2//!
3//! Defines `Cli` and all subcommand enums; contains no business logic.
4
5use crate::commands::*;
6use crate::i18n::{current, Language};
7use clap::{Parser, Subcommand};
8
9/// Returns the maximum simultaneous invocations allowed by the CPU heuristic.
10fn max_concurrency_ceiling() -> usize {
11 std::thread::available_parallelism()
12 .map(|n| n.get() * 2)
13 .unwrap_or(8)
14}
15
16#[derive(Copy, Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
17pub enum GraphExportFormat {
18 Json,
19 Dot,
20 Mermaid,
21 /// Stream one JSON object per entity, then one per edge, then a summary line.
22 Ndjson,
23}
24
25// Backend choice enums live in `backend_choice` (Wave C1).
26pub use crate::backend_choice::{EmbeddingBackendChoice, LlmBackendChoice};
27
28#[derive(Parser)]
29#[command(name = "sqlite-graphrag")]
30#[command(version)]
31#[command(about = "Local GraphRAG memory for LLMs in a single SQLite file")]
32#[command(arg_required_else_help = true)]
33#[command(after_help = "DATABASE PATH (GAP-SG-32):\n \
34 `--db` is a PER-SUBCOMMAND flag, so it must come AFTER the subcommand:\n \
35 sqlite-graphrag remember --db ./graphrag.sqlite --name mem --type note ...\n \
36 Placing it before the subcommand (e.g. `sqlite-graphrag --db x.sqlite remember`) is rejected.\n \
37 Prefer `--db` on every invocation (one-shot agents). Optional XDG defaults:\n \
38 `sqlite-graphrag config set db.default_path ./graphrag.sqlite`\n \
39 Product environment variables are not read at runtime; use flags + `config set/get`.")]
40pub struct Cli {
41 /// Maximum number of simultaneous CLI invocations allowed (default: 4).
42 ///
43 /// Caps the counting semaphore used for CLI concurrency slots. The value must
44 /// stay within [1, 2×nCPUs]. Values above the ceiling are rejected with exit 2.
45 #[arg(long, global = true, value_name = "N")]
46 pub max_concurrency: Option<usize>,
47
48 /// Wait up to SECONDS for a free concurrency slot before giving up (exit 75).
49 ///
50 /// Useful in retrying agent pipelines: the process polls every 500 ms until a
51 /// slot opens or the timeout expires. Default: 300s (5 minutes).
52 #[arg(long, global = true, value_name = "SECONDS")]
53 pub wait_lock: Option<u64>,
54
55 /// Skip the available-memory check before loading the model.
56 ///
57 /// Exclusive use in automated tests where real allocation does not occur.
58 #[arg(long, global = true, hide = true, default_value_t = false)]
59 pub skip_memory_guard: bool,
60
61 /// v1.0.83 (ADR-0041): strict env-clear mode for compliance environments.
62 ///
63 /// When enabled, the LLM subprocess receives ONLY `PATH` — no
64 /// `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`
65 /// or other custom-provider credentials are forwarded. Defaults to
66 /// the standard v1.0.83 whitelist that preserves custom-provider
67 /// credentials (ADR-0041). Prefer the flag; optional XDG
68 /// `spawn.strict_env_clear=1` via `config set`.
69 #[arg(
70 long,
71 global = true,
72 hide = true,
73 default_value_t = false,
74 value_parser = clap::builder::BoolishValueParser::new(),
75 )]
76 pub strict_env_clear: bool,
77
78 /// v1.0.84 (ADR-0042 / GAP-002): resolve and print the LLM backend that
79 /// WOULD be invoked for embedding (binary path + model + flavour),
80 /// then exit 0 without executing the subprocess. Useful for CI
81 /// audit and sanity-check of `--llm-backend` before long sessions.
82 ///
83 /// Prefer the flag; optional XDG `llm.dry_run_backend=1` via `config set`.
84 #[arg(
85 long,
86 global = true,
87 hide = true,
88 default_value_t = false,
89 value_parser = clap::builder::BoolishValueParser::new(),
90 )]
91 pub dry_run_backend: bool,
92
93 /// Language for human-facing stderr messages. Accepts `en` or `pt`.
94 ///
95 /// Without the flag, detection uses XDG `i18n.lang` then OS locale
96 /// (`LC_ALL`/`LC_MESSAGES`/`LANG`). JSON stdout stays deterministic and
97 /// identical across languages; only human-facing strings are affected.
98 #[arg(long, global = true, value_enum, value_name = "LANG")]
99 pub lang: Option<crate::i18n::Language>,
100
101 /// Time zone for `*_iso` fields in JSON output (for example `America/Sao_Paulo`).
102 ///
103 /// Accepts any IANA time zone name. Without the flag, it falls back to
104 /// XDG `display.tz`; if unset, UTC is used. Integer epoch fields
105 /// are not affected.
106 #[arg(long, global = true, value_name = "IANA")]
107 pub tz: Option<chrono_tz::Tz>,
108
109 /// Increase logging verbosity (-v=info, -vv=debug, -vvv=trace).
110 ///
111 /// Overrides XDG `log.level` when present. Logs are emitted
112 /// to stderr; JSON stdout is unaffected.
113 #[arg(short = 'v', long, global = true, action = clap::ArgAction::Count)]
114 pub verbose: u8,
115
116 /// Suppress non-error tracing on stderr (sets log level to `error`).
117 ///
118 /// Prefer this in pipelines that capture stdout JSON (`> out.json`).
119 /// Never combine stdout and stderr into the same file (`&>` / `2>&1`) —
120 /// that contaminates the JSON envelope (v1.1.05 Bug 2). Conflicts with
121 /// `-v` / `--verbose` only in spirit: quiet wins when both are present.
122 #[arg(short = 'q', long, global = true, default_value_t = false)]
123 pub quiet: bool,
124
125 /// v1.0.75 (G21 solution): extraction backend selector. Accepts
126 /// `llm` (default), `embedding` (legacy), `none`, or `both` (composite).
127 /// The `llm` backend invokes claude code / codex CLI headless to extract
128 /// entities and relationships; `embedding` is a permanent stub since
129 /// v1.0.79 (legacy fastembed pipeline removed) that returns a clear
130 /// migration error.
131 #[arg(long, global = true, value_name = "KIND", default_value = "llm")]
132 pub extraction_backend: Option<String>,
133
134 /// v1.0.79 (G42/S1): embedding dimensionality override (default 64).
135 ///
136 /// Precedence: this flag > XDG `embedding.dim` >
137 /// the `dim` recorded in the database `schema_meta` > 64. Existing
138 /// databases keep their recorded dimensionality automatically; use
139 /// this flag only to migrate a corpus to a new dimensionality
140 /// (followed by `enrich --operation re-embed`). Range: [8, 4096].
141 #[arg(long, global = true, value_name = "N", value_parser = clap::value_parser!(u64).range(8..=4096))]
142 pub embedding_dim: Option<u64>,
143
144 /// v1.0.82 (GAP-003) / v1.0.84 (ADR-0042): LLM backend for embedding.
145 /// Accepts `auto` (detects via PATH, codex-first), `codex` (forces
146 /// `codex exec`), `claude` (forces `claude -p`; since v1.0.84 does NOT fall back to
147 /// codex — emits `AppError::Validation` if `claude` is absent),
148 /// `opencode` (forces `opencode run`), or `none`
149 /// (skips embedding; useful for tests). Prefer the flag; optional XDG
150 /// XDG `llm.backend` via `config set`.
151 #[arg(long, global = true, value_enum, default_value_t = LlmBackendChoice::Auto)]
152 pub llm_backend: LlmBackendChoice,
153
154 /// v1.0.82 (GAP-003): model to invoke on the chosen backend.
155 /// Prefer the flag; optional XDG `llm.model`. The default depends
156 /// on the backend (codex: `gpt-5.5`; claude: `claude-sonnet-4-6`).
157 #[arg(
158 long,
159 global = true,
160 value_name = "MODEL",
161 )]
162 pub llm_model: Option<String>,
163
164 /// v1.0.82 (GAP-003): path to the `claude` binary (overrides
165 /// PATH detection). Prefer the flag; optional XDG `llm.claude_binary`.
166 #[arg(
167 long,
168 global = true,
169 value_name = "PATH",
170 )]
171 pub claude_binary: Option<std::path::PathBuf>,
172
173 /// v1.0.89 (GAP-1): path to the `codex` binary (overrides
174 /// PATH detection). Prefer the flag; optional XDG `llm.codex_binary`.
175 #[arg(
176 long,
177 global = true,
178 value_name = "PATH",
179 )]
180 pub codex_binary: Option<std::path::PathBuf>,
181
182 /// v1.0.90 (GAP-OPENCODE-001): path to the `opencode` binary (overrides
183 /// PATH detection). Prefer the flag; optional XDG `llm.opencode_binary`.
184 #[arg(
185 long,
186 global = true,
187 value_name = "PATH",
188 )]
189 pub opencode_binary: Option<std::path::PathBuf>,
190
191 /// v1.0.82 (GAP-005): chain of LLM backends tried in order
192 /// when the primary fails. Default `codex,claude,none`. Prefer the
193 /// flag; optional XDG `llm.fallback`.
194 #[arg(
195 long,
196 global = true,
197 default_value = "codex,claude,none",
198 )]
199 pub llm_fallback: String,
200
201 /// v1.0.82 (GAP-005): persists with a NULL embedding when all
202 /// backends in the chain fail. The memory stays in `pending_embeddings`
203 /// for reprocessing via `embedding retry`. Prefer the flag; optional XDG
204 /// XDG `llm.skip_embedding_on_failure`.
205 #[arg(
206 long,
207 global = true,
208 default_value_t = false,
209 value_parser = clap::builder::BoolishValueParser::new(),
210 )]
211 pub skip_embedding_on_failure: bool,
212
213 /// v1.0.82 (GAP-004): host-wide limit of concurrent LLM
214 /// subprocesses. Default derived from `ncpus`. Prefer the flag; optional XDG
215 /// XDG `llm.max_host_concurrency`.
216 #[arg(
217 long,
218 global = true,
219 value_name = "N",
220 )]
221 pub llm_max_host_concurrency: Option<u32>,
222
223 /// v1.0.82 (GAP-004): seconds to wait for a free LLM slot
224 /// before failing with exit 75. Default 30s. Prefer the flag; optional XDG
225 /// XDG `llm.slot_wait_secs`.
226 #[arg(
227 long,
228 global = true,
229 value_name = "SECONDS",
230 )]
231 pub llm_slot_wait_secs: Option<u64>,
232
233 /// v1.0.82 (GAP-004): if set, fails immediately (exit 75)
234 /// when no LLM slot is free. Prefer the flag; optional XDG
235 /// XDG `llm.slot_no_wait`.
236 #[arg(
237 long,
238 global = true,
239 default_value_t = false,
240 value_parser = clap::builder::BoolishValueParser::new(),
241 )]
242 pub llm_slot_no_wait: bool,
243
244 /// v1.0.93: embedding backend selector. `auto` tries OpenRouter API if key
245 /// available, falls back to LLM subprocess. `openrouter` requires API key.
246 /// `llm` forces subprocess. Prefer the flag; optional XDG `embedding.backend`.
247 #[arg(long, global = true, value_enum, default_value_t = EmbeddingBackendChoice::Auto)]
248 pub embedding_backend: EmbeddingBackendChoice,
249
250 /// v1.0.93: embedding model for the OpenRouter API. Required when
251 /// `--embedding-backend openrouter`. Prefer the flag; optional XDG `embedding.model`.
252 #[arg(
253 long,
254 global = true,
255 value_name = "MODEL",
256 )]
257 pub embedding_model: Option<String>,
258
259 /// v1.0.93: OpenRouter API key (prefer env var or config.toml over CLI flag
260 /// to avoid shell history exposure). Prefer `config set-key openrouter`.
261 #[arg(
262 long,
263 global = true,
264 value_name = "KEY",
265 hide = true,
266 hide_env_values = true
267 )]
268 pub openrouter_api_key: Option<String>,
269
270 #[command(subcommand)]
271 pub command: Option<Commands>,
272}
273
274#[cfg(test)]
275#[path = "cli_json_only_format_tests.rs"]
276mod json_only_format_tests;
277
278
279impl Cli {
280 /// Validates concurrency flags and returns a localised descriptive error if invalid.
281 ///
282 /// Requires that `crate::i18n::init()` has already been called (happens before this
283 /// function in the `main` flow). In English it emits EN messages; in Portuguese it emits PT.
284 pub fn validate_flags(&self) -> Result<(), String> {
285 if let Some(n) = self.max_concurrency {
286 if n == 0 {
287 return Err(match current() {
288 Language::English => "--max-concurrency must be >= 1".to_string(),
289 Language::Portuguese => "--max-concurrency deve ser >= 1".to_string(),
290 });
291 }
292 let teto = max_concurrency_ceiling();
293 if n > teto {
294 return Err(match current() {
295 Language::English => format!(
296 "--max-concurrency {n} exceeds the ceiling of {teto} (2×nCPUs) on this system"
297 ),
298 Language::Portuguese => format!(
299 "--max-concurrency {n} excede o teto de {teto} (2×nCPUs) neste sistema"
300 ),
301 });
302 }
303 }
304 Ok(())
305 }
306}
307
308impl Commands {
309 /// Returns true for subcommands that load the ONNX model locally.
310 pub fn is_embedding_heavy(&self) -> bool {
311 matches!(
312 self,
313 Self::Init(_)
314 | Self::Remember(_)
315 | Self::RememberBatch(_)
316 | Self::Recall(_)
317 | Self::HybridSearch(_)
318 | Self::DeepResearch(_)
319 )
320 }
321
322 pub fn uses_cli_slot(&self) -> bool {
323 true
324 }
325
326 /// Read-only / no-embedding subcommands that MUST run without an embedding
327 /// API key. `init` warms a best-effort smoke test internally and degrades to
328 /// `ok_no_embedding` when the backend is unreachable; the `enrich` queue
329 /// inspectors (`--status` / `--list-dead` / `--requeue-dead` /
330 /// `--prune-dead-orphans`) never embed and never call the LLM. The eager
331 /// OpenRouter key preflight in `main` must skip its hard-fail for these.
332 pub fn tolerates_missing_embedding_key(&self) -> bool {
333 match self {
334 Self::Init(_) => true,
335 Self::Enrich(args) => {
336 args.status
337 || args.list_dead
338 || args.requeue_dead
339 || args.prune_dead_orphans
340 || args.prune_dead_entity_orphans
341 }
342 _ => false,
343 }
344 }
345}
346
347/// GAP-E2E-010 (v1.0.89): `codex-models` accepts `--json` as a no-op so
348/// agents that append `--json` to every subcommand never see clap errors.
349/// The handler in `main.rs` always emits JSON on stdout; this flag is
350/// accepted and ignored for parity with the rest of the CLI surface.
351#[derive(Debug, clap::Args)]
352pub struct CodexModelsArgs {
353 /// No-op; JSON is always emitted on stdout by `codex-models`.
354 #[arg(long, hide = true, help = "No-op; JSON is always emitted on stdout")]
355 pub json: bool,
356}
357
358#[derive(Subcommand)]
359pub enum Commands {
360 /// Initialize database and download embedding model
361 #[command(after_long_help = "EXAMPLES:\n \
362 # Initialize in current directory (default behavior)\n \
363 sqlite-graphrag init\n\n \
364 # Initialize at a specific path\n \
365 sqlite-graphrag init --db /path/to/graphrag.sqlite\n\n \
366 # Persist default db path via XDG config (no product env)\n \
367 sqlite-graphrag config set db.default_path /data/graphrag.sqlite\n \
368 sqlite-graphrag init\n\n\
369 NOTES:\n \
370 - `init` is OPTIONAL: any subsequent CRUD command auto-initializes graphrag.sqlite if missing.\n \
371 - As a side effect, `init` warms a smoke-test embedding via the LLM-only one-shot pipeline.")]
372 Init(init::InitArgs),
373 /// Save a memory with optional entity graph
374 #[command(after_long_help = "EXAMPLES:\n \
375 # Inline body\n \
376 sqlite-graphrag remember --name onboarding --type user --description \"intro\" --body \"hello\"\n\n \
377 # Body from file\n \
378 sqlite-graphrag remember --name doc1 --type document --description \"...\" --body-file ./README.md\n\n \
379 # Body from stdin (pipe)\n \
380 cat README.md | sqlite-graphrag remember --name doc1 --type document --description \"...\" --body-stdin\n\n \
381 # Enable automatic URL extraction (URL-regex only since v1.0.79)\n \
382 sqlite-graphrag remember --name rich --type note --description \"...\" --body \"...\" --enable-ner")]
383 Remember(remember::RememberArgs),
384 /// Batch-create memories from NDJSON stdin (one invocation, one slot)
385 #[command(after_long_help = "EXAMPLES:\n \
386 # Batch create from NDJSON\n \
387 cat memories.ndjson | sqlite-graphrag remember-batch --force-merge --json\n\n \
388 # Atomic batch\n \
389 cat memories.ndjson | sqlite-graphrag remember-batch --transaction --json")]
390 RememberBatch(remember_batch::RememberBatchArgs),
391 /// Bulk-ingest every file under a directory as separate memories (NDJSON output)
392 Ingest(Box<ingest::IngestArgs>),
393 /// Search memories semantically
394 #[command(after_long_help = "EXAMPLES:\n \
395 # Top 10 semantic matches (default)\n \
396 sqlite-graphrag recall \"agent memory\"\n\n \
397 # Top 3 only\n \
398 sqlite-graphrag recall \"agent memory\" -k 3\n\n \
399 # Search across all namespaces\n \
400 sqlite-graphrag recall \"agent memory\" --all-namespaces\n\n \
401 # Disable graph traversal (vector-only)\n \
402 sqlite-graphrag recall \"agent memory\" --no-graph")]
403 Recall(recall::RecallArgs),
404 /// Read a memory by exact name
405 Read(read::ReadArgs),
406 /// List memories with filters
407 List(list::ListArgs),
408 /// Soft-delete a memory
409 Forget(forget::ForgetArgs),
410 /// Permanently delete soft-deleted memories
411 Purge(purge::PurgeArgs),
412 /// Rename a memory preserving history
413 Rename(rename::RenameArgs),
414 /// Split an oversized memory body into N child memories (v1.1.03, GAP-V8)
415 SplitBody(split_body::SplitBodyArgs),
416 /// Edit a memory's body or description
417 Edit(edit::EditArgs),
418 /// List all versions of a memory
419 History(history::HistoryArgs),
420 /// Restore a memory to a previous version
421 Restore(restore::RestoreArgs),
422 /// Search using hybrid vector + full-text search
423 #[command(after_long_help = "EXAMPLES:\n \
424 # Hybrid search combining KNN + FTS5 BM25 with RRF\n \
425 sqlite-graphrag hybrid-search \"agent memory architecture\"\n\n \
426 # Custom weights for vector vs full-text components\n \
427 sqlite-graphrag hybrid-search \"agent\" --weight-vec 0.7 --weight-fts 0.3")]
428 HybridSearch(hybrid_search::HybridSearchArgs),
429 /// Show database health
430 Health(health::HealthArgs),
431 /// Apply pending schema migrations
432 Migrate(migrate::MigrateArgs),
433 /// Resolve namespace precedence for the current invocation
434 NamespaceDetect(namespace_detect::NamespaceDetectArgs),
435 /// Run PRAGMA optimize on the database
436 Optimize(optimize::OptimizeArgs),
437 /// Show database statistics
438 Stats(stats::StatsArgs),
439 /// Create a checkpointed copy safe for file sync
440 SyncSafeCopy(sync_safe_copy::SyncSafeCopyArgs),
441 /// Back up the database using the SQLite Online Backup API
442 Backup(backup::BackupArgs),
443 /// Run VACUUM after checkpointing the WAL
444 Vacuum(vacuum::VacuumArgs),
445 /// Create an explicit relationship between two entities
446 Link(link::LinkArgs),
447 /// Remove a specific relationship between two entities
448 Unlink(unlink::UnlinkArgs),
449 /// Deep parallel multi-hop GraphRAG research
450 #[command(name = "deep-research")]
451 DeepResearch(deep_research::DeepResearchArgs),
452 /// List memories connected via the entity graph
453 Related(related::RelatedArgs),
454 /// Export a graph snapshot in json, dot or mermaid
455 Graph(graph_export::GraphArgs),
456 /// Export memories as NDJSON (one JSON line per memory, plus a summary line)
457 Export(export::ExportArgs),
458 /// FTS5 full-text search index management (rebuild or check)
459 Fts(fts::FtsArgs),
460 /// Vector index maintenance (orphan detection, purge, stats) — G39
461 Vec(vec::VecArgs),
462 /// List codex OAuth models accepted by ChatGPT Pro (G33).
463 ///
464 /// GAP-E2E-010 (v1.0.89): accepts `--json` as a no-op (JSON is always
465 /// emitted on stdout) so the flag never breaks agent pipelines that
466 /// append `--json` to every invocation.
467 #[command(name = "codex-models")]
468 CodexModels(CodexModelsArgs),
469 /// Bulk-delete all relationships of a given type (e.g. mentions)
470 PruneRelations(prune_relations::PruneRelationsArgs),
471 /// Remove NER bindings (memory_entities rows) for an entity or all entities
472 #[command(name = "prune-ner")]
473 PruneNer(prune_ner::PruneNerArgs),
474 /// Inspect and manage cross-process LLM slot semaphore (GAP-004, v1.0.82)
475 Slots(slots::SlotsArgs),
476 /// Inspect and manage the `remember` checkpoint queue (GAP-001, v1.0.82)
477 Pending(pending::PendingArgs),
478 /// Health and per-entry inspection of the pending-embeddings queue (GAP-005, v1.0.82)
479 Embedding(embedding::EmbeddingArgs),
480 /// Batch operations over the pending-embeddings queue (GAP-005, v1.0.82)
481 #[command(name = "pending-embeddings")]
482 PendingEmbeddings(pending_embeddings::PendingEmbeddingsArgs),
483 /// Remove entities that have no memories and no relationships
484 CleanupOrphans(cleanup_orphans::CleanupOrphansArgs),
485 /// List entities linked to a specific memory
486 MemoryEntities(memory_entities::MemoryEntitiesArgs),
487 /// Manage cached resources (embedding models, etc.)
488 Cache(cache::CacheArgs),
489 /// Delete an entity and all its relationships from the graph
490 #[command(name = "delete-entity")]
491 DeleteEntity(delete_entity::DeleteEntityArgs),
492 /// Reclassify one entity or a batch of entities to a new type
493 Reclassify(reclassify::ReclassifyArgs),
494 /// Rename an entity preserving all relationships and memory bindings
495 #[command(name = "rename-entity")]
496 RenameEntity(rename_entity::RenameEntityArgs),
497 /// Merge multiple source entities into a single target entity
498 #[command(name = "merge-entities")]
499 MergeEntities(merge_entities::MergeEntitiesArgs),
500 /// Enrich graph memories and entities using an LLM provider
501 Enrich(Box<enrich::EnrichArgs>),
502 /// Reclassify relationship types across the graph using rules or LLM judgment
503 #[command(name = "reclassify-relation")]
504 ReclassifyRelation(reclassify_relation::ReclassifyRelationArgs),
505 /// Normalize entity names (deduplicate, kebab-case, merge near-duplicates)
506 #[command(name = "normalize-entities")]
507 NormalizeEntities(normalize_entities::NormalizeEntitiesArgs),
508 /// Generate shell completions for Bash, Zsh, Fish, PowerShell, or Elvish
509 Completions(completions::CompletionsArgs),
510 #[command(name = "debug-schema", hide = true)]
511 DebugSchema(debug_schema::DebugSchemaArgs),
512 /// Manage API keys and diagnose provider configuration (v1.0.93)
513 Config(config_cmd::ConfigArgs),
514}
515// FIX-1 (v1.0.89): manual `Debug` impl so test panic messages that print
516// `{:?}` on a captured `Commands` variant compile without requiring every
517// contained subcommand arg struct to derive `Debug`. The Debug output is
518// only used in test assertions for diagnostic messages; we emit the variant
519// name only — arg payload is intentionally omitted.
520impl std::fmt::Debug for Commands {
521 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
522 let name = match self {
523 Self::Init(_) => "Init",
524 Self::Health(_) => "Health",
525 Self::Stats(_) => "Stats",
526 Self::List(_) => "List",
527 Self::Read(_) => "Read",
528 Self::Edit(_) => "Edit",
529 Self::Rename(_) => "Rename",
530 Self::SplitBody(_) => "SplitBody",
531 Self::Restore(_) => "Restore",
532 Self::History(_) => "History",
533 Self::Forget(_) => "Forget",
534 Self::Purge(_) => "Purge",
535 Self::Remember(_) => "Remember",
536 Self::RememberBatch(_) => "RememberBatch",
537 Self::Recall(_) => "Recall",
538 Self::HybridSearch(_) => "HybridSearch",
539 Self::Enrich(_) => "Enrich",
540 Self::Ingest(_) => "Ingest",
541 Self::Optimize(_) => "Optimize",
542 Self::Migrate(_) => "Migrate",
543 Self::SyncSafeCopy(_) => "SyncSafeCopy",
544 Self::Backup(_) => "Backup",
545 Self::Vacuum(_) => "Vacuum",
546 Self::Link(_) => "Link",
547 Self::Unlink(_) => "Unlink",
548 Self::DeepResearch(_) => "DeepResearch",
549 Self::Related(_) => "Related",
550 Self::Graph(_) => "Graph",
551 Self::Export(_) => "Export",
552 Self::Fts(_) => "Fts",
553 Self::Vec(_) => "Vec",
554 Self::CodexModels(_) => "CodexModels",
555 Self::PruneRelations(_) => "PruneRelations",
556 Self::PruneNer(_) => "PruneNer",
557 Self::Slots(_) => "Slots",
558 Self::Pending(_) => "Pending",
559 Self::Embedding(_) => "Embedding",
560 Self::PendingEmbeddings(_) => "PendingEmbeddings",
561 Self::CleanupOrphans(_) => "CleanupOrphans",
562 Self::MemoryEntities(_) => "MemoryEntities",
563 Self::Cache(_) => "Cache",
564 Self::DeleteEntity(_) => "DeleteEntity",
565 Self::Reclassify(_) => "Reclassify",
566 Self::RenameEntity(_) => "RenameEntity",
567 Self::ReclassifyRelation(_) => "ReclassifyRelation",
568 Self::NormalizeEntities(_) => "NormalizeEntities",
569 Self::MergeEntities(_) => "MergeEntities",
570 Self::NamespaceDetect(_) => "NamespaceDetect",
571 Self::Completions(_) => "Completions",
572 Self::DebugSchema(_) => "DebugSchema",
573 Self::Config(_) => "Config",
574 };
575 f.write_str(name)
576 }
577}
578
579#[derive(Copy, Clone, Debug, Default, clap::ValueEnum)]
580pub enum MemoryType {
581 User,
582 Feedback,
583 Project,
584 Reference,
585 Decision,
586 Incident,
587 Skill,
588 #[default]
589 Document,
590 Note,
591}
592
593#[cfg(test)]
594#[path = "cli_heavy_concurrency_tests.rs"]
595mod heavy_concurrency_tests;
596
597
598impl MemoryType {
599 pub fn as_str(&self) -> &'static str {
600 match self {
601 Self::User => "user",
602 Self::Feedback => "feedback",
603 Self::Project => "project",
604 Self::Reference => "reference",
605 Self::Decision => "decision",
606 Self::Incident => "incident",
607 Self::Skill => "skill",
608 Self::Document => "document",
609 Self::Note => "note",
610 }
611 }
612}
613
614/// GAP-SG-31/33/34/35/30: parse-time contracts for the Fase G clap fixes.
615#[cfg(test)]
616#[path = "cli_fase_g_parsing_tests.rs"]
617mod fase_g_parsing_tests;