dsh-brain/docs/plans/UI_PLAN.md

137 lines
9.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# settings-ui → UI 改造方案(总面板 + better-sidebar 项目记忆入口)
版本:v1(规划稿,本会话只做规划,不实施)
日期:2026-11-24
基线:accc1c3(D1+D2 部门接线已入库并推送)。
需求(用户原话):"把 setting ui 改成 UI,因为我需要有左侧栏入口打开的总面板,
有需要挂载在 better-sidebar 的项目记忆入口。"
## 0. 宿主接入面实测结论(2026-11-24,全部来自本机已装插件源码)
三个真实可用的注册面,各有现成范例:
| 面 | 机制 | 范例(本机已装) | 效果 |
| --- | --- | --- | --- |
| 左侧栏全局面板 | client 半区 ctx.slots.inject('sidebar.panellist', …) 注册行 + ctx.slots.inject('main', …) 注册页面 | @linxin666/dsh-client-ui-task-board v0.4.20(lib/client.js native-panel 段) | 与宿主"插件/日程"页同级的左栏入口,点开占中列主区;shell 拥有行盒/标签/高亮/折叠轨 |
| better-sidebar 页签 | client 半区 inject ['betterSidebar'],ctx.betterSidebar.registerTab(descriptor) | dsh-better-sidebar 0.32.1 README_ZH 最小示例 + lib/types/client/service.d.ts | 右侧栏/底部工作台新增页签类型,按会话 scope 渲染 |
| 设置卡(现状保留) | ctx.slots.inject('settings.section' / 'plugins.bundle.config') | dsh-brain client/index.js 现有 apply() | 设置页内嵌卡,不动 |
关键契约细节(照抄范例,不自造):
- panellist 行 options:{ name:'sidebar.panellist', id:<panelId>, order:<n>, label:()=>string },
组件只画 glyph(svg,带 data-dsh-panel-entry=<panelId> 语义锚点);
Plugins order=0、Schedule=10、task-board=20 → 本项目建议 order=30。
- main 页 options:{ name:'main', key:<panelId>, inject:()=>({…}) },
组件收 shell 注入的 face;layout 只在该面板选中时挂载,其余时间中列归会话。
- registerTab descriptor:{ id:'dsh-brain:memory', title, description, icon?, order?,
single:true, component:(props:TabComponentProps)=>ReactNode };
props 含 ctx/store/scope/sessionId/tab/visible——**visible=false 时暂停轮询**(契约明说)。
single:true = 单实例,重复打开聚焦已有页签。
- 两个 seat 都经 slots.inject 延迟触发,与 shell 加载顺序无关;shell 不支持时静默不挂。
- better-sidebar 未安装时 registerTab 面不存在 → 必须优雅降级(见 §3)。
## 1. 目标形态
左侧栏 [Brain] 行(order 30)
└─ 总面板(main slot,key='dsh-brain')
页签:概览 / 记忆 / 部门 / 技能 / MCP / 连接与上报
—— 现有 client/index.js 三页签 + settings-ui page.ts 八卡片的全部能力
收进一个 React 面板,数据仍走同源公开路由,零新后端。
better-sidebar 页签 "项目记忆"(id='dsh-brain:memory',single)
└─ 当前会话项目的记忆视图:空间状态 / 记忆列表 / 搜索 / 文档 / 部门召回
按 scope.sessionId → 会话 cwd → projectId 定位项目空间。
设置卡(settings.section)保留为精简入口:状态 + 跳转总面板按钮。
/dsh-brain 独立 HTML 页保留为兜底(无 shell seat 的环境仍可用)。
## 2. bundle 改名与边界
- src/entries/settings-ui.ts → src/entries/ui.ts;export name 'dsh-brain-settings-ui'
→ 'dsh-brain-ui';package.json exports './settings-ui' → './ui'(保留 './settings-ui'
别名导出指向同一文件,老 profile 行不断)。
- cordis.patch.yml insert 行 id 同步改 dsh-brain-ui;**兼容风险**:宿主 Settings→Plugins
的禁用行按旧 id 写死过(profile patch 里可能有 '- id: dsh-brain-settings-ui'),
改名后旧禁用行失效 → 迁移说明必须写清,或保留旧 id 只改显示名(见 §6 决策点)。
- kernel BrainBundle 类型 'settings-ui' → 'ui'(isActive/routeDeps 同步);
路由归属不变:page + core routes(status/capabilities/config/migrate/local-memory/departments)
仍由该 entry 注册,legacy /cloud-memory 别名自动跟随。
- 五子插件结构不变,只是第五个从"设置页"升格为"UI 面板";其余四 bundle 零改动。
## 3. 切片(每片独立 commit + verify)
### U1 · client 总面板骨架(左栏入口)
- client/index.js:新增 panelId='dsh-brain';apply() 里加两个 slots.inject
(panellist 行 + main 页),照 task-board native-panel 模式;glyph 自绘 svg。
- main 页组件 = 现有 SettingsCard 升格为 BrainPanel:页签壳 + 现有三页签内容复用,
新增"概览"页签(status/capabilities 聚合,数据已有)。
- 设置卡注册保留但瘦身:状态摘要 + "打开总面板"按钮(经 shell 面板切换 API;
若 seat 不可用则回退 window.open('/dsh-brain'))。
- 降级:slots 里没有 sidebar.panellist/main seat 时(web 精简 shell),
仅保留设置卡 + 独立页,console.info 一次,不报错。
- verify:verify-plugin-entry.mjs 更新入口名单;新增 verify-ui-panel.mjs
(静态断言 client bundle 含两 seat 注册、panelId、降级分支;形状检查为主,
DOM 行为留给 U4 冒烟)。
### U2 · 记忆/部门页签并入总面板
- "记忆"页签:消费 /dsh-brain/local-memory(status/spaces/documents/memories/forget),
列表 + 搜索 + 分页(limit/offset 路由已支持)。
- "部门"页签:消费 /dsh-brain/departments(list/create/update/disable/checkpoint/recall/resume),
表单走同源 POST(sameOrigin 闸门天然满足)。
- 两页签均为 React 手写(沿用 client/index.js 无打包器约定),不引新依赖。
- verify:verify-ui-panel.mjs 扩展路由消费断言;手工冒烟脚本起真实 server 核对 JSON 形状。
### U3 · better-sidebar "项目记忆"页签
- client apply():探测 ctx.betterSidebar(typeof registerTab === 'function');
存在则 ctx.effect(() => ctx.betterSidebar.registerTab({...})),不存在静默跳过。
- descriptor:id='dsh-brain:memory',title='项目记忆',description 写明
"当前会话项目的本地记忆:空间/条目/搜索/部门召回",single:true,order 建议 60。
- component(props):scope.sessionId → 会话 header.cwd(经 ctx sessions 面或
status 路由带回)→ 项目空间视图;visible=false 暂停一切轮询。
- 内容 = U2 记忆页签的项目子集(只读浏览 + 搜索 + forget),不做创建部门等重操作
(重操作引导去总面板)。
- 降级链:better-sidebar 未装 → 无页签(总面板不受影响);装了但 fiber 卸载 → disposer 自动清理。
- verify:verify-ui-panel.mjs 断言 registerTab 探测与 disposer;
真实宿主冒烟(U4)确认页签出现在 + 菜单。
### U4 · 改名落地 + 终验
- entries/settings-ui.ts → entries/ui.ts(含 exports 别名、patch 行、kernel 类型)。
- 全量门禁:typecheck + build + verify-all(39 脚本口径不回退)+ verify-plugin-entry。
- 宿主冒烟(升级 profile 依赖后):左栏出现 Brain 行 → 点开总面板六页签;
better-sidebar + 菜单出现"项目记忆";设置卡仍在;/dsh-brain 独立页仍可达。
- npm pack --dry-run:files 清单不变(client/lib 入库),exports 新增 './ui'。
## 4. 数据面(零新后端原则)
总面板与侧栏页签全部消费既有公开路由:
status / capabilities / config / local-memory/* / departments/* / skills / market / sync / clients / migrate。
唯一可能的新增:GET /dsh-brain/local-memory/memories 已支持 limit/offset,够用;
项目定位若需要"会话→cwd"映射,优先用 better-sidebar props.scope 自带信息,
其次 status 路由扩展一个 workspace 字段(小改,单独评审)。
**不新增写路由**;所有写操作沿用 sameOrigin 闸门与 revision 冲突语义。
## 5. 边界与约束
- client/index.js 保持手写无打包器(宿主 __ModuleLoader__ require shim 契约,
文件头注释已写明);不引 React 之外的运行时依赖。
- 面板/页签组件必须容错:路由失败显示可行动错误条,不白屏(沿用 CardBoundary 模式)。
- better-sidebar 是可选增强:未安装时一切功能经总面板/独立页可达,不硬依赖。
- 部门私有空间不上云边界不变;侧栏页签只读浏览为主。
- 皮肤语义锚点:glyph 带 data-dsh-panel-entry,面板根带 data-dsh-plugin="dsh-brain"
(对齐 task-board 的 L2 皮肤契约,避免主题适配找不到行)。
## 6. 待用户决策点
1. **bundle id 改名策略**:彻底改 'dsh-brain-ui'(干净,但老 profile 禁用行需迁移)
vs 保留 id 'dsh-brain-settings-ui' 只改显示名与职责(零迁移成本)。建议后者起步,
发布 0.11.0 时再彻底改名。
2. 总面板页签顺序与命名:概览/记忆/部门/技能/MCP/连接与上报(可调)。
3. better-sidebar 页签是否也要"部门"独立页签(本轮建议只做一个"项目记忆",部门在总面板)。
4. 排期位置:建议插在 P1 仓库整理之前、GPT 验收 D1+D2 之后(UI 改造会动 client 与
entries,先让部门验收落定,避免验收基线漂移)。
## 7. 验收(新增 verify-ui-panel.mjs + 宿主冒烟)
- 静态:client bundle 含 panellist/main/betterSidebar 三注册面与各自降级分支;
panelId/descriptor id 唯一;exports 别名齐全。
- 门禁:typecheck/build/verify-all 全绿,39 脚本口径不回退。
- 宿主冒烟清单(U4):左栏行、总面板六页签、侧栏页签、设置卡、独立页五处逐一截图核对。
- 发布件:npm pack --dry-run 比对,client/index.js 与 lib/entries/ui.js 在包内。