From 900472091e4d9b4000508b0d266d786ef41107bd Mon Sep 17 00:00:00 2001 From: soryu Date: Sat, 17 Jan 2026 19:47:35 +0000 Subject: Add phase guard toggle for contract phase confirmation (#2) * Add phase_guard field to Contract model and database This adds a new boolean field to control whether the supervisor should wait for user confirmation before progressing to the next phase. When enabled, users can review and potentially amend phase outputs (like plans, requirements docs) before the contract continues. Changes: - Add migration for phase_guard column (defaults to false) - Add phase_guard to Contract, CreateContractRequest, and UpdateContractRequest structs - Update create_contract_for_owner and update_contract_for_owner repository functions to handle phase_guard - Update all CreateContractRequest instantiations with phase_guard field Co-Authored-By: Claude Opus 4.5 * feat: Add phase_guard for contract phase transitions Implement phase_guard logic in the advance_phase tool. When a contract has phase_guard enabled, the phase transition now: 1. Asks for user confirmation before advancing 2. Allows users to request changes to phase deliverables 3. Passes feedback to the task without advancing if changes requested Changes: - Add phase_guard field to Contract model and CreateContractRequest - Add PhaseTransitionRequest, PhaseFileInfo, PhaseTaskInfo structs - Update ChangePhaseRequest with confirmed and feedback fields - Update ContractToolRequest::AdvancePhase with confirmed/feedback - Modify advance_phase handling in contract_chat.rs with phase_guard logic - Update change_phase endpoint in contracts.rs with phase_guard support - Add database migration for phase_guard column When phase_guard=false: Phase advances immediately (current behavior) When phase_guard=true: Returns pending_confirmation status with deliverables If user provides feedback: Returns feedback to task, doesn't advance Co-Authored-By: Claude Opus 4.5 * feat(frontend): Add UI for phase transition confirmation requests When phase_guard is enabled and a supervisor tries to advance the contract phase, users now see a confirmation modal with: - Current and proposed next phase visualization - Phase deliverables checklist (if available) - Summary of the phase work - Options to "Approve & Advance" or "Request Changes" with feedback Components added: - PhaseConfirmationModal: Full modal dialog for phase confirmations - PhaseConfirmationInline: Inline variant for task output view - PhaseConfirmationNotification: Global notification wrapper - PhaseConfirmationToast: Alternative toast-style notification Integration: - Added phase_confirmation message type to TaskOutput renderer - Extended PendingQuestion API type with phase confirmation data - Integrated notification into main app layout The UI uses the existing supervisor question infrastructure (polling via /api/v1/mesh/questions) and responds with APPROVE or CHANGES_REQUESTED prefixed feedback. Co-Authored-By: Claude Opus 4.5 * feat(frontend): Add Phase Guard toggle to AutopilotPanel Added the phase_guard toggle to the AutopilotPanel component, which allows users to enable/disable requiring confirmation before phase transitions. Changes: - Added phaseGuard and autonomousLoop fields to Contract interface in api.ts - Added phaseGuard field to UpdateContractRequest in api.ts - Added Phase Guard toggle UI in AutopilotPanel with similar styling to master - Toggle shows an 'active' badge when enabled - Connected toggle to contract update API The toggle appears below the autopilot control buttons and allows users to require confirmation before the supervisor advances to the next phase. Co-Authored-By: Claude Opus 4.5 --------- Co-authored-by: Claude Opus 4.5 --- makima/src/llm/contract_tools.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'makima/src/llm/contract_tools.rs') diff --git a/makima/src/llm/contract_tools.rs b/makima/src/llm/contract_tools.rs index 7a3d09a..07de1fe 100644 --- a/makima/src/llm/contract_tools.rs +++ b/makima/src/llm/contract_tools.rs @@ -203,7 +203,7 @@ pub static CONTRACT_TOOLS: once_cell::sync::Lazy> = once_cell::sync::L }, Tool { name: "advance_phase".to_string(), - description: "Advance the contract to the NEXT phase in sequence. Phases progress: research -> specify -> plan -> execute -> review. You can ONLY advance forward one step. Always use suggest_phase_transition first to check readiness and find the correct next phase.".to_string(), + description: "Advance the contract to the NEXT phase in sequence. Phases progress: research -> specify -> plan -> execute -> review. You can ONLY advance forward one step. Always use suggest_phase_transition first to check readiness and find the correct next phase. If the contract has phase_guard enabled, this will first return a pending_confirmation status with phase deliverables for user review. Call again with confirmed=true to complete the transition, or with feedback to request changes.".to_string(), parameters: json!({ "type": "object", "properties": { @@ -211,6 +211,14 @@ pub static CONTRACT_TOOLS: once_cell::sync::Lazy> = once_cell::sync::L "type": "string", "enum": ["specify", "plan", "execute", "review"], "description": "The next phase to transition to. Must be exactly one step ahead of current phase (e.g., research->specify, specify->plan, plan->execute, execute->review)" + }, + "confirmed": { + "type": "boolean", + "description": "Set to true to confirm the phase transition when phase_guard is enabled. If omitted or false, returns deliverables for review." + }, + "feedback": { + "type": "string", + "description": "User feedback when requesting changes instead of confirming the transition. The feedback will be passed back to the task to address." } }, "required": ["new_phase"] @@ -500,7 +508,13 @@ pub enum ContractToolRequest { // Phase management GetPhaseInfo, SuggestPhaseTransition, - AdvancePhase { new_phase: String }, + AdvancePhase { + new_phase: String, + /// Whether the user has confirmed the phase transition (for phase_guard) + confirmed: bool, + /// User feedback when they request changes instead of confirming + feedback: Option, + }, // Repository management ListDaemonDirectories, @@ -870,12 +884,28 @@ fn parse_advance_phase(call: &super::tools::ToolCall) -> ContractToolExecutionRe return error_result("Invalid phase. Must be one of: research, specify, plan, execute, review"); } + // Parse optional confirmed flag (defaults to false for initial phase_guard check) + let confirmed = call + .arguments + .get("confirmed") + .and_then(|v| v.as_bool()) + .unwrap_or(false); + + // Parse optional feedback (for when user requests changes) + let feedback = call + .arguments + .get("feedback") + .and_then(|v| v.as_str()) + .map(|s| s.to_string()); + ContractToolExecutionResult { success: true, message: format!("Advancing to '{}' phase...", new_phase), data: None, request: Some(ContractToolRequest::AdvancePhase { new_phase: new_phase.to_string(), + confirmed, + feedback, }), pending_questions: None, } -- cgit v1.2.3