2026-07-20 09:04:57 +07:00
|
|
|
//! Plan management tools — enter and mark ready.
|
|
|
|
|
|
|
|
|
|
use crate::tools::{Tool, ToolCtx};
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use serde_json::{json, Value};
|
2026-07-20 10:55:09 +07:00
|
|
|
use tracing::info;
|
2026-07-20 09:04:57 +07:00
|
|
|
|
|
|
|
|
pub struct PlanEnter;
|
|
|
|
|
|
|
|
|
|
impl Tool for PlanEnter {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"plan_enter"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
|
|
|
|
"Enter a planning phase — present a structured plan for approval"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
"plan": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "The structured plan text"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": ["plan"]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let plan_text = crate::tools::arg_str(args, "plan")?;
|
|
|
|
|
Ok(format!(
|
|
|
|
|
"Plan entered (length: {} chars). Waiting for approval...",
|
|
|
|
|
plan_text.len()
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct PlanReady;
|
|
|
|
|
|
|
|
|
|
impl Tool for PlanReady {
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"plan_ready"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &'static str {
|
|
|
|
|
"Signal that the plan is ready and execution can begin"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parameters(&self) -> Value {
|
|
|
|
|
json!({
|
|
|
|
|
"type": "object",
|
2026-07-20 10:55:09 +07:00
|
|
|
"properties": {
|
|
|
|
|
"plan": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "The final plan content"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": ["plan"]
|
2026-07-20 09:04:57 +07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-20 10:55:09 +07:00
|
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
|
|
|
let plan_content = crate::tools::arg_str(args, "plan")?;
|
|
|
|
|
info!("plan ready: {} chars", plan_content.len());
|
|
|
|
|
// Persist the plan to session directory for reference
|
|
|
|
|
let plan_dir = ctx.session_dir.join("plans");
|
|
|
|
|
if std::fs::create_dir_all(&plan_dir).is_ok() {
|
|
|
|
|
let filename = format!("plan-{}.md", chrono::Utc::now().format("%Y%m%d_%H%M%S"));
|
|
|
|
|
let path = plan_dir.join(&filename);
|
|
|
|
|
let _ = std::fs::write(&path, &plan_content);
|
|
|
|
|
Ok(format!("Plan saved to {filename}. Starting execution."))
|
|
|
|
|
} else {
|
|
|
|
|
Ok("Plan is ready. Starting execution.".to_string())
|
|
|
|
|
}
|
2026-07-20 09:04:57 +07:00
|
|
|
}
|
|
|
|
|
}
|