feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开 #320
@pullfrog review
✅ No new issues found.
Reviewed changes
parseChatCodeLink handles local file:// URIs, absolute/relative paths, :line, :line:col, :start-end, #L/#Lx-Ly/#LxC/#x-y fragments and #heading, preserves rawPath for literal-colon filenames, and rejects external/unsafe/remote schemes, pure fragments and null bytes. Shared isExternalLink matches the previous external set.data-md-*, then emits data-md-href with role="link"/tabindex="0" after sanitization; click and Enter route through onopenlink. Link styling moved to a[href]/a[data-md-href] so inert anchors no longer look clickable.locations, and resource_link blocks are now navigable; diff rows still open diff mode.CodeReveal fields (mode, rawPath, fromUri, line range, heading) flow through CodePanel, the pop-out channel and CodeWorkspace; candidate resolution covers cwd-relative, repo-root fallback, literal-colon fallback and the artifacts root, and openFileInOrigin threads contextId for cross-root tabs.CodeDocumentView applies jump after the version/diff resets and CodeReader.revealLine handles pre-placement requests, pending restore selection and column scrolling; placeInitial now retries until layout exists.I traced the parser guards, sanitizer hook ordering, Svelte effect ordering (version/diff resets before the jump effect), tab-key/context matching in CodeWorkspace, the pop-out handshake ordering, and the reader placement/selection paths; I found no defect that changes behavior. I did not run the frontend suites in this environment (dependencies absent), so the PR's test claims were not independently re-executed.
<!--
Pullfrog review metadata. These findings were written against 338d101;
if commits have landed on wt/vivid-cedar since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.
- 338d101 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
-->
<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a> | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>
✅ No new issues found.
Reviewed changes (since the prior review of 338d101)
main (40ab241, includes #315): verified with range-diff and a direct patch comparison that every web/src, web/test, web/stories, and openspec/specs/chat-view/spec.md hunk is identical to the previously reviewed version; only hunk line offsets and blob ids changed. No source behavior changed.docs/user-stories.md date-range edit is dropped (#315 already set the range to 2026-11-05), and the 2026-11-05 chat-link entry is appended after #315's attention entry in the verification log, with the E2E line updated to full hybrid.spec.ts (45 passed).ToolRow.svelte now carries both #315's status styling and this PR's ListButton/onopenlocation additions without duplication; ChatView.test.ts keeps its new link test alongside #315's attention assertions.The prior review's conclusion stands: no defect found in the parsing, sanitizer, reveal/placement, pop-out forwarding, or tab-resolution paths. I did not run the frontend suites locally (dependencies absent), so the test claims were not independently re-executed.
<!--
Pullfrog review metadata. These findings were written against 7b14be8;
if commits have landed on wt/vivid-cedar since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.
- 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
-->
<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a> | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>
When the target file tab is currently showing a comparison (compare() set mode = "diff"), this new mode = "file" write dirties shownDiff, so the pre-existing reset effect at line 289 runs later in the same flush and sets formatView = "source" and generation++. The tick() callback then finds markdownPreview unmounted, so a #heading link silently leaves the file at the top in source mode. This affects both chat heading links and the existing document-preview heading links.
<details><summary>Technical details</summary>
# Heading jump clobbered by the shownDiff reset effect
## Affected sites
- `web/src/components/CodeDocumentView.svelte:326` — `mode = "file"` dirties `shownDiff` (`:111`)
- `web/src/components/CodeDocumentView.svelte:289-310` — reset effect sets `formatView = "source"` and `generation++` whenever `shownDiff` changes
- `web/src/components/CodeDocumentView.svelte:331` — `tick()` then calls `scrollToHeading` on an absent preview
- `web/src/components/CodeWorkspace.svelte:1007-1008` and `:484-486` — both set `tab.heading` on the file tab
## Required outcome
- A `#heading` link must switch the target file tab to the Markdown preview and scroll to the slug even when the tab was previously in comparison/diff mode.
- Keep the reset effect's behavior for genuine document/side changes; do not weaken it globally.
## Suggested approach (optional)
- Let the reset effect settle before calling `showFormat("preview")` (e.g. call it inside a `tick()` callback, then wait one more tick for `CodeMarkdownPreview` to mount before `scrollToHeading`).
- Add a browser test that opens a changed Markdown file, enables compare, then requests a heading link.
## Open questions for the human
- Is the compare-mode case in scope for this PR, or should heading links intentionally stay in source mode when a comparison is open?
</details>
ℹ️ No critical issues — one behavioral gap and one design question below.
Reviewed changes
Reviewed the chat code-link feature end to end: parsing, sanitized rendering, tool-location links, code-workspace reveal resolution, reader line/column jumps, pop-out forwarding, and the accompanying tests/docs.
parseChatCodeLink/isExternalLink handle local file:// URIs, absolute/relative paths, :line suffixes and #L/heading fragments, rejecting unsafe schemes, remote hosts and bare anchors.hrefs, re-adds validated links as data-md-href with click/Enter activation, and keeps external links target="_blank" rel="noopener noreferrer".ToolRow/TimelineItem open locations and resource_link entries in the code browser through new ListButton link variants.CodeWorkspace resolves workspace/root/rawPath/artifacts candidates and forwards CodeReveal through the pop-out MessagePort.CodeReader.revealLine scrolls/selects line ranges and columns, with deferred placement for readers that are not yet mounted.<!--
Pullfrog review metadata. These findings were written against 7b14be8;
if commits have landed on wt/vivid-cedar since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.
- 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
-->
ℹ️ Relative-path base is ambiguous between the session cwd and the repo root
revealCandidates tries the link path against the session cwd first and only falls back to the repo-root form when that lookup misses. If a same-named file exists under the cwd, it opens that file (and selects the requested line in it) even when the link was meant to be repo-root-relative. The new test only covers the case where the cwd-relative lookup returns 404, so the shadowing case is untested and the precedence is not documented.
<details><summary>Technical details</summary>
# Relative-path base precedence
## Affected sites
- `web/src/components/CodeWorkspace.svelte:878-899` — candidate order is `target.path`, then `${rootPrefix}/${target.path}`, then rawPath
- `internal/codeview/navigation.go:276-288` — `Locate` resolves relative inputs against `ReportedCwd` (OSC 7) or the launch cwd
- `web/src/components/CodeWorkspace.svelte:869` — the comment "Revealed paths resolve against the workspace first" can be read as the opposite precedence
## Required outcome
- Decide and document which base relative chat links use (agent/session cwd vs repo root), and make the candidate order match.
- If cwd-first is intentional, note the shadowing behavior in the docs/story; if root-first is intended, swap the candidate order.
## Open questions for the human
- Which base should win when both a cwd-relative and a repo-root-relative file exist?
</details>
<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a> | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>
已在 9f1d61f5 修正:离开对比时先等重置 effect 执行完再切到 Markdown 预览并滚动到标题;CodeMarkdownDocument.test.ts 新增对比模式下的标题请求用例(修复前失败),真实服务上也复现并验证通过。
关于相对路径基准:保持“先会话当前目录、再仓库根目录”。agent 在会话目录运行,它写出的相对路径以该目录为基准;同名文件时打开当前目录下的文件。已在 9f1d61f5 中写入代码注释、chat-view 规格与 US-Q05,并在 CodePanel.test.ts 补充同名遮蔽用例。
✅ No new issues found.
Reviewed changes
Reviewed 9f1d61f against the prior pullfrog review: the heading-link fix, the documented relative-path precedence, and the new regression coverage.
CodeDocumentView detects !!shownDiff && !diff, forces file mode, and defers showFormat("preview") plus scrollToHeading to a tick() so the shownDiff reset effect (which sets formatView = "source") has already run. This addresses the previously reported clobber, and the new test exercises exactly that path.CodeWorkspace comments now state cwd-first then repo-root resolution with the same-name shadowing rule, and the CodePanel reveal test asserts a cwd-relative file wins over the repo-root one.comparison.I traced the deferred-reveal ordering (the reset effect flushes before reveal() runs), the leaving detection against the file/diff/comparison tab model, and the candidate order against internal/codeview/navigation.go's cwd resolution; behavior matches the updated docs. I did not run the frontend suites in this environment (dependencies absent), so the test claims were not independently re-executed.
<!--
Pullfrog review metadata. These findings were written against 9f1d61f;
if commits have landed on wt/vivid-cedar since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.
- 9f1d61f — fix(web): 对比视图中的标题链接切回预览并定位;记录相对路径先按会话目录解析
- 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
-->
<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a> | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>
✅ No new issues found.
Reviewed changes
Reviewed the rebase of the two commits onto main @ a27a546 (includes #319's removal of hybrid chat idle sleep).
23a4faf) diff is byte-identical to the previously reviewed 9f1d61f, and the feature commit (dc5ed33) carries the same hunks as 7b14be8. The only differences between the two heads are #319-driven edits to the verification log and the hybrid.spec.ts idle test context, neither of which touches the PR's code.CodeRevealSchema, parseChatCodeLink, and every E2E helper the new test relies on (createHybrid, openHybrid, sendChat, sideTab, conversation, composer, working, expectSide) remain present against the new base.<!--
Pullfrog review metadata. These findings were written against 23a4faf;
if commits have landed on wt/vivid-cedar since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.
- 23a4faf — fix(web): 对比视图中的标题链接切回预览并定位;记录相对路径先按会话目录解析
- dc5ed33 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
-->
<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a> | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>
mzdluo123
概要
在混合会话的聊天视图(
ChatView)中,支持点击 Agent 输出中指向代码位置的链接,直接在当前会话的代码浏览器(含已弹出的独立代码窗口)中打开目标文件或目录,并定位到对应行号、行范围或 Markdown 标题。变更内容
web/src/markdown-link.ts)- 新增
parseChatCodeLink,解析本机file:///.../file://localhost/...URI、绝对路径/...与相对路径(含Makefile:15、main.go:10:4等无斜杠的文件名:行号形式)。- 支持
#L10、#L10-L20、#L10C5、#L10:5、#10-20片段,:10、:10-20、:10:4行号后缀(保留rawPath以兼容字面含冒号的文件名),以及 Markdown#标题slug。- 外部
http(s):、mailto:链接保持新标签页打开(target="_blank" rel="noopener noreferrer");javascript:、data:、blob:、远端file://host/...、纯#fragment与伪造的data-md-*属性保持惰性。CodeMarkdownPreview、TimelineItem、ToolRow、ChatView)-
CodeMarkdownPreview在variant="message"且传入onopenlink时,在 DOMPurify 清洗阶段剥离非外部href并将合法代码链接转为data-md-href+role="link"+tabindex="0"(支持点击与键盘Enter);修正链接样式选择器,使无href/data-md-href的惰性<a>不再渲染为假下划线链接。-
ToolRow中的tool.locations、resource_link内容块以及TimelineItem折叠行“已浏览 N 项”中的文件位置支持点击打开代码浏览器(通过ListButton新增的link/code-link变体承载);diff块的“在代码面板中查看”继续打开文件 Diff(mode: "diff")。SessionTerminal、CodePanel、CodeWorkspace、CodeDocumentView、CodeReader)- 扩展
CodeRevealSchema(mode: "diff" | "file"、line、endLine、column、heading、rawPath、fromUri),通过MessagePort同步转发至已弹出的独立代码窗口,且在代码已弹出时不再在主页面重复展开占位面板。-
CodeWorkspace支持子目录cwd下的仓库根路径回退、字面文件名:行号回退以及会话临时文件夹(artifacts)回退;mode: "file"打开源码视图并通过CodeReader.revealLine滚动并选中目标行或行范围(或切换到 Markdown 预览定位标题)。用户故事与规格影响
docs/user-stories/hybrid-sessions.md、docs/user-stories/coverage.md、docs/user-stories/verification-log-2026-11.md、docs/hybrid-sessions.md与openspec/specs/chat-view/spec.md)。界面截图(隔离演示服务 + fake agent 演示仓库)
桌面端(
1280×720)| 修改前(
origin/main:相对代码链接剥离href后点击无响应) | 修改后(点击sortWorkspaces在右侧打开代码浏览器并选中 15–21 行) || --- | --- |
| 浅色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/before-desktop-light.png?raw=true" width="420"> | 浅色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/after-opened-desktop-light.png?raw=true" width="420"> |
| 深色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/before-desktop-dark.png?raw=true" width="420"> | 深色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/after-opened-desktop-dark.png?raw=true" width="420"> |
移动端(
390×844)| 修改前(
origin/main:点击无响应) | 修改后(点击sortWorkspaces自动切到“代码”标签页并选中 15–21 行) || --- | --- |
| 浅色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/before-mobile-light.png?raw=true" width="240"> | 浅色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/after-opened-mobile-light.png?raw=true" width="240"> |
| 深色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/before-mobile-dark.png?raw=true" width="240"> | 深色<br><img src="https://github.com/mzdluo123/webmux/blob/bae9ee980d394677d392a50cb3dc93cebed92117/screenshots/after-opened-mobile-dark.png?raw=true" width="240"> |
验证
make check(生产构建、svelte-check、测试类型检查、Oxlint、check:arch、docs-check、persistence-check、go vet、golangci-lint)make test-frontend(Vitest 单元与 Chromium 浏览器套件全量)acp-chat.spec.ts(241 项)、design-system.spec.ts(84 项)hybrid.spec.ts全量(45 项通过,含桌面与 Pixel 7 代码链接跳转并发送行范围引用新用例)