whetstone-cli 3.19.1

Installer and CLI for Claude Code token optimization (Headroom + RTK + Memory)
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(
    name = "whetstone",
    version = env!("WHETSTONE_VERSION"),
    about = "Headroom + RTK + Memory for Claude Code"
)]
pub struct Cli {
    /// Enable Headroom persistent cross-session memory for this run.
    /// Passes `--memory` to the proxy whetstone manages; a session with
    /// memory gets its own proxy, separate from one without.
    #[arg(long, global = true)]
    pub memory: bool,

    #[command(subcommand)]
    pub command: Option<Command>,
}

#[derive(Subcommand)]
pub enum Command {
    /// Install Headroom, RTK, and a memory provider
    Setup {
        /// Force-upgrade all tools and refresh installed files
        #[arg(long)]
        full: bool,

        /// Headroom pip extras: "all" (default), "none", or
        /// comma-separated like "proxy,code"
        #[arg(long, default_value = "all")]
        headroom_extras: String,

        /// Run the Headroom proxy on another machine, reached over SSH
        /// (user@host, an ssh-config alias, or ssh://user@host:port).
        /// Saved for this project; skips the interactive question
        #[arg(long, value_name = "SSH_DEST")]
        headroom_remote: Option<String>,

        /// With --headroom-remote: install Headroom on that machine too
        #[arg(long, requires = "headroom_remote")]
        remote_install: bool,
    },

    /// Deprecated: use `project uninstall` or `global uninstall`
    Uninstall,

    /// Project-scoped operations
    Project {
        #[command(subcommand)]
        action: ProjectCommand,
    },

    /// Global operations
    Global {
        #[command(subcommand)]
        action: GlobalCommand,
    },

    /// Start Claude Code via headroom wrap (default when no subcommand given)
    Claude {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },

    /// Alias for claude
    Code {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },

    /// Run headroom proxy
    Proxy {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },

    /// Run rtk
    Rtk {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },

    /// Print whetstone version
    Version,

    /// Internal: background update watcher for the session running as PID
    #[command(hide = true)]
    UpdateWatch { pid: u32 },

    /// Interactive dashboard
    Dashboard,

    /// Modify project settings interactively
    Settings,

    /// Check dependencies + ~/.claude/settings.json and report problems
    Doctor {
        /// Reinstall missing dependencies without prompting
        #[arg(long)]
        fix: bool,

        /// Headroom pip extras used when reinstalling: "all" (default),
        /// "none", or comma-separated like "proxy,code"
        #[arg(long, default_value = "all")]
        headroom_extras: String,
    },

    /// Install or repair every managed dependency (headroom, rtk, claude
    /// code, memory provider) and re-wire their hooks
    InstallTools {
        /// Reinstall/upgrade everything, not just what is missing
        #[arg(long)]
        force: bool,

        /// Headroom pip extras: "all" (default), "none", or
        /// comma-separated like "proxy,code"
        #[arg(long, default_value = "all")]
        headroom_extras: String,
    },

    /// Migrate a v2 install to v3 (Phase 3)
    Migrate {
        /// Print the plan without writing anything
        #[arg(long)]
        dry_run: bool,

        /// Skip the interactive confirmation
        #[arg(long, short = 'y')]
        yes: bool,

        /// Restore an earlier migration by id (e.g. 20260607-153012)
        #[arg(long, value_name = "MIGRATION_ID")]
        rollback: Option<String>,
    },

    /// Pull latest and rerun setup
    Update {
        #[arg(long)]
        full: bool,
    },

    /// Prepare a release PR; GitHub Actions publishes after merge
    Release {
        #[command(subcommand)]
        action: ReleaseAction,
    },

    /// Deprecated legacy release path
    ReleasePublish {
        #[command(subcommand)]
        action: ReleaseAction,
    },

    /// Regenerate site/src/changelog.js from CHANGELOG.md
    ChangelogSync {
        /// Path to CHANGELOG.md (defaults to repo root)
        #[arg(long)]
        input: Option<String>,

        /// Output JS file (defaults to site/src/changelog.js)
        #[arg(long)]
        output: Option<String>,

        /// Max number of releases to include
        #[arg(long, default_value_t = 8)]
        limit: usize,
    },

    /// Show token savings across all whetstone components
    Stats,

    /// Headroom persistent-memory maintenance
    Memory {
        #[command(subcommand)]
        action: MemoryCommand,
    },
}

#[derive(Subcommand)]
pub enum MemoryCommand {
    /// Drain a stray project-local `.headroom` store into the global
    /// `~/.headroom` root (fixes cross-project memory litter)
    Consolidate {
        /// Show what would move without changing anything
        #[arg(long)]
        dry_run: bool,
    },
}

#[derive(Subcommand)]
pub enum ProjectCommand {
    /// Remove whetstone files from this project directory
    Uninstall,
}

#[derive(Subcommand)]
pub enum GlobalCommand {
    /// Remove globally-installed whetstone components
    /// (binaries, RTK, Headroom)
    Uninstall,
}

#[derive(Subcommand, Clone)]
pub enum ReleaseAction {
    Patch,
    Minor,
    Major,
    Set { version: String },
}