authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-01 20:00:58-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-01 22:36:35-08:00
log9e04bad0a504dafbf19182fb0ec361c55018c780
treeb9c01db9a86696e5d073e9c78af91deae18a3d04
parenta574d9c936adcf0a8ccc9b10d8f65e0127d13adc

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

1 files changed, 15 insertions(+), 9 deletions(-)

apps/web/src/components/ChatView.tsx+15-9
...@@ -940,10 +940,12 @@ export default function ChatView({ threadId }: ChatViewProps) {...@@ -940,10 +940,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
940 worktreePath?: string | null;940 worktreePath?: string | null;
941 preferNewTerminal?: boolean;941 preferNewTerminal?: boolean;
942 rememberAsLastInvoked?: boolean;942 rememberAsLastInvoked?: boolean;
943 allowLocalDraftThread?: boolean;
943 },944 },
944 ) => {945 ) => {
945 const api = readNativeApi();946 const api = readNativeApi();
946 if (!api || !activeThreadId || !activeProject || !activeThread || !isServerThread) return;947 if (!api || !activeThreadId || !activeProject || !activeThread) return;
948 if (!isServerThread && !options?.allowLocalDraftThread) return;
947 if (options?.rememberAsLastInvoked !== false) {949 if (options?.rememberAsLastInvoked !== false) {
948 setLastInvokedScriptByProjectId((current) => {950 setLastInvokedScriptByProjectId((current) => {
949 if (current[activeProject.id] === script.id) return current;951 if (current[activeProject.id] === script.id) return current;
...@@ -1787,14 +1789,6 @@ export default function ChatView({ threadId }: ChatViewProps) {...@@ -1787,14 +1789,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
1787 worktreePath: result.worktree.path,1789 worktreePath: result.worktree.path,
1788 });1790 });
1789 }1791 }
1790 const setupScript = setupProjectScript(activeProject.scripts);
1791 if (setupScript && isServerThread) {
1792 await runProjectScript(setupScript, {
1793 cwd: result.worktree.path,
1794 worktreePath: result.worktree.path,
1795 rememberAsLastInvoked: false,
1796 });
1797 }
1798 }1792 }
17991793
1800 const titleSeed =1794 const titleSeed =
...@@ -1819,6 +1813,18 @@ export default function ChatView({ threadId }: ChatViewProps) {...@@ -1819,6 +1813,18 @@ export default function ChatView({ threadId }: ChatViewProps) {
1819 createdServerThreadForLocalDraft = true;1813 createdServerThreadForLocalDraft = true;
1820 }1814 }
18211815
1816 const setupScript = baseBranchForWorktree
1817 ? setupProjectScript(activeProject.scripts)
1818 : null;
1819 if (setupScript && (isServerThread || createdServerThreadForLocalDraft)) {
1820 await runProjectScript(setupScript, {
1821 worktreePath: nextThreadWorktreePath,
1822 rememberAsLastInvoked: false,
1823 allowLocalDraftThread: createdServerThreadForLocalDraft,
1824 ...(nextThreadWorktreePath ? { cwd: nextThreadWorktreePath } : {}),
1825 });
1826 }
1827
1822 // Auto-title from first message1828 // Auto-title from first message
1823 if (isFirstMessage && isServerThread) {1829 if (isFirstMessage && isServerThread) {
1824 await api.orchestration.dispatchCommand({1830 await api.orchestration.dispatchCommand({