grok-build-upstream-mirror/crates/codegen/xai-grok-pager/src/slash/commands/auto.rs

115 lines
3.6 KiB
Rust
Raw Normal View History

//! `/auto` -- toggle auto permission mode (LLM classifier).
//!
//! - Off (or always-approve) → `SetPermissionMode(Auto)`
//! - Already auto → `SetPermissionMode(Ask)` (toggle off)
//!
//! The dispatcher owns state mutation, persistence (with rollback), and toast.
//! Visibility is gated by
//! [`crate::slash::SlashController::set_auto_mode_available`]: `/auto` is
//! hard-hidden when the auto permission-mode feature is off.
use crate::app::actions::{Action, PermissionModeKind};
use crate::slash::command::{CommandExecCtx, CommandResult, SlashCommand};
/// Toggle auto permission mode (LLM classifier).
pub struct AutoCommand;
impl SlashCommand for AutoCommand {
fn name(&self) -> &str {
"auto"
}
fn description(&self) -> &str {
"Toggle auto mode (classifier approves safe tools)"
}
fn usage(&self) -> &str {
"/auto"
}
fn run(&self, ctx: &mut CommandExecCtx, _args: &str) -> CommandResult {
// Yolo wins over auto: if always-approve is on, treat auto as off so
// `/auto` switches into auto rather than "toggling off" to ask.
let currently_auto = ctx.pager_state.auto_mode && !ctx.pager_state.yolo_mode;
let kind = if currently_auto {
PermissionModeKind::Ask
} else {
PermissionModeKind::Auto
};
CommandResult::Action(Action::SetPermissionMode(kind))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::acp::model_state::ModelState;
use crate::app::bundle::BundleState;
use crate::settings::PagerLocalSnapshot;
fn make_ctx<'a>(
models: &'a ModelState,
bundle: &'a BundleState,
yolo_mode: bool,
auto_mode: bool,
) -> CommandExecCtx<'a> {
CommandExecCtx {
models,
session_id: None,
bundle_state: bundle,
screen_mode: crate::app::ScreenMode::Inline,
Synced from monorepo Synced from monorepo Changes: - Shell: accept target response id on rewind execute - Shell: stamp response id on chat user message chunks - Worktree: optional rebuild and stale git registration cleanup in auto-GC - Worktree: kind-aware auto-GC TTLs and config knobs - Worktree: macOS process CWD scan and Unix PID liveness for GC guards - Worktree: automatic throttled GC on startup (Linux age-based; non-Linux dead-only) - Pager: add `[ui].combine_queued_prompts` to batch queued follow-ups - Shell: stop overwriting user skills - Tools: read markdown in `skills/` directories untruncated - `/usage` shows per-session token and dollar usage in the TUI - Security: prompt on environment-dumping `ps` variants - Security: always-safe `kubectl` no longer runs arbitrary kubeconfig credential plugins without permission - Tools: make scheduler deletion durable - Shell: add relocation storage primitives - Shell: give side model calls their own conversation ids - Fix five workflow-runtime bugs (budget, pause, cancel, reconnect) - Security: peel `env -S` / `--split-string` operands in the Bash permission gate (managed deny/ask) - Pager: expose doctor in the TUI - Security: block unauthorized RCE via abused safe commands - Pager idle watcher cue: "1 subagent still running" instead of "watching · 1 subagent" - Security: block `rg --pre` arbitrary code execution in auto-mode - Voice: diagnose silent-mic failures (macOS permission) and add doctor/terminal-setup Voice section - App builder deployer: `allow_forking` and `show_built_with_grok` - Pager: stop stacking duplicate "Worked for" markers on parked turns - Shell: support `max` as a distinct reasoning effort tier - Tools: serialize background `/loop` fires on the whole work unit - Shell: add working-directory relocation state primitives - Proto: `ClientToolResult` and `ChatConfig` client-side tools - Shell: model providers - Chat: select App Builder product on the Build path - Shell: attach author identity to feedback when the deployment opts in - Doctor: fix for SSH wrap setup - Workflow authoring skills: create-workflow and import-claude-workflow docs - Add read-only grok doctor - Sandbox: apply Landlock without a controlling TTY - Pager: recover image paste over grok wrap on headless remotes - Pager: make actions screen-mode aware - Shell: resume sessions when the working directory moves - Pager: centralize terminal diagnostics - Workspace: gate inline shell file access - Pager: centralize terminal probes - Pager: edit minimal prompts in an external editor - Pager: standardize backgrounding on Ctrl+B - Shell: recap rides the parent turn's prompt cache - Tools: add scheduler lifecycle version clock Source-Revision: 0f4d7c91b8b2b408333f6de1e8a76cb8eaa71899
2026-07-21 18:10:23 +00:00
billing_surface_visible: true,
pager_state: PagerLocalSnapshot {
yolo_mode,
auto_mode,
auto_mode_gate: true,
..PagerLocalSnapshot::default()
},
}
}
#[test]
fn off_turns_auto_on() {
let models = ModelState::default();
let bundle = BundleState::default();
let mut ctx = make_ctx(&models, &bundle, false, false);
assert!(matches!(
AutoCommand.run(&mut ctx, ""),
CommandResult::Action(Action::SetPermissionMode(PermissionModeKind::Auto))
));
}
#[test]
fn on_turns_auto_off() {
let models = ModelState::default();
let bundle = BundleState::default();
let mut ctx = make_ctx(&models, &bundle, false, true);
assert!(matches!(
AutoCommand.run(&mut ctx, ""),
CommandResult::Action(Action::SetPermissionMode(PermissionModeKind::Ask))
));
}
#[test]
fn always_approve_switches_to_auto() {
let models = ModelState::default();
let bundle = BundleState::default();
// Stale auto_mode=true with yolo on must still switch to Auto.
let mut ctx = make_ctx(&models, &bundle, true, true);
assert!(matches!(
AutoCommand.run(&mut ctx, ""),
CommandResult::Action(Action::SetPermissionMode(PermissionModeKind::Auto))
));
}
#[test]
fn ignores_args() {
let models = ModelState::default();
let bundle = BundleState::default();
let mut ctx = make_ctx(&models, &bundle, false, false);
assert!(matches!(
AutoCommand.run(&mut ctx, "extra"),
CommandResult::Action(Action::SetPermissionMode(PermissionModeKind::Auto))
));
}
}