fix(desktop): resolve relative file paths using pty process cwd

Closed
KI
1y ago
+86-12

Summary

  • Fixed unreliable relative file path resolution when clicking links in the terminal
  • Added getCwd(paneId) method to TerminalManager that queries the actual cwd from the pty's process via PID
  • Updated openFileInEditor to accept paneId and resolve paths using the real process cwd

Problem

Clicking relative file paths in the terminal was intermittent - sometimes working, sometimes not. The issue was that the frontend tracked the terminal's cwd via OSC 7 escape sequences, which:

  • Not all shells emit reliably
  • Can have timing issues
  • Gets captured in a stale closure

Solution

Query the actual cwd directly from the OS using the pty's process ID:

  • macOS: lsof -d cwd -Fn -p <pid>
  • Linux: readlink /proc/<pid>/cwd

This ensures we always get the real current working directory at click time.

Test plan

  • Open terminal in desktop app
  • Navigate to a subdirectory with cd
  • Run a command that outputs relative file paths (e.g., ls, grep, compiler errors)
  • Cmd+click a relative file path
  • Verify it opens the correct file in the editor

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Better terminal → editor integration: opening files now uses the terminal session’s actual working directory, improving path resolution and file navigation.
  • Bug Fixes
    • Reduced incorrect file-open attempts when a terminal session is unavailable; users will see clearer warnings and fewer failed opens.

✏️ Tip: You can customize this high-level summary in your review settings.