Extends the CLI with six new commands that complete the search pipeline: - lore search <QUERY>: Hybrid search with mode selection (lexical, hybrid, semantic), rich filtering (--type, --author, --project, --label, --path, --after, --updated-after), result limits, and optional explain mode showing RRF score breakdowns. Safe FTS mode sanitizes user input; raw mode passes through for power users. - lore stats: Document and index statistics with optional --check for integrity verification and --repair to fix inconsistencies (orphaned documents, missing FTS entries, stale dirty queue items). - lore embed: Generate vector embeddings via Ollama. Supports --retry-failed to re-attempt previously failed embeddings. - lore generate-docs: Drain the dirty queue to regenerate documents. --full seeds all entities for complete rebuild. --project scopes to a single project. - lore sync: Full pipeline orchestration (ingest issues + MRs, generate-docs, embed) with --no-embed and --no-docs flags for partial runs. Reports per-stage results and total elapsed time. - lore health: Quick pre-flight check (config exists, DB exists, schema current). Returns exit code 1 if unhealthy. Designed for agent pre-flight scripts. - lore robot-docs: Machine-readable command manifest for agent self-discovery. Returns all commands, flags, examples, exit codes, and recommended workflows as structured JSON. Also enhances lore init with --gitlab-url, --token-env-var, and --projects flags for fully non-interactive robot-mode initialization. Fixes init's force/non-interactive precedence logic and adds JSON output for robot mode. Updates all command files for the GiError -> LoreError rename. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
451 lines
11 KiB
Rust
451 lines
11 KiB
Rust
//! CLI module with clap command definitions.
|
|
|
|
pub mod commands;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
use std::io::IsTerminal;
|
|
|
|
/// Gitlore - Local GitLab data management with semantic search
|
|
#[derive(Parser)]
|
|
#[command(name = "lore")]
|
|
#[command(version, about, long_about = None)]
|
|
pub struct Cli {
|
|
/// Path to config file
|
|
#[arg(short = 'c', long, global = true)]
|
|
pub config: Option<String>,
|
|
|
|
/// Machine-readable JSON output (auto-enabled when piped)
|
|
#[arg(long, global = true, env = "LORE_ROBOT")]
|
|
pub robot: bool,
|
|
|
|
/// JSON output (global shorthand)
|
|
#[arg(short = 'J', long = "json", global = true)]
|
|
pub json: bool,
|
|
|
|
#[command(subcommand)]
|
|
pub command: Commands,
|
|
}
|
|
|
|
impl Cli {
|
|
/// Check if robot mode is active (explicit flag, env var, or non-TTY stdout)
|
|
pub fn is_robot_mode(&self) -> bool {
|
|
self.robot || self.json || !std::io::stdout().is_terminal()
|
|
}
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
#[allow(clippy::large_enum_variant)]
|
|
pub enum Commands {
|
|
/// List or show issues
|
|
Issues(IssuesArgs),
|
|
|
|
/// List or show merge requests
|
|
Mrs(MrsArgs),
|
|
|
|
/// Ingest data from GitLab
|
|
Ingest(IngestArgs),
|
|
|
|
/// Count entities in local database
|
|
Count(CountArgs),
|
|
|
|
/// Show sync state
|
|
Status,
|
|
|
|
/// Verify GitLab authentication
|
|
Auth,
|
|
|
|
/// Check environment health
|
|
Doctor,
|
|
|
|
/// Show version information
|
|
Version,
|
|
|
|
/// Initialize configuration and database
|
|
Init {
|
|
/// Skip overwrite confirmation
|
|
#[arg(short = 'f', long)]
|
|
force: bool,
|
|
|
|
/// Fail if prompts would be shown
|
|
#[arg(long)]
|
|
non_interactive: bool,
|
|
|
|
/// GitLab base URL (required in robot mode)
|
|
#[arg(long)]
|
|
gitlab_url: Option<String>,
|
|
|
|
/// Environment variable name holding GitLab token (required in robot mode)
|
|
#[arg(long)]
|
|
token_env_var: Option<String>,
|
|
|
|
/// Comma-separated project paths (required in robot mode)
|
|
#[arg(long)]
|
|
projects: Option<String>,
|
|
},
|
|
|
|
/// Create timestamped database backup
|
|
Backup,
|
|
|
|
/// Delete database and reset all state
|
|
Reset {
|
|
/// Skip confirmation prompt
|
|
#[arg(short = 'y', long)]
|
|
yes: bool,
|
|
},
|
|
|
|
/// Search indexed documents
|
|
Search(SearchArgs),
|
|
|
|
/// Show document and index statistics
|
|
Stats(StatsArgs),
|
|
|
|
/// Generate searchable documents from ingested data
|
|
#[command(name = "generate-docs")]
|
|
GenerateDocs(GenerateDocsArgs),
|
|
|
|
/// Generate vector embeddings for documents via Ollama
|
|
Embed(EmbedArgs),
|
|
|
|
/// Run full sync pipeline: ingest -> generate-docs -> embed
|
|
Sync(SyncArgs),
|
|
|
|
/// Run pending database migrations
|
|
Migrate,
|
|
|
|
/// Quick health check: config, database, schema version
|
|
Health,
|
|
|
|
/// Machine-readable command manifest for agent self-discovery
|
|
#[command(name = "robot-docs")]
|
|
RobotDocs,
|
|
|
|
// --- Hidden backward-compat aliases ---
|
|
/// List issues or MRs (deprecated: use 'lore issues' or 'lore mrs')
|
|
#[command(hide = true)]
|
|
List {
|
|
/// Entity type to list
|
|
#[arg(value_parser = ["issues", "mrs"])]
|
|
entity: String,
|
|
|
|
#[arg(long, default_value = "50")]
|
|
limit: usize,
|
|
#[arg(long)]
|
|
project: Option<String>,
|
|
#[arg(long)]
|
|
state: Option<String>,
|
|
#[arg(long)]
|
|
author: Option<String>,
|
|
#[arg(long)]
|
|
assignee: Option<String>,
|
|
#[arg(long)]
|
|
label: Option<Vec<String>>,
|
|
#[arg(long)]
|
|
milestone: Option<String>,
|
|
#[arg(long)]
|
|
since: Option<String>,
|
|
#[arg(long)]
|
|
due_before: Option<String>,
|
|
#[arg(long)]
|
|
has_due_date: bool,
|
|
#[arg(long, value_parser = ["updated", "created", "iid"], default_value = "updated")]
|
|
sort: String,
|
|
#[arg(long, value_parser = ["desc", "asc"], default_value = "desc")]
|
|
order: String,
|
|
#[arg(long)]
|
|
open: bool,
|
|
#[arg(long, conflicts_with = "no_draft")]
|
|
draft: bool,
|
|
#[arg(long, conflicts_with = "draft")]
|
|
no_draft: bool,
|
|
#[arg(long)]
|
|
reviewer: Option<String>,
|
|
#[arg(long)]
|
|
target_branch: Option<String>,
|
|
#[arg(long)]
|
|
source_branch: Option<String>,
|
|
},
|
|
|
|
/// Show detailed entity information (deprecated: use 'lore issues <IID>' or 'lore mrs <IID>')
|
|
#[command(hide = true)]
|
|
Show {
|
|
/// Entity type to show
|
|
#[arg(value_parser = ["issue", "mr"])]
|
|
entity: String,
|
|
|
|
/// Entity IID
|
|
iid: i64,
|
|
|
|
#[arg(long)]
|
|
project: Option<String>,
|
|
},
|
|
|
|
/// Verify GitLab authentication (deprecated: use 'lore auth')
|
|
#[command(hide = true, name = "auth-test")]
|
|
AuthTest,
|
|
|
|
/// Show sync state (deprecated: use 'lore status')
|
|
#[command(hide = true, name = "sync-status")]
|
|
SyncStatus,
|
|
}
|
|
|
|
/// Arguments for `lore issues [IID]`
|
|
#[derive(Parser)]
|
|
pub struct IssuesArgs {
|
|
/// Issue IID (omit to list, provide to show details)
|
|
pub iid: Option<i64>,
|
|
|
|
/// Maximum results
|
|
#[arg(short = 'n', long = "limit", default_value = "50")]
|
|
pub limit: usize,
|
|
|
|
/// Filter by state (opened, closed, all)
|
|
#[arg(short = 's', long)]
|
|
pub state: Option<String>,
|
|
|
|
/// Filter by project path
|
|
#[arg(short = 'p', long)]
|
|
pub project: Option<String>,
|
|
|
|
/// Filter by author username
|
|
#[arg(short = 'a', long)]
|
|
pub author: Option<String>,
|
|
|
|
/// Filter by assignee username
|
|
#[arg(short = 'A', long)]
|
|
pub assignee: Option<String>,
|
|
|
|
/// Filter by label (repeatable, AND logic)
|
|
#[arg(short = 'l', long)]
|
|
pub label: Option<Vec<String>>,
|
|
|
|
/// Filter by milestone title
|
|
#[arg(short = 'm', long)]
|
|
pub milestone: Option<String>,
|
|
|
|
/// Filter by time (7d, 2w, 1m, or YYYY-MM-DD)
|
|
#[arg(long)]
|
|
pub since: Option<String>,
|
|
|
|
/// Filter by due date (before this date, YYYY-MM-DD)
|
|
#[arg(long = "due-before")]
|
|
pub due_before: Option<String>,
|
|
|
|
/// Show only issues with a due date
|
|
#[arg(long = "has-due")]
|
|
pub has_due: bool,
|
|
|
|
/// Sort field (updated, created, iid)
|
|
#[arg(long, value_parser = ["updated", "created", "iid"], default_value = "updated")]
|
|
pub sort: String,
|
|
|
|
/// Sort ascending (default: descending)
|
|
#[arg(long)]
|
|
pub asc: bool,
|
|
|
|
/// Open first matching item in browser
|
|
#[arg(short = 'o', long)]
|
|
pub open: bool,
|
|
}
|
|
|
|
/// Arguments for `lore mrs [IID]`
|
|
#[derive(Parser)]
|
|
pub struct MrsArgs {
|
|
/// MR IID (omit to list, provide to show details)
|
|
pub iid: Option<i64>,
|
|
|
|
/// Maximum results
|
|
#[arg(short = 'n', long = "limit", default_value = "50")]
|
|
pub limit: usize,
|
|
|
|
/// Filter by state (opened, merged, closed, locked, all)
|
|
#[arg(short = 's', long)]
|
|
pub state: Option<String>,
|
|
|
|
/// Filter by project path
|
|
#[arg(short = 'p', long)]
|
|
pub project: Option<String>,
|
|
|
|
/// Filter by author username
|
|
#[arg(short = 'a', long)]
|
|
pub author: Option<String>,
|
|
|
|
/// Filter by assignee username
|
|
#[arg(short = 'A', long)]
|
|
pub assignee: Option<String>,
|
|
|
|
/// Filter by reviewer username
|
|
#[arg(short = 'r', long)]
|
|
pub reviewer: Option<String>,
|
|
|
|
/// Filter by label (repeatable, AND logic)
|
|
#[arg(short = 'l', long)]
|
|
pub label: Option<Vec<String>>,
|
|
|
|
/// Filter by time (7d, 2w, 1m, or YYYY-MM-DD)
|
|
#[arg(long)]
|
|
pub since: Option<String>,
|
|
|
|
/// Show only draft MRs
|
|
#[arg(short = 'd', long, conflicts_with = "no_draft")]
|
|
pub draft: bool,
|
|
|
|
/// Exclude draft MRs
|
|
#[arg(short = 'D', long = "no-draft", conflicts_with = "draft")]
|
|
pub no_draft: bool,
|
|
|
|
/// Filter by target branch
|
|
#[arg(long)]
|
|
pub target: Option<String>,
|
|
|
|
/// Filter by source branch
|
|
#[arg(long)]
|
|
pub source: Option<String>,
|
|
|
|
/// Sort field (updated, created, iid)
|
|
#[arg(long, value_parser = ["updated", "created", "iid"], default_value = "updated")]
|
|
pub sort: String,
|
|
|
|
/// Sort ascending (default: descending)
|
|
#[arg(long)]
|
|
pub asc: bool,
|
|
|
|
/// Open first matching item in browser
|
|
#[arg(short = 'o', long)]
|
|
pub open: bool,
|
|
}
|
|
|
|
/// Arguments for `lore ingest [ENTITY]`
|
|
#[derive(Parser)]
|
|
pub struct IngestArgs {
|
|
/// Entity to ingest (issues, mrs). Omit to ingest everything.
|
|
#[arg(value_parser = ["issues", "mrs"])]
|
|
pub entity: Option<String>,
|
|
|
|
/// Filter to single project
|
|
#[arg(short = 'p', long)]
|
|
pub project: Option<String>,
|
|
|
|
/// Override stale sync lock
|
|
#[arg(short = 'f', long)]
|
|
pub force: bool,
|
|
|
|
/// Full re-sync: reset cursors and fetch all data from scratch
|
|
#[arg(long)]
|
|
pub full: bool,
|
|
}
|
|
|
|
/// Arguments for `lore stats`
|
|
#[derive(Parser)]
|
|
pub struct StatsArgs {
|
|
/// Run integrity checks
|
|
#[arg(long)]
|
|
pub check: bool,
|
|
|
|
/// Repair integrity issues (requires --check)
|
|
#[arg(long, requires = "check")]
|
|
pub repair: bool,
|
|
}
|
|
|
|
/// Arguments for `lore search <QUERY>`
|
|
#[derive(Parser)]
|
|
pub struct SearchArgs {
|
|
/// Search query string
|
|
pub query: String,
|
|
|
|
/// Search mode (lexical, hybrid, semantic)
|
|
#[arg(long, default_value = "hybrid")]
|
|
pub mode: String,
|
|
|
|
/// Filter by source type (issue, mr, discussion)
|
|
#[arg(long = "type", value_name = "TYPE")]
|
|
pub source_type: Option<String>,
|
|
|
|
/// Filter by author username
|
|
#[arg(long)]
|
|
pub author: Option<String>,
|
|
|
|
/// Filter by project path
|
|
#[arg(short = 'p', long)]
|
|
pub project: Option<String>,
|
|
|
|
/// Filter by label (repeatable, AND logic)
|
|
#[arg(long, action = clap::ArgAction::Append)]
|
|
pub label: Vec<String>,
|
|
|
|
/// Filter by file path (trailing / for prefix match)
|
|
#[arg(long)]
|
|
pub path: Option<String>,
|
|
|
|
/// Filter by created after (7d, 2w, or YYYY-MM-DD)
|
|
#[arg(long)]
|
|
pub after: Option<String>,
|
|
|
|
/// Filter by updated after (7d, 2w, or YYYY-MM-DD)
|
|
#[arg(long = "updated-after")]
|
|
pub updated_after: Option<String>,
|
|
|
|
/// Maximum results (default 20, max 100)
|
|
#[arg(short = 'n', long = "limit", default_value = "20")]
|
|
pub limit: usize,
|
|
|
|
/// Show ranking explanation per result
|
|
#[arg(long)]
|
|
pub explain: bool,
|
|
|
|
/// FTS query mode: safe (default) or raw
|
|
#[arg(long = "fts-mode", default_value = "safe")]
|
|
pub fts_mode: String,
|
|
}
|
|
|
|
/// Arguments for `lore generate-docs`
|
|
#[derive(Parser)]
|
|
pub struct GenerateDocsArgs {
|
|
/// Full rebuild: seed all entities into dirty queue, then drain
|
|
#[arg(long)]
|
|
pub full: bool,
|
|
|
|
/// Filter to single project
|
|
#[arg(short = 'p', long)]
|
|
pub project: Option<String>,
|
|
}
|
|
|
|
/// Arguments for `lore sync`
|
|
#[derive(Parser)]
|
|
pub struct SyncArgs {
|
|
/// Reset cursors, fetch everything
|
|
#[arg(long)]
|
|
pub full: bool,
|
|
|
|
/// Override stale lock
|
|
#[arg(long)]
|
|
pub force: bool,
|
|
|
|
/// Skip embedding step
|
|
#[arg(long)]
|
|
pub no_embed: bool,
|
|
|
|
/// Skip document regeneration
|
|
#[arg(long)]
|
|
pub no_docs: bool,
|
|
}
|
|
|
|
/// Arguments for `lore embed`
|
|
#[derive(Parser)]
|
|
pub struct EmbedArgs {
|
|
/// Retry previously failed embeddings
|
|
#[arg(long)]
|
|
pub retry_failed: bool,
|
|
}
|
|
|
|
/// Arguments for `lore count <ENTITY>`
|
|
#[derive(Parser)]
|
|
pub struct CountArgs {
|
|
/// Entity type to count (issues, mrs, discussions, notes)
|
|
#[arg(value_parser = ["issues", "mrs", "discussions", "notes"])]
|
|
pub entity: String,
|
|
|
|
/// Parent type filter: issue or mr (for discussions/notes)
|
|
#[arg(short = 'f', long = "for", value_parser = ["issue", "mr"])]
|
|
pub for_entity: Option<String>,
|
|
}
|