diff options
Diffstat (limited to 'makima/src/db/models.rs')
| -rw-r--r-- | makima/src/db/models.rs | 666 |
1 files changed, 0 insertions, 666 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs index f951751..3b10cb5 100644 --- a/makima/src/db/models.rs +++ b/makima/src/db/models.rs @@ -2596,672 +2596,6 @@ pub struct HeartbeatHistoryQuery { } // ============================================================================= -// Directives (Goal-driven orchestration with chains of steps) -// ============================================================================= - -/// Directive status -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "snake_case")] -pub enum DirectiveStatus { - Draft, - Planning, - Active, - Paused, - Completed, - Archived, - Failed, -} - -impl Default for DirectiveStatus { - fn default() -> Self { - DirectiveStatus::Draft - } -} - -impl std::fmt::Display for DirectiveStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - DirectiveStatus::Draft => write!(f, "draft"), - DirectiveStatus::Planning => write!(f, "planning"), - DirectiveStatus::Active => write!(f, "active"), - DirectiveStatus::Paused => write!(f, "paused"), - DirectiveStatus::Completed => write!(f, "completed"), - DirectiveStatus::Archived => write!(f, "archived"), - DirectiveStatus::Failed => write!(f, "failed"), - } - } -} - -impl std::str::FromStr for DirectiveStatus { - type Err = String; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - match s.to_lowercase().as_str() { - "draft" => Ok(DirectiveStatus::Draft), - "planning" => Ok(DirectiveStatus::Planning), - "active" => Ok(DirectiveStatus::Active), - "paused" => Ok(DirectiveStatus::Paused), - "completed" => Ok(DirectiveStatus::Completed), - "archived" => Ok(DirectiveStatus::Archived), - "failed" => Ok(DirectiveStatus::Failed), - _ => Err(format!("Invalid directive status: {}", s)), - } - } -} - -/// Directive - the top-level goal-driven orchestration entity -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct Directive { - pub id: Uuid, - pub owner_id: Uuid, - pub title: String, - pub goal: String, - /// Structured requirements: [{ id, title, description, priority, category }] - #[sqlx(json)] - pub requirements: serde_json::Value, - /// Acceptance criteria: [{ id, requirementIds, description, testable, verificationMethod }] - #[sqlx(json)] - pub acceptance_criteria: serde_json::Value, - /// Constraints: [{ id, type, description, impact }] - #[sqlx(json)] - pub constraints: serde_json::Value, - /// External dependencies: [{ id, name, type, status, requiredBy }] - #[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>, -} - -impl Directive { - /// Parse status string to DirectiveStatus enum - pub fn status_enum(&self) -> Result<DirectiveStatus, String> { - self.status.parse() - } -} - -/// Directive chain - a generated execution plan (DAG) for a directive -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, 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>, -} - -/// Chain step status -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "snake_case")] -pub enum StepStatus { - Pending, - Ready, - Running, - Evaluating, - Passed, - Failed, - Rework, - Skipped, - Blocked, -} - -impl Default for StepStatus { - fn default() -> Self { - StepStatus::Pending - } -} - -impl std::fmt::Display for StepStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - StepStatus::Pending => write!(f, "pending"), - StepStatus::Ready => write!(f, "ready"), - StepStatus::Running => write!(f, "running"), - StepStatus::Evaluating => write!(f, "evaluating"), - StepStatus::Passed => write!(f, "passed"), - StepStatus::Failed => write!(f, "failed"), - StepStatus::Rework => write!(f, "rework"), - StepStatus::Skipped => write!(f, "skipped"), - StepStatus::Blocked => write!(f, "blocked"), - } - } -} - -impl std::str::FromStr for StepStatus { - type Err = String; - fn from_str(s: &str) -> Result<Self, Self::Err> { - match s.to_lowercase().as_str() { - "pending" => Ok(StepStatus::Pending), - "ready" => Ok(StepStatus::Ready), - "running" => Ok(StepStatus::Running), - "evaluating" => Ok(StepStatus::Evaluating), - "passed" => Ok(StepStatus::Passed), - "failed" => Ok(StepStatus::Failed), - "rework" => Ok(StepStatus::Rework), - "skipped" => Ok(StepStatus::Skipped), - "blocked" => Ok(StepStatus::Blocked), - _ => Err(format!("Invalid step status: {}", s)), - } - } -} - -/// Chain step - a node in the DAG execution plan -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, 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>, - #[sqlx(default)] - pub phases: Vec<String>, - #[sqlx(default)] - pub depends_on: Vec<Uuid>, - pub parallel_group: Option<String>, - #[sqlx(default)] - pub requirement_ids: Vec<String>, - #[sqlx(default)] - pub acceptance_criteria_ids: Vec<String>, - #[sqlx(json)] - #[serde(default)] - 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>, -} - -impl ChainStep { - /// Parse status string to StepStatus enum - pub fn status_enum(&self) -> Result<StepStatus, String> { - self.status.parse() - } -} - -/// Confidence level (traffic light) -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "snake_case")] -pub enum ConfidenceLevel { - Green, - Yellow, - Red, -} - -impl ConfidenceLevel { - pub fn from_score(score: f64, green_threshold: f64, yellow_threshold: f64) -> Self { - if score >= green_threshold { - Self::Green - } else if score >= yellow_threshold { - Self::Yellow - } else { - Self::Red - } - } -} - -impl std::fmt::Display for ConfidenceLevel { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ConfidenceLevel::Green => write!(f, "green"), - ConfidenceLevel::Yellow => write!(f, "yellow"), - ConfidenceLevel::Red => write!(f, "red"), - } - } -} - -/// Directive evaluation - composite programmatic + LLM evaluation result -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveEvaluation { - pub id: Uuid, - pub directive_id: Uuid, - pub chain_id: Option<Uuid>, - pub step_id: Option<Uuid>, - pub contract_id: Option<Uuid>, - pub evaluation_type: String, - pub evaluation_number: i32, - pub evaluator: Option<String>, - pub passed: bool, - pub overall_score: Option<f64>, - pub confidence_level: Option<String>, - #[sqlx(json)] - #[serde(default)] - pub programmatic_results: serde_json::Value, - #[sqlx(json)] - #[serde(default)] - pub llm_results: serde_json::Value, - #[sqlx(json)] - #[serde(default)] - pub criteria_results: serde_json::Value, - pub summary_feedback: String, - pub rework_instructions: Option<String>, - #[sqlx(json)] - pub directive_snapshot: Option<serde_json::Value>, - #[sqlx(json)] - pub deliverables_snapshot: Option<serde_json::Value>, - pub started_at: DateTime<Utc>, - pub completed_at: Option<DateTime<Utc>>, - pub created_at: DateTime<Utc>, -} - -/// Directive event - audit stream entry -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveEvent { - pub id: Uuid, - pub directive_id: Uuid, - pub chain_id: Option<Uuid>, - pub step_id: Option<Uuid>, - pub event_type: String, - pub severity: String, - #[sqlx(json)] - pub event_data: Option<serde_json::Value>, - pub actor_type: String, - pub actor_id: Option<Uuid>, - pub created_at: DateTime<Utc>, -} - -/// Directive verifier - pluggable verification configuration -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveVerifier { - pub id: Uuid, - pub directive_id: Uuid, - pub name: String, - pub verifier_type: String, - pub command: Option<String>, - pub working_directory: Option<String>, - pub timeout_seconds: Option<i32>, - #[sqlx(json)] - #[serde(default)] - pub environment: serde_json::Value, - pub auto_detect: bool, - #[sqlx(default)] - pub detect_files: Vec<String>, - pub weight: f64, - pub required: bool, - pub enabled: bool, - pub last_run_at: Option<DateTime<Utc>>, - #[sqlx(json)] - pub last_result: Option<serde_json::Value>, - pub created_at: DateTime<Utc>, - pub updated_at: DateTime<Utc>, -} - -/// Directive approval - human-in-the-loop gate -#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveApproval { - pub id: Uuid, - pub directive_id: Uuid, - pub step_id: Option<Uuid>, - pub approval_type: String, - pub description: String, - #[sqlx(json)] - pub context: Option<serde_json::Value>, - pub urgency: String, - pub status: String, - pub response: Option<String>, - pub responded_by: Option<Uuid>, - pub responded_at: Option<DateTime<Utc>>, - pub expires_at: Option<DateTime<Utc>>, - pub created_at: DateTime<Utc>, -} - -// ============================================================================= -// Directive Request/Response Types -// ============================================================================= - -/// Request to create a directive from a goal -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct CreateDirectiveRequest { - pub goal: String, - pub title: Option<String>, - pub repository_url: Option<String>, - pub local_path: Option<String>, - pub base_branch: Option<String>, - pub autonomy_level: Option<String>, - pub requirements: Option<serde_json::Value>, - pub acceptance_criteria: Option<serde_json::Value>, - 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>, -} - -/// Request to update a directive -#[derive(Debug, 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 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 version: i32, -} - -/// Directive summary for list views -#[derive(Debug, Clone, Serialize, FromRow, 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 current_confidence: Option<f64>, - pub completed_steps: i32, - pub total_steps: i32, - pub chain_generation_count: i32, - pub started_at: Option<DateTime<Utc>>, - pub created_at: DateTime<Utc>, -} - -/// Directive with progress, chain, events, and approvals -#[derive(Debug, Serialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveWithProgress { - #[serde(flatten)] - pub directive: Directive, - pub chain: Option<DirectiveChain>, - pub steps: Vec<ChainStep>, - pub recent_events: Vec<DirectiveEvent>, - pub pending_approvals: Vec<DirectiveApproval>, -} - -/// Request to add a step to a chain -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct AddStepRequest { - pub name: String, - pub description: Option<String>, - pub step_type: Option<String>, - pub contract_type: Option<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>>, - pub verifier_config: Option<serde_json::Value>, - pub editor_x: Option<f64>, - pub editor_y: Option<f64>, -} - -/// Request to update a step -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct UpdateStepRequest { - pub name: Option<String>, - pub description: Option<String>, - pub task_plan: Option<String>, - pub depends_on: Option<Vec<Uuid>>, - pub requirement_ids: Option<Vec<String>>, - pub acceptance_criteria_ids: Option<Vec<String>>, - pub verifier_config: Option<serde_json::Value>, - pub editor_x: Option<f64>, - pub editor_y: Option<f64>, -} - -/// Chain graph response for DAG visualization -#[derive(Debug, Serialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveChainGraphResponse { - pub chain_id: Uuid, - pub directive_id: Uuid, - pub nodes: Vec<DirectiveChainGraphNode>, - pub edges: Vec<DirectiveChainGraphEdge>, -} - -/// Node in directive chain graph -#[derive(Debug, Serialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveChainGraphNode { - pub id: Uuid, - pub name: String, - pub step_type: String, - pub status: String, - pub confidence_score: Option<f64>, - pub confidence_level: Option<String>, - pub contract_id: Option<Uuid>, - pub editor_x: Option<f64>, - pub editor_y: Option<f64>, -} - -/// Edge in directive chain graph -#[derive(Debug, Serialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveChainGraphEdge { - pub source: Uuid, - pub target: Uuid, -} - -/// Start directive response -#[derive(Debug, Serialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct StartDirectiveResponse { - pub directive_id: Uuid, - pub chain_id: Uuid, - pub chain_generation: i32, - pub steps: Vec<ChainStep>, - pub status: String, -} - -/// Request to create a verifier -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct CreateVerifierRequest { - pub name: String, - pub verifier_type: String, - pub command: Option<String>, - pub working_directory: Option<String>, - pub timeout_seconds: Option<i32>, - pub environment: Option<serde_json::Value>, - pub weight: Option<f64>, - pub required: Option<bool>, -} - -/// Request to update a verifier -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct UpdateVerifierRequest { - pub name: Option<String>, - pub command: Option<String>, - pub working_directory: Option<String>, - pub timeout_seconds: Option<i32>, - pub weight: Option<f64>, - pub required: Option<bool>, - pub enabled: Option<bool>, -} - -/// Approval action request -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct ApprovalActionRequest { - pub response: Option<String>, -} - -/// Request to update directive requirements -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct UpdateRequirementsRequest { - pub requirements: Vec<DirectiveRequirement>, -} - -/// Request to update directive acceptance criteria -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct UpdateCriteriaRequest { - pub acceptance_criteria: Vec<DirectiveAcceptanceCriterion>, -} - -/// Request to trigger step rework -#[derive(Debug, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct ReworkStepRequest { - pub instructions: Option<String>, -} - -/// Directive requirement (shared type used in directive specification) -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveRequirement { - pub id: String, - pub title: String, - pub description: String, - pub priority: String, - pub category: Option<String>, - #[serde(skip_serializing_if = "Option::is_none")] - pub parent_id: Option<String>, -} - -/// Directive acceptance criterion -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -#[serde(rename_all = "camelCase")] -pub struct DirectiveAcceptanceCriterion { - pub id: String, - #[serde(default)] - pub requirement_ids: Vec<String>, - pub description: String, - #[serde(default = "default_true")] - pub testable: bool, - pub verification_method: Option<String>, -} - -fn default_true() -> bool { - true -} - -// Old chain types (Chain, ChainContract, ChainContractDefinition, ChainDirective, -// ContractEvaluation, ChainEvent, ChainRepository, etc.) have been replaced by -// the directive system above: Directive, DirectiveChain, ChainStep, -// DirectiveEvaluation, DirectiveEvent, DirectiveVerifier, DirectiveApproval. - -// Legacy types kept temporarily for chain runner/parser compatibility during migration. -// These will be removed once the chain daemon module is replaced. - -/// Request payload for creating a new chain (legacy - used by chain runner) -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateChainRequest { - pub name: String, - pub description: Option<String>, - pub repository_url: Option<String>, - pub repositories: Option<Vec<AddChainRepositoryRequest>>, - pub loop_enabled: Option<bool>, - pub loop_max_iterations: Option<i32>, - pub loop_progress_check: Option<String>, - pub contracts: Option<Vec<CreateChainContractRequest>>, -} - -/// Request to add a repository to a chain (legacy - used by chain runner) -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct AddChainRepositoryRequest { - pub name: String, - pub repository_url: Option<String>, - pub local_path: Option<String>, - #[serde(default = "default_source_type")] - pub source_type: String, - #[serde(default)] - pub is_primary: bool, -} - -fn default_source_type() -> String { - "remote".to_string() -} - -/// Request to create a contract within a chain (legacy - used by chain runner) -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateChainContractRequest { - pub name: String, - pub description: Option<String>, - #[serde(default)] - pub contract_type: Option<String>, - pub initial_phase: Option<String>, - pub phases: Option<Vec<String>>, - pub depends_on: Option<Vec<String>>, - pub tasks: Option<Vec<CreateChainTaskRequest>>, - pub deliverables: Option<Vec<CreateChainDeliverableRequest>>, - pub editor_x: Option<f64>, - pub editor_y: Option<f64>, -} - -/// Task definition within a chain contract (legacy - used by chain runner) -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateChainTaskRequest { - pub name: String, - pub plan: String, -} - -/// Deliverable definition within a chain contract (legacy - used by chain runner) -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateChainDeliverableRequest { - pub id: String, - pub name: String, - pub priority: Option<String>, -} - -// ============================================================================= // Unit Tests // ============================================================================= |
