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::memory::{
4    run_delta, run_eval, run_memories, run_memory_show, run_read_resource, run_related,
5    run_resources, DeltaArgs, EvalArgs, MemoriesArgs, MemoryShowArgs, ReadResourceArgs,
6    RelatedArgs, ResourcesArgs,
7};
8use crate::commands::pins::{run_pin, run_pins, run_unpin, PinArgs, PinsArgs, UnpinArgs};
9use crate::commands::recent::{run_day, run_recent, DayArgs, RecentArgs};
10use crate::commands::search::{run_bundle, run_search, run_show, BundleArgs, SearchArgs, ShowArgs};
11use crate::commands::watch::{run_status, run_watch, StatusArgs, WatchArgs};
12use anyhow::Result;
13use clap::{CommandFactory, Parser, Subcommand};
14
15#[derive(Debug, Parser)]
16#[command(
17    version,
18    about = "Local search and recall for Codex session JSONL archives"
19)]
20struct Cli {
21    #[command(subcommand)]
22    command: Option<Command>,
23}
24
25#[derive(Debug, Subcommand)]
26enum Command {
27    /// Incrementally index Codex session archives.
28    Index(IndexArgs),
29    /// Delete and rebuild the index from session archives.
30    Rebuild(RebuildArgs),
31    /// Continuously index stable pending session files.
32    Watch(WatchArgs),
33    /// Show watch/index freshness and pending-file status.
34    Status(StatusArgs),
35    /// Search indexed sessions and print grouped receipts.
36    Search(SearchArgs),
37    /// Show latest indexed sessions without a query.
38    Recent(RecentArgs),
39    /// Show an indexed session inventory for one local calendar day.
40    Day(DayArgs),
41    /// Print a compact Markdown bundle for a search query.
42    Bundle(BundleArgs),
43    /// Show indexed events for one session.
44    Show(ShowArgs),
45    /// List or query extracted memory objects.
46    Memories(MemoriesArgs),
47    /// Show one extracted memory object with evidence receipts.
48    MemoryShow(MemoryShowArgs),
49    /// List changed sessions and memories since an optional cursor.
50    Delta(DeltaArgs),
51    /// Expand related sessions and memories from a session or memory reference.
52    Related(RelatedArgs),
53    /// Run retrieval eval cases from a JSON fixture.
54    Eval(EvalArgs),
55    /// List MCP-style resources for sessions and memories.
56    Resources(ResourcesArgs),
57    /// Read a single MCP-style session or memory resource.
58    ReadResource(ReadResourceArgs),
59    /// Pin a high-value session anchor.
60    Pin(PinArgs),
61    /// List pinned session anchors.
62    Pins(PinsArgs),
63    /// Remove a pinned session anchor.
64    Unpin(UnpinArgs),
65    /// Check database health, FTS integrity, and source paths.
66    Doctor(DoctorArgs),
67    /// Print database counts.
68    Stats(StatsArgs),
69}
70
71pub fn run(args: impl IntoIterator<Item = String>) -> Result<()> {
72    let cli = Cli::parse_from(std::iter::once("codex-recall".to_owned()).chain(args));
73    match cli.command {
74        Some(Command::Index(args)) => run_index(args),
75        Some(Command::Rebuild(args)) => run_rebuild(args),
76        Some(Command::Watch(args)) => run_watch(args),
77        Some(Command::Status(args)) => run_status(args),
78        Some(Command::Search(args)) => run_search(args),
79        Some(Command::Recent(args)) => run_recent(args),
80        Some(Command::Day(args)) => run_day(args),
81        Some(Command::Bundle(args)) => run_bundle(args),
82        Some(Command::Show(args)) => run_show(args),
83        Some(Command::Memories(args)) => run_memories(args),
84        Some(Command::MemoryShow(args)) => run_memory_show(args),
85        Some(Command::Delta(args)) => run_delta(args),
86        Some(Command::Related(args)) => run_related(args),
87        Some(Command::Eval(args)) => run_eval(args),
88        Some(Command::Resources(args)) => run_resources(args),
89        Some(Command::ReadResource(args)) => run_read_resource(args),
90        Some(Command::Pin(args)) => run_pin(args),
91        Some(Command::Pins(args)) => run_pins(args),
92        Some(Command::Unpin(args)) => run_unpin(args),
93        Some(Command::Doctor(args)) => run_doctor(args),
94        Some(Command::Stats(args)) => run_stats(args),
95        None => {
96            Cli::command().print_help()?;
97            println!();
98            Ok(())
99        }
100    }
101}