Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### 未发布

- **侧边对话支持图片输入**:可以粘贴截图或选择 PNG / JPEG / WebP / GIF,预览并移除后发送,也支持只发图片。文本与图片整批交给宿主附件服务,历史和待发送队列保留图片预览;刷新或冷恢复后仍可读取。默认上限为 8 张、单张 10 MiB、合计 20 MiB,宿主限制更小时跟随宿主。发送失败保留草稿,网络响应丢失时提示先检查对话;已明确声明只支持文本的模型会拒绝图片。

- ⚡ **大 Markdown 的 Mermaid 预览不再卡死渲染器(chunk 内测量隔离到沙箱 iframe)**:Mermaid 用 `SVGElement.getBBox()` 量文字,测量节点挂在 `document.body` 上 → 每次测量都刷新整个 DSH 文档布局。真机实测一次 `getBBox` **59–75 ms**(15,418 节点),空 iframe 里只要 **1 ms**;31 张图因此阻塞主线程 >20 s,触发桌面壳看门狗杀渲染器,恢复标签页后循环卡死。现在图表改在隐藏的 `sandbox="allow-scripts"` iframe(blob: 自包含 mermaid UMD + 协议)里渲染,父侧只做 postMessage 收发与 SVG 清洗:**单图 1,500–7,300 ms → 30–104 ms,31 图约 5 s 内完成**,客户端 mermaid chunk 同时从 **7.04 MB → 3.69 MB**。另加共享渲染队列(可见/近视口优先,其余 `requestIdleCallback` 逐张补齐,两次之间让出 16 ms 主线程;**所有图最终都会渲染成图,不再退化为代码块**)与按围栏行数预留高度的占位骨架。设计与实测见 [docs/plans/2026-10-23-mermaid-iframe-isolation.md](docs/plans/2026-10-23-mermaid-iframe-isolation.md)。
- ⚡ **大文档滚动流畅性:渲染让位于滚动、隐藏页签不空转、摘掉全量 DOM 扫描**:图表渲染队列在滚动期间暂停(停止滚动 350 ms 后恢复),并且只服务当前可见的预览——隐藏页签里的图表保持占位、切回时才渲染;`Markdown` 变更触发的两次全量扫描(内联 HTML pass、标题锚点 pass)由「每次 mutation 跑一遍」(实测 8–15 ms/次)改为 80 ms 合并一次;打开文档时的近视口判断改为先批量读 rect、再统一写入,去掉每张图一次强制布局;`.mermaidWrap` 增加 `content-visibility: auto` + `contain-intrinsic-size` + `contain: layout paint style`,视口外的图表不再参与布局与绘制。滚动时不再有后台渲染、全量扫描与视口外 SVG 重绘抢主线程;图表仍会在滚动停止后或进入视口时补齐,不退化为代码块。
- 🐞 **图表渲染失败时直接显示 mermaid 的解析错误**:之前只显示通用「Mermaid 渲染失败」+ 源码块(完整错误只在 hover title 里)。现在错误条下方直接给出 mermaid 报错的首两行(如 `Parse error on line 10 ... Expecting 'SEMI', ... got 'UNICODE_TEXT'`),配合下方源码可快速定位坏围栏;错误信息仍完整保留在 title 中。
Expand Down
7 changes: 7 additions & 0 deletions docs/external-plugin-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,12 @@ interface SettingsDescriptor {

---

### Side Chat 图片输入

`POST /sidebar/api/sidechat.prompt` 接受 `{childId,text,images?}`,图片条目为 `{mediaType,data,name?}`,`data` 是原始图片字节的 base64,允许空文本加图片。成功返回 `{accepted:true,messageId}`,消息身份由宿主创建。`sidechat.info` 的 `images` 字段报告附件服务可用性和实际数量、单张及合计字节限制;图片是否适用于所选模型在发送时校验。

转录与 pending 行携带图片出现位置和显示元数据,读取走经宿主鉴权的 `GET /sidebar/sidechat-image?childId=...&messageId=...&blockIndex=...`。路由核验侧聊归属与用户消息身份,禁止用附件 ID 或本地路径直接读取。图片请求只在页签可见时发出;冷历史读取不恢复 Agent。输入与读取边界详见[设计记录](plans/2026-11-02-sidechat-image-input.md)。

## 12. 皮肤兼容(令牌驱动)

> better-sidebar 所有视觉值消费 DSH 的 `--dsw-alias-*` / `--dsw-font-*` / `--ds-*` 令牌(无硬编码颜色),**不做每皮肤适配**。已与 dsh-web-ui 皮肤中心兼容(10 款皮肤全覆盖 `--dsw-alias-*` 层;`tests/theme.spec.ts` 守护)。你的 tab/viewer 组件遵循同样的令牌规则即可自动兼容全部皮肤。
Expand All @@ -1210,6 +1216,7 @@ interface SettingsDescriptor {
- **拖拽区退出(视口层)**:宿主把每个**直挂 body 的子元素**都设成 `no-drag`(`html[data-platform=darwin] body > :not(#root)`,选择器含 id,只能靠 `!important` 压过),而 app-region **无视 `pointer-events`**——插件宿主就是这样一个 body 子元素,在 Electron 里该值还会传到它内部的**铺满视口的面板层**(#772 的 CDP 实测;挂载 lane 用的浏览器引擎不传播该属性,所以面板层自己也声明了同一条规则),于是它把下面每条 `[data-window-drag]` 拖拽带一起抵消(窗口拖一次就失效,同时丢掉 macOS 双击标题栏缩放,issue #772)。契约:装饰性的视口层用**中性值** `-webkit-app-region: initial !important` 退出计算(`initial` 的计算值 `none` 不扣减拖拽区;注意**字面量 `none` 不是中性值**——它计算成 `no-drag`,是扣减值),层内的面板/控件再声明 `no-drag` 保住点击;当前覆盖 `[data-dsh-better-sidebar]`、`[data-dsh-panel-host]`(`> *` 保持 `no-drag`)与 `.mermaidModal`(放大视图是第二个**持久**铺满视口的 body 直挂层)。**交互弹层不要加 `initial`**(`.selectionPopup` 是 `<button>`,`FloatingWindow` / `AnchoredPopover` 自带指针拖拽、不是遮罩层):宿主 `:is(button, a, input, …)` 已给它们 `no-drag`,反过来声明 `initial !important` 会让按下变成拖窗(重演 #103/#111)。放大视图是**遮罩层例外**——它是模态,只有其中的控件必须保持 `no-drag`;代价是它覆盖在顶部拖拽带上时,点背景会变成拖窗而不是关闭(为「放大图时窗口仍可拖」付的账)。**未纳入**:`FileTree` 的 `.uploadDropChatHint` 同样是 body 直挂的装饰层,但它只在 OS 文件拖拽悬停期间存在且 `pointer-events: none`,收益极小、暂不处理(`FloatingWindow` / `AnchoredPopover` 是交互层,按上面的判据本就该保持 `no-drag`)。形状由 `tests/panel-host-css.spec.ts` 在 Linux 的 `pnpm test` 里守护(无 macOS runner;`tests/theme.spec.ts` 只守颜色,故本轮不涉及),真实级联由挂载 lane 的探针按宿主规则断言计算值(面板宿主探针复现宿主两条 darwin 规则,放大视图探针直接用页面里宿主自己的规则)。
- **z-index**:面板宿主层 25、按钮簇 45——低于 DSH ui-cordis 插件面板(30)与浮层栈(100/1000+),浮层天然盖住侧边栏。
- **更改行选中态**:Git 文件行和本轮操作行保持原有布局;选中只绘制 `--dsw-alias-interactive-bg-active` 背景,以及行内 inset 4px、宽 2px 的 `--dsw-alias-state-business-primary` 标记。选中规则与缩进参考线的绝对定位规则必须分开;`tests/theme.spec.ts` 解析实际 CSS 规则守护,挂载测试验证点击后文件行仍在原分组内。
- **侧聊图片**:草稿预览与历史图片使用同一缩略图布局,长宽保持比例且限制在输入框与转录列内;草稿边框使用 `--dsw-alias-hairline`,移除按钮沿用宿主 `Button`。隐藏页签停止图片读取并释放 blob URL,切回后按消息身份重新读取。图片内容本身保留用户的原始颜色。
- **提交图高度**:更改区保持自然高度,提交图区填满固定底栏上方的剩余空间,不设 `vh` 或固定最大高度。展开的图谱分区以 248px(28px 标题 + 220px 视口)为最小高度参与 flex 分配,避免自动最小内容高度把长历史撑到外层;折叠后只保留标题,长历史在内部滚动;更改列表过长时仍由原外层滚动容器承载。预览区展开或窗口缩放后随可用空间调整,无需额外尺寸观察器。
- **提交图的 ref pills(含 tag)**:分支/远端/HEAD 按 lane 调色板上色(五个 `--dsw-alias-state-*`);tag 是装饰而非 lane,使用中性 `--dsw-alias-label-secondary` + 虚线边框,不占 `data-color` 槽位,并以服务端返回的 `tag: ` 名称前缀作为文字 kind 标记(不新增图标/文案)。HEAD 只折叠进本地分支,tag 永不成为 current(detached HEAD 场景同样);`tests/theme.spec.ts` 钉住 tag 的 CSS 规则,`tests/git-graph-ui.spec.tsx` 钉住 tone / current / 无调色板槽位。

Expand Down
33 changes: 33 additions & 0 deletions docs/plans/2026-11-02-sidechat-image-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Side Chat image input

Side Chat accepts PNG, JPEG, WebP and GIF through the file picker or clipboard. The composer reuses the host's 16px paperclip icon as its attachment entry. A draft owns its files and preview URLs until the user removes them, the thread binding ends, or the host accepts that part of the draft. Image-only prompts are valid. Limits are the smaller of the host attachment limits and 8 images, 10 MiB per image, 20 MiB total.

The browser sends text and encoded images together in `sidechat.prompt`. The host validates the entire batch, checks the thread's effective model, and admits all image bytes through `attachments.admitPromptContent` before adding the first-contact boundary or user message. The host creates the user message ID. Accepted echoes, pending rows and durable rows reconcile by that ID; identical text does not establish identity. The accepted echo shows image processing until the pending or durable projection exposes the occurrence. The host may await system-prompt assembly after claiming an inbox message and before logging it, so an echo alone does not establish read membership.

The ordinary JSON body limit stays 1 MiB. Only the exact prompt method gets enough additional room for bounded base64, with a separate 1 MiB metadata limit and at most two concurrent prompt body/admission requests. Oversized streams return 413. Authentication runs before buffering. The attachment service validates actual image content. Its durable writes and the Agent inbox are separate host operations: storage failure can leave unreferenced image bytes, and process failure between boundary injection and followup cannot be made transactional in a plugin.

The image GET locator is `{childId,messageId,blockIndex}`. A supplied attachment ID or filesystem path is never read authority. The route verifies a sidechat creation descriptor, subagent origin and parent, then finds the occurrence in the thread's own durable user messages or current legitimate pending inbox. It excludes inherited ghosts and messages removed before claim. Responses use the host media type, `nosniff`, and `private, no-store`. Cold reads do not activate an Agent. Transcript, metadata and image requests share a bounded per-persistence snapshot cache keyed by the host storage revision, including concurrent-read deduplication.

Cold pending replay folds every inbox splice over full messages before excluding exact inherited IDs. Filtering the inherited prefix before replay would change queue indices. Cold rows expose previews but cannot dequeue through the existing live-only API.

Each draft binding has its own active lifetime and revision. FileReader and request completion retain their captured child ID, so A-to-B-to-A navigation cannot deliver to a new owner or erase its draft. An accepted attempt retires only its captured image IDs; newer edits remain. Object URLs are revoked on removal and teardown. Saved previews load through the authenticated host route only while visible and release their blob URLs when hidden. A lost network response preserves the draft and tells the user to check the conversation before retrying. There is no automatic replay.

Cold resumes are shared per thread. Closing a thread or unloading the plugin invalidates pending delivery and cancels an unfinished resume. After asynchronous admission, delivery rechecks the current model and lifetime, compares the validated selection again without an intervening await, then synchronously decides whether to add the first boundary and enqueue the message. If followup throws immediately, only that newly inserted boundary is removed.

The selected design uses host-created IDs and one combined prompt request. A staged upload registry would add lease/receipt cleanup without a host transaction. A client-created frozen message would rely on additional inbox-consumer compatibility. Independent review selected the combined host-ID design and added explicit lifecycle guards and resource limits.

Verification covers batch failure before boundary, effective model changes, plugin unload, message identity, image-only input, occurrence ownership, cold full-log replay, shared cold reads, clipboard/picker input, delayed completions, draft URL cleanup, localized uncertainty, and theme constraints. A separate real-host harness captures the OpenAI-compatible provider request and decodes its image payload, then checks page reload and cold restart previews. Actual run results belong in the PR verification evidence.

The reusable harness runs against preinstalled host dependencies. Create an isolated directory with a minimal package manifest, install `@deepseek-ai/dsh@0.2.1-rc.1` there using the registry and memory options from AGENTS, then build this repository and install Playwright Chromium. No provider key is required; the harness starts a deterministic loopback provider and a separate scratch profile.

```sh
node scripts/e2e-sidechat-images.mjs --host-root /path/to/isolated-host --large-image --mount-check
```

Use `--channel chrome` for an installed Chrome, `--plugin /path/to/unpacked/package` to exercise a tarball, `--baseline` for the unchanged plugin, and `--artifacts-dir /path/to/results` to retain evidence at a chosen location. The default is a fresh directory in the system temp area. The script stops only its own host process tree and retains the fixture, screenshots and provider captures.

The recorded rc.1/Chrome run selected and pasted a 1024×768 PNG of 2,352,559 bytes. The JSON prompt bodies were 3,136,904 and 3,142,724 bytes, both above the old 1 MiB cap. The model-request images were normalized JPEGs; decoded dimensions and fixture pixels matched. Eight image reads across delivery, page reload and a complete host restart returned 200. The same run opened the Files editor and replaced the client entry inside the page without a registration error. See the [verification receipt](sidechat-image-input/verification.json).

| Before image input | Draft preview | After a cold host restart |
| --- | --- | --- |
| ![Side Chat before image input](sidechat-image-input/before.png) | ![Selected image in the Side Chat draft](sidechat-image-input/draft.png) | ![Both images restored after a cold host restart](sidechat-image-input/after-restart.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/plans/sidechat-image-input/before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/plans/sidechat-image-input/draft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 153 additions & 0 deletions docs/plans/sidechat-image-input/verification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"status": "passed",
"host": "0.2.1-rc.1",
"browser": "Chrome",
"artifact": {
"format": "npm tarball",
"bytes": 5595547,
"sha256": "cfadc207aa539c293e1c57cee5d803773b8b542ff1db5ba2a0089ffbae60b529"
},
"fixture": {
"bytes": 2352559,
"width": 1024,
"height": 768
},
"tests": {
"finalFocused": {
"total": 317,
"passed": 317,
"failed": 0,
"skipped": 0
},
"earlierWindowsFullSweep": {
"total": 2968,
"passed": 2960,
"failed": 1,
"skipped": 7,
"scope": "Before the final model-selection microtask regression and paperclip adjustment; these are covered by finalFocused.",
"knownFailure": "plugin-meta.spec.ts expects LF-only tar listing names; Windows tar emits CRLF. Present in the unchanged baseline."
}
},
"steps": [
{
"step": "host-authenticated"
},
{
"step": "baseline-rendered"
},
{
"step": "selected-provider-image",
"images": [
{
"mime": "image/jpeg",
"bytes": 557783,
"sha256": "2345b9bccf138e32b86b6b4484af026b4501b222a3205e5092291098338ba763",
"width": 1024,
"height": 768
}
]
},
{
"step": "selected-saved",
"count": 1,
"images": [
{
"alt": "fixture.png",
"width": 1024,
"height": 768
}
]
},
{
"step": "pasted-provider-image",
"images": [
{
"mime": "image/jpeg",
"bytes": 557783,
"sha256": "2345b9bccf138e32b86b6b4484af026b4501b222a3205e5092291098338ba763",
"width": 1024,
"height": 768
},
{
"mime": "image/jpeg",
"bytes": 557783,
"sha256": "2345b9bccf138e32b86b6b4484af026b4501b222a3205e5092291098338ba763",
"width": 1024,
"height": 768
}
]
},
{
"step": "pasted-saved",
"count": 2,
"images": [
{
"alt": "fixture.png",
"width": 1024,
"height": 768
},
{
"alt": "image.png",
"width": 1024,
"height": 768
}
]
},
{
"step": "page-reload",
"count": 2,
"images": [
{
"alt": "fixture.png",
"width": 1024,
"height": 768
},
{
"alt": "image.png",
"width": 1024,
"height": 768
}
]
},
{
"step": "host-authenticated"
},
{
"step": "cold-host-restart",
"count": 2,
"images": [
{
"alt": "fixture.png",
"width": 1024,
"height": 768
},
{
"alt": "image.png",
"width": 1024,
"height": 768
}
]
},
{
"step": "packed-mount-and-native-entry-replacement",
"filesReadable": true,
"registrationErrors": 0
}
],
"imagePromptBodyBytes": [
3136904,
3142724
],
"imageReadStatuses": [
200,
200,
200,
200,
200,
200,
200,
200
],
"pageErrors": [],
"registrationErrors": []
}
Loading
Loading