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/server/handlers/directives.rs | 45 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'makima/src/server') diff --git a/makima/src/server/handlers/directives.rs b/makima/src/server/handlers/directives.rs index 929769c..6060171 100644 --- a/makima/src/server/handlers/directives.rs +++ b/makima/src/server/handlers/directives.rs @@ -823,29 +823,32 @@ pub async fn update_goal( .into_response(); }; - match repository::update_directive_goal(pool, auth.owner_id, id, &req.goal).await { - Ok(Some(directive)) => { - // Clear non-started steps so replanning starts fresh - match repository::clear_pending_directive_steps(pool, id).await { - Ok(count) => { - if count > 0 { - tracing::info!( - directive_id = %id, - removed_steps = count, - "Cleared pending steps after goal update — replanning will generate new steps" - ); - } - } - Err(e) => { - tracing::warn!( - directive_id = %id, - error = %e, - "Failed to clear pending steps after goal update" - ); - } + // Save old goal to history before overwriting (best-effort) + match repository::get_directive_for_owner(pool, auth.owner_id, id).await { + Ok(Some(current)) => { + if let Err(e) = repository::save_directive_goal_history(pool, id, ¤t.goal).await + { + tracing::warn!( + directive_id = %id, + error = %e, + "Failed to save goal history before update — continuing with goal update" + ); } - Json(directive).into_response() } + Ok(None) => { + // Directive not found — update_directive_goal will handle this + } + Err(e) => { + tracing::warn!( + directive_id = %id, + error = %e, + "Failed to fetch current directive for goal history — continuing with goal update" + ); + } + } + + match repository::update_directive_goal(pool, auth.owner_id, id, &req.goal).await { + Ok(Some(directive)) => Json(directive).into_response(), Ok(None) => ( StatusCode::NOT_FOUND, Json(ApiError::new("NOT_FOUND", "Directive not found")), -- cgit v1.2.3