diff options
| author | soryu <soryu@soryu.co> | 2026-02-16 00:28:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-16 00:28:16 +0000 |
| commit | a9da99085bc0b1f94e13cb27639915fd1398ccbe (patch) | |
| tree | 7b990499368002af8aa72b8e7b619674d8d5c654 /makima/src/server/handlers | |
| parent | bf087f48af2962d884b861345ae52be4f4a54daa (diff) | |
| download | soryu-a9da99085bc0b1f94e13cb27639915fd1398ccbe.tar.gz soryu-a9da99085bc0b1f94e13cb27639915fd1398ccbe.zip | |
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
Diffstat (limited to 'makima/src/server/handlers')
| -rw-r--r-- | makima/src/server/handlers/directives.rs | 45 |
1 files changed, 24 insertions, 21 deletions
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")), |
