diff options
| author | soryu <soryu@soryu.co> | 2026-03-02 15:18:31 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-02 15:18:31 +0000 |
| commit | 78cb861412850889424ae7d5ae5cd952a2b90295 (patch) | |
| tree | 7a6eb0693457886dbe0eea84c0c1489724791f79 /makima/src/db | |
| parent | 2bc1cd4717b587cd2b8ffccd723b62f888e61aa8 (diff) | |
| download | soryu-78cb861412850889424ae7d5ae5cd952a2b90295.tar.gz soryu-78cb861412850889424ae7d5ae5cd952a2b90295.zip | |
feat: move daemon reauth to daemons page, add contract-backed directive steps, rename Mesh to Exec (#84)
* feat: soryu-co/soryu - makima: Rename Mesh to Exec in navigation
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* feat: soryu-co/soryu - makima: Add contract-backed steps to directive flow
* WIP: heartbeat checkpoint
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/models.rs | 9 | ||||
| -rw-r--r-- | makima/src/db/repository.rs | 63 |
2 files changed, 70 insertions, 2 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 6b77563..6292e7b 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -2746,6 +2746,11 @@ pub struct DirectiveStep { /// Status: pending, ready, running, completed, failed, skipped pub status: String, pub task_id: Option<Uuid>, + /// Optional contract ID for contract-backed execution. + pub contract_id: Option<Uuid>, + /// Optional contract type (e.g. "simple", "specification", "execute"). + /// When set, the orchestrator creates a contract instead of a standalone task. + pub contract_type: Option<String>, pub order_index: i32, pub generation: i32, pub started_at: Option<DateTime<Utc>>, @@ -2871,6 +2876,10 @@ pub struct CreateDirectiveStepRequest { /// Optional order ID to auto-link this step to an order. #[serde(default)] pub order_id: Option<Uuid>, + /// Optional: create a contract for this step instead of a standalone task. + /// Valid values: "simple", "specification", "execute" + #[serde(default)] + pub contract_type: Option<String>, } /// Request to update a directive step. diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 8d7a70c..1af22f6 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -5402,10 +5402,11 @@ pub async fn create_directive_step( ) -> Result<DirectiveStep, sqlx::Error> { let generation = req.generation.unwrap_or(1); let order_id = req.order_id; + let contract_type = req.contract_type.clone(); let step = sqlx::query_as::<_, DirectiveStep>( r#" - INSERT INTO directive_steps (directive_id, name, description, task_plan, depends_on, order_index, generation) - VALUES ($1, $2, $3, $4, $5, $6, $7) + INSERT INTO directive_steps (directive_id, name, description, task_plan, depends_on, order_index, generation, contract_type) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING * "#, ) @@ -5416,6 +5417,7 @@ pub async fn create_directive_step( .bind(&req.depends_on) .bind(req.order_index) .bind(generation) + .bind(&contract_type) .fetch_one(pool) .await?; @@ -5727,6 +5729,8 @@ pub struct StepForDispatch { pub order_index: i32, pub generation: i32, pub depends_on: Vec<Uuid>, + /// Optional contract type — when set, orchestrator creates a contract instead of a task. + pub contract_type: Option<String>, // Directive fields pub owner_id: Uuid, pub directive_title: String, @@ -5751,6 +5755,7 @@ pub async fn get_ready_steps_for_dispatch( ds.order_index, ds.generation, ds.depends_on, + ds.contract_type, d.owner_id, d.title AS directive_title, d.repository_url, @@ -5760,6 +5765,7 @@ pub async fn get_ready_steps_for_dispatch( JOIN directives d ON d.id = ds.directive_id WHERE ds.status = 'ready' AND ds.task_id IS NULL + AND ds.contract_id IS NULL AND d.status = 'active' ORDER BY ds.order_index "#, @@ -5831,6 +5837,39 @@ pub async fn get_running_steps_with_tasks( JOIN tasks t ON t.id = ds.task_id WHERE ds.status = 'running' AND ds.task_id IS NOT NULL + AND ds.contract_id IS NULL + "#, + ) + .fetch_all(pool) + .await +} + +/// A running step backed by a contract, joined with the contract's current status. +#[derive(Debug, Clone, sqlx::FromRow)] +pub struct RunningStepWithContract { + pub step_id: Uuid, + pub directive_id: Uuid, + pub contract_id: Uuid, + pub contract_status: String, + pub contract_phase: String, +} + +/// Get running steps that are backed by contracts (for contract-based monitoring). +pub async fn get_running_steps_with_contracts( + pool: &PgPool, +) -> Result<Vec<RunningStepWithContract>, sqlx::Error> { + sqlx::query_as::<_, RunningStepWithContract>( + r#" + SELECT + ds.id AS step_id, + ds.directive_id, + ds.contract_id AS "contract_id!", + c.status AS contract_status, + c.phase AS contract_phase + FROM directive_steps ds + JOIN contracts c ON c.id = ds.contract_id + WHERE ds.status = 'running' + AND ds.contract_id IS NOT NULL "#, ) .fetch_all(pool) @@ -5995,6 +6034,26 @@ pub async fn link_task_to_step( Ok(()) } +/// Link a contract to a directive step. +pub async fn link_contract_to_step( + pool: &PgPool, + step_id: Uuid, + contract_id: Uuid, +) -> Result<(), sqlx::Error> { + sqlx::query( + r#" + UPDATE directive_steps + SET contract_id = $1 + WHERE id = $2 + "#, + ) + .bind(contract_id) + .bind(step_id) + .execute(pool) + .await?; + Ok(()) +} + /// Set a step to 'running' status (after its task has been dispatched). pub async fn set_step_running( pool: &PgPool, |
