fix(tui/slash): restrict /pro to dev and pref builds

This commit is contained in:
James Peter
2025-09-25 11:52:42 +10:00
parent e024d7acb3
commit ff1e82b476
2 changed files with 45 additions and 5 deletions
+43 -4
View File
@@ -38,6 +38,37 @@ fn demo_command_enabled() -> bool {
})
}
fn pro_command_enabled() -> bool {
static ENABLED: OnceLock<bool> = OnceLock::new();
*ENABLED.get_or_init(|| {
let profile_matches = |
profile: &str
| {
let normalized = profile.trim().to_ascii_lowercase();
normalized.starts_with("dev") || normalized == "pref" || normalized == "perf"
};
if let Some(profile) = BUILD_PROFILE.or(option_env!("PROFILE")) {
if profile_matches(profile) {
return true;
}
}
if let Ok(exe_path) = std::env::current_exe() {
let path = exe_path.to_string_lossy().to_ascii_lowercase();
if path.contains("target/dev-fast/")
|| path.contains("target/dev/")
|| path.contains("target/pref/")
|| path.contains("target/perf/")
{
return true;
}
}
false
})
}
/// Commands that can be invoked by starting a message with a leading slash.
///
/// IMPORTANT: When adding or changing slash commands, also update
@@ -159,6 +190,7 @@ impl SlashCommand {
pub fn is_available(self) -> bool {
match self {
SlashCommand::Pro => pro_command_enabled(),
SlashCommand::Demo => demo_command_enabled(),
_ => true,
}
@@ -234,10 +266,17 @@ pub fn process_slash_command_message(message: &str) -> ProcessedCommand {
// Try to parse the command
if let Ok(command) = canonical_command.parse::<SlashCommand>() {
if !command.is_available() {
return ProcessedCommand::Error(format!(
"Error: /{} is only available in dev or perf builds.",
command.command()
));
let command_name = command.command();
let message = match command {
SlashCommand::Pro => {
"Error: /pro is only available in dev, dev-fast, or pref builds.".to_string()
}
SlashCommand::Demo => {
format!("Error: /{command_name} is only available in dev or perf builds.")
}
_ => format!("Error: /{command_name} is not available in this build."),
};
return ProcessedCommand::Error(message);
}
// Check if it's a prompt-expanding command
+2 -1
View File
@@ -62,7 +62,8 @@ Notes
- `/perf (on|off|show|reset)`: performance tracing controls.
- `/agents`: list agents (running and availability).
- `/pro [on|off|toggle|status|auto (on|off|toggle|status)]`: manage Pro mode,
including autonomous follow-ups and observer status.
including autonomous follow-ups and observer status (available in dev,
dev-fast, and pref builds).
## Prompt‑Expanding (Multi‑Agent)