From d7ab69e8ae340433d9bb321817b10f3e31c43b6f Mon Sep 17 00:00:00 2001 From: Louis Knight-Webb Date: Sat, 21 Jun 2025 19:45:47 +0100 Subject: [PATCH] BE improvements --- backend/src/models/task_attempt.rs | 19 ++++++++++--------- backend/src/routes/task_attempts.rs | 7 ++----- backend/src/routes/tasks.rs | 14 +------------- frontend/src/pages/project-tasks.tsx | 2 +- shared/types.ts | 8 ++++---- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/backend/src/models/task_attempt.rs b/backend/src/models/task_attempt.rs index badb3d50..fa5a918b 100644 --- a/backend/src/models/task_attempt.rs +++ b/backend/src/models/task_attempt.rs @@ -73,10 +73,7 @@ pub struct TaskAttempt { #[derive(Debug, Deserialize, TS)] #[ts(export)] pub struct CreateTaskAttempt { - pub task_id: Uuid, - pub worktree_path: String, - pub merge_commit: Option, - pub executor: Option, + pub executor: Option, // Optional executor name (defaults to "echo") } #[derive(Debug, Deserialize, TS)] @@ -156,9 +153,10 @@ impl TaskAttempt { pool: &SqlitePool, data: &CreateTaskAttempt, attempt_id: Uuid, + task_id: Uuid, ) -> Result { // First, get the task to get the project_id - let task = Task::find_by_id(pool, data.task_id) + let task = Task::find_by_id(pool, task_id) .await? .ok_or(TaskAttemptError::TaskNotFound)?; @@ -167,9 +165,12 @@ impl TaskAttempt { .await? .ok_or(TaskAttemptError::ProjectNotFound)?; + // Generate worktree path automatically + let worktree_path_str = format!("/tmp/mission-control-worktree-{}", attempt_id); + let worktree_path = Path::new(&worktree_path_str); + // Create the worktree using git2 let repo = Repository::open(&project.git_repo_path)?; - let worktree_path = Path::new(&data.worktree_path); // We no longer store base_commit in the database - it's retrieved live via git2 @@ -190,9 +191,9 @@ impl TaskAttempt { VALUES ($1, $2, $3, $4, $5) RETURNING id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, merge_commit, executor, created_at as "created_at!: DateTime", updated_at as "updated_at!: DateTime""#, attempt_id, - data.task_id, - data.worktree_path, - data.merge_commit, + task_id, + worktree_path_str, + Option::::None, // merge_commit is always None during creation data.executor ) .fetch_one(pool) diff --git a/backend/src/routes/task_attempts.rs b/backend/src/routes/task_attempts.rs index c5727501..52a16e0a 100644 --- a/backend/src/routes/task_attempts.rs +++ b/backend/src/routes/task_attempts.rs @@ -113,7 +113,7 @@ pub async fn create_task_attempt( Path((project_id, task_id)): Path<(Uuid, Uuid)>, Extension(pool): Extension, Extension(app_state): Extension, - Json(mut payload): Json, + Json(payload): Json, ) -> Result>, StatusCode> { // Verify task exists in project first match Task::exists(&pool, task_id, project_id).await { @@ -127,10 +127,7 @@ pub async fn create_task_attempt( let id = Uuid::new_v4(); - // Ensure the task_id in the payload matches the path parameter - payload.task_id = task_id; - - match TaskAttempt::create(&pool, &payload, id).await { + match TaskAttempt::create(&pool, &payload, id, task_id).await { Ok(attempt) => { // Start execution asynchronously (don't block the response) let pool_clone = pool.clone(); diff --git a/backend/src/routes/tasks.rs b/backend/src/routes/tasks.rs index 3291a5ba..893fc59d 100644 --- a/backend/src/routes/tasks.rs +++ b/backend/src/routes/tasks.rs @@ -132,23 +132,11 @@ pub async fn create_task_and_start( // Create task attempt let attempt_id = Uuid::new_v4(); - let worktree_path = format!( - "/tmp/task-{}-attempt-{}", - task_id, - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_millis() - ); - let attempt_payload = CreateTaskAttempt { - task_id, - worktree_path, - merge_commit: None, executor: Some("claude".to_string()), // Default executor }; - match TaskAttempt::create(&pool, &attempt_payload, attempt_id).await { + match TaskAttempt::create(&pool, &attempt_payload, attempt_id, task_id).await { Ok(attempt) => { // Start execution asynchronously (don't block the response) let pool_clone = pool.clone(); diff --git a/frontend/src/pages/project-tasks.tsx b/frontend/src/pages/project-tasks.tsx index 91d83fe6..67e26a4e 100644 --- a/frontend/src/pages/project-tasks.tsx +++ b/frontend/src/pages/project-tasks.tsx @@ -355,7 +355,7 @@ export function ProjectTasks() { ) : (
-
+
; -export type TaskAttemptActivity = { id: string, task_attempt_id: string, status: TaskAttemptStatus, note: string | null, created_at: string, }; +export type TaskAttemptActivity = { id: string, execution_process_id: string, status: TaskAttemptStatus, note: string | null, created_at: string, }; -export type CreateTaskAttemptActivity = { task_attempt_id: string, status: TaskAttemptStatus | null, note: string | null, }; +export type CreateTaskAttemptActivity = { execution_process_id: string, status: TaskAttemptStatus | null, note: string | null, }; export type DirectoryEntry = { name: string, path: string, is_directory: boolean, is_git_repo: boolean, };