Skip to content

Run draft-thread project scripts from resolved project/worktree cwd#1178

Open
juliusmarminge wants to merge 3 commits intomainfrom
t3code/fix-draft-thread-script-cwd
Open

Run draft-thread project scripts from resolved project/worktree cwd#1178
juliusmarminge wants to merge 3 commits intomainfrom
t3code/fix-draft-thread-script-cwd

Conversation

@juliusmarminge
Copy link
Member

@juliusmarminge juliusmarminge commented Mar 17, 2026

Summary

  • Fix project script execution in draft threads by resolving cwd through a shared projectScriptCwd helper.
  • Allow script runs from local draft threads without requiring a server-thread-only guard.
  • Use the resolved cwd consistently for terminal/script actions and the “Open in…” cwd value in ChatView.
  • Add coverage for cwd resolution helper behavior and browser-level ChatView flows for both local and worktree draft threads.
  • Regenerate mockServiceWorker.js (MSW package version bump) and include updated Vitest attachment artifact.

Testing

  • apps/web/src/projectScripts.test.ts: verifies projectScriptCwd prefers worktreePath and falls back to project cwd.
  • apps/web/src/components/ChatView.browser.tsx: verifies terminalOpen for local draft thread uses cwd: /repo/project and env includes T3CODE_PROJECT_ROOT.
  • apps/web/src/components/ChatView.browser.tsx: verifies worktree draft thread uses cwd: /repo/worktrees/feature-draft and env includes both T3CODE_PROJECT_ROOT and T3CODE_WORKTREE_PATH.
  • apps/web/src/components/ChatView.browser.tsx: verifies script command dispatch (terminalWrite) sends the expected command (bun run lint\r).
  • Not run: bun fmt, bun lint, bun typecheck.

Note

Medium Risk
Changes how/when project scripts and terminal actions resolve their working directory and enables running scripts from local draft threads, which could alter where commands execute. Adds test coverage that should catch regressions, but behavior impacts developer workflow and command execution paths.

Overview
Project script execution now resolves cwd consistently across project vs worktree threads. ChatView switches from ad-hoc worktreePath ?? project.cwd logic to a shared projectScriptCwd helper, and uses that value for git queries and the header “Open in…” target.

Draft-thread behavior changes: the guard that previously blocked runProjectScript on non-server threads is removed, allowing scripts to run from local draft threads as well.

Regression coverage added: new unit tests cover projectScriptCwd and isTerminalFocused (now ignores detached DOM nodes), plus browser-level ChatView tests asserting terminalOpen/terminalWrite cwd/env for local vs worktree draft threads and more robust shortcut assertions. Also updates .gitignore to ignore .tanstack.

Written by Cursor Bugbot for commit 1caf2db. This will update automatically on new commits. Configure here.

Note

Run draft-thread project scripts from the resolved project or worktree cwd

  • Removes the early return in runProjectScript that blocked execution for non-server (local draft) threads, so project scripts now run from draft threads.
  • Adds projectScriptCwd in projectScripts.ts to resolve the working directory: uses worktreePath when present, otherwise falls back to the project cwd.
  • Fixes isTerminalFocused in terminalFocus.ts to return false for xterm helper textareas that are detached from the DOM.
  • Adds browser tests covering script execution from local and worktree draft threads, asserting correct cwd and env vars (T3CODE_PROJECT_ROOT, T3CODE_WORKTREE_PATH) in terminal open/write payloads.
  • Behavioral Change: runProjectScript no longer skips execution for local draft threads; scripts will now open a terminal using the resolved project or worktree path.

Macroscope summarized 1caf2db.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f0c6fdb3-e305-4889-b001-a09aee272d1f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/fix-draft-thread-script-cwd
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Mar 17, 2026
- use shared `projectScriptCwd` to choose worktree path or project root
- allow script execution from local draft threads with correct terminal env/cwd
- add ChatView and helper tests covering local and worktree draft cases
- Treat detached `xterm-helper-textarea` nodes as unfocused in `isTerminalFocused`
- Add unit tests for connected vs detached terminal focus behavior
- Harden ChatView shortcut test flow by waiting for keybindings/config and retrying route transition
@juliusmarminge juliusmarminge force-pushed the t3code/fix-draft-thread-script-cwd branch from b06a638 to 1caf2db Compare March 17, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant