From d1f5dadb549d499c5aeee9cacf6c9aa0a233c198 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Mon, 26 Jan 2026 22:12:57 +0000
Subject: Add local-only mode for contracts with patch export support (#34)

* Add local_only flag to contracts database and models

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

* Task completion checkpoint

* Skip automatic completion actions in local_only mode

Add `local_only` flag to contracts that prevents automatic completion
actions (branch, merge, pr) from executing when tasks complete. This
allows users to manually handle code changes via patch files or other
means when operating in local-only mode.

Changes:
- Add `local_only` field to Contract model and request types
- Add database migration for the new column
- Add `local_only` parameter to SpawnTask command in both state.rs and
  daemon protocol.rs
- Modify task manager to skip completion action execution when
  `local_only` is true, with appropriate logging
- Pass `local_only` flag through all task spawning paths:
  - mesh_supervisor.rs (task spawn, retry, resume)
  - mesh.rs (task start, reassign, continue)
  - mesh_chat.rs (run task)
  - contract_chat.rs (run task)
- Update repository create/update functions to handle `local_only`

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

* Task completion checkpoint

* Implement core patch export system

Add functionality to create uncompressed, human-readable git patches
for export. This enables users to generate patches that can be manually
applied or shared, without the compression used for internal checkpoints.

Changes:
- Add ExportPatchResult struct with patch content, file count, and line stats
- Add create_export_patch() function that generates diffs against a base SHA
- Add get_head_sha() utility function
- Add parse_diff_stat() helper to extract line counts from git output
- Add CreateExportPatch command to daemon protocol
- Add ExportPatchCreated response message to protocol
- Add handler in task manager to process export patch requests
- Add server-side handling to broadcast patch results to UI

The export patch system automatically finds the merge-base when no base
SHA is provided, trying upstream tracking branch first, then common
default branches (origin/main, origin/master, main, master).

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

* Task completion checkpoint

* Add GitActionsPanel frontend component

* Add WorktreeFilesPanel and PatchesListPanel components

* Add local-only mode toggle to contract creation

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
---
 makima/frontend/src/components/mesh/TaskDetail.tsx | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'makima/frontend/src/components/mesh/TaskDetail.tsx')

diff --git a/makima/frontend/src/components/mesh/TaskDetail.tsx b/makima/frontend/src/components/mesh/TaskDetail.tsx
index 8936d28..fdcc58b 100644
--- a/makima/frontend/src/components/mesh/TaskDetail.tsx
+++ b/makima/frontend/src/components/mesh/TaskDetail.tsx
@@ -7,6 +7,9 @@ import { PRPreview } from "./PRPreview";
 import { InlineSubtaskEditor } from "./InlineSubtaskEditor";
 import { DirectoryInput } from "./DirectoryInput";
 import { BranchTaskModal } from "./BranchTaskModal";
+import { GitActionsPanel } from "./GitActionsPanel";
+import { WorktreeFilesPanel } from "./WorktreeFilesPanel";
+import { PatchesListPanel } from "./PatchesListPanel";
 
 interface TaskDetailProps {
   task: TaskWithSubtasks;
@@ -36,6 +39,8 @@ interface TaskDetailProps {
   fetchSubtasks?: (taskId: string) => Promise<TaskSummary[]>;
   /** For supervisor tasks: all tasks in the contract (excluding the supervisor itself) */
   contractTasks?: TaskSummary[];
+  /** Whether the contract is in local-only mode (no push/PR) */
+  isLocalOnly?: boolean;
 }
 
 function formatDate(dateStr: string): string {
@@ -119,6 +124,7 @@ export function TaskDetail({
   onAutoMerge,
   fetchSubtasks,
   contractTasks,
+  isLocalOnly = false,
 }: TaskDetailProps) {
   const [isEditing, setIsEditing] = useState(false);
   const [editName, setEditName] = useState(task.name);
@@ -879,6 +885,25 @@ export function TaskDetail({
             )}
           </div>
         )}
+
+        {/* Git Actions Panel for manual git operations */}
+        {task.status === "done" && (
+          <GitActionsPanel
+            taskId={task.id}
+            isLocalOnly={isLocalOnly}
+            taskStatus={task.status}
+          />
+        )}
+
+        {/* Worktree Files Panel - show changed files in the worktree */}
+        {(task.status === "done" || task.status === "failed" || task.status === "merged" || task.status === "running") && (
+          <WorktreeFilesPanel taskId={task.id} />
+        )}
+
+        {/* Patches List Panel - show exported patches for this task */}
+        {task.contractId && (task.status === "done" || task.status === "failed" || task.status === "merged") && (
+          <PatchesListPanel taskId={task.id} contractId={task.contractId} />
+        )}
       </div>
 
       {/* Overlay Diff Modal */}
-- 
cgit v1.2.3

