dsh-brain/docs/plans/UI_FIX.md

111 lines
7.1 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.

# UI 批次验收 FAIL 修复单(给 GPT 执行)
日期:2026-11-25
基线:c8101a3(U0–U5 七个交付 commit 齐全,工作树干净)。
依据:GPT 独立复核报告(三个 P1 + diff --check 六处)。规划侧已逐项对照源码核实,全部属实。
角色变更:本轮由 **GPT 实施修复**(此前 GPT 只验收;用户明确指派)。修完自验 + 交回规划侧复核。
环境:npm/node 不在 PATH,用宿主 bundled node + pnpm(路径见 UI_HANDOFF.md §开工前核对)。
## 根因分析(已核实,照此修,不要另起方案)
### P1-A 项目记忆跨工作区混列
两处断点,都要修:
1. **服务端**:src/routes.ts serveLocalMemory 的五个 GET 分支(status/spaces/documents/memories)
与 forget POST 都**不读 workspace 参数**,直接调 manager.xxx()——manager 这些方法
全都已支持可选 workspace 尾参(storageStatus(workspace?)/projects(workspace?)/
documents(workspace?)/list(options,workspace?,projectId?)/forget(id,rev?,workspace?)),
路由层没传而已。
2. **客户端**:src-client/sidebar/ProjectMemoryView.tsx 的 status/memories 请求不带
workspace(departments/list 带了);src-client/panel/MemoryTab.tsx 定义了
workspaceSuffix 助手但**三个请求都没用它**,且组件 props 没有 workspace 来源。
修法:
- routes.ts:每个分支加
`const workspace = url.searchParams.get('workspace')?.trim() || undefined`
并传入 manager 对应方法;forget 从 body.workspace 取(string trim)。
响应形状不变(新增可选入参,向后兼容)。
- ProjectMemoryView.tsx:status/memories/documents 请求统一加
`workspace === undefined ? '' : '?workspace=' + encodeURIComponent(workspace)`
(memories 已有 query 用 &)。workspace 来自 props.scope?.cwd(已有变量)。
- MemoryTab.tsx:props 加 workspace?: string;BrainPanel 渲染 MemoryTab 时传入
面板持有的当前会话 cwd(与 DepartmentTab 同源;若面板尚无 workspace 状态,
加一个经 ctx sessions 面探测的 hook,参考 UI_SPEC U2 的 workspace 取值段)。
三个请求用上 workspaceSuffix。
- **注意**:local-memory 路由不在部门保护清单内(保护的是 departments-routes.ts),可以改。
### P1-B 发布包带构建机绝对路径 + 重建不一致
根因:tsdown.config.ts brainCssPlugin 的虚拟模块 id 用**绝对路径**
(CSS_VIRTUAL_PREFIX + absolute + '.mjs'),rolldown 把虚拟 id 写成产物注释:
client/index.js L4193/L5092 出现
`// \0dsh-brain-css:C:\Users\qyh15\dsh-brain\src-client\...module.css.mjs`。
pack-guard 内容黑名单 /C:[\\/]Users[\\/]/ 命中 → exit 1;换机重建注释路径不同 → 字节不一致。
修法(tsdown.config.ts):
1. resolveId 返回的虚拟 id 改用**仓库相对路径**:
`const rel = relative(process.cwd(), absolute).replaceAll('\\\\','/')`
return CSS_VIRTUAL_PREFIX + rel + CSS_VIRTUAL_SUFFIX
2. load 里 fileId 还原绝对路径供 readFile/addWatchFile:
`const fileId = resolvePath(process.cwd(), virtualId.slice(prefix.length, -suffix.length))`
3. filename(classMap 哈希与 tagId)已经是 relative——保持不变,确保哈希稳定。
4. 重建后 client/index.js 不得再含 C:\\Users 或 qyh15;
隔离副本重建产物与提交产物逐字节一致(pack-guard 的 rebuild-parity 口径)。
5. 顺手核 client/index.js 是否还有其他绝对路径注释(grep 'C:' 全文件)。
### P1-C 诊断搜索日志落错工作区 + 121 字符
两个独立小 bug:
1. **search 日志 workspace 丢失**:manager.ts searchHits L233 把形参 workspace 直接传给
logger;当调用方经 withWorkspace(B) 包裹而**不显式传 workspace 形参**时(remote.run
之外的路径、或测试直调),形参为 undefined → BrainLogger.directoryFor('project', undefined)
→ projectRootOf(undefined) 回落默认工作区 A。remember 之所以正确,是因为它用
`this.workspacePath()`(读 AsyncLocalStorage 上下文)而非形参。
修法:searchHits 日志行改用 `const ws = this.workspacePath(workspace)`
(workspacePath 已接受可选 override,看 manager 现有签名;若只读上下文则
`workspace ?? this.workspacePath()`),与 remember 同口径。
同查 forget/projects/documents/storageStatus 各日志行是否同样依赖形参——统一改上下文优先。
2. **121 字符**:diagnostics.ts sanitizeValue 截断 `value.slice(0,120)+'…'` = 121。
与部门 C7 同款错误。修法:`value.slice(0, MAX_FIELD_CHARS - 1) + '…'`;
err 字段同理 `slice(0, MAX_ERR_CHARS - 1)`。规格口径"≤120 含省略号"。
### P2 diff --check 六处 EOF 空行
src-client/api.ts:95 / format.ts:98 / sections/ImportSection.tsx:301 /
sections/McpCustomSection.tsx:99 / sections/SyncResolveSection.tsx:118 / styles.ts:368
——各删文件末尾多余空行(保留单个终止换行)。
## 测试补强(修代码同时补断言,防回归)
1. verify-diagnostics.mjs:
- 双工作区 search:withWorkspace(B) 内 memory.search(不显式传 workspace)→
日志落 B 的 logs/,A 无该事件(现有测试 L44 只搜默认区,漏了这个路径)。
- 截断边界:构造 130 字符 detail 字段 → 落盘值 length ≤120(含省略号)。
2. verify-client-build.mjs(或新增 verify-ui-workspace.mjs):
- 静态断言 ProjectMemoryView/MemoryTab 的 memories/status/documents 请求含 workspace 拼接。
- HTTP 探针:双工作区 A/B 各 remember 一条 → GET memories?workspace=B 只含 B 记录
(服务端隔离);GET 不带 workspace 行为与旧版一致(回落 process.cwd())。
3. pack-guard 重跑 exit 0;隔离重建 parity changed=[] extra=[]。
4. git diff --check exit 0。
## 执行与验收
顺序:P1-C(最小)→ P1-A → P1-B → P2 → 测试补强,可合 2–3 个 commit:
- fix(diagnostics): route search logs by workspace context and count ellipsis in budget
- fix(ui): pass workspace through local-memory routes and both memory views
- build(client): relative css virtual ids — no machine paths in bundle
- style: trim EOF blank lines flagged by git diff --check
(测试补强随对应 fix commit 入库。)
终验(全绿才报完成):
typecheck + build(bundled node + pnpm)
node scripts/verify-all.mjs # 41 脚本口径不回退
node verify-client-build.mjs # 40 项
node verify-diagnostics.mjs # 15 项 + 新断言
node verify-departments-wiring.mjs # 25 项(保护期回归)
node scripts/pack-guard.mjs # exit 0
git diff --check # exit 0
隔离副本重建 → client/index.js 与提交逐字节一致
约束:
- 部门保护四文件仍禁改(departments-tools/departments-routes/skill-sync/库层 departments/)。
manager.ts 的日志行修改允许(不在保护清单);不改任何存储语义。
- 不 push 不打 tag 不升级宿主;修完回报 commit hash + 验证摘要,规划侧复核后由用户定推送。
- 与根因分析不符的现状:停下报告,不自行改方案。