| ... | @@ -1424,6 +1424,19 @@ export default function ChatView({ threadId }: ChatViewProps) { | ... | @@ -1424,6 +1424,19 @@ export default function ChatView({ threadId }: ChatViewProps) { |
| 1424 | }, | 1424 | }, |
| 1425 | ]); | 1425 | ]); |
| 1426 | | 1426 | |
| | 1427 | // In worktree mode, require an explicit base branch so we don't silently |
| | 1428 | // fall back to local execution when branch selection is missing. |
| | 1429 | const shouldCreateWorktree = |
| | 1430 | activeThread.messages.length === 0 && envMode === "worktree" && !activeThread.worktreePath; |
| | 1431 | if (shouldCreateWorktree && !activeThread.branch) { |
| | 1432 | dispatch({ |
| | 1433 | type: "SET_ERROR", |
| | 1434 | threadId: activeThread.id, |
| | 1435 | error: "Select a base branch before sending in New worktree mode.", |
| | 1436 | }); |
| | 1437 | return; |
| | 1438 | } |
| | 1439 | |
| 1427 | setThreadError(threadIdForSend, null); | 1440 | setThreadError(threadIdForSend, null); |
| 1428 | promptRef.current = ""; | 1441 | promptRef.current = ""; |
| 1429 | setPrompt(""); | 1442 | setPrompt(""); |
| ... | @@ -1449,11 +1462,20 @@ export default function ChatView({ threadId }: ChatViewProps) { | ... | @@ -1449,11 +1462,20 @@ export default function ChatView({ threadId }: ChatViewProps) { |
| 1449 | branch: result.worktree.branch, | 1462 | branch: result.worktree.branch, |
| 1450 | worktreePath: result.worktree.path, | 1463 | worktreePath: result.worktree.path, |
| 1451 | }); | 1464 | }); |
| | 1465 | // Keep local thread state in sync immediately so terminal drawer opens |
| | 1466 | // with the worktree cwd/env instead of briefly using the project root. |
| | 1467 | dispatch({ |
| | 1468 | type: "SET_THREAD_BRANCH", |
| | 1469 | threadId: activeThread.id, |
| | 1470 | branch: result.worktree.branch, |
| | 1471 | worktreePath: result.worktree.path, |
| | 1472 | }); |
| 1452 | const setupScript = setupProjectScript(activeProject.scripts); | 1473 | const setupScript = setupProjectScript(activeProject.scripts); |
| 1453 | if (setupScript) { | 1474 | if (setupScript) { |
| 1454 | void runProjectScript(setupScript, { | 1475 | await runProjectScript(setupScript, { |
| 1455 | cwd: result.worktree.path, | 1476 | cwd: result.worktree.path, |
| 1456 | worktreePath: result.worktree.path, | 1477 | worktreePath: result.worktree.path, |
| | 1478 | preferNewTerminal: true, |
| 1457 | rememberAsLastInvoked: false, | 1479 | rememberAsLastInvoked: false, |
| 1458 | }); | 1480 | }); |
| 1459 | } | 1481 | } |