Skip to main content

codex_recall/
cli.rs

1use crate::commands::doctor::{run_doctor, run_stats, DoctorArgs, StatsArgs};
2use crate::commands::index::{run_index, run_rebuild, IndexArgs, RebuildArgs};
3use crate::commands::pins::{run_pin, run_pins, run_unpin, PinArgs, PinsArgs, UnpinArgs};
4use crate::commands::recent::{run_day, run_recent, DayArgs, RecentArgs};
5use crate::commands::search::{run_bundle, run_search, run_show, BundleArgs, SearchArgs, ShowArgs};
6use crate::commands::watch::{run_status, run_watch, StatusArgs, WatchArgs};
7use anyhow::Result;
8use clap::{CommandFactory, Parser, Subcommand};
9
10#[derive(Debug, Parser)]
11#[command(
12    version,
13    about = "Local search and recall for Codex session JSONL archives"
14)]
15struct Cli {
16    #[command(subcommand)]
17    command: Option<Command>,
18}
19
20#[derive(Debug, Subcommand)]
21enum Command {
22    /// Incrementally index Codex session archives.
23    Index(IndexArgs),
24    /// Delete and rebuild the index from session archives.
25    Rebuild(RebuildArgs),
26    /// Continuously index stable pending session files.
27    Watch(WatchArgs),
28    /// Show watch/index freshness and pending-file status.
29    Status(StatusArgs),
30    /// Search indexed sessions and print grouped receipts.
31    Search(SearchArgs),
32    /// Show latest indexed sessions without a query.
33    Recent(RecentArgs),
34    /// Show an indexed session inventory for one local calendar day.
35    Day(DayArgs),
36    /// Print a compact Markdown bundle for a search query.
37    Bundle(BundleArgs),
38    /// Show indexed events for one session.
39    Show(ShowArgs),
40    /// Pin a high-value session anchor.
41    Pin(PinArgs),
42    /// List pinned session anchors.
43    Pins(PinsArgs),
44    /// Remove a pinned session anchor.
45    Unpin(UnpinArgs),
46    /// Check database health, FTS integrity, and source paths.
47    Doctor(DoctorArgs),
48    /// Print database counts.
49    Stats(StatsArgs),
50}
51
52pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
53    let cli = Cli::parse_from(std::iter::once("codex-recall".to_owned()).chain(args));
54    match cli.command {
55        Some(Command::Index(args)) => run_index(args),
56        Some(Command::Rebuild(args)) => run_rebuild(args),
57        Some(Command::Watch(args)) => run_watch(args),
58        Some(Command::Status(args)) => run_status(args),
59        Some(Command::Search(args)) => run_search(args),
60        Some(Command::Recent(args)) => run_recent(args),
61        Some(Command::Day(args)) => run_day(args),
62        Some(Command::Bundle(args)) => run_bundle(args),
63        Some(Command::Show(args)) => run_show(args),
64        Some(Command::Pin(args)) => run_pin(args),
65        Some(Command::Pins(args)) => run_pins(args),
66        Some(Command::Unpin(args)) => run_unpin(args),
67        Some(Command::Doctor(args)) => run_doctor(args),
68        Some(Command::Stats(args)) => run_stats(args),
69        None => {
70            Cli::command().print_help()?;
71            println!();
72            Ok(())
73        }
74    }
75}