Watch
0
0
Fork
You've already forked hyperhive
0

agents: remove the hive-level /effort control too

mara on #5034: "effort shares /models fate". The per-agent web UI no
longer sets effort: the `/effort` slash command, the effort picker,
`POST /api/effort`, `Bus::set_effort`, the `hyperhive-effort` writer,
`EFFORT_LEVELS`/`is_valid_effort` and the ACP effort-list payload are
gone, and `lib/modelEffort.ts` with them. The effort chip is
display-only and shows its source (`effort_source` in `/api/state`);
on ACP it stays hidden while the session offers no effort level.

The read side is unchanged: with no swarm value an agent runs an
existing `hyperhive-effort` file, else its agent.nix effort, else
medium. Existing files are not touched.

Refs #5034
This commit is contained in:
atlas 2026-10-11 01:26:39 +02:00
commit ed271e655f
25 changed files with 170 additions and 464 deletions

View file

@ -1,5 +1,5 @@
//! Operator action POST handlers (send, cancel, compact, model, effort,
//! reset, todos mark-done).
//! Operator action POST handlers (send, cancel, compact, reset, todos
//! mark-done).
use axum::{
Form,
@ -126,68 +126,6 @@ pub(super) async fn post_new_session(State(state): State<AppState>) -> Response
(axum::http::StatusCode::OK, "ok").into_response()
}
#[derive(Deserialize)]
pub(super) struct EffortForm {
effort: String,
}
/// Switch the claude effort level for future sessions. Operator-only
/// (the dashboard picker POSTs here through the gateway). Validated
/// server-side against [`crate::harness_state::EFFORT_LEVELS`] — an out-of-set
/// value is rejected rather than handed to `claude --effort`, since an
/// unknown level would fail every subsequent launch. Applies on the next
/// session start (no mid-session swap). On ACP the level must instead be one
/// the session offers for its model, and applies from the next turn.
pub(super) async fn post_set_effort(
State(state): State<AppState>,
Form(form): Form<EffortForm>,
) -> Response {
let level = form.effort.trim();
let text = if state.bus.session_choices().is_some() {
let offered = super::state::pickers(&state.bus).available_efforts;
if let Some(response) = accept_or_refuse("effort", level, &offered) {
return response;
}
format!("operator: /effort — effort set to '{level}' from the next turn")
} else if crate::harness_state::is_valid_effort(level) {
format!("operator: /effort — claude effort set to '{level}' for future sessions")
} else {
return error_response(
StatusCode::BAD_REQUEST,
&format!(
"effort: level must be one of {}",
crate::harness_state::EFFORT_LEVELS.join(", ")
),
);
};
state.bus.set_effort(level);
state.bus.emit(crate::events::LiveEvent::Note { text });
tracing::info!(%level, "operator set effort");
(axum::http::StatusCode::OK, "ok").into_response()
}
/// The ACP branch of `post_set_effort`: `None` when `name`
/// is one `offered` (the session's current pickers list) names, else the
/// [`not_offered`] refusal to return. Before a session has attached,
/// `offered` is empty and every name is refused.
fn accept_or_refuse(what: &str, name: &str, offered: &[String]) -> Option<Response> {
if offered.iter().any(|o| o == name) {
None
} else {
Some(not_offered(what, offered))
}
}
/// Refuses a pick the ACP session does not offer.
fn not_offered(what: &str, offered: &[String]) -> Response {
let message = if offered.is_empty() {
format!("{what}: the agent's session offers no choice now")
} else {
format!("{what}: the agent's session offers {}", offered.join(", "))
};
error_response(StatusCode::BAD_REQUEST, &message)
}
#[derive(Deserialize)]
pub(super) struct MarkTodosDoneForm {
/// Comma-separated todo ids. Same "one field, JS joins the checked
@ -230,31 +168,3 @@ pub(super) async fn post_mark_todos_done(Form(form): Form<MarkTodosDoneForm>) ->
struct MarkTodosDoneBody {
acked: u64,
}
#[cfg(test)]
mod tests {
use super::accept_or_refuse;
#[test]
fn an_offered_value_is_accepted() {
let offered = vec!["m/think".to_owned(), "m/plain".to_owned()];
assert!(accept_or_refuse("model", "m/plain", &offered).is_none());
}
#[test]
fn a_value_the_session_does_not_offer_is_refused_with_400() {
let offered = vec!["m/think".to_owned()];
let response = accept_or_refuse("model", "m/plain", &offered).unwrap();
assert_eq!(response.status(), axum::http::StatusCode::BAD_REQUEST);
}
#[test]
fn nothing_offered_yet_refuses_with_400() {
// Before a session has attached (or on the effort picker while a
// model switch is pending), `pickers()` returns an empty list —
// every name is refused, not just ones the session once offered
// and later dropped.
let response = accept_or_refuse("effort", "high", &[]).unwrap();
assert_eq!(response.status(), axum::http::StatusCode::BAD_REQUEST);
}
}