From 9e9f18884c78c21f5785908fb7ccd00e2fa5436b Mon Sep 17 00:00:00 2001 From: soryu Date: Sat, 7 Feb 2026 01:11:26 +0000 Subject: Add new directive initial implementation --- makima/src/db/models.rs | 234 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) (limited to 'makima/src/db/models.rs') diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index 3b10cb5..ec4ee15 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -2690,3 +2690,237 @@ mod tests { assert_eq!(deserialized.progress, 50); } } + +// ============================================================================= +// Directive Types +// ============================================================================= + +/// Default autonomy level for directives +fn default_autonomy_level() -> String { + "guardrails".to_string() +} + +/// Default empty JSON array +fn default_json_array() -> serde_json::Value { + serde_json::json!([]) +} + +/// Default empty JSON object +fn default_json_object() -> serde_json::Value { + serde_json::json!({}) +} + +/// Default confidence threshold (green) +fn default_confidence_green() -> f64 { + 0.85 +} + +/// Default confidence threshold (yellow) +fn default_confidence_yellow() -> f64 { + 0.60 +} + +/// Default max rework cycles +fn default_max_rework_cycles() -> Option { + Some(3) +} + +/// Default max chain regenerations +fn default_max_chain_regenerations() -> Option { + Some(2) +} + +/// Full directive row from the database. +#[derive(Debug, Clone, FromRow, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct Directive { + pub id: Uuid, + pub owner_id: Uuid, + pub title: String, + pub goal: String, + #[sqlx(json)] + pub requirements: serde_json::Value, + #[sqlx(json)] + pub acceptance_criteria: serde_json::Value, + #[sqlx(json)] + pub constraints: serde_json::Value, + #[sqlx(json)] + pub external_dependencies: serde_json::Value, + pub status: String, + pub autonomy_level: String, + pub confidence_threshold_green: f64, + pub confidence_threshold_yellow: f64, + pub max_total_cost_usd: Option, + pub max_wall_time_minutes: Option, + pub max_rework_cycles: Option, + pub max_chain_regenerations: Option, + pub repository_url: Option, + pub local_path: Option, + pub base_branch: Option, + pub orchestrator_contract_id: Option, + pub current_chain_id: Option, + pub chain_generation_count: i32, + pub total_cost_usd: f64, + pub started_at: Option>, + pub completed_at: Option>, + pub version: i32, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// Summary of a directive for list views. +#[derive(Debug, Clone, FromRow, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct DirectiveSummary { + pub id: Uuid, + pub title: String, + pub goal: String, + pub status: String, + pub autonomy_level: String, + pub chain_count: i64, + pub step_count: i64, + pub total_cost_usd: f64, + pub version: i32, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// Response for directive list endpoint. +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct DirectiveListResponse { + pub directives: Vec, + pub total: i64, +} + +/// Request to create a new directive. +#[derive(Debug, Clone, Deserialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct CreateDirectiveRequest { + pub title: String, + pub goal: String, + #[serde(default = "default_json_array")] + pub requirements: serde_json::Value, + #[serde(default = "default_json_array")] + pub acceptance_criteria: serde_json::Value, + #[serde(default = "default_json_array")] + pub constraints: serde_json::Value, + #[serde(default = "default_json_array")] + pub external_dependencies: serde_json::Value, + #[serde(default = "default_autonomy_level")] + pub autonomy_level: String, + #[serde(default = "default_confidence_green")] + pub confidence_threshold_green: f64, + #[serde(default = "default_confidence_yellow")] + pub confidence_threshold_yellow: f64, + pub max_total_cost_usd: Option, + pub max_wall_time_minutes: Option, + #[serde(default = "default_max_rework_cycles")] + pub max_rework_cycles: Option, + #[serde(default = "default_max_chain_regenerations")] + pub max_chain_regenerations: Option, + pub repository_url: Option, + pub local_path: Option, + pub base_branch: Option, +} + +/// Request to update an existing directive. +#[derive(Debug, Clone, Deserialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct UpdateDirectiveRequest { + pub title: Option, + pub goal: Option, + pub requirements: Option, + pub acceptance_criteria: Option, + pub constraints: Option, + pub external_dependencies: Option, + pub status: Option, + pub autonomy_level: Option, + pub confidence_threshold_green: Option, + pub confidence_threshold_yellow: Option, + pub max_total_cost_usd: Option, + pub max_wall_time_minutes: Option, + pub max_rework_cycles: Option, + pub max_chain_regenerations: Option, + pub repository_url: Option, + pub local_path: Option, + pub base_branch: Option, + /// Version for optimistic locking + pub version: Option, +} + +/// Directive with its chains for detail view. +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct DirectiveWithChains { + #[serde(flatten)] + pub directive: Directive, + pub chains: Vec, +} + +/// Full row from directive_chains table. +#[derive(Debug, Clone, FromRow, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct DirectiveChain { + pub id: Uuid, + pub directive_id: Uuid, + pub generation: i32, + pub name: String, + pub description: Option, + pub rationale: Option, + pub planning_model: Option, + pub status: String, + pub total_steps: i32, + pub completed_steps: i32, + pub failed_steps: i32, + pub current_confidence: Option, + pub started_at: Option>, + pub completed_at: Option>, + pub version: i32, + pub created_at: DateTime, + pub updated_at: DateTime, +} + +/// Full row from chain_steps table. +#[derive(Debug, Clone, FromRow, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct ChainStep { + pub id: Uuid, + pub chain_id: Uuid, + pub name: String, + pub description: Option, + pub step_type: String, + pub contract_type: String, + pub initial_phase: Option, + pub task_plan: Option, + pub phases: Option>, + pub depends_on: Option>, + pub parallel_group: Option, + pub requirement_ids: Option>, + pub acceptance_criteria_ids: Option>, + #[sqlx(json)] + pub verifier_config: serde_json::Value, + pub status: String, + pub contract_id: Option, + pub supervisor_task_id: Option, + pub confidence_score: Option, + pub confidence_level: Option, + pub evaluation_count: i32, + pub rework_count: i32, + pub last_evaluation_id: Option, + pub editor_x: Option, + pub editor_y: Option, + pub order_index: i32, + pub started_at: Option>, + pub completed_at: Option>, + pub created_at: DateTime, +} + +/// Chain with its steps for detail view. +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct ChainWithSteps { + #[serde(flatten)] + pub chain: DirectiveChain, + pub steps: Vec, +} -- cgit v1.2.3