Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
The link routing works, but as submitted this PR stops the TUI from starting.
App() in packages/tui/src/app.tsx already declares const paths = useTuiPaths() further down (line 697), so the new declaration at line 461 is a redeclaration. Running OpenCode from this branch fails with SyntaxError: Identifier 'paths' has already been declared, and bun run typecheck in packages/tui fails with TS2451. The branch is up to date with dev, so this isn't caused by an out-of-date base.
How I checked: I ran the reproduction from #54816 with an absolute link (/tmp/example.md) and a relative one (plan/example.md). On dev both clicks show the "Only http and https links" error notice. On this branch the TUI wouldn't start. With the duplicate line removed locally, neither click shows an error notice, and both paths reach the system opener, the relative one resolved against the session directory. The open.test.ts and link.test.tsx tests pass.
Public API: unchanged. The new openHref and resolveOpenTarget are internal to @opencode/util.
|
AI-assisted independent resolver check of The seven owning Please cover encoded relative hrefs and fragments before treating session-relative Markdown routing as complete. The relative branch currently calls These checks import the actual utility source; they do not exercise renderer normalization, launch an OS handler, or establish a full TUI/typecheck/suite pass. No production code was changed. reviewed and tested locally. |
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.
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.
URL.canParse treats C:\ and C:/ paths as scheme "c:", so resolveOpenTarget returned undefined before path.isAbsolute. Check native absolute and drive-qualified paths first, and cover both slash styles in tests.
App already calls useTuiPaths later; the second binding broke startup with a redeclaration SyntaxError / TS2451. Keep one paths and define linkBase next to it.
Percent-escaped session-relative Markdown links and #fragments were passed through path.resolve as literal filenames. Decode URI spelling and strip fragment/query so plan%20notes.md#section opens plan notes.md, while literal % and # stay reachable via %25 and %23.
70857a2 to
fb6fe74
Compare
pedro757
left a comment
There was a problem hiding this comment.
Reviewed fb6fe74 on Linux with Bun 1.4.4. I recommend fixing the absolute-href normalization bug below before merging; confirmed through a real OpenTUI click, an existing-file check, and four added utility regression cases. No production code was changed.
Web compatibility: production build and app typecheck pass; built Chromium E2Es for artifact-link reopening and image preview/zoom/pan/reset both pass. The GUI file-link resolver (32 tests), shared Markdown image/session-link/inline-code helpers (71 tests), and desktop URL policy (2 tests) also pass. The web/desktop opening paths are unchanged and do not import this utility; none of the 1,460 generated web JavaScript source maps includes it or TUI sources. Existing HTTP-only openUrl behavior is unchanged.
The PR's original 9 utility tests and original TUI click test pass (the latter also passed 10 consecutive runs). Full verification is not green: an existing photon-node patch blocks a full install/TUI dependency check, and broader Bun GUI suites hit missing solid-js jsxDEV exports. No Windows/macOS runtime verification.
Absolute Markdown hrefs early-returned before decodeHrefPath, so /tmp/mobile%20menu.png and /tmp/plan.md#section were passed to the OS literally. Apply the same URI decode and fragment stripping used for relative hrefs; leave openPath and openUrl unchanged.
|
Thanks @pedro757 — addressed the P2 in a follow-up commit. Absolute Markdown hrefs (including drive-qualified ones) now go through `decodeHrefPath` the same way relatives do, so `/tmp/mobile%20menu.png` and `/tmp/plan.md#section` open as `/tmp/mobile menu.png` / `/tmp/plan.md`. `openPath` and `openUrl` are unchanged. Added regression coverage in `packages/util/src/open.test.ts`. |
There was a problem hiding this comment.
The earlier blocker is fixed: the duplicate paths declaration is gone and the TUI starts again.
I re-ran the #54816 reproduction against the current base, adding a relative link with an escaped space and a fragment (plan/my%20plan.md#top). On dev, clicking either link shows the "Only http and https links" error notice. With this PR there's no error notice, and the system opener receives /tmp/example.md and <project>/plan/my plan.md, so the new decoding works as intended. open.test.ts (10 tests) and link.test.tsx pass. tsgo shows no errors in the changed files.
Public API: unchanged. openHref and resolveOpenTarget are internal to @opencode/util.
No new concerns.
|
Tried this and the Markdown-link case works well for me. One gap I hit: agents mostly print bare paths in plain text (no link behind them), e.g. I have this working on a fork (resolves plain-text paths, joins wrapped rows, only opens if the file exists, and refuses |
|
@moritzWa Thanks! |
|
@rekram1-node could you take a look at this when you get a chance? Checks are green, the author addressed both rounds of review feedback on Oct 27, and the bot review says no new concerns. It's been waiting on a maintainer review since. It fixes #54816. |
pedro757
left a comment
There was a problem hiding this comment.
Reviewed 99248fe. Found a remote-path policy gap and an ineffective Meta-click regression test; details are inline.
Verification: bun test src/open.test.ts in packages/util passes all 10 tests, and bun test --timeout 30000 test/ui/link.test.tsx in packages/tui passes its test. A targeted UNC-rejection regression fails. Additional real OpenTUI renderer probes confirm that the UNC Markdown href reaches the resolver unchanged and that the mock mouse discards Meta. Windows path classification was checked with Node's path.win32; no native Windows/macOS opener or full-workspace verification was performed. No production code was changed.
Reject //server/share and \\server\share targets, including percent-encoded spellings, before they reach the OS handler. file URL paths that decode to a UNC target are rejected the same way.
The OpenTUI mouse mock only reports shift/alt/ctrl, so a meta option was silently dropped and the guard went untested. Cover every modifier directly, including meta, and drop the ineffective mock option.
# Conflicts: # packages/tui/src/ui/link.tsx
|
Follow-up pushed in d2850d1 (also merged current
Verification:
Public API is unchanged; the new policy only applies to |
|
Folded in the follow-up from YidaWeng#1 (andy-takker) and merged current
Verification:
|
pedro757
left a comment
There was a problem hiding this comment.
Reviewed c4cd204. One remaining P2 in remote-path rejection; details inline. The earlier findings are addressed.
Verification on Linux with Bun 1.4.4: 11 utility tests pass; the 4 affected TUI tests pass and five repetitions pass 20/20. bun run check passes all 35 tasks, none cached. An additional real OpenTUI Markdown-click regression fails because the mixed-separator target reaches the intercepted OS launcher. Windows path classification was checked with path.win32; no native Windows/macOS opener execution or full test-suite run. No production code was changed.
|
|
||
| /** Paths that reach a remote SMB share or a Windows device namespace instead of a local file. */ | ||
| function isRemotePath(value: string) { | ||
| return value.startsWith("//") || value.startsWith("\\\\") |
There was a problem hiding this comment.
[P2] Reject mixed-separator UNC prefixes after decoding
isRemotePath only recognizes identical separator pairs, but Windows also treats mixed leading separators as UNC. For example, resolveOpenTarget("/%5Cserver/share/report.md", base) returns a path beginning with / followed by \, and path.win32.toNamespacedPath classifies it as \\?\UNC\server\share\report.md. This helper is called by the shared TUI on Windows as well, where open forwards the target to PowerShell Start, so the new local-file policy still permits a remote SMB target. A real OpenTUI Markdown-click probe preserves this encoded href and hands the decoded path to the intercepted launcher; a rejection regression fails. Please recognize mixed pairs too (including after decoding), and add regression coverage. Native Windows launching was not exercised.
pedro757
left a comment
There was a problem hiding this comment.
One additional, nonblocking P3 in the new test's WSL launcher expectation. This is a test-portability issue, not a defect in the production opener. Reproduced on Linux by preloading a Microsoft/WSL kernel-release value and SSH_CONNECTION before importing the real app and opener; both new app-link cases fail with the OS launcher intercepted. No native WSL execution or production-code changes.
| function expectLaunch(launch: { command: string; args: readonly string[] }, target: string) { | ||
| // `open` launches Windows PowerShell on both Windows and WSL; only the path conversion differs. | ||
| if (process.platform === "win32" || isWsl()) { | ||
| expect(path.basename(launch.command).toLowerCase()).toBe("powershell.exe") |
There was a problem hiding this comment.
[P3] Account for the supported WSL Linux-launcher fallback
A Microsoft kernel release does not guarantee that open selects PowerShell. The pinned [email protected] only enables Windows integration in WSL when it is outside a container, outside SSH, and PowerShell is accessible; otherwise it deliberately uses xdg-open. This assertion therefore makes both new tests fail in valid WSL-over-SSH environments, WSL without Windows integration, and containers running on a Microsoft kernel, even though the target is handed to the correct launcher. Reproduced by preloading os.release() = "6.6.87.2-microsoft-standard-WSL2" and an SSH_CONNECTION before imports: both cases fail here with expected powershell.exe, received xdg-open. Please account for the dependency's supported fallback conditions, and assert the target arguments for whichever valid launcher is selected rather than assuming WSL always means PowerShell. This reproduction simulates the environment signals; it was not run on native WSL.
|
One Windows case for #54816 is the reverse of the WSL launcher case already tested: the TUI runs natively on Windows, but the before/after screenshots in the assistant’s reply live in a WSL distro on the same machine. Clicking a screenshot link produced the Example with a placeholder path: Reading Could this case get a Windows-side test for opening the image or revealing its folder in an installed local WSL distro, while keeping arbitrary network shares blocked? If that’s outside this PR’s scope, a Copy Windows path action on the error would still let us inspect the screenshots. |




Issue for this PR
Fixes #54816
Type of change
What does this PR do?
Clicking a local file Markdown link in the TUI always went through the HTTP-only opener, so absolute paths and
file://links showed an error toast.This adds
openHref/resolveOpenTargetso http(s) still opens in the browser, while absolute paths, Windows drive paths (C:\/C:/), localfile://URLs, and session-relative paths open with the OS handler. Remotefile://host/...and other schemes stay rejected. Modified clicks (Cmd/Ctrl/etc.) are left to the terminal.Relative links also resolved against the launch directory while the session's Location metadata was still loading.
linkBasenow uses the route'slocation.refbeforepaths.cwd, so a click during that window still resolves against the session directory.How did you verify your code works?
bun test src/open.test.tsinpackages/util(absolute paths, both Windows slash styles,file://, https, relative paths, unsafe schemes)bun test test/app-links.test.tsinpackages/tui— 2 passed (loaded and pending Location metadata);--rerun-each 5— 10/10 passedbun test test/ui/link.test.tsxinpackages/tui— 2 passed (modifier guard)openbun run checkfrom the repository root — 35/35 tasks passedutil/tuion the change setScreenshots / recordings
Covered in the earlier review thread on this PR (before toast / after no toast).
Checklist
Added by the opencode bot (AI-generated).
Related: #51756, #47765