From 54c6d409e1d5667f4ab7f63a43e1459e68575c94 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Tue, 20 Jan 2026 17:19:18 +0000
Subject: Clean contract lifecycle: Add supervisor complete command (#13)

* feat: Add contract lifecycle management commands (complete and resume-contract)

Add supervisor commands for properly managing contract lifecycle:
- `makima supervisor complete` - Mark a contract as complete and stop the supervisor
- `makima supervisor resume-contract` - Resume a completed contract (reactivate it)

Also adds `api_key` field to TaskConfig for authenticated API calls.

This consolidates the lifecycle management features from the contract-lifecycle-cleanup branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix: prevent supervisor auto-start for completed contracts

When viewing a completed contract, the supervisor was auto-starting
on component mount. This would resurrect completed contracts and
cause them to continue running.

Changes:
- Add contract.status !== 'completed' check to the auto-start condition
- Add contract.status to the useEffect dependency array

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Task completion checkpoint

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
---
 makima/frontend/src/components/contracts/ContractCliInput.tsx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'makima/frontend/src/components/contracts/ContractCliInput.tsx')

diff --git a/makima/frontend/src/components/contracts/ContractCliInput.tsx b/makima/frontend/src/components/contracts/ContractCliInput.tsx
index 821d03c..54d9f3a 100644
--- a/makima/frontend/src/components/contracts/ContractCliInput.tsx
+++ b/makima/frontend/src/components/contracts/ContractCliInput.tsx
@@ -279,9 +279,9 @@ export function ContractCliInput({ contractId, contract, onUpdate }: ContractCli
     }
   }, [messages]);
 
-  // Auto-start supervisor when component mounts if it's pending
+  // Auto-start supervisor when component mounts if it's pending (but not for completed contracts)
   useEffect(() => {
-    if (supervisorTask && isSupervisorPending && !supervisorStarting) {
+    if (supervisorTask && isSupervisorPending && !supervisorStarting && contract.status !== 'completed') {
       console.log("Auto-starting supervisor task on mount...");
       ensureSupervisorStarted().then((started) => {
         if (started) {
@@ -289,7 +289,7 @@ export function ContractCliInput({ contractId, contract, onUpdate }: ContractCli
         }
       });
     }
-  }, [supervisorTask?.id]); // Only run when task ID changes, not on every render
+  }, [supervisorTask?.id, contract.status]); // Only run when task ID or contract status changes
 
   // Convert supervisor output events to messages
   useEffect(() => {
-- 
cgit v1.2.3

