Repository navigation
feat(tui): carry link destinations through rendering as OSC 8 hyperlinks - #703
Merged
Merged
Conversation
Links in the transcript were parsed and thrown away: `Tag::Link` kept the underline and dropped `dest_url`, so the text looked clickable and was inert. Destinations now travel beside the rendered rows as column ranges and are attached to the ratatui buffer's cells after layout. An OSC 8 sequence is zero-width on screen but its bytes are characters to `Span::width`, so a destination inside span content would be measured as columns and shift every wrapped row after it. Keeping the destination out of the text also keeps it out of the copy path. The underline is now a promise: only destinations that may be emitted get it (`http`/`https`, no control bytes, a real host, under the length cap). The writer re-checks that policy, so no caller can put a `BEL`-carrying destination into an escape sequence by building the struct directly, and the sequence is emitted only for terminals known to render it, resolved once per process, with any multiplexer disqualifying. Streaming answers and table cells do not carry link columns yet; the keyboard picker and the remaining panes follow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Links in the transcript were parsed and thrown away:
Tag::Linkkept theunderline and dropped
dest_url, so link text looked clickable and didnothing. Destinations now travel beside the rendered rows as column ranges
and are attached to the ratatui buffer's cells after layout, so the terminal
owns the click.
Why the destination cannot live in the text
An
OSC 8sequence is zero columns wide on screen, but its bytes are ordinarycharacters to
Span::width. A destination written into aSpanwould bemeasured as columns, and every wrapped row after the link would land in the
wrong place - a direct hit on the 80x18 layout invariant (§4.10). Keeping the
destination out of the text also keeps it out of the copy path:
Linerows arewhat selection and
visible_conversation_copy_rowsread.So the carrier is a column range per row (
links::HyperlinkLine), remapped atevery step that moves text: markdown wrapping (a wrapped link becomes a range on
each row it occupies), the transcript assembly, the plan dock swap, and the
assistant message indent.
The destination is model output going into an escape sequence
FORGE-DESIGN.md§9 already states the rule forOSC 9notifications - "Textis sanitized, not trusted... an embedded
ESCorBELwould terminate thesequence early and leave the remainder to be read as terminal commands" - and
OSC 8inherits it. Three layers:links::destination_for):http/httpsonly, no control bytes,no whitespace, a real host, 2 KiB cap. Rejecting rather than repairing: a
control byte in a URL is corruption or an injection attempt, and "this is not
a link" is the honest reading of both.
mark_buffer_hyperlinks).TerminalHyperlinkisconstructible by any caller, and this is the function that writes bytes to the
terminal, so a struct cannot be the only gate.
underline, because an affordance that cannot be acted on is worse than none.
The sequence is emitted only for terminals known to render it, resolved once per
process from
TERM_PROGRAM, and any multiplexer disqualifies (tmuxbefore 3.4cannot forward hyperlinks, and
TERM_PROGRAMnames the outer terminal inside oneeither way). Unknown terminals degrade to exactly today's rendering. No hint row
advertises a click, because the binding's availability is not Forge's to promise.
Deliberately not in this change
a bare URL in tool output stays prose. No detection, no false positives.
still-streaming answer joins when the block settles; a table cell link keeps
its underline, because
render_tablere-lays cells out against its owngeometry. Both are follow-ups, not regressions.
click for terminals where the click works, for the cost of a command surface.
Verification
cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --locked -- -D warningsclean; theforge-tuilib suite is green apart from fivefailures that reproduce on the pre-change tree (
git stashon the base commit),three of them the sandbox-unavailable background-task tests that CI exercises
with bubblewrap.
New tests pin the claims rather than the implementation:
assembly -> paint path, lands as an OSC 8 sequence over exactly the cells the
label occupies;
BEL-carrying destination produces no escape bytes even whenthe struct is built directly;
marking_stops_at_the_pane_edge, so a clipped link cannot push an escape intothe next row;
FORGE-DESIGN.md§9.4 gains the three rules this ships.Known unknown
The load-bearing assumption was not verified outside this container: that
Cmd-click on an
OSC 8link still reaches the terminal while Forge holdsEnableMouseCapture(app/shell.rs). Worth one manual check in Ghostty oriTerm2 before merge.