dsh-brain/docs/plans/DEPARTMENT_FIX.md

81 lines
4.8 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.

# D1+D2 验收 FAIL 项修复单(给 DeepSeek)
日期:2026-11-24
依据:GPT 独立验收报告(基线 accc1c3)。规划侧已逐项对照源码复核,两个 FAIL 均属实。
基线注意:当前 HEAD 已含 UI 规划文档 commit(4dbc090/50b90ea),工作树另有
src/skill-sync.ts 未提交改动(冲突确认逻辑重构,非部门范围)——**修复开工前先与
用户确认该改动归属:是 DeepSeek 自己的在途工作就一并收尾提交,否则 stash 隔离。
修复 commit 不得混入 skill-sync 改动。**
## FAIL-1(C8)· 项目部门未按调用工作区隔离【严重,先修】
现象:同一进程内,工作区 A、B 分别创建同名 project 部门,B 得到 created=false
和 A 的 ID——B 的部门建到了 A 的项目注册表里。
根因(已核实):
- DepartmentManager.root(scope) 读 this.memory.projectRoot(manager.ts:36 附近),
而 projectRoot 取 AsyncLocalStorage 的 workspaceContext,缺省回落 process.cwd()。
- LocalMemoryManager 已有现成绑定机制:withWorkspace(workspace, job)(manager.ts:94)。
- memory/tools.ts 的五个工具把 workspace 作为参数传给 remote(remote 内部绑定);
但 departments-tools.ts 只有 recall 传了 workspace 参数,create/list/remember/
checkpoint/resume 都没绑定,且 DepartmentManager 公开方法除 recall 外不收 workspace。
修法(库层零改动约束下,接线层绑定):
1. DepartmentToolDeps 增加 memory: () => LocalMemoryManager(kernel.departmentToolDeps()
补返回 this.localMemory)。
2. 六个工具的 execute 统一包一层:
const ws = deps.workspace(exec)
return deps.memory().withWorkspace(ws, async () => { …原逻辑… })
recall 保留现有 workspace 参数传递(双保险,库层 recall 自己也会用)。
3. HTTP 路由侧:departments-routes.ts 的每个分支同样用
deps.localMemory.withWorkspace(workspace, …) 包裹;workspace 来源:
- 工具面:exec 上下文(已有)。
- HTTP 面:query/body 的 workspace 参数(recall 已支持,扩展到 create/list/
remember/checkpoint/resume/update/disable);缺省时回落 process.cwd() 语义不变。
RouteDeps 已含 localMemory,无需新增依赖面。
4. 不改 src/local-memory/departments/ 任何字节(A2 红线)。
验证(新增断言进 verify-departments-wiring.mjs):
- 同进程双工作区:withWorkspace(A) create 'X' → withWorkspace(B) create 'X'
必须 created=true 且 ID 不同;B recall 不见 A 的私有记忆。
- 工具面模拟 exec={workspace:B} 调 department_create,注册表落 B 的
.dsh/brain/departments/registry.json(mkdtemp 双项目夹具)。
- 原 18 项 wiring + 21 项库层保持全绿。
commit:fix(departments): bind caller workspace around every department operation
## FAIL-2(C7)· 召回片段超 600 字符预算【轻,后修】
现象:工具 snippet 截 600 后追加 '…' 实长 601;HTTP /recall 直接返回完整
record.content(实测 715)。
裁定(规划侧统一口径,消除任务卡与验收单的矛盾):
- **agent 工具面**:snippet 总长 ≤600 **含省略号**——改 slice(0, limit-1) + '…'。
- **HTTP 管理路由**:/recall 是同源管理页消费,允许全文(任务卡 D1b 原口径),
但为防误用也加投影:默认返回 content 全文 + contentSnippet(≤600 含省略号)双字段;
验收断言改为"snippet 字段 ≤600"。若 GPT 复验坚持路由也限 600,则路由直接复用
同一 snippet 函数返回短片段——两种都合规,实施者选前者(管理页需要全文编辑)。
- 共用一个 snippet 实现:从 departments-tools.ts 导出或挪到共享 util,
路由 import 同一函数,杜绝两处漂移。
验证:wiring 脚本加断言——构造 700 字符记忆,工具返回 content.length ≤600;
路由返回 contentSnippet.length ≤600。
commit:fix(departments): count ellipsis inside the 600-char recall budget
## 执行顺序与门禁
1. 先处置 skill-sync.ts 在途改动(问用户),保证干净起点。
2. FAIL-1 → FAIL-2 各一 commit,每 commit 前跑:
typecheck + build + verify-departments(21) + verify-departments-wiring(18+新断言)。
3. 终验:verify-all 全绿(39+ 脚本口径不回退)。
4. 完成后 push,通知用户转 GPT 复验(复验范围:C7/C8 + 新断言 + A5 干净树;
其余 PASS 项不重跑,除非 diff 触及)。
## 给 GPT 复验的口径更新
- C7 通过标准修订:工具 content ≤600 含省略号;路由 contentSnippet ≤600(全文字段允许)。
- C8 通过标准:双工作区 create 各自 created=true、ID 不同、私有记忆互不可见;
工具与 HTTP 两面都要探。
- A5:交付提交必须干净树;skill-sync 改动若属另一任务,单独 commit 不混入。