From 8c23b3ab6f7fabca01b0468911bae073aa5ced32 Mon Sep 17 00:00:00 2001 From: soryu Date: Mon, 9 Feb 2026 00:11:51 +0000 Subject: Add new directive mechanism v3 --- makima/src/daemon/api/directive.rs | 124 +++++++++++++++++++++++++++++++++++++ makima/src/daemon/api/mod.rs | 1 + 2 files changed, 125 insertions(+) create mode 100644 makima/src/daemon/api/directive.rs (limited to 'makima/src/daemon/api') diff --git a/makima/src/daemon/api/directive.rs b/makima/src/daemon/api/directive.rs new file mode 100644 index 0000000..fbd27fe --- /dev/null +++ b/makima/src/daemon/api/directive.rs @@ -0,0 +1,124 @@ +//! Directive API methods. + +use serde::Serialize; +use uuid::Uuid; + +use super::client::{ApiClient, ApiError}; +use super::supervisor::JsonValue; + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CreateStepRequest { + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub task_plan: Option, + pub depends_on: Vec, + pub order_index: i32, +} + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateGoalRequest { + pub goal: String, +} + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateStepDepsRequest { + pub depends_on: Vec, +} + +impl ApiClient { + /// List all directives. + pub async fn list_directives(&self) -> Result { + self.get("/api/v1/directives").await + } + + /// Get a directive with its steps. + pub async fn get_directive(&self, directive_id: Uuid) -> Result { + self.get(&format!("/api/v1/directives/{}", directive_id)).await + } + + /// Add a step to a directive. + pub async fn directive_add_step( + &self, + directive_id: Uuid, + req: CreateStepRequest, + ) -> Result { + self.post(&format!("/api/v1/directives/{}/steps", directive_id), &req).await + } + + /// Remove a step from a directive. + pub async fn directive_remove_step( + &self, + directive_id: Uuid, + step_id: Uuid, + ) -> Result<(), ApiError> { + self.delete(&format!("/api/v1/directives/{}/steps/{}", directive_id, step_id)).await + } + + /// Set dependencies for a step. + pub async fn directive_set_deps( + &self, + directive_id: Uuid, + step_id: Uuid, + depends_on: Vec, + ) -> Result { + let req = UpdateStepDepsRequest { depends_on }; + self.put(&format!("/api/v1/directives/{}/steps/{}", directive_id, step_id), &req).await + } + + /// Start a directive. + pub async fn directive_start(&self, directive_id: Uuid) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/start", directive_id)).await + } + + /// Pause a directive. + pub async fn directive_pause(&self, directive_id: Uuid) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/pause", directive_id)).await + } + + /// Advance the directive DAG. + pub async fn directive_advance(&self, directive_id: Uuid) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/advance", directive_id)).await + } + + /// Mark a step as completed. + pub async fn directive_complete_step( + &self, + directive_id: Uuid, + step_id: Uuid, + ) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/steps/{}/complete", directive_id, step_id)).await + } + + /// Mark a step as failed. + pub async fn directive_fail_step( + &self, + directive_id: Uuid, + step_id: Uuid, + ) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/steps/{}/fail", directive_id, step_id)).await + } + + /// Mark a step as skipped. + pub async fn directive_skip_step( + &self, + directive_id: Uuid, + step_id: Uuid, + ) -> Result { + self.post_empty(&format!("/api/v1/directives/{}/steps/{}/skip", directive_id, step_id)).await + } + + /// Update the directive's goal. + pub async fn directive_update_goal( + &self, + directive_id: Uuid, + goal: &str, + ) -> Result { + let req = UpdateGoalRequest { goal: goal.to_string() }; + self.put(&format!("/api/v1/directives/{}/goal", directive_id), &req).await + } +} diff --git a/makima/src/daemon/api/mod.rs b/makima/src/daemon/api/mod.rs index 49d80e0..2d1efbf 100644 --- a/makima/src/daemon/api/mod.rs +++ b/makima/src/daemon/api/mod.rs @@ -2,6 +2,7 @@ pub mod client; pub mod contract; +pub mod directive; pub mod supervisor; pub use client::ApiClient; -- cgit v1.2.3