fix(desktop): keep terminal links within URL boundaries

Merged
KI
2mo ago
+1482-1472

What & why

A terminal URL ending in / could absorb the next log line's prefix, extending its underline and changing the destination. For example, http://localhost:3001/ became http://localhost:3001/sloyd-web:dev:localhost.

Replace newline-guessing with terminal wrap metadata and map URL ranges to actual terminal cells, including wide characters, combining marks, and early wrapping. Adapt VS Code's URL parser for IPv6, quotes, Markdown delimiters, and international paths. Bound scanning while supporting URLs across more than three rows.

Explicit newlines now stop inferred URLs. TUIs that split URLs with explicit newlines should emit OSC 8 hyperlinks; genuine terminal wrapping remains supported. Existing file-link and OSC 8 handlers remain in place.

The verification report includes upstream revisions, all before/after case results, and the implementation tradeoffs. Generated report files are excluded from the code diff; the published page retains the evidence.

How I tested it

  • 3,551 URL cases pass using real xterm buffers. The original 3,545-case suite had 503 passes and 3,042 failures before this PR; many failures share the range-boundary bug. Six additional regression cases reproduce and fix leaked bracket context between URLs.
  • 605 related link tests pass, covering local-link parsing, resolution, adapters, and manager lifecycle.
  • Repository-wide bun run lint and bun run typecheck pass (42 typecheck tasks). bun run check:plugins and git diff --check pass.
  • The earlier local repository-wide bun run test stopped at the desktop suite: 7,531 pass, 22 fail. Failures are in untouched Git/worktree and shell-environment suites, including external worktree import, branch detection, hook tolerance, and shell environment capture. No link tests failed. All GitHub CI checks, including Test and Build, subsequently passed on the initial PR revision.
  • Real mouse hover and click in a browser xterm component harness reproduced the malformed destination before and the correct destination after. This is component verification, not signed-in desktop E2E; no matching dev renderer was running for this worktree.
  • Verified the report offline, including embedded screenshots, filtering, and mobile layout.

Before hover:

Before: URL highlight spills into subsequent log rows

After hover:

After: only the URL is highlighted

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs — not applicable; same-repository branch

Summary by cubic

Fixes terminal URL highlighting so a URL ending in / no longer absorbs the next log line's prefix, which previously extended the underline and changed the destination from http://localhost:3001/ to http://localhost:3001/sloyd-web:dev:localhost.

  • Replaces the hard-wrap guessing in multi-line-link-provider with xterm wrap metadata and cell-level ranges that handle wide characters, combining marks, and early wrapping.
  • Explicit newlines now end URL matches; TUIs that split URLs with explicit newlines should emit OSC 8 hyperlinks instead.
  • Adapts VS Code's URL link parser for IPv6, quotes, Markdown delimiters, and international paths.
  • Resets bracket context between URLs so an unterminated bracket can't make a later URL absorb trailing prose.
  • 3,551 URL cases pass against real xterm buffers, up from 503; the 22 remaining repo test failures are in untouched Git/worktree and shell-environment suites.

Summary by CodeRabbit

  • New Features

    • Improved terminal URL detection for wrapped lines, Unicode text, CJK characters, and varied URL formats.
    • Added support for accurate link positioning after terminal resizing or reflow.
    • Links now support reliable activation, hover, and leave interactions.
  • Bug Fixes

    • Prevented URLs from incorrectly merging across hard line breaks.
    • Improved handling of punctuation, delimiters, and invalid or excessively long URLs.
  • Documentation

    • Added documentation and verification records for terminal URL parsing and link behavior.