code_mesh_core/planner/
mod.rs

1//! Task planning for Code Mesh
2
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5
6/// Planner trait for task decomposition and planning
7#[async_trait]
8pub trait Planner: Send + Sync {
9    /// Create a plan from a high-level task description
10    async fn plan(&self, task: &str, context: PlanContext) -> crate::Result<Plan>;
11    
12    /// Update a plan based on progress
13    async fn update_plan(&self, plan: &mut Plan, progress: &Progress) -> crate::Result<()>;
14}
15
16/// Planning context
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct PlanContext {
19    pub available_tools: Vec<String>,
20    pub constraints: Vec<String>,
21    pub preferences: serde_json::Value,
22}
23
24/// Execution plan
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Plan {
27    pub id: String,
28    pub goal: String,
29    pub steps: Vec<Step>,
30    pub dependencies: Vec<Dependency>,
31}
32
33/// Plan step
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct Step {
36    pub id: String,
37    pub description: String,
38    pub tool: Option<String>,
39    pub parameters: serde_json::Value,
40    pub expected_outcome: String,
41}
42
43/// Step dependency
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct Dependency {
46    pub from: String,
47    pub to: String,
48    pub dependency_type: DependencyType,
49}
50
51#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
52#[serde(rename_all = "snake_case")]
53pub enum DependencyType {
54    Sequential,
55    Parallel,
56    Conditional,
57}
58
59/// Progress tracking
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct Progress {
62    pub completed_steps: Vec<String>,
63    pub failed_steps: Vec<(String, String)>, // (step_id, error)
64    pub current_step: Option<String>,
65}