fix(settings): stop inventorying programmatic-only tab types (#1009)

Hidden tab types (the built-in diff page, dsh-remote's dsh-remote:file)
have no + menu row and no native guide entry, yet the side-card inventory
still gave them an enable switch. Turning one off changed nothing in the
sidebar and only made openTab silently refuse that type - which the
reporter saw as "remote:file cannot be turned off / git:diff does
nothing", and dsh-remote saw as "remote files stop opening".

- SideCardSection: the inventory skips hidden types (the count badge
  follows); tabOrder becomes the order-only tabInventory.
- service.isTabEnabled: a hidden type is always enabled, so a
  tabsEnabled[id] = false written by an older build cannot keep refusing
  its programmatic opens.
- docs/external-plugin-guide.md and CHANGELOG describe the contract; the
  two new specs fail on the previous code.
This commit is contained in:
Menghuan1918 committed 2026-10-29 23:48:23 +08:00
1 parent 58310536d6
commit 15b51ca55e
6 files changed
+79 -14

No files matched your search

+1
View File
@@ -8,6 +8,7 @@
- **子线程归属与生命周期**:保留线程、消息及原始文本块身份;隐藏、切换线程、替换行或卸载后撤销旧回调,交互不会转发到主会话。保留原链接改写缓存、媒体处理与流式状态。
- **冷恢复边界**:仅移除明确标为继承的历史前缀,普通恢复标记不再清掉子线程历史。
- **贡献**:感谢 [@sunxiuguo](https://github.com/sunxiuguo) 的配套实现([#1033](https://github.com/omdsh-dev/DSH-better-sidebar/pull/1033));保留原始贡献提交,并整合最新 dev 与 0.28.2 的冷会话读取修复。
- 🐞 **「侧边卡片」不再给程序化类型发假开关**([#1009](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1009)):`hidden: true` 的 tab 类型(内置的 diff 页、dsh-remote 的 `dsh-remote:file`)本就没有 `+` 菜单行和原生 guide 条目,设置页却照注册表给它发了一张卡片——点掉后侧边栏毫无变化,唯一实际效果是 `openTab` 静默拒绝它的打开(差异预览的「展开为独立页签」、远程文件打开随之失效),同一现象也被 dsh-remote 侧报告为「开关无效」。现在清单只列真正出现在侧边栏的类型,`isTabEnabled()` 对 hidden 类型恒为 true(旧版本写下的 `tabsEnabled[id] = false` 不再拦截它们的打开)。`tests/side-card-section.spec.tsx` + `tests/service.spec.ts` 各新增一例守护。
### v0.28.2
+12 -5
View File
@@ -210,7 +210,13 @@ interface TabDescriptor {
icon?: ReactNode | ((size: number) => ReactNode)
/** + 菜单排序(升序);默认 100。内置:editor=10, git=20, subagent=30, sidechat=35, terminal-bottom=40 */
order?: number
/** 从 + 菜单隐藏(editor/diff 用:由其他流程触发打开,不在菜单里) */
/**
* 从 + 菜单隐藏(diff 用:由其他流程触发打开,不在菜单里)。同时不占原生
* guide 条目、也不出现在「侧边卡片」设置清单里——它没有任何可见承载面,
* 开关无处可关(旧版本给它发过开关,点掉后唯一效果是 `openTab` 静默拒绝,
* 见 #1009)。因此 hidden 类型**恒为启用**:`isTabEnabled()` 忽略
* `tabsEnabled[id]`。
*/
hidden?: boolean
/**
* 只投放到插件自己的底部工作台,**永不注册原生右侧栏承载面**(#774)。
@@ -749,7 +755,8 @@ interface BetterSidebarService {
folderIcon(path: string, open: boolean, size: number): ReactNode
/** 按 id 查 tab 描述符 */
getTab(id: string): TabDescriptor | undefined
/** 某个 tab 类型是否在 Side card 设置中启用(v0.4.1+;缺省 = 启用) */
/** 某个 tab 类型是否在 Side card 设置中启用(v0.4.1+;缺省 = 启用;
* hidden: true 的类型恒为 true——设置清单不提供它的开关,见 §4) */
isTabEnabled(id: string): boolean
/** 某个 file viewer 是否在 Side card 设置中启用(v0.4.1+;缺省 = 启用) */
isViewerEnabled(id: string): boolean
@@ -1031,10 +1038,10 @@ registerSidechatSurfaceAdapter(adapter: SidechatSurfaceAdapter): () => void
## 8. 声明式设置(v0.4.1+)
每个注册的 tab / viewer **自动**出现在 DSH 设置页「侧边卡片」分区(`SideCardSection` 按注册表驱动渲染,无硬编码):
每个注册的 tab / viewer **自动**出现在 DSH 设置页「侧边卡片」分区(`SideCardSection` 按注册表驱动渲染,无硬编码),**`hidden: true` 的 tab 类型除外**:
- 展示:小卡片网格(图标 + 标题 + 类型 id),**高亮 = 启用**,勾选徽标钉在卡片最右端;viewer 卡片额外显示扩展名。
- 持久化:开关写入 `SidebarPrefs.tabsEnabled / viewersEnabled`(开放 map,**缺省 = 启用**,显式 `false` 才禁用)。
- 展示:小卡片网格(图标 + 标题 + 类型 id),**高亮 = 启用**,勾选徽标钉在卡片最右端;viewer 卡片额外显示扩展名。`hidden` 类型没有 `+` 菜单行、没有原生 guide 条目,也就没有可切换的承载面,因此不进清单,且 `isTabEnabled()` 对它恒为 true(#1009)。
- 持久化:开关写入 `SidebarPrefs.tabsEnabled / viewersEnabled`(开放 map,**缺省 = 启用**,显式 `false` 才禁用;`hidden` 类型的键被忽略)。
- 关闭语义:tab 从 `+` 菜单消失、`openTab` 拒绝新开(`console.warn`)、派生流程(子代理自动展开、agent 终端自动补 tab)停止,**已打开的 tab 保留**;viewer 被 `matchFileViewer` 跳过,文件落到下一个匹配。
- `settings.toggles`(可选):在卡片行下追加**嵌套设置行**(仅父级启用时显示),绑定 `SidebarPrefs` 字段;通过卡片底部「功能设置」条在原生弹窗中编辑。行控件形状见 §4.1 的 `SettingRow`:`type: 'switch' | 'text' | 'number'`(v0.11.0+;text/number 行 blur/Enter 提交,number 行按 min/max 钳制,unit 渲染单位后缀)与 `type: 'select'`(v0.13.0+;`options` 支持 value/title/desc/icon,`multi` 多选存数组并按 options 顺序提交;任一项带 icon 时渲染大图标选项卡)与 `type: 'patterns'`(可编辑字符串数组——chips + 删除钮 + 常驻添加输入框,add/remove 均原子提交整表,占位符走 `patternsPlaceholder`,值必须存 `string[]`;能力 gate `settingPatterns`)。内置示例:subagent tab 的 `autoOpenSubagent`、editor tab 的 `editorExplorer` 图标化下拉(工作区路径围栏与它的开关已移除,见 §8.1)与 `explorerExclude` 排除模式行。
- `settings.pluginToggles`(可选,v0.12.0+):**插件自有设置行**,行控件与 toggles 相同,但 key 是插件局部的——持久化在 prefs 文档的 `pluginSettings[<descriptor id>]`(开放 map,无需宿主 schema 字段)。tab 与 viewer 都可用(v0.12.0 起 viewer 卡片也有设置条)。
+18 -7
View File
@@ -11,7 +11,11 @@
* - 侧边栏内容: one SMALL CARD per REGISTERED tab type (built-ins and
* external plugins alike), laid out in a responsive grid that wraps
* several cards per row — icon chip + title + type id, clicked to toggle
* the switch persisted in `prefs.tabsEnabled[id]`.
* the switch persisted in `prefs.tabsEnabled[id]`. Programmatic-only
* types (`hidden: true`, e.g. the built-in diff page or dsh-remote's
* `dsh-remote:file`) are NOT listed: they have no + menu row and no
* native guide entry, so a switch could only break their opens without
* hiding anything (#1009).
* - 文件预览: one SMALL CARD per REGISTERED file viewer — icon chip + title
* + the extensions it covers, clicked to toggle `prefs.viewersEnabled[id]`.
*
@@ -97,10 +101,17 @@ function iconOf(icon: ReactNode | ((size: number) => ReactNode) | undefined, siz
return typeof icon === 'function' ? icon(size) : icon
}
/** Tab inventory order: hidden types (editor/diff) last, then + menu order. */
function tabOrder(a: TabDescriptor, b: TabDescriptor): number {
if (a.hidden !== b.hidden) return a.hidden === true ? 1 : -1
return (a.order ?? 100) - (b.order ?? 100)
/**
* The tab inventory: the types that actually reach the side card, in + menu
* order. `hidden` types are programmatic-only (no + menu row, no native
* guide entry), so they have no side-card presence to switch — listing them
* produced switches whose only observable effect was to refuse their own
* opens (#1009).
* @param tabs - the service's whole registry.
* @returns a sorted copy without the hidden types.
*/
function tabInventory(tabs: readonly TabDescriptor[]): TabDescriptor[] {
return tabs.filter(tab => tab.hidden !== true).sort((a, b) => (a.order ?? 100) - (b.order ?? 100))
}
/** Viewer inventory order: priority desc (the catch-all `code` comes last). */
@@ -658,10 +669,10 @@ export function SideCardSection({ store, service }: SideCardSectionProps) {
// The declarative inventory: the registered tab types and file viewers.
// Local state + service.subscribe (registry changes are rare — plugin
// load/unload — so a plain effect is enough; no external-store ceremony).
const [tabs, setTabs] = useState<TabDescriptor[]>(() => [...service.getTabs()].sort(tabOrder))
const [tabs, setTabs] = useState<TabDescriptor[]>(() => tabInventory(service.getTabs()))
const [viewers, setViewers] = useState<FileViewerDescriptor[]>(() => [...service.getFileViewers()].sort(viewerOrder))
useEffect(() => service.subscribe(() => {
setTabs([...service.getTabs()].sort(tabOrder))
setTabs(tabInventory(service.getTabs()))
setViewers([...service.getFileViewers()].sort(viewerOrder))
}), [service])
+13 -2
View File
@@ -676,6 +676,13 @@ export interface BetterSidebarService {
* `tabsEnabled[id]` entry means enabled — only an explicit `false`
* disables the type (hidden from the + menu, `openTab` refuses, and
* derived flows gate on it).
*
* A `hidden: true` type is ALWAYS enabled: it has no + menu row and no
* native guide entry, so the side-card inventory offers no switch for it —
* and none of the paths that open it (a diff's "expand to page", a remote
* plugin's file open) has a visible state the user could read. The entry is
* ignored rather than honoured so a value written by an older build cannot
* keep silently refusing those opens (#1009).
*/
isTabEnabled(id: string): boolean
/** Whether a file viewer is enabled (absent `viewersEnabled[id]` = enabled). */
@@ -1067,8 +1074,12 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
}
// The enable switches come from the user's side card prefs (the shared
// store the service is bound to): an absent key means enabled.
const isTabEnabled = (id: string): boolean => store.getPrefs().tabsEnabled[id] !== false
// store the service is bound to): an absent key means enabled. A hidden
// type is exempt — it has no side-card card (SideCardSection skips it), so
// its prefs entry can only be a leftover from an older build and must not
// keep refusing the programmatic opens it exists for (#1009).
const isTabEnabled = (id: string): boolean =>
tabs.get(id)?.hidden === true || store.getPrefs().tabsEnabled[id] !== false
const isViewerEnabled = (id: string): boolean => store.getPrefs().viewersEnabled[id] !== false
const matchFileViewer = (path: string, head?: Uint8Array): FileViewerDescriptor | undefined => {
+15
View File
@@ -124,6 +124,21 @@ describe('enable switches (declarative settings)', () => {
expect(tabs.filter(t => t.type === 'explorer')).toHaveLength(0)
})
it('a hidden type is always enabled: the settings inventory offers no switch for it', () => {
const { store, service } = setup()
service.registerTab({ id: 'helper', title: 'Helper', hidden: true, component: () => null })
store.setPrefs({ ...store.getPrefs(), tabsEnabled: { helper: false } })
// A hidden type never reaches the side card grid (there is no sidebar
// presence to switch), so a stale `false` — written by an older build
// that did inventory hidden types — must not keep refusing its opens.
expect(service.isTabEnabled('helper')).toBe(true)
// The gate really is open: the programmatic open lands.
store.setSession('s1')
service.openTab({ type: 'helper', title: 'Helper' })
const tabs = allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs)
expect(tabs.filter(tab => tab.type === 'helper')).toHaveLength(1)
})
it('matchFileViewer skips a disabled viewer (files fall through)', () => {
const { store, service } = setup()
service.registerFileViewer({ id: 'code', exts: [], priority: -100, fetchStrategy: 'fsRead', component: () => null })
+20
View File
@@ -175,6 +175,26 @@ describe('SideCardSection declarative inventory', () => {
expect(html.match(/checked=""/g)?.length ?? 0).toBe(2)
})
it('does not list a hidden tab type: it has no sidebar presence to switch', () => {
const { store, service } = mount()
// Programmatic-only types (the built-in diff page, dsh-remote's
// `dsh-remote:file`) take no + menu row and no native guide entry, so an
// enable switch could only break their opens without hiding anything
// (issue #1009). They keep working; the inventory has no card for them.
service.registerTab({
id: 'my-plugin:hidden',
title: () => 'Hidden helper',
hidden: true,
component: () => null,
})
const html = renderSection(store, service)
expect(html).not.toContain('>Hidden helper<')
expect(html).not.toContain('>my-plugin:hidden<')
// The two visible tabs + the image viewer keep their cards (3 pressed);
// the hidden type does not add a fourth.
expect(pressedCount(html, 'true')).toBe(3)
})
it('hides the gear of a disabled feature (its related settings are dormant)', () => {
const { store, service } = mount()
store.setPrefs({ ...store.getPrefs(), tabsEnabled: { subagent: false } })