release: merge dev for v0.31.1 (file:// image URLs in Markdown)

This commit is contained in:
Menghuan1918 committed 2026-11-11 21:59:07 +08:00
commit 8d8592bb0e
13 files changed
+221 -41

No files matched your search

+5
View File
@@ -2,6 +2,11 @@
> 本文档收录 dsh-better-sidebar 的完整发布历史(最新版摘要见 [README](README_ZH.md);同步发布于 [GitHub Releases](https://github.com/omdsh-dev/DSH-better-sidebar/releases))。
### v0.31.1
- 🔗 **Markdown 里的 `file://` 图片地址也能显示了**:`file:` 不交给渲染器或 DOMPurify(前者会拒绝、后者会剥掉 src),而是先还原成绝对本地路径,再走与相对图片相同的会话媒体路由。支持 POSIX 路径、Windows 盘符(`file:///C:/...`,含百分号编码)、`localhost` 与 UNC(`file://server/share/...`);原始 HTML 的 `<img src="file:///...">` 同样在消毒前完成映射。与 VSCode Markdown 预览的 webview 资源映射同一思路。
- 🧪 测试:`tests/markdown-images.spec.ts`、`tests/markdown-html-render.spec.tsx`、`test:mount` 的 `file://` 图片断言。
### v0.31.0
- 🖼 **Markdown 语法里的 `data:image` 图片能显示了**:预览的图片词表此前只放行本地路径,`data:` 一律退回 alt 文本;现在 `data:image/*` 原样交给宿主渲染器(其白名单本就接受 `data:`),`data:text/html` 等仍拒绝。相对/绝对本地图片在桌面壳下的 page-base 修复(#1043)同批进入本版,0.30.1 用户升级后本地图片不再只剩斜体 alt。
+5
View File
@@ -4,6 +4,11 @@
>
> 📝 The Chinese [CHANGELOG](./CHANGELOG.md) is the authoritative, item-by-item record; this file carries the English summaries and has historically lagged behind it. Where the two disagree, the Chinese one is current.
### v0.31.1
- 🔗 **`file://` image destinations in Markdown now render.** The `file:` scheme is never handed to the renderer or DOMPurify (the former rejects it and the latter drops the src); it is converted to an absolute local path and served by the same session media route as a relative image. POSIX paths, Windows drive URLs (`file:///C:/...`, percent-encoding included), `localhost` and UNC (`file://server/share/...`) are covered; raw HTML `<img src="file:///...">` is mapped before sanitization too. This is the same idea as VSCode's Markdown-preview webview resource mapping.
- 🧪 `tests/markdown-images.spec.ts`, `tests/markdown-html-render.spec.tsx`, and the `file://` image assertion in `test:mount`.
### v0.31.0
- 🖼 **Markdown-syntax `data:image` images now render.** The preview's image vocabulary only admitted local paths, so every `data:` destination fell back to alt text; `data:image/*` now passes straight to the host renderer (whose own allowlist already accepts `data:`), while `data:text/html` and friends stay rejected. The page-base fix for relative/absolute local images in the desktop shell (#1043) ships in this release too, so 0.30.1 users no longer see only italic alt text.
+9 -13
View File
@@ -44,14 +44,14 @@ dsh plugin --profile web add dsh-better-sidebar@latest
Then **hard-refresh the browser** (Cmd/Ctrl+Shift+R). Requires DSH **0.2.2-rc.1+**.
> **Compatibility warning — match the plugin to the host line.** As of 2026-11-04, DSH's npm `latest` is **0.2.1-rc.5** and `next` is **0.2.2-rc.1**. **v0.31.0 requires DSH 0.2.2-rc.1+**; hosts on the 0.2.1 line (**0.2.1-rc.1 ~ rc.5**, i.e. today's `latest`) must pin `dsh-better-sidebar@0.28.2` — v0.29.0 was never published to npm. DSH 0.2.1-alpha.5 users must pin `dsh-better-sidebar@0.28.0-alpha.0`, and hosts still on **0.2.0-rc.2** must pin `dsh-better-sidebar@0.26.1`. A 0.x caret never spans a minor version, so one plugin build cannot serve two host lines. The marketplace installer picks the plugin's `latest` regardless of host version, so an old host gets a version-rejection error — upgrade the host or pin the version explicitly. The two packages' `latest` tags are independent.
> **Compatibility warning — match the plugin to the host line.** As of 2026-11-04, DSH's npm `latest` is **0.2.1-rc.5** and `next` is **0.2.2-rc.1**. **v0.31.1 requires DSH 0.2.2-rc.1+**; hosts on the 0.2.1 line (**0.2.1-rc.1 ~ rc.5**, i.e. today's `latest`) must pin `dsh-better-sidebar@0.28.2` — v0.29.0 was never published to npm. DSH 0.2.1-alpha.5 users must pin `dsh-better-sidebar@0.28.0-alpha.0`, and hosts still on **0.2.0-rc.2** must pin `dsh-better-sidebar@0.26.1`. A 0.x caret never spans a minor version, so one plugin build cannot serve two host lines. The marketplace installer picks the plugin's `latest` regardless of host version, so an old host gets a version-rejection error — upgrade the host or pin the version explicitly. The two packages' `latest` tags are independent.
<details>
<summary><b>Pick the plugin version for your DSH version</b></summary>
| Your DSH version | Install command |
| --- | --- |
| **0.2.2-rc.1+** | `dsh plugin --profile web add dsh-better-sidebar@0.31.0` |
| **0.2.2-rc.1+** | `dsh plugin --profile web add dsh-better-sidebar@0.31.1` |
| **0.2.1-rc.1 ~ 0.2.1-rc.5** | `dsh plugin --profile web add dsh-better-sidebar@0.28.2` |
| **0.2.1-alpha.5** | `dsh plugin --profile web add dsh-better-sidebar@0.28.0-alpha.0` |
| **0.2.0-rc.2** | `dsh plugin --profile web add dsh-better-sidebar@0.26.1` |
@@ -71,12 +71,12 @@ Always pin **exact versions** for older releases (`latest` moves forward with ea
```text
Install the dsh-better-sidebar plugin (a sidebar workbench for DSH):
1. Confirm DSH is 0.2.2-rc.1 or newer, then run dsh plugin --profile web add dsh-better-sidebar@0.31.0
1. Confirm DSH is 0.2.2-rc.1 or newer, then run dsh plugin --profile web add dsh-better-sidebar@0.31.1
2. Remind me to hard-refresh the browser (Cmd/Ctrl+Shift+R) afterwards
If something fails, check the FAQ table in https://github.com/omdsh-dev/DSH-better-sidebar README first.
```
**One-line script** — clone this repo and run `bash scripts/install.sh 0.31.0` (macOS / Linux / Windows Git Bash; `./scripts/install.ps1 -Version 0.31.0` for native Windows). It handles installation + bundle registration.
**One-line script** — clone this repo and run `bash scripts/install.sh 0.31.1` (macOS / Linux / Windows Git Bash; `./scripts/install.ps1 -Version 0.31.1` for native Windows). It handles installation + bundle registration.
**Updating**: just re-run the install command, then hard-refresh the browser.
@@ -94,12 +94,16 @@ If something fails, check the FAQ table in https://github.com/omdsh-dev/DSH-bett
| **Two sidebars** on the page | Double mounting. Remove the legacy manual mount line (`- insert: ... better-sidebar ...`) from `~/.dsh/profiles/web/cordis.patch.yml`; aggregate packages mounting this package under a different id are auto-yielded, no action needed. |
| Settings values gone after upgrade | Since DSH 0.1.7, preferences live on this plugin's mount row in the profile (default entry id `better-sidebar`). The plugin migrates your old `settings.yaml` values once on first start and never overwrites newer values. |
| Terminal unavailable | Terminals are provided by **DSH itself** (this plugin ships no PTY) — see DSH docs; "host provides no terminal capability" in the bottom terminal means this deployment has no terminal controller mounted. |
| `dsh: command not found` | Install DSH first; or use `npx -y --package @deepseek-ai/dsh@0.2.2-rc.1 dsh plugin --profile web add dsh-better-sidebar@0.31.0`. |
| `dsh: command not found` | Install DSH first; or use `npx -y --package @deepseek-ai/dsh@0.2.2-rc.1 dsh plugin --profile web add dsh-better-sidebar@0.31.1`. |
</details>
## 🆕 Recent Updates
**v0.31.1 — `file://` image URLs in Markdown**
- **`file:///...` images now render**: a Markdown-syntax or raw-HTML `file:` URL is converted to an absolute local path and served by the same session media route as a relative image; Windows drives, `localhost`, UNC and percent-encoding are covered.
**v0.31.0 — local-image and desktop-shell preview fixes**
- **Markdown previews show local images again**: relative/absolute paths no longer collapse to alt text in the desktop shell because their media URL is no longer cross-site; Markdown-syntax `data:image` renders too (`data:text/html` and friends stay rejected).
@@ -110,14 +114,6 @@ If something fails, check the FAQ table in https://github.com/omdsh-dev/DSH-bett
- **The "Side card" row in Settings no longer shows two icons.** The plugin used to paint its own glyph over the shell's fallback gear with a CSS mask; the shell now wraps the nav icon in a container and exposes a per-section icon slot. The row contributes its icon through that slot, and the stale marker + CSS apparatus is gone — along with a document-wide DOM observer.
**v0.30.0 — DSH 0.2.2 support, side-chat images, clickable quote chips**
- **DSH 0.2.2-rc.1 is the new baseline** (all 14 peer floors move to `^0.2.2-rc.1`). The host replaced the installable model-selection ref with an agent-owned `AgentModel`, so a side-chat thread's model switch now goes through `agent.model.select()` — recorded once in the log and applied to the next step. A 0.x caret never spans a minor: DSH 0.2.1 hosts (today's npm `latest`) keep pinning plugin v0.28.2.
- **Side Chat takes images**: paste a screenshot or pick PNG / JPEG / WebP / GIF, preview or remove before sending, or send images alone; the preview survives a reload and a cold restore.
- **Quote chips are clickable**: a passage selected with "Add to conversation" lands as a chip that jumps back to the source file and flashes the quoted lines, with a nonce so a second click jumps again; if the reference record cannot be persisted the plugin falls back to the previous built-in chip instead of landing a dead one.
- **Drafts survive the host-owned close paths**: closing a native sidebar tab or quitting the desktop app keeps the unsaved draft and offers it back when the same file is reopened — the host exposes no cancellable close hook, so this is backup-and-restore rather than a prompt.
- **Reliability**: a side-chat seed built from a compacted parent no longer persists an unreadable session log; page CSS zoom is no longer misread as a page transform; the bottom workbench terminal no longer paints black; container workspaces show every child repository in the Git panel; the installers refuse a profile whose `@deepseek-ai/dsh-*` copies are a mixed version pair and print the repair command.
## 🔌 Plugin Ecosystem
`ctx.betterSidebar` offers five extension points to every plugin — `registerTab` / `registerFileViewer` / `registerFileIcon` / `registerFileAction` / `registerTabAction`; the built-in 6 tabs + 5 viewers use the very same API. The GitHub topic [`dsh-better-sidebar`](https://github.com/topics/dsh-better-sidebar) already lists **30+ ecosystem plugins**; the full integration guide is at **[docs/external-plugin-guide.md](./docs/external-plugin-guide.md)**.
+9 -13
View File
@@ -44,14 +44,14 @@ dsh plugin --profile web add dsh-better-sidebar@latest
装完**硬刷新浏览器**(Cmd/Ctrl+Shift+R)即可。要求 DSH **0.2.2-rc.1+**。
> **兼容性警告:插件版本必须与宿主线匹配。** 截至 2026-11-04,DSH 的 npm `latest` 是 **0.2.1-rc.5**、`next` 是 **0.2.2-rc.1**。**v0.31.0 要求 DSH 0.2.2-rc.1+**;仍停在 0.2.1 线(**0.2.1-rc.1 ~ rc.5**,也就是今天的 `latest`)的宿主必须固定 `dsh-better-sidebar@0.28.2`——v0.29.0 从未发布到 npm。DSH 0.2.1-alpha.5 用户固定 `dsh-better-sidebar@0.28.0-alpha.0`,**0.2.0-rc.2** 宿主固定 `dsh-better-sidebar@0.26.1`。0.x 的 caret 不跨 minor,因此一个构建无法同时服务两条宿主线。市场安装器按插件的 `latest` 安装、不按宿主版本选版本,旧宿主会收到版本拒绝错误——请升级宿主或显式固定版本。两个包的 `latest` 标签不是同一支持线。
> **兼容性警告:插件版本必须与宿主线匹配。** 截至 2026-11-04,DSH 的 npm `latest` 是 **0.2.1-rc.5**、`next` 是 **0.2.2-rc.1**。**v0.31.1 要求 DSH 0.2.2-rc.1+**;仍停在 0.2.1 线(**0.2.1-rc.1 ~ rc.5**,也就是今天的 `latest`)的宿主必须固定 `dsh-better-sidebar@0.28.2`——v0.29.0 从未发布到 npm。DSH 0.2.1-alpha.5 用户固定 `dsh-better-sidebar@0.28.0-alpha.0`,**0.2.0-rc.2** 宿主固定 `dsh-better-sidebar@0.26.1`。0.x 的 caret 不跨 minor,因此一个构建无法同时服务两条宿主线。市场安装器按插件的 `latest` 安装、不按宿主版本选版本,旧宿主会收到版本拒绝错误——请升级宿主或显式固定版本。两个包的 `latest` 标签不是同一支持线。
<details>
<summary><b>按 DSH 版本选插件版本</b></summary>
| 你的 DSH 版本 | 安装命令 |
| --- | --- |
| **0.2.2-rc.1+** | `dsh plugin --profile web add dsh-better-sidebar@0.31.0` |
| **0.2.2-rc.1+** | `dsh plugin --profile web add dsh-better-sidebar@0.31.1` |
| **0.2.1-rc.1 ~ 0.2.1-rc.5** | `dsh plugin --profile web add dsh-better-sidebar@0.28.2` |
| **0.2.1-alpha.5** | `dsh plugin --profile web add dsh-better-sidebar@0.28.0-alpha.0` |
| **0.2.0-rc.2** | `dsh plugin --profile web add dsh-better-sidebar@0.26.1` |
@@ -71,12 +71,12 @@ dsh plugin --profile web add dsh-better-sidebar@latest
```text
帮我安装 dsh-better-sidebar 插件(DSH 侧边栏工作台),步骤:
1. 先确认 DSH 为 0.2.2-rc.1 或更新版本,再执行 dsh plugin --profile web add dsh-better-sidebar@0.31.0
1. 先确认 DSH 为 0.2.2-rc.1 或更新版本,再执行 dsh plugin --profile web add dsh-better-sidebar@0.31.1
2. 完成后提醒我硬刷新浏览器(Cmd/Ctrl+Shift+R)
遇到报错先查 https://github.com/omdsh-dev/DSH-better-sidebar README 的常见问题表。
```
**一键脚本**——克隆本仓库后执行 `bash scripts/install.sh 0.31.0`(macOS / Linux / Windows Git Bash;Windows 原生用 `./scripts/install.ps1 -Version 0.31.0`),自动完成安装 + bundle 注册。
**一键脚本**——克隆本仓库后执行 `bash scripts/install.sh 0.31.1`(macOS / Linux / Windows Git Bash;Windows 原生用 `./scripts/install.ps1 -Version 0.31.1`),自动完成安装 + bundle 注册。
**更新**:重跑一次安装命令即可,然后硬刷新浏览器。
@@ -94,12 +94,16 @@ dsh plugin --profile web add dsh-better-sidebar@latest
| 页面出现**两个侧边栏** | 双挂载。删掉 `~/.dsh/profiles/web/cordis.patch.yml` 里旧的手动挂载行(`- insert: ... better-sidebar ...`);聚合包以不同 id 挂载本包时会自动退让,无需处理。 |
| 升级后设置页的值去哪了 | DSH 0.1.7 起偏好写在 profile 里本插件的挂载行上(默认 entry id `better-sidebar`),插件首次启动会把旧 `settings.yaml` 里的配置一次性回迁,不会覆盖新设的值。 |
| 终端无法使用 | 终端由 **DSH 自身**提供(本插件不自带 PTY),请查 DSH 侧文档;底部终端显示「宿主未提供终端能力」= 这个部署没挂终端控制器。 |
| 提示 `dsh: command not found` | 先安装 DSH;或用 `npx -y --package @deepseek-ai/dsh@0.2.2-rc.1 dsh plugin --profile web add dsh-better-sidebar@0.31.0`。 |
| 提示 `dsh: command not found` | 先安装 DSH;或用 `npx -y --package @deepseek-ai/dsh@0.2.2-rc.1 dsh plugin --profile web add dsh-better-sidebar@0.31.1`。 |
</details>
## 🆕 最近更新
**v0.31.1 — Markdown 的 `file://` 图片地址**
- **`file:///...` 图片现在能显示**:Markdown 语法和原始 HTML 的 `file:` 地址会先还原成绝对本地路径,再走与相对图片相同的会话媒体路由;支持 Windows 盘符、`localhost`、UNC 与百分号编码。
**v0.31.0 — Markdown/HTML 预览的本地图片与桌面壳修复**
- **Markdown 预览的本地图片恢复正常**:桌面壳里相对/绝对路径不再因媒体 URL 跨站而只剩 alt;Markdown 语法的 `data:image` 也能显示(`data:text/html` 等仍拒绝)。
@@ -110,14 +114,6 @@ dsh plugin --profile web add dsh-better-sidebar@latest
- **设置页「侧边卡片」那一行不再显示两个图标**:插件此前用 CSS 遮罩盖住宿主的兜底齿轮、再画自己的图标;宿主的导航图标外层多了容器,同时也提供了按 section 挂图标的口子。现在图标走宿主插槽,标记 + 遮罩那一套整体删除(顺带去掉了一个全局 DOM 观察器)。
**v0.30.0 — 支持 DSH 0.2.2、侧边对话可发图、引用 chip 可点击**
- **基线抬到 DSH 0.2.2-rc.1**(14 条 peer 下限全部前移到 `^0.2.2-rc.1`)。宿主把可安装的模型选择 ref 换成了 agent 自有的 `AgentModel`,侧边对话的模型切换改走 `agent.model.select()`——只落盘一次,并作用于下一步。0.x 的 caret 不跨 minor:DSH 0.2.1 线(也就是今天的 npm `latest`)继续固定插件 v0.28.2。
- **侧边对话可以发图**:粘贴截图或选择 PNG / JPEG / WebP / GIF,发送前可预览、可移除,也可以只发图片;刷新页面或冷恢复后预览仍在。
- **引用 chip 可点击**:用「添加到对话」划选的一段文字会落成一枚 chip,点击跳回源文件并闪烁被引行段;带 nonce,所以连点两次仍会再次跳转。引用记录写不进存储时回退到原来的内置 chip,而不是落一枚点不动的死 chip。
- **草稿不再被宿主侧的关闭路径吞掉**:关闭原生侧边页签、或退出桌面端时,未保存草稿会被备份,重开同一文件时提示恢复——宿主没有可取消的关闭钩子,所以这是备份 + 恢复,不是弹窗拦截。
- **可靠性**:父会话压缩过之后开的侧聊不再写出不可读的会话日志;页面 CSS zoom 不再被误判为页面变换;底部工作台终端不再自带黑底;容器工作区在 Git 面板里能看到每个子仓库;安装脚本发现 profile 里 `@deepseek-ai/dsh-*` 版本混搭会直接拒绝并打印修复命令。
## 🔌 插件生态
`ctx.betterSidebar` 向所有插件开放 `registerTab` / `registerFileViewer` / `registerFileIcon` / `registerFileAction` / `registerTabAction` 五个扩展点,内置 6 tab + 5 viewer 与第三方插件走同一套 API。GitHub topic [`dsh-better-sidebar`](https://github.com/topics/dsh-better-sidebar) 下已有 **30+ 生态插件**;完整接入文档见 **[docs/external-plugin-guide.md](./docs/external-plugin-guide.md)**。
+3 -3
View File
@@ -2,8 +2,8 @@
> 面向 **消费插件开发者**:如何让你的插件向 better-sidebar 注册新的侧边栏页面(tab)和文件类型预览器。
>
> 适用版本:**v0.4.0+**(`ctx.betterSidebar` 服务);声明式设置 **v0.4.1+**;text/number 设置行 **v0.11.0+**;badge/生命周期/定向打开/插件设置/版本探测 **v0.12.0+**;select 设置行(`settingSelect`)与外链认领(`urlTarget`)**v0.13.0+**;统一 `@deepseek-ai/cordis` 类型基底 **v0.15.2+**;路由前缀安全解析(`hostRouteUrl`)**v0.25.0+**。当前版本 **v0.31.0**(14 条 DSH peer 下限 `^0.2.2-rc.1`,仅支持 DSH **0.2.2-rc.1+**;0.2.1 线(0.2.1-rc.1 ~ rc.5)请固定 v0.28.2;0.2.1-alpha.5 请固定 v0.28.0-alpha.0,0.2.0-rc.2 请固定 v0.26.1(v0.27.0 尚未发布),0.2.0-rc.1 请用 v0.24.1,0.1.7 线请用 v0.22.1——caret 范围跨 minor 不成立,`^0.1.7-rc.1` 会被 0.2.0 宿主的启动预检静默禁用)。**v0.19.0 移除了自绘右侧面板与自由窗口**(见 §0、§11);**自 v0.20.0 开发线起**(**注意:0.20.0 从未发布到 npm,这些变更全部落在 v0.21.1**)插件**移除了自带的终端**(宿主 0.1.6 的 `ui-sidebar-terminal` 取代,见 §4.4)、**移除了终端固定(pin)**,并在 0.1.7 上**把浏览器视图与只读文件预览整体让给宿主**(`ui-sidebar-browser` / `ui-sidebar-documentpreview`,见 §4.4、§5.4)、**收敛了外链接管**(见 §4.1)、**重写了设置接入面**(`SettingsForms`,见 §8.2)、**给文件树加了实时刷新**(见 §10);同时**删除了轮尾产物行接管**(DSH 0.1.6 把 `conversation.chat.turnTail` 从 chain 改成只能追加的 list,替换语义不复存在)。
> **版本对照提醒**:当前版本 **v0.31.0**(DSH 0.2.2-rc.1+)。0.x 的 caret 不跨 minor,因此 0.2.1 线(0.2.1-rc.1 ~ 0.2.1-rc.5,即今天的宿主 npm `latest`)必须固定插件 **v0.28.2**——v0.29.0 从未发布;DSH 0.2.1-alpha.5 固定 v0.28.0-alpha.0,0.2.0-rc.2 固定 v0.26.1。市场安装器按插件 `latest` 安装、不按宿主版本选版本。
> 适用版本:**v0.4.0+**(`ctx.betterSidebar` 服务);声明式设置 **v0.4.1+**;text/number 设置行 **v0.11.0+**;badge/生命周期/定向打开/插件设置/版本探测 **v0.12.0+**;select 设置行(`settingSelect`)与外链认领(`urlTarget`)**v0.13.0+**;统一 `@deepseek-ai/cordis` 类型基底 **v0.15.2+**;路由前缀安全解析(`hostRouteUrl`)**v0.25.0+**。当前版本 **v0.31.1**(14 条 DSH peer 下限 `^0.2.2-rc.1`,仅支持 DSH **0.2.2-rc.1+**;0.2.1 线(0.2.1-rc.1 ~ rc.5)请固定 v0.28.2;0.2.1-alpha.5 请固定 v0.28.0-alpha.0,0.2.0-rc.2 请固定 v0.26.1(v0.27.0 尚未发布),0.2.0-rc.1 请用 v0.24.1,0.1.7 线请用 v0.22.1——caret 范围跨 minor 不成立,`^0.1.7-rc.1` 会被 0.2.0 宿主的启动预检静默禁用)。**v0.19.0 移除了自绘右侧面板与自由窗口**(见 §0、§11);**自 v0.20.0 开发线起**(**注意:0.20.0 从未发布到 npm,这些变更全部落在 v0.21.1**)插件**移除了自带的终端**(宿主 0.1.6 的 `ui-sidebar-terminal` 取代,见 §4.4)、**移除了终端固定(pin)**,并在 0.1.7 上**把浏览器视图与只读文件预览整体让给宿主**(`ui-sidebar-browser` / `ui-sidebar-documentpreview`,见 §4.4、§5.4)、**收敛了外链接管**(见 §4.1)、**重写了设置接入面**(`SettingsForms`,见 §8.2)、**给文件树加了实时刷新**(见 §10);同时**删除了轮尾产物行接管**(DSH 0.1.6 把 `conversation.chat.turnTail` 从 chain 改成只能追加的 list,替换语义不复存在)。
> **版本对照提醒**:当前版本 **v0.31.1**(DSH 0.2.2-rc.1+)。0.x 的 caret 不跨 minor,因此 0.2.1 线(0.2.1-rc.1 ~ 0.2.1-rc.5,即今天的宿主 npm `latest`)必须固定插件 **v0.28.2**——v0.29.0 从未发布;DSH 0.2.1-alpha.5 固定 v0.28.0-alpha.0,0.2.0-rc.2 固定 v0.26.1。市场安装器按插件 `latest` 安装、不按宿主版本选版本。
> 上一次 alpha.5 → rc.1 适配只动了 `package.json`(完整树差异 355 项,源码零变化);**本次 0.2.1 → 0.2.2 有真实代码改动**(`AgentModel` 取代可安装的 `ModelSelectionRef`、PTC 事件类型声明被移除、宿主图标改为 sprite),逐项记录见 [0.2.2 适配记录](plans/2026-11-04-dsh-0.2.2-rc.1-adaptation.md);伴随依赖仍为 Cordis peer `^4.0.5` / dev `4.0.5`、group `1.0.5`、schemastery `~3.18.5`、include `1.0.10`。
> 权威代码:`src/client/service.ts`(服务实现)、`src/client/builtins/`(内置 6 tab + 3 viewer 参考实现)、`lib/types/client/service.d.ts`(类型声明)。
> alpha.5 已删除 `@deepseek-ai/dsh-invariants` 与上游 `/invariant` 子路径;本插件同步移除 invariant companion,不提供替代注册服务。HTTP/WS 准入遵循宿主 Connection(见 §6)。
@@ -578,7 +578,7 @@ interface FileViewerProps {
> **head 字节从哪来**:第一次匹配(纯扩展名)没有 head。`fsRead` 策略读取后若文件为二进制,host 的 `fs.read` 响应会带 `head` 字段(base64,前 4KB,`src/index.ts` 的 `READ_HEAD_LIMIT`),编辑器会用它对 `detect` viewer **重匹配一次**——所以 detect 型 viewer 的实际触发场景是"扩展名匹配落空/二进制文件"。文本文件的 detect 嗅探不在内置流程内(用 `exts` 或 `custom` 策略替代)。
> **内置 viewer**(不可重复注册,全部 5 个):markdown(0, fsRead;内嵌 HTML 支持:DOMPurify 白名单消毒、`<details>` 跨段嵌套、本地媒体走页面 base(markdown 语法的图片经 `pathImages` 解析:浏览器用页面 base 的 `/sidebar/file`,桌面壳用 `dsh-app://app/api/file`;`data:image/*` 同样经该词表放行,`data:text/html` 等仍拒绝;内嵌 HTML 的 `<img src>` 直接重写为页面 base 的 `/sidebar/file`);≥3 标题时浮动目录大纲。实现 `markdown-html.ts` / `MarkdownHtml.tsx` / `md-toc.tsx`,[设计文档](plans/2026-08-24-markdown-html-toc-design.md);桌面壳媒体基址的修复见 [2026-10-23 记录](plans/2026-10-23-desktop-markdown-media-base.md)) / html(0, fsRead, 沙箱 iframe 预览 + `htmlViewerNoSandbox` / `htmlViewerDefaultUnsafe` 两个宿主没有的逃生门;桌面壳沙箱下由顶层帧取回文档与同源资源、内联成自包含 Blob 后交给 sandboxed iframe,仍不含 `allow-same-origin`) / jsonl(0, fsRead, 一条记录一行的预览 + 编辑器模式) / media(0, **mediaUrl**, `.mp4/.webm/.mov/.mp3/…` 用裸 `<video>` / `<audio>` 直接吃 `/sidebar/file` 的 206 + `content-range`:可拖动时间轴、`preload="metadata"` 不预下全片,解码失败或地址缺失时保留「下载」链接;实现 `src/client/builtins/media-preview.tsx`) / code(-100, catch-all, fsRead, **可编辑** CodeMirror + 保存 + 未提交变更提示(行号着色 / 左侧细色条 / hover blame,一个 `editorGitGutter` 开关,[设计文档](plans/2026-10-05-editor-git-gutter.md)))。
> **内置 viewer**(不可重复注册,全部 5 个):markdown(0, fsRead;内嵌 HTML 支持:DOMPurify 白名单消毒、`<details>` 跨段嵌套、本地媒体走页面 base(markdown 语法的图片经 `pathImages` 解析:浏览器用页面 base 的 `/sidebar/file`,桌面壳用 `dsh-app://app/api/file`;`data:image/*` 同样经该词表放行,`data:text/html` 等仍拒绝;`file://` 会还原成绝对本地路径后走同一媒体路由(Windows 盘符 / UNC / 百分号编码均支持);内嵌 HTML 的 `<img src>` 直接重写为页面 base 的 `/sidebar/file`);≥3 标题时浮动目录大纲。实现 `markdown-html.ts` / `MarkdownHtml.tsx` / `md-toc.tsx`,[设计文档](plans/2026-08-24-markdown-html-toc-design.md);桌面壳媒体基址的修复见 [2026-10-23 记录](plans/2026-10-23-desktop-markdown-media-base.md)) / html(0, fsRead, 沙箱 iframe 预览 + `htmlViewerNoSandbox` / `htmlViewerDefaultUnsafe` 两个宿主没有的逃生门;桌面壳沙箱下由顶层帧取回文档与同源资源、内联成自包含 Blob 后交给 sandboxed iframe,仍不含 `allow-same-origin`) / jsonl(0, fsRead, 一条记录一行的预览 + 编辑器模式) / media(0, **mediaUrl**, `.mp4/.webm/.mov/.mp3/…` 用裸 `<video>` / `<audio>` 直接吃 `/sidebar/file` 的 206 + `content-range`:可拖动时间轴、`preload="metadata"` 不预下全片,解码失败或地址缺失时保留「下载」链接;实现 `src/client/builtins/media-preview.tsx`) / code(-100, catch-all, fsRead, **可编辑** CodeMirror + 保存 + 未提交变更提示(行号着色 / 左侧细色条 / hover blame,一个 `editorGitGutter` 开关,[设计文档](plans/2026-10-05-editor-git-gutter.md)))。
> code 是兜底 viewer:任何其他 viewer 未认领的文件都会落到 code(CodeMirror 文本编辑);二进制文件经 head 重匹配找不到 sniffer,落到编辑器的下载面板。外部 viewer 注册同扩展名 + 更高 priority 即可覆盖内置的那几个。
>
> ⚠️ **让给宿主的格式(重要,影响你的 viewer 能不能被调用)**:DSH 0.1.7 的 `ui-sidebar-documentpreview` 自带 code / excel(xlsx,xls,csv,tsv) / office(宿主侧转 PDF)/ pdf / image / html / markdown / text 预览,并带缩放与**按目录自动刷新**——本插件原有的 image / pdf / binary-download 三个 viewer 描述符因此删除。更重要的是**路由**:插件的 `editor` 类型在 `canOpen` 里对下列扩展名一律返回 false(`src/client/native/index.ts` 的 `HOST_OWNED_EXTS`),把地址让给内置 `text` 档,**根本不会进入本插件的 `matchFileViewer`**:
+1 -1
View File
@@ -1,6 +1,6 @@
{
"id": "dsh-external/dsh-better-sidebar",
"version": "0.31.0",
"version": "0.31.1",
"main": "./lib/index.js",
"description": "更好用的右侧边栏——文件树、编辑器、文件变动、任务和侧边对话都收在这一栏里,每个会话互不干扰。暴露服务供其他插件注册侧边栏页面与文件预览器",
"engines": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dsh-better-sidebar",
"version": "0.31.0",
"version": "0.31.1",
"description": "Better Sidebar for DSH — file tree, editor, changes, tasks and side chat in one column, separate for every conversation. Also exposes a service other plugins use to register sidebar tabs and file viewers.",
"type": "module",
"repository": {
+24 -2
View File
@@ -88,10 +88,32 @@ function postProcessSanitized(root: Element, media: MarkdownHtmlMedia): void {
}
}
/**
* Rewrite authored `file:` media URLs before DOMPurify sees them. The
* sanitizer's URI allowlist drops a raw `file:` scheme (it is not a browser
* subresource the GUI can load), so a raw-HTML `<img src="file:///…">` would
* lose its src entirely. The file URL is a local path in another spelling:
* map it through the same media route as a relative src first, then sanitize
* the resulting http URL. Sources without a file URL are returned untouched.
*/
function rewriteFileUrlMedia(source: string, media: MarkdownHtmlMedia): string {
if (!/file:/i.test(source)) return source
const template = document.createElement('template')
template.innerHTML = source
for (const element of template.content.querySelectorAll('img, video, audio, source')) {
for (const attribute of ['src', 'poster']) {
const value = element.getAttribute(attribute)
if (value === null || !/^file:/i.test(value.trim())) continue
element.setAttribute(attribute, resolveLocalMediaDest(value, media.scope, media.path, media.baseUrl))
}
}
return template.innerHTML
}
/** Sanitize one balanced HTML span into markup for dangerouslySetInnerHTML. */
function sanitizeHtmlBlock(source: string, media: MarkdownHtmlMedia): string {
const holder = document.createElement('div')
holder.innerHTML = DOMPurify.sanitize(source, {
holder.innerHTML = DOMPurify.sanitize(rewriteFileUrlMedia(source, media), {
FORBID_TAGS: PURIFY_FORBID_TAGS,
FORBID_ATTR: PURIFY_FORBID_ATTR,
})
@@ -108,7 +130,7 @@ function sanitizeHtmlBlock(source: string, media: MarkdownHtmlMedia): string {
*/
function sanitizeInlineHtml(text: string, media: MarkdownHtmlMedia): string | null {
const holder = document.createElement('span')
holder.innerHTML = DOMPurify.sanitize(text, {
holder.innerHTML = DOMPurify.sanitize(rewriteFileUrlMedia(text, media), {
FORBID_TAGS: PURIFY_FORBID_TAGS,
FORBID_ATTR: PURIFY_FORBID_ATTR,
})
+63
View File
@@ -62,6 +62,50 @@ function imageDataUrl(destination: string): string | undefined {
return /^data:image\//i.test(trimmed) ? trimmed : undefined
}
/**
* The local path of an authored `file:` URL, or undefined when the
* destination is not a well-formed file URL. This is how a Markdown file can
* name a local image with the browser's own file-URL spelling
* (`file:///C:/pics/a.png`, `file:///home/me/a.png`) without the preview ever
* handing the `file:` scheme to the renderer: the path goes through the same
* session media route as every other local image. VSCode's Markdown preview
* does the equivalent through its webview resource provider.
*
* A non-empty host is a UNC path (`file://server/share/a.png` ->
* `//server/share/a.png`); `localhost` is the local machine. Query and hash
* are not part of a local filename and are dropped.
* @param destination - One authored image destination.
* @returns The local path, or undefined when this is not a file URL.
*/
export function fileUrlToLocalPath(destination: string): string | undefined {
const trimmed = destination.trim()
if (!/^file:/i.test(trimmed)) return undefined
let url: URL
try {
url = new URL(trimmed)
} catch {
return undefined
}
if (url.protocol !== 'file:' || url.username !== '' || url.password !== '') return undefined
let pathname: string
try {
pathname = decodeURIComponent(url.pathname)
} catch {
return undefined
}
if (pathname === '' || pathname === '/' || pathname.includes('\0')) return undefined
const host = url.hostname
if (host !== '' && host.toLowerCase() !== 'localhost') {
// `file://C:/x` names a drive, not a host; anything else is UNC.
if (/^[A-Za-z]:$/.test(host)) return normalizeLocalPath(`${host}${pathname}`)
return `//${host}${pathname}`
}
const local = /^\/[A-Za-z]:[\\/]/.test(pathname) ? pathname.slice(1) : pathname
// Keep the UNC spelling for the host resolver; everything else is normalized
// (Windows drive spellings become backslashes, POSIX roots stay POSIX).
return local.startsWith('//') ? local : normalizeLocalPath(local)
}
/**
* Collapse `.`/`..` segments of an absolute local path, preserving its root
* (POSIX `/`), its Windows drive (`C:\`), or its UNC `\\server\share`
@@ -195,6 +239,14 @@ export function createMarkdownPathImages(
resolve: (destination: string): string | undefined => {
const dataUrl = imageDataUrl(destination)
if (dataUrl !== undefined) return dataUrl
// A file: URL is a local path in another spelling; never hand the scheme
// to the renderer (its vocabulary rejects it and a sandboxed frame cannot
// load it). The path goes through the same media route as a relative one.
const filePathFromUrl = fileUrlToLocalPath(destination)
if (filePathFromUrl !== undefined) {
if (!desktop) return markdownMediaUrl(filePathFromUrl, scope, baseUrl)
return desktopFileUrl(filePathFromUrl, baseUrl)
}
const decoded = decodeDestination(destination)
if (decoded === undefined) return undefined
const target = markdownImageTarget(decoded, filePath)
@@ -230,6 +282,11 @@ export function resolveLocalMediaDest(
): string {
const trimmed = dest.trim()
if (trimmed === '' || trimmed.startsWith('#')) return dest
// Raw HTML may spell a local image as a file: URL. The path is served by the
// same plugin media route as a relative src (a plain DOM <img> in the GUI
// frame can load it; a raw file: URL cannot).
const filePathFromUrl = fileUrlToLocalPath(trimmed)
if (filePathFromUrl !== undefined) return markdownMediaUrl(filePathFromUrl, scope, baseUrl)
if (isRemoteUrl(trimmed)) return dest
const decoded = decodeDestination(trimmed)
if (decoded === undefined) return dest
@@ -252,6 +309,12 @@ function resolveMediaDest(
): string {
const trimmed = dest.trim()
if (trimmed === '' || trimmed.startsWith('#')) return dest
const filePathFromUrl = fileUrlToLocalPath(trimmed)
if (filePathFromUrl !== undefined) {
const params = new URLSearchParams({ sessionId: scope.sessionId, path: filePathFromUrl })
if (scope.cwd !== undefined && scope.cwd !== '') params.set('cwd', scope.cwd)
return hostRouteUrl(`sidebar/file?${params.toString()}`, baseUrl).href
}
if (isRemoteUrl(trimmed)) return dest
const absolute = isAbsolutePath(trimmed)
if (!absolute && directory === undefined) return dest
+1 -1
View File
@@ -1011,7 +1011,7 @@ export function matchUrlTarget(tabs: readonly TabDescriptor[], url: URL): TabDes
* The plugin version this service instance reports. Keep in lockstep with
* `package.json`'s version — `tests/service.spec.ts` asserts the pair.
*/
export const SIDEBAR_SERVICE_VERSION = '0.31.0'
export const SIDEBAR_SERVICE_VERSION = '0.31.1'
/**
* Monotonic capability list consumers use to gate new API usage (features
+14 -7
View File
@@ -30,6 +30,7 @@
import { mkdirSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { test, expect, type APIRequestContext } from '@playwright/test'
import { PAGE_URL, composerEditable, createHostApi, dismissOnboarding, gotoPage, hostRpc, sendFirstMessage, sidebarApi } from './host'
@@ -112,6 +113,7 @@ async function seedSession(): Promise<void> {
// The local-image probe: the markdown preview's media route must serve the
// relative path, and a data:image destination must render as an <img>.
writeFileSync(join(WORKSPACE_PATH, SEEDED_PNG), Buffer.from(ONE_PIXEL_PNG, 'base64'))
const seededPngUrl = pathToFileURL(join(WORKSPACE_PATH, SEEDED_PNG)).href
// The README-style probe file: raw-HTML runs (badge wall div with an
// embedded script, a <details> nesting a fence + heading) plus inline tags
// inside a table cell. The script must be sanitized away in the preview.
@@ -130,6 +132,8 @@ async function seedSession(): Promise<void> {
'',
`![data image](data:image/png;base64,${ONE_PIXEL_PNG})`,
'',
`![file url image](${seededPngUrl})`,
'',
'[docs link][def]',
'',
'<details>',
@@ -768,13 +772,16 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async
// Local image: a relative markdown destination must resolve through the
// plugin media route and actually decode. Data image: the vocabulary now
// admits data:image, so it must render as an <img>, not alt text.
const localImage = pane.locator('img[src*="/sidebar/file"]').first()
await expect(localImage, 'the relative markdown image must render through the media route').toHaveCount(1, { timeout: 30_000 })
await localImage.scrollIntoViewIfNeeded()
await expect.poll(
() => localImage.evaluate((image) => (image as HTMLImageElement).naturalWidth),
{ message: 'the local markdown image must decode in the real browser' },
).toBeGreaterThan(0)
const localImages = pane.locator('img[src*="/sidebar/file"]')
await expect(localImages, 'the relative and file: URL markdown images must render through the media route').toHaveCount(2, { timeout: 30_000 })
for (let index = 0; index < 2; index += 1) {
const image = localImages.nth(index)
await image.scrollIntoViewIfNeeded()
await expect.poll(
() => image.evaluate((node) => (node as HTMLImageElement).naturalWidth),
{ message: 'each local markdown image (relative and file: URL) must decode in the real browser' },
).toBeGreaterThan(0)
}
const dataImage = pane.locator('img[src^="data:image/png;base64,"]').first()
await expect(dataImage, 'a markdown data:image must render as an <img>').toHaveCount(1, { timeout: 30_000 })
await dataImage.scrollIntoViewIfNeeded()
+23
View File
@@ -111,6 +111,16 @@ describe('MarkdownDocument (HTML leaves)', () => {
await unmount(root)
})
it('rewrites a raw HTML file: URL through /sidebar/file', async () => {
const { container, root } = await renderDocument('<img src="file:///ws/docs/shot.png" alt="shot"/>')
const img = container.querySelector('img')
expect(img).not.toBeNull()
expect(img?.getAttribute('src')).toBe(
'http://gui.origin/proxy/3080/sidebar/file?sessionId=s1&path=%2Fws%2Fdocs%2Fshot.png&cwd=%2Fws',
)
await unmount(root)
})
it('keeps an inline data:image through DOMPurify', async () => {
const dataUrl = 'data:image/png;base64,iVBORw0KGgo='
const { container, root } = await renderDocument(`<img src="${dataUrl}" alt="pasted"/>`)
@@ -390,6 +400,19 @@ describe('MarkdownDocument (local markdown images)', () => {
await unmount(root)
})
it('renders a markdown-syntax file: URL through the media routes', async () => {
for (const [renderMedia, expected] of [
[media, 'http://gui.origin/proxy/3080/sidebar/file?sessionId=s1&path=%2Fws%2Fdocs%2Fpic.png&cwd=%2Fws'],
[desktopMedia, 'dsh-app://app/api/file?path=%2Fws%2Fdocs%2Fpic.png'],
] as const) {
const { container, root } = await renderDocument('![file](file:///ws/docs/pic.png)', renderMedia)
const img = container.querySelector('img')
expect(img, 'a file: URL image must render as <img>, not alt').not.toBeNull()
expect(img?.getAttribute('src')).toContain(expected)
await unmount(root)
}
})
it('renders a markdown-syntax image data URI (the only data: the vocabulary admits)', async () => {
const dataUrl = 'data:image/png;base64,iVBORw0KGgo='
for (const renderMedia of [media, desktopMedia]) {
+63
View File
@@ -10,6 +10,7 @@ import { describe, expect, it } from 'vitest'
import {
createMarkdownPathImages,
desktopFileUrl,
fileUrlToLocalPath,
markdownImageTarget,
markdownMediaUrl,
resolveLocalMediaDest,
@@ -54,6 +55,26 @@ describe('markdownImageTarget', () => {
})
})
describe('fileUrlToLocalPath', () => {
it('turns POSIX, Windows and localhost file URLs into local paths', () => {
expect(fileUrlToLocalPath('file:///repo/docs/my%20image.png')).toBe('/repo/docs/my image.png')
expect(fileUrlToLocalPath('file://localhost/repo/docs/a.png')).toBe('/repo/docs/a.png')
expect(fileUrlToLocalPath('FILE:///C:/repo/docs/a.png')).toBe('C:\\repo\\docs\\a.png')
expect(fileUrlToLocalPath('file://C:/repo/docs/a.png')).toBe('C:\\repo\\docs\\a.png')
})
it('keeps a UNC file URL in the host resolver\'s forward-slash spelling', () => {
expect(fileUrlToLocalPath('file://server/share/a.png')).toBe('//server/share/a.png')
})
it('refuses malformed file URLs and every non-file scheme', () => {
expect(fileUrlToLocalPath('file:///bad%E0%A4%A.png')).toBeUndefined()
expect(fileUrlToLocalPath('file://')).toBeUndefined()
expect(fileUrlToLocalPath('https://example.com/x.png')).toBeUndefined()
expect(fileUrlToLocalPath('./x.png')).toBeUndefined()
})
})
describe('markdownMediaUrl', () => {
it('builds a same-origin media URL on the page base (browser)', () => {
expect(markdownMediaUrl('/repo/docs/img.png', scope, ORIGIN)).toBe(
@@ -172,6 +193,35 @@ describe('createMarkdownPathImages', () => {
expect(images.resolve('data:application/pdf;base64,AAA')).toBeUndefined()
})
it('maps an authored file: URL through the same media routes as a local path', () => {
const browser = createMarkdownPathImages(scope, '/repo/docs/readme.md', ORIGIN)
expect(browser.resolve('file:///repo/docs/img.png')).toBe(
'http://127.0.0.1:3080/sidebar/file?sessionId=abc&path=%2Frepo%2Fdocs%2Fimg.png&cwd=%2Frepo',
)
const desktop = createMarkdownPathImages(scope, '/repo/docs/readme.md', APP)
expect(desktop.resolve('file:///repo/docs/img.png')).toBe(
'dsh-app://app/api/file?path=%2Frepo%2Fdocs%2Fimg.png',
)
})
it('maps a Windows file: URL with the drive and backslashes intact', () => {
const images = createMarkdownPathImages(
{ sessionId: 'abc', cwd: 'C:\\repo' },
'C:\\repo\\t\\doc.md',
APP,
)
expect(images.resolve('file:///C:/pics/a%20b.png')).toBe(
'dsh-app://app/api/file?path=C%3A%5Cpics%5Ca+b.png',
)
})
it('maps a UNC file: URL through the media route', () => {
const images = createMarkdownPathImages(scope, '/repo/docs/readme.md', ORIGIN)
expect(images.resolve('file://server/share/a.png')).toBe(
'http://127.0.0.1:3080/sidebar/file?sessionId=abc&path=%2F%2Fserver%2Fshare%2Fa.png&cwd=%2Frepo',
)
})
it('maps a relative image from a Windows absolute tab path on the browser base', () => {
// The reporter's platform: an absolute Windows path joined with the image's
// relative destination, then percent-encoded for /sidebar/file.
@@ -208,6 +258,12 @@ describe('resolveLocalMediaDest (raw HTML leaves)', () => {
)
})
it('rewrites a raw HTML file: URL through the media route', () => {
expect(resolveLocalMediaDest('file:///repo/docs/shot.png', scope, '/repo/docs/readme.md', ORIGIN)).toBe(
'http://127.0.0.1:3080/sidebar/file?sessionId=abc&path=%2Frepo%2Fdocs%2Fshot.png&cwd=%2Frepo',
)
})
it('decodes one percent-escape from the authored src', () => {
expect(resolveLocalMediaDest('./my%20shot.png', scope, '/repo/docs/readme.md', ORIGIN)).toBe(
'http://127.0.0.1:3080/sidebar/file?sessionId=abc&path=%2Frepo%2Fdocs%2Fmy+shot.png&cwd=%2Frepo',
@@ -274,6 +330,13 @@ describe('rewriteProseLocalImageUrls', () => {
expect(out).toBe(`![a](${FILE_URL('/repo/cat.png')})`)
})
it('rewrites a file: URL to the media route (prose and legacy file surfaces)', () => {
const out = rewriteProseLocalImageUrls('![a](file:///repo/cat.png)', proseScope, '/repo', ORIGIN)
expect(out).toBe(`![a](${FILE_URL('/repo/cat.png')})`)
expect(rewriteLocalImageUrls('![a](file:///repo/cat.png)', proseScope, '/repo/readme.md', ORIGIN))
.toBe(`![a](${FILE_URL('/repo/cat.png')})`)
})
it('leaves relative destinations untouched when the cwd is unknown', () => {
const md = '![a](./cat.png)\n![b](cat.png)'
expect(rewriteProseLocalImageUrls(md, { sessionId: 'abc' }, undefined, ORIGIN)).toBe(md)