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
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-03-01 22:36:35 -08:00
1 parent a574d9c936
commit 9e04bad0a5
1 file changed
+15 -9
+15 -9
View File
@@ -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({