grok-build-upstream-mirror/crates/codegen/xai-grok-pager/src/slash/commands/cd.rs
grokkybara[bot] 3af4d5d398 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

123 lines
4 KiB
Rust

//! `/cd [path]` — change the working directory new dashboard sessions
//! spawn in.
//!
//! With no argument it opens the dashboard's location picker; with a path
//! it changes directly. Both are dashboard affordances — invoked from a
//! non-dashboard surface the dispatcher prints a toast pointing the user
//! at `/dashboard` (see `dispatch_dashboard_open_location_picker` /
//! `dispatch_dashboard_change_location`).
use crate::app::actions::Action;
use crate::slash::command::{CommandExecCtx, CommandResult, SlashCommand};
/// Change the working directory for newly dispatched dashboard sessions.
pub struct CdCommand;
impl SlashCommand for CdCommand {
fn name(&self) -> &str {
"cd"
}
fn description(&self) -> &str {
"Change the working directory for new agents"
}
fn usage(&self) -> &str {
"/cd [path]"
}
fn takes_args(&self) -> bool {
true
}
fn arg_placeholder(&self) -> Option<&str> {
Some("path")
}
/// `/cd` only makes sense on the dashboard (it changes where the
/// dashboard dispatches new agents), so hide it from completion on
/// every other surface — the agent view and the welcome screen.
fn dashboard_only(&self) -> bool {
true
}
fn run(&self, _ctx: &mut CommandExecCtx, args: &str) -> CommandResult {
let trimmed = args.trim();
if trimmed.is_empty() {
CommandResult::Action(Action::DashboardOpenLocationPicker)
} else {
CommandResult::Action(Action::DashboardChangeLocation {
input: trimmed.to_string(),
})
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::acp::model_state::ModelState;
use crate::app::bundle::BundleState;
/// Build a throwaway exec ctx over the given borrows. Mirrors the
/// inline ctx construction in `dashboard.rs`'s command tests.
fn ctx<'a>(models: &'a ModelState, bundle: &'a BundleState) -> CommandExecCtx<'a> {
CommandExecCtx {
models,
session_id: None,
bundle_state: bundle,
screen_mode: crate::app::ScreenMode::Inline,
billing_surface_visible: true,
pager_state: crate::settings::PagerLocalSnapshot {
multiline_mode: false,
yolo_mode: false,
..crate::settings::PagerLocalSnapshot::default()
},
}
}
#[test]
fn no_args_opens_location_picker() {
let (models, bundle) = (ModelState::default(), BundleState::default());
let mut c = ctx(&models, &bundle);
assert!(matches!(
CdCommand.run(&mut c, ""),
CommandResult::Action(Action::DashboardOpenLocationPicker)
));
}
#[test]
fn whitespace_only_opens_location_picker() {
let (models, bundle) = (ModelState::default(), BundleState::default());
let mut c = ctx(&models, &bundle);
assert!(matches!(
CdCommand.run(&mut c, " "),
CommandResult::Action(Action::DashboardOpenLocationPicker)
));
}
#[test]
fn path_arg_changes_location() {
let (models, bundle) = (ModelState::default(), BundleState::default());
let mut c = ctx(&models, &bundle);
match CdCommand.run(&mut c, " ~/projects/foo ") {
CommandResult::Action(Action::DashboardChangeLocation { input }) => {
assert_eq!(input, "~/projects/foo");
}
other => panic!("expected DashboardChangeLocation, got {other:?}"),
}
}
#[test]
fn metadata() {
let cmd = CdCommand;
assert_eq!(cmd.name(), "cd");
assert!(cmd.takes_args());
assert_eq!(cmd.arg_placeholder(), Some("path"));
assert!(!cmd.description().is_empty());
assert!(!cmd.usage().is_empty());
// `/cd` is dashboard-only — hidden from completion on every other
// surface (the agent view, the welcome screen).
assert!(cmd.dashboard_only(), "/cd must be dashboard-only");
}
}