diff options
Diffstat (limited to 'makima/src/db/models.rs')
| -rw-r--r-- | makima/src/db/models.rs | 234 |
1 files changed, 234 insertions, 0 deletions
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<i32> { + Some(3) +} + +/// Default max chain regenerations +fn default_max_chain_regenerations() -> Option<i32> { + 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<f64>, + pub max_wall_time_minutes: Option<i32>, + pub max_rework_cycles: Option<i32>, + pub max_chain_regenerations: Option<i32>, + pub repository_url: Option<String>, + pub local_path: Option<String>, + pub base_branch: Option<String>, + pub orchestrator_contract_id: Option<Uuid>, + pub current_chain_id: Option<Uuid>, + pub chain_generation_count: i32, + pub total_cost_usd: f64, + pub started_at: Option<DateTime<Utc>>, + pub completed_at: Option<DateTime<Utc>>, + pub version: i32, + pub created_at: DateTime<Utc>, + pub updated_at: DateTime<Utc>, +} + +/// 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<Utc>, + pub updated_at: DateTime<Utc>, +} + +/// Response for directive list endpoint. +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct DirectiveListResponse { + pub directives: Vec<DirectiveSummary>, + 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<f64>, + pub max_wall_time_minutes: Option<i32>, + #[serde(default = "default_max_rework_cycles")] + pub max_rework_cycles: Option<i32>, + #[serde(default = "default_max_chain_regenerations")] + pub max_chain_regenerations: Option<i32>, + pub repository_url: Option<String>, + pub local_path: Option<String>, + pub base_branch: Option<String>, +} + +/// Request to update an existing directive. +#[derive(Debug, Clone, Deserialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct UpdateDirectiveRequest { + pub title: Option<String>, + pub goal: Option<String>, + pub requirements: Option<serde_json::Value>, + pub acceptance_criteria: Option<serde_json::Value>, + pub constraints: Option<serde_json::Value>, + pub external_dependencies: Option<serde_json::Value>, + pub status: Option<String>, + pub autonomy_level: Option<String>, + pub confidence_threshold_green: Option<f64>, + pub confidence_threshold_yellow: Option<f64>, + pub max_total_cost_usd: Option<f64>, + pub max_wall_time_minutes: Option<i32>, + pub max_rework_cycles: Option<i32>, + pub max_chain_regenerations: Option<i32>, + pub repository_url: Option<String>, + pub local_path: Option<String>, + pub base_branch: Option<String>, + /// Version for optimistic locking + pub version: Option<i32>, +} + +/// 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<DirectiveChain>, +} + +/// 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<String>, + pub rationale: Option<String>, + pub planning_model: Option<String>, + pub status: String, + pub total_steps: i32, + pub completed_steps: i32, + pub failed_steps: i32, + pub current_confidence: Option<f64>, + pub started_at: Option<DateTime<Utc>>, + pub completed_at: Option<DateTime<Utc>>, + pub version: i32, + pub created_at: DateTime<Utc>, + pub updated_at: DateTime<Utc>, +} + +/// 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<String>, + pub step_type: String, + pub contract_type: String, + pub initial_phase: Option<String>, + pub task_plan: Option<String>, + pub phases: Option<Vec<String>>, + pub depends_on: Option<Vec<Uuid>>, + pub parallel_group: Option<String>, + pub requirement_ids: Option<Vec<String>>, + pub acceptance_criteria_ids: Option<Vec<String>>, + #[sqlx(json)] + pub verifier_config: serde_json::Value, + pub status: String, + pub contract_id: Option<Uuid>, + pub supervisor_task_id: Option<Uuid>, + pub confidence_score: Option<f64>, + pub confidence_level: Option<String>, + pub evaluation_count: i32, + pub rework_count: i32, + pub last_evaluation_id: Option<Uuid>, + pub editor_x: Option<f64>, + pub editor_y: Option<f64>, + pub order_index: i32, + pub started_at: Option<DateTime<Utc>>, + pub completed_at: Option<DateTime<Utc>>, + pub created_at: DateTime<Utc>, +} + +/// 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<ChainStep>, +} |
