From 9e04bad0a504dafbf19182fb0ec361c55018c780 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 1 Mar 2026 20:00:58 -0800 Subject: [PATCH] Run setup script after promoting local draft threads - allow `runProjectScript` for local draft threads when explicitly enabled - move setup script execution to run after server thread creation - gate setup script on worktree/base-branch availability and pass resolved worktree cwd --- apps/web/src/components/ChatView.tsx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 437cad93131d9291085894b3a21ef3ca05ed385c..af023f741b333a325a2e9c34f6ffc7a8e54ccd02 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -940,10 +940,12 @@ export default function ChatView({ threadId }: ChatViewProps) { worktreePath?: string | null; preferNewTerminal?: boolean; rememberAsLastInvoked?: boolean; + allowLocalDraftThread?: boolean; }, ) => { const api = readNativeApi(); - if (!api || !activeThreadId || !activeProject || !activeThread || !isServerThread) return; + if (!api || !activeThreadId || !activeProject || !activeThread) return; + if (!isServerThread && !options?.allowLocalDraftThread) return; if (options?.rememberAsLastInvoked !== false) { setLastInvokedScriptByProjectId((current) => { if (current[activeProject.id] === script.id) return current; @@ -1787,14 +1789,6 @@ export default function ChatView({ threadId }: ChatViewProps) { worktreePath: result.worktree.path, }); } - const setupScript = setupProjectScript(activeProject.scripts); - if (setupScript && isServerThread) { - await runProjectScript(setupScript, { - cwd: result.worktree.path, - worktreePath: result.worktree.path, - rememberAsLastInvoked: false, - }); - } } const titleSeed = @@ -1819,6 +1813,18 @@ export default function ChatView({ threadId }: ChatViewProps) { createdServerThreadForLocalDraft = true; } + const setupScript = baseBranchForWorktree + ? setupProjectScript(activeProject.scripts) + : null; + if (setupScript && (isServerThread || createdServerThreadForLocalDraft)) { + await runProjectScript(setupScript, { + worktreePath: nextThreadWorktreePath, + rememberAsLastInvoked: false, + allowLocalDraftThread: createdServerThreadForLocalDraft, + ...(nextThreadWorktreePath ? { cwd: nextThreadWorktreePath } : {}), + }); + } + // Auto-title from first message if (isFirstMessage && isServerThread) { await api.orchestration.dispatchCommand({ -- 2.54.0