Expand description
Library-level implementation of zag plan.
Wraps a goal in the plan prompt template, runs it through a provider, and either streams the result to stdout (via the agent’s default output handling) or captures it to a file path.
§Example
use zag_agent::plan::{PlanParams, run_plan};
let result = run_plan(PlanParams {
provider: "claude".to_string(),
goal: "Add OAuth".to_string(),
output: Some("docs/oauth-plan.md".to_string()),
..PlanParams::default()
})
.await?;
if let Some(path) = result.written_to {
println!("plan written to {}", path.display());
}Structs§
- Plan
Params - Parameters for
run_plan. - Plan
Result - Result of running a plan.
Functions§
- build_
plan_ prompt - Render the plan prompt from
plan_template. - plan_
template - Plan prompt template (front matter stripped) —
{GOAL},{CONTEXT_SECTION},{PROMPT}are replaced at run time. - resolve_
output_ path - Resolve a caller-supplied output path. If the input has an extension the
path is used verbatim; otherwise a timestamped
plan-YYYYMMDD-HHMMSS.mdis generated inside that directory. - run_
plan - Run a plan, returning captured text and the path written (if any).
- validate_
output_ path - Validate that
pathis inside the user’s home directory — used whenZAG_USER_HOME_DIRis set (multi-userzag servemode) to keep a user from writing outside their sandbox. In direct CLI modeZAG_USER_HOME_DIRis unset and this function is a no-op.