use super::{Error, Fx, Outcome};
use crate::prompt::inbox::{self, ProbeOutcome};
use crate::prompt::step::latest_step_outcome;
use crate::provider::segment;
use std::path::{Path, PathBuf};
#[derive(clap::Args, Debug)]
pub struct Args {
pub workspace: PathBuf,
pub agent: String,
pub content: String,
}
pub fn run(args: Args, fx: &mut Fx) -> Result<Outcome, Error> {
crate::name::require_agent_id(&args.agent).map_err(|e| Error::new("message", e))?;
let failed = branch_failed(&args.workspace, &args.agent);
let probe = inbox::cli_run(
&args.workspace,
&args.agent,
&args.content,
&fx.driver_target,
)
.map_err(|e| Error::new("message", e))?;
if failed && probe == ProbeOutcome::Launched {
eprintln!("{}", failed_branch_note(&args.agent));
}
Ok(Outcome::Quiet)
}
pub(super) fn branch_failed(workspace: &Path, agent: &str) -> bool {
latest_step_outcome(workspace, agent) == Some(segment::Outcome::Failed)
}
pub(super) fn failed_branch_note(agent: &str) -> String {
format!(
"lernie: {agent}: latest model call failed (§2.10) — message queued and a driver \
launched, but if the cause persists the branch will not advance; \
see steps/{agent}/ or run `lernie scan`"
)
}