From a9da99085bc0b1f94e13cb27639915fd1398ccbe Mon Sep 17 00:00:00 2001 From: soryu Date: Mon, 16 Feb 2026 00:28:16 +0000 Subject: feat: track directive goal history for intelligent re-planning (#63) * WIP: heartbeat checkpoint * feat: soryu-co/soryu - makima: Save previous goal on update and include history in re-planning prompt --- makima/src/orchestration/directive.rs | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'makima/src/orchestration/directive.rs') diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs index 5f8cb486..92aacde 100644 --- a/makima/src/orchestration/directive.rs +++ b/makima/src/orchestration/directive.rs @@ -44,7 +44,7 @@ impl DirectiveOrchestrator { "Directive needs planning — spawning planning task" ); - let plan = build_planning_prompt(&directive, &[], 1); + let plan = build_planning_prompt(&directive, &[], 1, &[]); if let Err(e) = self .spawn_orchestrator_task( @@ -317,8 +317,11 @@ impl DirectiveOrchestrator { repository::list_directive_steps(&self.pool, directive.id).await?; let generation = repository::get_directive_max_generation(&self.pool, directive.id).await? + 1; + let goal_history = + repository::get_directive_goal_history(&self.pool, directive.id, 3).await?; - let plan = build_planning_prompt(&directive, &existing_steps, generation); + let plan = + build_planning_prompt(&directive, &existing_steps, generation, &goal_history); if let Err(e) = self .spawn_orchestrator_task( @@ -846,6 +849,7 @@ fn build_planning_prompt( directive: &crate::db::models::Directive, existing_steps: &[crate::db::models::DirectiveStep], generation: i32, + goal_history: &[crate::db::models::DirectiveGoalHistory], ) -> String { let mut prompt = String::new(); @@ -854,8 +858,42 @@ fn build_planning_prompt( prompt.push_str(&format!( "⚠️ RE-PLANNING: The GOAL has been updated — you must re-evaluate ALL existing steps.\n\ Previous steps were planned for an earlier version of the goal. Some may no longer be \ - relevant. Review each step below and act according to the instructions per status category.\n\n\ - EXISTING STEPS (generation {}):\n", + relevant. Review each step below and act according to the instructions per status category.\n\n", + )); + + // ── Goal changes section ────────────────────────────────── + if !goal_history.is_empty() { + prompt.push_str("-- GOAL CHANGES --\n"); + prompt.push_str("The goal has been updated. Compare the previous and current goals to understand what changed:\n\n"); + for (i, entry) in goal_history.iter().enumerate() { + if i == 0 { + prompt.push_str(&format!( + "PREVIOUS GOAL (replaced at {}):\n{}\n\n", + entry.created_at.format("%Y-%m-%d %H:%M:%S UTC"), + entry.goal + )); + } else { + prompt.push_str(&format!( + "OLDER GOAL (version from {}):\n{}\n\n", + entry.created_at.format("%Y-%m-%d %H:%M:%S UTC"), + entry.goal + )); + } + } + prompt.push_str(&format!( + "CURRENT GOAL (what you must plan for):\n{}\n\n", + directive.goal + )); + prompt.push_str( + "IMPORTANT: Analyze what CHANGED between the previous goal and the current goal.\n\ + - If the change is minor (e.g., clarification, small addition), try to KEEP existing pending steps and only add/modify what is needed for the delta.\n\ + - If the change is major (e.g., completely different objective), you may need to remove most pending steps and create a fresh plan.\n\ + - Always preserve completed and running steps - they represent work already done.\n\n", + ); + } + + prompt.push_str(&format!( + "EXISTING STEPS (generation {}):\n", generation - 1 )); -- cgit v1.2.3