subx_cli/cli/cache_args.rs
1//! Cache management command-line arguments and operations.
2//!
3//! This module defines the command-line interface for cache-related operations
4//! in SubX. The cache system stores intermediate results from AI analysis and
5//! other computationally expensive operations to improve performance and reduce
6//! API costs during development and testing.
7//!
8//! # Cache System Overview
9//!
10//! SubX maintains several types of caches:
11//! - **AI Analysis Cache**: Results from AI-powered file matching
12//! - **Audio Analysis Cache**: Speech pattern detection results
13//! - **Configuration Cache**: Processed configuration data
14//! - **Dry-run Cache**: Preview results that can be applied later
15//!
16//! # Cache Benefits
17//!
18//! - **Performance**: Avoid re-analyzing the same content
19//! - **Cost Savings**: Reduce AI API calls during testing
20//! - **Development**: Faster iteration during debugging
21//! - **Reliability**: Consistent results across multiple runs
22//!
23//! # Examples
24//!
25//! ```bash
26//! # Clear all cache data
27//! subx cache clear
28//!
29//! # View cache status (future enhancement)
30//! subx cache status
31//!
32//! # Selective cache clearing (future enhancement)
33//! subx cache clear --type ai
34//! ```
35
36use clap::{Args, Subcommand, ValueEnum};
37
38/// Command-line arguments for cache management operations.
39#[derive(Args, Debug)]
40pub struct CacheArgs {
41 /// The cache management action to perform
42 #[command(subcommand)]
43 pub action: CacheAction,
44}
45
46/// Cache management operations and subcommands.
47#[derive(Subcommand, Debug)]
48pub enum CacheAction {
49 /// Display cache status including size, age, and validity
50 Status(StatusArgs),
51 /// Apply cached dry-run results without calling the AI provider
52 Apply(ApplyArgs),
53 /// Undo the most recent batch of file operations
54 Rollback(RollbackArgs),
55 /// Clear cached data
56 Clear(ClearArgs),
57}
58
59/// Arguments for the `cache status` subcommand.
60#[derive(Args, Debug)]
61pub struct StatusArgs {
62 /// Output status in JSON format for scripting.
63 ///
64 /// **Backward-compatible alias** for the global `--output json`
65 /// flag (see [`crate::cli::OutputMode`]). When this flag is set,
66 /// the command behaves exactly as if the user had invoked
67 /// `subx-cli --output json cache status`: the same JSON envelope
68 /// is rendered through [`crate::cli::output::emit_success`] and the
69 /// stdout bytes are guaranteed to be byte-identical between the
70 /// two invocations. Per the `cache-management` spec this alias is
71 /// limited to `cache status`; no other cache subcommand exposes a
72 /// `--json` flag.
73 #[arg(long)]
74 pub json: bool,
75}
76
77/// Arguments for the `cache apply` subcommand.
78#[derive(Args, Debug)]
79pub struct ApplyArgs {
80 /// Skip interactive confirmation prompt
81 #[arg(long)]
82 pub yes: bool,
83 /// Bypass staleness and validation checks
84 #[arg(long)]
85 pub force: bool,
86 /// Minimum confidence threshold (0-100) to filter operations
87 #[arg(long, value_parser = clap::value_parser!(u8).range(0..=100))]
88 pub confidence: Option<u8>,
89}
90
91/// Arguments for the `cache rollback` subcommand.
92#[derive(Args, Debug)]
93pub struct RollbackArgs {
94 /// Bypass integrity verification checks
95 #[arg(long)]
96 pub force: bool,
97}
98
99/// Arguments for the `cache clear` subcommand.
100#[derive(Args, Debug)]
101pub struct ClearArgs {
102 /// Type of data to clear
103 #[arg(long, value_enum, default_value_t = ClearType::All)]
104 pub r#type: ClearType,
105}
106
107/// Types of cache data that can be cleared.
108#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
109pub enum ClearType {
110 /// Clear only the match cache file
111 Cache,
112 /// Clear only the operation journal
113 Journal,
114 /// Clear both cache and journal
115 All,
116}