Skip to content

Commit c24c8f7

Browse files
committed
fix: wire /yolo command handler and apply yolo_mode from settings
The yolo_mode setting field existed in core/src/lib.rs with serde and merge logic, and docs described the /yolo command, but the actual TUI command handler was missing and the setting was never read at startup. - Add /yolo command handler in app.rs (on/off/status/toggle) - Wire yolo_mode from settings.json into permission_mode at startup - Add test for /yolo command toggling permission_mode
1 parent c55c66f commit c24c8f7

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

src-rust/crates/cli/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ async fn main() -> anyhow::Result<()> {
547547
);
548548
}
549549
config.permission_mode = PermissionMode::BypassPermissions;
550+
} else if settings.config.yolo_mode {
551+
// Persistent YOLO mode from settings.json — same effect as the CLI
552+
// flag but without the root/sudo guard (settings are user-controlled).
553+
config.permission_mode = PermissionMode::BypassPermissions;
550554
} else {
551555
config.permission_mode = cli.permission_mode.into();
552556
}

src-rust/crates/tui/src/app.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const PROMPT_SLASH_COMMANDS: &[(&str, &str)] = &[
102102
("upgrade", "Check for updates and upgrade to the latest version"),
103103
("vim", "Toggle vim keybindings"),
104104
("voice", "Toggle voice input mode"),
105+
("yolo", "Toggle YOLO mode (skip all permission prompts)"),
105106
];
106107

107108
fn help_command_category(name: &str) -> &'static str {
@@ -2220,6 +2221,51 @@ impl App {
22202221
}
22212222
return true;
22222223
}
2224+
if cmd == "yolo" {
2225+
let mut s = claurst_core::Settings::load_sync().unwrap_or_default();
2226+
let sub = args.trim();
2227+
match sub {
2228+
"on" | "enable" => {
2229+
s.config.yolo_mode = true;
2230+
let _ = s.save_sync();
2231+
self.config.permission_mode =
2232+
claurst_core::config::PermissionMode::BypassPermissions;
2233+
self.status_message =
2234+
Some("YOLO mode enabled. All tool calls auto-approved.".to_string());
2235+
}
2236+
"off" | "disable" => {
2237+
s.config.yolo_mode = false;
2238+
let _ = s.save_sync();
2239+
self.config.permission_mode =
2240+
claurst_core::config::PermissionMode::Default;
2241+
self.status_message = Some("YOLO mode disabled.".to_string());
2242+
}
2243+
"status" => {
2244+
self.status_message = Some(format!(
2245+
"YOLO mode: {}",
2246+
if s.config.yolo_mode { "ON" } else { "OFF" },
2247+
));
2248+
}
2249+
"" => {
2250+
s.config.yolo_mode = !s.config.yolo_mode;
2251+
let _ = s.save_sync();
2252+
self.config.permission_mode = if s.config.yolo_mode {
2253+
claurst_core::config::PermissionMode::BypassPermissions
2254+
} else {
2255+
claurst_core::config::PermissionMode::Default
2256+
};
2257+
self.status_message = Some(format!(
2258+
"YOLO mode {}.",
2259+
if s.config.yolo_mode { "enabled" } else { "disabled" }
2260+
));
2261+
}
2262+
_ => {
2263+
self.status_message =
2264+
Some("Usage: /yolo [on|off|status] (no arg toggles).".to_string());
2265+
}
2266+
}
2267+
return true;
2268+
}
22232269
self.intercept_slash_command(cmd)
22242270
}
22252271

@@ -8466,4 +8512,38 @@ mod tests {
84668512
assert!(app.selection_anchor.is_none());
84678513
assert!(app.selection_focus.is_none());
84688514
}
8515+
8516+
#[test]
8517+
fn yolo_command_toggles_permission_mode() {
8518+
let mut app = make_app();
8519+
// Default permission mode.
8520+
assert_eq!(
8521+
app.config.permission_mode,
8522+
claurst_core::config::PermissionMode::Default
8523+
);
8524+
// /yolo on sets bypass mode.
8525+
assert!(app.intercept_slash_command_with_args("yolo", "on"));
8526+
assert_eq!(
8527+
app.config.permission_mode,
8528+
claurst_core::config::PermissionMode::BypassPermissions
8529+
);
8530+
assert!(app.status_message.as_deref().unwrap().contains("enabled"));
8531+
// /yolo off resets to default.
8532+
assert!(app.intercept_slash_command_with_args("yolo", "off"));
8533+
assert_eq!(
8534+
app.config.permission_mode,
8535+
claurst_core::config::PermissionMode::Default
8536+
);
8537+
assert!(app.status_message.as_deref().unwrap().contains("disabled"));
8538+
// /yolo on again.
8539+
assert!(app.intercept_slash_command_with_args("yolo", "on"));
8540+
assert_eq!(
8541+
app.config.permission_mode,
8542+
claurst_core::config::PermissionMode::BypassPermissions
8543+
);
8544+
assert!(app.status_message.as_deref().unwrap().contains("enabled"));
8545+
// /yolo status shows current state.
8546+
assert!(app.intercept_slash_command_with_args("yolo", "status"));
8547+
assert!(app.status_message.as_deref().unwrap().contains("ON"));
8548+
}
84698549
}

0 commit comments

Comments
 (0)