- 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
Unified · Split
| @@ -940,10 +940,12 @@ export default function ChatView({ threadId }: ChatViewProps) { · 939 unmodified lines | |||
| 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) { · 837 unmodified lines | |||
| 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 | } |
| 1799 | 1793 | ||
| 1800 | const titleSeed = | 1794 | const titleSeed = |
| @@ -1819,6 +1813,18 @@ export default function ChatView({ threadId }: ChatViewProps) { · 18 unmodified lines | |||
| 1819 | createdServerThreadForLocalDraft = true; | 1813 | createdServerThreadForLocalDraft = true; |
| 1820 | } | 1814 | } |
| 1821 | 1815 | ||
| 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 message | 1828 | // Auto-title from first message |
| 1823 | if (isFirstMessage && isServerThread) { | 1829 | if (isFirstMessage && isServerThread) { |
| 1824 | await api.orchestration.dispatchCommand({ | 1830 | await api.orchestration.dispatchCommand({ |