Skip to content

Fix Cmd+click file path punctuation trimming - #2831

Merged
austinywang merged 2 commits into
mainfrom
issue-2807-cmdclick-trailing-punctuation
Apr 12, 2026
Merged

austinywang merged 2 commits into
mainfrom
issue-2807-cmdclick-trailing-punctuation

Conversation

@austinywang

@austinywang austinywang commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • trim trailing sentence punctuation from Cmd+click file-path candidates when the punctuation is not part of a balanced path token
  • preserve legitimate trailing punctuation by trying the literal path first and only then the smart-trimmed fallback
  • add focused regression coverage for periods, commas, unbalanced closers, balanced parens, multiple trailing punctuation characters, and literal filenames that really end with punctuation

Testing

  • not run locally (per repo policy)

Closes #2807


Note

Low Risk
Low risk: changes are limited to Cmd+click file path candidate parsing and add regression tests; main risk is minor behavior changes in which path variant gets selected when filenames legitimately end with punctuation.

Overview
Improves Cmd+click Quick Look path resolution by adding a “smart” fallback candidate that trims trailing sentence punctuation/quotes and certain unmatched closing delimiters (e.g., ), ]) so paths followed by punctuation in terminal output still resolve.

Candidate ordering is updated to try the literal token first and only then try the punctuation-trimmed variant, reducing false negatives while preserving legitimate filenames that end with punctuation. Adds focused XCTest coverage for the trimming rules and resolution preference behavior.

Reviewed by Cursor Bugbot for commit c77d2bd. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Smart-trims trailing punctuation on Cmd+click file paths so sentence-ending characters don’t break resolution. Keeps legitimate trailing punctuation by trying the literal path first, then a trimmed fallback.

  • Bug Fixes
    • Trim trailing sentence punctuation, quotes, and unmatched closers while preserving balanced delimiters.
    • Add focused tests for periods, commas, unbalanced closers, balanced parens, multiple trailing characters, and literal filenames ending with punctuation.

Written for commit c77d2bd. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cmd-click path detection in terminal output by intelligently trimming trailing punctuation (periods, commas, parentheses, quotes) that isn't part of the actual file path, while preserving balanced delimiters within paths.

@vercel

vercel Bot commented Apr 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Apr 12, 2026 0:33am

@coderabbitai

coderabbitai Bot commented Apr 12, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca3226b6-f586-4da2-95b0-c6c6fb64aadc

📥 Commits

Reviewing files that changed from the base of the PR and between d289f66 and c77d2bd.

📒 Files selected for processing (2)
  • Sources/GhosttyTerminalView.swift
  • cmuxTests/TerminalAndGhosttyTests.swift

📝 Walkthrough

Walkthrough

Added trailing punctuation trimming logic for cmd+click file path resolution. The implementation introduces sanitization helpers that use delimiter-balance heuristics to strip sentence-terminating punctuation while preserving legitimate path characters, along with comprehensive test coverage.

Changes

Cohort / File(s) Summary
Path Punctuation Trimming Implementation
Sources/GhosttyTerminalView.swift
Added internal helpers for trimming trailing punctuation from terminal paths using delimiter-balance heuristics. Introduced constants for sentence punctuation and closing quotes, plus helpers to detect unmatched opening delimiters. Extended quicklook candidate generation to include both original and punctuation-stripped path versions with deduplication. Exposed DEBUG-only test helper cmuxTrimTerminalPathTrailingPunctuationForTesting().
Path Punctuation Trimming Tests
cmuxTests/TerminalAndGhosttyTests.swift
Added comprehensive test suite TerminalCmdClickPathPunctuationTrimmingTests with 9 test methods covering punctuation trimming scenarios (periods, commas, parentheses, quotes, multiple punctuation) and quicklook resolution fallback behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #2579: Introduced the initial quicklook/path-resolution logic in Sources/GhosttyTerminalView.swift that this PR directly extends with punctuation-trimming candidates and deduplication.

Poem

🐰 A rabbit hops through paths now clean,
No trailing dots to spoil the scene,
Balanced parens stay intact,
Cmd+click works—a perfect fact!
Punctuation trimmed with care,
File paths resolved with flair! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix Cmd+click file path punctuation trimming' directly describes the main change—addressing trailing punctuation issues in file path resolution.
Description check ✅ Passed The description covers main change (smart punctuation trimming), rationale (preserving legitimate punctuation via literal-path-first strategy), testing approach (regression tests), and closes issue #2807.
Linked Issues check ✅ Passed The implementation fully meets issue #2807 requirements: strips trailing sentence punctuation via smart trimming, preserves balanced delimiters and legitimate trailing punctuation, and includes comprehensive regression tests.
Out of Scope Changes check ✅ Passed All changes (new trimming logic, test helper function, and test suite) directly support the punctuation-trimming objective and issue #2807 requirements; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-2807-cmdclick-trailing-punctuation

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.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Cmd+click file-path resolution by stripping trailing sentence punctuation (., ,, ;, etc.), unmatched closing delimiters (), ], }, >), and trailing quotes from path candidates. The literal path is always tried first so that filenames that genuinely end with those characters are still resolved correctly when they exist on disk.

Confidence Score: 5/5

Safe to merge — the trimming logic is correct and the only finding is a missing test for a behaviour the implementation already handles properly.

All findings are P2. The core implementation (balance-tracking loop, candidate ordering, empty-string guard) is correct. The single concern is that testPreservesBalancedParensInMiddleOfPath exercises a trivial non-paren-ending path rather than the important 'balanced closer at path end is preserved' case — a missing regression test, not a bug.

cmuxTests/TerminalAndGhosttyTests.swift — consider adding the missing 'balanced closer at path end' test case.

Important Files Changed

Filename Overview
Sources/GhosttyTerminalView.swift Adds cmuxTrimTerminalPathTrailingPunctuation and cmuxHasUnmatchedOpeningPathDelimiter to strip sentence punctuation / unbalanced closers from Cmd+click path candidates; literal path is always tried first, trimmed form appended as fallback. Logic is correct.
cmuxTests/TerminalAndGhosttyTests.swift New TerminalCmdClickPathPunctuationTrimmingTests class covers sentence punctuation, trailing quotes, unbalanced closers, multi-character runs, literal-path preference, and the trimmed fallback. One test name is misleading and the key 'balanced closer at path end is preserved' behaviour is untested.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[rawText from Cmd+click] --> B[cmuxQuicklookPathCandidates]
    B --> C[append: trimmed literal]
    C --> D{cmuxTrimTerminalPathTrailingPunctuation}
    D --> E{punctuationTrimmed != trimmed?}
    E -- yes --> F[append: punctuation-trimmed fallback]
    E -- no --> G[skip fallback]
    B --> H[append: unescaped variants]
    B --> I[append: unquoted variants]
    subgraph cmuxTrimTerminalPathTrailingPunctuation
        T1[scan from end] --> T2{trailing char type?}
        T2 -- sentence punct / quote --> T3[strip and continue]
        T3 --> T1
        T2 -- closing pair --> T4{cmuxHasUnmatchedOpeningPathDelimiter?}
        T4 -- no unmatched opener --> T3
        T4 -- has unmatched opener --> T5[stop - preserve balanced closer]
        T2 -- other char --> T5
    end
    F --> R[cmuxResolveQuicklookPath: iterate candidates]
    G --> R
    H --> R
    I --> R
    R --> S{fileExists?}
    S -- first match --> Z[return path]
    S -- no match --> R
Loading

Reviews (1): Last reviewed commit: "Trim trailing punctuation from cmd-click..." | Re-trigger Greptile

Comment on lines +3748 to +3755
func testPreservesBalancedParensInMiddleOfPath() {
XCTAssertEqual(
cmuxTrimTerminalPathTrailingPunctuationForTesting(
"/tmp/fixtures/report (draft)/notes.txt"
),
"/tmp/fixtures/report (draft)/notes.txt"
)
}

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.

P2 Test doesn't cover the key "balanced closer at path end" scenario

The input /tmp/fixtures/report (draft)/notes.txt ends in .txt, not ), so the loop breaks immediately on the first character without exercising the closing-pair preservation logic at all. The test verifies "don't corrupt a path that has parens inside it" — which is fine — but the advertised behaviour ("preserves balanced parens") is the case where the path itself ends with a ) that IS balanced, e.g. /tmp/fixtures/report (draft).

For that path: the balance check on characters[..<(len-1)] (/tmp/fixtures/report (draft) finds one unmatched (, so cmuxHasUnmatchedOpeningPathDelimiter returns true and the closing paren is preserved. This is the correct and important case — but it is currently untested.

Consider adding:

func testPreservesTrailingCloseParenWhenBalancedWithOpener() {
    XCTAssertEqual(
        cmuxTrimTerminalPathTrailingPunctuationForTesting(
            "/tmp/fixtures/report (draft)"
        ),
        "/tmp/fixtures/report (draft)"
    )
}

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

@austinywang
austinywang merged commit 44b31eb into main Apr 12, 2026
21 checks passed
rodchristiansen pushed a commit to rodchristiansen/cmux that referenced this pull request Sep 2, 2026
…ick-trailing-punctuation

Fix Cmd+click file path punctuation trimming

This branch was successfully deployed

1 active deployment
Preview — c77d2bda Deployed Apr 11, 2026 by vercel[bot]
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.

Cmd+click on file paths includes trailing punctuation

1 participant