Repository navigation
Conversation
📝 WalkthroughWalkthroughThis change adds an optional 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/shared/terminal-startup-cwd.ts (1)
5-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExport
OutsideWorktreeCwdPolicyto avoid literal-union duplication.
src/main/ipc/pty.tsre-declares'throw' | 'fallback-to-worktree'inline instead of importing this type, so any future change to the policy's members must be updated in two places.♻️ Proposed fix
-type OutsideWorktreeCwdPolicy = 'throw' | 'fallback-to-worktree' +export type OutsideWorktreeCwdPolicy = 'throw' | 'fallback-to-worktree'src/main/ipc/pty.ts (1)
2540-2540: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a short "Why" comment for the SSH-exclusion gate.
Every sibling field in this args block (
tabId/leafId,telemetry) carries a "Why:" comment, butcwdFallbackand the!args.connectionIdgate that keeps this fallback local-only don't. This is exactly the kind of non-obvious, security-relevant constraint (never let fallback apply to SSH/remote spawns) that's worth a one-line note so a future edit doesn't accidentally drop the!args.connectionIdcheck.📝 Proposed comment
+ // Why: opt-in for the local-UI new-terminal flow (see `#7239`) so a + // stale inherited/remembered cwd falls back to the worktree root + // instead of hard-failing. Never honored for SSH — see the + // `!args.connectionId` gate below. cwdFallback?: 'worktree'const cwd = resolveGuardedPtySpawnCwd( args.worktreeId, args.cwd, + // Why: fallback-to-worktree is a local-only convenience; SSH/remote + // spawns must keep the strict containment guard. !args.connectionId && args.cwdFallback === 'worktree' ? 'fallback-to-worktree' : undefined )As per coding guidelines: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
Also applies to: 2568-2572
Source: Coding guidelines
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
2561-2562: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd rationale comment and dedupe the repeated local/non-remote-runtime check.
The
!connectionId && runtimeEnvironmentId === nullcondition (or its reordered form) now appears three times (projectRuntime,shouldSettleStartupGridBeforeConnect, and the newcwdFallbackline). Extracting it to a single named constant would prevent the checks from silently diverging, and a short comment on thecwdFallbackline would document why the fallback is scoped to local, non-remote-runtime panes only (per issue#7239).♻️ Suggested consolidation
+ // Why: cwdFallback (and projectRuntime/grid-settle gating) must stay local-only — + // remote-runtime, SSH, and other non-local callers keep the strict cwd guard. + const isLocalNonRuntimeSpawn = !connectionId && runtimeEnvironmentId === null const projectRuntime = - !connectionId && runtimeEnvironmentId === null + isLocalNonRuntimeSpawn ? getLocalProjectExecutionRuntimeContext(state, deps.worktreeId, undefined, { wslAvailable: localWindowsTerminalCapabilities?.wslAvailable, availableWslDistros: localWindowsTerminalCapabilities?.wslDistros ?? null }) : undefined ... const transportOptions = { cwd: deps.cwd, - ...(runtimeEnvironmentId === null && !connectionId ? { cwdFallback: 'worktree' as const } : {}), + ...(isLocalNonRuntimeSpawn ? { cwdFallback: 'worktree' as const } : {}), ... const shouldSettleStartupGridBeforeConnect = (): boolean => Boolean(paneStartup?.command) && deps.isVisibleRef.current && - !connectionId && - runtimeEnvironmentId === null + isLocalNonRuntimeSpawnAlso applies to: 2604-2604, 3057-3058
Source: Coding guidelines
src/renderer/src/components/terminal-pane/pty-transport.ts (1)
460-460: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a short rationale comment for the SSH exclusion.
shouldSendLocalCwdFallbackand its spread into the spawn payload implement a security/scope-relevant containment rule (fallback must stay local-only), but there's no inline comment explaining whyconnectionIddisables it.📝 Suggested comment
+ // Why: cwdFallback must stay local-only — SSH-backed sessions keep the + // strict containment guard, so never forward the flag when connectionId is set. const shouldSendLocalCwdFallback = cwdFallback === 'worktree' && !connectionIdAlso applies to: 609-609
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5b387618-fe3c-4bdb-813b-0ab5adf9cbc7
📥 Commits
Reviewing files that changed from the base of the PR and between 0d2d44b and 74c8c5ab65980ec73fda510621f3bc012b00fb98.
📒 Files selected for processing (11)
src/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/shared/terminal-startup-cwd.test.tssrc/shared/terminal-startup-cwd.ts
74c8c5a to
0692114
Compare
|
Thanks @rodboev for digging into this and for the local-only opt-in shape — that design carried through to the final fix. Closing because the landscape changed under this PR: #7750 removed the startup-cwd containment guard entirely (out-of-worktree cwds now spawn as requested, shipped in v1.4.128), so the outside-worktree fallback this PR implements no longer has a guard to fall back from. The residual #7239 failure — a saved startup cwd whose directory was deleted — was just fixed in #7847 using the same fresh-local-only opt-in approach you proposed here (renderer flag + strict reattach/SSH/remote semantics), retargeted to a missing-directory probe. |
Summary
Closes #7239.
Screenshots
No visual change
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildFocused validation run in this session:
pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts- passed; covers strict default behavior, stale-path fallback, and nested-path preservation.pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts -t "stale local renderer cwd values|renderer cwd values without the fallback flag|connectionId is present|sessionId is present"- passed; covers local fallback and strict no-flag, connection-backed, or session-reattach rejection.pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts -t "cwdFallback|explicitly local worktrees while a runtime is focused|owner runtime when focus differs"- passed; covers local-only transport routing and remote omission.pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-transport.test.ts -t "startup cwd fallback|SSH-tagged|session reattach"- passed; covers preload spawn payload routing for local IPC versus SSH-tagged and session-reattach inputs.pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts src/main/ipc/pty.test.ts -t "fallback|stale renderer cwd values|stale local UI cwd|raw worktree root|resolved folder workspace root|sessionId is present"- passed; covers the combined shared-helper and main-IPC fallback compatibility row.pnpm run typecheck:node- passed; covers main, preload, and shared type plumbing.pnpm run typecheck:web- passed; covers renderer and preload type plumbing.pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts src/main/ipc/pty.test.ts src/renderer/src/components/terminal-pane/pty-transport.test.ts- failed in pre-existingsrc/main/ipc/pty.test.tsattribution-path assertions; the new cwd fallback tests passed.AI Review Report
Reviewed against the implemented diff after two review passes and fixed a CodeRabbit finding about session reattach spawns. The change keeps the containment guard strict by default, scopes the fallback to new local IPC terminal creation, preserves SSH, session reattach, and remote-runtime rejection, and keeps the shared helper as the single owner of cwd policy. Cross-platform path normalization, macOS/Linux/Windows behavior, local versus remote routing, SSH-tagged payloads, IPC shape, performance, and UI quality were covered by source review and focused tests.
Security Audit
The change keeps the terminal cwd containment guard strict by default and never permits a shell outside the selected worktree. The only new fallback rewrites a stale local UI cwd to the already selected worktree root, and remote/session/API callers must remain unable to opt into it implicitly.
Notes
No UI or Electron rendering changes. The fallback is local-only, explicit, and opt-in through the renderer-to-main spawn payload. If PR #7184 lands first, rebase the helper changes so the deleted in-worktree directory fallback and this outside-worktree stale cwd fallback share the same terminal startup cwd authority without widening strict callers.