Skip to content

feat(tui): add a basic path picker for the last response - #60178

Open
spaxe-dev wants to merge 4 commits into
anomalyco:devfrom
spaxe-dev:path-picker-1-basic
Open

spaxe-dev wants to merge 4 commits into
anomalyco:devfrom
spaxe-dev:path-picker-1-basic

Conversation

@spaxe-dev

@spaxe-dev spaxe-dev commented Oct 29, 2026 •

Copy link
Copy Markdown

This is part 1 of 5. Part 2 adds multi-select, part 3 recognizes more path forms (Windows and UNC paths, file:// URLs, quoted paths, Markdown links, inline code), part 4 styles the tags with red selection dots, and part 5 adds a storybook story. Parts 2 to 5 open as this one merges, so each PR has a clean diff against dev.

Issue for this PR

Part of #60175. The final part will close it. Related: #58242, #54816, #55769, #48609. This is keyboard driven, so it does not implement #58242 as filed. It does not change Markdown link handling (#55769) or tool header rendering (#48609).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Agent responses usually end with a list of files. In the TUI those paths are plain text, so getting to one means selecting and copying it. This adds /paths (and <leader>f): it numbers the paths in the last completed assistant response and opens the number you type.

It covers relative paths, ./ and ../, absolute POSIX paths, directories, and optional :line or :line:column suffixes. Fenced code, inline code, Markdown links, URLs, and angle-bracket text are left alone. Relative names that do not exist stay plain text. A missing explicit path is numbered only when it is relative, names a file extension, or its first absolute directory exists, so a broken /tmp/report.md can be selected and reported while prose such as /goal or /api/users stays plain text.

Opening prefers $VISUAL or $EDITOR and passes the line and column in the syntax the editor understands (--goto, file:line:column, +line). Without an editor, files go to the OS handler, directories to the file manager, and executable types are refused with a message instead of being launched. Terminal editors suspend the renderer until they exit. An editor that is not a known GUI editor is treated as a terminal editor, and known GUI editors launch detached with their output ignored, so neither can write over the TUI.

Type a number to open it. If one number is a prefix of another (1 and 12), the picker waits 600 ms before opening so typing 12 does not open 1. backspace edits the number, enter opens it, and esc closes the picker.

Tags are inserted after the path with a space so the number reads as a tag and the Markdown stays intact. Rendered Markdown writes the tag as [[1]], which conceals to a bracketed [1] with link styling; source mode keeps the plain [1]. Only the last completed assistant response is tagged, so an earlier response with identical text stays unchanged.

The feature is behind a command and a keybinding, so it adds no work to the normal transcript path until the picker is opened.

Worked example. The response ends with:

Updated out/report.md and src/app.ts:12. Notes are in ./docs/.

Running /paths renders:

Updated out/report.md [1] and src/app.ts:12 [2]. Notes are in ./docs/ [3].
● Paths 3 · type a number · esc close

Typing 2 opens src/app.ts at line 12. When a number is also the prefix of a longer one, the bar previews the shorter path while the 600 ms timer runs, for example ● Paths #1 · out/report.md · enter open · backspace edit · esc close.

A missing explicit path such as /tmp/not-there.md gets a number. Choosing it shows Path not found: /tmp/not-there.md. A missing rooted directory without an extension, such as /tmp/not-there, is numbered only when its first directory exists.

How did you verify your code works?

Automated, from the affected package:

cd packages/tui
bun test --timeout 30000 test/file-links.test.ts test/editor.test.ts test/path-links.test.ts
bun run typecheck:tsc

That run: 26 pass, 4 skip, 0 fail. The skips are platform-specific editor tests that need a POSIX executable bit or a terminal editor. Typecheck passes.

Full TUI suite on this branch: 1564 pass, 19 skip, 7 fail. All seven failures are EPERM: operation not permitted, symlink in test fixtures that copy plugins or create watcher helpers, which this Windows machine cannot create without developer mode or elevation. The same seven tests fail identically on a clean origin/dev checkout here.

Coverage added:

  • scanner and resolver: relative paths, directories, line and column suffixes, dot-segment normalization, explicit missing paths, slash commands and filesystem roots staying plain text, missing rooted directories gated on their first segment, repeated paths reusing one number, numbering across parts, multi-digit disambiguation, marker spacing and formats, fenced code, URLs, code spans, links, and missing relative names
  • editor: command splitting, quoted executables, per-editor line and column arguments, unknown editors keeping the terminal, GUI editors leaving it, missing paths, launchable refusal, terminal editor suspend and resume
  • session route: only the last completed assistant response is tagged when an earlier response has identical text, and the rendered tag keeps its brackets

Manual check:

  1. Start the TUI with EDITOR set to an editor. Terminal editors suspend the renderer until exit.
  2. Ask the agent to write several files, then run /paths.
  3. Type a number to open it. Try a two-digit number that shares a prefix with a one-digit number.
  4. Try a missing absolute path such as /tmp/not-there.md: it gets a number and reports that it does not exist. Try /goal in prose: it stays plain text.

Visual

Path tags appearing after each path, then the picker bar

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="currentColor" font-family="ui-monospace, SFMono-Regular, Menlo, monospace">
  <style>
    .tag { animation: tag 2.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
    .bar { animation: bar 2.8s ease-in-out infinite; }
    .caret { animation: caret 1.4s steps(1) infinite; }
    @keyframes tag { 0%, 10% { opacity: 0; transform: scale(.8) } 28%, 84% { opacity: .9; transform: scale(1) } 100% { opacity: 0 } }
    @keyframes bar { 0%, 18% { opacity: .35 } 36%, 90% { opacity: 1 } 100% { opacity: .35 } }
    @keyframes caret { 50% { opacity: 0 } }
  </style>
  <text x="12" y="24" font-size="11" opacity=".45">Updated</text>
  <text x="68" y="24" font-size="11">out/report.md</text>
  <g class="tag"><text x="158" y="24" font-size="11" font-weight="700">[1]</text></g>
  <text x="12" y="40" font-size="11" opacity=".45">and</text>
  <text x="34" y="40" font-size="11">src/app.ts:12</text>
  <g class="tag" style="animation-delay:.15s"><text x="124" y="40" font-size="11" font-weight="700">[2]</text></g>
  <g class="bar">
    <rect x="12" y="50" width="216" height="1" opacity=".15"/>
    <text x="12" y="66" font-size="9" opacity=".85">● Paths 2</text>
    <text x="62" y="66" font-size="9" opacity=".55">· type number · esc</text>
    <rect class="caret" x="178" y="58" width="5" height="9" opacity=".5"/>
  </g>
</svg>

Screenshots / recordings

The /paths picker open, with numbered paths and the picker bar

Picker open on a completed response. Each existing path gets a number, and the bar shows the count and the available keys.

The picker bar reporting No path 9 after an invalid number

An invalid number reports No path 9 in the bar instead of opening anything.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #60175, #58242, #48609, #54816, #48648

Public API: adds the /paths slash command and the session.file_links keybind (default <leader>f) (backwards compatible)

Scan the last completed assistant response for relative and POSIX paths
with optional line and column suffixes, number them, and open one by
typing its number from /paths or <leader>f. Files open in $VISUAL or
$EDITOR at the requested line; directories open in the file manager,
and launchable file types are never handed to the OS default handler.

@opencodejr opencodejr 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.

The picker works as described. I ran it from source with the simulated model. /paths numbered the paths in the last response, typing 2 opened src/app.ts through $EDITOR, and a missing rooted path gets a number. The scanner and editor tests pass (25 pass, 1 skip), and tsc -b is clean.

Public API: this adds the /paths slash command and the session.file_links keybind (default <leader>f). Both are new, so it is backwards compatible. No SDK, server or plugin API changes.

The interaction is still under discussion in #60175: command name, keybinding, in-transcript numbering and the five-part split. No maintainer has decided it yet, so the design may still change.

Things worth fixing, in more detail inline:

  • Editors that are not on the terminal list run while the TUI renderer is still active. That garbles the screen for any terminal editor missing from the list.
  • GUI editors inherit the TUI's stdio, so anything they print lands in the TUI's terminal.
  • Any /word counts as an explicit path. Slash commands such as /goal get numbered and then report "Path not found". I saw this when I ran it.

Two smaller points. First, [1] tags are parsed by the Markdown renderer as reference links, so they show as underlined 1, not [1]. Second, mark() matches parts only by text:N and the text, not by message. An earlier message with exactly the same text would get tags too.

Related: #60175, #58242, #48609, #54816, #48648

Before

After

Comment thread packages/tui/src/editor.ts Resolved
Comment thread packages/tui/src/editor.ts Resolved
Comment thread packages/tui/src/util/file-links.ts Resolved
Treat only known GUI editors as detached so an unrecognized $EDITOR cannot
write over the active TUI, and ignore the output of detached launches.
Require a file extension, a relative token, or an existing first directory
before numbering a missing explicit path, and reject bare roots, so prose
like /goal or /api/users no longer reports as a broken path.
Key detected parts by message so an earlier response with identical text
stays untagged, and write rendered tags as [[n]] so conceal mode keeps the
brackets instead of turning them into link markup.
@spaxe-dev

Copy link
Copy Markdown
Author

Both smaller points are fixed in 56ab60a:

  • Rendered tags are written as [[1]], so conceal mode keeps the brackets and shows [1] with link styling. Source mode stays [1].
  • mark() is keyed by message and part, so an earlier response with identical text stays untagged. A new session-route test asserts exactly one tag when two responses share the same text.

Inline threads have replies with the commit for each fix. Screenshots and the PR body are refreshed too.

Focused tests: 26 pass, 4 skip, 0 fail. Full TUI suite: 1564 pass, 19 skip, 7 fail, where all seven are the pre-existing Windows symlink EPERM failures.

@opencodejr opencodejr 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.

All three earlier points are addressed:

  • Editors that are not known GUI editors now suspend the renderer.
  • GUI editors start detached, with stdio ignored.
  • A missing explicit path is numbered only when it has an extension, is relative, or its first directory exists, so /goal and /api/users stay plain text.

Tags are now scoped to the last response by message ID and render as [1]. I checked this again in the TUI: /goal is no longer tagged, /tmp/not-there.md still is, and an unknown $EDITOR opens the file with the TUI suspended and then restored. The scanner, editor and new path-links tests pass (29 pass, 1 skip), and tsc -b is clean.

The public API has not changed since the last review: it adds the /paths command and the session.file_links keybind (<leader>f), which is backwards compatible. Nothing new worth blocking on. The interaction is still being discussed in #60175.

Before

After

@spaxe-dev

Copy link
Copy Markdown
Author

All three review points are fixed in fac6911c68, 803a721dac, and 56ab60abd2. I resolved the inline threads since each one has a reply with its commit.

  • Unrecognized editors keep the terminal and suspend the renderer (fac6911c68).
  • GUI editors spawn detached with stdio ignored, so their output cannot reach the TUI (fac6911c68).
  • Missing explicit paths are numbered only when they are relative, have a file extension, or their first absolute directory exists, so /goal, /api/users, and / stay plain text (803a721dac).
  • Tags are scoped to the last completed response by message ID and render as [1] (56ab60abd2).

Head 56ab60abd2: check-standards and check-compliance pass. Focused tests: 26 pass, 4 skip, 0 fail. tsc -b is clean. The full TUI suite is 1564 pass, 19 skip, 7 fail, where the seven are the pre-existing Windows symlink EPERM failures.

This is ready for maintainer review. The open interaction questions (command name, <leader>f as the default binding, in-transcript tags, directory behavior, multi-select cap, five-part split) are in #60175. Parts two to five are prepared locally and open on top of this one after there is direction on those questions.

This branch has not been deployed

No deployments
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