Skip to content

fix(terminal): link paths typed after a prompt cwd and probe glued hard-wrap guesses before opening - #23221

Closed
MatrixA wants to merge 4 commits into
stablyai:mainfrom
MatrixA:MatrixA/terminal-input-path-cmd-enter
Closed

MatrixA wants to merge 4 commits into
stablyai:mainfrom
MatrixA:MatrixA/terminal-input-path-cmd-enter

Conversation

@MatrixA

@MatrixA MatrixA commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Cmd/Ctrl+Click on a file path in the terminal sometimes did nothing. Two separate reasons: paths you typed after a prompt that itself shows a directory (like root@host:/mnt/x# echo /root/y) were never recognised as links, and paths in output occasionally opened nothing on the first click but worked on the next identical line. Both are now fixed.

What Changed

Before

  1. root@ubuntu:/mnt/data/project# echo /root/.claude/settings.json — the typed /root/.claude/settings.json is not clickable. Same for cp /a/b /c/d (neither path is clickable).
  2. The output line /root/.claude/settings.json sometimes does nothing on Cmd+Click, especially over SSH. Running the same command again makes the new output line work.

After

Both the typed path and the output path open on Cmd/Ctrl+Click, first time.

Mechanism

  1. src/renderer/src/lib/terminal-links.ts — the spaced-path scanner (which exists so /Users/A/My Folder/file.ts is one link) is deliberately broad and runs to the end of the line. When the line already contains a path earlier (the prompt's cwd, or the first argument of cp), it swallowed everything after it into one nonexistent "path", and that range then masked the real /root/.claude/settings.json match. The broad match is now split at whitespace followed by an explicit path start (/, ~/, ./, ../, X:/) before the existing filters run. Foo Bar/file is not an explicit start, so spaced folder names are unaffected. The splitter lives in terminal-file-link-detection-ranges.ts alongside the other range helpers.

  2. src/renderer/src/components/terminal-pane/terminal-file-link-hit-testing.ts — the direct-click fallback (runs on mouseup before xterm's own activation) picked the first candidate that had not yet been probed for existence. The hard-wrap joiner can glue an output row to the prompt on the next row (/root/.claude/settings.json + root@ubuntu:/mnt/... → bogus /root/.claude/settings.jsonroot@ubuntu), and that multi-row candidate sorts first. If the hover probe had not answered yet (one SSH round-trip), the click opened the bogus guess, failed silently, and its stopPropagation also suppressed xterm's correct link. On the second identical line the bogus path was already cached as missing, which is why it "worked the second time". Now, when there are several unprobed candidates at the click position, they are batch-probed through the same createTerminalPathExistenceBatch the hover provider uses (SSH goes through runtimePathsExist), results are written to the shared cache, and the longest existing path opens. A single unprobed candidate still opens immediately as before.

Why

Both are root-cause fixes in the shared detection/selection code rather than special-casing shell prompts. Alternatives considered: teaching the hard-wrap joiner to recognise prompts (heuristic, would still break for other row shapes), or preferring single-row candidates in the fallback (breaks genuinely hard-wrapped long paths in TUIs). Probing instead of guessing costs one batched request only in the ambiguous case.

Linked Issue

Fixes #

Visual Proof

N/A — no visual change; the affected interaction is "Cmd+Click opens the file vs. does nothing", covered by the unit tests below.

Testing

  • vitest: terminal-links.test.ts, terminal-links-redos.test.ts, terminal-link-click-fallback.test.ts, terminal-link-provider-link-detection.test.ts pass; full src/renderer/src/components/terminal-pane + src/renderer/src/lib/terminal* suites pass (4832 tests).

  • pnpm tc:web, pnpm run check:code-quality:changed, oxfmt --check clean.

  • Reproduced the reported case as unit tests: prompt-line detection, cp /a/b /c/d, and the two-row glued-path fallback (probe called, only the real path opened, bogus path cached as missing).

  • Platforms: logic is platform-independent (macOS Cmd / Linux+Windows Ctrl handled by existing isTerminalLinkDirectActivation); SSH path goes through the existing remote existence batch. Not manually run in the packaged app.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Implemented with Claude (Fable 5) via Conductor; reviewed by the author.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

…rd-wrap guesses before opening

Two independent defects made Cmd/Ctrl+Click on terminal file paths flaky:

- The broad spaced-path scan ran to line end, so a prompt whose cwd is a
  path (root@host:/mnt/x# echo /root/y) or a multi-argument command
  (cp /a/b /c/d) collapsed every later path into one nonexistent
  candidate that also masked the real LOCAL_PATH_REGEX matches. Split
  the broad match at whitespace followed by an explicit path start.

- The direct-click fallback opened the first unprobed candidate. The
  hard-wrap joiner can glue an output row to the next prompt row and
  yield a bogus path that sorts first; when the hover probe had not yet
  answered (SSH RTT) the click opened the guess, failed silently, and
  stopped xterm's own activation. With several unprobed candidates,
  batch-probe them and open the longest that exists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Spaced-path split — splitSpacedPathRangeAtNextPathStart splits a detected broad range at each whitespace followed by an explicit path start (/, ~/, ./, ../, X:/) before the existing filters run, so a prompt cwd or cp /a/b /c/d no longer masks the real paths on the line. trimTrailingWhitespace is renamed/moved to trimTerminalFileLinkRangeEnd with identical behavior.
  • Probe-before-open fallback — openFilePathLinkAtBufferPosition now aggregates candidates across all logical lines, prefers cached/known-worktree-root matches, still opens a lone unprobed candidate immediately, and for 2+ unprobed candidates batch-probes existence through createTerminalPathExistenceBatch (same remote path as hover), writes the shared cache, and opens the longest existing one; the rejection arm opens nothing rather than guessing.
  • Tests — new cases for the prompt-cwd typed path, cp /a/b /c/d, and the two-row glued-path probe. I verified these fail without their respective code paths (the prompt test with the splitter disabled, the glued-path test with the probe branch removed), so they really pin the fix.

The range-index arithmetic in the splitter is consistent with detectTerminalFileLinkRanges (lineText.slice(startIndex, endIndex) === text), the module-level g regex is safe under matchAll, and the targeted suites (93 tests) plus check:code-quality:changed are clean.

ℹ️ Two side effects worth carrying forward

The splitter surfaces a partial drive-letter match inside a longer token: root@ubuntu:/mnt/x now yields a separate u:/mnt/x candidate beside the real path. Pre-PR that line was one merged bogus link starting at u:/, so the root cause is the pre-existing [A-Za-z]:[\\/] drive alternative rather than this change; existence probing filters it from hover, and the click fallback's single-candidate blind open is unchanged. Separately, extractTerminalFileLinks also feeds comment-markdown-native-chat-file-links.ts, which has no tests; a spaced folder followed by another explicit path now splits (/repo/My Folder /repo/Other → /repo/My, /repo/Other) where pre-PR it was one merged bogus span. Neither is a regression from previously-correct behavior, but they are the blast radius I'd keep an eye on if link extraction ever grows another consumer.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 65924ba3-8c43-40a6-944a-3aafecd50765

📥 Commits

Reviewing files that changed from the base of the PR and between cc18a1e and b04108c.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-file-link-hit-testing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-click-fallback.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/terminal-link-click-fallback.test.ts
  • src/renderer/src/components/terminal-pane/terminal-file-link-hit-testing.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Terminal file-link extraction now splits detected ranges at subsequent path starts and trims trailing whitespace. Click handling gathers candidates across logical lines, selects among cached-existing and worktree-root paths, and probes multiple uncached candidates before opening. Probe results are cached when a cache is provided, and a newer hit-test invocation prevents an earlier probe result from opening a path. Tests cover path extraction and click fallback behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b0410

The terminal path-click changes are mergeable after normal checks; no actionable issue remains from the inspected behavior.

### Architecture Summary

Architecture risk: 🔵 Low · up to cc18a

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 5 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/lib/terminal-file-link-detection-ranges.ts: Adds a splitter that recognizes whitespace before ~/, /, ./, ../, or a drive-letter path prefix, returning ranges with adjusted text and offsets. If no prefix is found, it returns the input range unchanged.
  • observed — Modified behavior in src/renderer/src/lib/terminal-file-link-detection-ranges.ts: Adds an end-trimming helper that removes trailing whitespace from the range text and recalculates endIndex, leaving startIndex unchanged.
  • observed — Modified behavior in src/renderer/src/lib/terminal-links.test.ts: Added a test expecting extraction to include /root/.claude/settings.json from a command following a path-like shell prompt.
  • observed — Modified behavior in src/renderer/src/lib/terminal-links.test.ts: Added a test expecting both extensionless absolute paths in cp /a/b /c/d to be extracted, in order.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the user impact, mechanism, rationale, testing, platform considerations, and checklist. However, the required Linked Issue field is incomplete and contains only “Fixes #”. Add the complete linked issue number or URL. Also reconcile the checklist claim that lint, typecheck, test, and build pass with the specific commands and results reported in the Testing section.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary fixes: terminal paths typed after prompts and glued hard-wrap candidates during click handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1f397509-84aa-4bae-8d09-492576b8206c

📥 Commits

Reviewing files that changed from the base of the PR and between da6d483 and 332c6e7.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/terminal-file-link-hit-testing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-click-fallback.test.ts
  • src/renderer/src/lib/terminal-file-link-detection-ranges.ts
  • src/renderer/src/lib/terminal-links.test.ts
  • src/renderer/src/lib/terminal-links.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

… superseded probes

Review follow-ups: Promise.allSettled so a single runtime {error} row does
not discard a candidate that resolved, and a gesture revision so a slow
probe from an earlier click cannot open its file after a later click.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c98dd907-e0c2-45aa-b755-1041c5ef20db

📥 Commits

Reviewing files that changed from the base of the PR and between 332c6e7 and cc18a1e.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-file-link-hit-testing.ts
  • src/renderer/src/components/terminal-pane/terminal-link-click-fallback.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — minor suggestions inline.

Reviewed changes

Reviewed the delta since pullfrog's prior review (commit cc18a1e, on top of 332c6e7):

  • Promise.allSettled for the candidate probe — a runtime { error } row for one candidate no longer discards a sibling that resolved; a whole-batch connection failure still opens nothing rather than a guessed path.
  • Superseded-probe guard — a module-level latestProbedClickGesture counter drops an earlier click's pending probe once a later click starts its own probe.
  • Test coverage — a new case pins that only one file opens when a slow probe is superseded; the targeted suite passes (19 tests).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

The gesture revision only advanced in the multi-candidate branch, so a
later click that opened synchronously (cached hit, worktree root, lone
candidate) left an earlier probe free to open a second file. Bump at
function entry.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the delta since pullfrog's prior review (commit cc18a1e, on top of 332c6e7):

  • Gesture bump moved to function entry — const gesture = ++latestProbedClickGesture now runs before every early return, so any later click (cached hit, known worktree root, a lone uncached candidate, or the probe branch) invalidates an earlier click's pending probe. This resolves the stale-probe gap flagged in the prior review: at most one file opens per user action.
  • Test extended — the superseded-probe case now issues a second click on a lone candidate that opens synchronously and asserts only package.json is opened. Without the fix the first probe's settings.json would also open, so the assertion genuinely pins the change.

The function is only called from the modifier-mouseup fallback (terminal-link-handlers.ts:291), so bumping the counter on every call cannot be triggered by hover traffic. The module-level counter being global across panes is intentional per the author's reply — a click is one user gesture regardless of pane.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@szsip239

szsip239 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Related follow-up before candidate selection/probing: #14291 (comment).

We reproduced CJK-directory, CJK-filename and parenthesized-filename paths failing across TUI hard wraps on Orca 1.4.218/macOS. With no Codex process, real xterm-buffer replay through the unmodified Orca detector still fails for hard wraps, while the same existing target succeeds on one row or with xterm soft wrapping. ASCII hard-wrap controls pass.

Here the complete target never enters the candidate set because the ASCII-only hard-wrapped-terminal-path-fragments.ts predicates reject those fragments. Batch-probing the resulting candidates cannot recover an absent target. This is distinct from the real/bogus-candidate race fixed here; I have not run your full PR branch and am not claiming this PR introduced the issue. Sharing the standalone fixture as complementary reconstruction/range coverage, not asking to conflate the two fixes.

Use main's shared file-link target resolution and host-aware existence
checks for ambiguous clicks, preserving remote terminal grants and the
stale-click guard. Add coverage for a host-granted path alongside a
failed candidate probe.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@MatrixA

MatrixA commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Merged the latest main in 3473a8d916; GitHub reported this PR as mergeable after the push.

The resolution uses main’s shared path resolution and host-aware existence checks while preserving this PR’s candidate probing and stale-click protection. Added a regression test for a host-granted remote file alongside a failed candidate probe.

Path regression tests, renderer typecheck, and changed-code quality checks pass. The broader terminal suite had two failures in the snapshot test file during parallel execution; all tests in that file passed when rerun in isolation.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @MatrixA! You traced the click fallback to the same cause we did: the hard-wrap guess was opened before anything confirmed it existed. Your idea of checking the ambiguous candidates in one batch, and dropping a slow check once the user clicks again, is the core of #32411, which fixes #32128, and we kept your stale-click test case. On top of that, #32411 makes the server answer ENOTDIR as "missing", shows a toast when a click can't open anything, and checks the full wrapped name before a shorter prefix. Your commits are credited with a Co-authored-by trailer. We left out the spaced-path splitting in terminal-links.ts to keep this fix small. It's a separate improvement for paths typed after a prompt, and we'd welcome it as its own PR.

@nwparker nwparker closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants