插件自 v0.19.0 起不再自绘顶部 chrome:`223b254` 把那三条读 strip 的规则
(`top: calc(var(--dsh-title-bar-strip, 40px) + 3px)` / 右面板
`padding-top: var(--dsh-title-bar-strip, 40px)` / 折叠态 `+14px`)连同自绘
chrome 一起删掉了。此后「位置兼容模式」四方案仍在写
`--dsh-title-bar-strip` + `body[data-dsh-title-bar-compat]`,但**没有任何
消费者**:`src/**/*.css` 零命中,宿主也不读这条契约(DSH 核心整树 grep
`windowControlsOverlay|dsh-desktop-titlebar-inset|titlebarInset|
title-bar-strip|title-bar-compat` 与 `desktopWindow` 全部零命中)。结果是
用户改设置只写变量、什么都不动,而设置项描述(「标题栏条带高度:侧边栏
按钮与内容下移的像素数」)与现实不符。整套删除,不留兼容层。
删除范围(先做了完整消费者普查,见新增的设计文档):
- 计算与写入:`src/client/titlebar-strip.ts`、`src/client/wco.ts`、
`src/client/shell-presets.ts` 三个文件整体删除;`Sidebar.tsx` 里的 strip
计算 + 写 `--dsh-title-bar-strip` / `body[data-dsh-title-bar-compat]` 的
effect 与 `titleBarCompat` 局部量一并清理。
- 壳信号:`desktop-env.ts` 的 `parseDesktopEnv` / `DesktopEnv` /
`probeDesktopWindow` 与 `context-types.ts` 的 `SidebarDesktopWindowService`
(含 Insets / DragRegion)删除。#864 新增的 `desktopWindow` 优先读取随之
消失。**`desktop-env.ts` 文件保留**:同文件的 `hostTransportBase()` 另有
3 个消费者(`host-route-url.ts` / `TextEditor.tsx` / `changes/DiffPane.tsx`),
是反向代理前缀与 `dsh-app://` 自定义 scheme 的解析基准,与本机制无关。
- 配置:`titleBarScheme` / `titleBarPresetId` / `titleBarCompat` /
`titleBarStripPx` 及 `TITLE_BAR_STRIP_{MIN,MAX,DEFAULT}` / `TITLE_BAR_SCHEMES`
/ `TitleBarScheme` / `clampTitleBarStrip`(`prefs-shared.ts` 的字段与默认值、
`config.ts` 的 schema 字段、`client/prefs.ts` 的读迁移逻辑)。
- 设置界面:常规行的方案下拉 + 「自定义方案」齿轮弹窗 + `titleBarSchemeValue`
/ `onSchemeSelect` / `detectedEnv` / `stripSettingsOpen` 全部删除;
**自定义 CSS 逃生口保留**,搬到独立的「自定义 CSS」分组,并去掉 scheme
门控(非空即生效)。`SideCardSection.module.css` 的死样式 `.rowGear` 同步删。
- 词典:21 份(`locales.ts` 的 zh + en 与 19 个 `locales-*.ts`)同步删除 12 个
只服务这些设置的 key(`settingsTitleBar*` / `settingsScheme*` /
`presetDshDesktopDesc`);`settingsCustomCssPlaceholder` 的示例改为
`[data-dsh-bottom-panel]` + `--dsw-font-mono`,不再引用已删变量。
- 文档:指南 §12.1 重写(删四方案 / strip 取值链 / 壳信号 / 迁移,保留用户
空间 CSS 与两条拖拽区退出)、§7 的 `toggles` 键清单、AGENTS §5 皮肤契约与
「契约反向引用」;新增 `docs/plans/2026-10-05-remove-titlebar-compat-strip.md`
记录普查结论与去留理由。`docs/plans/` 的历史文档未改。
迁移安全(旧偏好数据被安全忽略):四个已删键在 OPEN 的宿主 schema 里是未知键,
解析不报错、不写回(`plugin-shape.spec.ts`);客户端 `parsePrefs` 只按声明字段
构造结果,旧键不进入 UI(`prefs.spec.ts`);一次性 `settings.yaml` 回迁按
`Config.dict` 的声明字段过滤,已删键被丢弃而非转发(`smoke.spec.ts`)。
三条新断言都做过变异证伪:让 `parsePrefs` 透传原记录 / 让 schema 重新声明
`titleBarCompat` / 去掉回迁的声明字段过滤,对应用例分别红在
「不要带上已删键」「解析结果不得含该字段」「回迁不得保留该键」。
测试:删除 `tests/titlebar-strip.spec.ts` / `wco.spec.ts` /
`shell-presets.spec.ts` / `desktop-window-strip.spec.tsx` /
`desktop-env.spec.ts`(五个文件断言的行为已整体移除,不留断言已删行为的测试);
`prefs.spec.ts` / `plugin-shape.spec.ts` / `smoke.spec.ts` /
`side-card-section{,-rows}.spec.tsx` 的夹具与断言改写;`mount.e2e.ts` 删掉 WCO
与壳预设两个场景,URL 戳记场景保留挂载与拖拽区断言、只删 strip 断言,
自定义 CSS 场景改为只写 `customCss`。
门禁:`pnpm typecheck`(0 错误)/ `pnpm lint`(0 问题)/
`pnpm exec vitest run --maxWorkers=3` —— 179 文件 / 2075 passed + 13 skipped
(删除前基线 184 文件 / 2117 passed + 13 skipped;差额 = 5 个被删 spec 的
41 条 + `prefs.spec.ts` 净减 1 条)。词典 parity(`locales.spec.ts`)与皮肤
契约(`theme.spec.ts`)均绿。
184 lines
7.8 KiB
TypeScript
184 lines
7.8 KiB
TypeScript
/**
|
|
* Client-side read of the user-facing "Side card" preferences. The host owns
|
|
* the namespace through the settings seam (in-process); the DSH settings RPC
|
|
* domain only serves allowlisted namespaces to configuration clients, so the
|
|
* client reads and writes THIS namespace through the plugin's own fenced
|
|
* /sidebar routes instead (api.settingsGet/settingsUpdate). Any failure
|
|
* (route rejected, namespace absent, a field of the wrong type, a value out
|
|
* of the contract range) falls back to the schema defaults — the side card
|
|
* must keep working exactly as composed when the settings surface is missing.
|
|
*/
|
|
import type { api } from './api.ts'
|
|
import {
|
|
EXPLORER_EXCLUDE_DEFAULTS,
|
|
SIDEBAR_PREFS_DEFAULTS,
|
|
type SidebarPrefs,
|
|
} from '../prefs-shared.ts'
|
|
|
|
export {
|
|
EXPLORER_EXCLUDE_DEFAULTS,
|
|
SIDEBAR_PREFS_DEFAULTS,
|
|
}
|
|
export type { SidebarPrefs }
|
|
|
|
/** The settings wire face the preferences need (a subset of the plugin api). */
|
|
export type SidebarSettingsClient = Pick<typeof api, 'settingsGet' | 'settingsUpdate'>
|
|
|
|
/** Validate one raw resolved value into {@link SidebarPrefs}. Used for the
|
|
* settings.get payload AND the settings.update response (both carry the
|
|
* layered resolved value); any malformed field falls back to its default.
|
|
* @param value - the raw resolved section from the settings wire.
|
|
* @returns validated prefs (always well-formed).
|
|
*/
|
|
export function parsePrefs(value: unknown): SidebarPrefs {
|
|
if (value === null || typeof value !== 'object') return { ...SIDEBAR_PREFS_DEFAULTS }
|
|
const record = value as Record<string, unknown>
|
|
// The result is built from DECLARED fields only, so a key this release no
|
|
// longer has — the retired title-bar compatibility set (`titleBarScheme` /
|
|
// `titleBarPresetId` / `titleBarCompat` / `titleBarStripPx`), a legacy
|
|
// `workspaceFence` — is dropped here instead of reaching the UI. The host
|
|
// schema passes unknown keys through untouched (config.ts); this is the
|
|
// typed face that makes them inert.
|
|
return {
|
|
autoOpenSubagent: typeof record.autoOpenSubagent === 'boolean'
|
|
? record.autoOpenSubagent
|
|
: SIDEBAR_PREFS_DEFAULTS.autoOpenSubagent,
|
|
autoOpenJobs: typeof record.autoOpenJobs === 'boolean'
|
|
? record.autoOpenJobs
|
|
: SIDEBAR_PREFS_DEFAULTS.autoOpenJobs,
|
|
tasksViewMode: record.tasksViewMode === 'tree' || record.tasksViewMode === 'graph'
|
|
? record.tasksViewMode
|
|
: SIDEBAR_PREFS_DEFAULTS.tasksViewMode,
|
|
mobileNoAutoOpen: typeof record.mobileNoAutoOpen === 'boolean'
|
|
? record.mobileNoAutoOpen
|
|
: SIDEBAR_PREFS_DEFAULTS.mobileNoAutoOpen,
|
|
mobileDefaultTree: typeof record.mobileDefaultTree === 'boolean'
|
|
? record.mobileDefaultTree
|
|
: SIDEBAR_PREFS_DEFAULTS.mobileDefaultTree,
|
|
agentOpenTools: typeof record.agentOpenTools === 'boolean'
|
|
? record.agentOpenTools
|
|
: SIDEBAR_PREFS_DEFAULTS.agentOpenTools,
|
|
editorExplorer: typeof record.editorExplorer === 'boolean'
|
|
? record.editorExplorer
|
|
: SIDEBAR_PREFS_DEFAULTS.editorExplorer,
|
|
editorGitGutter: typeof record.editorGitGutter === 'boolean'
|
|
? record.editorGitGutter
|
|
: SIDEBAR_PREFS_DEFAULTS.editorGitGutter,
|
|
explorerExclude: stringArrayOf(record.explorerExclude),
|
|
customCss: typeof record.customCss === 'string'
|
|
? record.customCss
|
|
: SIDEBAR_PREFS_DEFAULTS.customCss,
|
|
htmlViewerNoSandbox: typeof record.htmlViewerNoSandbox === 'boolean'
|
|
? record.htmlViewerNoSandbox
|
|
: SIDEBAR_PREFS_DEFAULTS.htmlViewerNoSandbox,
|
|
htmlViewerDefaultUnsafe: typeof record.htmlViewerDefaultUnsafe === 'boolean'
|
|
? record.htmlViewerDefaultUnsafe
|
|
: SIDEBAR_PREFS_DEFAULTS.htmlViewerDefaultUnsafe,
|
|
tabsEnabled: booleanMapOf(record.tabsEnabled),
|
|
viewersEnabled: booleanMapOf(record.viewersEnabled),
|
|
pluginSettings: pluginSettingsMapOf(record.pluginSettings),
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validate the plugin-owned settings map (v0.12.0+): `{ descriptorId: { key:
|
|
* value } }`, nested open maps. Any non-object value (or a malformed whole)
|
|
* falls back to the empty map — the schema defaults already guard the wire
|
|
* shape, this is the client's second line.
|
|
*/
|
|
function pluginSettingsMapOf(value: unknown): Record<string, Record<string, unknown>> {
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return {}
|
|
const out: Record<string, Record<string, unknown>> = {}
|
|
for (const [id, blob] of Object.entries(value as Record<string, unknown>)) {
|
|
if (blob !== null && typeof blob === 'object' && !Array.isArray(blob)) {
|
|
out[id] = blob as Record<string, unknown>
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
/**
|
|
* Validate the exclude-pattern list: a JSON array whose string entries
|
|
* survive (trimmed; blanks dropped). Anything else falls back to the stock
|
|
* list — the schema defaults already guard the wire shape, this is the
|
|
* client's second line.
|
|
*/
|
|
function stringArrayOf(value: unknown): string[] {
|
|
if (!Array.isArray(value)) return [...EXPLORER_EXCLUDE_DEFAULTS]
|
|
const out: string[] = []
|
|
for (const item of value) {
|
|
if (typeof item !== 'string') continue
|
|
const trimmed = item.trim()
|
|
if (trimmed !== '') out.push(trimmed)
|
|
}
|
|
return out
|
|
}
|
|
|
|
/**
|
|
* Validate one enable-switch map (per-tab / per-viewer). Only boolean values
|
|
* survive; a non-object or a non-boolean entry falls back to the empty map /
|
|
* drops the entry — an absent key means the feature stays enabled.
|
|
*/
|
|
function booleanMapOf(value: unknown): Record<string, boolean> {
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) return {}
|
|
const out: Record<string, boolean> = {}
|
|
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
if (typeof item === 'boolean') out[key] = item
|
|
}
|
|
return out
|
|
}
|
|
|
|
/**
|
|
* Read the resolved side card preferences through the plugin's settings route.
|
|
* @param settings - the settings wire face (the plugin api by default).
|
|
* @returns validated prefs, or the schema defaults when the route rejects,
|
|
* the namespace is absent, or a stored value violates the contract.
|
|
*/
|
|
export async function loadPrefs(settings: SidebarSettingsClient): Promise<SidebarPrefs> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return parsePrefs(view.value)
|
|
} catch {
|
|
// Transport/fence rejection or a malformed response: keep the defaults.
|
|
return { ...SIDEBAR_PREFS_DEFAULTS }
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Read the external-disable flag from the same settings route: the
|
|
* dsh-web-ui family's aionui-panel provider choice. True only when the host
|
|
* resolved `aionui-panel.rightPanel` to 'aionui-panel' — while true the
|
|
* sidebar must not mount (the two right panels are mutually exclusive). Any
|
|
* failure (route rejected, aionui absent, malformed response) reads false,
|
|
* so a missing family never hides the sidebar.
|
|
* @param settings - the settings wire face (the plugin api by default).
|
|
* @returns the external-disable flag (false on any failure).
|
|
*/
|
|
export async function loadExternalDisable(settings: SidebarSettingsClient): Promise<boolean> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return view.externalDisable === true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
/** The boot decision both the prefs and the external-disable flag need:
|
|
* ONE settings fetch answers both (the boot path used to await
|
|
* {@link loadPrefs} and {@link loadExternalDisable} serially — two round
|
|
* trips of the same document before the first paint, and the second had no
|
|
* timeout, so a stalled wire could keep the sidebar unmounted forever). */
|
|
export interface BootDecision {
|
|
prefs: SidebarPrefs
|
|
suspended: boolean
|
|
}
|
|
|
|
export async function loadBootDecision(settings: SidebarSettingsClient): Promise<BootDecision> {
|
|
try {
|
|
const view = await settings.settingsGet()
|
|
return { prefs: parsePrefs(view.value), suspended: view.externalDisable === true }
|
|
} catch {
|
|
return { prefs: { ...SIDEBAR_PREFS_DEFAULTS }, suspended: false }
|
|
}
|
|
}
|