Commit Graph
6 Commits
Author SHA1 Message Date
Menghuan1918andidoall 78274c7b78 fix(sidebar): /sidebar/* 传输按页面前缀解析,反代子路径下不再甩掉前缀(#584 移植)
贡献者 PR #584(fix: preserve reverse-proxy base paths,head 1ca99d8)的改动面在
dev 上仍然需要——JSON API / upload / file / html / bundle 与两条 WebSocket 都还是
源站绝对路径(带前导斜杠 → 反代子路径下 404 / 1006),目标 issue #753 仍 OPEN,
docs/plans/2026-10-04-issue-triage.md 也把 #584 记为优先合入项。但它不能机械解冲突,
故按 dev 现有结构重写。

复用(PR 的可复用部分):
- 新增 src/client/host-route-url.ts:hostRouteUrl() / hostWebSocketUrl() 先去前导
  斜杠,再按注入基底解析;基底去 search/hash 并强制目录尾斜杠——launch token 查询串
  与「缺尾斜杠的前缀」都不会吃掉路径最后一段。

改写(dev 侧已经变掉的东西):
- 基底来源并进 dev 的 2718725:desktop-env.ts 的 sidebarWebSocketBase() 泛化为
  hostTransportBase()(__DSH_TRANSPORT__.streamBaseUrl 优先,回落 document.baseURI),
  HTTP 与 WS 从此共用一个基底权威,而不是另起一套。丢弃 PR 的 hostDocumentBase()
  「取 document.baseURI 与 location.href 中更长者」启发式:它会顶掉刚落地的桌面壳修复
  (dsh-app://app/ 下 location.href 会重新拼出不可达的 ws://app/…),而基线
  0.2.0-rc.1 的宿主产物里没有 <base href>(PR 自己的 e2e 也只采集、从不断言它)。
  最终解析式与宿主 dsh-api-gateway 逐字同形(去前导斜杠 + 壳注入基底优先)。
- 丢弃 src/client/TerminalView.tsx 的改动:该文件在 dev 已删除(终端已交还宿主),
  其覆盖的 WS 语义改由 dev 现存的两条调用点承担,并补齐 PR 文件清单里漏掉的
  src/client/use-dir-watch.ts(fs-watch socket)。

调用点(一律相对路径 + 前缀解析):api.ts 的 JSON API / upload / file / html /
archive、chunk-loader.ts 的 CHUNK_URL、markdown-images.ts 与 MarkdownHtml /
TextEditor / DiffPane 的媒体改写(原 window.location.origin 在桌面壳下是
dsh-app://app,媒体同样不可达)、use-host-feeds.ts 与 use-dir-watch.ts 的两条
WebSocket。archiveDownloadUrl 是 PR 漏掉的同类调用点(FileTree 用它 fetch zip 字节),
一并纳入;open-in-app.ts 打的是宿主路由 /open-in-app/*,与 PR 明确不碰的宿主 /api
同类,不纳入。

消费插件契约(指南「接入 API 即文档」):
- BetterSidebarService 新增 hostRouteUrl(path)(features 'hostRouteUrl'),
  docs/external-plugin-guide.md §6 / §7 / §15 的 fetch('/sidebar/api/…') 示例改为
  经它解析,并写明「绝不写前导斜杠」。

验证:pnpm typecheck / pnpm exec vitest run(161 files / 1812 passed / 13 skipped)/
eslint 全绿。tests/base-path.spec.ts 钉前缀保留与基底优先级,并在真实调用点上断言
(api fetch 的 URL、chunk 注入的 script src、jsdom 下 fs-watch 的 socket URL);
PR 自带的 base-path e2e 在 page.evaluate 里复制实现后自证,回归守不住,故不引入该 lane。

Refs #584

Co-authored-by: idoall <6040958+idoall@users.noreply.github.com>
2026-10-05 02:22:03 +08:00
ymac f5ffd10474 fix(markdown): render anchors without a stray close tag and keep <details> summaries as direct children
Two raw-HTML preview defects (client rendering only, no DSH source touched):

- A stray `</a>` from an author's `<a id="x"></a>` was printed as literal text.
  The host renderer emits one text node per raw-HTML token, so the open tag and
  its close tag arrive as siblings; DOMPurify drops a lone close tag (no element
  children), which fell into the inline pass's "no elements means prose, keep
  the text" branch. The pass now deletes a node that is nothing but a close tag,
  keeping the anchor id and leaving comparison prose (`a < b`, `x </ y`) intact.
- A `<details>` fold showed the UA's own "Details" label while the authored
  summary text dropped into the body: `<summary>…</summary>` is a balanced span,
  so analyzeHtmlSegment reduced it to an `html` leaf wrapped in a block div,
  which is not a direct child of `<details>` and therefore not honored as the
  disclosure widget. The renderer now hoists a leaf-leading summary into a real
  `<summary>` element inside its details frame (attributes via the shared props
  extraction, media/anchors still hardened), with no hardcoded label.

Also scope `.editorMd details > summary { cursor: pointer }` so a hoisted
summary keeps its pointer cursor (the old `.editorHtmlBlock summary` rule no
longer matches once it leaves the leaf wrapper).

Tests: 8 new/tightened cases in tests/markdown-html-render.spec.tsx (13 -> 21),
plus a seeded anchor and direct-child summary assertions in the real mount
smoke (tests/e2e/mount.e2e.ts). Verified pnpm test (113 files / 1140 passed),
typecheck, lint, and pnpm test:mount (7/7).

Fixes #778
2026-09-27 19:45:17 +08:00
Menghuan1918 bd11bad65c feat: adapt to DSH 0.1.7-rc.1
Move the support line from 0.1.7-alpha.1 to 0.1.7-rc.1 (peer floor
`^0.1.7-rc.1`). 0.21.0-alpha.1 never reached npm, and once the code-card
labels below are fixed the same build crashes on alpha.1 (its DiffBlock
still reads the `labels.files` upstream deleted), so declaring only the
host we verify against is the honest floor — and from rc.1 on the host
enforces peers at boot anyway: a row whose `@deepseek-ai/dsh-*` peers do
not satisfy the runtime is silently disabled.

Dependencies: 28 devDependency pins and 14 peers move to 0.1.7-rc.1.
rc.1 also raised the vendored runtime (cordis 4.0.4, schemastery 3.18.4,
cordis-plugin-group 1.0.4, cordis-plugin-include 1.0.9) and publishes DSH
cross-references as exact versions, so bumping schemastery/cordis alone
left four unmet transitive peers — the three vendor packages are hoisted
into devDependencies, which is what makes `pnpm peers check` clean again.

One compile break: rc.1 added `CodeToolbarLabels` (codeLabel / wrapLabel /
unwrapLabel, all required), made DiffBlockLabels / ReadBlockLabels extend
it and deleted `DiffBlockLabels.files`. Fixing SideChatView then leaving
markdown on the legacy banner would render two different code-card styles
inside one side-chat view, so the plugin adopts the card everywhere:
`markdownTextProps()` now passes `labels.code.toolbarLabels` with the
host's own wording (codeBlock.title|wrap|unwrap, added to all 20
dictionaries; `sideChatBlockFiles` retires with the deleted footer).

Adopting the card surfaced a silent regression the suite caught: the new
toolbar shows `codeLabel` for languages the highlighter does not know, and
mermaid has no shiki grammar, so the info string no longer reaches the DOM
and the banner-text probe in mermaid.tsx matched nothing — mermaid fences
stopped being swapped for diagrams. Detection now matches the FENCE BODY
from the source that produced the render.

`tests/market-manifest.spec.ts` pins every DSH peer as a floating caret
range: an exact pin (the devDependency style) or a comparator without a
prerelease would fail rc.1's preflight and silently stop the plugin from
loading, and `pnpm peers check` cannot see that — it validates the
resolved dev tree, not the range shape the host reads.
2026-09-23 22:24:56 +08:00
Menghuan1918 2a99968fa3 fix(editor): rewrite local images in markdown runs of the split renderer
Every .md preview renders through MarkdownDocument (htmlInfo is ungated),
but its markdown segments passed the raw source into MarkdownText, whose
chat-security stance drops non-http(s) image destinations — so local
markdown-syntax images (![alt](./icon.svg), reference-style definitions)
always fell back to alt text. Only HTML <img src> tags were rewritten
(postProcessSanitized).

Apply rewriteLocalImageUrls to each markdown run (segment + appended
reference definitions) inside MarkdownDocument's prepared memo, through
the same media trust fence the sanitized HTML leaves already use.
Idempotent for already-absolute media URLs; remote destinations
untouched. Also correct the stale "non-null only for HTML documents"
comment on TextEditor's htmlInfo.
2026-09-06 21:53:49 +08:00
Menghuan1918 936df662b0 test(specs): 收敛 28 个组件 spec 的渲染样板到共享 test-utils
- 7 个 spec 的本地 mount()(createRoot + act 容器循环)替换为
  renderRoot():sidechat-view、subagent-jobs-view、subagent-live-polling、
  lazy-chunk、side-card-section-rows(本地 mount 删除,调用点改名);
  editor-refresh、markdown-manual-refresh(EditorHost 包装 mount 改为
  委托 renderRoot,调用点不动)
- 24 个 spec 的内联 IS_REACT_ACT_ENVIRONMENT 赋值替换为 setupReactAct()
  (subagent-jobs-view / subagent-live-polling / lazy-chunk 原本未设
  flag,保持原样不引入)

全部为语义相同的样板替换:迁移后全量 118 files / 1241 passed +
9 skipped,与迁移前一致。
2026-09-03 12:04:35 +08:00
Menghuan1918 7f634866bf feat(editor): Markdown 预览内嵌 HTML 安全渲染 + 目录大纲(TOC)
宿主 MarkdownText 出于聊天安全把 raw HTML 按字面文本渲染,预览 GitHub
风格 README(徽章墙 div、details 折叠块内嵌 markdown、表格单元格内联
标签、video/picture)时全是源码文本。本次在不动渲染器的前提下:

- markdown-html.ts(纯函数):fence 感知切分器把文档切成 markdown/html
  段(CommonMark type-6 块级标签名单 + 注释段 + 空行终止);段内标签
  tokenizer 归约 open/close/html parts;全文档引用定义收集(每段追加
  保持 [text][id] 跨段语义)
- MarkdownHtml.tsx:DOMPurify 白名单消毒(显式禁 script/iframe/form
  等;a 强制 _blank+noopener;本地媒体 src 经 /sidebar/file 重写);
  MarkdownDocument 帧栈状态机让 <details> 跨段嵌套内部 markdown;
  MarkdownSegment 内联替换(MutationObserver 幂等 pass,把表格单元格
  等处标签文本消毒还原为元素,纯散文不误伤)
- md-toc.tsx:零高度 sticky 浮动目录按钮(≥3 标题)+ 弹出大纲,跳转
  平滑滚动 + 自动展开折叠 details + 高亮闪现。关键修复:子组件读父
  ref 在 React layout 阶段恒为 null(子先于父),改为经自身 bar ref
  的 parentElement 定位容器(jsdom 单测传预填 ref 掩盖了该 bug,仅
  真实挂载 e2e 抓到)
- 纯 markdown 文档走原单次解析路径零变化(现有 mermaid e2e 守卫一字
  不动);新增 readme-style.md 种子 + 探针(消毒渲染/嵌套/内联/TOC
  全链路);19 语言词典新增 toc 键;dompurify 提升为直接依赖(与
  mermaid 传递依赖去重单版本)

设计文档 docs/plans/2026-08-24-markdown-html-toc-design.md
2026-08-24 12:05:14 +08:00