fix(desktop): open terminal file links the way chat does
Summary
A user reported that file paths in a terminal (TUI agents) do not open the right pane the way they do in chat. Chat carried its link rules inline in useOpenChatLink, so the terminal never got them. This moves each rule to one shared place and has both surfaces use it.
Before/after of every case below, captured in the dev app: https://app.superset.sh/page/terminal-file-links-plain-click-opens-the-file-y1kacs
| Terminal text | Before | After |
|---|---|---|
packages/shared/package.json:2, plain click | "Not bound" hint | Opens in the right pane at line 2 |
shared/package.json:17-33 (shortened path) | Not a link | Resolves to packages/shared/package.json, line 17 |
apps/desktop/package.json#L17 | Not a link | Opens at line 17 |
example.com/docs, ⌘-click | Not a link | Opens as a website |
What changed
- Plain-click default.
withPlainDefault(clickPolicy/tiers.ts) fills an unbound plain click; the file and folder policy hooks apply it. A plain click the user bound in Settings is kept. Chat's inline fallbacks are deleted. - Settings → Files. The plain-click row for file and folder links showed "Do nothing" while chat opened the file anyway. It now shows the real default and no longer offers "Do nothing" for that row. No new strings.
- Path lookup.
useWorkspacePathHostis the one adapter forstatPathandresolveFileReference; chat and the terminal both use it. The terminal asks for the plausible file only for path-like text whose exact candidates all failed, never for single words. - Line locations.
lib/fileLocationparses:12,:12:3,:12-20,#L12,#L12-L20. It replaces two regexes in chat (parseFileHref,pathText) and gives the terminal detector#Lanchors. Chat gains:12-20, which it did not parse. - Schemeless sites.
bareWebUrlmoves tolib/; the terminal detector calls it after the file checks fail. - Drag is not a click. A plain mouse-up that ends a text selection no longer activates the link under it (
terminal-link-manager.ts). Needed now that plain click acts.
Not in this PR
Opening Paradev app links (task, automation, workspace) in-app from the terminal. #9892 covers workspace links and touches the same files, so this will conflict with it in terminal-link-manager.ts, TerminalPane.tsx and useTerminalFolderPolicy.ts.
Validation
- Dev app over CDP: the four rows above, old code and branch, on identical terminal lines; drag-select opens nothing; ⌘-click on a path still opens; Settings rows read "Open in tab" / "Reveal in sidebar".
- Chat links were not clicked through in the app. They share the hooks and parser, and their unit tests pass.
bun testonsrc/renderer/lib,usePaneRegistryandsettings: 5432 pass.biome checkclean. Desktop typecheck clean apart from the local TS1149 path-casing noise in my worktree.- Not measured: the cost of the shortened-path lookup on hover in a very large repo (it reads the host's cached file index).
Summary by cubic
Makes terminal file links behave like chat links: a plain click on a file path now opens it in the right pane at the correct line, and folders reveal in the sidebar, instead of showing the "Not bound" hint.
- Moves chat's inline link rules into shared click policies and one path host, so both surfaces resolve links the same way.
- Resolves paths that don't exist as written to the file they most plausibly mean, asking only for file-like names, never bare words.
- Parses line locations (
file:12,file:12:3,file:12-20,file#L12,file#L12-L20) in one shared module; chat gains the:12-20range form. - Opens schemeless sites like
example.com/docsas web links when they aren't files; a file location that is no file stays unlinked. - Stops a plain mouse-up that ends a text selection from activating the link under it.
- Settings shows the real default for the plain-click row on file and folder links instead of "Do nothing".
Opening Paradev app links (task, automation, workspace) from the terminal is not included; this PR overlaps with #9892, which covers workspace links.
Summary by CodeRabbit
- New Features
- Terminal and chat output now recognize file references with line and column locations, as well as web links in terminal output.
- Plain clicks on file and folder links use default actions: files open in a pane, and folders are revealed in the sidebar.
- Link settings show these plain-click defaults.
- Bug Fixes
- Clicking a terminal link to finish selecting text no longer opens the link; use a modifier key to open it while a selection is active.
- File references with line ranges now open at the starting line.