Skip to main content

vtcode_core/cli/args/
mod.rs

1use clap::{ArgAction, ColorChoice, Parser, Subcommand, ValueHint};
2use colorchoice_clap::Color as ColorSelection;
3use std::env;
4use std::path::PathBuf;
5
6use crate::config::models::ModelId;
7
8mod acp;
9mod ask;
10mod background;
11mod bench;
12mod check;
13mod companion;
14mod config;
15mod dependencies;
16mod exec;
17mod models;
18mod plugins;
19mod pods;
20mod review;
21mod schedule;
22mod schema;
23mod secret;
24mod session_store;
25mod skills;
26mod version;
27mod webmcp;
28pub use version::long_version;
29
30pub use acp::AgentClientProtocolTarget;
31pub use ask::{AskCommandOptions, AskOutputFormat};
32pub use background::BackgroundSubagentArgs;
33pub use bench::BenchAllocatorArgs;
34pub use check::CheckSubcommand;
35pub use companion::{CompanionCommand, CompanionSetupArgs};
36pub use config::{
37    ConfigCommand, ConfigFile, ConfigResetArgs, ContextConfig, LoggingConfig, PerformanceConfig, SecurityConfig,
38    ToolConfig,
39};
40pub use dependencies::{DependenciesSubcommand, ManagedDependency};
41pub use exec::{EvalOutputFormat, ExecEvalArgs, ExecResumeArgs, ExecSubcommand};
42pub use models::ModelCommands;
43pub use plugins::PluginsSubcommand;
44pub use pods::PodsCommands;
45pub use review::ReviewArgs;
46pub use schedule::{ScheduleCreateArgs, ScheduleSubcommand};
47pub use schema::{SchemaCommands, SchemaMode, SchemaOutputFormat};
48pub use secret::{MigrateArgs, SecretArgs, SecretProvider, SecretSubcommand};
49pub use session_store::SessionStoreCommand;
50pub use skills::{SkillsRefSubcommand, SkillsSubcommand};
51pub use webmcp::{WebmcpCommand, WebmcpPairArgs, WebmcpServeArgs};
52
53#[derive(Parser, Debug, Clone)]
54pub struct Cli {
55    /// Color output selection (auto, always, never)
56    #[command(flatten)]
57    pub color: ColorSelection,
58
59    /// Optional positional path to run vtcode against a different workspace
60    #[arg(
61        value_name = "WORKSPACE",
62        value_hint = ValueHint::DirPath,
63        value_parser = version::parse_workspace_directory,
64        global = true,
65        last = true
66    )]
67    pub workspace_path: Option<PathBuf>,
68
69    /// LLM Model ID (e.g., gpt-5, claude-sonnet-4-6, gemini-3-flash-preview)
70    #[arg(long, global = true)]
71    pub model: Option<String>,
72
73    /// LLM Provider (gemini, openai, anthropic, deepseek, meta, openrouter, merge-gateway, codex, zai, moonshot, minimax, ollama, lmstudio)
74    #[arg(long, global = true)]
75    pub provider: Option<String>,
76
77    /// API key environment variable (auto-detects GEMINI_API_KEY, OPENAI_API_KEY, etc.)
78    #[arg(long, global = true, default_value = crate::config::constants::defaults::DEFAULT_API_KEY_ENV)]
79    pub api_key_env: String,
80
81    /// Workspace root directory (default: current directory)
82    #[arg(
83        long,
84        global = true,
85        alias = "workspace-dir",
86        value_name = "PATH",
87        value_hint = ValueHint::DirPath,
88        value_parser = version::parse_workspace_directory
89    )]
90    pub workspace: Option<PathBuf>,
91
92    /// Enable research-preview features
93    #[arg(long, global = true)]
94    pub research_preview: bool,
95
96    /// Security level for tool execution (strict, moderate, permissive)
97    #[arg(long, global = true, default_value = "moderate")]
98    pub security_level: String,
99
100    /// Show diffs for file changes in chat interface
101    #[arg(long, global = true)]
102    pub show_file_diffs: bool,
103
104    /// Maximum concurrent async operations
105    #[arg(long, global = true, default_value_t = 5)]
106    pub max_concurrent_ops: usize,
107
108    /// Maximum API requests per minute
109    #[arg(long, global = true, default_value_t = 30)]
110    pub api_rate_limit: usize,
111
112    /// Maximum tool calls per session
113    #[arg(long, global = true, default_value_t = 10)]
114    pub max_tool_calls: usize,
115
116    /// Enable debug output for troubleshooting
117    #[arg(long, global = true)]
118    pub debug: bool,
119
120    /// Enable verbose logging
121    #[arg(long, global = true)]
122    pub verbose: bool,
123
124    /// Suppress all non-essential output (for scripting, CI/CD)
125    #[arg(short, long, global = true)]
126    pub quiet: bool,
127
128    /// Configuration overrides or file path (KEY=VALUE or PATH)
129    #[arg(
130        short = 'c',
131        long = "config",
132        value_name = "KEY=VALUE|PATH",
133        action = ArgAction::Append,
134        global = true
135    )]
136    pub config: Vec<String>,
137
138    /// Log level (error, warn, info, debug, trace)
139    #[arg(long, global = true, default_value = "info")]
140    pub log_level: String,
141
142    /// Disable color output (equivalent to `--color never`)
143    #[arg(long, global = true)]
144    pub no_color: bool,
145
146    /// Select UI theme (e.g., ciapre-dark, ciapre-blue)
147    #[arg(long, global = true, value_name = "THEME")]
148    pub theme: Option<String>,
149
150    /// App tick rate in milliseconds (default: 250)
151    #[arg(short = 't', long, default_value_t = 250)]
152    pub tick_rate: u64,
153
154    /// Frame rate in FPS (default: 60)
155    #[arg(short = 'f', long, default_value_t = 60)]
156    pub frame_rate: u64,
157
158    /// Enable skills system
159    #[arg(long, global = true)]
160    pub enable_skills: bool,
161
162    /// Enable Chrome browser integration for web automation
163    #[arg(long, global = true)]
164    pub chrome: bool,
165
166    /// Disable Chrome browser integration
167    #[arg(long = "no-chrome", global = true, conflicts_with = "chrome")]
168    pub no_chrome: bool,
169
170    /// Skip safety confirmations (use with caution)
171    #[arg(long, global = true)]
172    pub skip_confirmations: bool,
173
174    /// Enable experimental Codex app-server features for this run
175    #[arg(long = "codex-experimental", global = true, conflicts_with = "no_codex_experimental")]
176    pub codex_experimental: bool,
177
178    /// Disable experimental Codex app-server features for this run
179    #[arg(long = "no-codex-experimental", global = true, conflicts_with = "codex_experimental")]
180    pub no_codex_experimental: bool,
181
182    /// Print response without launching the interactive TUI
183    #[arg(
184        short = 'p',
185        long = "print",
186        value_name = "PROMPT",
187        value_hint = ValueHint::Other,
188        num_args = 0..=1,
189        default_missing_value = "",
190        global = true,
191        conflicts_with_all = ["full_auto"]
192    )]
193    pub print: Option<String>,
194
195    /// Run non-interactively with full-auto permission review
196    #[arg(
197        long = "full-auto",
198        global = true,
199        help = "Run non-interactively with full-auto permission review",
200        long_help = r#"Run non-interactively on top of the active primary agent.
201
202If no primary agent is explicitly selected or configured, VT Code selects the effective `auto` primary agent. Explicit choices, including `duck`, are honoured. Full-auto is an execution and permission layer, not a primary agent.
203
204Full-auto does not override explicit denies or grant tools outside `[automation.full_auto].allowed_tools`. Tools outside that allow-list are denied. Promptable actions inside the allow-list are routed through automatic permission review after deny and policy checks instead of asking. The run fails fast if it needs the defaulted `auto` primary agent and no effective `auto` exists."#,
205        value_name = "PROMPT",
206        num_args = 0..=1,
207        default_missing_value = "",
208        value_hint = ValueHint::Other
209    )]
210    pub full_auto: Option<String>,
211
212    /// Resume a previous conversation (use without ID for interactive picker)
213    #[arg(
214        short = 'r',
215        long = "resume",
216        global = true,
217        value_name = "SESSION_ID",
218        num_args = 0..=1,
219        default_missing_value = "__interactive__",
220        conflicts_with_all = ["continue_latest", "full_auto"]
221    )]
222    pub resume_session: Option<String>,
223
224    /// Continue the most recent conversation automatically
225    #[arg(
226        long = "continue",
227        visible_alias = "continue-session",
228        global = true,
229        conflicts_with_all = ["resume_session", "full_auto"]
230    )]
231    pub continue_latest: bool,
232
233    /// Fork an existing session with a new session ID
234    #[arg(
235        long = "fork-session",
236        global = true,
237        value_name = "SESSION_ID",
238        conflicts_with_all = ["resume_session", "continue_latest", "full_auto"]
239    )]
240    pub fork_session: Option<String>,
241
242    /// Show archived sessions from every workspace when resuming or forking
243    #[arg(long, global = true)]
244    pub all: bool,
245
246    /// Custom suffix for session identifier (alphanumeric, dash, underscore only, max 64 chars)
247    #[arg(long = "session-id", global = true, value_name = "CUSTOM_SUFFIX")]
248    pub session_id: Option<String>,
249
250    /// Use summarized history when forking a session
251    #[arg(long, global = true)]
252    pub summarize: bool,
253
254    /// Override the default agent model for this session
255    #[arg(long, global = true, value_name = "AGENT")]
256    pub agent: Option<String>,
257
258    /// Tools that execute without prompting (comma-separated, supports patterns like "Bash(git:*)")
259    #[arg(long = "allowed-tools", global = true, value_name = "TOOLS", action = ArgAction::Append)]
260    pub allowed_tools: Vec<String>,
261
262    /// Tools that cannot be used by the agent
263    #[arg(long = "disallowed-tools", global = true, value_name = "TOOLS", action = ArgAction::Append)]
264    pub disallowed_tools: Vec<String>,
265
266    /// Auto-approve promptable actions while respecting denies and policy blocks
267    #[arg(
268        long = "dangerously-skip-permissions",
269        global = true,
270        help = "Auto-approve promptable actions while respecting denies and policy blocks",
271        long_help = "Auto-approve promptable actions while still respecting explicit denies and policy blocks."
272    )]
273    pub dangerously_skip_permissions: bool,
274
275    /// Disable the process sandbox and automatically approve promptable actions for this session.
276    #[arg(long, global = true, conflicts_with_all = ["full_auto", "skip_confirmations", "dangerously_skip_permissions"])]
277    pub full_access: bool,
278
279    /// Explicitly connect to IDE on startup (auto-detects available IDEs)
280    #[arg(long, global = true)]
281    pub ide: bool,
282
283    #[command(subcommand)]
284    pub command: Option<Commands>,
285}
286
287#[derive(Subcommand, Debug, Clone)]
288pub enum Commands {
289    /// Configure the local VT Code Companion plugin.
290    #[command(name = "companion")]
291    Companion {
292        #[command(subcommand)]
293        command: CompanionCommand,
294    },
295
296    /// Start Agent Client Protocol bridge for IDE integrations
297    #[command(name = "acp")]
298    AgentClientProtocol {
299        /// Client to connect over ACP
300        #[arg(value_enum, default_value_t = AgentClientProtocolTarget::Zed)]
301        target: AgentClientProtocolTarget,
302    },
303
304    /// Unified per-session state store (single source of truth for state,
305    /// context, and history). Consolidates the legacy `checkpoints/`, `logs/`,
306    /// and `history/` stores.
307    #[command(name = "session-store")]
308    SessionStore {
309        #[command(subcommand)]
310        command: SessionStoreCommand,
311    },
312
313    /// Interactive AI coding assistant
314    Chat,
315
316    /// Resume the most recent conversation automatically
317    ///
318    /// Equivalent to `vtcode --continue`. Loads the latest archived session in
319    /// the current workspace (or across all workspaces with `--all`) and resumes
320    /// it without showing the interactive picker.
321    ///
322    /// Examples:
323    ///   vtcode continue
324    ///   vtcode continue --all
325    ///   vtcode continue --session-id my-fork   # fork latest into a new session
326    Continue,
327
328    /// Single prompt mode - prints model reply without tools
329    ///
330    /// Send a single prompt to the model and print the response. No tools are
331    /// invoked, no session is created, and the process exits after replying.
332    ///
333    /// Examples:
334    ///   vtcode ask "what is a monad?"
335    ///   echo "summarize this" | vtcode ask
336    ///   vtcode ask --output-format json "explain ownership in Rust"
337    Ask {
338        /// Prompt to ask. Use `-` to force reading from stdin.
339        #[arg(
340            value_name = "PROMPT",
341            long_help = "The prompt to send to the model.\n\nOmit to read from stdin (piped input).\nUse '-' to explicitly force reading from stdin."
342        )]
343        prompt: Option<String>,
344        /// Format the response using a structured representation.
345        #[arg(
346            long = "output-format",
347            value_enum,
348            value_name = "FORMAT",
349            long_help = "Output format for the response.\n\nCurrently supports:\n  json - Emit the response as a structured JSON document."
350        )]
351        output_format: Option<AskOutputFormat>,
352    },
353    /// Headless execution mode
354    ///
355    /// Run the agent in non-interactive mode. The agent executes the prompt,
356    /// runs tools, and exits when done. Ideal for CI/CD, scripting, and
357    /// agent-to-agent workflows.
358    ///
359    /// Examples:
360    ///   vtcode exec "explain this codebase"
361    ///   vtcode exec --json "fix the failing test"
362    ///   vtcode exec --dry-run "refactor auth module"
363    ///   cat file.rs | vtcode exec "review this code"
364    ///   vtcode exec resume --last
365    Exec {
366        /// Emit structured JSON events to stdout (one per line)
367        #[arg(
368            long,
369            long_help = "Stream newline-delimited JSON events to stdout.\nEach line is a JSON object representing an agent event (tool call, message, etc.).\nUseful for programmatic consumption and CI integration."
370        )]
371        json: bool,
372        /// Run a read-only dry-run execution (blocks mutating tool calls)
373        #[arg(
374            long,
375            long_help = "Simulate execution without making changes.\nThe agent plans tool calls but does not execute mutating operations (file writes, shell commands).\nUseful for previewing what the agent would do."
376        )]
377        dry_run: bool,
378        /// Optional path to write the JSONL transcript
379        #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath, long_help = "Write the full JSONL event transcript to this file.\nIncludes all agent events: tool calls, messages, errors, and metadata.")]
380        events: Option<PathBuf>,
381        /// Write the last agent message to this file
382        #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath, long_help = "Write only the final agent message to this file.\nUseful for piping the agent's response into other tools.")]
383        last_message_file: Option<PathBuf>,
384        /// Optional exec subcommand
385        #[command(subcommand)]
386        command: Option<ExecSubcommand>,
387        /// Prompt to execute. Use `-` to force reading from stdin.
388        #[arg(
389            value_name = "PROMPT",
390            long_help = "The prompt to execute.\n\nOmit to read from stdin (piped input).\nUse '-' to explicitly force reading from stdin.\nQuote multi-word prompts: vtcode exec \"fix the bug in auth.rs\""
391        )]
392        prompt: Option<String>,
393    },
394    /// Run an evaluation suite (shorthand for `vtcode exec eval`)
395    ///
396    /// Executes each task in the suite autonomously in an isolated worktree,
397    /// verifies the outcome with environment probes, and aggregates pass@k /
398    /// pass^k metrics into a markdown or JSON report.
399    ///
400    /// Examples:
401    ///   vtcode eval --suite suite.json
402    ///   vtcode eval --suite suite.json --format json --output report.json
403    Eval(ExecEvalArgs),
404    /// Manage durable scheduled tasks
405    ///
406    /// Create, list, and delete scheduled tasks that run on a recurring or
407    /// one-shot basis. Tasks are stored persistently and survive restarts
408    /// when paired with `vtcode schedule install-service`.
409    ///
410    /// Examples:
411    ///   vtcode schedule create --name "daily-review" --cron "0 9 * * 1-5" --prompt "review recent changes"
412    ///   vtcode schedule create --name "reminder" --reminder "standup in 10 minutes" --at "09:50"
413    ///   vtcode schedule list
414    ///   vtcode schedule delete `<task-id>`
415    Schedule {
416        #[command(subcommand)]
417        command: ScheduleSubcommand,
418    },
419
420    /// Internal VT Code background subagent runner
421    #[command(name = "background-subagent", hide = true)]
422    BackgroundSubagent(BackgroundSubagentArgs),
423
424    /// Headless code review for the current diff, selected files, or a custom git target
425    #[command(
426        long_about = "Run a non-interactive code review.\n\nExamples:\n  vtcode review\n  vtcode review \"Review the full diff for correctness and regressions\"\n  vtcode review --last-diff\n  vtcode review --target HEAD~1..HEAD\n  vtcode review --file src/main.rs --file crates/codegen/vtcode-core/src/lib.rs\n  vtcode review --style security \"Focus on auth bypass and injection\""
427    )]
428    Review(ReviewArgs),
429
430    /// Runtime schema introspection for built-in tools
431    Schema {
432        #[command(subcommand)]
433        command: SchemaCommands,
434    },
435
436    /// Verbose interactive chat with debug output
437    ChatVerbose,
438
439    /// Analyze workspace (structure, security, performance)
440    Analyze {
441        /// Type of analysis to perform
442        #[arg(value_name = "TYPE", default_value = "full")]
443        analysis_type: String,
444    },
445
446    /// Pretty-print trajectory logs
447    #[command(name = "trajectory")]
448    Trajectory {
449        /// Optional path to trajectory JSONL file
450        #[arg(long)]
451        file: Option<PathBuf>,
452        /// Number of top entries to show
453        #[arg(long, default_value_t = 10)]
454        top: usize,
455    },
456
457    /// Send a VT Code notification using the built-in notification system
458    Notify {
459        /// Optional notification title
460        #[arg(long, value_name = "TITLE")]
461        title: Option<String>,
462        /// Notification message
463        #[arg(value_name = "MESSAGE")]
464        message: String,
465    },
466
467    /// Benchmark against SWE-bench evaluation framework
468    Benchmark {
469        /// Path to a JSON benchmark specification
470        #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath)]
471        task_file: Option<PathBuf>,
472        /// Inline JSON specification for quick experiments
473        #[arg(long, value_name = "JSON")]
474        task: Option<String>,
475        /// Optional path to write the structured benchmark report
476        #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath)]
477        output: Option<PathBuf>,
478        /// Limit the number of tasks executed
479        #[arg(long, value_name = "COUNT")]
480        max_tasks: Option<usize>,
481    },
482
483    /// Measure allocator RSS behavior under a bursty/sparse Tokio workload
484    ///
485    /// Reproduces the mimalloc-vs-jemalloc analysis pattern: many short-lived
486    /// tasks allocated across Tokio worker threads, with idle gaps between
487    /// bursts. Reports the RSS trajectory so you can see whether the global
488    /// allocator returns memory to the OS (jemalloc) or pins it (mimalloc/glibc).
489    /// Build with `--features allocator-jemalloc` to compare allocators.
490    #[command(name = "bench-allocator")]
491    BenchAllocator(BenchAllocatorArgs),
492
493    /// Create complete Rust project
494    CreateProject {
495        name: String,
496        #[arg(long = "feature", value_name = "FEATURE", action = ArgAction::Append)]
497        features: Vec<String>,
498    },
499
500    /// Revert agent to a previous snapshot
501    Revert {
502        /// Turn number to revert to
503        #[arg(short, long)]
504        turn: usize,
505        /// Scope of revert operation: conversation, code, full
506        #[arg(long)]
507        partial: Option<String>,
508        /// Session that owns the checkpoint (required when several sessions recorded the same turn)
509        #[arg(long)]
510        session: Option<String>,
511    },
512
513    /// List all available snapshots
514    Snapshots,
515
516    /// Clean up old snapshots
517    ///
518    /// Features:
519    ///   • Remove snapshots beyond limit
520    ///   • Configurable retention policy
521    ///   • Safe deletion with confirmation
522    ///
523    /// Examples:
524    ///   vtcode cleanup-snapshots
525    ///   vtcode cleanup-snapshots --max 20
526    #[command(name = "cleanup-snapshots")]
527    CleanupSnapshots {
528        /// Maximum number of snapshots to keep
529        ///
530        /// Default: 50
531        /// Example: --max 20
532        #[arg(short, long, default_value_t = 50)]
533        max: usize,
534    },
535
536    /// Initialize project guidance and workspace scaffolding
537    ///
538    /// Bootstrap a workspace for use with VT Code. Creates vtcode.toml,
539    /// AGENTS.md, and other scaffolding. Run this once per project.
540    ///
541    /// Examples:
542    ///   vtcode init
543    ///   vtcode init --force
544    Init {
545        /// Overwrite an existing AGENTS.md without prompting
546        #[arg(
547            long,
548            short = 'f',
549            long_help = "Overwrite AGENTS.md without confirmation.\nUse this in CI/CD or scripts where interactive prompts are not possible."
550        )]
551        force: bool,
552    },
553
554    /// Initialize project in the user state directory's `projects/` path.
555    ///
556    /// Create a new project entry in the VT Code projects directory.
557    /// This is separate from `vtcode init` which bootstraps a workspace.
558    ///
559    /// Examples:
560    ///   vtcode init-project
561    ///   vtcode init-project --name my-project
562    ///   vtcode init-project --force --migrate
563    #[command(name = "init-project")]
564    InitProject {
565        /// Project name - defaults to current directory name
566        #[arg(
567            long,
568            long_help = "Name for the project.\nDefaults to the current directory name if not specified."
569        )]
570        name: Option<String>,
571        /// Force initialization - overwrite existing project structure
572        #[arg(long, long_help = "Overwrite existing project structure without confirmation.")]
573        force: bool,
574        /// Migrate existing files - move existing config/cache files to new structure
575        #[arg(
576            long,
577            long_help = "Move existing config and cache files into the new project structure."
578        )]
579        migrate: bool,
580    },
581
582    /// Generate or manage configuration files
583    ///
584    /// Create a vtcode.toml configuration file with default settings, or use
585    /// `reset` to clear one configuration layer.
586    /// Use --global to create in the canonical user config directory or specify an output path.
587    ///
588    /// Examples:
589    ///   vtcode config
590    ///   vtcode config --global
591    ///   vtcode config --output ./my-vtcode.toml
592    ///   vtcode config reset
593    ///   vtcode config reset --global
594    ///   vtcode config reset --project
595    Config {
596        #[command(subcommand)]
597        command: Option<ConfigCommand>,
598        /// Output file path
599        #[arg(
600            long,
601            long_help = "Write the configuration to this path.\nDefaults to ./vtcode.toml in the current directory."
602        )]
603        output: Option<PathBuf>,
604        /// Create in the canonical user config directory.
605        #[arg(
606            long,
607            long_help = "Write the configuration to the canonical user config directory.\nThis sets global defaults for all workspaces."
608        )]
609        global: bool,
610    },
611
612    /// Authenticate with a supported provider
613    ///
614    /// Start an OAuth or API-key login flow for the given provider.
615    /// Credentials are stored securely in the OS keychain.
616    ///
617    /// Examples:
618    ///   vtcode login openai
619    ///   vtcode login openai --from-codex
620    ///   vtcode login openrouter
621    ///   vtcode login codex
622    ///   vtcode login codex --device-code
623    Login {
624        /// Provider name (`openai`, `openrouter`, `copilot`, or `codex`)
625        #[arg(long_help = "The provider to authenticate with.\nSupported: openai, openrouter, copilot, codex")]
626        provider: String,
627        /// Use device-code login when the provider supports it (currently `codex` only)
628        #[arg(
629            long,
630            default_value_t = false,
631            long_help = "Use the device-code OAuth flow.\nCurrently supported only for the `codex` provider.\nOpens a browser URL and asks you to enter a code."
632        )]
633        device_code: bool,
634        /// Import ChatGPT credentials from Codex's `~/.codex/auth.json` instead
635        /// of running the browser OAuth flow (currently `openai` only)
636        #[arg(
637            long,
638            default_value_t = false,
639            long_help = "Import ChatGPT OAuth tokens from Codex's auth.json.\n\
640                         Requires that you have already run `codex login`.\n\
641                         Currently supported only for the `openai` provider."
642        )]
643        from_codex: bool,
644    },
645
646    /// Clear stored authentication credentials for a provider
647    ///
648    /// Remove stored OAuth tokens or API keys for the given provider.
649    ///
650    /// Examples:
651    ///   vtcode logout openai
652    ///   vtcode logout openrouter
653    Logout {
654        /// Provider name (`openai`, `openrouter`, `copilot`, or `codex`)
655        #[arg(long_help = "The provider to deauthenticate.\nSupported: openai, openrouter, copilot, codex")]
656        provider: String,
657    },
658
659    /// Show authentication status for one provider or all supported providers
660    ///
661    /// Display whether each provider is authenticated, which credential type
662    /// is in use, and token/session metadata when available.
663    ///
664    /// Examples:
665    ///   vtcode auth
666    ///   vtcode auth openai
667    ///   vtcode auth openrouter
668    Auth {
669        /// Optional provider name (`openai`, `openrouter`, `copilot`, or `codex`)
670        #[arg(long_help = "Show status for a single provider.\nOmit to show status for all supported providers.")]
671        provider: Option<String>,
672    },
673
674    /// Manage tool execution policies
675    #[command(name = "tool-policy")]
676    ToolPolicy {
677        #[command(subcommand)]
678        command: crate::cli::tool_policy_commands::ToolPolicyCommands,
679    },
680
681    /// Manage Model Context Protocol providers and inspect their resources
682    #[command(name = "mcp")]
683    Mcp {
684        #[command(subcommand)]
685        command: crate::mcp::cli::McpCommands,
686    },
687
688    /// Agent2Agent (A2A) Protocol
689    #[command(name = "a2a")]
690    A2a {
691        #[command(subcommand)]
692        command: super::super::a2a::cli::A2aCommands,
693    },
694
695    /// Authenticated browser editor bridge
696    #[command(name = "webmcp")]
697    Webmcp {
698        #[command(subcommand)]
699        command: WebmcpCommand,
700    },
701
702    /// Proxy to the official Codex app-server
703    #[command(name = "app-server")]
704    AppServer {
705        /// Transport listen target passed through to `codex app-server`
706        #[arg(long, default_value = "stdio://")]
707        listen: String,
708    },
709
710    /// Start the local VT Code desktop service over JSON-RPC stdio.
711    #[command(name = "desktop-server")]
712    DesktopServer,
713
714    /// Open the VT Code desktop app (macOS).
715    ///
716    /// Locates VT Code.app (explicit path, VTCODE_DESKTOP_APP, then
717    /// ~/Applications and /Applications) and opens a new instance.
718    /// Pass --install to download and install it from the release asset instead.
719    ///
720    ///   vtcode desktop --install
721    #[command(name = "desktop")]
722    Desktop {
723        /// Path to VT Code.app when it is outside the standard locations
724        #[arg(value_name = "APP_PATH")]
725        app_path: Option<PathBuf>,
726        /// Download and install the app from the prebuilt release asset instead of opening it
727        #[arg(
728            long,
729            conflicts_with = "app_path",
730            long_help = "Download and install the desktop app from the prebuilt release asset instead of opening it.\nUpdates install in place; fresh installs go to ~/Applications."
731        )]
732        install: bool,
733    },
734
735    /// Manage models and providers
736    Models {
737        #[command(subcommand)]
738        command: ModelCommands,
739    },
740
741    /// Manage GPU pod deployments
742    #[command(name = "pods")]
743    Pods {
744        #[command(subcommand)]
745        command: PodsCommands,
746    },
747
748    /// Generate or display man pages
749    Man {
750        /// Command name to generate man page for (optional)
751        command: Option<String>,
752        /// Generate the main page and every visible command page
753        #[arg(long, conflicts_with = "command", requires = "output")]
754        all_pages: bool,
755        /// Output file, or output directory when --all-pages is specified
756        #[arg(short, long)]
757        output: Option<PathBuf>,
758    },
759
760    /// Manage Agent Skills
761    ///
762    /// Skills are reusable instruction sets that extend the agent's capabilities.
763    /// Each skill is a directory containing a SKILL.md manifest and optional scripts.
764    ///
765    /// Examples:
766    ///   vtcode skills list
767    ///   vtcode skills create my-skill
768    ///   vtcode skills load my-skill
769    ///   vtcode skills info my-skill
770    ///   vtcode skills validate ./path/to/skill
771    #[command(subcommand)]
772    Skills(SkillsSubcommand),
773
774    /// Manage Agent Plugins
775    ///
776    /// Agent Plugins are portable packages that bundle Agent Skills and MCP servers
777    /// under a root plugin.json manifest, following the Agent Plugins spec.
778    ///
779    /// Examples:
780    ///   vtcode plugins list
781    ///   vtcode plugins info my-plugin
782    ///   vtcode plugins validate ./path/to/plugin
783    ///   vtcode plugins add <https://github.com/example/plugin>
784    ///   vtcode plugins remove my-plugin
785    #[command(subcommand)]
786    Plugins(PluginsSubcommand),
787
788    /// List available skills (alias for `vtcode skills list`)
789    #[command(name = "list-skills", hide = true)]
790    ListSkills {},
791
792    /// Manage optional VT Code dependencies
793    ///
794    /// Install, update, or check the status of optional tools that VT Code
795    /// can use (ripgrep, ast-grep, search-tools bundle).
796    ///
797    /// Examples:
798    ///   vtcode dependencies status
799    ///   vtcode dependencies install search-tools
800    ///   vtcode deps install ripgrep
801    #[command(name = "dependencies", visible_alias = "deps", subcommand)]
802    Dependencies(DependenciesSubcommand),
803
804    /// Manage API keys in secure storage (OS keyring or encrypted file)
805    ///
806    /// Store, inspect, and delete provider API keys without exposing them
807    /// in shell history or workspace files.
808    ///
809    /// Examples:
810    ///   vtcode secret
811    ///   vtcode secret list
812    ///   vtcode secret status openai
813    ///   vtcode secret add openai
814    ///   vtcode secret delete openai
815    Secret(SecretArgs),
816
817    /// Run built-in repository checks
818    ///
819    /// Execute repository-level checks such as ast-grep rule tests and scans.
820    ///
821    /// Examples:
822    ///   vtcode check ast-grep
823    Check {
824        #[command(subcommand)]
825        command: CheckSubcommand,
826    },
827
828    /// Check for and install binary updates from GitHub Releases
829    ///
830    /// Manage VT Code binary updates. By default checks for a new version
831    /// and offers to install it. Use flags to customize behavior.
832    ///
833    /// Examples:
834    ///   vtcode update
835    ///   vtcode update --check
836    ///   vtcode update --force
837    ///   vtcode update --list
838    ///   vtcode update --pin 0.120.0
839    ///   vtcode update --unpin
840    ///   vtcode update --with-desktop
841    #[command(name = "update")]
842    Update {
843        /// Check for updates without installing
844        #[arg(
845            long,
846            long_help = "Check whether a newer version is available without installing it."
847        )]
848        check: bool,
849        /// Force update even if on latest version
850        #[arg(
851            long,
852            long_help = "Reinstall or downgrade even if the current version is already the latest."
853        )]
854        force: bool,
855        /// List available versions
856        #[arg(long, long_help = "Print available release versions from GitHub and exit.")]
857        list: bool,
858        /// Number of versions to list (default: 10)
859        #[arg(
860            long,
861            default_value = "10",
862            long_help = "Maximum number of versions to display with --list."
863        )]
864        limit: usize,
865        /// Pin to a specific version
866        #[arg(
867            long,
868            value_name = "VERSION",
869            long_help = "Pin the binary to a specific version.\nAuto-updates are disabled until --unpin is used."
870        )]
871        pin: Option<String>,
872        /// Unpin version
873        #[arg(long, long_help = "Remove a previously set version pin and resume auto-updates.")]
874        unpin: bool,
875        /// Set release channel (stable, beta, nightly)
876        #[arg(
877            long,
878            value_name = "CHANNEL",
879            long_help = "Switch the release channel.\nAccepted values: stable, beta, nightly."
880        )]
881        channel: Option<String>,
882        /// Show current update configuration
883        #[arg(
884            long,
885            long_help = "Display the current update configuration (channel, pin, intervals) and exit."
886        )]
887        show_config: bool,
888        /// Install or update the macOS desktop app without prompting
889        #[arg(
890            long,
891            conflicts_with = "without_desktop",
892            long_help = "Install or update the macOS desktop app from the prebuilt release asset without prompting.\nFails on non-macOS platforms."
893        )]
894        with_desktop: bool,
895        /// Skip the macOS desktop app without prompting
896        #[arg(
897            long,
898            conflicts_with = "with_desktop",
899            long_help = "Skip the macOS desktop app install/update step without prompting."
900        )]
901        without_desktop: bool,
902    },
903
904    /// Start Anthropic API compatibility server
905    #[command(name = "anthropic-api")]
906    AnthropicApi {
907        /// Port to run the server on
908        #[arg(long, default_value = "11434")]
909        port: u16,
910        /// Host address to bind to
911        #[arg(long, default_value = "127.0.0.1")]
912        host: String,
913    },
914}
915
916impl Default for Cli {
917    fn default() -> Self {
918        Self {
919            color: ColorSelection { color: ColorChoice::Auto },
920            workspace_path: None,
921            model: Some(ModelId::default().to_string()),
922            provider: Some("gemini".to_owned()),
923            api_key_env: "GEMINI_API_KEY".to_owned(),
924            workspace: None,
925            research_preview: false,
926            security_level: "moderate".to_owned(),
927            show_file_diffs: false,
928            max_concurrent_ops: 5,
929            api_rate_limit: 30,
930            max_tool_calls: 10,
931            verbose: false,
932            quiet: false,
933            config: Vec::new(),
934            log_level: "info".to_owned(),
935            no_color: false,
936            theme: None,
937            skip_confirmations: false,
938            codex_experimental: false,
939            no_codex_experimental: false,
940            print: None,
941            full_auto: None,
942            resume_session: None,
943            continue_latest: false,
944            fork_session: None,
945            all: false,
946            session_id: None,
947            summarize: false,
948            debug: false,
949            enable_skills: false,
950            tick_rate: 250,
951            frame_rate: 60,
952            agent: None,
953            allowed_tools: Vec::new(),
954            disallowed_tools: Vec::new(),
955            dangerously_skip_permissions: false,
956            full_access: false,
957            ide: false,
958            chrome: false,
959            no_chrome: false,
960            command: Some(Commands::Chat),
961        }
962    }
963}
964
965impl Cli {
966    /// Get the effective API key environment variable
967    ///
968    /// Automatically infers the API key environment variable based on the provider
969    /// when the current value matches the default or is not explicitly set.
970    pub fn get_api_key_env(&self) -> String {
971        crate::config::api_keys::resolve_api_key_env(
972            self.provider
973                .as_deref()
974                .unwrap_or(crate::config::constants::defaults::DEFAULT_PROVIDER),
975            &self.api_key_env,
976        )
977    }
978
979    pub fn codex_experimental_override(&self) -> Option<bool> {
980        if self.codex_experimental {
981            Some(true)
982        } else if self.no_codex_experimental {
983            Some(false)
984        } else {
985            None
986        }
987    }
988}
989
990#[cfg(test)]
991mod tests;