From 94e5604e770d6589f786ea71e51738e21492f301 Mon Sep 17 00:00:00 2001 From: soryu Date: Wed, 21 Jan 2026 17:31:46 +0000 Subject: Add task branching feature (#15) --- makima/frontend/src/lib/api.ts | 47 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'makima/frontend/src/lib/api.ts') diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index 14ec9f2..86ff06c 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -607,8 +607,8 @@ export interface TaskListResponse { } export interface CreateTaskRequest { - /** Contract this task belongs to (required) */ - contractId: string; + /** Contract this task belongs to (optional - can be standalone) */ + contractId?: string; name: string; description?: string; plan: string; @@ -974,6 +974,49 @@ export async function listSubtasks(taskId: string): Promise { return res.json(); } +// ============================================================================= +// Task Branching +// ============================================================================= + +/** Request to branch a task */ +export interface BranchTaskRequest { + /** Message to send to the new branched task */ + message: string; + /** Optional name for the new task (defaults to "Branch of {original task name}") */ + name?: string; + /** Whether to include conversation history from the source task */ + includeConversation?: boolean; +} + +/** Response from branching a task */ +export interface BranchTaskResponse { + /** The newly created task */ + task: Task; + /** Number of conversation messages copied to the new task */ + messageCount: number; + /** ID of the daemon assigned to the new task (null if not yet assigned) */ + daemonId: string | null; +} + +/** + * Branch a task to create a new task with the same state. + * Copies the worktree and optionally the conversation history. + */ +export async function branchTask( + taskId: string, + request: BranchTaskRequest +): Promise { + const res = await authFetch(`${API_BASE}/api/v1/mesh/tasks/${taskId}/branch`, { + method: "POST", + body: JSON.stringify(request), + }); + if (!res.ok) { + const errorText = await res.text(); + throw new Error(`Failed to branch task: ${errorText || res.statusText}`); + } + return res.json(); +} + export async function listTaskEvents( taskId: string ): Promise { -- cgit v1.2.3