harness-tui + engine: jobs pane, subtask drill-in, reminders (M4)

TUI: Ctrl+J (or /jobs) opens a jobs pane listing the current session's board —
alias, agent, state, objective, files read — populated on load and kept live via
JobUpdated events; Enter drills into a subtask's child session. Snapshot test added.

Engine: optional orchestration reminders (off by default) injected as synthetic,
non-persisted turn-start blocks and, after a file tool runs, an after-file-tool
block on the following turn. Processor reports file-tool usage via StepOutcome.

This completes M4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 06:46:31 +02:00
co-authored by Claude Opus 4.8
parent 54f91b7e4c
commit 7738ed55b9
15 changed files with 426 additions and 28 deletions
+96 -9
View File
@@ -24,6 +24,10 @@ pub struct RunConfig {
pub cost: Option<crate::types::ModelCost>,
/// Whether to append the background job board to requests (primary/delegating agents).
pub inject_job_board: bool,
/// Optional user-provided reminder injected at the start of every turn (off by default).
pub reminder_turn_start: Option<String>,
/// Optional user-provided reminder injected on the turn after a file tool ran.
pub reminder_after_file_tool: Option<String>,
}
/// Adds a step's usage/cost onto the persisted session and republishes it. Cost accounting is
@@ -162,6 +166,8 @@ pub async fn run_session(
) -> RunOutcome {
let mut doomloop = DoomLoopGuard::new();
let mut steps = 0u32;
// Whether the previous step ran a file tool, gating the `after_file_tool` reminder.
let mut prev_used_file_tool = false;
loop {
match should_continue(&ctx.store, &ctx.session_id).await {
@@ -200,18 +206,33 @@ pub async fn run_session(
wire_messages.extend(convert_message(message, &parts));
}
// Append the (synthetic, non-persisted) job board to the last user message so the
// orchestrator sees running/reusable subtasks. docs/04-multiagent.md.
// Collect synthetic (non-persisted) blocks to append to the last user message this
// turn: the optional turn-start reminder, the job board, and — if the previous step
// ran a file tool — the optional after-file-tool reminder. docs/04-multiagent.md.
let mut synthetic: Vec<String> = Vec::new();
if let Some(reminder) = &run_config.reminder_turn_start {
synthetic.push(reminder.clone());
}
if run_config.inject_job_board {
if let Some(board) = &ctx.job_board {
if let Some(block) = board.format_for_prompt() {
if let Some(last_user) = wire_messages
.iter_mut()
.rev()
.find(|m| m.role == WireRole::User)
{
last_user.content.push(WireContent::Text { text: block });
}
synthetic.push(block);
}
}
}
if prev_used_file_tool {
if let Some(reminder) = &run_config.reminder_after_file_tool {
synthetic.push(reminder.clone());
}
}
if !synthetic.is_empty() {
if let Some(last_user) = wire_messages
.iter_mut()
.rev()
.find(|m| m.role == WireRole::User)
{
for text in synthetic {
last_user.content.push(WireContent::Text { text });
}
}
}
@@ -278,6 +299,7 @@ pub async fn run_session(
}
Ok(outcome) => {
accumulate_session_usage(&ctx, &outcome.usage, outcome.cost, now_fn()).await;
prev_used_file_tool = outcome.used_file_tool;
// A completed step means the orchestrator has now seen any terminal jobs
// that were on the board this turn; mark them reconciled.
if run_config.inject_job_board {
@@ -494,6 +516,8 @@ mod tests {
..Default::default()
}),
inject_job_board: false,
reminder_turn_start: None,
reminder_after_file_tool: None,
};
let outcome = run_session(Arc::new(provider), ctx, &run_config, || 2).await;
@@ -602,6 +626,8 @@ mod tests {
instructions: Vec::new(),
cost: None,
inject_job_board: false,
reminder_turn_start: None,
reminder_after_file_tool: None,
};
let outcome = run_session(Arc::new(provider), ctx, &run_config, || 2).await;
@@ -707,6 +733,8 @@ mod tests {
instructions: Vec::new(),
cost: None,
inject_job_board: true,
reminder_turn_start: None,
reminder_after_file_tool: None,
};
let provider = std::sync::Arc::new(CapturingProvider {
@@ -735,4 +763,63 @@ mod tests {
assert!(text.contains("exp-1"), "got: {text}");
assert!(text.contains("map the auth flow"), "got: {text}");
}
#[tokio::test]
async fn turn_start_reminder_is_injected_into_the_request() {
let store = Store::open_in_memory().unwrap();
let bus = EventBus::new();
let model = ModelRef::new("mock", "mock-model");
let session = Session::new_root("orchestrator", model.clone(), 1);
let session_id = session.id.clone();
store.upsert_session(session).await.unwrap();
let user_message = Message::new_user(session_id.clone(), 1);
store.upsert_message(user_message.clone()).await.unwrap();
store
.upsert_part(Part {
id: crate::types::PartId::new(),
message_id: user_message.id.clone(),
session_id: session_id.clone(),
idx: 0,
body: PartBody::Text {
text: "do the thing".into(),
synthetic: false,
},
})
.await
.unwrap();
let cwd = tempfile::tempdir().unwrap();
let ctx = make_ctx(store, bus, session_id, cwd.path().to_path_buf()).await;
let run_config = RunConfig {
agent_name: "orchestrator".into(),
agent_prompt: "You orchestrate.".into(),
model,
temperature: None,
max_steps: 1,
instructions: Vec::new(),
cost: None,
inject_job_board: false,
reminder_turn_start: Some("REMEMBER: stay on task.".into()),
reminder_after_file_tool: None,
};
let provider = std::sync::Arc::new(CapturingProvider {
last: StdMutex::new(None),
});
let outcome = run_session(provider.clone(), ctx, &run_config, || 2).await;
assert!(matches!(outcome, RunOutcome::Stopped));
let req = provider.last.lock().unwrap().clone().expect("a request");
let last_user = req
.messages
.iter()
.rev()
.find(|m| m.role == WireRole::User)
.expect("a user message");
let has_reminder = last_user.content.iter().any(
|c| matches!(c, WireContent::Text { text } if text.contains("REMEMBER: stay on task.")),
);
assert!(has_reminder, "turn-start reminder should be injected");
}
}