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:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ pub struct StepOutcome {
|
||||
/// Dollar cost of this step's usage (0.0 when no pricing is available).
|
||||
pub cost: f64,
|
||||
pub aborted: bool,
|
||||
/// Whether a file-mutating tool (`edit`/`write`) ran this step — drives the optional
|
||||
/// `after_file_tool` reminder injection on the next turn.
|
||||
pub used_file_tool: bool,
|
||||
}
|
||||
|
||||
pub struct StepError {
|
||||
@@ -98,9 +101,13 @@ impl FlushTracker {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tool names that mutate files — after one runs, the optional `after_file_tool` reminder fires.
|
||||
const FILE_TOOLS: &[&str] = &["edit", "write"];
|
||||
|
||||
struct Run<'a> {
|
||||
ctx: &'a StepContext,
|
||||
assistant: Option<Message>,
|
||||
used_file_tool: bool,
|
||||
next_idx: u32,
|
||||
active_text: Option<PartId>,
|
||||
active_reasoning: Option<PartId>,
|
||||
@@ -117,6 +124,7 @@ impl<'a> Run<'a> {
|
||||
Self {
|
||||
ctx,
|
||||
assistant: None,
|
||||
used_file_tool: false,
|
||||
next_idx: 0,
|
||||
active_text: None,
|
||||
active_reasoning: None,
|
||||
@@ -386,6 +394,9 @@ impl<'a> Run<'a> {
|
||||
input: serde_json::Value,
|
||||
doomloop: &mut DoomLoopGuard,
|
||||
) -> Result<(), ProviderError> {
|
||||
if FILE_TOOLS.contains(&name.as_str()) {
|
||||
self.used_file_tool = true;
|
||||
}
|
||||
let part_id = self.pending_tools.remove(&call_id).unwrap_or_default();
|
||||
let running = Part {
|
||||
id: part_id.clone(),
|
||||
@@ -607,6 +618,7 @@ pub async fn process_step(
|
||||
usage,
|
||||
cost: step_cost,
|
||||
aborted: true,
|
||||
used_file_tool: run.used_file_tool,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -679,5 +691,6 @@ pub async fn process_step(
|
||||
usage,
|
||||
cost: step_cost,
|
||||
aborted: false,
|
||||
used_file_tool: run.used_file_tool,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user