turn loop: --continue, disable claude auto-compact, /compact on overflow

This commit is contained in:
müde 2026-05-15 15:40:51 +02:00
parent 409263f1c9
commit 70af56e050
3 changed files with 183 additions and 49 deletions

View file

@ -153,24 +153,8 @@ async fn serve(
});
let prompt = format_wake_prompt(&label, &from, &body);
let outcome =
turn::run_turn(&prompt, &mcp_config, &bus, mcp::Flavor::Agent).await;
match outcome {
Ok(()) => {
bus.emit(LiveEvent::TurnEnd {
ok: true,
note: None,
});
tracing::info!("claude turn finished");
}
Err(e) => {
let note = format!("{e:#}");
bus.emit(LiveEvent::TurnEnd {
ok: false,
note: Some(note.clone()),
});
tracing::warn!(error = %note, "claude turn failed");
}
}
drive_turn(&prompt, &mcp_config, &bus, mcp::Flavor::Agent).await;
emit_turn_end(&bus, &outcome);
}
Ok(AgentResponse::Empty) => {}
Ok(AgentResponse::Ok | AgentResponse::Status { .. }) => {
@ -187,6 +171,47 @@ async fn serve(
}
}
/// Drive one turn end-to-end. If claude hits `Prompt is too long`, run
/// `/compact` against the persistent session and retry once. Returns the
/// final `TurnOutcome` to drive the `TurnEnd` live event.
async fn drive_turn(
prompt: &str,
mcp_config: &Path,
bus: &Bus,
flavor: mcp::Flavor,
) -> turn::TurnOutcome {
match turn::run_turn(prompt, mcp_config, bus, flavor).await {
turn::TurnOutcome::PromptTooLong => {
if let Err(e) = turn::compact_session(bus).await {
tracing::warn!(error = %format!("{e:#}"), "compact failed");
return turn::TurnOutcome::Failed(e);
}
turn::run_turn(prompt, mcp_config, bus, flavor).await
}
other => other,
}
}
fn emit_turn_end(bus: &Bus, outcome: &turn::TurnOutcome) {
match outcome {
turn::TurnOutcome::Ok | turn::TurnOutcome::PromptTooLong => {
bus.emit(LiveEvent::TurnEnd {
ok: true,
note: None,
});
tracing::info!("claude turn finished");
}
turn::TurnOutcome::Failed(e) => {
let note = format!("{e:#}");
bus.emit(LiveEvent::TurnEnd {
ok: false,
note: Some(note.clone()),
});
tracing::warn!(error = %note, "claude turn failed");
}
}
}
/// System prompt handed to claude on each turn. The harness has already
/// popped one message off the inbox (the wake signal); claude is told
/// about it and the MCP tools, and is expected to drive any further