feat: gate code tools by task mode

This commit is contained in:
John
2026-07-02 07:12:18 +08:00
parent c9b7252832
commit e17dcaf4a8
11 changed files with 338 additions and 19 deletions
@@ -458,6 +458,48 @@ docker exec memind-runtime-redis redis-cli DEL memind:runtime:worker:goosed-3:dr
- 新增 drain 运维脚本 `scripts/runtime-worker-drain.mjs`
- runtime 构建模板同步上述脚本,并将 RUNBOOK 中主路径更新为 `mm.tkmind.cn -> local nginx -> Portal :8081`
- 本地和远端分支提交 `4420cca chore: add runtime observability ops`
- 修正检查脚本为 `HEAD` 探测 SSE 入口,避免健康检查打开真实上游 SSE;提交 `c9b7252 fix: avoid opening sse in runtime check`
### 2026-07-02 P4.5 Tool Gateway 过渡层第一阶段
目标:
- 不拆 goosed 内部 Aider/OpenHands,不引入队列系统,先把普通聊天和代码工具任务隔离。
- 普通聊天默认不注入 Aider/OpenHands,即使用户有显式白名单。
- 只有显式 `toolMode='code'` 的代码任务 policy 才注入 Aider/OpenHands。
已完成:
- `buildAgentExtensionPolicy()` 新增 `toolMode`,默认 `chat`
- `toolMode='chat'` 时不注入 `aider` / `openhands`
- `toolMode='code'` 时才注入白名单用户的 `aider` / `openhands`
- Aider/OpenHands extension 增加:
- `timeout_ms`
- `metadata.runtime_scope='code_tool_task'`
- `userAuth.getAgentSessionPolicy(userId)` 默认返回 chat policy。
- 新增 `userAuth.getCodeAgentSessionPolicy(userId)` 作为后续代码任务入口。
- `/api/runtime/status` 增加 `toolRuntime` 摘要:
- `defaultMode`
- `codeToolMode`
- `chatInjectsCodeTools`
- `aiderTimeoutMs`
- `openhandsTimeoutMs`
- 新增生产只读检查脚本 `scripts/check-tool-runtime.mjs`
生产验证:
- `scripts/check-tool-runtime.mjs` 返回 `ok=true`
- `role=user``aider` / `openhands` 均为 `false`
- 显式白名单用户数为 `2`
- 白名单用户 chat mode 不含 Aider/OpenHandscode mode 具备 Aider/OpenHands。
- `scripts/check-stream-runtime.mjs` 返回 `ok=true`,四个 worker healthy。
- `scripts/runtime-worker-drain.mjs status` 显示四个 worker `activeStreams=0`
生产部署:
- 允许重启生产 Portal,已使用 `launchctl kickstart -k gui/$(id -u)/cn.tkmind.memind-portal` 生效。
- 本阶段不写数据库、不删除数据、不修改 `/Users/john/Project/Memind/MindSpace`
- 生产代码备份: `/Users/john/Project/memind_backups/20260702-071020-pre-p45-tool-guard`
## 回滚策略