use newt_core::agentic::print_newt;
use crate::settings_form::{self, Field};
use crate::{current_prompt_and_preview, prompt_token_help, strip_one_quote_pair};
fn apply_setting(field: Field, value: &str, via: &str) -> String {
match settings_form::apply_and_record(field, value, via) {
Ok(msg) | Err(msg) => msg,
}
}
pub(crate) fn dispatch(
cmd: &str,
arg1: &str,
input: &str,
workspace: &str,
color: bool,
verbose: bool,
) -> anyhow::Result<bool> {
match cmd {
"prompt" if arg1 == "set" => {
let template = input
.trim_start_matches('/')
.strip_prefix("prompt")
.and_then(|s| s.trim_start().strip_prefix("set"))
.map(|s| s.strip_prefix(' ').unwrap_or(s))
.map(strip_one_quote_pair)
.unwrap_or("");
if template.is_empty() {
print_newt(
"usage: /prompt set \"<template>\" (try /prompt for the token list)",
color,
verbose,
);
} else {
apply_setting(Field::Prompt, template, "/prompt set");
let (_t, preview) = current_prompt_and_preview(workspace);
print_newt(
&format!("prompt set for this session — preview: {preview}"),
color,
verbose,
);
print_newt(
"(add to [tui] prompt to persist — use $NAME macros there to avoid TOML escaping)",
color,
verbose,
);
}
}
"prompt" if matches!(arg1, "reset" | "default" | "clear") => {
apply_setting(Field::Prompt, "reset", "/prompt reset");
print_newt(
"prompt reset to your [tui] prompt / the built-in default.",
color,
verbose,
);
}
"prompt" => {
print_newt(
"Prompt tokens — `/prompt set \"<template>\"` to change, or `[tui] prompt` to persist:",
color,
verbose,
);
for line in prompt_token_help() {
println!("{line}");
}
print_newt(
"In config.toml prefer the $NAME macros — the \\x forms are eaten by TOML \
(use a 'literal string' or doubled \\\\).",
color,
verbose,
);
let (tmpl, preview) = current_prompt_and_preview(workspace);
print_newt(&format!("current: {tmpl:?}"), color, verbose);
print_newt(&format!("preview: {preview}"), color, verbose);
}
"vi" | "emacs" | "nano" | "edit-mode" => {
let want = match cmd {
"vi" => Some("vi"),
"emacs" => Some("emacs"),
"nano" => Some("nano"),
_ => match arg1.to_lowercase().as_str() {
"vi" | "vim" => Some("vi"),
"emacs" => Some("emacs"),
"nano" => Some("nano"),
_ => None,
},
};
match want {
Some(m) => {
print_newt(
&apply_setting(Field::EditMode, m, &format!("/{cmd}")),
color,
verbose,
);
print_newt(
&settings_form::moved_notice(cmd, Field::EditMode),
color,
verbose,
);
}
None => print_newt(
"usage: /settings edit-mode <vi|emacs|nano> (or just /vi, /emacs, /nano)",
color,
verbose,
),
}
}
"nudge" => match arg1 {
"off" => {
apply_setting(Field::Nudge, "off", "/nudge");
print_newt(
"action-pressure nudges OFF for this session (narration rescue, \
workflow repair steering, plan pushes) — factual corrections stay on",
color,
verbose,
);
}
"on" => {
apply_setting(Field::Nudge, "on", "/nudge");
print_newt("action-pressure nudges ON (default)", color, verbose);
}
"" | "status" => {
print_newt(
&format!(
"action-pressure nudges: {} (/settings nudge <on|off>)",
if settings_form::nudges_off() {
"OFF"
} else {
"on"
}
),
color,
verbose,
);
}
_ => print_newt(
"usage: /settings nudge <on|off> (/nudge status shows it)",
color,
verbose,
),
},
"tenacity" | "cognition" => print_newt(&retired_dial_redirect(cmd), color, verbose),
"thinking" => print_newt(
&format!(
"/thinking folded into /settings — /settings opens the form; \
text: /settings thinking <{}> (nothing changed)",
Field::Thinking.accepts_hint()
),
color,
verbose,
),
"psyche" => {
let rest = input
.trim_start()
.trim_start_matches('/')
.strip_prefix("psyche")
.unwrap_or("")
.trim();
print_newt(&psyche_command(rest), color, verbose);
}
other => {
unreachable!("commands::settings::dispatch routed a non-setting command: {other:?}")
}
}
Ok(true)
}
fn explicit_relentless_round_note() -> Option<&'static str> {
matches!(
newt_core::tenacity::cli_tenacity(),
Some(newt_core::Tenacity::Relentless)
)
.then_some(
"explicit relentless tenacity makes the initial tool-round allowance effectively unlimited; an explicit `/rounds` overrides the initial value; progress renewal still applies",
)
}
fn level_usage<'a>(labels: impl IntoIterator<Item = &'a str>) -> String {
std::iter::once("auto")
.chain(labels)
.collect::<Vec<_>>()
.join("|")
}
fn tenacity_command(arg: &str) -> String {
use newt_core::tenacity::{effective_tenacity, Tenacity};
let usage = format!(
"(/psyche tenacity <{}>|list)",
level_usage(Tenacity::all().map(Tenacity::label))
);
match arg.trim() {
"" | "status" | "show" => {
let t = effective_tenacity();
let rounds = explicit_relentless_round_note()
.map(|note| format!(" {note}."))
.unwrap_or_default();
format!(
"tenacity: {} — {}{rounds} {usage}",
t.label(),
t.describe()
)
}
"list" => {
let mut out = String::from("tenacity levels (normal → relentless):");
out.push_str("\n auto normal, unless set explicitly");
let active_level = effective_tenacity();
for t in Tenacity::all() {
let active = if t == active_level { " ← active" } else { "" };
out.push_str(&format!("\n {:<10} {}{active}", t.label(), t.describe()));
}
if let Some(note) = explicit_relentless_round_note() {
out.push_str(&format!("\n rounds {note}."));
}
out
}
"auto" | "inherit" | "reset" => {
apply_setting(Field::Tenacity, "auto", "/psyche tenacity");
format!(
"tenacity → auto (override cleared) — now {}",
effective_tenacity().label()
)
}
other => match other.parse::<Tenacity>() {
Ok(level) => {
apply_setting(Field::Tenacity, level.label(), "/psyche tenacity");
let rounds = if level == Tenacity::Relentless {
"; initial tool-round allowance → effectively unlimited (an explicit `/rounds` overrides the initial value; progress renewal still applies)"
} else {
""
};
format!(
"tenacity → {} — {}{rounds}",
level.label(),
level.describe()
)
}
Err(e) => format!("{e} {usage}"),
},
}
}
fn initiative_command(arg: &str) -> String {
use newt_core::initiative::{effective_initiative, Initiative};
let usage = format!(
"(/psyche initiative <{}>|list)",
level_usage(Initiative::all().map(Initiative::label))
);
match arg.trim() {
"" | "status" | "show" => {
let i = effective_initiative();
format!("initiative: {} — {} {usage}", i.label(), i.describe())
}
"list" => {
let mut out = String::from("initiative levels (patient → eager):");
out.push_str("\n auto inherit from the persona / config / model family");
let active_level = effective_initiative();
for i in Initiative::all() {
let active = if i == active_level { " ← active" } else { "" };
out.push_str(&format!("\n {:<10} {}{active}", i.label(), i.describe()));
}
out
}
"auto" | "inherit" | "reset" => {
apply_setting(Field::Initiative, "auto", "/psyche initiative");
format!(
"initiative → auto (override cleared) — now {} (from persona / config / model family)",
effective_initiative().label()
)
}
other => match other.parse::<Initiative>() {
Ok(level) => {
apply_setting(Field::Initiative, level.label(), "/psyche initiative");
format!("initiative → {} — {}", level.label(), level.describe())
}
Err(e) => format!("{e} {usage}"),
},
}
}
fn cognition_command(arg: &str) -> String {
use newt_core::cognition::{cli_cognition, CognitionOverride};
use newt_core::role_profile::Cognition;
let levels: Vec<&str> = Cognition::all().into_iter().map(Cognition::label).collect();
let usage = format!("(/psyche cognition <{}>|off|auto|list)", levels.join("|"));
match arg.trim() {
"" | "status" | "show" => {
match cli_cognition() {
CognitionOverride::Unset => {
format!("cognition: auto — follows the active persona's `cognition:` (or off) {usage}")
}
CognitionOverride::Off => {
format!("cognition: off — no reasoning controls sent, overriding any persona {usage}")
}
CognitionOverride::Set(c) => format!(
"cognition: {} — {} (session override, beats the persona) {usage}",
c.label(),
c.describe()
),
}
}
"list" => {
let active = cli_cognition();
let mut out = String::from("cognition levels (light → deep):");
for c in Cognition::all() {
let mark = if matches!(active, CognitionOverride::Set(a) if a == c) {
" ← override"
} else {
""
};
out.push_str(&format!("\n {:<14} {}{mark}", c.label(), c.describe()));
}
out.push_str("\n off no reasoning controls (overrides the persona)");
out.push_str("\n auto follow the active persona (default)");
out
}
"off" | "none" => {
apply_setting(Field::Cognition, "off", "/psyche cognition");
"cognition → off — no reasoning controls will be sent".to_string()
}
"auto" | "reset" | "persona" => {
apply_setting(Field::Cognition, "auto", "/psyche cognition");
"cognition → auto — following the active persona".to_string()
}
other => match other.parse::<Cognition>() {
Ok(level) => {
apply_setting(Field::Cognition, level.label(), "/psyche cognition");
format!("cognition → {} — {}", level.label(), level.describe())
}
Err(e) => format!("{e} {usage}"),
},
}
}
fn retired_dial_redirect(cmd: &str) -> String {
format!(
"/{cmd} folded into /psyche — /psyche opens the dial panel; \
text: /settings {cmd} <level> (nothing changed)"
)
}
fn psyche_command(rest: &str) -> String {
use newt_core::cognition::{cli_cognition, CognitionOverride};
use newt_core::initiative::effective_initiative;
use newt_core::tenacity::effective_tenacity;
let rest = rest.trim();
let (sub, arg) = match rest.split_once(char::is_whitespace) {
Some((s, a)) => (s, a.trim()),
None => (rest, ""),
};
if sub.eq_ignore_ascii_case("obsessive") || sub.eq_ignore_ascii_case("obsessive-relentless") {
let (cog, ten) = (
newt_core::psyche::OBSESSIVE_COGNITION,
newt_core::psyche::OBSESSIVE_TENACITY,
);
apply_setting(Field::Cognition, cog.label(), "/psyche obsessive");
apply_setting(Field::Tenacity, ten.label(), "/psyche obsessive");
return format!(
"obsessive engaged (live): cognition → {}, tenacity → {}, \
initial tool-round allowance → effectively unlimited (an explicit \
`/rounds` overrides the initial value; progress renewal still applies); initiative stays {}.\n\
crew is a launch gate — relaunch with `newt --obsessive` (or set \
NEWT_TEAM) to add the crew this session.",
cog.label(),
ten.label(),
effective_initiative().label()
);
}
match sub {
"cognition" => return cognition_command(arg),
"tenacity" => return tenacity_command(arg),
"initiative" => return initiative_command(arg),
"edit" => {
return if arg.is_empty() {
"/psyche opens the dial panel on the rich TUI with an \
interactive terminal; here, /psyche status shows the text \
view and /psyche cognition / tenacity / initiative <level> \
change the dials."
.to_string()
} else {
format!(
"usage: /psyche edit takes no arguments (got `{arg}`) — \
bare /psyche opens the dial panel"
)
}
}
"" | "status" | "show" => {}
other => {
return format!(
"unknown /psyche subcommand `{other}` — usage: /psyche \
[status|cognition <level>|tenacity <level>|initiative <level>|obsessive]"
)
}
}
let cog = match cli_cognition() {
CognitionOverride::Off => "off — no reasoning controls (session override)".to_string(),
CognitionOverride::Set(c) => {
format!("{} — {} (session override)", c.label(), c.describe())
}
CognitionOverride::Unset => match newt_core::cognition::persona_cognition() {
Some(c) => format!("{} — {} (from the active persona)", c.label(), c.describe()),
None => "auto — no reasoning controls (no persona sets it)".to_string(),
},
};
let ten = effective_tenacity();
let init = effective_initiative();
let init_from = if newt_core::initiative::cli_initiative().is_some() {
"session override"
} else if newt_core::initiative::persona_initiative().is_some() {
"from the active persona"
} else if newt_core::initiative::model_default_initiative().is_some() {
"model default"
} else {
"config default"
};
let crew = if std::env::var("NEWT_TEAM").is_ok() {
"on"
} else {
"off"
};
let mut out = String::from("psyche — how hard the agent works (orthogonal dials):");
out.push_str(&format!("\n cognition {cog}"));
out.push_str(
"\n backend-specific reasoning depth (/psyche cognition)",
);
out.push_str(&format!(
"\n tenacity {} — {}",
ten.label(),
ten.describe()
));
out.push_str("\n how long it pursues the task (/psyche tenacity)");
if let Some(note) = explicit_relentless_round_note() {
out.push_str(&format!("\n {note}."));
}
out.push_str(&format!(
"\n initiative {} — {} ({init_from})",
init.label(),
init.describe()
));
out.push_str("\n how much it looks before acting (/psyche initiative)");
out.push_str(&format!("\n crew {crew}"));
out.push_str(
"\n how many minds work the task (NEWT_TEAM / newt crew)",
);
out.push_str(&format!(
"\nobsessive = cognition {} + tenacity {} + crew on; initiative is left alone.",
newt_core::psyche::OBSESSIVE_COGNITION.label(),
newt_core::psyche::OBSESSIVE_TENACITY.label()
));
out.push_str(
"\n/psyche — open the dial panel (rich TUI build + interactive terminal) · \
/psyche cognition|tenacity|initiative <level> — text setters.",
);
out
}
#[cfg(test)]
mod tests {
use super::{cognition_command, tenacity_command};
use crate::settings_form::{Field, ValueSpace};
#[test]
fn every_declared_thinking_value_is_reachable_through_the_slash_command() {
let ValueSpace::Choice(values) = Field::Thinking.value_space() else {
panic!("thinking is a fixed vocabulary, not a number");
};
assert!(
values.len() >= 3,
"the three-way vocabulary is the point: {values:?}"
);
for (value, _) in &values {
assert_eq!(
Field::Thinking.accepts(value).as_deref(),
Some(*value),
"`/thinking {value}` must reach the field it is declared on"
);
}
assert_eq!(Field::Thinking.accepts("on").as_deref(), Some("fold"));
assert_eq!(Field::Thinking.accepts("maybe"), None);
}
#[test]
fn thinking_usage_is_derived_from_the_declared_values() {
let hint = Field::Thinking.accepts_hint();
for want in ["fold", "stream", "off"] {
assert!(hint.contains(want), "usage omits `{want}`: {hint}");
}
assert!(
!hint.contains("on|off"),
"the stale two-value literal is back: {hint}"
);
}
#[test]
fn cognition_status_list_set_off_auto_and_error_are_informative() {
use newt_core::cognition::{cli_cognition, set_cli_cognition, CognitionOverride};
use newt_core::role_profile::Cognition;
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
let restore = cli_cognition();
set_cli_cognition(CognitionOverride::Unset);
let status = cognition_command("");
assert!(status.starts_with("cognition: auto"), "{status}");
assert!(status.contains("/psyche cognition"), "{status}");
let list = cognition_command("list");
for label in ["zen", "rational", "thoughtful", "meticulous", "off", "auto"] {
assert!(list.contains(label), "list missing {label}: {list}");
}
let msg = cognition_command("meticulous");
assert!(msg.contains("meticulous"), "{msg}");
assert_eq!(
cli_cognition(),
CognitionOverride::Set(Cognition::Meticulous)
);
cognition_command("off");
assert_eq!(cli_cognition(), CognitionOverride::Off);
cognition_command("auto");
assert_eq!(cli_cognition(), CognitionOverride::Unset);
let err = cognition_command("banana");
assert!(err.contains("unknown cognition"), "{err}");
set_cli_cognition(restore);
}
#[test]
fn psyche_panel_shows_all_the_dials_and_how_to_change_them() {
let out = super::psyche_command("");
for k in ["cognition", "tenacity", "initiative", "crew", "obsessive"] {
assert!(out.contains(k), "psyche panel missing '{k}': {out}");
}
assert!(
out.contains("/psyche cognition")
&& out.contains("/psyche tenacity")
&& out.contains("/psyche initiative"),
"status view points at the /psyche subcommand setters: {out}"
);
assert!(
!out.contains("/psyche edit"),
"bare /psyche IS the panel now — the footer must not advertise \
the old edit subcommand: {out}"
);
}
#[test]
fn psyche_obsessive_engages_the_max_live_dials_and_notes_crew() {
use newt_core::cognition::{cli_cognition, set_cli_cognition, CognitionOverride};
use newt_core::initiative::{cli_initiative, set_cli_initiative, Initiative};
use newt_core::role_profile::Cognition;
use newt_core::tenacity::{effective_tenacity, set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
set_cli_cognition(CognitionOverride::Unset);
set_cli_tenacity(Tenacity::Normal);
set_cli_initiative(Initiative::Patient);
let out = super::psyche_command("obsessive");
assert_eq!(
cli_cognition(),
CognitionOverride::Set(Cognition::Meticulous)
);
assert_eq!(effective_tenacity(), Tenacity::Relentless);
assert_eq!(cli_initiative(), Some(Initiative::Patient));
assert!(out.contains("initiative stays patient"), "{out}");
assert!(out.to_lowercase().contains("crew"), "{out}");
assert!(out.contains("--obsessive"), "{out}");
assert!(out.contains("round"), "{out}");
assert!(out.contains("/rounds"), "{out}");
}
#[test]
fn tenacity_status_and_list_and_error_are_informative() {
use newt_core::tenacity::{set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
set_cli_tenacity(Tenacity::Normal);
let status = tenacity_command("");
assert!(status.starts_with("tenacity: "), "{status}");
assert!(
status.contains("/psyche tenacity <auto|normal|relentless>"),
"{status}"
);
let list = tenacity_command("list");
for label in ["normal", "relentless"] {
assert!(list.contains(label), "list missing {label}: {list}");
}
assert!(
list.contains("← active"),
"list marks the active level: {list}"
);
let err = tenacity_command("banana");
assert!(err.contains("unknown tenacity"), "{err}");
let err = tenacity_command("insistent");
assert!(err.contains("--initiative decisive"), "{err}");
}
#[test]
fn initiative_status_and_list_and_error_are_informative() {
use newt_core::initiative::{set_cli_initiative, Initiative};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
newt_core::initiative::set_initiative_config(Default::default());
set_cli_initiative(Initiative::Measured);
let status = super::initiative_command("");
assert!(status.starts_with("initiative: measured"), "{status}");
assert!(
status.contains("/psyche initiative <auto|patient|measured|decisive|eager>"),
"{status}"
);
let list = super::initiative_command("list");
for label in ["patient", "measured", "decisive", "eager", "auto"] {
assert!(list.contains(label), "list missing {label}: {list}");
}
assert!(list.contains("after 12 read-only"), "rounds shown: {list}");
assert!(list.contains("← active"), "{list}");
let err = super::initiative_command("banana");
assert!(err.contains("unknown initiative"), "{err}");
}
#[test]
fn explicit_relentless_status_views_explain_the_round_budget() {
use newt_core::tenacity::{set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
set_cli_tenacity(Tenacity::Relentless);
for out in [
tenacity_command("status"),
tenacity_command("list"),
super::psyche_command("status"),
] {
assert!(out.contains("effectively unlimited"), "{out}");
assert!(out.contains("/rounds"), "{out}");
}
}
#[test]
fn psyche_subcommands_route_to_the_dial_setters() {
use newt_core::cognition::{cli_cognition, set_cli_cognition, CognitionOverride};
use newt_core::initiative::{effective_initiative, Initiative};
use newt_core::role_profile::Cognition;
use newt_core::tenacity::{effective_tenacity, set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
set_cli_cognition(CognitionOverride::Unset);
set_cli_tenacity(Tenacity::Normal);
let msg = super::psyche_command("cognition thoughtful");
assert!(msg.contains("thoughtful"), "{msg}");
assert_eq!(
cli_cognition(),
CognitionOverride::Set(Cognition::Thoughtful)
);
let msg = super::psyche_command("tenacity relentless");
assert!(msg.contains("relentless"), "{msg}");
assert_eq!(effective_tenacity(), Tenacity::Relentless);
let msg = super::psyche_command("initiative eager");
assert!(msg.contains("eager"), "{msg}");
assert_eq!(effective_initiative(), Initiative::Eager);
let status = super::psyche_command("cognition");
assert!(status.starts_with("cognition:"), "{status}");
for rest in ["", "status", "show"] {
let out = super::psyche_command(rest);
assert!(out.contains("psyche — how hard"), "{rest:?}: {out}");
}
let edit = super::psyche_command("edit");
assert!(edit.contains("dial panel"), "{edit}");
assert!(
!edit.contains("needs an interactive rich terminal"),
"review v2: the arm must not assert the terminal is incapable \
(it also fires for malformed aliases ON a rich TTY): {edit}"
);
let extra = super::psyche_command("edit extra");
assert!(extra.contains("takes no arguments"), "{extra}");
let err = super::psyche_command("banana");
assert!(err.contains("unknown /psyche subcommand"), "{err}");
}
#[test]
fn psyche_setters_mark_exactly_the_axis_they_change() {
use newt_core::cognition::CognitionOverride;
use newt_core::initiative::Initiative;
use newt_core::role_profile::Cognition;
use newt_core::runtime::drain_preference_actions;
use newt_core::tenacity::Tenacity;
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
let _ = drain_preference_actions();
for rest in [
"",
"status",
"cognition",
"cognition list",
"cognition transcending",
"tenacity",
"tenacity list",
"tenacity nonsense",
"initiative",
"initiative list",
"initiative relaxed",
"banana",
"edit",
] {
let _ = super::psyche_command(rest);
assert!(
drain_preference_actions().is_empty(),
"`/psyche {rest}` must not pin anything"
);
}
let _ = super::psyche_command("cognition thoughtful");
let a = drain_preference_actions();
assert_eq!(
a.cognition,
Some(CognitionOverride::Set(Cognition::Thoughtful))
);
assert_eq!((a.tenacity, a.backend, a.model), (None, None, None));
let _ = super::psyche_command("tenacity relentless");
let a = drain_preference_actions();
assert_eq!(a.tenacity, Some(Some(Tenacity::Relentless)));
assert_eq!(a.cognition, None);
let _ = super::psyche_command("initiative decisive");
let a = drain_preference_actions();
assert_eq!(a.initiative, Some(Some(Initiative::Decisive)));
assert_eq!((a.cognition, a.tenacity), (None, None));
let _ = super::psyche_command("cognition off");
assert_eq!(
drain_preference_actions().cognition,
Some(CognitionOverride::Off)
);
let _ = super::psyche_command("cognition auto");
assert_eq!(
drain_preference_actions().cognition,
Some(CognitionOverride::Unset)
);
let _ = super::psyche_command("tenacity auto");
assert_eq!(drain_preference_actions().tenacity, Some(None));
let _ = super::psyche_command("initiative auto");
assert_eq!(drain_preference_actions().initiative, Some(None));
let _ = super::psyche_command("obsessive");
let a = drain_preference_actions();
assert!(a.cognition.is_some() && a.tenacity.is_some(), "{a:?}");
assert_eq!(a.initiative, None, "obsessive does not pin initiative");
assert_eq!((a.backend, a.model), (None, None), "crew/backend untouched");
}
#[test]
fn the_redirect_line_names_both_the_panel_and_the_text_setter() {
for cmd in ["tenacity", "cognition"] {
let line = super::retired_dial_redirect(cmd);
assert!(line.contains("folded into /psyche"), "{line}");
assert!(line.contains("/psyche opens the dial panel"), "{line}");
assert!(line.contains(&format!("/settings {cmd} <level>")), "{line}");
assert!(line.contains("(nothing changed)"), "{line}");
}
}
#[test]
fn retired_top_level_dials_redirect_without_mutating() {
use newt_core::cognition::{cli_cognition, set_cli_cognition, CognitionOverride};
use newt_core::tenacity::{cli_tenacity, set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
set_cli_cognition(CognitionOverride::Unset);
set_cli_tenacity(Tenacity::Normal);
super::dispatch(
"tenacity",
"relentless",
"/tenacity relentless",
".",
false,
false,
)
.unwrap();
assert_eq!(
cli_tenacity(),
Some(Tenacity::Normal),
"retired /tenacity must not mutate the override"
);
super::dispatch(
"cognition",
"meticulous",
"/cognition meticulous",
".",
false,
false,
)
.unwrap();
assert_eq!(
cli_cognition(),
CognitionOverride::Unset,
"retired /cognition must not mutate the override"
);
}
#[test]
fn tenacity_command_sets_the_level_live() {
use newt_core::tenacity::{effective_tenacity, set_cli_tenacity, Tenacity};
let _g = newt_core::test_guard::GlobalSettingsGuard::acquire();
let restore = effective_tenacity();
let msg = tenacity_command("relentless");
assert!(msg.contains("relentless"), "{msg}");
assert!(msg.contains("effectively unlimited"), "{msg}");
assert!(msg.contains("/rounds"), "{msg}");
assert_eq!(effective_tenacity(), Tenacity::Relentless);
let msg = tenacity_command("auto");
assert!(msg.contains("cleared"), "{msg}");
assert_eq!(
newt_core::tenacity::cli_tenacity(),
None,
"/tenacity auto clears the session override"
);
set_cli_tenacity(Tenacity::Relentless);
tenacity_command("reset");
assert_eq!(newt_core::tenacity::cli_tenacity(), None);
set_cli_tenacity(restore);
}
}