Repository navigation
fix(native-chat): link a bare file name once the chat's folder has it - #28818
Conversation
…as it An agent's reply naming a file it created in its own folder, e.g. `decision-explainer.html`, stayed plain inline code: chat required a slash before it would even ask the host whether the path exists. Every chat agent runs in one known folder (the host's launch directory, which chat already resolves its links against), so a bare name the terminal's bare-word detector accepts now goes through the same host existence check and links only when the file is there. Version-like names (v1.2) and spaced names are still never asked about. Fixes STA-10392
Bare names with a dot now pass chat's existing inline-code shape rule, so v1.2.3 and 1.0 stay plain as on main.
Review status: ready for merge review (code reviewed, QA passed, CI green on 15ae03a)The problem. In the Chat UI, OpenCode created What changes for users. In a chat reply, a file name written as code on its own ( What review changed (four rounds of fresh reviewers plus an architecture challenge):
Deferred, labelled in the PR body:
Verified:
Not verified by hand: SSH, WSL and Windows chats. They use the same resolve-and-check path #26675 verified, and this PR doesn't change it. A remote host's click on a folder named like a file was not exercised live. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
ELI5
An agent in a chat made a web page,
decision-explainer.html, and its reply named the file in a code span. You couldn't click the name to open it, because chat only made file names clickable when they had a folder in front (src/x.htmlor./x.html). Now a plain file name written as code becomes clickable too, but only when that file really exists in the chat's folder.What Changed
The problem (STA-10392). OpenCode in the Chat UI created
decision-explainer.htmlin the workspace root and replied "Done.decision-explainer.htmlis in the worktree root". The name showed as plain code: no underline, no click, no way to reach the HTML preview from the reply. This happens for every chat agent, not just OpenCode. Chat's link rule (isLinkifiableFileincomment-markdown-native-chat-file-links.ts) threw out any candidate without a/or\before asking whether the file exists. #26675 did that on purpose, because it wasn't clear which folder a bare name refers to.Chat does know the folder. Every chat agent runs in one fixed folder, and Orca already knows which one. Claude, Codex, the ACP agents (OpenCode, Grok and others) and Pi all launch through
resolveAgentSessionLaunchDirectoryon the host, and the chat window works out the same folder (resolveNativeChatTabDirectory). Chat already resolves./x.htmlandsrc/x.tsagainst it and asks the host that owns the chat (this computer, an SSH host or a paired Orca server, with WSL paths mapped first) whether they exist. Unlike a terminal, a chat agent's folder never changes withcd, so a bare name has one meaning: the file in that folder.What is different for you (desktop chat only):
decision-explainer.htmlin a code span, and the file exists in the chat's folderpackage.json,Makefile:7in a code span, when they exist therenot-here.htmlin a code span (doesn't exist)v1.2.3,1.0,glm-5.3in a code span, even if something by that name existspackage.jsonor"decision-explainer.html"in ordinary prosesrc/a.ts) and explicit linksThe mechanism.
Makefile). A name with a dot must also pass the shape rule chat already applies to code spans with a slash: a letter-led extension or a:linesuffix. That one rule is what keepsv1.2.3andglm-5.3plain for bare names and slash paths alike. Such a name then takes the existing route: resolve against the chat's folder, ask the host with the existing yes/no existence check (batched, cached per chat, not while the reply is still streaming), and underline only if the host says it is there. The click handler already opened bare names correctly; it never got the chance.native-chat-file-link-existence.tskeeps answers for names still shown on screen beside its 1,024-entry cache instead of inside it. Before, a chat showing more names than that pushed shown answers out, and they were checked again on every render. Answers move back into the cache when nothing shows them any more.Why
Node.js,e.g.); checking each would cost a lookup per word, often over SSH, for almost no benefit. Admitting only the whole span also matches the common pattern for linking code spans.\\server\sharepaths without a click is unaffected.packages/athat namespackage.jsonlinks the rootpackage.jsonif one exists, which is also what the agent's own tools open for that name.console.log,process.env) now each cost one existence check per chat. Checks are batched and cached, and these stay plain unless a file by that name exists in the chat's folder.Button.tsxliving insrc/components/stays plain. Searching subfolders would guess between same-named files.archive.7z,libfoo.so.1) stay plain, both bare and assrc/archive.7z, as on main. Fixing this belongs in one change to the shared shape rule for both spellings.docs.html/) can be underlined, and on a remote host the click can do nothing. Slash paths already behave this way on main; the follow-up is a file-or-folder answer from the host.Linked Issue
Fixes STA-10392
Visual Proof
Recorded on a second Mac in hidden Orca windows (each with a throwaway home), built from
mainand from this branch at15ae03a, with real OpenCode 2.0.21 and the same reply on both. The chat folder helddecision-explainer.html,package.json,Makefile,src/a.ts, a folder namedv1.2.3and a file named1.0. The reply was: Done.decision-explainer.htmlis here. AlsoMakefile:1,package.json,not-here.html,v1.2.3,1.0,glm-5.3,src/a.ts. In prose: package.json and "decision-explainer.html".Before (main): only
src/a.tsis underlined.After (this branch):
decision-explainer.html,Makefile:1,package.jsonandsrc/a.tsare underlined.not-here.html,v1.2.3,1.0andglm-5.3stay plain even thoughv1.2.3and1.0exist, and so do the prose and quoted names.After, clicking
decision-explainer.htmland choosing Open file: the page opens in Orca's HTML preview.Whole windows
Testing
CommentMarkdown.link-click.test.tsxanduse-native-chat-file-link-click.test.tsx(63 tests) pass: the ticket's reply linksdecision-explainer.htmlandMakefile:7and clicking opens<chat folder>/decision-explainer.html; prosepackage.jsonand folders stay plain; the existing "numeric versions stay plain even when they exist" test passes unchanged.native-chat-file-link-existence.test.tsadds one test: more shown names than the cache holds are not checked again on re-render.CI runs lint, typecheck and the full suite on the head commit.
Manual: hidden-window comparison of
mainand this branch on macOS with real OpenCode, as in Visual Proof above. Sending, the tab and the Working/Done status matchedmain.Not run by hand: SSH, WSL and Windows. They use the same resolve-and-check path fix(native-chat): underline a file path only once its workspace confirms it exists #26675 verified, unchanged here.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Four rounds of adversarial review, each by fresh reviewers, plus an architecture challenge that weighed the design against the common pattern. Findings, fixes and what is deferred are in the status comment below.
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author: Brennan Benson (@BrennanKB5)