Skip to content

TASK-166: fix .md preview when Ink hard-wraps a no-space path#1

Open
mpmisha wants to merge 1 commit into
mainfrom
fix/task-166-md-preview-phantom-seam
Open

TASK-166: fix .md preview when Ink hard-wraps a no-space path#1
mpmisha wants to merge 1 commit into
mainfrom
fix/task-166-md-preview-phantom-seam

Conversation

@mpmisha

@mpmisha mpmisha commented May 21, 2026

Copy link
Copy Markdown
Owner

Problem

When Ink-based TUIs (Copilot CLI, Claude Code) hard-wrap a long .md path that has no embedded spaces, the continuation row starts with Ink's layout indent. The TASK-132/137 seam-space heuristic in TerminalPanel.tsx's .md link provider could not distinguish that indent from a wrap-eaten literal space (as in OneDrive - Microsoft\…), so it always inserted a phantom space at the join — …/files/… became …/fi les/…fileRead 404'd silently and the preview never opened.

User repro: shrink a terminal pane narrow enough to wrap a .md path printed by a TUI, click the underlined link — nothing happens. DevTools console shows:

[md-link] fileRead returned null { fullPath: '/Users/.../session-state/<id>/fi les/reddit-scout-2026-05-21.md' }

Fix

  • Track each inserted seam-space offset during forward and backward hard-newline stitching.
  • In activate(), compute a seam-stripped variant of the matched path. Try fileRead on the primary (with-seam) path first; if it returns null and a stripped variant exists, retry. First success drives the markdownPreview overlay.
  • Order preserves backward compatibility: legitimate OneDrive - Microsoft\… paths still succeed on the primary attempt.

Tests

Added phantom seam: hard-newline-wrapped no-space path falls back to stripped path on fileRead null to tests/e2e/task-107-md-path-wrap-and-spaces.spec.ts, plus a new installSelectiveFileReadSpy helper that returns content only for the real path. The test asserts both that the primary attempt fires first and that the fallback opens the overlay with the correct path.

Verification

  • Typecheck: same baseline (32 pre-existing errors, no new ones).
  • E2E: cannot run locally on macOS (suite requires a Windows-packaged build); the new test will validate on CI.
  • Manual repro: user confirmed fix before commit.

Ink-based TUIs (Copilot CLI, Claude Code) hard-wrap long paths and emit
the continuation row with layout indent. TASK-132/137's seam-space
heuristic could not distinguish that indent from a wrap-eaten literal
space, so it always inserted a phantom space at the join (.../files/...
became .../fi les/...) and fileRead 404'd silently.

Fix: track each inserted seam-space offset during forward and backward
hard-newline stitching. In activate(), compute a seam-stripped variant
of the matched path and retry fileRead with it if the primary read
returns null. Primary is tried first so OneDrive - Microsoft\... paths
still resolve normally.

Added an e2e regression test plus an installSelectiveFileReadSpy helper
that returns content only for the real path, asserting both the primary
attempt and the stripped-path fallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant