Skip to content

fix(tui): open local file links with the OS handler - #54838

Closed
YidaWeng wants to merge 2 commits into
anomalyco:devfrom
YidaWeng:local-file-links
Closed

YidaWeng wants to merge 2 commits into
anomalyco:devfrom
YidaWeng:local-file-links

Conversation

@YidaWeng

@YidaWeng YidaWeng commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

  • Add openHref / resolveOpenTarget in @opencode/util/open so http(s) links still open in the browser, while absolute paths and local file:// URLs use the OS file handler.
  • Use openHref for TUI transcript link clicks and the shared Link component. Leave openUrl http(s)-only for auth/docs flows.
  • Reject remote file://host/... URLs and non-local schemes, matching desktop's local-file policy.

Fixes #54816

Test plan

  • bun test src/open.test.ts from packages/util
  • Sanity-check resolveOpenTarget for absolute paths, file://, https, javascript, and relative paths
  • Click a Markdown link to an absolute local file in the TUI and confirm it opens with the OS handler instead of the HTTP-only toast

Added by the opencode bot (AI-generated).

Related: #47765

Transcript clicks always went through the HTTP-only browser opener, so
absolute paths and file:// links showed an error toast. Route those
targets through openHref while keeping openUrl strict for auth and docs.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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.

With this change, clicking an absolute local-file Markdown link no longer shows the error toast. I ran the #54816 reproduction script on the base (toast) and with this PR (no toast), and called openHref directly with absolute, file://, relative and ~ paths. bun test src/open.test.ts and the typecheck scripts for util and tui pass. There's no desktop in the sandbox, so I couldn't watch a file actually open.

Public API: no user-facing change. openHref and resolveOpenTarget are new exports of the internal @opencode/util/open (additive).

Concerns:

  • Relative links are still rejected (inline). This is the most common form of file link a model writes.
  • Cmd-click. clickedLink still doesn't skip the meta modifier, so in VS Code or Cursor a Cmd-click is handled here instead of by the terminal. #54816 asks for that, and it's a one-line addition to the modifier check.
  • What one click hands to the OS (inline). This is a policy question for maintainers rather than a blocker.

Related: #47765

Before

After

Comment thread packages/util/src/open.ts
}
}
}
if (path.isAbsolute(input)) return input

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.

Models usually link project files relatively, e.g. [plan](plan/example.md) or src/foo.ts. Those still fail here and end in an error toast, just with different wording, and the test fixes that behaviour in place. Could the TUI resolve relative paths against the session directory before calling openHref, or at least not intercept links it can't handle, so the click falls through to the terminal? Otherwise #54816 is only fixed for absolute paths.

Comment thread packages/util/src/open.ts Outdated
}

/** Open an http(s) URL in the browser, or a local file path / file:// link with the OS handler. */
export function openHref(input: string) {

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.

One plain click now passes a path the model wrote straight to the OS default handler. On Linux that usually opens a viewer or editor. On Windows an .exe or .bat path (and, through path.isAbsolute, a \\server\share\… network path, which openUrl's tests deliberately reject) and on macOS a .command or .app path would be run. The desktop app's shell.openPath behaves similarly, so this may be acceptable. It's worth a maintainer decision, though, on whether the TUI should refuse UNC and executable targets, or only open files that exist. Right now a missing file resolves without any feedback.

Address review feedback on anomalyco#54838: resolve project-relative Markdown
paths before opening, skip any modified click so the terminal can handle
Cmd-click, and avoid toasting when a link cannot be opened.
@YidaWeng

Copy link
Copy Markdown
Author

Thanks for the review — pushed a follow-up that covers the actionable items:

  1. Relative links — resolveOpenTarget now resolves paths like plan/example.md against the session directory (falling back to cwd), and the transcript click handler uses that base.
  2. Modified / Cmd-click — clickedLink now treats any truthy modifier as “leave it to the terminal,” so Ctrl/Alt/Shift/Meta (when reported) are not intercepted. If a link still cannot be resolved, we no longer toast; the click falls through.

On the OS-handler policy point (executables / UNC / missing files): left as-is to match desktop openPath behavior; happy to tighten that in a follow-up if maintainers want a deny-list or existence check.

@Evan-Du-037

Copy link
Copy Markdown

Thanks for working on this. Could TUI local-file links support opening in the same editor as /editor (VISUAL, then EDITOR), rather than only the OS default application?

My use case is clicking an assistant reply such as [file](./data/file.txt) and opening the real file in my configured editor. I use OpenCode 2.0.27 with EDITOR="code --wait"; the editor should not be hard-coded to VS Code.

HTTP/HTTPS handling should stay unchanged, and relative paths should use the session directory. I'm asking about ordinary Markdown links, not a new file menu or automatic linking of bare paths. #48609 requests a similar editor preference for tool titles.

Would editor-first behavior, or an opt-in setting, fit the intended design? I'd like to contribute a focused follow-up once the approach is agreed. Remote-session handling and terminal-editor suspend/resume would need explicit boundaries.

@YidaWeng

Copy link
Copy Markdown
Author

Follow-up for Windows drive-qualified paths (e.g. from kvnloo/opencode#206):

URL.canParse("C:\\..." ) / URL.canParse("C:/...") is true with protocol c:, so those absolute paths never reached path.isAbsolute and resolveOpenTarget returned undefined. That would also break the existing absolute-path unit test on the Windows CI job.

Fix: resolve native absolute paths and drive-qualified paths (^[A-Za-z]:[\\/]) before URL parsing. Added coverage for both slash styles. file:///C:/... and http(s) handling unchanged.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 15, 2026
@github-actions github-actions Bot closed this Oct 15, 2026
YidaWeng added a commit to YidaWeng/opencode that referenced this pull request Oct 15, 2026
Address review feedback on anomalyco#54838: resolve project-relative Markdown
paths before opening, skip any modified click so the terminal can handle
Cmd-click, and avoid toasting when a link cannot be opened.
@YidaWeng

Copy link
Copy Markdown
Author

Reopened as a new PR with the required template sections filled in (this one was auto-closed for compliance). Continuing here: will link the new PR URL next.

@YidaWeng

Copy link
Copy Markdown
Author

Replacement PR with the template filled in: #55769

YidaWeng added a commit to YidaWeng/opencode that referenced this pull request Oct 16, 2026
Address review feedback on anomalyco#54838: resolve project-relative Markdown
paths before opening, skip any modified click so the terminal can handle
Cmd-click, and avoid toasting when a link cannot be opened.
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.

tui: local Markdown file links are sent to the HTTP-only browser opener

2 participants