← Back to Pull requests

feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开 #320

Merged
mzdluo123 merged 31 files (1458 lines) on Nov 05, 2026 03:56 UTC
View on GitHub
mzdluo123 mzdluo123 commented on Nov 05, 2026 02:40 UTC
Author

概要

在混合会话的聊天视图(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 预览定位标题)。

    用户故事与规格影响

  • 受影响故事:US-Q05(已同步更新 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 浏览器套件全量)

  • Storybook Playwright:acp-chat.spec.ts(241 项)、design-system.spec.ts(84 项)

  • E2E Playwright:hybrid.spec.ts 全量(45 项通过,含桌面与 Pixel 7 代码链接跳转并发送行范围引用新用例)
  • Diff: 1458 lines (+1338 / -120) across 31 files Reviewer: mzdluo123 Review duration: 76m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.86) × (1 − Review Confidence (0.77)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.86 · 1458 lines diff across 31 files
    0.86
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.83 · 4 substantive comment(s)
    0.83
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    76%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    10 items
    mzdluo123 mzdluo123 commented on Nov 05, 2026 03:09 UTC
    Author

    @pullfrog review

    pullfrog[bot] pullfrog[bot] approved these changes on Nov 05, 2026 03:12 UTC
    Approved Reviewer

    ✅ No new issues found.

    Reviewed changes

  • Code-location parsing: 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.

  • Chat rendering: the message purifier captures only validated non-external hrefs, strips forged 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.

  • Tool rows and message timeline: grouped reads, single/multi locations, and resource_link blocks are now navigable; diff rows still open diff mode.

  • Code browser reveal: 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.

  • Line/heading positioning: 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.

  • Docs and tests: US-Q05/coverage/verification log and the chat-view spec match the behavior; unit, browser, pop-out and desktop/mobile E2E coverage were added for the new paths.
  • 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.

  • Mode: Review (initial)

  • Files reviewed: 30

  • Commits reviewed: 1

  • Base: main (40ab241)

  • Head: wt/vivid-cedar (338d101)

  • Reviewed commits:

  • - 338d101 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
  • Prior pullfrog review: none

  • -->

    <!-- 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>&nbsp;&nbsp;| View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>

    pullfrog[bot] pullfrog[bot] approved these changes on Nov 05, 2026 03:13 UTC
    Approved Reviewer

    ✅ No new issues found.

    Reviewed changes (since the prior review of 338d101)

  • Rebase onto current 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 reconciled with the new base: the now-redundant 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).

  • Rebased conflicts: 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.

  • Mode: IncrementalReview (delta against prior pullfrog review)

  • Files reviewed: 29

  • Commits reviewed: 1

  • Base: main (40ab241)

  • Head: wt/vivid-cedar (7b14be8)

  • Reviewed commits:

  • - 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
  • Prior pullfrog review: 338d101 (https://github.com/mzdluo123/webmux/pull/320#pullrequestreview-5779384528)

  • -->

    <!-- 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>&nbsp;&nbsp;| View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>

    pullfrog[bot] pullfrog[bot] commented on code on Nov 05, 2026 03:38 UTC
    Code Review
    web/src/components/CodeDocumentView.svelte:1
    @@ -318,11 +323,30 @@
         if (!request) return;
         untrack(() => {
           onHeading?.();
    -      if (formatFile !== "markdown") return;
    +      mode = "file";

    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>

    pullfrog[bot] pullfrog[bot] commented on Nov 05, 2026 03:38 UTC
    Reviewer

    ℹ️ 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.

  • Link parsing — parseChatCodeLink/isExternalLink handle local file:// URIs, absolute/relative paths, :line suffixes and #L/heading fragments, rejecting unsafe schemes, remote hosts and bare anchors.

  • Message rendering — the message DOMPurify instance strips non-external hrefs, re-adds validated links as data-md-href with click/Enter activation, and keeps external links target="_blank" rel="noopener noreferrer".

  • Tool rows — ToolRow/TimelineItem open locations and resource_link entries in the code browser through new ListButton link variants.

  • Reveal resolution — CodeWorkspace resolves workspace/root/rawPath/artifacts candidates and forwards CodeReveal through the pop-out MessagePort.

  • Reader — 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.

  • Mode: Review (initial)

  • Files reviewed: 29

  • Commits reviewed: 1

  • Base: main (40ab241)

  • Head: wt/vivid-cedar (7b14be8)

  • Reviewed commits:

  • - 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
  • Prior pullfrog review: none

  • -->

    ℹ️ 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>&nbsp;&nbsp;| Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>

    mzdluo123 mzdluo123 commented on code on Nov 05, 2026 03:48 UTC
    Code Review
    web/src/components/CodeDocumentView.svelte:1
    @@ -318,11 +323,30 @@
         if (!request) return;
         untrack(() => {
           onHeading?.();
    -      if (formatFile !== "markdown") return;
    +      mode = "file";

    已在 9f1d61f5 修正:离开对比时先等重置 effect 执行完再切到 Markdown 预览并滚动到标题;CodeMarkdownDocument.test.ts 新增对比模式下的标题请求用例(修复前失败),真实服务上也复现并验证通过。

    mzdluo123 mzdluo123 commented on Nov 05, 2026 03:48 UTC
    Author

    关于相对路径基准:保持“先会话当前目录、再仓库根目录”。agent 在会话目录运行,它写出的相对路径以该目录为基准;同名文件时打开当前目录下的文件。已在 9f1d61f5 中写入代码注释、chat-view 规格与 US-Q05,并在 CodePanel.test.ts 补充同名遮蔽用例。

    pullfrog[bot] pullfrog[bot] approved these changes on Nov 05, 2026 03:51 UTC
    Approved Reviewer

    ✅ 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.

  • Heading links now leave an open comparison: 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.

  • Relative-path precedence documented and tested: the hybrid-sessions story, the chat-view spec and the 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.

  • Regression coverage: a browser test requests a heading while a comparison is open and verifies the Markdown preview mounts and scrolls to the slug, with the harness gaining an optional 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.

  • Mode: IncrementalReview (delta against prior pullfrog review)

  • Files reviewed: 31

  • Commits reviewed: 2

  • Base: main (40ab241)

  • Head: wt/vivid-cedar (9f1d61f)

  • Reviewed commits:

  • - 9f1d61f — fix(web): 对比视图中的标题链接切回预览并定位;记录相对路径先按会话目录解析
    - 7b14be8 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
  • Prior pullfrog review: 7b14be8 (https://github.com/mzdluo123/webmux/pull/320#pullrequestreview-5779548819)

  • -->

    <!-- 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>&nbsp;&nbsp;| View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>

    pullfrog[bot] pullfrog[bot] approved these changes on Nov 05, 2026 03:53 UTC
    Approved Reviewer

    ✅ 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).

  • Rebase preserved the PR patch: the fix commit (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.

  • No interaction with #319: the chat/code-link paths, 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.

  • Mode: IncrementalReview (delta against prior pullfrog review)

  • Files reviewed: 31

  • Commits reviewed: 2

  • Base: main (a27a546)

  • Head: wt/vivid-cedar (23a4faf)

  • Reviewed commits:

  • - 23a4faf — fix(web): 对比视图中的标题链接切回预览并定位;记录相对路径先按会话目录解析
    - dc5ed33 — feat(web): 在聊天视图点击代码位置链接时在代码浏览器打开
  • Prior pullfrog review: 9f1d61f (https://github.com/mzdluo123/webmux/pull/320#pullrequestreview-5779634231)

  • -->

    <!-- 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>&nbsp;&nbsp;| View workflow run | Using deepseek-v4.1-flash | 𝕏</sup>

    Reviewers
    Assignees
    mzdluo123 mzdluo123
    Labels
    risk: low confidence: 76.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 85.5% (HIGH) · Higher = larger blast radius
    85.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 76.8% · Lower = rushed or shallow review
    76.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%