use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "kiromi-ai", version, about, long_about = None)]
pub(crate) struct Cli {
#[command(flatten)]
pub(crate) globals: GlobalArgs,
#[command(subcommand)]
pub(crate) command: Command,
}
#[derive(Debug, Args, Clone)]
pub(crate) struct GlobalArgs {
#[arg(long, env = "KIROMI_AI_CONFIG", global = true)]
pub(crate) config: Option<PathBuf>,
#[arg(long, env = "KIROMI_AI_STORAGE", global = true)]
pub(crate) storage: Option<String>,
#[arg(long, env = "KIROMI_AI_METADATA", global = true)]
pub(crate) metadata: Option<String>,
#[arg(long, env = "KIROMI_AI_TENANT", global = true)]
pub(crate) tenant: Option<String>,
#[arg(long, env = "KIROMI_AI_SCHEME", global = true)]
pub(crate) scheme: Option<String>,
#[arg(
long = "embedder-family",
env = "KIROMI_AI_EMBEDDER_FAMILY",
global = true
)]
pub(crate) embedder_family: Option<String>,
#[arg(
long = "embedder-config",
env = "KIROMI_AI_EMBEDDER_CONFIG",
global = true
)]
pub(crate) embedder_config: Option<String>,
#[arg(long = "no-embedder", env = "KIROMI_AI_NO_EMBEDDER", global = true)]
pub(crate) no_embedder: bool,
#[arg(long, env = "KIROMI_AI_ACTOR", global = true)]
pub(crate) actor: Option<String>,
#[arg(long, env = "KIROMI_AI_JSON", global = true)]
pub(crate) json: bool,
#[arg(short, long, action = clap::ArgAction::Count, global = true)]
pub(crate) verbose: u8,
}
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
Init(InitArgs),
Append(AppendArgs),
Get(GetArgs),
List(ListArgs),
Search(SearchArgs),
Related(RelatedArgs),
#[command(subcommand)]
Link(LinkCmd),
Delete(DeleteArgs),
#[command(name = "delete-partition")]
DeletePartition(DeletePartitionArgs),
Inspect(InspectArgs),
Export(ExportArgs),
#[command(subcommand)]
Attribute(AttributeCmd),
#[command(subcommand)]
Snapshot(SnapshotCmd),
#[command(subcommand)]
Regenerate(RegenerateCmd),
#[command(name = "migrate-scheme")]
MigrateScheme(MigrateSchemeArgs),
Gc(GcArgs),
Context(ContextArgs),
}
#[derive(Debug, Subcommand)]
pub(crate) enum SnapshotCmd {
Create(SnapshotCreateArgs),
List,
Delete(SnapshotDeleteArgs),
Restore(SnapshotRestoreArgs),
}
#[derive(Debug, Args)]
pub(crate) struct SnapshotCreateArgs {
#[arg(long)]
pub(crate) tag: Option<String>,
#[arg(long)]
pub(crate) reason: Option<String>,
}
#[derive(Debug, Args)]
pub(crate) struct SnapshotDeleteArgs {
pub(crate) id: String,
}
#[derive(Debug, Args)]
pub(crate) struct SnapshotRestoreArgs {
pub(crate) id: String,
#[arg(long = "no-attributes")]
pub(crate) no_attributes: bool,
}
#[derive(Debug, Subcommand)]
pub(crate) enum RegenerateCmd {
Embeddings(RegenerateEmbeddingsArgs),
#[command(name = "summaries-list")]
SummariesList(RegenerateSummariesListArgs),
Reindex(ReindexArgs),
}
#[derive(Debug, Args)]
pub(crate) struct ScopeArg {
#[arg(long, default_value = "all")]
pub(crate) scope: String,
}
#[derive(Debug, Args)]
pub(crate) struct RegenerateEmbeddingsArgs {
#[command(flatten)]
pub(crate) scope: ScopeArg,
}
#[derive(Debug, Args)]
pub(crate) struct RegenerateSummariesListArgs {
#[command(flatten)]
pub(crate) scope: ScopeArg,
#[arg(long)]
pub(crate) force: bool,
#[arg(long, default_value = "compact")]
pub(crate) style: String,
}
#[derive(Debug, Args)]
pub(crate) struct ReindexArgs {
#[command(flatten)]
pub(crate) scope: ScopeArg,
}
#[derive(Debug, Args)]
pub(crate) struct MigrateSchemeArgs {
#[arg(long = "new-scheme")]
pub(crate) new_scheme: String,
#[arg(long = "mapper-binary")]
pub(crate) mapper_binary: std::path::PathBuf,
#[arg(long)]
pub(crate) dry_run: bool,
#[arg(long = "no-snapshot")]
pub(crate) no_snapshot: bool,
#[arg(long = "batch-size", default_value_t = 64)]
pub(crate) batch_size: u32,
}
#[derive(Debug, Args)]
pub(crate) struct GcArgs {
#[arg(long = "retain-for", default_value = "24h")]
pub(crate) retain_for: String,
#[arg(long)]
pub(crate) dry_run: bool,
}
#[derive(Debug, Args)]
pub(crate) struct ContextArgs {
#[arg(long)]
pub(crate) focus: String,
#[arg(long, default_value_t = 4_000)]
pub(crate) budget: u32,
#[arg(long = "top-k", default_value_t = 5)]
pub(crate) top_k: u32,
#[arg(long, default_value_t = true)]
pub(crate) memo: bool,
}
#[derive(Debug, Subcommand)]
pub(crate) enum AttributeCmd {
Set(AttrSetArgs),
Get(AttrGetArgs),
Clear(AttrClearArgs),
List(AttrListArgs),
Find(AttrFindArgs),
FindRange(AttrFindRangeArgs),
}
#[derive(Debug, Args, Clone)]
pub(crate) struct AttrKindArg {
#[arg(long, default_value = "string")]
pub(crate) kind: String,
}
#[derive(Debug, Args)]
pub(crate) struct AttrSetArgs {
#[arg(long)]
pub(crate) memory: String,
#[arg(long)]
pub(crate) key: String,
#[arg(long)]
pub(crate) value: String,
#[command(flatten)]
pub(crate) kind: AttrKindArg,
}
#[derive(Debug, Args)]
pub(crate) struct AttrGetArgs {
#[arg(long)]
pub(crate) memory: String,
#[arg(long)]
pub(crate) key: String,
}
#[derive(Debug, Args)]
pub(crate) struct AttrClearArgs {
#[arg(long)]
pub(crate) memory: String,
#[arg(long)]
pub(crate) key: String,
}
#[derive(Debug, Args)]
pub(crate) struct AttrListArgs {
#[arg(long)]
pub(crate) memory: String,
}
#[derive(Debug, Args)]
pub(crate) struct AttrFindArgs {
#[arg(long)]
pub(crate) key: String,
#[arg(long)]
pub(crate) value: String,
#[command(flatten)]
pub(crate) kind: AttrKindArg,
}
#[derive(Debug, Args)]
pub(crate) struct AttrFindRangeArgs {
#[arg(long)]
pub(crate) key: String,
#[arg(long)]
pub(crate) min: String,
#[arg(long)]
pub(crate) max: String,
#[arg(long, default_value = "int")]
pub(crate) kind: String,
}
#[derive(Debug, Args)]
pub(crate) struct InitArgs {
#[arg(long)]
pub(crate) force: bool,
}
#[derive(Debug, Args)]
pub(crate) struct AppendArgs {
#[arg(long)]
pub(crate) partition: String,
#[arg(long, conflicts_with_all = ["stdin", "message"])]
pub(crate) file: Option<PathBuf>,
#[arg(long, conflicts_with_all = ["file", "message"])]
pub(crate) stdin: bool,
#[arg(long, conflicts_with_all = ["file", "stdin"])]
pub(crate) message: Option<String>,
#[arg(long, default_value = "md")]
pub(crate) kind: String,
#[arg(long)]
pub(crate) embedding: Option<PathBuf>,
#[arg(long = "link", value_name = "MEMORY_ID")]
pub(crate) links: Vec<String>,
}
#[derive(Debug, Args)]
pub(crate) struct GetArgs {
pub(crate) id: String,
}
#[derive(Debug, Args)]
pub(crate) struct ListArgs {
#[arg(long)]
pub(crate) partition: String,
#[arg(long, default_value_t = 50)]
pub(crate) limit: u32,
#[arg(long)]
pub(crate) cursor: Option<String>,
#[arg(long = "include-tombstoned")]
pub(crate) include_tombstoned: bool,
}
#[derive(Debug, Args)]
pub(crate) struct SearchArgs {
pub(crate) query: String,
#[arg(long, conflicts_with_all = ["text", "hybrid"])]
pub(crate) semantic: bool,
#[arg(long, conflicts_with_all = ["semantic", "hybrid"])]
pub(crate) text: bool,
#[arg(long, conflicts_with_all = ["semantic", "text"])]
pub(crate) hybrid: bool,
#[arg(long)]
pub(crate) alpha: Option<f32>,
#[arg(long, default_value_t = 10)]
pub(crate) top: usize,
#[arg(long)]
pub(crate) within: Option<String>,
}
#[derive(Debug, Args)]
pub(crate) struct RelatedArgs {
pub(crate) id: String,
#[arg(long, default_value_t = 5)]
pub(crate) top: usize,
}
#[derive(Debug, Subcommand)]
pub(crate) enum LinkCmd {
Add {
src: String,
dst: String,
},
Remove {
src: String,
dst: String,
},
List {
id: String,
},
}
#[derive(Debug, Args)]
pub(crate) struct DeleteArgs {
pub(crate) id: String,
}
#[derive(Debug, Args)]
pub(crate) struct DeletePartitionArgs {
pub(crate) path: String,
}
#[derive(Debug, Args)]
pub(crate) struct InspectArgs {
#[arg(long, conflicts_with = "partition")]
pub(crate) memory: Option<String>,
#[arg(long, conflicts_with = "memory")]
pub(crate) partition: Option<String>,
}
#[derive(Debug, Args)]
pub(crate) struct ExportArgs {
#[arg(long)]
pub(crate) partition: String,
#[arg(long)]
pub(crate) to: PathBuf,
}