167 lines
11 KiB
Markdown
167 lines
11 KiB
Markdown
# UI 改造 U0–U4 可执行任务卡(给 DeepSeek)
|
||
|
||
版本:v1(2026-11-24 23:35)
|
||
基线:89e67d0(部门 FAIL 修复已入库推送,待 GPT 复验——**UI 开工不等复验,但不得触碰
|
||
src/memory/departments-tools.ts、src/settings-ui/departments-routes.ts、src/skill-sync.ts**,
|
||
避免与复验/修复线冲突)。
|
||
决策已定(用户拍板):**选项 B 借壳不借芯** + **bundle id 彻底改名 dsh-brain-ui**。
|
||
上游方案:UI_PLAN.md(§0.5 三选项评估、§2 改名边界、§3 切片)。
|
||
**详细实施规格:UI_SPEC.md**(文件级改动清单、可抄源码位置、代码骨架、API 契约、逐卡验收命令)——执行以 UI_SPEC.md 为准,本卡为总览。
|
||
|
||
## 总览
|
||
|
||
| 卡 | 内容 | 依赖 | 预估 |
|
||
| --- | --- | --- | --- |
|
||
| U0 | client 构建链落地(tsdown,devDep 已有)+ 现有 client 迁 TS 源 | 无 | 0.5–1 天 |
|
||
| U1 | 左栏总面板骨架(panellist+main 双 seat,抄 Mnemon 接入层) | U0 | 1 天 |
|
||
| U2 | 记忆/部门页签并入总面板(消费既有 HTTP 路由) | U1 | 1 天 |
|
||
| U3 | better-sidebar "项目记忆"页签(registerTab + 降级) | U1 | 0.5 天 |
|
||
| U4 | bundle 彻底改名 settings-ui → ui(含迁移)+ 终验 | U1–U3 | 0.5 天 |
|
||
| U5 | 诊断日志 .dsh/brain/logs(JSONL/脱敏/滚动),详见 LOGGING_SPEC.md | 可与 U2/U3 并行 | 0.5–1 天 |
|
||
|
||
每卡独立 commit;U2/U3/U5 可并行。总量约 4–5 天。
|
||
升级批次(用户拍板 2026-11-24):**先不升级宿主**,U0–U5 全部完成 + GPT 部门复验通过后一次升级。
|
||
|
||
---
|
||
|
||
## U0 · client 构建链(先决)
|
||
|
||
现状:client/index.js 是 3735 行手写 IIFE(__ModuleLoader__ 契约);
|
||
devDependencies **已含 tsdown ^0.22.2**(无需新增依赖!);vendor/dsh-mnemon/tsdown.config.ts
|
||
有现成的 client 构建配置可抄(banner/footer/intro 包裹 __ModuleLoader__、css modules 内联插件、
|
||
react externals)。
|
||
|
||
1. 新建 src-client/(或 client-src/)目录放 TS 源;把现有 client/index.js 的逻辑
|
||
**原样迁为 TS**(第一步不求重构,求字节级行为等价):
|
||
- 入口 src-client/index.ts,导出 { apply, inject, name:'dsh-brain' }。
|
||
- 现有 SettingsCard 三页签、API 常量、request 助手、CardBoundary 全部搬入。
|
||
2. 新建 tsdown.config.ts(根目录),client 段照抄 vendor 配置:
|
||
- format:'cjs'、platform:'browser'、target:'es2022'、deps.neverBundle:[/^react(?:\/.*)?$/]
|
||
- outputOptions.banner/intro/footer 生成 window.__ModuleLoader__.load({id:'dsh-brain',factory:(require)=>{…}})
|
||
- 产物固定写 **client/index.js**(outDir:'client',entry:{index:'src-client/index.ts'},
|
||
outExtensions 强制 .js;clean:false 防误删)。
|
||
- css modules 内联插件从 vendor 抄(lightningcss transform → 注入 style),
|
||
U1 起样式用 .module.css。
|
||
3. package.json scripts 加 "build:client": "tsdown";"build" 改为
|
||
"tsc -p tsconfig.build.json && tsdown"(host lib 与 client 一起出)。
|
||
prepack 同步。tsconfig.json include 排除 src-client(走 tsdown 自己的转译,
|
||
或单列 tsconfig.client.json——二选一,保证 npm run typecheck 仍覆盖 host src)。
|
||
4. **等价门禁**:构建后 client/index.js 与迁移前手写版做行为对比——
|
||
新增 verify-client-build.mjs:断言产物含 __ModuleLoader__.load、id:'dsh-brain'、
|
||
settings.section/plugins.bundle.config 注册、三页签标签字符串;
|
||
再起临时 http server 用 jsdom-free 方式静态 require 产物(react shim)验证 apply 不抛。
|
||
旧手写版先备份到 artifacts/analysis/client-legacy.js(gitignore 内)供比对。
|
||
5. .gitignore 确认 client/index.js **仍入库**(发布件),src-client/ 入库。
|
||
|
||
commit:build(client): migrate hand-written bundle to tsdown with byte-equivalent output
|
||
验证:npm run typecheck && npm run build && node verify-client-build.mjs && verify-all 不回退。
|
||
|
||
## U1 · 左栏总面板骨架
|
||
|
||
抄 Mnemon 接入层(vendor/dsh-mnemon/src/client/):
|
||
- native-sidebar.tsx:mountMnemonSidebarNavigation 的 panellist+main 双 slots.inject、
|
||
usePanelInfo 激活判定、window-drag band、glyph 语义锚点。
|
||
- shared/dom-seat.ts 的 HeldSeat、shared/store.ts 的 ExternalStore(小文件,直接搬改前缀)。
|
||
- workspace-mount.tsx 的 coordinateSidebarPanels 协调逻辑按需简化。
|
||
|
||
落点(src-client/):
|
||
1. panel.ts:PANEL_ID='dsh-brain';registerBrainPanel(ctx):
|
||
- slots.inject('sidebar.panellist', () => slots.register({name:'sidebar.panellist',
|
||
id:PANEL_ID, order:30, label:()=>'Brain'}, BrainPanelIcon))
|
||
- slots.inject('main', () => slots.register({name:'main', key:PANEL_ID,
|
||
inject:()=>({…})}, BrainPanel))
|
||
- glyph svg 带 data-dsh-panel-entry="dsh-brain";面板根带 data-dsh-plugin="dsh-brain"。
|
||
- seat 不存在时静默(slots.inject 回调不触发即天然降级),console.info 一次。
|
||
2. BrainPanel 组件:页签壳(概览/记忆/部门/技能/MCP/连接与上报),
|
||
本轮先实现"概览"(GET status+capabilities 聚合卡片)与"连接与上报"
|
||
(现有 SettingsCard connection 页签内容搬入);其余页签占位"即将上线"。
|
||
轮询仅面板激活时跑(usePanelInfo),15s 间隔沿用现状。
|
||
3. 设置卡瘦身:settings.section 注册保留,内容改为状态摘要 + "打开总面板"按钮
|
||
(经 ctx.layout.selectPanel(PANEL_ID)——该服务面参考 task-board/mnemon 用法,
|
||
typeof 探测,不可用时回退 window.open('/dsh-brain'))。
|
||
4. 样式:BrainPanel.module.css 布局抄 MnemonWorkspace.module.css 的骨架
|
||
(nativeWorkspace/windowDragBand/entry 系列),配色用宿主中性 token,不硬编码纯白纯黑
|
||
(verify-theme 口径)。
|
||
|
||
commit:feat(ui): left-rail Brain panel with overview and connection tabs
|
||
验证:verify-client-build.mjs 扩展断言(panellist/main 注册、PANEL_ID、降级分支);
|
||
typecheck+build+verify-all 全绿。宿主冒烟留 U4。
|
||
|
||
## U2 · 记忆/部门页签
|
||
|
||
数据面零新后端,全部既有路由(UI_PLAN §4):
|
||
1. 记忆页签:GET /dsh-brain/local-memory/status|spaces|documents|memories?limit&offset;
|
||
列表+搜索框(前端过滤当前页即可,不做服务端搜索新路由)+分页;
|
||
forget 按钮走 POST /dsh-brain/local-memory/forget(同源天然满足)。
|
||
2. 部门页签:GET /dsh-brain/departments/list;create/update/disable/checkpoint 表单
|
||
POST 对应子路由;recall 查询框 GET /departments/recall?id&query&k&workspace;
|
||
展示 contentSnippet(≤600)而非全文;revision 冲突 409 显示"数据已变化,请刷新"。
|
||
3. 错误条组件复用 CardBoundary 模式:路由失败显示可行动文案,不白屏。
|
||
4. workspace 参数:面板处于会话上下文时经 ctx sessions 面取当前会话 cwd 传入;
|
||
取不到则省略(服务端回落 process.cwd() 语义)。
|
||
|
||
commit:feat(ui): memory and department tabs in the Brain panel
|
||
验证:verify-client-build 断言两页签路由消费;手工冒烟脚本起真实 server 核对 JSON 形状;
|
||
verify-all 不回退。**不得改 departments-routes.ts/departments-tools.ts**(复验保护期)。
|
||
|
||
## U3 · better-sidebar 项目记忆页签
|
||
|
||
抄 vendor better-sidebar.tsx 的 mountBetterSidebarTab 模式(reconcile + internal/service 监听):
|
||
1. src-client/better-sidebar.ts:detect ctx.get('betterSidebar'),存在则
|
||
ctx.effect(() => service.registerTab(descriptor));监听 'internal/service' 热插拔;
|
||
不存在静默跳过(总面板不受影响)。
|
||
2. descriptor:id:'dsh-brain:memory',title:'项目记忆',description:'当前会话项目的本地记忆:空间/条目/搜索/部门召回',
|
||
single:true,order:60,icon 自绘脑形 svg(可参考 MnemonLogo/memory-icon 简化)。
|
||
3. component(props:TabComponentProps):scope.sessionId/cwd → 项目空间只读视图
|
||
(status+memories 列表+搜索+recall);**visible=false 暂停一切轮询**(契约);
|
||
重操作(建部门/forget)引导"去总面板"按钮(selectPanel)。
|
||
4. 降级链测试:无 betterSidebar 服务时 apply 不抛、无注册。
|
||
|
||
commit:feat(ui): project-memory tab for better-sidebar with graceful fallback
|
||
验证:verify-client-build 断言 registerTab 探测/disposer/visible 暂停逻辑;verify-all 不回退。
|
||
|
||
## U4 · 彻底改名 settings-ui → ui + 迁移 + 终验
|
||
|
||
改名清单(一处不漏):
|
||
1. src/entries/settings-ui.ts → src/entries/ui.ts;export name='dsh-brain-ui';
|
||
kernel.activate('ui');effect 标签前缀改 'dsh-brain-ui:'。
|
||
2. src/kernel.ts:BrainBundle 类型 'settings-ui'→'ui';注释同步。
|
||
3. package.json exports:'./ui':'./lib/entries/ui.js';**保留 './settings-ui' 别名**
|
||
指向同一文件(老 profile 行不断)。
|
||
4. cordis.patch.yml:insert 行 id:'dsh-brain-ui',name:'dsh-brain/ui'。
|
||
5. src/index.ts compat root:import * as ui from './entries/ui.ts'。
|
||
6. src/settings-ui/ 目录(page.ts/routes.ts/departments-routes.ts)→ src/ui/?
|
||
**注意:departments-routes.ts 在复验保护期,本卡只改 import 路径不改其内容**;
|
||
若 GPT 复验尚未结束,目录搬迁推迟到复验通过后(改名先只动 entry/kernel/exports/patch 四处,
|
||
目录名 settings-ui 暂留,单独后续 commit 搬)。
|
||
7. **旧 id 迁移**:宿主 profile patch 里可能存在 '- id: dsh-brain-settings-ui' 禁用/配置行
|
||
(本机实测 desktop/web 均无,但其他机器可能有)。在 ui entry apply 开头做一次迁移探测:
|
||
读 ctx 配置面若发现旧 id 行,logger.warn 提示用户在新行重设;
|
||
不自动改写宿主文件(越权)。README 升级说明写明此点。
|
||
8. verify-plugin-entry.mjs:import 路径改 lib/entries/ui.js,断言名改 'ui entry …';
|
||
兼容断言:require('./lib/entries/settings-ui.js') 别名仍可用(exports 别名生效)。
|
||
9. README 五行表、docs/management-surface.md 的 id 提及同步。
|
||
|
||
终验(全绿才报完成):
|
||
npm run typecheck && npm run build
|
||
node scripts/verify-all.mjs # 39+ 脚本口径不回退
|
||
node verify-plugin-entry.mjs
|
||
node verify-client-build.mjs
|
||
npm pack --dry-run # files 含 client/index.js + lib/entries/ui.js
|
||
宿主冒烟(升级 profile 依赖后,另行授权):
|
||
左栏 Brain 行 → 总面板六页签;better-sidebar + 菜单"项目记忆";
|
||
设置卡仍在;/dsh-brain 独立页可达;旧 /cloud-memory 别名可达。
|
||
|
||
commit:refactor(ui)!: rename settings-ui bundle to dsh-brain-ui with export alias
|
||
(breaking 标记仅指内部 id;exports 别名保证老 profile 不断。)
|
||
|
||
## 硬约束(全卡通用)
|
||
|
||
- 运行时零新依赖(tsdown 已在 devDeps;react 走宿主 shim externals)。
|
||
- 复验保护期不碰:departments-tools.ts / departments-routes.ts / skill-sync.ts /
|
||
src/local-memory/departments/。
|
||
- client 产物必须仍是单文件 __ModuleLoader__ IIFE,id:'dsh-brain' 不变(client bundle id
|
||
与子插件 row id 是两回事,后者才改 dsh-brain-ui)。
|
||
- 每卡 commit 前跑该卡验证;lib/ 与 client/index.js 产物随卡入库。
|
||
- 遇到与本卡不符的代码现状:停下报告差异,等规划侧修订。
|