diff options
| author | soryu <soryu@soryu.co> | 2026-01-15 17:59:37 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-15 17:59:37 +0000 |
| commit | 11c78ade600a2d74b8f033f18045a0c28fac4362 (patch) | |
| tree | 19a62408769292cefd2f990f9fd8d9fff43becdf /makima/src/server/handlers/mesh_supervisor.rs | |
| parent | 3efdab36ca61a6795454668881d5b925abe22bd3 (diff) | |
| download | soryu-11c78ade600a2d74b8f033f18045a0c28fac4362.tar.gz soryu-11c78ade600a2d74b8f033f18045a0c28fac4362.zip | |
Implement simple git checkpoint command for supervisor
Diffstat (limited to 'makima/src/server/handlers/mesh_supervisor.rs')
| -rw-r--r-- | makima/src/server/handlers/mesh_supervisor.rs | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/makima/src/server/handlers/mesh_supervisor.rs b/makima/src/server/handlers/mesh_supervisor.rs index 3add89f..278d0f5 100644 --- a/makima/src/server/handlers/mesh_supervisor.rs +++ b/makima/src/server/handlers/mesh_supervisor.rs @@ -714,10 +714,12 @@ pub async fn read_worktree_file( ), request_body = CreateCheckpointRequest, responses( - (status = 201, description = "Checkpoint created", body = CheckpointResponse), + (status = 202, description = "Checkpoint creation accepted", body = CheckpointResponse), (status = 401, description = "Unauthorized"), + (status = 403, description = "Forbidden - can only create checkpoint for own task"), (status = 404, description = "Task not found"), (status = 500, description = "Internal server error"), + (status = 503, description = "Task has no assigned daemon"), ), tag = "Mesh Supervisor" )] @@ -749,7 +751,7 @@ pub async fn create_checkpoint( let pool = state.db_pool.as_ref().unwrap(); - // Get task + // Get task and daemon_id let task = match repository::get_task(pool, task_id).await { Ok(Some(t)) => t, Ok(None) => { @@ -767,16 +769,37 @@ pub async fn create_checkpoint( } }; - // TODO: Implement checkpoint creation via daemon command - // For now, checkpoints should be created by the task itself via git commands - let _ = (task, request); + let Some(daemon_id) = task.daemon_id else { + return ( + StatusCode::SERVICE_UNAVAILABLE, + Json(ApiError::new("NO_DAEMON", "Task has no assigned daemon")), + ).into_response(); + }; + + // Send CreateCheckpoint command to daemon + let cmd = DaemonCommand::CreateCheckpoint { + task_id, + message: request.message.clone(), + }; + if let Err(e) = state.send_daemon_command(daemon_id, cmd).await { + tracing::error!(error = %e, "Failed to send CreateCheckpoint command"); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ApiError::new("COMMAND_FAILED", "Failed to send command to daemon")), + ).into_response(); + } + + // Return accepted - the checkpoint result will be delivered via WebSocket + // and stored in the database by the daemon message handler ( - StatusCode::NOT_IMPLEMENTED, - Json(ApiError::new( - "NOT_IMPLEMENTED", - "Checkpoint creation via API not yet implemented. Use git commands directly in the task.", - )), + StatusCode::ACCEPTED, + Json(CheckpointResponse { + task_id, + checkpoint_number: 0, // Will be assigned by DB on actual creation + commit_sha: "pending".to_string(), + message: request.message, + }), ).into_response() } |
