From 151e9d87e117b7980e6aad522ac8f3633eeca87a Mon Sep 17 00:00:00 2001 From: soryu Date: Mon, 2 Feb 2026 02:34:50 +0000 Subject: Make makima more opinionated and structured --- makima/src/db/repository.rs | 131 ++++++-------------------------------------- 1 file changed, 16 insertions(+), 115 deletions(-) (limited to 'makima/src/db/repository.rs') diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index e308df7..2ecbc4a 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -12,7 +12,7 @@ use super::models::{ CreateFileRequest, CreateTaskRequest, CreateTemplateRequest, Daemon, DaemonTaskAssignment, DaemonWithCapacity, DeliverableDefinition, File, FileSummary, FileVersion, HistoryEvent, HistoryQueryFilters, MeshChatConversation, MeshChatMessageRecord, PhaseChangeResult, - PhaseConfig, PhaseDefinition, RedTeamNotification, SupervisorHeartbeatRecord, SupervisorState, + PhaseConfig, PhaseDefinition, SupervisorHeartbeatRecord, SupervisorState, Task, TaskCheckpoint, TaskEvent, TaskSummary, UpdateContractRequest, UpdateFileRequest, UpdateTaskRequest, UpdateTemplateRequest, }; @@ -691,11 +691,11 @@ pub async fn create_task(pool: &PgPool, req: CreateTaskRequest) -> Result Result Result, sqlx::Error> t.parent_task_id, t.depth, t.name, t.status, t.priority, t.progress_summary, (SELECT COUNT(*) FROM tasks WHERE parent_task_id = t.id) as subtask_count, - t.version, t.is_supervisor, COALESCE(t.is_red_team, false) as is_red_team, - COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at + t.version, t.is_supervisor, COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at FROM tasks t LEFT JOIN contracts c ON t.contract_id = c.id WHERE t.parent_task_id IS NULL AND COALESCE(t.hidden, false) = false @@ -770,8 +768,7 @@ pub async fn list_subtasks(pool: &PgPool, parent_id: Uuid) -> Result( r#" - INSERT INTO contracts (owner_id, name, description, contract_type, phase, autonomous_loop, phase_guard, local_only, auto_merge_local, red_team_enabled, red_team_prompt, phase_config) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + INSERT INTO contracts (owner_id, name, description, contract_type, phase, autonomous_loop, phase_guard, local_only, auto_merge_local, phase_config) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING * "#, ) @@ -2488,8 +2479,6 @@ pub async fn create_contract_for_owner( .bind(phase_guard) .bind(local_only) .bind(auto_merge_local) - .bind(red_team_enabled) - .bind(&req.red_team_prompt) .bind(phase_config_json) .fetch_one(pool) .await @@ -2523,7 +2512,7 @@ pub async fn list_contracts_for_owner( r#" SELECT c.id, c.name, c.description, c.contract_type, c.phase, c.status, - c.supervisor_task_id, c.local_only, c.auto_merge_local, c.red_team_enabled, c.version, c.created_at, + c.supervisor_task_id, c.local_only, c.auto_merge_local, c.version, c.created_at, (SELECT COUNT(*) FROM files WHERE contract_id = c.id) as file_count, (SELECT COUNT(*) FROM tasks WHERE contract_id = c.id) as task_count, (SELECT COUNT(*) FROM contract_repositories WHERE contract_id = c.id) as repository_count @@ -2547,7 +2536,7 @@ pub async fn get_contract_summary_for_owner( r#" SELECT c.id, c.name, c.description, c.contract_type, c.phase, c.status, - c.supervisor_task_id, c.local_only, c.auto_merge_local, c.red_team_enabled, c.version, c.created_at, + c.supervisor_task_id, c.local_only, c.auto_merge_local, c.version, c.created_at, (SELECT COUNT(*) FROM files WHERE contract_id = c.id) as file_count, (SELECT COUNT(*) FROM tasks WHERE contract_id = c.id) as task_count, (SELECT COUNT(*) FROM contract_repositories WHERE contract_id = c.id) as repository_count @@ -3118,8 +3107,7 @@ pub async fn list_tasks_in_contract( t.parent_task_id, t.depth, t.name, t.status, t.priority, t.progress_summary, (SELECT COUNT(*) FROM tasks WHERE parent_task_id = t.id) as subtask_count, - t.version, t.is_supervisor, COALESCE(t.is_red_team, false) as is_red_team, - COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at + t.version, t.is_supervisor, COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at FROM tasks t LEFT JOIN contracts c ON t.contract_id = c.id WHERE t.contract_id = $1 AND t.owner_id = $2 @@ -4774,93 +4762,6 @@ pub async fn delete_checkpoint_patches_for_task( // ============================================================================= // Red Team Notifications // ============================================================================= - -/// Create a red team notification. -/// Red team tasks use this to report issues found during implementation review. -pub async fn create_red_team_notification( - pool: &PgPool, - contract_id: Uuid, - red_team_task_id: Uuid, - message: &str, - severity: &str, - related_task_id: Option, - file_path: Option<&str>, - context: Option<&str>, -) -> Result { - sqlx::query_as::<_, RedTeamNotification>( - r#" - INSERT INTO red_team_notifications - (contract_id, red_team_task_id, related_task_id, message, severity, file_path, context) - VALUES ($1, $2, $3, $4, $5, $6, $7) - RETURNING * - "#, - ) - .bind(contract_id) - .bind(red_team_task_id) - .bind(related_task_id) - .bind(message) - .bind(severity) - .bind(file_path) - .bind(context) - .fetch_one(pool) - .await - .map_err(RepositoryError::Database) -} - -/// Mark a notification as delivered to the supervisor. -pub async fn mark_notification_delivered( - pool: &PgPool, - notification_id: Uuid, -) -> Result { - sqlx::query_as::<_, RedTeamNotification>( - r#" - UPDATE red_team_notifications - SET delivered = TRUE, delivered_at = NOW() - WHERE id = $1 - RETURNING * - "#, - ) - .bind(notification_id) - .fetch_one(pool) - .await - .map_err(RepositoryError::Database) -} - -/// Get the red team task for a contract (if one exists). -/// Returns the most recently created red team task for the contract. -pub async fn get_red_team_task_for_contract( - pool: &PgPool, - contract_id: Uuid, -) -> Result, RepositoryError> { - sqlx::query_as::<_, Task>( - r#" - SELECT * FROM tasks - WHERE contract_id = $1 AND is_red_team = TRUE - ORDER BY created_at DESC - LIMIT 1 - "#, - ) - .bind(contract_id) - .fetch_optional(pool) - .await - .map_err(RepositoryError::Database) -} - -/// Get the count of notifications for a red team task. -pub async fn get_notification_count_for_task( - pool: &PgPool, - red_team_task_id: Uuid, -) -> Result { - let result: (i64,) = sqlx::query_as( - "SELECT COUNT(*) FROM red_team_notifications WHERE red_team_task_id = $1", - ) - .bind(red_team_task_id) - .fetch_one(pool) - .await - .map_err(RepositoryError::Database)?; - Ok(result.0) -} - // ============================================================================= // Supervisor Status API Helpers // ============================================================================= -- cgit v1.2.3