feat: Semantic History — resolve bare filenames against OSC 7 CWD on click

JI
7d ago
+67-4

Summary

When a user clicks a bare filename (e.g. README.md, src/main.py) in the terminal, resolve it against the terminal's current working directory (reported via OSC 7) and open it if the file exists on disk.

This is the terminal equivalent of iTerm2's Semantic History feature, and the #1 workflow gap for AI coding agent users (Claude Code, Codex, etc.) who frequently see bare filenames in output.

Changes

  • resolveTerminalOpenURLTarget() now accepts an optional workingDirectory parameter
  • Before falling through to browser URL heuristics (resolveBrowserNavigableURL), it checks whether CWD/clicked_text resolves to an existing file via FileManager.default.fileExists(atPath:)
  • Line/column suffixes (e.g. file.swift:42:10) are stripped before the file existence check
  • GHOSTTY_ACTION_OPEN_URL handler now retrieves the terminal's CWD from workspace.panelDirectories[surfaceId] (per-panel) or workspace.currentDirectory (workspace-level fallback)

Before / After

ScenarioBeforeAfter
Click README.mdOpens https://README.md (bug #1154) or no actionOpens /Users/me/project/README.md in editor
Click src/main.py:42No actionOpens /Users/me/project/src/main.py in editor
Click /absolute/path.mdOpens correctly ✅No change ✅
Click https://google.comOpens correctly ✅No change ✅
Click nonexistent.xyzFalls throughFalls through (file doesn't exist, no change)

How it works

User clicks "file.md" in terminal output
  → resolveTerminalOpenURLTarget("file.md", workingDirectory: "/Users/me/project")
  → Not an absolute path
  → CWD check: does /Users/me/project/file.md exist?
  → Yes → return .external(URL(fileURLWithPath: "/Users/me/project/file.md"))
  → NSWorkspace.shared.open() → opens in default editor

Why this matters

AI coding agents output bare filenames constantly:

I've updated the following files:
  proposal_draft.md
  workflow_v2.md
  src/coordinator.ts

In iTerm2, every one of these is Cmd+clickable. In cmux, none of them are. This PR fixes that.

Related

  • Closes #2199
  • Related to #1154 (relative paths misrouted to browser URL — this PR also fixes that case when the file exists locally)

Test plan

  • Click bare filename in terminal output → opens in editor
  • Click file.swift:42 → opens file (line number stripped)
  • Click absolute path → still works as before
  • Click URL → still works as before
  • Click non-existent filename → falls through to existing behavior
  • Works in split panes with different CWDs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved file path resolution when opening files from terminal output: relative paths and bare filenames (including trailing :line or :line:column numeric suffixes) are now resolved against the terminal's working directory, and files are opened only if the resolved path exists.
  • Other
    • Enhanced debug logging for open-from-terminal actions to include the resolved working directory.