From cdaafbc456b307d88c499199d67ff6e5341dd48d Mon Sep 17 00:00:00 2001 From: zhc Date: Thu, 17 Sep 2026 16:29:12 +0800 Subject: [PATCH 1/7] feat(client): add shared developer tools setting --- ...9-08-document-preview-operations.i18n.yaml | 4 +- .../2026-09-08-document-preview-operations.md | 2 +- ...26-09-08-document-preview-operations.zh.md | 2 +- ...09-workspace-file-read-authority.i18n.yaml | 4 +- ...026-09-09-workspace-file-read-authority.md | 4 +- ...-09-09-workspace-file-read-authority.zh.md | 4 +- ...6-09-17-developer-tools-settings.i18n.yaml | 6 +++ .../2026-09-17-developer-tools-settings.md | 29 +++++++++++ .../2026-09-17-developer-tools-settings.zh.md | 29 +++++++++++ apps/web/tests/changed-files-turn.e2e.ts | 7 +++ .../web/tests/developer-tools-settings.e2e.ts | 29 +++++++++++ apps/web/tests/document-preview.e2e.ts | 44 +++++++++++++++- .../settings-chrome/dialog-en.expected.md | 2 + .../settings-chrome/dialog.expected.md | 2 + apps/web/tests/scaffold.ts | 5 ++ apps/web/tsconfig.json | 1 + docs/subsystems/web-client.i18n.yaml | 4 +- docs/subsystems/web-client.md | 2 + docs/subsystems/web-client.zh.md | 2 + .../client/ui-agent-preset/README.i18n.yaml | 4 +- packages/client/ui-agent-preset/README.md | 2 + packages/client/ui-agent-preset/README.zh.md | 2 + .../src/client/AgentPresetSeat.tsx | 18 ++++--- .../ui-agent-preset/src/client/index.ts | 4 +- .../tests/apply.client.spec.ts | 2 +- .../tests/components.client.spec.tsx | 17 ++++++- .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 + packages/client/ui-conversation/README.zh.md | 2 + .../ui-conversation/src/client/apply.ts | 4 ++ .../tests/apply-inject.client.spec.tsx | 2 +- .../tests/apply-wiring.client.spec.tsx | 21 ++++++-- .../client/ui-deliverables/README.i18n.yaml | 4 +- packages/client/ui-deliverables/README.md | 2 + packages/client/ui-deliverables/README.zh.md | 2 + packages/client/ui-deliverables/package.json | 6 ++- .../src/client/Deliverables.tsx | 6 ++- .../ui-deliverables/src/client/index.ts | 6 ++- .../tests/deliverables.client.spec.tsx | 16 +++++- packages/client/ui-deliverables/tsconfig.json | 3 ++ .../ui-settings-general/README.i18n.yaml | 4 +- packages/client/ui-settings-general/README.md | 2 + .../client/ui-settings-general/README.zh.md | 2 + .../src/client/DeveloperToolsRow.module.css | 20 ++++++++ .../src/client/DeveloperToolsRow.tsx | 34 +++++++++++++ .../ui-settings-general/src/client/index.ts | 8 +++ .../ui-settings-general/src/client/locales.ts | 4 ++ .../tests/apply.client.spec.ts | 6 +-- .../tests/components.client.spec.tsx | 19 +++++++ packages/client/ui-settings/README.i18n.yaml | 4 +- packages/client/ui-settings/README.md | 2 + packages/client/ui-settings/README.zh.md | 2 + packages/client/ui-settings/package.json | 6 ++- .../ui-settings/src/client/developer-tools.ts | 27 ++++++++++ .../ui-settings/src/client/settings-scope.ts | 5 ++ .../src/developer-tools-settings.ts | 16 ++++++ packages/client/ui-settings/src/index.ts | 16 ++++-- .../tests/developer-tools.client.spec.ts | 50 +++++++++++++++++++ .../ui-settings/tests/plugin.client.spec.ts | 4 +- .../README.i18n.yaml | 4 +- .../ui-sidebar-documentpreview/README.md | 4 +- .../ui-sidebar-documentpreview/README.zh.md | 4 +- .../ui-sidebar-documentpreview/package.json | 6 ++- .../src/client/html/HtmlBody.tsx | 28 +++++++++-- .../src/client/html/basic-document.ts | 23 +++++++++ .../src/client/html/index.ts | 6 ++- .../src/client/index.ts | 2 +- .../tests/apply.client.spec.ts | 1 + .../tests/basic-html.client.spec.ts | 23 +++++++++ .../tests/document-seat.client.spec.tsx | 1 + .../tests/html-apply.client.spec.ts | 3 +- .../tests/html-body.client.spec.tsx | 23 +++++++++ .../tsconfig.client.json | 3 ++ .../src/client/slot-catalog.ts | 1 + pnpm-lock.yaml | 13 +++-- .../web/document-preview/document.expected.md | 8 +++ tsconfig.host.json | 1 + 77 files changed, 625 insertions(+), 71 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml create mode 100644 .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md create mode 100644 .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md create mode 100644 apps/web/tests/developer-tools-settings.e2e.ts create mode 100644 packages/client/ui-settings-general/src/client/DeveloperToolsRow.module.css create mode 100644 packages/client/ui-settings-general/src/client/DeveloperToolsRow.tsx create mode 100644 packages/client/ui-settings/src/client/developer-tools.ts create mode 100644 packages/client/ui-settings/src/developer-tools-settings.ts create mode 100644 packages/client/ui-settings/tests/developer-tools.client.spec.ts create mode 100644 packages/client/ui-sidebar-documentpreview/src/client/html/basic-document.ts create mode 100644 packages/client/ui-sidebar-documentpreview/tests/basic-html.client.spec.ts diff --git a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.i18n.yaml b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.i18n.yaml index 60e03dbff7..414fda0806 100644 --- a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-09-08-document-preview-operations.md -2026-09-08-document-preview-operations.md: 980e2e443db13d6a956d554172bc765a5c11b435 -2026-09-08-document-preview-operations.zh.md: 364ef9ced6f8d98313f9bc287588c98daa408837 +2026-09-08-document-preview-operations.md: be3a835a6296cb28d9a90c5c5e8b9bf7367598c2 +2026-09-08-document-preview-operations.zh.md: efb87e16cc126001c1a6eb2bf938124d7e00044a diff --git a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.md b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.md index 980e2e443d..be3a835a62 100644 --- a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.md +++ b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.md @@ -18,7 +18,7 @@ Readable files use `dsh-resource://file/session//`. The path ma [Document Preview](../../../../packages/client/ui-sidebar-documentpreview/README.md) owns format selection and loading policy. Metadata registers with `ctx.documentPreviews`; components register separately into the keyed `sidebar.right.tab.document` Slot. Extension registrations precede builtins, then longer suffixes and registration order decide. The toolbar lists supported alternatives and remembers a manual choice per tab. Plain text remains available for unknown extensions and text-compatible renderers. Registered binary suffixes determine text compatibility independently of loading mode; HTML and SVG remain outside those suffixes and retain source viewing. A single candidate renders no viewer control. Registered binary suffixes omit plain text; known binary suffixes without a renderer show an unsupported state without reading the file ([sidebar preview polish](../feature/2026-09-11-sidebar-document-preview-polish.md)). The child receives accumulated text or complete native bytes, the original resource address, and the standard `useResource` and `useTabInfo` hooks. Preview calls existing `read`, `readAll`, and `readRelated` through ordinary injection and decodes bytes in its own `rpc.ts`. Refresh remains per tab, with no resource reload, shared `changed` acknowledgement, extra resource wrapper, or content Session. -Markdown and code reuse the incremental primitives with cumulative paged text. HTML, PDF, and images read complete `Uint8Array` data; Host transport remains base64. Published buffers are borrowed read-only and never persist into layout or Session JSON. PDF.js runs in an owned Worker with version-matched bundled font and decoder data, and copies input before transfer to preserve Preview's retained buffer. HTML runs in a Blob iframe with `sandbox="allow-scripts"`, without same-origin, popup, form, download, or top-navigation privileges. The browser retains its normal external-network rules. Bounded static local JS/CSS reads stay in the parent; the opaque frame creates its own asset Blobs, because it cannot load parent-origin Blobs. PNG, JPEG, GIF, WebP, BMP, ICO, and SVG use image-specific Blob URLs in an `` static-image context. An image wider than the pane scales down to its width at its aspect ratio; a smaller image keeps its intrinsic CSS-pixel dimensions centred by auto margins, and a taller image extends the shared scroller's vertical range ([sidebar preview polish](../feature/2026-09-11-sidebar-document-preview-polish.md)). The renderer provides no zoom or drag-to-pan. SVG markup never enters the application DOM or an iframe, so scripts remain inert and cannot reach the parent page. Replacing HTML or an image revokes its root Blob URL. +Markdown and code reuse the incremental primitives with cumulative paged text. HTML, PDF, and images read complete `Uint8Array` data; Host transport remains base64. Published buffers are borrowed read-only and never persist into layout or Session JSON. PDF.js runs in an owned Worker with version-matched bundled font and decoder data, and copies input before transfer to preserve Preview's retained buffer. With [Developer tools](../feature/2026-09-17-developer-tools-settings.md) enabled, HTML runs in a Blob iframe with `sandbox="allow-scripts"`, without same-origin, popup, form, download, or top-navigation privileges. The browser retains its normal external-network rules. Bounded static local JS/CSS reads stay in the parent; the opaque frame creates its own asset Blobs, because it cannot load parent-origin Blobs. PNG, JPEG, GIF, WebP, BMP, ICO, and SVG use image-specific Blob URLs in an `` static-image context. An image wider than the pane scales down to its width at its aspect ratio; a smaller image keeps its intrinsic CSS-pixel dimensions centred by auto margins, and a taller image extends the shared scroller's vertical range ([sidebar preview polish](../feature/2026-09-11-sidebar-document-preview-polish.md)). The renderer provides no zoom or drag-to-pan. SVG markup never enters the application DOM or an iframe, so scripts remain inert and cannot reach the parent page. Replacing HTML or an image revokes its root Blob URL. PDF.js's official TextLayerBuilder owns selection boundaries and copy normalization over the width-fitted canvas, with shared page cleanup and a component-owned resize observer. Responsive sizing uses the CSS `scale` property independently of PDF.js's page rotation and translation transforms. Its end-of-content marker and stacking rules constrain selection in blank regions; line-break highlighting is suppressed. Per-page cancellation uses the builder's cleanup rather than aborting the first page's signal, because the official selection listeners are shared across pages. diff --git a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.zh.md b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.zh.md index 364ef9ced6..efb87e16cc 100644 --- a/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.zh.md +++ b/.agents/notes/implemented/architecture/2026-09-08-document-preview-operations.zh.md @@ -18,7 +18,7 @@ Document Preview 将资源观察与内容读取分开。[资源模型](2026-09-0 [Document Preview](../../../../packages/client/ui-sidebar-documentpreview/README.zh.md) 负责格式选择和加载策略。元数据通过 `ctx.documentPreviews` 注册;组件单独注册到 keyed `sidebar.right.tab.document` Slot。扩展注册优先于内置注册,其次比较后缀长度和注册顺序。工具栏列出受支持的候选,按 tab 记住手动选择。未知扩展名及文本兼容的渲染器仍可使用纯文本。文本兼容性由注册的二进制后缀决定,与加载方式无关;HTML 和 SVG 不属于二进制后缀,保留源码查看。只有一个候选时不显示查看器控件。注册声明为二进制的后缀不提供纯文本;已知二进制后缀没有注册渲染器时不发起读取,并显示不支持预览的空态([侧边栏预览打磨](../feature/2026-09-11-sidebar-document-preview-polish.zh.md))。子组件收到累积文本或完整原生字节、原始资源地址,以及标准 `useResource` 和 `useTabInfo` 钩子。Preview 经普通注入调用既有 `read`、`readAll` 与 `readRelated`,在自己的 `rpc.ts` 解码字节。刷新仍按 tab 独立进行,不引入资源 reload、共享 `changed` 确认、额外资源包装层或内容 Session。 -Markdown 和代码通过累积的分页文本复用增量渲染原语。HTML、PDF 和图片读取完整 `Uint8Array` 数据;Host 传输保持 base64。发布后的缓冲区只读借用,绝不持久化进布局或 Session JSON。PDF.js 在自有 Worker 中运行,字体和解码数据以相同版本随包发布,转移输入前先复制,以保留 Preview 的缓冲区。HTML 在 Blob iframe 中运行,设置 `sandbox="allow-scripts"`,不授予同源、弹窗、表单、下载或顶层导航权限。浏览器保持正常的外部网络规则。有上限的静态本地 JS/CSS 读取由父页面负责;不透明源 iframe 创建自己的资源 Blob,因为它不能加载父源创建的 Blob。PNG、JPEG、GIF、WebP、BMP、ICO 和 SVG 使用图片专用 Blob URL,在 `` 静态图片上下文中渲染。比面板宽的图片按纵横比缩小到面板宽度;较小的图片保留固有 CSS 像素尺寸并由 auto margin 居中,较高的图片扩展共享滚动区的纵向范围([侧边栏预览打磨](../feature/2026-09-11-sidebar-document-preview-polish.zh.md))。渲染器不提供缩放或拖拽平移。SVG 标记绝不进入应用 DOM 或 iframe,因此脚本保持不可执行,也无法访问父页面。替换 HTML 或图片时会撤销其根 Blob URL。 +Markdown 和代码通过累积的分页文本复用增量渲染原语。HTML、PDF 和图片读取完整 `Uint8Array` 数据;Host 传输保持 base64。发布后的缓冲区只读借用,绝不持久化进布局或 Session JSON。PDF.js 在自有 Worker 中运行,字体和解码数据以相同版本随包发布,转移输入前先复制,以保留 Preview 的缓冲区。开启[开发者工具](../feature/2026-09-17-developer-tools-settings.zh.md)时,HTML 在 Blob iframe 中运行,设置 `sandbox="allow-scripts"`,不授予同源、弹窗、表单、下载或顶层导航权限。浏览器保持正常的外部网络规则。有上限的静态本地 JS/CSS 读取由父页面负责;不透明源 iframe 创建自己的资源 Blob,因为它不能加载父源创建的 Blob。PNG、JPEG、GIF、WebP、BMP、ICO 和 SVG 使用图片专用 Blob URL,在 `` 静态图片上下文中渲染。比面板宽的图片按纵横比缩小到面板宽度;较小的图片保留固有 CSS 像素尺寸并由 auto margin 居中,较高的图片扩展共享滚动区的纵向范围([侧边栏预览打磨](../feature/2026-09-11-sidebar-document-preview-polish.zh.md))。渲染器不提供缩放或拖拽平移。SVG 标记绝不进入应用 DOM 或 iframe,因此脚本保持不可执行,也无法访问父页面。替换 HTML 或图片时会撤销其根 Blob URL。 PDF.js 官方 TextLayerBuilder 在适配宽度的 canvas 上负责选择边界和复制规范化,共享页面清理,并使用由组件拥有的 resize observer。响应式尺寸适配使用独立的 CSS `scale` 属性,与 PDF.js 的页面旋转和平移变换组合。其内容结束标记和堆叠规则限制空白区域中的选择;换行高亮被抑制。逐页取消使用 builder 的清理操作,而不 abort 第一页的信号,因为官方选择监听器跨页面共享。 diff --git a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.i18n.yaml b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.i18n.yaml index e4d4d80da4..97cdb07d3f 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.md -2026-09-09-workspace-file-read-authority.md: 35ac15f5e463910be3b3a0cfe7b80dc69c129ad3 -2026-09-09-workspace-file-read-authority.zh.md: 559a59af0bfa988ff880fad22470397e4e74f296 +2026-09-09-workspace-file-read-authority.md: d1a5b9d9634381cb74b17651c67f2b701402ff1c +2026-09-09-workspace-file-read-authority.zh.md: f8b0fae4325a90548c6b9dc33ac46b17248b04e7 diff --git a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.md b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.md index 35ac15f5e4..d1a5b9d963 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.md +++ b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.md @@ -14,7 +14,7 @@ Workspace Files serves both file content and workspace navigation. Applying work `list` and `changes` remain workspace-scoped because they expose workspace navigation and observation rather than a named file read. `list` rejects a directory outside the root, and `changes` filters observations through the backend's workspace-containment predicate. -`readRelated` resolves a relative path from the base file's directory. A `..` path may therefore read JavaScript or CSS outside the workspace when the Session backend permits it. Document Preview packages bounded, statically declared local scripts and stylesheets into an HTML Blob iframe with `sandbox="allow-scripts"`; the opaque origin blocks parent access, but the browser retains normal network access. This exposure is an intentional security trade-off for rendering static generated HTML. +`readRelated` resolves a relative path from the base file's directory. A `..` path may therefore read JavaScript or CSS outside the workspace when the Session backend permits it. With [Developer tools](../feature/2026-09-17-developer-tools-settings.md) enabled, Document Preview packages bounded, statically declared local scripts and stylesheets into an HTML Blob iframe with `sandbox="allow-scripts"`; the opaque origin blocks parent access, but the browser retains normal network access. This exposure is an intentional security trade-off for rendering static generated HTML. The [Workspace Files service](2026-09-05-workspace-files-service.md) owns paging, file checks, listing, and observation. [Document Preview](2026-09-08-document-preview-operations.md) owns which related files are packaged and the iframe sandbox. @@ -26,4 +26,4 @@ The [Workspace Files service](2026-09-05-workspace-files-service.md) owns paging ## Consequences -Any caller holding a valid Session file address can receive bytes from every regular file that the Session filesystem backend permits it to read, including files outside the workspace. A previewed HTML document can execute packaged local JavaScript and make network requests. Outside files do not produce `changes` frames, so their previews require explicit refresh to observe updates. +Any caller holding a valid Session file address can receive bytes from every regular file that the Session filesystem backend permits it to read, including files outside the workspace. With Developer tools enabled, a previewed HTML document can execute packaged local JavaScript and make network requests. Outside files do not produce `changes` frames, so their previews require explicit refresh to observe updates. diff --git a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.zh.md b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.zh.md index 559a59af0b..f8b0fae432 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.zh.md +++ b/.agents/notes/implemented/architecture/2026-09-09-workspace-file-read-authority.zh.md @@ -14,7 +14,7 @@ Workspace Files 同时提供文件内容与工作区导航。对所有操作应 `list` 与 `changes` 仍限于工作区,因为它们暴露工作区导航和观察,而不是读取一个具名文件。`list` 拒绝根外目录,`changes` 通过后端的工作区包含判定过滤观察。 -`readRelated` 从基准文件所在目录解析相对路径。因此,只要 Session 后端允许,`..` 路径就可以读取工作区外的 JavaScript 或 CSS。Document Preview 把有界、静态声明的本地脚本与样式表打包进带 `sandbox="allow-scripts"` 的 HTML Blob iframe;不透明源阻止访问父应用,但浏览器保留正常网络访问。这种暴露是为渲染静态生成 HTML 而有意接受的安全取舍。 +`readRelated` 从基准文件所在目录解析相对路径。因此,只要 Session 后端允许,`..` 路径就可以读取工作区外的 JavaScript 或 CSS。开启[开发者工具](../feature/2026-09-17-developer-tools-settings.zh.md)时,Document Preview 把有界、静态声明的本地脚本与样式表打包进带 `sandbox="allow-scripts"` 的 HTML Blob iframe;不透明源阻止访问父应用,但浏览器保留正常网络访问。这种暴露是为渲染静态生成 HTML 而有意接受的安全取舍。 [Workspace Files 服务](2026-09-05-workspace-files-service.zh.md)负责分页、文件检查、列举和观察。[Document Preview](2026-09-08-document-preview-operations.zh.md)负责选择要打包的关联文件及 iframe sandbox。 @@ -26,4 +26,4 @@ Workspace Files 同时提供文件内容与工作区导航。对所有操作应 ## Consequences -持有有效 Session 文件地址的调用方可以接收 Session 文件系统后端允许读取的每个普通文件的字节,包括工作区外文件。预览的 HTML 文档可以执行已打包的本地 JavaScript,并发起网络请求。工作区外文件不会产生 `changes` 帧,因此其预览需要显式刷新才能观察更新。 +持有有效 Session 文件地址的调用方可以接收 Session 文件系统后端允许读取的每个普通文件的字节,包括工作区外文件。开启开发者工具时,预览的 HTML 文档可以执行已打包的本地 JavaScript,并发起网络请求。工作区外文件不会产生 `changes` 帧,因此其预览需要显式刷新才能观察更新。 diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml new file mode 100644 index 0000000000..945d2c9c60 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml @@ -0,0 +1,6 @@ +# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each +# side as of the last confirmed-consistent state. Both languages carry equal authority; +# after editing either side, bring the other along and re-record with: +# pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md +2026-09-17-developer-tools-settings.md: cfef2402b8e332f0db60eda50c59637865709130 +2026-09-17-developer-tools-settings.zh.md: 675ffb2812d554d57d5109bfe3b8ac045f2e1138 diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md new file mode 100644 index 0000000000..cfef2402b8 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md @@ -0,0 +1,29 @@ +# Agent Note: Shared developer-tool settings + +Status: implemented + +English | [中文](2026-09-17-developer-tools-settings.zh.md) + +## Problem + +Diagnostic views, preset selection and changed-file summaries add complexity to routine tasks. Scripted HTML also grants capabilities that a basic document preview does not need. Desktop and Web share these renderers, so independent switches would let the same setting produce different results across clients. + +## Decision + +The settings owner exposes one accepted `ui-developer-tools.enabled` preference, defaulting off. General Settings offers the same switch on Web and desktop. The existing settings transport owns validation, ordered writes, persistence and recovery; the browser adds no second copy of the preference. Loopback Web and desktop use Host persistence, while remote Web retains the existing memory policy. + +Off exposes only Chat, removes the conversation View tab bar, hides the new-session preset chip, and omits the changed-files card and its summary read. Turning it off from another View activates Chat. The preset composition, saved default, Session events and explicit delivery cards remain unchanged. This preference is presentation policy, not Host authorization. + +The builtin HTML renderer enforces its own preview policy. Off parses into an inert template, removes active documents and navigation, and mounts an iframe with no sandbox permissions and a CSP denying scripts and external resources. It reads no related files. On retains the opaque scripted Blob renderer and its bounded related-file reads. Switching modes replaces the browsing context and disposes pending reads. The [document-preview decision](../architecture/2026-09-08-document-preview-operations.md) and [filesystem-read authority](../architecture/2026-09-09-workspace-file-read-authority.md) remain authoritative for advanced rendering and Host read access. + +## Alternatives considered + +**Limit the switch to desktop.** The selected requirement contains no desktop-only restriction, and the affected UI is shared. A desktop check would leave the Web renderer with inconsistent visibility and preview behavior. + +**Hide controls without changing the active View or iframe.** Previously selected diagnostic content and already-running scripts would survive the toggle. Filtering the available View roster and remounting the HTML context enforce the selected presentation immediately. + +## Consequences + +Basic HTML sacrifices JavaScript, external and related resources, and link navigation; inline styles and data images remain available. Advanced mode retains normal browser networking and does not gain parent-origin, popup, form or top-navigation privileges. The setting does not constrain third-party preview implementations or revoke Host filesystem authority. + +Component and settings tests cover defaulting, schema rejection, accepted-state updates, chip disclosure, changed-file visibility and iframe disposal. The recorded-session [document preview](../../../../apps/web/tests/document-preview.e2e.ts) and [changed-files](../../../../apps/web/tests/changed-files-turn.e2e.ts) scenarios exercise the real settings control and the shared renderer. The browser scaffold explicitly seeds developer mode for diagnostic scenarios; these two scenarios leave the shipped default untouched. Native Electron execution is a separate acceptance surface. diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md new file mode 100644 index 0000000000..675ffb2812 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md @@ -0,0 +1,29 @@ +# Agent Note: 共享开发者工具设置 + +Status: implemented + +[English](2026-09-17-developer-tools-settings.md) | 中文 + +## Problem + +诊断视图、预设选择和改动文件摘要增加了日常任务的复杂度。支持脚本的 HTML 还授予了基础文档预览不需要的能力。桌面端和 Web 共享这些渲染器,分别设置开关会让同一设置在不同客户端产生不同结果。 + +## Decision + +设置所有者提供一个已接受的 `ui-developer-tools.enabled` 偏好,默认关闭。Web 和桌面端的通用设置提供同一个开关。现有设置传输负责验证、有序写入、持久化和恢复;浏览器不再复制偏好状态。回环 Web 和桌面端使用 Host 持久化,远程 Web 保持现有的内存策略。 + +关闭时仅展示 Chat,移除会话 View 标签栏,隐藏新会话预设入口,并省略改动文件卡片及其摘要读取。在其他 View 中关闭开关会激活 Chat。预设组合、保存的默认值、Session 事件和显式交付卡片保持不变。此偏好是展示策略,不是 Host 授权。 + +内置 HTML 渲染器执行自己的预览策略。关闭时,内容被解析到惰性 template 中,移除主动文档与导航,再放入不授予沙箱权限的 iframe,并通过 CSP 禁止脚本和外部资源。不读取关联文件。开启时保留不透明源的脚本 Blob 渲染器及其有界关联文件读取。切换模式会替换浏览上下文并清理待处理读取。[文档预览决策](../architecture/2026-09-08-document-preview-operations.zh.md)和[文件系统读取权限](../architecture/2026-09-09-workspace-file-read-authority.zh.md)继续定义高级渲染与 Host 读取访问。 + +## Alternatives considered + +**仅在桌面端提供开关。** 所选需求没有仅限桌面的约束,相关 UI 也是共享的。桌面端条件判断会让 Web 渲染器的展示和预览行为不一致。 + +**隐藏控件但不改变激活的 View 或 iframe。** 之前选择的诊断内容和已经运行的脚本会在切换后继续存在。过滤可用 View 并重新挂载 HTML 上下文,可以立即执行所选展示策略。 + +## Consequences + +基础 HTML 放弃 JavaScript、外部与关联资源和链接导航;行内样式与 data 图片仍可用。高级模式保留正常浏览器网络能力,不增加父源、弹窗、表单或顶层导航权限。此设置不约束第三方预览实现,也不撤销 Host 文件系统读取权限。 + +组件和设置测试覆盖默认值、schema 拒绝、已接受状态更新、入口折叠、改动文件展示和 iframe 清理。基于已记录 Session 的[文档预览](../../../../apps/web/tests/document-preview.e2e.ts)与[改动文件](../../../../apps/web/tests/changed-files-turn.e2e.ts)场景验证真实设置控件及共用渲染器。浏览器脚手架为诊断场景显式开启开发者模式;这两个场景保留产品默认值。原生 Electron 执行是独立的验收面。 diff --git a/apps/web/tests/changed-files-turn.e2e.ts b/apps/web/tests/changed-files-turn.e2e.ts index 08045544fc..170adedbe7 100644 --- a/apps/web/tests/changed-files-turn.e2e.ts +++ b/apps/web/tests/changed-files-turn.e2e.ts @@ -51,6 +51,7 @@ describe('web e2e: a git workspace turn ends with its changed files', () => { await writeFile(replayOverride, JSON.stringify(script).replaceAll('{{cwd}}', JSON.stringify(cwdToken).slice(1, -1))) } scaffold = await launchWebScaffold({ + developerTools: false, compareReplaySession: true, extraOverlayPath: fileURLToPath(new URL('./changed-files-turn.overlay.yml', import.meta.url)), ...(replayOverride === undefined ? {} : { replayFixture: FIXTURE, replayOverride }), @@ -106,6 +107,12 @@ describe('web e2e: a git workspace turn ends with its changed files', () => { expect(await readFile(join(cwd, 'notes.txt'), 'utf8')).toBe('start\ndone\n') const card = page.locator('[data-changed-files]') + expect(await card.count()).toBe(0) + await page.getByRole('button', { name: '设置', exact: true }).click() + const settings = page.getByRole('dialog', { name: '设置' }) + await settings.getByRole('switch', { name: '开发者工具' }).click() + await expect.poll(() => settings.getByRole('switch', { name: '开发者工具' }).getAttribute('aria-checked')).toBe('true') + await settings.getByRole('button', { name: '关闭', exact: true }).click() await card.waitFor({ state: 'visible' }) expect(await card.getByText('已编辑 4 个文件', { exact: true }).count()).toBe(1) expect(await card.getByRole('listitem').count()).toBe(3) diff --git a/apps/web/tests/developer-tools-settings.e2e.ts b/apps/web/tests/developer-tools-settings.e2e.ts new file mode 100644 index 0000000000..16c0e6500a --- /dev/null +++ b/apps/web/tests/developer-tools-settings.e2e.ts @@ -0,0 +1,29 @@ +/** Shared settings are off on a fresh Host and survive browser reload through the ordinary settings UI. */ +import { readFile } from 'node:fs/promises' +import { join } from 'node:path' +import { chromium } from 'playwright' +import { expect, it, onTestFinished } from 'vitest' +import { launchWebScaffold } from './scaffold.ts' +import { newEnglishPage } from './support.ts' + +it('persists developer tools in the Host settings document and restores the accepted choice', async () => { + const scaffold = await launchWebScaffold({ developerTools: false }) + onTestFinished(() => scaffold.close()) + const browser = await chromium.launch() + onTestFinished(() => browser.close()) + const page = await newEnglishPage(browser) + await page.goto(scaffold.authenticatedUrl) + await page.getByRole('button', { name: 'Settings', exact: true }).click() + const toggle = page.getByRole('switch', { name: 'Developer tools' }) + expect(await toggle.getAttribute('aria-checked')).toBe('false') + expect(await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')).not.toContain('ui-developer-tools:') + await toggle.click() + await expect.poll(() => toggle.getAttribute('aria-checked')).toBe('true') + expect(await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')).toContain('ui-developer-tools:\n enabled: true') + await page.reload() + await page.getByRole('button', { name: 'Settings', exact: true }).click() + await expect.poll(() => toggle.getAttribute('aria-checked')).toBe('true') + await toggle.click() + await expect.poll(() => toggle.getAttribute('aria-checked')).toBe('false') + expect(await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')).toContain('ui-developer-tools:\n enabled: false') +}) diff --git a/apps/web/tests/document-preview.e2e.ts b/apps/web/tests/document-preview.e2e.ts index 24137b06ad..548abeb18d 100644 --- a/apps/web/tests/document-preview.e2e.ts +++ b/apps/web/tests/document-preview.e2e.ts @@ -86,7 +86,9 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () beforeAll(async () => { outsideRoot = await mkdtemp(join(tmpdir(), 'dsh-preview-outside-')) - scaffold = await launchWebScaffold({ replayFixture: FIXTURE, paceMs: 5, compareReplaySession: false, extraOverlayPath: PAGING_PATCH }) + scaffold = await launchWebScaffold({ + developerTools: false, replayFixture: FIXTURE, paceMs: 5, compareReplaySession: false, extraOverlayPath: PAGING_PATCH, + }) browser = await chromium.launch() page = await newEnglishPage(browser) tripwire = watchConsole(page) @@ -111,17 +113,25 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () await mkdir(SHOT_DIR, { recursive: true }) await saveFailureShot(page, `screenshots/0908-document-preview/smoke-${process.pid}`) }) + expect(await page.locator('[data-slot="conversation.hero.agentPreset"] button').count()).toBe(0) + expect(scaffold.ctx.settings.get('ui-developer-tools')).toEqual({ enabled: false }) const settled = scaffold.whenTurnSettled() const input = page.locator('[data-composer-input]').first() await input.fill(PROMPT) await input.press('Enter') const sessionId = await settled await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 }) + expect(await page.getByRole('tablist').count()).toBe(0) const cwd = scaffold.ctx.agents.get(sessionId)?.session.header.cwd if (cwd === undefined) throw new Error('settled Session has no workspace cwd') if (outsideRoot === undefined) throw new Error('outside fixture directory is unavailable') const outsideScript = join(outsideRoot, 'outside.js') const outsideReference = relative(cwd, outsideScript).replace(/\\/g, '/') + let previewNetworkRequests = 0 + await page.route('https://preview.invalid/developer-tools.png', async (route) => { + previewNetworkRequests += 1 + await route.fulfill({ status: 200, contentType: 'image/png', body: TINY_PNG }) + }) const markdownText = [ '# Markdown smoke', '', 'Rendered from the workspace.', '', ...Array.from({ length: (PAGE_LINES - 4) / 2 }, (_, index) => [`Paragraph ${index + 1}: ${'visible prefix '.repeat(20)}`, '']).flat(), @@ -138,6 +148,7 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () writeFile(join(cwd, 'smoke.html'), [ '', '

HTML smoke

pending

pending

pending

', + '', '

pending

', ' + + LinkSVG + `)) + const parsed = new DOMParser().parseFromString(html, 'text/html') + expect(parsed.head.firstElementChild?.getAttribute('http-equiv')).toBe('Content-Security-Policy') + expect(parsed.querySelector('meta')?.getAttribute('content')).toContain("connect-src 'none'") + expect(parsed.querySelectorAll('script, iframe, object, embed, base, a[href], a[xlink\\:href]')).toHaveLength(0) + expect(parsed.querySelectorAll('meta[http-equiv]')).toHaveLength(1) + expect(parsed.querySelector('p')?.textContent).toBe('Static') + expect(parsed.querySelector('style')?.textContent).toContain('color: red') + expect(parsed.querySelector('img')?.getAttribute('src')).toBe('data:image/png;base64,AA==') +}) diff --git a/packages/client/ui-sidebar-documentpreview/tests/document-seat.client.spec.tsx b/packages/client/ui-sidebar-documentpreview/tests/document-seat.client.spec.tsx index 5c8f1c258c..a5c1ca9433 100644 --- a/packages/client/ui-sidebar-documentpreview/tests/document-seat.client.spec.tsx +++ b/packages/client/ui-sidebar-documentpreview/tests/document-seat.client.spec.tsx @@ -36,6 +36,7 @@ afterEach(async () => { async function boot() { const rt = await SlotTestRuntime.create() runtime = rt + rt.ctx.provide('settingsScope', { developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) rt.ctx.provide('layout', { openRightbar: vi.fn(), closeRightbar: vi.fn() } as never) const locale = new LocaleRuntime(rt.ctx) rt.ctx.provide('locale', locale) diff --git a/packages/client/ui-sidebar-documentpreview/tests/html-apply.client.spec.ts b/packages/client/ui-sidebar-documentpreview/tests/html-apply.client.spec.ts index ccb8ec82c8..554f5e2b06 100644 --- a/packages/client/ui-sidebar-documentpreview/tests/html-apply.client.spec.ts +++ b/packages/client/ui-sidebar-documentpreview/tests/html-apply.client.spec.ts @@ -30,6 +30,7 @@ describe('HTML registration', () => { it('registers its dictionary and matching keyed body, and removes all contributions on disposal', async () => { const ctx = new Context() + ctx.provide('settingsScope', { developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) // No Session or Tab services are mounted; the global callback must use its file address. const registry = new DocumentPreviewRegistry() const dictionaries = new Map() @@ -46,7 +47,7 @@ describe('HTML registration', () => { bind: () => (key: keyof typeof en) => en[key], register: (name: string, value: unknown) => { dictionaries.set(name, value); return () => { dictionaries.delete(name) } }, } as never) - const fiber = ctx.plugin({ apply }) + const fiber = ctx.plugin({ inject: ['settingsScope'], apply }) dispose = async () => { await fiber.dispose() } await fiber.await() expect(registry.candidates('INDEX.HTM').map(entry => entry.id)).toEqual([HTML_BODY_ID]) diff --git a/packages/client/ui-sidebar-documentpreview/tests/html-body.client.spec.tsx b/packages/client/ui-sidebar-documentpreview/tests/html-body.client.spec.tsx index 78eca6a5f2..38f19351fe 100644 --- a/packages/client/ui-sidebar-documentpreview/tests/html-body.client.spec.tsx +++ b/packages/client/ui-sidebar-documentpreview/tests/html-body.client.spec.tsx @@ -34,6 +34,7 @@ afterEach(() => { function props(text = '

hello

'): HtmlBodyProps { const signal = new AbortController().signal return { + useDeveloperTools: select => select(true), resourceAddress: 'dsh-resource://file/session/html/index.html', content: { kind: 'bytes', data: utf8(text) }, wrap: false, @@ -48,6 +49,28 @@ function props(text = '

hello

'): HtmlBodyProps { const utf8 = (text: string): Uint8Array => new TextEncoder().encode(text) describe('HtmlBody', () => { + it('renders static HTML without reading related files, running scripts or retaining an advanced frame', async () => { + const initial = props('

Preview

Static content

') + const basic = { ...initial, useDeveloperTools: ((select: (enabled: boolean) => unknown) => select(false)) as HtmlBodyProps['useDeveloperTools'] } + const view = render() + const frame = screen.getByTitle(en.frame) + expect(frame.getAttribute('sandbox')).toBe('') + expect(frame.getAttribute('srcdoc')).toContain("default-src 'none'") + expect(frame.getAttribute('srcdoc')).not.toContain('Advanced

') + view.rerender() + const advanced = await screen.findByTitle(en.frame) + expect(advanced).not.toBe(frame) + expect(advanced.getAttribute('sandbox')).toBe('allow-scripts') + view.rerender() + expect(advanced.isConnected).toBe(false) + expect(revoke).toHaveBeenCalledOnce() + view.rerender() + expect(screen.getByRole('alert').textContent).toBe(en.failed) + }) + it('renders a Blob iframe with only scripts allowed, keeping it mounted for unrelated props', async () => { const initial = props() const view = render() diff --git a/packages/client/ui-sidebar-documentpreview/tsconfig.client.json b/packages/client/ui-sidebar-documentpreview/tsconfig.client.json index f1a8702766..c02235dfc2 100644 --- a/packages/client/ui-sidebar-documentpreview/tsconfig.client.json +++ b/packages/client/ui-sidebar-documentpreview/tsconfig.client.json @@ -64,6 +64,9 @@ }, { "path": "../../document/office-to-pdf" + }, + { + "path": "../ui-settings" } ] } diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 0caa5b38bf..011791768c 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -1967,6 +1967,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ 'client-ui-chat TranscriptViewRow id \'transcript-view\'', 'client-ui-conversation EnterBehaviorRow id \'composer-enter\'', 'client-ui-permission-presets PermissionRow id \'permission\'', + 'client-ui-settings-general DeveloperToolsRow id \'developer-tools\'', 'client-ui-theme AppearanceRow id \'appearance\'', 'client-ui-theme FontSizeRow id \'font-size\'', ], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13ab4ef874..27966301e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3077,6 +3077,9 @@ importers: '@deepseek-ai/dsh-client-ui-renderer': specifier: workspace:^ version: link:../ui-renderer + '@deepseek-ai/dsh-client-ui-settings': + specifier: workspace:^ + version: link:../ui-settings '@deepseek-ai/dsh-client-ui-sidebar-right': specifier: workspace:^ version: link:../ui-sidebar-right @@ -4015,6 +4018,10 @@ importers: version: 18.3.1 packages/client/ui-settings: + dependencies: + '@deepseek-ai/schemastery': + specifier: link:../../../vendor/schemastery + version: link:../../../vendor/schemastery devDependencies: '@deepseek-ai/cordis': specifier: workspace:^ @@ -4037,9 +4044,6 @@ importers: '@deepseek-ai/dsh-util-values': specifier: workspace:^ version: link:../../util/values - '@deepseek-ai/schemastery': - specifier: link:../../../vendor/schemastery - version: link:../../../vendor/schemastery '@types/react': specifier: ~18.3.1 version: 18.3.31 @@ -4429,6 +4433,9 @@ importers: '@deepseek-ai/dsh-client-ui-session': specifier: workspace:^ version: link:../ui-session + '@deepseek-ai/dsh-client-ui-settings': + specifier: workspace:^ + version: link:../ui-settings '@deepseek-ai/dsh-client-ui-sidebar-right': specifier: workspace:^ version: link:../ui-sidebar-right diff --git a/snapshots/web/document-preview/document.expected.md b/snapshots/web/document-preview/document.expected.md index 28689fa8ca..41159c8576 100644 --- a/snapshots/web/document-preview/document.expected.md +++ b/snapshots/web/document-preview/document.expected.md @@ -14,6 +14,14 @@ - Viewers: Markdown -> Code -> Plain text - Same tab: true +## Basic HTML + +- Developer tools: off by default on Web and desktop +- Sandbox: no permissions +- Inline script: pending +- Local script: pending +- Network requests: 0 + ## HTML - Viewer: HTML diff --git a/tsconfig.host.json b/tsconfig.host.json index 2b98af6f58..edcbb07ff1 100644 --- a/tsconfig.host.json +++ b/tsconfig.host.json @@ -15,6 +15,7 @@ "apps/web/tests/default-product-isolation.e2e.ts", "apps/web/tests/diff-context.e2e.ts", "apps/web/tests/scaffold.ts", + "apps/web/tests/developer-tools-settings.e2e.ts", "apps/web/tests/auto-review-fixture.ts", "apps/web/tests/auto-review-denial.e2e.ts", "apps/web/tests/scaffold-generation.spec.ts", From 012f993ed4b0809c266a05cd797bd92accd19815 Mon Sep 17 00:00:00 2001 From: zhc Date: Thu, 17 Sep 2026 18:08:34 +0800 Subject: [PATCH 2/7] fix: address developer tools preference review --- ...6-09-17-developer-tools-settings.i18n.yaml | 4 +-- .../2026-09-17-developer-tools-settings.md | 8 ++--- .../2026-09-17-developer-tools-settings.zh.md | 8 ++--- apps/web/tests/document-preview.e2e.ts | 28 +++++++++++++++++ .../settings-chrome/dialog-en.expected.md | 2 +- .../settings-chrome/dialog.expected.md | 2 +- apps/web/tests/settings-chrome.e2e.ts | 12 ++++---- .../ui-chat/src/client/chat/ChatView.tsx | 4 +-- .../ui-chat/src/client/contract/slots.ts | 2 +- .../tests/apply-inject.client.spec.tsx | 2 +- .../ui-chat/tests/chat-apply.client.spec.tsx | 1 + .../ui-chat/tests/chat-view.client.spec.tsx | 13 ++++++-- .../client/ui-conversation/README.i18n.yaml | 4 +-- packages/client/ui-conversation/README.md | 2 +- packages/client/ui-conversation/README.zh.md | 2 +- .../ui-conversation/src/client/apply.ts | 4 +-- .../src/client/contract/slots.ts | 2 ++ .../skeleton/DefaultConversationViews.tsx | 1 + .../src/client/view-selection.ts | 3 +- .../tests/apply-inject.client.spec.tsx | 5 ++++ .../tests/assembly-surfaces.client.spec.tsx | 8 ++--- .../tests/browser-plugin.client.spec.ts | 2 +- .../ui-layout/tests/apply.client.spec.ts | 2 +- .../tests/browser-plugin.client.spec.ts | 2 +- .../ui-settings-general/README.i18n.yaml | 4 +-- packages/client/ui-settings-general/README.md | 10 +++---- .../client/ui-settings-general/README.zh.md | 10 +++---- .../src/client/DeveloperToolsRow.tsx | 5 +++- .../ui-settings-general/src/client/locales.ts | 2 ++ .../tests/components.client.spec.tsx | 14 +++++++++ packages/client/ui-settings/README.i18n.yaml | 4 +-- packages/client/ui-settings/README.md | 6 ++-- packages/client/ui-settings/README.zh.md | 6 ++-- .../ui-settings/src/client/developer-tools.ts | 23 ++++++++++---- .../tests/developer-tools.client.spec.ts | 30 +++++++++++++++++++ .../tests/settings-scope.client.spec.ts | 6 ++++ .../src/client/html/basic-document.ts | 22 ++++++++------ .../tests/basic-html.client.spec.ts | 17 +++++++++++ .../tests/browser-plugin.client.spec.ts | 2 +- packages/client/ui-tool/README.i18n.yaml | 4 +-- packages/client/ui-tool/README.md | 2 +- packages/client/ui-tool/README.zh.md | 2 +- .../ui-tool/src/client/tool/ToolCallTree.tsx | 2 +- .../tests/assembly-surfaces.client.spec.tsx | 2 +- .../tests/chat-ptc-subcalls.client.spec.tsx | 3 +- .../tests/tool-call-tree.client.spec.tsx | 6 ++++ .../tests/toolview-slot.client.spec.tsx | 4 +-- .../tests/client-bundle.client.spec.ts | 2 +- .../ui-trajectory/tests/views.client.spec.tsx | 7 +++-- .../tests/workflow-run.client.spec.tsx | 2 +- .../src/client/slot-catalog.ts | 5 ++-- 51 files changed, 235 insertions(+), 90 deletions(-) diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml index 945d2c9c60..43b546d998 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md -2026-09-17-developer-tools-settings.md: cfef2402b8e332f0db60eda50c59637865709130 -2026-09-17-developer-tools-settings.zh.md: 675ffb2812d554d57d5109bfe3b8ac045f2e1138 +2026-09-17-developer-tools-settings.md: 694e2a09fc20ad3185ba9c09058e8684a2247e46 +2026-09-17-developer-tools-settings.zh.md: e03aa258675be8f49dc13a9b43f2e3e00c8b85fa diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md index cfef2402b8..694e2a09fc 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md @@ -10,11 +10,11 @@ Diagnostic views, preset selection and changed-file summaries add complexity to ## Decision -The settings owner exposes one accepted `ui-developer-tools.enabled` preference, defaulting off. General Settings offers the same switch on Web and desktop. The existing settings transport owns validation, ordered writes, persistence and recovery; the browser adds no second copy of the preference. Loopback Web and desktop use Host persistence, while remote Web retains the existing memory policy. +The settings owner exposes one accepted `ui-developer-tools.enabled` preference, defaulting off. General Settings offers the same switch on Web and desktop. The existing settings transport owns validation, ordered writes, persistence and recovery; loopback Web and desktop follow Host acceptance. Remote Web owns one browser-local observable shared by all consumers until reload, with no Host writes. -Off exposes only Chat, removes the conversation View tab bar, hides the new-session preset chip, and omits the changed-files card and its summary read. Turning it off from another View activates Chat. The preset composition, saved default, Session events and explicit delivery cards remain unchanged. This preference is presentation policy, not Host authorization. +Off exposes only Chat, hides tool Inspect actions whose trajectory target is unavailable, removes the conversation View tab bar, hides the new-session preset chip, and omits the changed-files card and its summary read. Turning it off from another View activates Chat. The preset composition, saved default, Session events and explicit delivery cards remain unchanged. This preference is presentation policy, not Host authorization. -The builtin HTML renderer enforces its own preview policy. Off parses into an inert template, removes active documents and navigation, and mounts an iframe with no sandbox permissions and a CSP denying scripts and external resources. It reads no related files. On retains the opaque scripted Blob renderer and its bounded related-file reads. Switching modes replaces the browsing context and disposes pending reads. The [document-preview decision](../architecture/2026-09-08-document-preview-operations.md) and [filesystem-read authority](../architecture/2026-09-09-workspace-file-read-authority.md) remain authoritative for advanced rendering and Host read access. +The builtin HTML renderer enforces its own preview policy. Off parses a complete inert document, preserves root styling, recursively sanitizes template contents, removes active documents, resource hints, SVG animation and navigation, and mounts an iframe with no sandbox permissions and a CSP denying scripts and external resources. It reads no related files. On retains the opaque scripted Blob renderer and its bounded related-file reads. Switching modes replaces the browsing context and disposes pending reads. The [document-preview decision](../architecture/2026-09-08-document-preview-operations.md) and [filesystem-read authority](../architecture/2026-09-09-workspace-file-read-authority.md) remain authoritative for advanced rendering and Host read access. ## Alternatives considered @@ -26,4 +26,4 @@ The builtin HTML renderer enforces its own preview policy. Off parses into an in Basic HTML sacrifices JavaScript, external and related resources, and link navigation; inline styles and data images remain available. Advanced mode retains normal browser networking and does not gain parent-origin, popup, form or top-navigation privileges. The setting does not constrain third-party preview implementations or revoke Host filesystem authority. -Component and settings tests cover defaulting, schema rejection, accepted-state updates, chip disclosure, changed-file visibility and iframe disposal. The recorded-session [document preview](../../../../apps/web/tests/document-preview.e2e.ts) and [changed-files](../../../../apps/web/tests/changed-files-turn.e2e.ts) scenarios exercise the real settings control and the shared renderer. The browser scaffold explicitly seeds developer mode for diagnostic scenarios; these two scenarios leave the shipped default untouched. Native Electron execution is a separate acceptance surface. +Component and settings tests cover defaulting, schema rejection, accepted-state updates, chip disclosure, changed-file visibility and iframe disposal. The recorded-session [document preview](../../../../apps/web/tests/document-preview.e2e.ts) and [changed-files](../../../../apps/web/tests/changed-files-turn.e2e.ts) scenarios exercise the real settings control and the shared renderer. The browser scaffold explicitly seeds developer mode for diagnostic scenarios; settings chrome, document preview and changed-file scenarios leave the shipped default untouched. Native Electron execution remains unverified. diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md index 675ffb2812..e03aa25867 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md @@ -10,11 +10,11 @@ Status: implemented ## Decision -设置所有者提供一个已接受的 `ui-developer-tools.enabled` 偏好,默认关闭。Web 和桌面端的通用设置提供同一个开关。现有设置传输负责验证、有序写入、持久化和恢复;浏览器不再复制偏好状态。回环 Web 和桌面端使用 Host 持久化,远程 Web 保持现有的内存策略。 +设置所有者提供一个已接受的 `ui-developer-tools.enabled` 偏好,默认关闭。Web 和桌面端的通用设置提供同一个开关。现有设置传输负责验证、有序写入、持久化和恢复;回环 Web 和桌面端跟随 Host 接受的状态。远程 Web 持有一个所有消费者共享的浏览器本地可观察值,刷新后重置,不发送 Host 写入。 -关闭时仅展示 Chat,移除会话 View 标签栏,隐藏新会话预设入口,并省略改动文件卡片及其摘要读取。在其他 View 中关闭开关会激活 Chat。预设组合、保存的默认值、Session 事件和显式交付卡片保持不变。此偏好是展示策略,不是 Host 授权。 +关闭时仅展示 Chat,隐藏轨迹目标不可用的工具 Inspect 操作,移除会话 View 标签栏,隐藏新会话预设入口,并省略改动文件卡片及其摘要读取。在其他 View 中关闭开关会激活 Chat。预设组合、保存的默认值、Session 事件和显式交付卡片保持不变。此偏好是展示策略,不是 Host 授权。 -内置 HTML 渲染器执行自己的预览策略。关闭时,内容被解析到惰性 template 中,移除主动文档与导航,再放入不授予沙箱权限的 iframe,并通过 CSP 禁止脚本和外部资源。不读取关联文件。开启时保留不透明源的脚本 Blob 渲染器及其有界关联文件读取。切换模式会替换浏览上下文并清理待处理读取。[文档预览决策](../architecture/2026-09-08-document-preview-operations.zh.md)和[文件系统读取权限](../architecture/2026-09-09-workspace-file-read-authority.zh.md)继续定义高级渲染与 Host 读取访问。 +内置 HTML 渲染器执行自己的预览策略。关闭时,内容被解析为完整的惰性文档,保留根节点样式,递归清理 template 内容,移除主动文档、资源提示、SVG 动画与导航,再放入不授予沙箱权限的 iframe,并通过 CSP 禁止脚本和外部资源。不读取关联文件。开启时保留不透明源的脚本 Blob 渲染器及其有界关联文件读取。切换模式会替换浏览上下文并清理待处理读取。[文档预览决策](../architecture/2026-09-08-document-preview-operations.zh.md)和[文件系统读取权限](../architecture/2026-09-09-workspace-file-read-authority.zh.md)继续定义高级渲染与 Host 读取访问。 ## Alternatives considered @@ -26,4 +26,4 @@ Status: implemented 基础 HTML 放弃 JavaScript、外部与关联资源和链接导航;行内样式与 data 图片仍可用。高级模式保留正常浏览器网络能力,不增加父源、弹窗、表单或顶层导航权限。此设置不约束第三方预览实现,也不撤销 Host 文件系统读取权限。 -组件和设置测试覆盖默认值、schema 拒绝、已接受状态更新、入口折叠、改动文件展示和 iframe 清理。基于已记录 Session 的[文档预览](../../../../apps/web/tests/document-preview.e2e.ts)与[改动文件](../../../../apps/web/tests/changed-files-turn.e2e.ts)场景验证真实设置控件及共用渲染器。浏览器脚手架为诊断场景显式开启开发者模式;这两个场景保留产品默认值。原生 Electron 执行是独立的验收面。 +组件和设置测试覆盖默认值、schema 拒绝、已接受状态更新、入口折叠、改动文件展示和 iframe 清理。基于已记录 Session 的[文档预览](../../../../apps/web/tests/document-preview.e2e.ts)与[改动文件](../../../../apps/web/tests/changed-files-turn.e2e.ts)场景验证真实设置控件及共用渲染器。浏览器脚手架为诊断场景显式开启开发者模式;设置外壳、文档预览和改动文件场景保留产品默认值。原生 Electron 执行尚未验证。 diff --git a/apps/web/tests/document-preview.e2e.ts b/apps/web/tests/document-preview.e2e.ts index 548abeb18d..57d513c72a 100644 --- a/apps/web/tests/document-preview.e2e.ts +++ b/apps/web/tests/document-preview.e2e.ts @@ -132,6 +132,11 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () previewNetworkRequests += 1 await route.fulfill({ status: 200, contentType: 'image/png', body: TINY_PNG }) }) + const blockedRequests: string[] = [] + await page.route('https://blocked-preview.invalid/**', async (route) => { + blockedRequests.push(route.request().url()) + await route.fulfill({ status: 200, contentType: 'text/html', body: 'ESCAPED' }) + }) const markdownText = [ '# Markdown smoke', '', 'Rendered from the workspace.', '', ...Array.from({ length: (PAGE_LINES - 4) / 2 }, (_, index) => [`Paragraph ${index + 1}: ${'visible prefix '.repeat(20)}`, '']).flat(), @@ -142,6 +147,15 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () 'const tail = "CODE_TAIL";', ] await Promise.all([ + writeFile(join(cwd, 'hostile.html'), ` + + +

Static adversarial preview

+ Plain link +
+ SVG link + + `), writeFile(join(cwd, 'smoke.md'), markdownText), writeFile(join(cwd, 'pages.ts'), codeLines.join('\n')), writeFile(join(cwd, 'notes.unknown'), 'UNKNOWN_SUFFIX\nPlain fallback.'), @@ -274,6 +288,20 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', () `- Same tab: ${String(await markdownTab.getAttribute('data-dockkit-tab') === markdownTabId)}`, ].join('\n')) + await openFile('hostile.html') + const hostileFrame = page.frameLocator('[data-html-preview]') + await hostileFrame.getByRole('heading', { name: 'Static adversarial preview' }).waitFor() + expect(await hostileFrame.locator('html').getAttribute('class')).toBe('dark') + expect(await hostileFrame.locator('body').evaluate(node => getComputedStyle(node).margin)).toBe('0px') + for (const id of ['plain-link', 'shadow-link', 'svg-link']) { + const link = hostileFrame.locator(`#${id}`) + expect(await link.getAttribute('href')).toBeNull() + await link.click() + } + expect(await hostileFrame.locator('noscript, link, set, animate, iframe').count()).toBe(0) + expect(blockedRequests).toEqual([]) + await hostileFrame.getByRole('heading', { name: 'Static adversarial preview' }).waitFor() + await openFile('smoke.html') await expect.poll(() => viewer.innerText()).toBe('HTML') const iframe = preview.locator('[data-html-preview]') diff --git a/apps/web/tests/expected/settings-chrome/dialog-en.expected.md b/apps/web/tests/expected/settings-chrome/dialog-en.expected.md index a7ca7e1f39..f06841fc54 100644 --- a/apps/web/tests/expected/settings-chrome/dialog-en.expected.md +++ b/apps/web/tests/expected/settings-chrome/dialog-en.expected.md @@ -22,6 +22,6 @@ - text: px Conversation display Controls process content in completed turns - button "Compact" - text: Developer tools Show tools and information for debugging and troubleshooting - - switch "Developer tools" [checked] + - switch "Developer tools" - text: Send behavior while busy What Enter and the Send button do while the agent is running; Cmd/Ctrl+Enter uses the other behavior - button "Queue" diff --git a/apps/web/tests/expected/settings-chrome/dialog.expected.md b/apps/web/tests/expected/settings-chrome/dialog.expected.md index 272a15368c..0cd84e6a3c 100644 --- a/apps/web/tests/expected/settings-chrome/dialog.expected.md +++ b/apps/web/tests/expected/settings-chrome/dialog.expected.md @@ -22,6 +22,6 @@ - text: px 对话显示 控制已完成轮次的过程内容 - button "紧凑" - text: 开发者工具 显示用于调试和排查问题的工具与信息 - - switch "开发者工具" [checked] + - switch "开发者工具" - text: 繁忙时的发送行为 智能体运行时 Enter 键和发送按钮的行为;Cmd/Ctrl+Enter 使用另一行为 - button "排队发送" diff --git a/apps/web/tests/settings-chrome.e2e.ts b/apps/web/tests/settings-chrome.e2e.ts index ceed3263cb..b396d5f969 100644 --- a/apps/web/tests/settings-chrome.e2e.ts +++ b/apps/web/tests/settings-chrome.e2e.ts @@ -37,7 +37,7 @@ describe('web e2e: settings modal and General preferences', () => { let tripwire: ReturnType beforeAll(async () => { - scaffold = await launchWebScaffold({}) + scaffold = await launchWebScaffold({ developerTools: false }) browser = await chromium.launch() // Chinese browser: the shared page asserts the localized settings surface // the client derives from it (the English default has its own spec below). @@ -384,7 +384,7 @@ describe('web e2e: settings modal and General preferences', () => { // A second live Host binds another ephemeral port but shares the same // user-settings home. Its fresh origin has no theme localStorage and still // converges to dark before the settings dialog opens. - const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome }) + const second = await launchWebScaffold({ developerTools: false, harnessHome: scaffold.harnessHome }) const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE }) const secondTripwire = watchConsole(secondPage) try { @@ -549,7 +549,7 @@ describe('web e2e: settings modal and General preferences', () => { const reloaded = page.getByRole('dialog', { name: '设置' }) await reloaded.getByRole('button', { name: '插话发送' }).waitFor({ timeout: 10_000 }) - const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome }) + const second = await launchWebScaffold({ developerTools: false, harnessHome: scaffold.harnessHome }) const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE }) const secondTripwire = watchConsole(secondPage) try { @@ -615,7 +615,7 @@ describe('web e2e: settings modal and General preferences', () => { // A Chinese browser on another port still receives the explicit English // preference from the shared Host settings document. - const second = await launchWebScaffold({ harnessHome: scaffold.harnessHome }) + const second = await launchWebScaffold({ developerTools: false, harnessHome: scaffold.harnessHome }) const secondPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE }) const secondTripwire = watchConsole(secondPage) try { @@ -649,7 +649,7 @@ describe('web e2e: settings modal and General preferences', () => { // browser. English is also FALLBACK_LOCALE, so this scenario alone cannot // distinguish detection from the default — the zh scenarios above supply // the discriminating half (a Chinese browser must NOT land on the default). - const fresh = await launchWebScaffold({}) + const fresh = await launchWebScaffold({ developerTools: false }) const enPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'en-US' }) const enTripwire = watchConsole(enPage) onTestFailed(() => saveFailureShot(enPage, 'web-e2e-settings-browser-language')) @@ -688,7 +688,7 @@ describe('web e2e: settings modal and General preferences', () => { // The product default for "no usable signal": a French browser ships // neither zh nor en, so resolution falls to FALLBACK_LOCALE (en) rather // than to Chinese. - const fresh = await launchWebScaffold({}) + const fresh = await launchWebScaffold({ developerTools: false }) const frPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: 'fr-FR' }) const frTripwire = watchConsole(frPage) onTestFailed(() => saveFailureShot(frPage, 'web-e2e-settings-unshipped-language')) diff --git a/packages/client/ui-chat/src/client/chat/ChatView.tsx b/packages/client/ui-chat/src/client/chat/ChatView.tsx index 12a6f42546..acec184158 100644 --- a/packages/client/ui-chat/src/client/chat/ChatView.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatView.tsx @@ -220,7 +220,7 @@ const ChatNodeList = memo(function ChatNodeList({ order, ...seatProps }: ChatNod export function ChatView({ useSession, useChat, useChatNode, useChatNodeProcess, useSessions, useStore, actions, renderSlot, sessionId, openFile, openSkill, openExternalLink, loadOlder, loadThrough, loadImage, openView, chatScroll, forkAt, fileMentions, - useTranscriptView, useProjection, t, + useTranscriptView, useProjection, availableViews, t, }: ChatViewSlotProps) { const order = useChat(s => s.order) const nodeStore = useChat(s => s.nodes) @@ -796,7 +796,7 @@ export function ChatView({ cwd={cwd} openFile={requestOpenFile} openSkill={openSkill} - inspectCall={inspectCall} + inspectCall={availableViews.some(view => view.id === 'trajectory') ? inspectCall : undefined} forkAt={forkAt} loadImage={loadImage} renderMessageImages={renderMessageImages} diff --git a/packages/client/ui-chat/src/client/contract/slots.ts b/packages/client/ui-chat/src/client/contract/slots.ts index 81cee7d021..80b29002b1 100644 --- a/packages/client/ui-chat/src/client/contract/slots.ts +++ b/packages/client/ui-chat/src/client/contract/slots.ts @@ -82,7 +82,7 @@ export interface ChatNodeOwnerProps { /** Open the current source file of a skill referenced by a sent message. */ openSkill: (name: string) => void openFile: (path: string, options?: OpenFileOptions) => void - inspectCall: (callId: ToolCallId) => void + inspectCall?: ((callId: ToolCallId) => void) | undefined forkAt: (seq: number) => void /** * Session-authorized image loader, down-threaded from the Chat view so a diff --git a/packages/client/ui-chat/tests/apply-inject.client.spec.tsx b/packages/client/ui-chat/tests/apply-inject.client.spec.tsx index eab2fdf96e..15aed51516 100644 --- a/packages/client/ui-chat/tests/apply-inject.client.spec.tsx +++ b/packages/client/ui-chat/tests/apply-inject.client.spec.tsx @@ -48,7 +48,7 @@ function sessionFakeFor() { async function bench() { const runtime = await SlotTestRuntime.create() - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const layout = { closeRightbar: vi.fn(), openRightbar: vi.fn() } runtime.ctx.provide('layout', layout as never) const sidebarRight = { diff --git a/packages/client/ui-chat/tests/chat-apply.client.spec.tsx b/packages/client/ui-chat/tests/chat-apply.client.spec.tsx index 83fe28642b..72233351ef 100644 --- a/packages/client/ui-chat/tests/chat-apply.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-apply.client.spec.tsx @@ -38,6 +38,7 @@ async function bench() { const runtime = await SlotTestRuntime.create() const chatSettings = stubSettingsScope() runtime.ctx.provide('settingsScope', { + developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } }, bind: ({ namespace }: { namespace: string }) => namespace === CHAT_SETTINGS_NAMESPACE ? chatSettings.scope : stubSettingsScope().scope, diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index d62466703f..2066cca99c 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -400,6 +400,7 @@ function makeHarness( useTranscriptView: bindSnapshotSelector(transcriptView), renderSlot, SessionProvider: SessionProviderStub, + availableViews: [{ id: 'chat', label: 'Chat' }, { id: 'trajectory', label: 'Trajectory' }], viewRequest: null, openView, completeViewRequest: () => {}, @@ -1320,12 +1321,20 @@ describe('ChatView', () => { expect(view.queryByText('本轮运行失败')).toBeNull() }) + it('removes Inspect when trajectory is unavailable and restores it with the view', () => { + const h = makeHarness({ nodes: [toolResult(3, 'a')] }) + const view = render() + expect(h.toolOwners.at(-1)?.inspectCall).toBeUndefined() + view.rerender() + expect(h.toolOwners.at(-1)?.inspectCall).toBeTypeOf('function') + }) + it('hands the trajectory callback to the Tool seat', () => { const h = makeHarness({ nodes: [toolResult(3, 'a')], }) render() - h.toolOwners[0]?.inspectCall('a') + h.toolOwners[0]?.inspectCall?.('a') expect(h.openView).toHaveBeenCalledWith('trajectory', 'a') }) @@ -2233,7 +2242,7 @@ describe('ChatView', () => { expect(owner.openFile).not.toBe(h.openFile) owner.openFile('src/a.ts') expect(h.openFile).toHaveBeenCalledWith('src/a.ts') - owner.inspectCall('a') + owner.inspectCall?.('a') expect(h.openView).toHaveBeenCalledWith('trajectory', 'a') }) diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index c64a330c57..bfa1ac0977 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-conversation/README.md -README.md: 11ef2b6bfbe0443d37eaabce17f7ee44c8d267ec -README.zh.md: 864332bc685ca496849bf92bf7905e8ecab9a328 +README.md: ac7c4b14d10acdf3addd7939244cd1f614daa42e +README.zh.md: 5755358e22f59c31c02078fa8081e2cdd754f736 diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 11ef2b6bfb..ac7c4b14d1 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -40,7 +40,7 @@ The shared image slot props keep display choices separate from durable reference The context-occupancy button shows a ring and percentage below the input card, after the Session statistics. Clicking it opens the token breakdown in a panel kept inside the viewport, including when no statistics are shown; the button stays hidden until context usage and capacity are available. -With Developer tools off, the shell exposes only Chat and hides the View tab bar. Turning it off while another View is active returns to Chat; stored View preferences and recorded Session data remain intact. Turning it on makes registered Views available again. +With Developer tools off, the shell exposes only Chat and hides the View tab bar. Turning it off while another View is active returns to Chat; stored View preferences and recorded Session data remain intact. Turning it on makes registered Views available again. View owners receive the available roster so their navigation actions can follow the same visibility. The composer registers the File command action and owns its label, availability, and native file-dialog callback. Menu availability and invocation both consult the mounted composer's current attachment-intake policy. Unmounting or locking the composer disables that action; disposing the plugin removes its registration. The callback binding stays inside the input module. diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index 864332bc68..5755358e22 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -40,7 +40,7 @@ target package 通过 declaration merge 扩展 snapshot 与 Location data map, 上下文占用按钮在输入卡片下方、会话统计右侧显示圆环和百分比。点击按钮可在视口内的面板查看 token 构成,没有统计项时面板也不会越界;上下文用量和容量尚不可用时,按钮保持隐藏。 -关闭开发者工具时,外壳仅展示 Chat 并隐藏 View 标签栏。在其他 View 激活时关闭开关会返回 Chat;已保存的 View 偏好和 Session 记录保持不变。开启后,已注册的 View 恢复可用。 +关闭开发者工具时,外壳仅展示 Chat 并隐藏 View 标签栏。在其他 View 激活时关闭开关会返回 Chat;已保存的 View 偏好和 Session 记录保持不变。开启后,已注册的 View 恢复可用。View 所有者接收可用列表,使导航操作跟随相同的可见性。 输入框注册「文件」命令动作,负责其标题、可用性和原生文件选择器回调。菜单可用性与实际调用都读取已挂载输入框当前的附件接收策略。输入框卸载或锁定后该动作不可用,插件 dispose(资源释放)时移除注册。回调绑定留在输入模块内部。 diff --git a/packages/client/ui-conversation/src/client/apply.ts b/packages/client/ui-conversation/src/client/apply.ts index 3c7c444a83..7879f8e388 100644 --- a/packages/client/ui-conversation/src/client/apply.ts +++ b/packages/client/ui-conversation/src/client/apply.ts @@ -34,7 +34,7 @@ import { ConversationPanel } from './skeleton/ConversationPanel.tsx' import { ConversationSession, ConversationSessionHeader } from './skeleton/ConversationSession.tsx' import { InputBar } from './skeleton/InputBar.tsx' import { todoDockEntry } from './skeleton/TodoPanel.tsx' -import { resolveActiveView } from './view-selection.ts' +import { DEFAULT_VIEW_ID, resolveActiveView } from './view-selection.ts' import { en, NS, zh, type ConversationKey } from './locales.ts' import { CONVERSATION_SETTINGS_NAMESPACE, type ConversationSettings } from '../submission-settings.ts' @@ -158,7 +158,7 @@ export function apply(ctx: Context, config: Config = Config({})): void { for (const entry of slots.entries('conversation.view')) { /* v8 ignore next -- list registration validates id at load. */ if (entry.options.id === undefined) continue - if (!ctx.settingsScope.developerTools.enabled.getSnapshot() && entry.options.id !== 'chat') continue + if (!ctx.settingsScope.developerTools.enabled.getSnapshot() && entry.options.id !== DEFAULT_VIEW_ID) continue tabs.push({ id: entry.options.id, label: resolveSlotLabel(entry.options.label) ?? entry.options.id, diff --git a/packages/client/ui-conversation/src/client/contract/slots.ts b/packages/client/ui-conversation/src/client/contract/slots.ts index d37387ec4d..c82e273e3a 100644 --- a/packages/client/ui-conversation/src/client/contract/slots.ts +++ b/packages/client/ui-conversation/src/client/contract/slots.ts @@ -299,6 +299,8 @@ export interface InputZone { /** Conversation View entries obtain their data from registered standard hooks. */ export interface ConvViewOwnerProps { + /** Currently available navigation targets. */ + availableViews: readonly ViewTab[] /** Focus request addressed to the selected View. */ viewRequest: import('./views.ts').ConversationViewRequest | null /** Select a View and address one opaque focus identity to it. */ diff --git a/packages/client/ui-conversation/src/client/skeleton/DefaultConversationViews.tsx b/packages/client/ui-conversation/src/client/skeleton/DefaultConversationViews.tsx index 16d1aedc47..5f4d6ffe40 100644 --- a/packages/client/ui-conversation/src/client/skeleton/DefaultConversationViews.tsx +++ b/packages/client/ui-conversation/src/client/skeleton/DefaultConversationViews.tsx @@ -36,6 +36,7 @@ export function DefaultConversationViews({ return (
{viewId !== undefined && renderSlot('conversation.view', { + availableViews: tabs, viewRequest, openView, completeViewRequest: actions.completeViewRequest, diff --git a/packages/client/ui-conversation/src/client/view-selection.ts b/packages/client/ui-conversation/src/client/view-selection.ts index 7639dbae03..0d777c9b7d 100644 --- a/packages/client/ui-conversation/src/client/view-selection.ts +++ b/packages/client/ui-conversation/src/client/view-selection.ts @@ -1,6 +1,7 @@ import type { ViewTab } from './contract/views.ts' -const DEFAULT_VIEW_ID = 'chat' +/** Chat remains available when developer tools are disabled. */ +export const DEFAULT_VIEW_ID = 'chat' /** * Resolve a preferred registered View, then Chat, without choosing another View. diff --git a/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx b/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx index cf6cf29590..da59f1a80c 100644 --- a/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx +++ b/packages/client/ui-conversation/tests/apply-inject.client.spec.tsx @@ -214,6 +214,11 @@ describe('Conversation inject API', () => { expect(header.instance.store.getSnapshot().view).toBe('chat') removeTrajectory() + await b.runtime.flush() + activate.mockClear() + body.injected.openView('trajectory', 'hidden-call') + expect(activate).not.toHaveBeenCalled() + expect(body.instance.store.getSnapshot().view).toBe('chat') removeChat() await b.runtime.dispose() }) diff --git a/packages/client/ui-conversation/tests/assembly-surfaces.client.spec.tsx b/packages/client/ui-conversation/tests/assembly-surfaces.client.spec.tsx index 39f656a5ac..2ae375104c 100644 --- a/packages/client/ui-conversation/tests/assembly-surfaces.client.spec.tsx +++ b/packages/client/ui-conversation/tests/assembly-surfaces.client.spec.tsx @@ -79,7 +79,7 @@ function WorkspaceProbe({ open }: EmptyWorkspaceOwnerProps) { async function bench(opts?: { blank?: boolean }) { const runtime = await SlotTestRuntime.create() const openSession = provideWorkspaceNavigation(runtime) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const locale = new LocaleRuntime(runtime.ctx) runtime.ctx.provide('locale', locale) runtime.slots.installLocale(locale) @@ -102,7 +102,7 @@ describe('resident composer', () => { it('renders the locked view state while no session exists at all', async () => { const runtime = await SlotTestRuntime.create() provideWorkspaceNavigation(runtime) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const locale = new LocaleRuntime(runtime.ctx) runtime.ctx.provide('locale', locale) runtime.slots.installLocale(locale) @@ -129,7 +129,7 @@ describe('resident composer', () => { it('keeps the complete Hero tree mounted when the first Workspace session appears', async () => { const runtime = await SlotTestRuntime.create() const openSession = provideWorkspaceNavigation(runtime) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const locale = new LocaleRuntime(runtime.ctx) runtime.ctx.provide('locale', locale) runtime.slots.installLocale(locale) @@ -196,7 +196,7 @@ describe('prompt rejection through the assembled composer', () => { it('renders the promptError alert strip and keeps the draft in the machine', async () => { const runtime = await SlotTestRuntime.create() const openSession = provideWorkspaceNavigation(runtime) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const locale = new LocaleRuntime(runtime.ctx) runtime.ctx.provide('locale', locale) runtime.slots.installLocale(locale) diff --git a/packages/client/ui-jobs/tests/browser-plugin.client.spec.ts b/packages/client/ui-jobs/tests/browser-plugin.client.spec.ts index db6245819f..c5fb1571b6 100644 --- a/packages/client/ui-jobs/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-jobs/tests/browser-plugin.client.spec.ts @@ -34,7 +34,7 @@ async function bench(): Promise<{ ctx: Context; fiber: ReturnType () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) await ctx.plugin({ inject: localeInject, apply: applyLocale }).await() // These specs assert the shipped Chinese copy. There is no jsdom `window` in // this lane, so browser-language detection never runs and the locale comes diff --git a/packages/client/ui-layout/tests/apply.client.spec.ts b/packages/client/ui-layout/tests/apply.client.spec.ts index 74c58022c9..adda0cef68 100644 --- a/packages/client/ui-layout/tests/apply.client.spec.ts +++ b/packages/client/ui-layout/tests/apply.client.spec.ts @@ -60,7 +60,7 @@ async function bench() { ctx.provide('connection', { api: { settings: {} }, isLoopback: false } as never) // ui-theme's Appearance row binds a durable scope through these two. ctx.provide('remote', { $on: () => () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) await ctx.plugin({ inject: themeInject, apply: themeApply }).await() await slotsFiber.await() const slots = ctx.get('slots') as SlotRegistry diff --git a/packages/client/ui-schedule/tests/browser-plugin.client.spec.ts b/packages/client/ui-schedule/tests/browser-plugin.client.spec.ts index ada8829181..a8aea3c0f9 100644 --- a/packages/client/ui-schedule/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-schedule/tests/browser-plugin.client.spec.ts @@ -20,7 +20,7 @@ async function baseContext(): Promise { await ctx.plugin(SlotRegistry).await() ctx.provide('connection', { api: { settings: {} }, isLoopback: false } as never) ctx.provide('remote', { $on: () => () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) await ctx.plugin({ inject: localeInject, apply: applyLocale }).await() return ctx } diff --git a/packages/client/ui-settings-general/README.i18n.yaml b/packages/client/ui-settings-general/README.i18n.yaml index 8d04e90769..a485e99405 100644 --- a/packages/client/ui-settings-general/README.i18n.yaml +++ b/packages/client/ui-settings-general/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-settings-general/README.md -README.md: 7bc122f76b86ffdb93b90ab73823adde2ab301af -README.zh.md: 8f0a84cf216edf1eebb782fd8207cd0bb8a538cd +README.md: cf8bb5a75aa90842108646b57ceec67ada8ae711 +README.zh.md: 7df3eee13df7bd041cc5f09288d1b7fe28acded6 diff --git a/packages/client/ui-settings-general/README.md b/packages/client/ui-settings-general/README.md index 7bc122f76b..cf8bb5a75a 100644 --- a/packages/client/ui-settings-general/README.md +++ b/packages/client/ui-settings-general/README.md @@ -9,7 +9,7 @@ English | [中文](README.zh.md) ## Summary -Use this package to give the dsh web client a Settings panel, connection-recovery control, feature-contributed navigation, and sequential first-run onboarding. Users can open it from the sidebar, retry a failed connection immediately, and access a local configuration file when the Host makes one available on a loopback browser. Feature packages supply their own settings rows, sections, and onboarding steps; this package supplies their shared presentation and does not add onboarding copy or built-in General rows. +Use this package to give the dsh web client a Settings panel, connection-recovery control, feature-contributed navigation, and sequential first-run onboarding. Users can open it from the sidebar, retry a failed connection immediately, and access a local configuration file when the Host makes one available on a loopback browser. Feature packages supply their own settings rows, sections, and onboarding steps; this package supplies their shared presentation and the Developer tools switch without adding onboarding copy. ## Table of Contents @@ -31,9 +31,9 @@ In Desktop, the account-row update control shows availability, progress, verific ### The General section -The Developer tools switch controls the shared preference described by [ui-settings](../ui-settings/README.md#use-this-package). It is available in both Web and desktop, follows accepted changes immediately, and disables duplicate input while a write settles. +The Developer tools switch controls the shared preference described by [ui-settings](../ui-settings/README.md#use-this-package). It is available in both Web and desktop, follows accepted changes immediately, and disables duplicate input while a write settles. A failed write displays localized retry guidance. -The General section holds rows registered into `settings.general.item` by feature packages — it has no built-in rows. Feature plugins own the row copy and behavior; the shell only provides the section and its slot. The Appearance row, for example, lives in ui-theme. +The General section holds the built-in Developer tools row and rows registered into `settings.general.item` by feature packages. Each registrant owns its row copy and behavior. The Appearance row, for example, lives in ui-theme. ### Opening the configuration file @@ -51,7 +51,7 @@ The onboarding ledger projects in ascending order and mounts exactly one step at
Implementation internals — click to expand -The shell owns the chrome and the projections; every piece of content and copy belongs to a registrant. +The shell owns the chrome and the projections; it contributes the Developer tools row, while feature registrants own their additional content and copy. ### Ledger projections @@ -102,7 +102,7 @@ None; this package neither assembles nor sends a provider request. These limits define what the shell itself provides versus what features must supply; they are current package constraints. -- **The General section has no built-in rows** — each row appears only when its owning feature plugin is mounted; the shell cannot fill the section alone. +- **Additional General rows require their feature plugins** — the shell supplies Developer tools; feature plugins supply the remaining preferences. ### Dev Note diff --git a/packages/client/ui-settings-general/README.zh.md b/packages/client/ui-settings-general/README.zh.md index 8f0a84cf21..7df3eee13d 100644 --- a/packages/client/ui-settings-general/README.zh.md +++ b/packages/client/ui-settings-general/README.zh.md @@ -9,7 +9,7 @@ kind: "package-reference" ## 概述 -使用本包可为 dsh Web 客户端提供 Settings 面板、连接恢复控件、由功能包贡献的导航,以及依次进行的首次运行引导。用户可以从侧边栏打开面板、立即重试失败的连接,并在宿主为回环浏览器提供本地配置文件时访问该文件。各功能包提供自己的设置行、分区和引导步骤;本包提供共享的界面展示,但不添加引导文案或「通用」分区的内置行。 +使用本包可为 dsh Web 客户端提供 Settings 面板、连接恢复控件、由功能包贡献的导航,以及依次进行的首次运行引导。用户可以从侧边栏打开面板、立即重试失败的连接,并在宿主为回环浏览器提供本地配置文件时访问该文件。各功能包提供自己的设置行、分区和引导步骤;本包提供共享的界面展示和开发者工具开关,但不添加引导文案。 ## 目录 @@ -31,9 +31,9 @@ kind: "package-reference" ### 「通用」分区 -开发者工具开关控制 [ui-settings](../ui-settings/README.zh.md#use-this-package) 定义的共享偏好。Web 和桌面端均提供此开关,立即跟随已接受的变更,并在写入完成前禁用重复输入。 +开发者工具开关控制 [ui-settings](../ui-settings/README.zh.md#use-this-package) 定义的共享偏好。Web 和桌面端均提供此开关,立即跟随已接受的变更,并在写入完成前禁用重复输入。写入失败时显示本地化的重试提示。 -「通用」分区承载由功能包注册进 `settings.general.item` 的行——它没有内置行。功能插件拥有行文案与行为;外壳只提供分区及其 slot。例如「外观」行位于 ui-theme。 +「通用」分区承载内置的开发者工具行和功能包注册进 `settings.general.item` 的行。每个注册方拥有自己的行文案与行为。例如「外观」行位于 ui-theme。 ### 打开配置文件 @@ -51,7 +51,7 @@ kind: "package-reference"
实现细节——点击展开 -外壳拥有界面框架与投影;每段内容与文案都属于某个注册方。 +外壳拥有界面框架与投影,并提供开发者工具行;功能注册方拥有其余内容与文案。 ### 账本投影 @@ -102,7 +102,7 @@ kind: "package-reference" 这些限制说明外壳自身提供什么、功能包必须提供什么;它们是当前包约束。 -- **「通用」分区没有内置行**:每一行仅在其所属功能插件挂载时出现;外壳单独无法填满该分区。 +- **额外的通用设置行需要相应功能插件**:外壳提供开发者工具;功能插件提供其他偏好。 ### 开发备注 diff --git a/packages/client/ui-settings-general/src/client/DeveloperToolsRow.tsx b/packages/client/ui-settings-general/src/client/DeveloperToolsRow.tsx index 972aef2a08..bedc732892 100644 --- a/packages/client/ui-settings-general/src/client/DeveloperToolsRow.tsx +++ b/packages/client/ui-settings-general/src/client/DeveloperToolsRow.tsx @@ -20,15 +20,18 @@ export function DeveloperToolsRow({ useDeveloperTools, setEnabled, t }: PropsRuntime<'settings.general.item'> & PropsLocale<'settings'> & InjectFace) { const enabled = useDeveloperTools(value => value) const [busy, setBusy] = useState(false) + const [failed, setFailed] = useState(false) return
{t('developerTools.title')}
{t('developerTools.description')}
+ {failed &&
{t('developerTools.error')}
}
{ + setFailed(false) setBusy(true) - void setEnabled(next).finally(() => { setBusy(false) }) + void setEnabled(next).catch(() => { setFailed(true) }).finally(() => { setBusy(false) }) }} />
} diff --git a/packages/client/ui-settings-general/src/client/locales.ts b/packages/client/ui-settings-general/src/client/locales.ts index eb806470d2..e906f1714c 100644 --- a/packages/client/ui-settings-general/src/client/locales.ts +++ b/packages/client/ui-settings-general/src/client/locales.ts @@ -27,6 +27,7 @@ export const zh = { 'openDocument.error': '无法打开配置文件', 'general.nav': '通用设置', 'developerTools.title': '开发者工具', + 'developerTools.error': '保存失败,请重试', 'developerTools.description': '显示用于调试和排查问题的工具与信息', 'connection.error': '连接异常,刷新重试', 'connection.connecting': '重新连接中', @@ -65,6 +66,7 @@ export const en = { 'openDocument.error': 'Could not open configuration file', 'general.nav': 'General', 'developerTools.title': 'Developer tools', + 'developerTools.error': 'Could not save. Please try again.', 'developerTools.description': 'Show tools and information for debugging and troubleshooting', 'connection.error': 'Disconnected', 'connection.connecting': 'Reconnecting', diff --git a/packages/client/ui-settings-general/tests/components.client.spec.tsx b/packages/client/ui-settings-general/tests/components.client.spec.tsx index cf941fa13b..89c78fe1af 100644 --- a/packages/client/ui-settings-general/tests/components.client.spec.tsx +++ b/packages/client/ui-settings-general/tests/components.client.spec.tsx @@ -208,3 +208,17 @@ describe('SettingsDocumentAction', () => { expect(screen.getByRole('button', { name: 'Open configuration file' })).toBeTruthy() }) }) + +it('reports a failed developer-tool write and allows retry', async () => { + const state = createSnapshotStore(false) + const setEnabled = vi.fn().mockRejectedValueOnce(new Error('offline')).mockImplementation(async (enabled: boolean) => { state.set(enabled) }) + render() + const toggle = screen.getByRole('switch', { name: 'Developer tools' }) + fireEvent.click(toggle) + expect((await screen.findByRole('alert')).textContent).toBe('Could not save. Please try again.') + expect(toggle.hasAttribute('disabled')).toBe(false) + expect(toggle.getAttribute('aria-checked')).toBe('false') + fireEvent.click(toggle) + await waitFor(() => { expect(toggle.getAttribute('aria-checked')).toBe('true') }) + expect(screen.queryByRole('alert')).toBeNull() +}) diff --git a/packages/client/ui-settings/README.i18n.yaml b/packages/client/ui-settings/README.i18n.yaml index 06a40f9d9f..12d06cb627 100644 --- a/packages/client/ui-settings/README.i18n.yaml +++ b/packages/client/ui-settings/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-settings/README.md -README.md: 1f5d2dae13d0bdeb4e1eb776c0cb05629031e4e8 -README.zh.md: 768fa156dadb335e6571d16014ec97db414d9677 +README.md: 7bb05738e7100daaec622f6e34269c78526cdbce +README.zh.md: 6f332fcbc1c6ae8fa04818c65559c15043ee037b diff --git a/packages/client/ui-settings/README.md b/packages/client/ui-settings/README.md index 1f5d2dae13..7bb05738e7 100644 --- a/packages/client/ui-settings/README.md +++ b/packages/client/ui-settings/README.md @@ -29,7 +29,7 @@ Feature plugins use this package to store and edit their preferences without re- ### Binding a namespace -`ctx.settingsScope.developerTools` owns the shared Web and desktop preference `ui-developer-tools.enabled`, defaulting to `false`. Its `enabled` observable publishes accepted choices and `setEnabled` uses the same ordered settings writes. Desktop and loopback Web persist to the Host document; remote Web retains the existing in-memory settings policy. This controls presentation and HTML preview permissions, not Host authorization or Session recording. +`ctx.settingsScope.developerTools` owns the shared Web and desktop preference `ui-developer-tools.enabled`, defaulting to `false`. Its `enabled` observable publishes accepted choices and `setEnabled` uses the same ordered settings writes. Desktop and loopback Web persist to the Host document; remote Web keeps this choice in one browser-local observable until reload without issuing Host writes. This controls presentation and HTML preview permissions, not Host authorization or Session recording. A feature calls `ctx.settingsScope.bind(spec)` with a per-namespace spec and gets a scope derived from the shared document mirror. The scope snapshot carries the resolved section, composition `base`, raw `user`, revision, writability, and host/memory mode; a field is overridden when it is present in `user`, even when its value equals `base`, and `unset` clears that override. Writes go through the scope: `set` and `unset` submit one operation, while `mutate` submits several ordered operations atomically. Each write is fenced by the namespace revision as `expectedRevision`, so a concurrent write from another surface is refused instead of silently overwritten. A staged editor can supply the revision where its draft began as a fixed fence; otherwise the scope uses the latest queued or mirrored revision. @@ -53,7 +53,7 @@ The package realizes one ownership rule: the browser keeps one shared mirror of ### The describe mirror -The plugin injects `remote` with its `settings` namespace, resolves Host persistence once from the fixed `remote.$host` facts, and owns the one `settings.describe` reader in the browser: a shared mirror refreshed on every forwarded `settings/document-updated` event and on `connection/reset` (the first connection included, closing the window where a commit lands between the eager read and the SSE subscription). Cross-namespace surfaces read it through `ctx.settingsScope.describe()`, a read/fold face (`getSnapshot`/`subscribe`/`ensure`, plus `acceptView` folding a write answer in). +The Host half registers the `ui-developer-tools` schema and its default-off value with settings. The Client plugin injects `remote` with its `settings` namespace, resolves Host persistence once from the fixed `remote.$host` facts, and owns the one `settings.describe` reader in the browser: a shared mirror refreshed on every forwarded `settings/document-updated` event and on `connection/reset` (the first connection included, closing the window where a commit lands between the eager read and the SSE subscription). Cross-namespace surfaces read it through `ctx.settingsScope.describe()`, a read/fold face (`getSnapshot`/`subscribe`/`ensure`, plus `acceptView` folding a write answer in). ### Scope derivation @@ -96,7 +96,7 @@ None; this package neither assembles nor sends a provider request. These limits define where the settings transport cannot reach; they are current package constraints. -- **Non-loopback pages get no durable settings** — this Client keeps Host persistence disabled there, so a scope starts `unavailable` and never crosses the wire; every row it backs is inert even though Connection authentication covers the API. +- **Non-loopback pages get no durable settings** — this Client keeps Host persistence disabled there, so a scope starts `unavailable` and never crosses the wire; generic scope writes are inert even though Connection authentication covers the API. The shared Developer tools preference instead provides browser-local changes. ### Dev Note diff --git a/packages/client/ui-settings/README.zh.md b/packages/client/ui-settings/README.zh.md index 768fa156da..6f332fcbc1 100644 --- a/packages/client/ui-settings/README.zh.md +++ b/packages/client/ui-settings/README.zh.md @@ -29,7 +29,7 @@ kind: "package-reference" ### 绑定命名空间 -`ctx.settingsScope.developerTools` 管理 Web 和桌面端共享的偏好 `ui-developer-tools.enabled`,默认为 `false`。其 `enabled` 可观察值发布已接受的选择,`setEnabled` 使用相同的有序设置写入。桌面端和回环 Web 将设置持久化到 Host 文档;远程 Web 保持现有的内存设置策略。此设置控制界面展示和 HTML 预览权限,不控制 Host 授权或 Session 记录。 +`ctx.settingsScope.developerTools` 管理 Web 和桌面端共享的偏好 `ui-developer-tools.enabled`,默认为 `false`。其 `enabled` 可观察值发布已接受的选择,`setEnabled` 使用相同的有序设置写入。桌面端和回环 Web 将设置持久化到 Host 文档;远程 Web 将此选择保存在单个浏览器本地可观察值中,刷新后重置,不发送 Host 写入。此设置控制界面展示和 HTML 预览权限,不控制 Host 授权或 Session 记录。 功能调用 `ctx.settingsScope.bind(spec)` 并传入按命名空间的 spec,得到一个由共享文档镜像派生的 scope。scope 快照携带解析后的分区、组合 `base`、原始 `user`、revision、可写性以及 host/内存模式;字段只要出现在 `user` 中即视为覆盖,即使其值与 `base` 相等,`unset` 会清除该覆盖。写入经 scope 进行:`set` 与 `unset` 提交一个操作,`mutate` 则原子提交多个有序操作。每次写入都以命名空间 revision 作为 `expectedRevision` 围栏,因此来自另一界面的并发写入会被拒绝,而不是被静默覆盖。暂存编辑器可以把开始草拟时读取的 revision 作为固定围栏传入;否则 scope 使用最新排队或镜像 revision。 @@ -53,7 +53,7 @@ kind: "package-reference" ### Describe 镜像 -插件注入 `remote` 及其 `settings` 命名空间,从固定的 `remote.$host` 事实一次性解析 Host 持久化模式,并持有浏览器中唯一的 `settings.describe` 读取方:一面共享镜像,在每次转发的 `settings/document-updated` 事件与 `connection/reset` 时刷新(首次连接也包含在内,关闭「提交落在急切读取与 SSE 订阅之间」的窗口)。跨命名空间表面通过 `ctx.settingsScope.describe()` 读它,这是一个读取/折叠面(`getSnapshot`/`subscribe`/`ensure`,另有把写应答折入的 `acceptView`)。 +Host 部分向 settings 注册 `ui-developer-tools` schema 及其默认关闭值。Client 插件注入 `remote` 及其 `settings` 命名空间,从固定的 `remote.$host` 事实一次性解析 Host 持久化模式,并持有浏览器中唯一的 `settings.describe` 读取方:一面共享镜像,在每次转发的 `settings/document-updated` 事件与 `connection/reset` 时刷新(首次连接也包含在内,关闭「提交落在急切读取与 SSE 订阅之间」的窗口)。跨命名空间表面通过 `ctx.settingsScope.describe()` 读它,这是一个读取/折叠面(`getSnapshot`/`subscribe`/`ensure`,另有把写应答折入的 `acceptView`)。 ### Scope 派生 @@ -96,7 +96,7 @@ kind: "package-reference" 这些限制说明设置传输层够不到的地方;它们是当前包约束。 -- **非 loopback 页面没有持久化设置**:本 Client 在那里禁用 Host 持久化,因此 scope 以 `unavailable` 起步且从不跨线路;尽管 Connection 认证覆盖 API,它支撑的每一行仍在那里无效。 +- **非 loopback 页面没有持久化设置**:本 Client 在那里禁用 Host 持久化,因此 scope 以 `unavailable` 起步且从不跨线路;尽管 Connection 认证覆盖 API,通用 scope 写入仍在那里无效。共享的开发者工具偏好单独提供浏览器本地变更。 ### 开发备注 diff --git a/packages/client/ui-settings/src/client/developer-tools.ts b/packages/client/ui-settings/src/client/developer-tools.ts index 5041d35fd1..e34897372a 100644 --- a/packages/client/ui-settings/src/client/developer-tools.ts +++ b/packages/client/ui-settings/src/client/developer-tools.ts @@ -1,5 +1,5 @@ /** One accepted preference drives every developer-tool consumer. */ -import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store' +import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store' import type { DeveloperToolsSettings } from '../developer-tools-settings.ts' import type { SettingsScope } from './settings-contract.ts' @@ -7,21 +7,34 @@ import type { SettingsScope } from './settings-contract.ts' export class DeveloperToolsPreference { /** Accepted enablement, observable through renderer-bound hooks. */ readonly enabled: ObservableSnapshot + private readonly local = createSnapshotStore(false) /** @param scope - settings-owned namespace controller. */ constructor(private readonly scope: SettingsScope) { - this.enabled = { + this.enabled = scope.getSnapshot().mode === 'memory' ? this.local : { getSnapshot: () => scope.getSnapshot().value?.enabled ?? false, - subscribe: listener => scope.subscribe(listener), + subscribe: (listener) => { + let previous = this.enabled.getSnapshot() + return scope.subscribe(() => { + const next = this.enabled.getSnapshot() + if (next === previous) return + previous = next + listener() + }) + }, } } /** - * Persist a choice using the settings transport's ordered write and recovery policy. + * Persist a Host choice with ordered writes, or update the shared browser-local choice. * @param enabled - requested developer-tool mode. - * @returns settlement after the write or recovery read. + * @returns settlement after local publication, the Host write or its recovery read. */ setEnabled(enabled: boolean): Promise { + if (this.scope.getSnapshot().mode === 'memory') { + this.local.set(enabled) + return Promise.resolve() + } return this.scope.set('enabled', enabled) } } diff --git a/packages/client/ui-settings/tests/developer-tools.client.spec.ts b/packages/client/ui-settings/tests/developer-tools.client.spec.ts index 1b2f180a18..7d3344ffcf 100644 --- a/packages/client/ui-settings/tests/developer-tools.client.spec.ts +++ b/packages/client/ui-settings/tests/developer-tools.client.spec.ts @@ -48,3 +48,33 @@ describe('developer tools settings', () => { dispose() }) }) + +it('keeps remote browser choices local and publishes only changed values', async () => { + const host = stubSettingsScope() + host.publish({ mode: 'memory' }) + const preference = new DeveloperToolsPreference(host.scope) + const notify = vi.fn() + const dispose = preference.enabled.subscribe(notify) + expect(preference.enabled.getSnapshot()).toBe(false) + await preference.setEnabled(true) + expect(preference.enabled.getSnapshot()).toBe(true) + await preference.setEnabled(true) + expect(notify).toHaveBeenCalledOnce() + await preference.setEnabled(false) + expect(preference.enabled.getSnapshot()).toBe(false) + expect(host.set).not.toHaveBeenCalled() + dispose() +}) + +it('ignores host revisions that do not change enablement', () => { + const host = stubSettingsScope() + const preference = new DeveloperToolsPreference(host.scope) + const notify = vi.fn() + const dispose = preference.enabled.subscribe(notify) + host.publish({ revision: 1 }) + host.publish({ value: { enabled: false } }) + expect(notify).not.toHaveBeenCalled() + host.publish({ value: { enabled: true } }) + expect(notify).toHaveBeenCalledOnce() + dispose() +}) diff --git a/packages/client/ui-settings/tests/settings-scope.client.spec.ts b/packages/client/ui-settings/tests/settings-scope.client.spec.ts index 1eef32e6f0..1feed95b72 100644 --- a/packages/client/ui-settings/tests/settings-scope.client.spec.ts +++ b/packages/client/ui-settings/tests/settings-scope.client.spec.ts @@ -555,6 +555,12 @@ describe('SettingsScopeBinder.bind', () => { }) await fiber.await() expect(scope.getSnapshot()).toMatchObject({ status: 'unavailable', mode: 'memory', writable: false }) + const preference = ctx.settingsScope.developerTools + expect(fiber.ctx.settingsScope.developerTools).toBe(preference) + await preference.setEnabled(true) + expect(fiber.ctx.settingsScope.developerTools.enabled.getSnapshot()).toBe(true) + await fiber.ctx.settingsScope.developerTools.setEnabled(false) + expect(preference.enabled.getSnapshot()).toBe(false) await fiber.dispose() expect(describeCall).not.toHaveBeenCalled() }) diff --git a/packages/client/ui-sidebar-documentpreview/src/client/html/basic-document.ts b/packages/client/ui-sidebar-documentpreview/src/client/html/basic-document.ts index ded1af828d..9c3c28040f 100644 --- a/packages/client/ui-sidebar-documentpreview/src/client/html/basic-document.ts +++ b/packages/client/ui-sidebar-documentpreview/src/client/html/basic-document.ts @@ -7,17 +7,21 @@ import { decodeText } from './bytes.ts' * @returns document with the restrictive CSP first in its head. */ export function createBasicHtmlDocument(data: Uint8Array): string { - const template = document.createElement('template') - template.innerHTML = decodeText(data) - for (const element of template.content.querySelectorAll('script, base, meta[http-equiv], iframe, frame, object, embed')) { - element.remove() - } - for (const link of template.content.querySelectorAll('a, area')) { - link.removeAttribute('href') - link.removeAttribute('xlink:href') + const parsed = new DOMParser().parseFromString(decodeText(data), 'text/html') + const sanitize = (root: Document | DocumentFragment): void => { + for (const element of root.querySelectorAll('script, noscript, base, link, meta[http-equiv], iframe, frame, object, embed, set, animate, animateMotion, animateTransform')) { + element.remove() + } + for (const link of root.querySelectorAll('a, area')) { + link.removeAttribute('href') + link.removeAttribute('xlink:href') + } + for (const template of root.querySelectorAll('template')) sanitize(template.content) } + sanitize(parsed) const policy = document.createElement('meta') policy.setAttribute('http-equiv', 'Content-Security-Policy') policy.setAttribute('content', "default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; media-src data:; connect-src 'none'; frame-src 'none'; form-action 'none'; base-uri 'none'") - return `${policy.outerHTML}${template.innerHTML}` + parsed.head.prepend(policy) + return `${parsed.documentElement.outerHTML}` } diff --git a/packages/client/ui-sidebar-documentpreview/tests/basic-html.client.spec.ts b/packages/client/ui-sidebar-documentpreview/tests/basic-html.client.spec.ts index 0545081a67..9f713ea78e 100644 --- a/packages/client/ui-sidebar-documentpreview/tests/basic-html.client.spec.ts +++ b/packages/client/ui-sidebar-documentpreview/tests/basic-html.client.spec.ts @@ -21,3 +21,20 @@ it('preserves static content and removes navigation, policy overrides and active expect(parsed.querySelector('style')?.textContent).toContain('color: red') expect(parsed.querySelector('img')?.getAttribute('src')).toBe('data:image/png;base64,AA==') }) + +it('preserves document styling and removes navigation inside nested templates and SVG animation', () => { + const html = createBasicHtmlDocument(new TextEncoder().encode(` + +
+ + `)) + const parsed = new DOMParser().parseFromString(html, 'text/html') + expect(parsed.documentElement.lang).toBe('zh') + expect(parsed.documentElement.className).toBe('dark') + expect(parsed.body.style.margin).toBe('0px') + expect(parsed.body.dir).toBe('rtl') + expect(parsed.querySelectorAll('noscript, link, set, animate')).toHaveLength(0) + const nested = parsed.querySelector('template')!.content.querySelector('template')!.content + expect(nested.querySelector('a')!.hasAttribute('href')).toBe(false) + expect(nested.querySelector('iframe')).toBeNull() +}) diff --git a/packages/client/ui-subagent/tests/browser-plugin.client.spec.ts b/packages/client/ui-subagent/tests/browser-plugin.client.spec.ts index e2fa92ac49..7101c7f465 100644 --- a/packages/client/ui-subagent/tests/browser-plugin.client.spec.ts +++ b/packages/client/ui-subagent/tests/browser-plugin.client.spec.ts @@ -78,7 +78,7 @@ async function fullBench(sessions: SessionSummary[]) { }, } as never) ctx.provide('remote', { $on: () => () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) await provideSlotFaces(ctx) await ctx.plugin({ inject: localeInject, apply: applyLocale }).await() await ctx.plugin({ inject: [...inject], apply }).await() diff --git a/packages/client/ui-tool/README.i18n.yaml b/packages/client/ui-tool/README.i18n.yaml index ae29876c1d..04b554ad36 100644 --- a/packages/client/ui-tool/README.i18n.yaml +++ b/packages/client/ui-tool/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-tool/README.md -README.md: 69a4c2d380ff1198e38e8ac7e72cdef90ca1da88 -README.zh.md: 27cbfbfe6ab8e956ec2268014e0549220fc2eeec +README.md: 067fa16bad9f6a34b26da3402de5e0a574323500 +README.zh.md: 9376493b780511c6e412cff4c5b976126c230693 diff --git a/packages/client/ui-tool/README.md b/packages/client/ui-tool/README.md index 69a4c2d380..067fa16bad 100644 --- a/packages/client/ui-tool/README.md +++ b/packages/client/ui-tool/README.md @@ -62,7 +62,7 @@ The package realizes one dispatch rule: atomic Tool views are keyed by wire Tool ### Cards -Every card is read in place in the call tree; there is no second, full-height presentation of a selected call. Row renderers share one pure card model for each terminal, read, diff, search, and web card, and the image card's gallery renders through the tool-owned `tool.call.images` slot. These models validate raw call arguments, result content, failure state, persisted metadata, PTC dispatch `parentCallId`, and Session path facts. Unsupported or malformed inputs use flattened Tool result text. A file-path summary opens the file through the owner's `openFile`, which the chat view routes to the right Sidebar's text preview; `inspect` opens the trajectory view. Card-specific limits and fallback rules for the terminal, diff, read, search, and web cards remain in [the ui-primitives README](../ui-primitives/README.md); the image card's model in this package carries its own fallback rules. +Every card is read in place in the call tree; there is no second, full-height presentation of a selected call. Row renderers share one pure card model for each terminal, read, diff, search, and web card, and the image card's gallery renders through the tool-owned `tool.call.images` slot. These models validate raw call arguments, result content, failure state, persisted metadata, PTC dispatch `parentCallId`, and Session path facts. Unsupported or malformed inputs use flattened Tool result text. A file-path summary opens the file through the owner's `openFile`, which the chat view routes to the right Sidebar's text preview; `inspect` opens the trajectory view and is absent when that View is unavailable; cards then omit Inspect. Card-specific limits and fallback rules for the terminal, diff, read, search, and web cards remain in [the ui-primitives README](../ui-primitives/README.md); the image card's model in this package carries its own fallback rules. Chat diff cards keep nine rows before folding, enough for a file header, one removed/added pair, and three context lines on either side. The collapsed row and expanded footer share the primitive's exact or coarse-replacement counts. diff --git a/packages/client/ui-tool/README.zh.md b/packages/client/ui-tool/README.zh.md index 27cbfbfe6a..9376493b78 100644 --- a/packages/client/ui-tool/README.zh.md +++ b/packages/client/ui-tool/README.zh.md @@ -62,7 +62,7 @@ owner 载荷为 `ToolCallOwnerProps`:`callId`、`toolName`、冻结的 `block` ### 卡片 -每张卡片都直接在调用树中查看;选中调用后不会再显示第二个全高视图。行 renderer 为 terminal、read、diff、search 和 web 卡片各复用同一个纯 card model,image 卡片的图库经由工具自有 `tool.call.images` slot 渲染。这些 model 校验原始调用参数、结果内容、失败状态、持久 metadata、PTC dispatch 的 `parentCallId` 与会话路径信息。不受支持或格式错误的输入使用压平的工具结果文本。文件路径摘要经属主的 `openFile` 打开文件,chat 视图把它路由到右侧 Sidebar 的文本预览;`inspect` 打开轨迹视图。terminal、diff、read、search 与 web 卡片的上限与 fallback 规则仍由 [ui-primitives README](../ui-primitives/README.zh.md) 负责;image 卡片的 fallback 规则由本包内的 card model 自行承载。 +每张卡片都直接在调用树中查看;选中调用后不会再显示第二个全高视图。行 renderer 为 terminal、read、diff、search 和 web 卡片各复用同一个纯 card model,image 卡片的图库经由工具自有 `tool.call.images` slot 渲染。这些 model 校验原始调用参数、结果内容、失败状态、持久 metadata、PTC dispatch 的 `parentCallId` 与会话路径信息。不受支持或格式错误的输入使用压平的工具结果文本。文件路径摘要经属主的 `openFile` 打开文件,chat 视图把它路由到右侧 Sidebar 的文本预览;`inspect` 打开轨迹视图;该视图不可用时不提供此回调,卡片随之隐藏 Inspect。terminal、diff、read、search 与 web 卡片的上限与 fallback 规则仍由 [ui-primitives README](../ui-primitives/README.zh.md) 负责;image 卡片的 fallback 规则由本包内的 card model 自行承载。 Chat diff 卡片在折叠前保留九行,足以容纳文件标题、一对删除与新增行及两侧各三行上下文。折叠工具行与展开卡片底部采用原语一致的精确或粗粒度替换统计。 diff --git a/packages/client/ui-tool/src/client/tool/ToolCallTree.tsx b/packages/client/ui-tool/src/client/tool/ToolCallTree.tsx index f4d62697f7..6338f89f1c 100644 --- a/packages/client/ui-tool/src/client/tool/ToolCallTree.tsx +++ b/packages/client/ui-tool/src/client/tool/ToolCallTree.tsx @@ -29,7 +29,7 @@ const ToolCall = memo(function ToolCall({ cwd, home, loadImage, - inspect: () => { inspectCall(callId) }, + inspect: inspectCall === undefined ? undefined : () => { inspectCall(callId) }, }), [callId, toolName, block, openFile, cwd, home, loadImage, inspectCall]) const autoReviewDenied = useMemo( () => toolRowModel(toolName, block).autoReviewDenial !== null, diff --git a/packages/client/ui-tool/tests/assembly-surfaces.client.spec.tsx b/packages/client/ui-tool/tests/assembly-surfaces.client.spec.tsx index 4b48f88c0b..50facd04d2 100644 --- a/packages/client/ui-tool/tests/assembly-surfaces.client.spec.tsx +++ b/packages/client/ui-tool/tests/assembly-surfaces.client.spec.tsx @@ -76,7 +76,7 @@ async function bench(nodes: ToolResultNode[]) { openWorkspacePath: vi.fn(async () => ({ ok: true, value: { opened: true } })), }, }) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) runtime.ctx.provide('layout', { openDetails: vi.fn(), closeDetails: vi.fn() }) runtime.ctx.provide('sidebarRight', { openResource: vi.fn() } as never) runtime.ctx.provide('uiWorkspace', { diff --git a/packages/client/ui-tool/tests/chat-ptc-subcalls.client.spec.tsx b/packages/client/ui-tool/tests/chat-ptc-subcalls.client.spec.tsx index 58a4eece75..b35e755512 100644 --- a/packages/client/ui-tool/tests/chat-ptc-subcalls.client.spec.tsx +++ b/packages/client/ui-tool/tests/chat-ptc-subcalls.client.spec.tsx @@ -80,6 +80,7 @@ function snapshotWith( /** Test-owned AppFrame role: declares and renders the Chat view list. */ type AppRootProps = PropsRenderSlots<'conversation.view'> const VIEW_OWNER: ConvViewOwnerProps = { + availableViews: [{ id: 'chat', label: 'Chat' }, { id: 'trajectory', label: 'Trajectory' }], viewRequest: null, openView: () => {}, completeViewRequest: () => {}, @@ -103,7 +104,7 @@ async function bench(snapshot: ChatSnapshot) { const chat = createSnapshotStore(snapshot) const events = new ConversationEventRegistry(ctx) const views = new ConversationViewRegistry(ctx) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) ctx.provide('uiConversation', { events, views, diff --git a/packages/client/ui-tool/tests/tool-call-tree.client.spec.tsx b/packages/client/ui-tool/tests/tool-call-tree.client.spec.tsx index 093295b407..f8215ed61c 100644 --- a/packages/client/ui-tool/tests/tool-call-tree.client.spec.tsx +++ b/packages/client/ui-tool/tests/tool-call-tree.client.spec.tsx @@ -93,6 +93,12 @@ describe('ToolCallTree', () => { ]) }) + it('omits Inspect from tool owners when the target view is unavailable', () => { + const owners: ToolCallOwnerProps[] = [] + render() + expect(owners[0]?.inspect).toBeUndefined() + }) + it('dispatches a running call by its wire name and forwards inspect', () => { const owners: ToolCallOwnerProps[] = [] const block: ToolCallBlock = { diff --git a/packages/client/ui-tool/tests/toolview-slot.client.spec.tsx b/packages/client/ui-tool/tests/toolview-slot.client.spec.tsx index c13ac0965a..9a7520117f 100644 --- a/packages/client/ui-tool/tests/toolview-slot.client.spec.tsx +++ b/packages/client/ui-tool/tests/toolview-slot.client.spec.tsx @@ -67,7 +67,7 @@ async function bench(nodes: ToolResultNode[]) { const runtime = await SlotTestRuntime.create() const openWorkspacePath = vi.fn(async () => ({ ok: true, value: { opened: true } })) runtime.remote.provideNamespaces({ session: { openWorkspacePath } }) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const layout = { openDetails: vi.fn(), closeDetails: vi.fn() } runtime.ctx.provide('layout', layout) const sidebarRight = { openResource: vi.fn<(address: string) => void>() } @@ -288,7 +288,7 @@ describe('registrant declaration injection', () => { openWorkspacePath: vi.fn(async () => ({ ok: true, value: { opened: true } })), }, }) - runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + runtime.ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) runtime.ctx.provide('layout', { openDetails: vi.fn(), closeDetails: vi.fn() }) runtime.ctx.provide('sidebarRight', { openResource: vi.fn() } as never) runtime.ctx.provide('uiWorkspace', { diff --git a/packages/client/ui-trajectory/tests/client-bundle.client.spec.ts b/packages/client/ui-trajectory/tests/client-bundle.client.spec.ts index e1ca41bfb2..82dd7573ce 100644 --- a/packages/client/ui-trajectory/tests/client-bundle.client.spec.ts +++ b/packages/client/ui-trajectory/tests/client-bundle.client.spec.ts @@ -89,7 +89,7 @@ describe('tsdown client artifact', () => { const { events, views } = uiConversation ctx.provide('connection', { api: { settings: {} }, isLoopback: false } as never) ctx.provide('remote', { $on: () => () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const locale = await import('@deepseek-ai/dsh-client-locale/client') ctx.plugin({ inject: [...locale.inject], apply: locale.apply }) const fiber = ctx.plugin(exports as { apply: (ctx: Context) => void }) diff --git a/packages/client/ui-trajectory/tests/views.client.spec.tsx b/packages/client/ui-trajectory/tests/views.client.spec.tsx index e1707c6aee..05980a12ca 100644 --- a/packages/client/ui-trajectory/tests/views.client.spec.tsx +++ b/packages/client/ui-trajectory/tests/views.client.spec.tsx @@ -234,6 +234,7 @@ function standaloneProps( useInput: bindSnapshotSelector(input), inputActions, useProjection, + availableViews: [{ id: 'chat', label: 'Chat' }, { id: 'trajectory', label: 'Trajectory' }], viewRequest: null, openView: () => {}, completeViewRequest: () => {}, @@ -290,7 +291,7 @@ async function bench(snapshot = historySnapshot(NODES)) { // The locale plugin backs the locale-aware view tab label ('locale' in // inject); its settings scope needs a connection handle. ctx.provide('connection', { api: { settings: {} }, isLoopback: false } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) await runtime.mount({ inject: [...localeInject], apply: localeApply }) const provide = vi.spyOn(ctx.uiSession, 'provide') const feature = await runtime.mount({ inject: [...inject], apply }) @@ -308,10 +309,10 @@ function tabsOf(slots: SlotRegistry): ViewTab[] { .map(e => ({ id: e.options.id!, label: resolveSlotLabel(e.options.label) ?? e.options.id! })) } -type ConvViewOwner = Pick +type ConvViewOwner = Pick function isConvViewOwner(owner: object): owner is ConvViewOwner { - return 'viewRequest' in owner + return 'availableViews' in owner && 'viewRequest' in owner && 'openView' in owner && typeof owner.openView === 'function' && 'completeViewRequest' in owner && typeof owner.completeViewRequest === 'function' } diff --git a/packages/client/ui-workflow-run/tests/workflow-run.client.spec.tsx b/packages/client/ui-workflow-run/tests/workflow-run.client.spec.tsx index 6c999db2b6..e43dbf163d 100644 --- a/packages/client/ui-workflow-run/tests/workflow-run.client.spec.tsx +++ b/packages/client/ui-workflow-run/tests/workflow-run.client.spec.tsx @@ -884,7 +884,7 @@ describe('plugin lifecycle', () => { await ctx.plugin(SlotRegistry).await() ctx.provide('connection', { api: { settings: {} }, isLoopback: false } as never) ctx.provide('remote', { $on: () => () => {} } as never) - ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never) + ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope, developerTools: { enabled: { getSnapshot: () => true, subscribe: () => () => {} } } } as never) const sessions = new TestSessions(async (action) => { await action() }, ctx) ctx.provide('sessions', sessions) const openSession = vi.fn(async () => {}) diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 011791768c..de039295d5 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -241,7 +241,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ }, ], ownerProps: [ - '/** Stable owner currency delivered to a keyed Chat renderer. */\nexport interface ChatNodeOwnerProps {\n cwd?: string | undefined\n /** Open the current source file of a skill referenced by a sent message. */\n openSkill: (name: string) => void\n openFile: (path: string, options?: OpenFileOptions) => void\n inspectCall: (callId: ToolCallId) => void\n forkAt: (seq: number) => void\n /**\n * Session-authorized image loader, down-threaded from the Chat view so a\n * chat-node renderer can render the attachment presentation slot directly\n * with only the durable references plus this loader, instead of receiving a\n * rendering closure.\n */\n loadImage: MessageImageLoader\n renderMessageImages: RenderMessageImages\n fileMentions: (owner: TurnTailOwnerProps) => MarkdownFileMentions | undefined\n /** Turn-process state when this Node belongs to a projected Turn. */\n turnProcess?: TurnProcessOwnerProps | undefined\n}', + '/** Stable owner currency delivered to a keyed Chat renderer. */\nexport interface ChatNodeOwnerProps {\n cwd?: string | undefined\n /** Open the current source file of a skill referenced by a sent message. */\n openSkill: (name: string) => void\n openFile: (path: string, options?: OpenFileOptions) => void\n inspectCall?: ((callId: ToolCallId) => void) | undefined\n forkAt: (seq: number) => void\n /**\n * Session-authorized image loader, down-threaded from the Chat view so a\n * chat-node renderer can render the attachment presentation slot directly\n * with only the durable references plus this loader, instead of receiving a\n * rendering closure.\n */\n loadImage: MessageImageLoader\n renderMessageImages: RenderMessageImages\n fileMentions: (owner: TurnTailOwnerProps) => MarkdownFileMentions | undefined\n /** Turn-process state when this Node belongs to a projected Turn. */\n turnProcess?: TurnProcessOwnerProps | undefined\n}', ], ownerPropsReferences: [ 'MarkdownFileMentions', @@ -1506,10 +1506,11 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ }, ], ownerProps: [ - '/** Conversation View entries obtain their data from registered standard hooks. */\nexport interface ConvViewOwnerProps {\n /** Focus request addressed to the selected View. */\n viewRequest: import(\'./views.ts\').ConversationViewRequest | null\n /** Select a View and address one opaque focus identity to it. */\n openView: (view: string, focus: string) => void\n /** Acknowledge the current one-shot focus request. */\n completeViewRequest: () => void\n}', + '/** Conversation View entries obtain their data from registered standard hooks. */\nexport interface ConvViewOwnerProps {\n /** Currently available navigation targets. */\n availableViews: readonly ViewTab[]\n /** Focus request addressed to the selected View. */\n viewRequest: import(\'./views.ts\').ConversationViewRequest | null\n /** Select a View and address one opaque focus identity to it. */\n openView: (view: string, focus: string) => void\n /** Acknowledge the current one-shot focus request. */\n completeViewRequest: () => void\n}', ], ownerPropsReferences: [ 'ConversationViewRequest', + 'ViewTab', ], standardProps: [ 'useResource: UseResource', From 07e3619ec3344bfac54aa2eee620fdf0ef2c3ee2 Mon Sep 17 00:00:00 2001 From: zhc Date: Thu, 17 Sep 2026 18:32:59 +0800 Subject: [PATCH 3/7] test(web): enable developer tools in trajectory image fixture --- apps/web/tests/assembled-remote.ts | 22 +++++++++++++++++-- .../trajectory-image-display.expected.e2e.ts | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/web/tests/assembled-remote.ts b/apps/web/tests/assembled-remote.ts index 69739dc7a7..36eab3cb42 100644 --- a/apps/web/tests/assembled-remote.ts +++ b/apps/web/tests/assembled-remote.ts @@ -71,7 +71,14 @@ interface ControlBaseline { interface CapturedFixture { readonly sessionList: { readonly ok: true; readonly value: { readonly items: readonly SessionSummary[] } } - readonly settingsDescribe: unknown + readonly settingsDescribe: { + readonly ok: true + readonly value: { + readonly writable: boolean + readonly hasDocument: boolean + readonly namespaces: readonly unknown[] + } + } readonly credentialsDescribe: unknown readonly modelCatalog: unknown readonly agentPresets: unknown @@ -90,6 +97,8 @@ interface CapturedFixture { } export interface AssembledRemoteOptions { + /** Supply an enabled Host preference for diagnostic View scenarios. */ + readonly developerTools?: boolean /** Return the fixture's image-dimension admission error from Session prompt. */ readonly rejectPrompt?: boolean } @@ -131,7 +140,16 @@ export function createAssembledRemote(options: AssembledRemoteOptions = {}): Ass const mock = RemoteMock.create().load(remoteDefaultResponses) mock.load({ unary: { - 'settings/describe': structuredClone(fixture.settingsDescribe), + 'settings/describe': options.developerTools === true + ? ok({ + ...fixture.settingsDescribe.value, + namespaces: [...fixture.settingsDescribe.value.namespaces, { + ns: 'ui-developer-tools', + schema: { type: 'object', dict: { enabled: { type: 'boolean' } } }, + value: { enabled: true }, applies: 'live', secrets: [], revision: 0, + }], + }) + : structuredClone(fixture.settingsDescribe), 'credentials/describe': structuredClone(fixture.credentialsDescribe), 'session/modelCatalog': structuredClone(fixture.modelCatalog), 'agentPresets/list': structuredClone(fixture.agentPresets), diff --git a/apps/web/tests/trajectory-image-display.expected.e2e.ts b/apps/web/tests/trajectory-image-display.expected.e2e.ts index 855e798e55..2a3ffc9aca 100644 --- a/apps/web/tests/trajectory-image-display.expected.e2e.ts +++ b/apps/web/tests/trajectory-image-display.expected.e2e.ts @@ -81,7 +81,7 @@ it('renders durable record images in the Trajectory details panel from the share configurable: true, value: () => {}, }) - mountAssembledApp() + mountAssembledApp({ remote: { developerTools: true } }) await openFixtureSession() const chatSrc = document.querySelector('[data-align="end"] img')?.getAttribute('src') if (chatSrc === null || chatSrc === undefined) throw new Error('chat gallery image missing') From 54e6aabf0c26ccead0c257b52af37fa6886cc414 Mon Sep 17 00:00:00 2001 From: zhc Date: Thu, 17 Sep 2026 18:35:05 +0800 Subject: [PATCH 4/7] test(client): cover developer tools row settings injection --- .../client/ui-settings-general/tests/apply.client.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/client/ui-settings-general/tests/apply.client.spec.ts b/packages/client/ui-settings-general/tests/apply.client.spec.ts index 659a494bcc..1d11e8ea30 100644 --- a/packages/client/ui-settings-general/tests/apply.client.spec.ts +++ b/packages/client/ui-settings-general/tests/apply.client.spec.ts @@ -13,6 +13,7 @@ import { createClientTest, type TestClient, webApp } from '@deepseek-ai/dsh-clie import { resolveSlotLabel } from '@deepseek-ai/dsh-client-ui-slots' import { LOCALE_SETTINGS_NAMESPACE, LocaleSettingsSchema } from '@deepseek-ai/dsh-client-locale/src/locale-settings.ts' import { inject } from '../src/client/index.ts' +import type { DeveloperToolsRowInjected } from '../src/client/DeveloperToolsRow.tsx' import { CloseLabel, HeaderContent, TriggerContent } from '../src/client/chrome.tsx' import { GeneralSection } from '../src/client/GeneralSection.tsx' import { SettingsDocumentAction } from '../src/client/SettingsDocumentAction.tsx' @@ -103,6 +104,13 @@ describe('ui-settings-general apply', () => { // The shared developer-tool control belongs to General; onboarding remains feature-owned. expect(c.ctx.slots.entries('settings.general.item').filter(row => row.locale === NS).map(row => row.options.id)).toEqual(['developer-tools']) expect(c.ctx.slots.entries('settings.onboarding').filter(row => row.locale === NS)).toEqual([]) + const developerRow = c.ctx.slots.entries('settings.general.item').find(row => row.options.id === 'developer-tools')! + const developer = (developerRow.inject as unknown as () => DeveloperToolsRowInjected)() + expect(developer.hooks.developerTools).toBe(c.ctx.settingsScope.developerTools.enabled) + expect(developer.hooks.developerTools.getSnapshot()).toBe(false) + const setEnabled = vi.spyOn(c.ctx.settingsScope.developerTools, 'setEnabled').mockResolvedValue(undefined) + await developer.setEnabled(true) + expect(setEnabled).toHaveBeenCalledExactlyOnceWith(true) const { controller, hooks } = actionInjectedOf(c) expect(controller.store.getSnapshot().status).toBe('idle') expect(hooks.snapshot).toBe(controller.store) From caaaf89b1e39055d22b419dd645119aadb8dd4da Mon Sep 17 00:00:00 2001 From: zhc Date: Thu, 17 Sep 2026 20:34:33 +0800 Subject: [PATCH 5/7] fix(client): separate developer tool policy and harden static previews --- ...6-09-17-developer-tools-settings.i18n.yaml | 4 +- .../2026-09-17-developer-tools-settings.md | 8 +-- .../2026-09-17-developer-tools-settings.zh.md | 8 +-- THIRD_PARTY_NOTICES.md | 1 + apps/web/tests/document-preview.e2e.ts | 9 +++- apps/web/tests/scaffold.ts | 2 +- docs/subsystems/conversation.i18n.yaml | 4 +- docs/subsystems/conversation.md | 2 +- docs/subsystems/conversation.zh.md | 2 +- .../src/client/AgentPresetSeat.tsx | 10 ++-- .../ui-agent-preset/src/client/index.ts | 4 +- .../tests/apply.client.spec.ts | 2 +- .../tests/components.client.spec.tsx | 2 +- .../ui-chat/src/client/chat/ChatView.tsx | 9 ++-- .../ui-chat/src/client/contract/slots.ts | 2 +- .../tests/apply-inject.client.spec.tsx | 5 +- .../ui-chat/tests/chat-apply.client.spec.tsx | 5 +- .../ui-chat/tests/chat-view.client.spec.tsx | 4 +- .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 +- packages/client/ui-conversation/README.zh.md | 2 +- .../ui-conversation/src/client/apply.ts | 39 +++++++++++---- .../src/client/contract/conversation.ts | 6 +++ .../src/client/contract/slots.ts | 9 ++-- .../skeleton/DefaultConversationViews.tsx | 5 +- .../tests/apply-inject.client.spec.tsx | 44 ++++++++++++++++- .../tests/apply-wiring.client.spec.tsx | 5 +- .../tests/assembly-surfaces.client.spec.tsx | 14 ++++-- .../tests/skeleton.client.spec.tsx | 1 + .../src/client/Deliverables.tsx | 8 +-- .../ui-deliverables/src/client/index.ts | 4 +- .../tests/deliverables.client.spec.tsx | 9 ++-- .../ui-deliverables/tsconfig.client.json | 3 ++ packages/client/ui-deliverables/tsconfig.json | 3 -- .../tests/browser-plugin.client.spec.ts | 5 +- .../ui-layout/tests/apply.client.spec.ts | 5 +- .../tests/browser-plugin.client.spec.ts | 5 +- .../ui-settings-general/src/client/index.ts | 6 +-- .../tests/apply.client.spec.ts | 6 +-- .../tests/shell.client.spec.ts | 2 +- .../tests/stores.client.spec.ts | 2 + packages/client/ui-settings/README.i18n.yaml | 4 +- packages/client/ui-settings/README.md | 4 +- packages/client/ui-settings/README.zh.md | 4 +- .../ui-settings/src/client/developer-tools.ts | 25 +++++++--- .../client/ui-settings/src/client/index.ts | 4 ++ .../src/client/settings-contract.ts | 15 +++--- .../ui-settings/src/client/settings-scope.ts | 32 ++++++------ .../tests/developer-tools.client.spec.ts | 49 +++++++++++++++++-- .../tests/settings-scope.client.spec.ts | 12 ++--- .../README.i18n.yaml | 4 +- .../ui-sidebar-documentpreview/README.md | 2 +- .../ui-sidebar-documentpreview/README.zh.md | 2 +- .../ui-sidebar-documentpreview/package.json | 7 +-- .../src/client/html/HtmlBody.tsx | 10 ++-- .../src/client/html/basic-document.ts | 21 +++----- .../src/client/html/index.ts | 2 +- .../src/client/index.ts | 2 +- .../tests/apply.client.spec.ts | 4 +- .../tests/basic-html.client.spec.ts | 13 +++++ .../tests/document-seat.client.spec.tsx | 4 +- .../tests/html-apply.client.spec.ts | 5 +- .../tests/html-body.client.spec.tsx | 4 +- .../tests/browser-plugin.client.spec.ts | 5 +- .../tests/assembly-surfaces.client.spec.tsx | 5 +- .../tests/chat-ptc-subcalls.client.spec.tsx | 7 +-- .../tests/toolview-slot.client.spec.tsx | 8 +-- .../src/client/trajectory-snapshot-builder.ts | 1 + .../tests/client-bundle.client.spec.ts | 5 +- .../conversation-definitions.client.spec.ts | 4 ++ .../ui-trajectory/tests/views.client.spec.tsx | 12 +++-- .../tests/workflow-run.client.spec.tsx | 5 +- .../src/client/slot-catalog.ts | 5 +- .../client-runtime/README.i18n.yaml | 4 +- .../test-support/client-runtime/README.md | 2 +- .../test-support/client-runtime/README.zh.md | 2 +- .../test-support/client-runtime/src/index.ts | 2 +- .../client-runtime/src/settings-scope.ts | 25 ++++++++-- .../tests/runtime.client.spec.tsx | 17 ++++++- pnpm-lock.yaml | 3 ++ scripts/gen-cordis-catalog.ts | 1 + 81 files changed, 404 insertions(+), 210 deletions(-) diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml index 43b546d998..fe05798168 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md -2026-09-17-developer-tools-settings.md: 694e2a09fc20ad3185ba9c09058e8684a2247e46 -2026-09-17-developer-tools-settings.zh.md: e03aa258675be8f49dc13a9b43f2e3e00c8b85fa +2026-09-17-developer-tools-settings.md: 62ec235d8d21ad621956363898da26935e1af487 +2026-09-17-developer-tools-settings.zh.md: b320c973be0e8b4d4a061db00d871d7e95f5460e diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md index 694e2a09fc..62ec235d8d 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.md @@ -10,11 +10,11 @@ Diagnostic views, preset selection and changed-file summaries add complexity to ## Decision -The settings owner exposes one accepted `ui-developer-tools.enabled` preference, defaulting off. General Settings offers the same switch on Web and desktop. The existing settings transport owns validation, ordered writes, persistence and recovery; loopback Web and desktop follow Host acceptance. Remote Web owns one browser-local observable shared by all consumers until reload, with no Host writes. +The dedicated `ctx.developerTools` service binds the generic settings scope and exposes one accepted `ui-developer-tools.enabled` preference, defaulting off. General Settings offers the same switch on Web and desktop. The existing settings transport owns validation, ordered writes, persistence and recovery; loopback Web and desktop follow Host acceptance. Remote Web owns one browser-local observable shared by all consumers until reload, with no Host writes. -Off exposes only Chat, hides tool Inspect actions whose trajectory target is unavailable, removes the conversation View tab bar, hides the new-session preset chip, and omits the changed-files card and its summary read. Turning it off from another View activates Chat. The preset composition, saved default, Session events and explicit delivery cards remain unchanged. This preference is presentation policy, not Host authorization. +Off exposes only Chat, hides tool Inspect actions when no visible View declares tool-call inspection, removes the conversation View tab bar, hides the new-session preset chip, and omits the changed-files card and its summary read. Turning it off from another View activates Chat. The preset composition, saved default, Session events and explicit delivery cards remain unchanged. This preference is presentation policy, not Host authorization. -The builtin HTML renderer enforces its own preview policy. Off parses a complete inert document, preserves root styling, recursively sanitizes template contents, removes active documents, resource hints, SVG animation and navigation, and mounts an iframe with no sandbox permissions and a CSP denying scripts and external resources. It reads no related files. On retains the opaque scripted Blob renderer and its bounded related-file reads. Switching modes replaces the browsing context and disposes pending reads. The [document-preview decision](../architecture/2026-09-08-document-preview-operations.md) and [filesystem-read authority](../architecture/2026-09-09-workspace-file-read-authority.md) remain authoritative for advanced rendering and Host read access. +Plugin assembly translates the shared preference into component-specific capabilities (`showCodeDiff`, `showPresetPicker`, and `interactivePreview`). Conversation supplies the inspection callback using the visible target's `toolCallFocus`; Chat does not name the target. The builtin HTML renderer uses DOMPurify for complete-document sanitization and parser-mutation defenses. Off preserves root styling, removes active documents, resource hints, SVG animation and all `href` attributes, and mounts an iframe with no sandbox permissions and a CSP denying scripts and external resources. It reads no related files. On retains the opaque scripted Blob renderer and its bounded related-file reads. Switching modes replaces the browsing context and disposes pending reads. The [document-preview decision](../architecture/2026-09-08-document-preview-operations.md) and [filesystem-read authority](../architecture/2026-09-09-workspace-file-read-authority.md) remain authoritative for advanced rendering and Host read access. ## Alternatives considered @@ -26,4 +26,4 @@ The builtin HTML renderer enforces its own preview policy. Off parses a complete Basic HTML sacrifices JavaScript, external and related resources, and link navigation; inline styles and data images remain available. Advanced mode retains normal browser networking and does not gain parent-origin, popup, form or top-navigation privileges. The setting does not constrain third-party preview implementations or revoke Host filesystem authority. -Component and settings tests cover defaulting, schema rejection, accepted-state updates, chip disclosure, changed-file visibility and iframe disposal. The recorded-session [document preview](../../../../apps/web/tests/document-preview.e2e.ts) and [changed-files](../../../../apps/web/tests/changed-files-turn.e2e.ts) scenarios exercise the real settings control and the shared renderer. The browser scaffold explicitly seeds developer mode for diagnostic scenarios; settings chrome, document preview and changed-file scenarios leave the shipped default untouched. Native Electron execution remains unverified. +Component and settings tests cover defaulting, schema rejection, accepted-state updates, chip disclosure, changed-file visibility and iframe disposal. The recorded-session [document preview](../../../../apps/web/tests/document-preview.e2e.ts) and [changed-files](../../../../apps/web/tests/changed-files-turn.e2e.ts) scenarios exercise the real settings control and the shared renderer. The browser scaffold enables developer tools by default. Only settings chrome, document preview, changed-files and developer-tools scenarios explicitly retain the shipped default; together they cover hidden diagnostic controls, static previews, and switching back to Chat. Refused Host writes recover accepted state and show the localized retry message. Native Electron execution remains unverified. diff --git a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md index e03aa25867..b320c973be 100644 --- a/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md +++ b/.agents/notes/implemented/feature/2026-09-17-developer-tools-settings.zh.md @@ -10,11 +10,11 @@ Status: implemented ## Decision -设置所有者提供一个已接受的 `ui-developer-tools.enabled` 偏好,默认关闭。Web 和桌面端的通用设置提供同一个开关。现有设置传输负责验证、有序写入、持久化和恢复;回环 Web 和桌面端跟随 Host 接受的状态。远程 Web 持有一个所有消费者共享的浏览器本地可观察值,刷新后重置,不发送 Host 写入。 +独立的 `ctx.developerTools` 服务绑定通用设置 scope,提供一个已接受的 `ui-developer-tools.enabled` 偏好,默认关闭。Web 和桌面端的通用设置提供同一个开关。现有设置传输负责验证、有序写入、持久化和恢复;回环 Web 和桌面端跟随 Host 接受的状态。远程 Web 持有一个所有消费者共享的浏览器本地可观察值,刷新后重置,不发送 Host 写入。 -关闭时仅展示 Chat,隐藏轨迹目标不可用的工具 Inspect 操作,移除会话 View 标签栏,隐藏新会话预设入口,并省略改动文件卡片及其摘要读取。在其他 View 中关闭开关会激活 Chat。预设组合、保存的默认值、Session 事件和显式交付卡片保持不变。此偏好是展示策略,不是 Host 授权。 +关闭时仅展示 Chat,在没有可见 View 声明工具调用检查能力时隐藏 Inspect 操作,移除会话 View 标签栏,隐藏新会话预设入口,并省略改动文件卡片及其摘要读取。在其他 View 中关闭开关会激活 Chat。预设组合、保存的默认值、Session 事件和显式交付卡片保持不变。此偏好是展示策略,不是 Host 授权。 -内置 HTML 渲染器执行自己的预览策略。关闭时,内容被解析为完整的惰性文档,保留根节点样式,递归清理 template 内容,移除主动文档、资源提示、SVG 动画与导航,再放入不授予沙箱权限的 iframe,并通过 CSP 禁止脚本和外部资源。不读取关联文件。开启时保留不透明源的脚本 Blob 渲染器及其有界关联文件读取。切换模式会替换浏览上下文并清理待处理读取。[文档预览决策](../architecture/2026-09-08-document-preview-operations.zh.md)和[文件系统读取权限](../architecture/2026-09-09-workspace-file-read-authority.zh.md)继续定义高级渲染与 Host 读取访问。 +插件组装层将共享偏好转换为组件自身的能力(`showCodeDiff`、`showPresetPicker` 和 `interactivePreview`)。Conversation 根据可见目标的 `toolCallFocus` 提供检查回调;Chat 不再指定目标名称。内置 HTML 渲染器使用 DOMPurify 清理完整文档并防护解析变异。关闭时保留根节点样式,移除主动文档、资源提示、SVG 动画及所有 `href` 属性,再放入不授予沙箱权限的 iframe,并通过 CSP 禁止脚本和外部资源。不读取关联文件。开启时保留不透明源的脚本 Blob 渲染器及其有界关联文件读取。切换模式会替换浏览上下文并清理待处理读取。[文档预览决策](../architecture/2026-09-08-document-preview-operations.zh.md)和[文件系统读取权限](../architecture/2026-09-09-workspace-file-read-authority.zh.md)继续定义高级渲染与 Host 读取访问。 ## Alternatives considered @@ -26,4 +26,4 @@ Status: implemented 基础 HTML 放弃 JavaScript、外部与关联资源和链接导航;行内样式与 data 图片仍可用。高级模式保留正常浏览器网络能力,不增加父源、弹窗、表单或顶层导航权限。此设置不约束第三方预览实现,也不撤销 Host 文件系统读取权限。 -组件和设置测试覆盖默认值、schema 拒绝、已接受状态更新、入口折叠、改动文件展示和 iframe 清理。基于已记录 Session 的[文档预览](../../../../apps/web/tests/document-preview.e2e.ts)与[改动文件](../../../../apps/web/tests/changed-files-turn.e2e.ts)场景验证真实设置控件及共用渲染器。浏览器脚手架为诊断场景显式开启开发者模式;设置外壳、文档预览和改动文件场景保留产品默认值。原生 Electron 执行尚未验证。 +组件和设置测试覆盖默认值、schema 拒绝、已接受状态更新、入口折叠、改动文件展示和 iframe 清理。基于已记录 Session 的[文档预览](../../../../apps/web/tests/document-preview.e2e.ts)与[改动文件](../../../../apps/web/tests/changed-files-turn.e2e.ts)场景验证真实设置控件及共用渲染器。浏览器脚手架默认开启开发者工具,仅设置外壳、文档预览、改动文件和开发者工具场景显式保留产品默认值;这些场景共同覆盖诊断控件隐藏、静态预览和切回 Chat。Host 拒绝写入后会恢复已接受状态,并显示本地化重试提示。原生 Electron 执行尚未验证。 diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 7eb0c36e18..ec698dca33 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -76,6 +76,7 @@ External packages installed for runtime use or distributed inside the prebuilt b | [`commander`](https://github.com/tj/commander.js) | MIT | | [`compression`](https://github.com/expressjs/compression) | MIT | | [`diff`](https://github.com/kpdecker/jsdiff) | BSD-3-Clause | +| [`dompurify`](https://github.com/cure53/DOMPurify) | (MPL-2.0 OR Apache-2.0) | | [`electron-updater`](https://github.com/electron-userland/electron-builder) | MIT | | [`eventsource-parser`](https://github.com/rexxars/eventsource-parser) | MIT | | [`execa`](https://github.com/sindresorhus/execa) | MIT | diff --git a/apps/web/tests/document-preview.e2e.ts b/apps/web/tests/document-preview.e2e.ts index 57d513c72a..bee048c828 100644 --- a/apps/web/tests/document-preview.e2e.ts +++ b/apps/web/tests/document-preview.e2e.ts @@ -155,6 +155,8 @@ describe.skipIf(MODE === 'record')('web e2e: document preview through Files', ()
SVG link + x +