Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/honk-testgoose/src/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,19 @@ pub fn default_config_options() -> Vec<Value> {
{ "name": "Gemini 3.8 Flash", "value": "gemini-3.8-flash" },
]
}),
json!({
"id": "thinking_effort",
"name": "Thinking Effort",
"type": "select",
"currentValue": "off",
"options": [
{ "name": "Off", "value": "off" },
{ "name": "Low", "value": "low" },
{ "name": "Medium", "value": "medium" },
{ "name": "High", "value": "high" },
{ "name": "Max", "value": "max" },
]
}),
]
}

Expand Down
35 changes: 35 additions & 0 deletions crates/honk/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct Timeouts {
pub swarm_enable: Duration,
pub rename: Duration,
pub model: Duration,
pub effort: Duration,
pub prompt_confirm: Duration,
pub which: Duration,
pub set: Duration,
Expand All @@ -106,6 +107,7 @@ impl Default for Timeouts {
swarm_enable: Duration::from_secs(30),
rename: Duration::from_secs(10),
model: Duration::from_secs(10),
effort: Duration::from_secs(10),
prompt_confirm: Duration::from_secs(60),
which: octags::DEFAULT_WHICH_TIMEOUT,
set: octags::DEFAULT_TIMEOUT,
Expand All @@ -120,6 +122,7 @@ pub struct LaunchOpts {
pub prompt: String,
pub title: Option<String>,
pub model: Option<String>,
pub effort: Option<String>,
pub tag: TagRequest,
/// The launching session as an oc-tags key (`ses_…` or `goose:<id>`).
pub launcher: Option<String>,
Expand Down Expand Up @@ -162,6 +165,7 @@ impl std::fmt::Debug for LaunchOpts {
.field("prompt", &self.prompt)
.field("title", &self.title)
.field("model", &self.model)
.field("effort", &self.effort)
.field("tag", &self.tag)
.field("launcher", &self.launcher)
.field("tags_bin", &self.tags_bin)
Expand Down Expand Up @@ -363,6 +367,13 @@ pub async fn run(opts: &LaunchOpts) -> Result<Launched, LaunchError> {
);
}

if let Some(effort) = &opts.effort {
step!(
set_effort(&mut client, &native, effort, opts.timeouts.effort).await,
"setting the thinking effort failed"
);
}

// A tag failure does not stop the launch: the worker is still worth
// running, and the caller can repair the tag (sw launch verifies and
// repairs, as for opencode). It still makes the exit non-zero.
Expand Down Expand Up @@ -746,6 +757,29 @@ async fn set_model(
Ok(())
}

async fn set_effort(
client: &mut Client,
sid: &str,
effort: &str,
timeout: Duration,
) -> anyhow::Result<()> {
let frame = call_with_timeout(
client,
"session/set_config_option",
json!({
"sessionId": sid,
"configId": "thinking_effort",
"value": effort,
}),
timeout,
)
.await?;
if let Some(e) = rpc_error(&frame) {
bail!("session/set_config_option: {e}");
}
Ok(())
}

fn client_req_id(sid: &str) -> String {
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand Down Expand Up @@ -1047,6 +1081,7 @@ mod tests {
prompt: "p".into(),
title: None,
model: None,
effort: None,
tag: TagRequest::Off,
launcher: None,
tags_bin: "tags".into(),
Expand Down
35 changes: 35 additions & 0 deletions crates/honk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ struct LaunchArgs {
#[arg(long)]
model: Option<String>,

/// Thinking effort for the new session (goose session/set_config_option thinking_effort); default: goose-serve's GOOSE_THINKING_EFFORT
#[arg(long, value_parser = ["off", "low", "medium", "high", "max"])]
effort: Option<String>,

/// pigeon daemon URL
#[arg(
long = "pigeon-url",
Expand Down Expand Up @@ -156,6 +160,11 @@ fn launch_opts(
Some(m) => Some(m.trim().to_string()),
None => None,
};
let effort = match args.effort {
Some(e) if e.trim().is_empty() => anyhow::bail!("--effort is empty"),
Some(e) => Some(e.trim().to_string()),
None => None,
};
let tag = match args.tag {
None => honk::launch::TagRequest::Inherit,
Some(honk::octags::TagArg::NoInherit) => honk::launch::TagRequest::Off,
Expand All @@ -182,6 +191,7 @@ fn launch_opts(
prompt,
title,
model,
effort,
tag,
launcher: honk::octags::resolve_launcher_from(&env_get),
tags_bin: honk::octags::resolve_bin_from(&env_get, honk::octags::on_path),
Expand Down Expand Up @@ -1330,4 +1340,29 @@ mod tests {
_ => panic!("expected launch command"),
}
}

#[test]
fn test_cli_parse_launch_effort() {
for valid in ["off", "low", "medium", "high", "max"] {
let cli = Cli::try_parse_from([
"honk", "launch", "--effort", valid, "--secret", "s", "/tmp", "do it",
])
.unwrap();
match cli.command {
Commands::Launch(args) => {
assert_eq!(args.effort.as_deref(), Some(valid));
let opts = launch_opts(args, |_| None, || unreachable!()).unwrap();
assert_eq!(opts.effort.as_deref(), Some(valid));
}
_ => panic!("expected launch command"),
}
}

assert!(
Cli::try_parse_from([
"honk", "launch", "--effort", "bogus", "--secret", "s", "/tmp", "do it",
])
.is_err()
);
}
}
139 changes: 138 additions & 1 deletion crates/honk/tests/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct Script {
enable: Value,
prompt: PromptReply,
model_error: Option<&'static str>,
effort_error: Option<&'static str>,
model_list: Option<Value>,
}

Expand All @@ -48,6 +49,7 @@ impl Default for Script {
enable: json!({"result": {"results": [{"name": "swarm", "ok": true}]}}),
prompt: PromptReply::Echo,
model_error: None,
effort_error: None,
model_list: None,
}
}
Expand Down Expand Up @@ -121,7 +123,13 @@ async fn fake_honkd(script: Script, tags_log: PathBuf, pigeon: Arc<StubPigeon>)
}
"_goose/unstable/session/rename" => out.push(json!({"id": id, "result": {}})),
"session/set_config_option" => {
if let Some(err) = script.model_error {
let config_id = v["params"]["configId"].as_str();
let err = match config_id {
Some("model") => script.model_error,
Some("thinking_effort") => script.effort_error,
_ => None,
};
if let Some(err) = err {
out.push(json!({"id": id, "error": {"code": -32602, "message": err}}));
} else {
out.push(json!({"id": id, "result": {"configOptions": []}}));
Expand Down Expand Up @@ -226,6 +234,7 @@ fn opts(r: &Rig, tag: TagRequest, launcher: Option<&str>, title: Option<&str>) -
prompt: "do the thing".into(),
title: title.map(str::to_string),
model: None,
effort: None,
tag,
launcher: launcher.map(str::to_string),
tags_bin: r.tags_bin.clone(),
Expand Down Expand Up @@ -908,6 +917,134 @@ async fn launch_with_model_failure_aborts_before_prompt() {
);
}

#[tokio::test]
async fn launch_with_effort_sets_config_option_before_prompt() {
let r = rig(Script::default(), Behaviour::default(), "", 0).await;
let mut o = opts(&r, TagRequest::Off, None, Some("Fix the thing"));
o.effort = Some("medium".into());
let out = run(&o).await.expect("launch");
assert_eq!(out.prompt, honk::launch::PromptState::Ok);

assert_eq!(
methods(&r),
[
"initialize",
"session/new",
"_goose/unstable/session/rename",
"session/set_config_option",
"session/prompt"
],
"set_config_option must be called after rename and before prompt"
);
let reqs = r.honkd.reqs.lock().unwrap().clone();
let m = &reqs[3];
assert_eq!(
m.params,
json!({
"sessionId": SID,
"configId": "thinking_effort",
"value": "medium",
})
);
}

#[tokio::test]
async fn launch_with_model_and_effort_orders_effort_after_model() {
let r = rig(Script::default(), Behaviour::default(), "", 0).await;
let mut o = opts(&r, TagRequest::Off, None, Some("Fix the thing"));
o.model = Some("gemini-3.8-flash".into());
o.effort = Some("medium".into());
let out = run(&o).await.expect("launch");
assert_eq!(out.prompt, honk::launch::PromptState::Ok);

assert_eq!(
methods(&r),
[
"initialize",
"session/new",
"_goose/unstable/session/rename",
"_honk/model/list",
"session/set_config_option",
"session/set_config_option",
"session/prompt"
],
"both set_config_option calls must be before prompt, with effort after model"
);
let reqs = r.honkd.reqs.lock().unwrap().clone();
let model_req = &reqs[4];
assert_eq!(
model_req.params,
json!({
"sessionId": SID,
"configId": "model",
"value": "gemini-3.8-flash",
})
);
let effort_req = &reqs[5];
assert_eq!(
effort_req.params,
json!({
"sessionId": SID,
"configId": "thinking_effort",
"value": "medium",
})
);
}

#[tokio::test]
async fn launch_without_effort_sends_no_thinking_effort() {
let r = rig(Script::default(), Behaviour::default(), "", 0).await;
let o = opts(&r, TagRequest::Off, None, Some("Fix the thing"));
let out = run(&o).await.expect("launch");
assert_eq!(out.prompt, honk::launch::PromptState::Ok);

let reqs = r.honkd.reqs.lock().unwrap().clone();
let effort_calls = reqs
.iter()
.filter(|req| {
req.method == "session/set_config_option"
&& req.params.get("configId").and_then(Value::as_str) == Some("thinking_effort")
})
.count();
assert_eq!(
effort_calls, 0,
"launch without --effort must send no thinking_effort option"
);
}

#[tokio::test]
async fn launch_with_effort_failure_aborts_before_prompt() {
let script = Script {
effort_error: Some("unsupported thinking effort"),
..Script::default()
};
let r = rig(script, Behaviour::default(), "", 0).await;
let mut o = opts(&r, TagRequest::Off, None, None);
o.effort = Some("high".into());
let err = run(&o).await.unwrap_err();
assert_eq!(err.exit_code(), honk::launch::EXIT_PARTIAL);
let LaunchError::Partial { launched, error } = err else {
panic!("expected partial error");
};
assert_eq!(launched.native, SID);
assert_eq!(launched.prompt, honk::launch::PromptState::No);
let msg = format!("{error:#}");
assert!(
msg.contains("setting the thinking effort failed"),
"error must mention setting the thinking effort failed: {msg}"
);
assert!(
msg.contains("unsupported thinking effort"),
"error must contain upstream message: {msg}"
);

assert_eq!(
methods(&r),
["initialize", "session/new", "session/set_config_option",],
"prompt must not be sent if setting effort fails"
);
}

#[tokio::test]
async fn launch_with_model_refuses_id_not_in_honkd_list() {
let script = Script {
Expand Down
1 change: 1 addition & 0 deletions crates/honk/tests/launch_attach_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn opts(r: &Rig) -> LaunchOpts {
prompt: "do the thing".into(),
title: Some("Fix it".into()),
model: None,
effort: None,
tag: TagRequest::Explicit("honk".into()),
launcher: Some("ses_launcher".into()),
tags_bin: r.tags_bin.clone(),
Expand Down
1 change: 1 addition & 0 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ honk telegram 20261016_7

- `--title <title>`: Session title, set before the first prompt (also sets the Telegram topic title).
- `--model <id>`: Initial model for the session, set before the first prompt. Refuses IDs not present in honkd's model list (configured via honkd `--models-file`), aborting before prompting. If setting the model fails, the launch aborts before prompting with a partial exit code and reports the created session ID.
- `--effort <level>`: Thinking effort for the new session (`off`, `low`, `medium`, `high`, `max`), set after the model step before the first prompt. If setting the thinking effort fails, the launch aborts before prompting with a partial exit code and reports the created session ID. Default: goose-serve's `GOOSE_THINKING_EFFORT`.
- `--tag <tag>`: Tag the session in session-tags (`goose:<id>`). Defaults to inheriting the launching session's tag; `--tag auto` opts out.
- `--no-attach`: Do not auto-attach (do not open a tab running `honk chat`).
- `--tmux-session <name>`: Target tmux session for auto-attach [default: nvim's session].
Expand Down
Loading