output() tool: don't error when no output dir (forked agents)

Forked agents don't have POC_AGENT_OUTPUT_DIR set. The output tool
now returns success regardless — forked agents extract output values
from the AST via run_with_backend. Subprocess agents still write
to disk when the dir is set.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 19:51:44 -04:00
parent 33ed54396c
commit 68fbcc351f

View file

@ -245,11 +245,13 @@ fn output(args: &serde_json::Value) -> Result<String> {
anyhow::bail!("invalid output key: {}", key);
}
let value = get_str(args, "value")?;
let dir = std::env::var("POC_AGENT_OUTPUT_DIR")
.map_err(|_| anyhow::anyhow!("no output directory set"))?;
let path = std::path::Path::new(&dir).join(key);
std::fs::write(&path, value)
.with_context(|| format!("writing output {}", path.display()))?;
// Write to disk if output dir is set (subprocess agents),
// otherwise just return success (forked agents extract from AST)
if let Ok(dir) = std::env::var("POC_AGENT_OUTPUT_DIR") {
let path = std::path::Path::new(&dir).join(&key);
std::fs::write(&path, &value)
.with_context(|| format!("writing output {}", path.display()))?;
}
Ok(format!("{}: {}", key, value))
}