Skip to main content

Module plan

Module plan 

Source
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§

PlanParams
Parameters for run_plan.
PlanResult
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.md is generated inside that directory.
run_plan
Run a plan, returning captured text and the path written (if any).
validate_output_path
Validate that path is inside the user’s home directory — used when ZAG_USER_HOME_DIR is set (multi-user zag serve mode) to keep a user from writing outside their sandbox. In direct CLI mode ZAG_USER_HOME_DIR is unset and this function is a no-op.