summaryrefslogtreecommitdiff
path: root/makima/src/server
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-15 17:59:37 +0000
committersoryu <soryu@soryu.co>2026-01-15 17:59:37 +0000
commit11c78ade600a2d74b8f033f18045a0c28fac4362 (patch)
tree19a62408769292cefd2f990f9fd8d9fff43becdf /makima/src/server
parent3efdab36ca61a6795454668881d5b925abe22bd3 (diff)
downloadsoryu-11c78ade600a2d74b8f033f18045a0c28fac4362.tar.gz
soryu-11c78ade600a2d74b8f033f18045a0c28fac4362.zip
Implement simple git checkpoint command for supervisor
Diffstat (limited to 'makima/src/server')
-rw-r--r--makima/src/server/handlers/mesh_daemon.rs124
-rw-r--r--makima/src/server/handlers/mesh_supervisor.rs43
-rw-r--r--makima/src/server/state.rs8
3 files changed, 165 insertions, 10 deletions
diff --git a/makima/src/server/handlers/mesh_daemon.rs b/makima/src/server/handlers/mesh_daemon.rs
index 39b12da..0d00f5b 100644
--- a/makima/src/server/handlers/mesh_daemon.rs
+++ b/makima/src/server/handlers/mesh_daemon.rs
@@ -381,6 +381,35 @@ pub enum DaemonMessage {
/// Error message if operation failed
error: Option<String>,
},
+ /// Notification that a checkpoint was created
+ CheckpointCreated {
+ #[serde(rename = "taskId")]
+ task_id: Uuid,
+ /// Whether the operation succeeded
+ success: bool,
+ /// Commit SHA if successful
+ #[serde(rename = "commitSha")]
+ commit_sha: Option<String>,
+ /// Branch name where checkpoint was created
+ #[serde(rename = "branchName")]
+ branch_name: Option<String>,
+ /// Checkpoint number in sequence
+ #[serde(rename = "checkpointNumber")]
+ checkpoint_number: Option<i32>,
+ /// Files changed in this checkpoint
+ #[serde(rename = "filesChanged")]
+ files_changed: Option<serde_json::Value>,
+ /// Lines added
+ #[serde(rename = "linesAdded")]
+ lines_added: Option<i32>,
+ /// Lines removed
+ #[serde(rename = "linesRemoved")]
+ lines_removed: Option<i32>,
+ /// Error message if operation failed
+ error: Option<String>,
+ /// User-provided checkpoint message
+ message: String,
+ },
}
/// Validated daemon authentication result.
@@ -1115,6 +1144,101 @@ async fn handle_daemon_connection(socket: WebSocket, state: SharedState, auth_re
});
}
}
+ Ok(DaemonMessage::CheckpointCreated {
+ task_id,
+ success,
+ commit_sha,
+ branch_name,
+ checkpoint_number: _, // We'll get from DB
+ files_changed,
+ lines_added,
+ lines_removed,
+ error,
+ message,
+ }) => {
+ tracing::info!(
+ task_id = %task_id,
+ success = success,
+ commit_sha = ?commit_sha,
+ "Checkpoint created notification received"
+ );
+
+ if success {
+ if let (Some(sha), Some(branch)) = (commit_sha.clone(), branch_name.clone()) {
+ // Store checkpoint in database
+ if let Some(pool) = state.db_pool.as_ref() {
+ match repository::create_task_checkpoint(
+ pool,
+ task_id,
+ &sha,
+ &branch,
+ &message,
+ files_changed.clone(),
+ lines_added,
+ lines_removed,
+ ).await {
+ Ok(checkpoint) => {
+ tracing::info!(
+ task_id = %task_id,
+ checkpoint_id = %checkpoint.id,
+ checkpoint_number = checkpoint.checkpoint_number,
+ "Checkpoint stored in database"
+ );
+
+ // Broadcast success as task output
+ state.broadcast_task_output(TaskOutputNotification {
+ task_id,
+ owner_id: Some(owner_id),
+ message_type: "system".to_string(),
+ content: format!(
+ "✓ Checkpoint #{} created: {} ({})",
+ checkpoint.checkpoint_number,
+ message,
+ &sha[..7.min(sha.len())]
+ ),
+ tool_name: None,
+ tool_input: None,
+ is_error: Some(false),
+ cost_usd: None,
+ duration_ms: None,
+ is_partial: false,
+ });
+ }
+ Err(e) => {
+ tracing::error!(error = %e, "Failed to store checkpoint in database");
+ state.broadcast_task_output(TaskOutputNotification {
+ task_id,
+ owner_id: Some(owner_id),
+ message_type: "error".to_string(),
+ content: format!("Checkpoint commit succeeded but DB storage failed: {}", e),
+ tool_name: None,
+ tool_input: None,
+ is_error: Some(true),
+ cost_usd: None,
+ duration_ms: None,
+ is_partial: false,
+ });
+ }
+ }
+ }
+ }
+ } else {
+ // Broadcast failure
+ let error_msg = error.unwrap_or_else(|| "Unknown error".to_string());
+ state.broadcast_task_output(TaskOutputNotification {
+ task_id,
+ owner_id: Some(owner_id),
+ message_type: "error".to_string(),
+ content: format!("✗ Checkpoint failed: {}", error_msg),
+ tool_name: None,
+ tool_input: None,
+ is_error: Some(true),
+ cost_usd: None,
+ duration_ms: None,
+ is_partial: false,
+ });
+ }
+ }
Err(e) => {
tracing::warn!("Failed to parse daemon message: {}", e);
}
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()
}
diff --git a/makima/src/server/state.rs b/makima/src/server/state.rs
index 2a45d88..6a56f21 100644
--- a/makima/src/server/state.rs
+++ b/makima/src/server/state.rs
@@ -396,6 +396,14 @@ pub enum DaemonCommand {
task_id: Uuid,
},
+ /// Create a git checkpoint (stage changes, commit, record stats)
+ CreateCheckpoint {
+ #[serde(rename = "taskId")]
+ task_id: Uuid,
+ /// Commit message for the checkpoint
+ message: String,
+ },
+
/// Clean up a task's worktree (used when contract is completed/deleted)
CleanupWorktree {
#[serde(rename = "taskId")]