Thinking levels: Tab cycles off/low/medium/high, /effort

This commit is contained in:
hermes committed 2026-10-06 12:05:29 +00:00
1 parent 2f1ce2c072
commit ab2af421a4
9 files changed
+180 -16

No files matched your search

+29 -7
View File
@@ -183,6 +183,10 @@ impl App {
fn apply_switch(&mut self, sw: &hx_core::switch::Switched) {
self.st.kind = sw.kind;
self.st.model = sw.model.clone();
// keep the level when the new provider has it, else its first (Codex has no "off")
if !hx_ai::Effort::levels(sw.kind).contains(&self.st.effort) {
self.st.effort = hx_ai::Effort::levels(sw.kind)[0];
}
if sw.provider_changed {
self.st.quota = None;
}
@@ -298,6 +302,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
st: status::Status {
kind: switcher.kind(),
model: agent.model().to_string(),
effort: agent.effort(),
usage: Usage::default(),
ctx_tokens: agent.context_tokens(),
ctx_max: agent.compact_at(),
@@ -906,6 +911,10 @@ fn on_key(app: &mut App, k: KeyEvent, abort: &AbortHandle) -> Option<String> {
KeyCode::End => app.ed.end(),
KeyCode::Up => app.ed.up(),
KeyCode::Down => app.ed.down(),
KeyCode::Tab if app.ed.buf.is_empty() => {
app.st.effort = app.st.effort.next(app.st.kind);
app.hint = format!("thinking: {}", app.st.effort.name());
}
KeyCode::Tab => {
let c = completion(app);
let labels: Vec<&str> = c.items.iter().map(|i| i.label.as_str()).collect();
@@ -1054,6 +1063,21 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
Err(e) => app.t.push(Item::Error(format!("/new: {e}"))),
}
}
"effort" if arg.is_empty() => app.t.push(Item::Info(format!(
"thinking: {} (off, low, medium, high)",
app.st.effort.name()
))),
"effort" => match arg.parse::<hx_ai::Effort>() {
Ok(e) if hx_ai::Effort::levels(app.st.kind).contains(&e) => {
app.st.effort = e;
app.t.push(Item::Info(format!("thinking → {}", e.name())));
}
Ok(_) => app.t.push(Item::Error(format!(
"{:?} cannot turn thinking off",
app.st.kind
))),
Err(e) => app.t.push(Item::Error(e)),
},
"model" if arg.is_empty() => app.t.push(Item::Info(format!("model: {}", app.st.model))),
"model" => {
let mut a = agent.lock().await;
@@ -1147,14 +1171,11 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
app.since = Instant::now();
let prompt = expand_mentions(&line, cwd);
let (agent, tx) = (agent.clone(), tx.clone());
let effort = app.st.effort;
tokio::spawn(async move {
let r = agent
.lock()
.await
.run(prompt)
.await
.map(|_| ())
.map_err(|e| e.to_string());
let mut a = agent.lock().await;
a.set_effort(effort);
let r = a.run(prompt).await.map(|_| ()).map_err(|e| e.to_string());
let _ = tx.send(Ui::Done(r));
});
}
@@ -1799,6 +1820,7 @@ mod tests {
st: status::Status {
kind: Kind::Claude,
model: "m1".into(),
effort: hx_ai::Effort::Off,
usage: Usage::default(),
ctx_tokens: 0,
ctx_max: 150_000,