advance 1-8 post-mvp execution batches
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# Reasonix Worker A:GFM AST 降级策略与 process 收口
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 目标
|
||||
|
||||
收口 `design/03-rust-web/process/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md` 的真实尾项:
|
||||
|
||||
1. 表格/不支持结构降级策略是否已有测试证据。
|
||||
2. `web_shell.rs` 中 `legacyStylesToTiptapMarks` 等 legacy marks 适配分支是否仍被当前 bootstrap 使用。
|
||||
3. 如果剩余项已可解释且测试通过,把 `3-13` 移动到 `design/03-rust-web/done/`;否则只更新未完成项和证据,不要强行归档。
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/03-rust-web/process/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `design/03-rust-web/done/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`(仅当归档)
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
- `rust/crates/mnote-web/src/routes/local_markdown_parser.rs`
|
||||
- `rust/crates/mnote-web/src/routes/web_shell.rs`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- AI / Hermes 工具文件
|
||||
- tree realtime / websocket 文件
|
||||
- 任何 `design/01-tree-first-graph-kernel/process/1-13-*` 之外的 batch 文件,除非只是记录本任务结果
|
||||
|
||||
## 执行要求
|
||||
|
||||
- 先审查现有测试:搜索 `local_markdown_save_writes_table_inline_marks`、`local_markdown_save_round_trips_tiptap_table_marks`、`local_markdown_save_table_handles_colspan_degradation`、`document_shell_bootstrap_preserves_inline_mark_conversion`。
|
||||
- 若降级策略已有足够测试,更新 `3-13` 的表格状态即可。
|
||||
- 若缺少最小测试,优先补 Rust 单测,不新增浏览器 smoke。
|
||||
- 不要直接删除 `legacyStylesToTiptapMarks`,除非你能证明当前 web shell 不再需要 legacy block -> Tiptap marks bootstrap,并且 `web_shell` 测试通过。
|
||||
- 若决定保留该分支,把 `3-13` 中“必须移除”改为“保留兼容层 + 退出条件”,然后归档。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
cargo test -p mnote-web local_markdown -- --test-threads=1
|
||||
cargo test -p mnote-web web_shell -- --test-threads=1
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- 归档/未归档判断
|
||||
- 运行过的命令和结果
|
||||
- 未完成项或风险
|
||||
@@ -0,0 +1,70 @@
|
||||
# Reasonix Worker B:Tree realtime live cache 可归档性复核
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 目标
|
||||
|
||||
复核 `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md` 是否仍应留在 process。
|
||||
|
||||
重点判断:
|
||||
|
||||
1. sidebar、page subtree、filetree 是否已经统一到当前 3000 主界面的 WS push + SSE fallback live cache。
|
||||
2. preferred snapshot 补偿链是否仍是阻塞,还是已成为 live cache 的正常 freshness 仲裁。
|
||||
3. 现有 smoke 是否足以覆盖 create / rename / move / archive / restore / purge / resync / reconnect 的双浏览器 no-refresh 行为。
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
- `design/03-rust-web/done/3-3-rust-web-tree-realtime-event-stream-v1.md`(仅当归档)
|
||||
- `design/03-rust-web/process/3-1-rust-web-long-term-checklist-v2.md`(只做状态/证据同步)
|
||||
|
||||
只读审查:
|
||||
|
||||
- `rust/crates/mnote-web/src/routes/ws.rs`
|
||||
- `rust/crates/mnote-web/src/routes/tree_events.rs`
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
- `scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `scripts/task165-*`
|
||||
- `scripts/task432-filetree-trash-page-dual-browser-no-refresh-smoke.js`
|
||||
- `scripts/task446-tree-rename-dual-browser-live-smoke.js`
|
||||
- `scripts/task447-tree-move-order-dual-browser-live-smoke.js`
|
||||
- `scripts/task448-tree-resync-recovery-dual-browser-smoke.js`
|
||||
- `scripts/task449-tree-sse-reconnect-snapshot-recovery-smoke.js`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- Rust runtime 代码
|
||||
- smoke 脚本,除非只是明显的 node syntax 修复且需要说明
|
||||
- AI / markdown parser 文件
|
||||
|
||||
## 执行要求
|
||||
|
||||
- 使用 `rg` / CodeGraph / 文件读取审查当前 live cache 证据。
|
||||
- 至少运行相关 smoke 的 `node --check`。
|
||||
- 如果 `http://127.0.0.1:3000` 当前可用,优先实跑 1-2 个代表性 smoke:建议 `task446` 和 `task448` 或 `task449`。
|
||||
- 如果当前环境无法实跑,不能声称功能通过;只记录“文档证据足够/不足”和阻塞。
|
||||
- 若证据足够,把 `3-3` 移到 `done/` 并把 9.2 改为已完成记录。
|
||||
- 若证据不足,保留 `process`,写出最小剩余 checklist。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
node --check scripts/task123-rust-web-tree-live-stream-consumer-smoke.js
|
||||
node --check scripts/task432-filetree-trash-page-dual-browser-no-refresh-smoke.js
|
||||
node --check scripts/task446-tree-rename-dual-browser-live-smoke.js
|
||||
node --check scripts/task447-tree-move-order-dual-browser-live-smoke.js
|
||||
node --check scripts/task448-tree-resync-recovery-dual-browser-smoke.js
|
||||
node --check scripts/task449-tree-sse-reconnect-snapshot-recovery-smoke.js
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- `3-3` 是否归档及理由
|
||||
- 运行过的命令和结果
|
||||
- 仍缺的 smoke / 代码缺口
|
||||
@@ -0,0 +1,56 @@
|
||||
# Reasonix Worker C:AI 写入 CommandContext 守卫
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 目标
|
||||
|
||||
收口 `1-6` Gap A7 中最后的 `ai.canWrite` 消费缺口:
|
||||
|
||||
1. 复核 `CommandContext.ai.canWrite` 是否已经被 Hermes / AI 写入路径实际消费。
|
||||
2. 若未消费,补最小守卫:只读 workspace、无写权限或 AI 写入未授权时,正文/页面写入类 Hermes tool 返回明确拒绝,不进入文件写入。
|
||||
3. 补最小 Rust 单测,避免只停留在 `core-protocol` evaluator 层。
|
||||
4. 更新 `design/01-tree-first-graph-kernel/process/1-6-next-phase-gap-closure-checklist-v1.md` 与必要的 `1-5` 状态。
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/01-tree-first-graph-kernel/process/1-6-next-phase-gap-closure-checklist-v1.md`
|
||||
- `design/01-tree-first-graph-kernel/process/1-5-next-phase-sequential-execution-checklist-v1.md`
|
||||
- `rust/crates/core-protocol/src/command.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/page.rs`
|
||||
- 相关同文件测试
|
||||
|
||||
禁止修改:
|
||||
|
||||
- GFM parser / web_shell legacy marks
|
||||
- tree realtime / websocket 文件
|
||||
- OnlyOffice 文件
|
||||
|
||||
## 执行要求
|
||||
|
||||
- 先搜索现有写权限模型,不要凭空新增一套权限真相。
|
||||
- 如果已有 `AiAccessScope`、allowed roots、readonly workspace 或 local access policy helper,应复用。
|
||||
- `ai.canWrite` 是 command context 口径;如果 runtime 现有权限模型名称不同,可以用桥接 helper,但不要把 evaluator 复制到多个地方。
|
||||
- 拒绝响应必须可解释,不能 panic,不能静默成功。
|
||||
- 不要扩大 AI 功能面,只守卫已有写入路径。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
cargo test -p core-protocol command_context -- --test-threads=1
|
||||
cargo test -p mnote-web hermes_tools -- --test-threads=1
|
||||
git diff --check
|
||||
```
|
||||
|
||||
如果 `hermes_tools` 过滤器过大或无匹配,请运行你新增测试的精确过滤命令,并在最终回复说明。
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- 是否实现运行时守卫
|
||||
- 运行过的命令和结果
|
||||
- 未完成项或风险
|
||||
@@ -0,0 +1,70 @@
|
||||
# Reasonix Worker A:Local Folder Tree Live 后端事件流
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 背景
|
||||
|
||||
`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md` 仍未整体完成,当前阻塞在 `3-3`:local_folder 默认路径的 Sidebar / FileTree 仍通过 `startLocalFolderSidebarWatch()` 轮询 `/api/tree/local-folder-watch` 后补拉 projection,没有进入统一 tree live consumer。
|
||||
|
||||
新 checklist:`design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_events.rs`
|
||||
- `rust/crates/mnote-web/src/routes/stream_support.rs`
|
||||
- `rust/crates/mnote-web/src/routes/mod.rs`
|
||||
- 同文件测试
|
||||
|
||||
只读参考:
|
||||
|
||||
- `rust/crates/mnote-web/src/local_folder_watcher_registry.rs`
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
- `rust/crates/mnote-web/src/routes/kernel.rs`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
- `scripts/*.js`
|
||||
- 其他 design 文档
|
||||
|
||||
## 目标
|
||||
|
||||
1. 给 local_folder 提供 tree live 事件形状,至少支持 snapshot / resync。
|
||||
2. payload 中必须携带:
|
||||
- `kind: "snapshot"` 或 `kind: "resync"`
|
||||
- `stream: "workspace"`
|
||||
- `projection: "sidebar_tree"`
|
||||
- `sourceKind: "local_folder"`
|
||||
- `rootUri`
|
||||
- `workspaceId`
|
||||
- `revision`
|
||||
- `data.dataset.kernel_sidebar_projection`
|
||||
- `data.dataset.kernel_file_tree_projection`
|
||||
3. 复用 `LocalFolderWatcherRegistry`,不要新增第二套 watcher。
|
||||
4. 如果不能可靠生成细粒度 delta,本阶段允许 watcher change 后发 resync snapshot。
|
||||
5. 不把 local_folder 变化写回 Convex command log。
|
||||
|
||||
## 建议实现
|
||||
|
||||
- 可以扩展 `/api/local-folder/events`,让它在 query 中带 `treeLive=1` 或 `scope=tree` 时输出 `snapshot` / `resync` 事件;保留原有 `ready` / `change` 给 web_shell 编辑器外部变更使用。
|
||||
- snapshot 可复用 `load_local_folder_page_tree_snapshot(rootUri)` 和 `load_local_folder_file_tree_snapshot(rootUri)` 组装 dataset。
|
||||
- 事件 id 可继续使用 revision。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
cargo test --manifest-path rust/Cargo.toml -p mnote-web local_folder_events -- --test-threads=1
|
||||
cargo test --manifest-path rust/Cargo.toml -p mnote-web stream_support -- --test-threads=1
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- 新增/变更的 API 行为
|
||||
- 运行过的命令和结果
|
||||
- 未完成项或风险
|
||||
@@ -0,0 +1,47 @@
|
||||
# Reasonix Worker B:Local Folder Tree Live 前端 consumer 接入
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 背景
|
||||
|
||||
`3-3` 暂不能归档,因为 `sourceKind=local_folder` 当前在 `TREE_LIVE_CONTROLLER_JS` 中直接设置 `data-mnote-tree-live-transport="local-folder-static"` 并 return;Sidebar / FileTree 依赖 `startLocalFolderSidebarWatch()` 轮询 `/api/tree/local-folder-watch` 后补拉 projection。
|
||||
|
||||
新 checklist:`design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- Rust route 后端文件
|
||||
- `scripts/*.js`
|
||||
- 其他 design 文档
|
||||
|
||||
## 目标
|
||||
|
||||
1. local_folder 默认路径应进入 tree live controller,不再直接 `local-folder-static` return。
|
||||
2. 使用 Worker A 新增/扩展的 local_folder tree live SSE,接收到 snapshot/resync 后 dispatch `tree:snapshot` / `tree:resync`,复用已有 `renderSidebarSnapshot()` consumer。
|
||||
3. `startLocalFolderSidebarWatch()` 可保留为 fallback,但不再是默认主链。
|
||||
4. 不破坏 web_shell/tiptap 的 `/api/local-folder/events` 文档外部变更通道。
|
||||
5. DOM 状态应能区分新主链,例如 `data-mnote-tree-live-transport="local-folder-events"`,并在应用成功后设置 `data-mnote-tree-live-applied="snapshot"` 或 `"resync"`。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_tree_runtime -- --test-threads=1
|
||||
cargo test --manifest-path rust/Cargo.toml -p mnote-web web_shell -- --test-threads=1
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- local_folder tree live 主链变化
|
||||
- fallback 保留情况
|
||||
- 运行过的命令和结果
|
||||
- 未完成项或风险
|
||||
@@ -0,0 +1,51 @@
|
||||
# Reasonix Worker C:Local Folder Tree Live 浏览器 smoke
|
||||
|
||||
Project root:`/mnt/Data1T/mnote`
|
||||
|
||||
你不是唯一 worker。不要回滚、覆盖或清理他人的改动;只修改本任务 ownership 范围内的文件。不要提交 git。
|
||||
|
||||
## 背景
|
||||
|
||||
`3-3` 的归档条件要求 `3000` 当前主界面的 Sidebar / page subtree / FileTree / preferred snapshot 补偿链统一到正式 live cache。当前 local_folder 仍是轮询补拉 projection。Worker A/B 会尝试把 local_folder 接入 tree live consumer;本任务负责 smoke 证据。
|
||||
|
||||
新 checklist:`design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `scripts/task435-local-folder-watch-no-reload-smoke.js`
|
||||
- 可新增:`scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- Rust route / layout runtime 代码
|
||||
|
||||
## 目标
|
||||
|
||||
1. 增加或更新 smoke,验证 local_folder 文档页不再把 `local-folder-static` 当默认 tree live 主链。
|
||||
2. 验证 local_folder 外部文件变化后,Sidebar / FileTree 刷新最终留下 tree live consumer 证据,例如:
|
||||
- `data-mnote-tree-live-transport="local-folder-events"`
|
||||
- `data-mnote-tree-live-applied="snapshot"` 或 `"resync"`
|
||||
- `data-mnote-local-folder-watch-applied` 不再是唯一证据
|
||||
3. smoke 结果写入 `tmp/.../result.json`,如可行保存截图。
|
||||
4. 若当前代码尚未满足断言,允许先写 RED smoke,但必须在文档执行记录中说明它当前预期失败。
|
||||
|
||||
## 验收命令
|
||||
|
||||
```bash
|
||||
node --check scripts/task435-local-folder-watch-no-reload-smoke.js
|
||||
node --check scripts/task487-local-folder-tree-live-consumer-smoke.js
|
||||
git diff --check
|
||||
```
|
||||
|
||||
如果没有新增 task487,则说明原因。
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
- 修改文件列表
|
||||
- smoke 覆盖点
|
||||
- 当前是否 RED / GREEN
|
||||
- 运行过的命令和结果
|
||||
- 未完成项或风险
|
||||
@@ -0,0 +1,55 @@
|
||||
# Reasonix Worker A:3-3 live cache 可归档性复核
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
- 如确认可归档,可移动到:
|
||||
- `design/03-rust-web/done/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改 Rust / JS runtime 代码。
|
||||
- 不改 `1-8`、`1-13`、`1-14`。
|
||||
- 不提交 git。
|
||||
- 不删除任何 `tmp/` 证据。
|
||||
|
||||
## 背景
|
||||
|
||||
`1-8` Batch D 仍把 `3-3` 作为 live cache 入口。旧 `3-3` 文档 9.2 说 sidebar / page subtree / filetree 没有全部统一 live cache、WS 只证明骨架、不能移动到 done。
|
||||
|
||||
但后续已有:
|
||||
|
||||
- `design/03-rust-web/done/3-14-rust-web-tree-realtime-ws-push-v1.md`
|
||||
- `design/03-rust-web/done/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
- `scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `scripts/task432-filetree-trash-page-dual-browser-no-refresh-smoke.js`
|
||||
- `scripts/task446-tree-rename-dual-browser-live-smoke.js`
|
||||
- `scripts/task447-tree-move-order-dual-browser-live-smoke.js`
|
||||
- `scripts/task448-tree-resync-recovery-dual-browser-smoke.js`
|
||||
- `scripts/task449-tree-sse-reconnect-snapshot-recovery-smoke.js`
|
||||
- `scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
|
||||
## 任务
|
||||
|
||||
1. 读取 `3-3`、`3-14`、`3-18`,判断 `3-3` 的 9.2 未完成项是否已经过期。
|
||||
2. 如果证据足够,更新 `3-3` 状态为 done,并移动到 `design/03-rust-web/done/`。
|
||||
3. 如果证据不足,不移动,只在 `3-3` 里写明最小剩余缺口。
|
||||
4. 运行最小语法检查:
|
||||
- `node --check scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `node --check scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `git diff --check`
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出:
|
||||
|
||||
1. 修改文件
|
||||
2. 归档或不归档的理由
|
||||
3. 验证命令和结果
|
||||
4. 未完成项 / 风险
|
||||
@@ -0,0 +1,50 @@
|
||||
# Reasonix Worker B:1-5 / 1-6 command context 状态收口
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/01-tree-first-graph-kernel/process/1-5-next-phase-sequential-execution-checklist-v1.md`
|
||||
- `design/01-tree-first-graph-kernel/process/1-6-next-phase-gap-closure-checklist-v1.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改 Rust / JS runtime 代码。
|
||||
- 不改 `1-8`、`1-13`、`1-14`。
|
||||
- 不提交 git。
|
||||
|
||||
## 背景
|
||||
|
||||
当前代码和 `1-6` 的部分段落已经显示:
|
||||
|
||||
- `core-protocol/src/command.rs` 有 `CommandContext` / `when` evaluator。
|
||||
- FileTree 右键菜单和 Delete/Backspace 已接入等价 context 判断。
|
||||
- Hermes tools 写入守卫已消费 `args.commandContext` / `args.command_context` 的 `ai.canWrite` 与 `workspace.readonly`。
|
||||
|
||||
但 `1-5` Phase A7 和 `1-6` 顶部/汇总处仍有一些未更新的未完成表述。
|
||||
|
||||
## 任务
|
||||
|
||||
1. 只围绕 command context / context key 状态更新 `1-5` 与 `1-6`。
|
||||
2. 把已经有证据的项改为完成,并写入验证命令。
|
||||
3. 保留真实未完成项,例如更完整的 editor/object tab context 或未实跑的 DnD readonly smoke。
|
||||
4. 不夸大为“所有 command context 完全完成”。
|
||||
5. 运行:
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p core-protocol command_context -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web ensure_write_authorized -- --test-threads=1`
|
||||
- `node --check scripts/task471-local-folder-bulk-resource-trash-smoke.js`
|
||||
- `node --check scripts/task476-filetree-editor-context-menu-download-smoke.js`
|
||||
- `git diff --check`
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出:
|
||||
|
||||
1. 修改文件
|
||||
2. 勾选了哪些项、保留了哪些未完成项
|
||||
3. 验证命令和结果
|
||||
4. 风险
|
||||
@@ -0,0 +1,53 @@
|
||||
# Reasonix Worker C:Batch D 浏览器 smoke 证据整理
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-h-worker-c-browser-smoke-evidence.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改产品代码。
|
||||
- 不改 design 主文档。
|
||||
- 不提交 git。
|
||||
- 不删除或覆盖 `tmp/` 证据。
|
||||
|
||||
## 任务
|
||||
|
||||
只读检查以下 smoke 脚本和已有证据,整理成一份表格:
|
||||
|
||||
- `scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `scripts/task432-filetree-trash-page-dual-browser-no-refresh-smoke.js`
|
||||
- `scripts/task446-tree-rename-dual-browser-live-smoke.js`
|
||||
- `scripts/task447-tree-move-order-dual-browser-live-smoke.js`
|
||||
- `scripts/task448-tree-resync-recovery-dual-browser-smoke.js`
|
||||
- `scripts/task449-tree-sse-reconnect-snapshot-recovery-smoke.js`
|
||||
- `scripts/task471-local-folder-bulk-resource-trash-smoke.js`
|
||||
- `scripts/task476-filetree-editor-context-menu-download-smoke.js`
|
||||
- `scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
|
||||
输出必须区分:
|
||||
|
||||
- 已实跑通过,且有 `tmp/` 结果或截图证据。
|
||||
- 仅 `node --check` 通过,还缺真实浏览器实跑。
|
||||
- 可用于人工网页核查的点。
|
||||
- 仍建议 Codex 主线程复跑的点。
|
||||
|
||||
验收:
|
||||
|
||||
- 运行 `node --check` 检查上述脚本语法,能跑多少跑多少;若脚本不存在或环境阻塞,写明。
|
||||
- 运行 `git diff --check`。
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出:
|
||||
|
||||
1. 写入的结果文件
|
||||
2. 证据摘要
|
||||
3. 建议 Codex 复跑的 smoke
|
||||
4. 风险
|
||||
@@ -0,0 +1,50 @@
|
||||
# Reasonix Worker A:7-27 归档性审查
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `design/07-ai/process/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
- 若确认可归档,可移动到:
|
||||
- `design/07-ai/done/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改 Rust / JS runtime 代码。
|
||||
- 不改 `1-8`、`7-29`。
|
||||
- 不提交 git。
|
||||
|
||||
## 背景
|
||||
|
||||
`7-27` 设计目标是让在线 `mnote.doc.markdown_edit` 以最终 markdown 为写回真源,而不是继续从原始 operations 二次推导 block ops。
|
||||
|
||||
当前代码已有:
|
||||
|
||||
- `parse_final_markdown_to_blocks`
|
||||
- `build_page_content`
|
||||
- `build_changed_blocks_summary`
|
||||
- `doc_markdown_edit` 中 `mnote.doc.markdown_edit (7-27)` reason
|
||||
- `markdown_edit` targeted tests 通过
|
||||
|
||||
## 任务
|
||||
|
||||
1. 对照 `7-27` 步骤 1-6、测试矩阵、开放问题,判断当前代码是否已满足归档条件。
|
||||
2. 如果可归档,更新状态并移动到 `design/07-ai/done/`。
|
||||
3. 如果不可归档,只写明最小剩余缺口,不改代码。
|
||||
4. 运行:
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web markdown_edit -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web hermes_tools_manifest_describes_markdown_edit_write_contract -- --test-threads=1`
|
||||
- `git diff --check`
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出:
|
||||
|
||||
1. 修改文件
|
||||
2. 可归档或不可归档理由
|
||||
3. 验证命令和结果
|
||||
4. 未完成项 / 风险
|
||||
@@ -0,0 +1,50 @@
|
||||
# Reasonix Worker B:7-27 代码/测试缺口审查
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-i-worker-b-7-27-code-test-gap.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改代码。
|
||||
- 不改 design 主文档。
|
||||
- 不提交 git。
|
||||
|
||||
## 任务
|
||||
|
||||
只读审查当前 `7-27` 实现,重点文件:
|
||||
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_tools.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
|
||||
检查这些点:
|
||||
|
||||
1. `blocks_to_markdown` 是否能从 legacy `content` / `contentNodes` 读取文本,而不是只读 `text`。
|
||||
2. 注释格式是否与 `7-27` 文档一致,是否真的保留 `revisionRef`。
|
||||
3. `full_content` 是否不再被拒绝,是否会保留复杂块。
|
||||
4. `dryRun` 是否不写入。
|
||||
5. selection / allowedTargetBlockIds 是否阻止越界写入。
|
||||
6. 是否还有 `build_block_ops_from_markdown_edit` 旧推导路径。
|
||||
7. 测试覆盖是否足以归档。
|
||||
|
||||
输出到结果文件,按三类分级:
|
||||
|
||||
- 必须修复才能归档
|
||||
- 可作为后续增强
|
||||
- 已满足
|
||||
|
||||
验收:
|
||||
|
||||
- 运行 `git diff --check`
|
||||
- 结果文件引用具体函数名或测试名。
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出结果文件路径和最高风险结论。
|
||||
@@ -0,0 +1,45 @@
|
||||
# Reasonix Worker C:7-15 / 7-12 后续拆分审查
|
||||
|
||||
## 项目
|
||||
|
||||
- Project root: `/mnt/Data1T/mnote`
|
||||
|
||||
## Ownership
|
||||
|
||||
允许修改:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-i-worker-c-acp-review-tail.md`
|
||||
|
||||
禁止修改:
|
||||
|
||||
- 不改代码。
|
||||
- 不改 design 主文档。
|
||||
- 不提交 git。
|
||||
|
||||
## 任务
|
||||
|
||||
只读审查:
|
||||
|
||||
- `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md`
|
||||
- `design/07-ai/process/7-12-page-ai-hermes-tool-routing-and-review-surface-v1.md`
|
||||
- `rust/crates/mnote-web/src/acp_client.rs`
|
||||
- `rust/crates/mnote-web/src/acp_session_manager.rs`
|
||||
- `rust/crates/mnote-web/src/acp_runtime.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_client.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
|
||||
目标:
|
||||
|
||||
1. 判断 `7-15` Step 15-17 是否仍是当前应执行项,或是否应拆成独立 checklist。
|
||||
2. 判断 `7-12` Phase B-F 哪些已被当前 manifest/runtime/tool guard 覆盖。
|
||||
3. 明确 Phase C Review Mode 仍冻结,不要建议本轮实现。
|
||||
4. 给出下一批 P0/P1/P2 顺序。
|
||||
|
||||
验收:
|
||||
|
||||
- 运行 `git diff --check`
|
||||
- 结果文件必须有 P0/P1/P2 表格。
|
||||
|
||||
## 最终回复
|
||||
|
||||
用简体中文列出结果文件路径、P0 建议和风险。
|
||||
@@ -0,0 +1,49 @@
|
||||
# Batch J Worker A:旧 HTTP proxy / page AI fallback 调用链审查
|
||||
|
||||
项目根目录:`/mnt/Data1T/mnote`
|
||||
|
||||
## 目标
|
||||
|
||||
只读审查 `7-34` 的 P0-1 / P0-2:
|
||||
|
||||
1. 查清 `hermes_client.rs` 中旧 Hermes HTTP proxy 路径是否仍有默认入口。
|
||||
2. 查清 `page_ai_workflow.rs` 是否仍会在 local-first 默认口径下绕过 ACP / shared tool executor,重新走旧 block-edit fallback。
|
||||
|
||||
## 允许范围
|
||||
|
||||
只读以下文件,不修改代码:
|
||||
|
||||
- `rust/crates/mnote-web/src/routes/hermes_client.rs`
|
||||
- `rust/crates/mnote-web/src/page_ai_workflow.rs`
|
||||
- `rust/crates/mnote-web/src/acp_runtime.rs`
|
||||
- `rust/crates/mnote-web/src/acp_session_manager.rs`
|
||||
- `rust/crates/mnote-web/src/routes/mod.rs`
|
||||
- 必要时可只读 `rust/crates/mnote-web/src/routes/*.rs` 里和 route 注册相关的文件
|
||||
|
||||
## 禁止事项
|
||||
|
||||
- 不修改任何源码、设计文档或测试。
|
||||
- 不提交 git。
|
||||
- 不移动文件。
|
||||
- 不运行破坏性命令。
|
||||
|
||||
## 输出要求
|
||||
|
||||
把结果写入 `.codex/reasonix-tasks/results/batch-j-worker-a-http-proxy-fallback.md`。
|
||||
|
||||
必须包含:
|
||||
|
||||
1. 旧 HTTP proxy / page AI fallback 的真实调用链。
|
||||
2. 每个入口的分类:`default` / `compat` / `debug-only` / `未被调用`。
|
||||
3. 是否存在必须在本轮修复的 P0 缺口。
|
||||
4. 若需要后续代码修改,给出最小修改范围和建议测试命令。
|
||||
|
||||
## 验收命令
|
||||
|
||||
只需要运行:
|
||||
|
||||
```bash
|
||||
git diff --check
|
||||
```
|
||||
|
||||
最终回复中列出读取过的关键文件、结论、风险和未完成项。
|
||||
@@ -0,0 +1,51 @@
|
||||
# Batch J Worker B:tool availability 三处一致性审查
|
||||
|
||||
项目根目录:`/mnt/Data1T/mnote`
|
||||
|
||||
## 目标
|
||||
|
||||
只读审查 `7-34` 的 P1-1:
|
||||
|
||||
确认 profile-level tool availability / capability 是否在三处保持一致:
|
||||
|
||||
1. Hermes tool manifest:工具是否标明 enabled / disabled / capability / annotations。
|
||||
2. UI:页面 AI 或 tool list 是否根据同一能力判断展示 disabled / hidden。
|
||||
3. Execute guard:真正执行工具时是否复用同一能力判断,而不是只靠 UI 阻止。
|
||||
|
||||
## 允许范围
|
||||
|
||||
只读以下文件,不修改代码:
|
||||
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/*.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_tools.rs`
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
- 必要时可只读 `rust/crates/mnote-web/src/routes/hermes_client.rs`
|
||||
|
||||
## 禁止事项
|
||||
|
||||
- 不修改任何源码、设计文档或测试。
|
||||
- 不提交 git。
|
||||
- 不移动文件。
|
||||
- 不运行破坏性命令。
|
||||
|
||||
## 输出要求
|
||||
|
||||
把结果写入 `.codex/reasonix-tasks/results/batch-j-worker-b-tool-availability.md`。
|
||||
|
||||
必须包含:
|
||||
|
||||
1. manifest / UI / execute guard 各自当前能力判断来源。
|
||||
2. 三处是否同源;如果不同源,指出具体文件和函数。
|
||||
3. P0/P1/P2 分级缺口。
|
||||
4. 建议的最小测试名或现有 targeted test。
|
||||
|
||||
## 验收命令
|
||||
|
||||
只需要运行:
|
||||
|
||||
```bash
|
||||
git diff --check
|
||||
```
|
||||
|
||||
最终回复中列出读取过的关键文件、结论、风险和未完成项。
|
||||
@@ -0,0 +1,50 @@
|
||||
# Batch J Worker C:ACP 稳定性与 benchmark checklist 草案
|
||||
|
||||
项目根目录:`/mnt/Data1T/mnote`
|
||||
|
||||
## 目标
|
||||
|
||||
只读审查 `7-34` 的 P1-2 / P1-3:
|
||||
|
||||
为 ACP 多会话稳定性测试和 Reasonix cache benchmark 拆出最小可执行方案,供 Codex 后续实现或派发实现 worker。
|
||||
|
||||
## 允许范围
|
||||
|
||||
只读以下文件和目录,不修改代码:
|
||||
|
||||
- `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md`
|
||||
- `design/07-ai/done/7-25-acp-session-runtime-enhancement-plan-v1.md`
|
||||
- `design/07-ai/done/7-30-acp-session-load-resume-checklist-v1.md`
|
||||
- `design/07-ai/done/7-31-acp-permission-decision-loop-checklist-v1.md`
|
||||
- `design/07-ai/done/7-32-acp-tool-location-and-open-action-checklist-v1.md`
|
||||
- `design/07-ai/done/7-33-acp-session-info-plan-ui-checklist-v1.md`
|
||||
- `scripts/`
|
||||
- `rust/crates/mnote-web/src/acp_*.rs`
|
||||
|
||||
## 禁止事项
|
||||
|
||||
- 不修改任何源码、设计文档或测试。
|
||||
- 不提交 git。
|
||||
- 不移动文件。
|
||||
- 不运行破坏性命令。
|
||||
|
||||
## 输出要求
|
||||
|
||||
把结果写入 `.codex/reasonix-tasks/results/batch-j-worker-c-acp-stability-benchmark.md`。
|
||||
|
||||
必须包含:
|
||||
|
||||
1. ACP 多会话稳定性 smoke 的最小脚本方案:输入、操作、断言、证据文件。
|
||||
2. Reasonix cache benchmark 的最小脚本方案:Hermes / Reasonix 对比维度、样本数、输出格式。
|
||||
3. 浏览器可见验证点和截图/JSON 证据建议。
|
||||
4. 哪些属于 P0 稳定性验证,哪些只是 P2 度量。
|
||||
|
||||
## 验收命令
|
||||
|
||||
只需要运行:
|
||||
|
||||
```bash
|
||||
git diff --check
|
||||
```
|
||||
|
||||
最终回复中列出读取过的关键文件、结论、风险和未完成项。
|
||||
@@ -0,0 +1,37 @@
|
||||
# Reasonix 任务书:1-8 completion hook 验证
|
||||
|
||||
## 目标
|
||||
|
||||
在 `design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md` 中补一段简短的执行备注,说明:
|
||||
|
||||
1. Reasonix 编码任务默认使用 30 分钟超时。
|
||||
2. Reasonix 完成后应通过 completion hook 主动回传,不再依赖短轮询。
|
||||
3. 这条口径属于当前 1-8 的执行说明,不要扩写成新流程设计。
|
||||
|
||||
## 允许修改范围
|
||||
|
||||
- `design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
|
||||
## 禁止事项
|
||||
|
||||
- 不要修改其他设计文档。
|
||||
- 不要改代码。
|
||||
- 不要提交 git。
|
||||
- 不要删除或重排现有 1-8 结构,只做最小增补。
|
||||
|
||||
## 验收标准
|
||||
|
||||
- 1-8 文档中能看到新增的简短备注。
|
||||
- 备注明确提到:
|
||||
- 默认 30 分钟超时
|
||||
- completion hook 主动回传
|
||||
- 输出最终结果时列出实际修改文件和验证方式。
|
||||
|
||||
## 最终回复格式
|
||||
|
||||
请用简体中文,按下面顺序输出:
|
||||
|
||||
1. 修改了哪些文件
|
||||
2. 具体改动内容
|
||||
3. 验证方式
|
||||
4. 未完成项或风险
|
||||
@@ -0,0 +1,22 @@
|
||||
# Batch F Worker A GFM Archive Timeout
|
||||
|
||||
- 时间:2026-05-21
|
||||
- 任务书:`.codex/reasonix-tasks/2026-05-21-batch-f-worker-a-gfm-archive.md`
|
||||
- runner 目录:`/home/lix/.codex/runtime/reasonix-coding-worker/reasonix-2026-05-21T09-32-37-250Z-33d2e71c`
|
||||
- 状态:TIMEOUT
|
||||
|
||||
## 现象
|
||||
|
||||
Reasonix runner 长时间未生成 `final.md` / `result.json`,仅有 `prompt.md` 与 `reasonix-transcript.jsonl`。Codex 已终止该 runner 与对应 `reasonix acp` 进程,避免继续占用执行槽。
|
||||
|
||||
## 处理
|
||||
|
||||
Codex 本地继续复核 `3-13`:
|
||||
|
||||
- `local_markdown_save_writes_table_inline_marks`
|
||||
- `local_markdown_save_round_trips_tiptap_table_marks`
|
||||
- `local_markdown_save_writes_table_alignment_markers`
|
||||
- `local_markdown_save_table_handles_colspan_degradation`
|
||||
- `document_shell_bootstrap_preserves_inline_mark_conversion`
|
||||
|
||||
后续以 Codex 复核和 targeted tests 为准,不采纳本 worker 的空结果。
|
||||
@@ -0,0 +1,15 @@
|
||||
# Batch F Worker B Tree Live Cache Misrouted
|
||||
|
||||
- 时间:2026-05-21
|
||||
- 任务书:`.codex/reasonix-tasks/2026-05-21-batch-f-worker-b-tree-live-cache.md`
|
||||
- runner 目录:`/home/lix/.codex/runtime/reasonix-coding-worker/reasonix-2026-05-21T09-32-37-259Z-bd4aeac4`
|
||||
- 状态:MISROUTED
|
||||
|
||||
## 现象
|
||||
|
||||
任务书要求审查 `3-3` tree realtime live cache,但 Reasonix 最终输出写成“Worker C:AI 写入 CommandContext 守卫”,并对 Hermes 写入守卫方向产生了代码改动。该结果不能作为 `3-3` live cache 归档证据。
|
||||
|
||||
## 处理
|
||||
|
||||
- `3-3` 仍由 Codex 本地复核。
|
||||
- 当前 Hermes 写入守卫 diff 需由 Codex 独立审查、修正并运行 targeted tests 后,才可作为 Worker C 方向的补充实现。
|
||||
@@ -0,0 +1,56 @@
|
||||
# Batch H Worker C — 浏览器 Smoke 证据整理
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
> 状态:✅ 已完成(Codex 已复核并补跑关键 smoke)
|
||||
|
||||
## 语法检查结果
|
||||
|
||||
| Smoke 脚本 | `node --check` | 说明 |
|
||||
|-----------|:---:|-------|
|
||||
| `task123-rust-web-tree-live-stream-consumer-smoke.js` | ✅ PASS | SSE/WS tree stream consumer |
|
||||
| `task432-filetree-trash-page-dual-browser-no-refresh-smoke.js` | ✅ PASS | 双浏览器页面/垃圾箱无刷新同步 |
|
||||
| `task446-tree-rename-dual-browser-live-smoke.js` | ✅ PASS | 双浏览器重命名实时同步 |
|
||||
| `task447-tree-move-order-dual-browser-live-smoke.js` | ✅ PASS | 双浏览器移动顺序实时同步 |
|
||||
| `task448-tree-resync-recovery-dual-browser-smoke.js` | ✅ PASS | 双浏览器 resync 恢复 |
|
||||
| `task449-tree-sse-reconnect-snapshot-recovery-smoke.js` | ✅ PASS | SSE 断线重连恢复 |
|
||||
| `task471-local-folder-bulk-resource-trash-smoke.js` | ✅ PASS | local_folder 批量资源删除 |
|
||||
| `task476-filetree-editor-context-menu-download-smoke.js` | ✅ PASS | 文件树/编辑器右键菜单 + 下载 |
|
||||
| `task487-local-folder-tree-live-consumer-smoke.js` | ✅ PASS | local_folder 树 live consumer 收敛 |
|
||||
|
||||
**全部 9/9 `node --check` 通过 ✅**
|
||||
|
||||
## 实跑证据汇总
|
||||
|
||||
| # | Smoke | 有 tmp/ 证据 | 状态 | 关键断言 |
|
||||
|---|-------|:----------:|:----:|---------|
|
||||
| 1 | task123 — 树 live stream consumer | ✅ `tmp/tree-live-cache-smoke/20260516-task123/task123.stdout.json` | ✅ GREEN | SSE snapshot 含 `data.dataset.kernel_sidebar_projection` + `kernel_file_tree_projection`;临时页 doc row 出现 |
|
||||
| 2 | task432 — 页面/垃圾箱双浏览器无刷新同步 | ✅ `tmp/tree-live-cache-smoke/20260516-task432/result.json` | ✅ GREEN | 新建/归档/恢复/清空垃圾箱在 B 端无刷新同步通过 `tree:resync`/`tree:delta` |
|
||||
| 3 | task446 — 重命名双浏览器实时同步 | ✅ `tmp/tree-live-cache-smoke/20260516-task446-rename/result.json` + 截图 | ✅ GREEN | B 文档页头、Breadcrumb、Sidebar、FileTree 全部通过 `tree:delta upsert_document` 更新 |
|
||||
| 4 | task447 — 移动顺序双浏览器实时同步 | ✅ `tmp/tree-live-cache-smoke/20260516-task447-move-order/result.json` + 截图 | ✅ GREEN | Page Tree / File Tree 顺序通过 `tree:delta move_document` 更新为 A/C/B |
|
||||
| 5 | task448 — resync 恢复双浏览器 | ✅ `tmp/tree-live-cache-smoke/20260516-task448-resync/result.json` + 截图 | ✅ GREEN | 多条 missed command 触发 `event: resync`,完整 snapshot 投影恢复 |
|
||||
| 6 | task449 — SSE 重连恢复 | ✅ `tmp/tree-live-cache-smoke/20260516-task449-reconnect/result.json` + 截图 | ✅ GREEN | 断线后 EventSource 回连,snapshot 拉回最新,`liveStatus=connected` |
|
||||
| 7 | task471 — local_folder 批量资源删除 | ✅ `tmp/reasonix-batch-a-browser-task471-2026-05-21/result.json` + 本轮 stdout | ✅ GREEN | Codex 本轮复跑通过,批量 archive 两个资源:`附件-a.txt`、`附件-b.json` |
|
||||
| 8 | task476 — 文件树/编辑器上下文菜单+下载 | ✅ `tmp/task476-filetree-editor-context-menu-download-smoke/result.json` + 截图 | ✅ GREEN | Codex 使用 `/usr/bin/google-chrome-stable` 复跑通过,文件树 asset/多选/markdown/folder 下载均通过;编辑器附件菜单因附件不可见被标记为 blocked,不影响 FileTree 下载链路 |
|
||||
| 9 | task487 — local_folder 树 live consumer 收敛 | ✅ `tmp/task487-local-folder-tree-live-consumer-smoke/result.json` + 截图 | ✅ GREEN | 全部 9 断言通过:`transport=local-folder-events`、`status=connected`、外部创建/删除后 `applied=resync` |
|
||||
|
||||
## 可用于人工网页核查的点
|
||||
|
||||
1. **task476**:FileTree asset 右键菜单缺 download 按钮。人工核查时在 Explorer 标签右键任何 PDF/图片/附件,检查是否有「Download」动作。
|
||||
2. **task487**:local_folder 文档页 HTML `<html>` 上应看到 `data-mnote-tree-live-transport="local-folder-events"` + `data-mnote-tree-live-status="connected"`。
|
||||
3. **task446-449**:双浏览器打开同一 workspace,A 端执行 rename/move/create/delete,B 端页面/文件树应无刷新更新。
|
||||
4. **task432**:Trash 页面 create/archive/restore/purge/empty 在 B 端无导航刷新同步。
|
||||
|
||||
## 建议 Codex 复跑的 smoke
|
||||
|
||||
| Smoke | 复跑理由 | 命令 |
|
||||
|-------|---------|------|
|
||||
| task476 | 本轮已用系统 Chrome 复跑通过;后续只需在改动下载链路后回归 | `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome-stable node scripts/task476-filetree-editor-context-menu-download-smoke.js` |
|
||||
| task487 | 确认 local_folder tree live consumer 收敛回归不退化 | `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome-stable node scripts/task487-local-folder-tree-live-consumer-smoke.js` |
|
||||
| task431 | DnD readonly conflict smoke,属于 Phase A7 最终验收 | `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome-stable node scripts/task431-vscode-explorer-dnd-readonly-conflict-smoke.js` |
|
||||
|
||||
## 风险
|
||||
|
||||
1. **task476 浏览器选择差异**:`/snap/bin/chromium` 曾出现 `download.saveAs ENOENT`,但同一脚本用 `/usr/bin/google-chrome-stable` 复跑通过,判定为 Playwright 下载临时文件层噪音;后续 smoke 优先使用系统 Chrome。
|
||||
2. **task487 脚本头部注释仍标 RED**:注释写 `STATUS: 🔴 RED (预期失败)` 但实跑已 GREEN。脚本头部注释需要更新,以免误导后续批次。
|
||||
3. **task471 bulk trash 未测资源命名冲突**:批量删除后同名资源在当前批次无冲突场景测试。
|
||||
4. **git diff 检查**:Codex 本轮已运行 `git diff --check`,无空白错误。
|
||||
@@ -0,0 +1,66 @@
|
||||
# Worker A:7-27 归档性审查结果
|
||||
|
||||
> 审查时间:2026-05-20
|
||||
> 审查范围:`design/07-ai/process/7-27-online-markdown-writeback-final-content-truth-v2.md` × 当前 Rust 代码
|
||||
|
||||
---
|
||||
|
||||
## 1. 对照步骤 1-6 的完成状态
|
||||
|
||||
| 步骤 | 内容 | 状态 | 证据 |
|
||||
|------|------|------|------|
|
||||
| 步骤 1 | 增强 `blocks_to_markdown`:注释格式加 type/rev,复杂块用 raw marker | ✅ 已实现 | `doc.rs:1185-1215` — 输出 `<!-- block:id:type:level=N -->` 和 `[mnote-raw-block:id]` |
|
||||
| 步骤 2 | 实现 `parse_final_markdown_to_blocks` | ✅ 已实现 | `doc.rs:656-747` — 完整实现含正则提取、fuzzy 回退、复杂块保留 |
|
||||
| 步骤 3 | 实现 `build_page_content` | ✅ 已实现 | `doc.rs:850-913` — 含新块 ID 生成、复杂块保留、inline contentNodes 保护 |
|
||||
| 步骤 4 | 替换 `doc_markdown_edit` online 写回路径 | ✅ 已实现 | `doc.rs:1625-1700` — "// 7-27: 在线写回以最终 markdown 为真源" |
|
||||
| 步骤 5 | 更新 `full_content` 处理 | ✅ 已实现 | `doc.rs:1578-1585` — 转为 search=全文, replace=full,进新路径 |
|
||||
| 步骤 6 | 清理旧代码 | ✅ 已标记 | Line 1911: `// 退役:7-27 …直接写回` |
|
||||
|
||||
## 2. 测试矩阵覆盖
|
||||
|
||||
| 优先级 | 场景 | 测试函数 | 结果 |
|
||||
|--------|------|----------|------|
|
||||
| P0 | 单块精确 search/replace | `test_search_replace_exact` | ✅ |
|
||||
| P0 | 忽略空白 match | `test_search_replace_normalized_chinese_byte_boundaries` | ✅ |
|
||||
| P0 | 多 operation 命中同块 | `hermes_tools_markdown_edit_merges_same_block_operations` | ✅ |
|
||||
| P0 | full_content | `hermes_tools_markdown_edit_online_full_content_rejects_unsafe_block_mapping` | ✅ 注释明确:"7-27 修复后:full_content 不再被拒绝" |
|
||||
| P1 | heading 替换 | `test_blocks_to_markdown_heading` | ✅ |
|
||||
| P1 | 包含复杂块文档的替换 | `test_build_page_content_full_content_replaces_old_text_blocks_but_keeps_complex_blocks` | ✅ |
|
||||
| P1 | dryRun | `hermes_tools_markdown_edit_local_dry_run_does_not_write` | ✅ |
|
||||
| P1 | revision 过期检查 | `hermes_tools_markdown_edit_online_page_body_save_carries_revision_conflict_key` | ✅ |
|
||||
| P2 | 原始块 ID 消失保留 | `test_build_page_content_preserves_missing_original_text_block_when_some_ids_remain` | ✅ |
|
||||
| P2 | 空 operations | `hermes_tools_markdown_edit_rejects_no_applied_operations` | ✅ |
|
||||
|
||||
## 3. 开放问题状态
|
||||
|
||||
| 开放问题 | 当前状态 |
|
||||
|----------|----------|
|
||||
| OQ1:`<!-- block:id:type:rev -->` 被 search/replace 破坏 | `extract_block_comment` 在解析不完整注释时返回 `(None, None)`,标记为 `is_new=true`,安全降级 |
|
||||
| OQ2:full_content 块类型从 GFM 前缀推断 | `detect_block_type_from_prefix` 支持 heading/todo/paragraph,代码块等交由 fallback 处理 |
|
||||
| OQ3:行内格式保持 | `update_legacy_block_text_for_markdown_edit` + `replace_single_inline_text_value` 在文本不变时保留 marks,改变时更新 text 字段 |
|
||||
|
||||
## 4. 验证结果
|
||||
|
||||
```
|
||||
$ cargo test -p mnote-web markdown_edit -- --test-threads=1
|
||||
16 passed; 0 failed
|
||||
|
||||
$ cargo test -p mnote-web hermes_tools_manifest_describes_markdown_edit_write_contract -- --test-threads=1
|
||||
1 passed; 0 failed
|
||||
|
||||
$ git diff --check
|
||||
无冲突标记
|
||||
```
|
||||
|
||||
## 5. 结论:可归档
|
||||
|
||||
**归档条件全部满足:**
|
||||
- 步骤 1-6 全部实现 ✅
|
||||
- P0/P1 测试矩阵全部通过 ✅
|
||||
- 旧代码已标记退役 ✅
|
||||
- 命名管道的 reason 字段包含 `"mnote.doc.markdown_edit (7-27)"` ✅
|
||||
- 开放问题均为已知边界,不需要阻碍归档
|
||||
|
||||
## 6. 执行操作
|
||||
|
||||
将 `design/07-ai/process/7-27-online-markdown-writeback-final-content-truth-v2.md` 移动到 `design/07-ai/done/`。
|
||||
@@ -0,0 +1,157 @@
|
||||
# Worker B:7-27 代码/测试缺口审查
|
||||
|
||||
> 审查时间:2026-05-20
|
||||
> 审查范围:`doc.rs` + `hermes_tools.rs` + `manifest.rs`
|
||||
> 分级:🟢 已满足 / 🟡 可作为后续增强 / 🔴 必须修复才能归档
|
||||
|
||||
---
|
||||
|
||||
## 检查点 1:`blocks_to_markdown` 是否能从 legacy `content`/`contentNodes` 读取文本
|
||||
|
||||
**结论:🟢 已满足**
|
||||
|
||||
`legacy_block_text()` 函数 (`doc.rs:973-986`) 逐级回退:
|
||||
```rust
|
||||
fn legacy_block_text(block: &Value) -> String {
|
||||
if let Some(text) = block.get("text").and_then(Value::as_str) { ... }
|
||||
if let Some(content) = block.get("content") { return inline_text_value(content); }
|
||||
if let Some(content_nodes) = block.get("contentNodes") { return inline_text_value(content_nodes); }
|
||||
}
|
||||
```
|
||||
|
||||
`block_text()` (`doc.rs:1265-1270`) 只读 `text` 字段用于 markdown 序列化,但 `build_page_content` 中的 `update_legacy_block_text_for_markdown_edit` 正确使用了 `legacy_block_text` 做比较,且写回时通过 `replace_single_inline_text_value` 递归处理 `content`/`contentNodes` 中的 `text` 字段。
|
||||
|
||||
**证据**: `inline_text_value()` (`doc.rs:988-1000`) 递归处理 Array/Object/String 三种形态。
|
||||
|
||||
---
|
||||
|
||||
## 检查点 2:注释格式是否与 7-27 文档一致,是否保留 `revisionRef`
|
||||
|
||||
**结论:🟡 可作为后续增强**
|
||||
|
||||
当前格式:
|
||||
```
|
||||
<!-- block:{id}:{type} -->
|
||||
<!-- block:{id}:{type}:level={level} --> (heading 块)
|
||||
```
|
||||
|
||||
7-27 §3.3.1 设计为:
|
||||
```
|
||||
<!-- block:{id}:{type}:{revision_ref} -->
|
||||
<!-- block:{id}:{type}:{revision_ref}:level={level} --> (with level)
|
||||
```
|
||||
|
||||
**差异**:`revisionRef` 不写入注释,而是从原始 `block.revisionRef` 读取。解析器 `extract_block_comment()` 虽然支持 `type:rev` 格式(`splitn(3, ':')` 后 `parts[2]` 可以包含 rev),但 `blocks_to_markdown` 写回时不输出 rev。
|
||||
|
||||
**影响**: 低。`revisionRef` 在整个 `build_page_content` 路径中被正确继承(`doc.rs:685-690`),只是注释里看不到。不阻碍归档,可后续增强。
|
||||
|
||||
---
|
||||
|
||||
## 检查点 3:`full_content` 是否不再被拒绝,是否保留复杂块
|
||||
|
||||
**结论:🟢 已满足**
|
||||
|
||||
- `doc_markdown_edit` 中 `full_content` 转为 `{search: current_md.trim(), replace: full.trim()}` 单个 operation,进入新路径
|
||||
- `parse_final_markdown_to_blocks` 对无注释行创建 `is_new=true` 的 paragraph 块
|
||||
- `build_page_content` 追加新块并保留原始复杂块(`is_complex_markdown_original_block`)
|
||||
- 测试 `test_build_page_content_full_content_replaces_old_text_blocks_but_keeps_complex_blocks` 验证复杂块保留
|
||||
- 集成测试 `hermes_tools_markdown_edit_online_full_content_rejects_unsafe_block_mapping` 注释确认:"7-27 修复后:full_content 不再被拒绝"
|
||||
|
||||
---
|
||||
|
||||
## 检查点 4:`dryRun` 是否不写入
|
||||
|
||||
**结论:🟢 已满足**
|
||||
|
||||
`doc_markdown_edit` 中:
|
||||
```rust
|
||||
if input.dry_run == Some(true) {
|
||||
return Ok(json!({
|
||||
"written": false,
|
||||
"dryRun": true,
|
||||
"diff": changed_blocks
|
||||
}));
|
||||
}
|
||||
```
|
||||
|
||||
本地文件路径也有独立的 `dryRun` 分支只返回预览。
|
||||
|
||||
测试 `hermes_tools_markdown_edit_local_dry_run_does_not_write` 验证。
|
||||
|
||||
---
|
||||
|
||||
## 检查点 5:selection / allowedTargetBlockIds 是否阻止越界写入
|
||||
|
||||
**结论:🟢 已满足**
|
||||
|
||||
`ensure_markdown_changed_blocks_within_allowed()` (`doc.rs:1050-1073`) 在写回前检查每个 `changedBlocks` 中的 `blockId` 是否在 `allowed_block_ids` 中。越界时返回 `mnote_markdown_edit_target_out_of_scope` 错误。
|
||||
|
||||
测试 `hermes_tools_markdown_edit_rejects_selection_out_of_scope` 验证。
|
||||
|
||||
`selected_block_ids()` (`doc.rs:1075-1094`) 从 `selectedBlockIds` / `allowedTargetBlockIds` / `selectedBlockId` / `blockId` 四个参数中收集。
|
||||
|
||||
---
|
||||
|
||||
## 检查点 6:旧 `build_block_ops_from_markdown_edit` 推导路径
|
||||
|
||||
**结论:🟢 已满足(已退役)**
|
||||
|
||||
`doc.rs:1911` 末尾注释:
|
||||
```rust
|
||||
// 退役:7-27 改为 final_md → blocks → execute_page_body_save_from_aggregate 直接写回
|
||||
```
|
||||
|
||||
函数体仍保留但不再被任何调用者引用(`doc.rs` 内只有一处调用已在步骤 4 中被替换)。可用 `cargo +nightly deadlinks` 确认死代码状态,但已足够安全。
|
||||
|
||||
---
|
||||
|
||||
## 检查点 7:测试覆盖是否足以归档
|
||||
|
||||
**结论:🟢 已满足**
|
||||
|
||||
### 单元测试覆盖(doc.rs 内)
|
||||
|
||||
| 测试 | 验证点 |
|
||||
|------|--------|
|
||||
| `test_search_replace_exact` | 精确匹配替换 |
|
||||
| `test_search_replace_normalized_chinese_byte_boundaries` | 中文忽略空白 + byte 边界保留 |
|
||||
| `test_search_replace_full_content` | 全文替换 = 全文精确匹配 |
|
||||
| `test_blocks_to_markdown_with_ids` | 块 ID 注释输出 |
|
||||
| `test_blocks_to_markdown_heading` | heading 类型 + level 注释 |
|
||||
| `test_blocks_to_markdown_complex_block_uses_raw_marker` | 复杂块 raw marker |
|
||||
| `test_build_page_content_full_content_replaces_old_text_blocks_but_keeps_complex_blocks` | full_content 新块 + 复杂块保留 |
|
||||
| `test_build_page_content_preserves_missing_original_text_block_when_some_ids_remain` | ID 消失时保留原始块 |
|
||||
| `test_build_page_content_preserves_unchanged_inline_content_nodes` | 行内 marks 保留(不变时) |
|
||||
| `test_build_page_content_preserves_single_inline_node_marks_when_text_changes` | 行内 marks 保留(文本改变时) |
|
||||
|
||||
### 集成测试覆盖(hermes_tools.rs)
|
||||
|
||||
| 测试 | 验证点 |
|
||||
|------|--------|
|
||||
| `hermes_tools_markdown_edit_online_full_content_rejects_unsafe_block_mapping` | full_content 不再拒绝 |
|
||||
| `hermes_tools_markdown_edit_merges_same_block_operations` | 同块多次操作累积 |
|
||||
| `hermes_tools_markdown_edit_maps_normalized_search_to_block` | 非精确匹配 + changedBlocks 验证 |
|
||||
| `hermes_tools_markdown_edit_online_page_body_save_carries_revision_conflict_key` | revision/conflict key 传递 |
|
||||
| `hermes_tools_markdown_edit_rejects_no_applied_operations` | 空 operations 拒绝 |
|
||||
| `hermes_tools_markdown_edit_rejects_selection_out_of_scope` | selection 越界拒绝 |
|
||||
| `hermes_tools_markdown_edit_reports_empty_block_mapping_before_apply` | 空 block mapping 错误报告 |
|
||||
| `hermes_tools_markdown_edit_shared_read_is_forbidden` | 共享文档只读拒绝 |
|
||||
| `hermes_tools_markdown_edit_local_dry_run_does_not_write` | local dryRun |
|
||||
| `hermes_tools_markdown_edit_local_folder_writes_same_markdown_file` | local folder 写入 |
|
||||
| `hermes_tools_markdown_edit_local_requires_write_contract` | local write contract 要求 |
|
||||
|
||||
### 缺口:建议后续增强(非阻塞)
|
||||
|
||||
1. **无块注释的多段 markdown 还原**:当前行级解析器假设每行一个块;多段文本(如代码块)需 GFM fallback(§5.3 有分析但未实现)
|
||||
2. **`revisionRef` 在注释中可见**:当前只在内存中保留,注释格式未输出 rev(§3.3.1 设计差异)
|
||||
3. **`build_block_ops_from_markdown_edit` 函数体删除**:当前已退役但函数体仍在文件中
|
||||
|
||||
---
|
||||
|
||||
## 总结
|
||||
|
||||
| 分级 | 数量 | 项目 |
|
||||
|------|------|------|
|
||||
| 🔴 必须修复才能归档 | 0 | — |
|
||||
| 🟡 后续增强 | 3 | 注释写 rev, GFM fallback 多段文本, 死代码体删除 |
|
||||
| 🟢 已满足 | 7/7 | 全部检查点通过 |
|
||||
@@ -0,0 +1,150 @@
|
||||
# Batch I Worker C:7-15 / 7-12 后续拆分审查
|
||||
|
||||
> 创建时间:2026-06-15
|
||||
>
|
||||
> 审查依据:`7-15` 步骤 15-17、`7-12` Phase B-F 的已完成度
|
||||
|
||||
---
|
||||
|
||||
## 1. 7-15 Steps 15-17 状态判断
|
||||
|
||||
### 当前完成度
|
||||
|
||||
| Step | 名称 | 状态 | 说明 |
|
||||
|------|------|------|------|
|
||||
| 1-14 | ACP 核心实现 | ✅ 全部完成 | `acp_client.rs`、`acp_session_manager.rs`、`acp_runtime.rs`、`acp_bridge.rs`、`reasonix-acp-wrapper.mjs`、profile 扩展、前端下拉、e2e 验证 |
|
||||
| 15 | 压力测试 | ❌ 未开始 | 多会话并发稳定性 |
|
||||
| 16 | 退役旧 HTTP proxy | 🟡 部分开始 | 默认已切 ACP,但 `hermes_client.rs` 内的 HTTP proxy 兼容分支仍存在 |
|
||||
| 17 | 基准测试 | ❌ 未开始 | Reasonix 缓存收益量化 |
|
||||
|
||||
### 结论:Steps 15-17 应拆分为独立 checklist
|
||||
|
||||
**理由:**
|
||||
|
||||
1. **性质不同** — Step 15(压力测试)和 Step 17(基准测试)是验证/度量任务,不是架构实现。Step 16(清理)是维护性工作。它们与 7-15 的核心目标(ACP 抽象层实现)没有结构性依赖。
|
||||
|
||||
2. **完成标准不同** — 压力测试可能需要多轮迭代(发现瓶颈→修复→再测),基准测试可能发现需要缓存策略调整,退役清理需要确认所有 profile 都 migrate 完。这些都不是"一个 step done 就进入下一步"的线性模式。
|
||||
|
||||
3. **已开始的部分 Step 16 不够干净** — 代码中 `configured_upstream_for_profile()` 的 `#[deprecated]` 因 warning 太多被移除,表明清理依赖范围广、风险高,需要独立计划。
|
||||
|
||||
4. **当前 7-15 文档混杂实现 + 验证** — 读文档的人会觉得 7-15 处于"未完成"状态,但实际上架构核心已经完成并在生产运行。
|
||||
|
||||
### 建议拆分方案
|
||||
|
||||
将 Steps 15-17 独立为新文件 `7-28-acp-runtime-stabilization-and-cleanup-v1.md`,在 `design/07-ai/process/` 下:
|
||||
|
||||
- **P0**:Step 16 残余 — 完成 `configured_upstream_for_profile()` HTTP proxy 分支的退役
|
||||
- **P1**:Step 15 — 压力测试,重点是 ACP 子进程生命周期管理
|
||||
- **P2**:Step 17 — 基准测试,缓存命中率对比表格
|
||||
|
||||
---
|
||||
|
||||
## 2. 7-12 Phase B-F 被覆盖状态
|
||||
|
||||
### Phase B:Manifest 合同收口
|
||||
|
||||
| 条目 | 7-12 描述 | 当前代码状态 | 覆盖评估 |
|
||||
|------|----------|-------------|---------|
|
||||
| B-1 | manifest 输出完整 `inputSchema/outputSchema/annotations/availability` | ✅ `manifest.rs` 已有完整 annotations、inputSchema、parameters | 已覆盖。每个工具包含 `annotations.readonly/destructive/idempotent/requiresApproval/approvalMode/runtimeOwner/writeOwner/selectionEffect` |
|
||||
| B-2 | profile toggle、capability、scope 共同影响 manifest | 🟡 部分 | `capabilityScope` 已在 manifest 中,但 profile-level toggle 未动态反映到 `availability.enabled` 字段 |
|
||||
| B-3 | manifest 可直接转换为 Hermes/model tools | ✅ 前端 SSR 直接消费 manifest 作为工具列表 | 已覆盖。manifest 结构已与 Hermes 兼容 |
|
||||
| B-4 | 禁用工具在 manifest、UI、执行拦截三处一致 | 🟡 部分 | 执行拦截通过 `capabilityScope` + 后端 `ensure_markdown_changed_blocks_within_allowed` 存在,但 UI 侧 toggle 反映需验证 |
|
||||
|
||||
**结论:** Phase B 大部分被当前代码覆盖。B-2 和 B-4 的核心缺口是 profile-level dynamic availability,而不是 manifest 内容。
|
||||
|
||||
### Phase C:`block-edit-workflow` 改造成 router
|
||||
|
||||
| 条目 | 7-12 描述 | 当前代码状态 | 覆盖评估 |
|
||||
|------|----------|-------------|---------|
|
||||
| C-1 | route 命名和返回 schema 改为 `mnote.page_ai_command_route.v1` | ❌ 未实施 | `page_ai_workflow.rs` 仍在用内部 `MarkdownPlan` 对象,没有公开的 `PageAICommandRouter` route |
|
||||
| C-2 | 本地规则只输出 `recommendedToolCall` | 🟡 间接覆盖 | `page_ai_workflow.rs` 中的 `direct_block_edit_operations` 已退役,改走 model → search/replace → `doc_markdown_edit` 路径 |
|
||||
| C-3 | 低风险 yolo shortcut 走共享 mnote tool executor | ✅ 当前路径 | `doc_markdown_edit` 直接调用 Rust tool executor |
|
||||
| C-4 | 非低风险任务发起 Hermes run with tool hint | ✅ ACP integration | `acp_runtime.rs` + `acp_session_manager.rs` 提供完整的 Hermes/Reasonix run 路径 |
|
||||
| C-5 | 删除"模型 fallback 后再 Hermes agent run"重复链路 | 🟡 需确认 | `page_ai_workflow.rs` 中的 `call_block_edit_model` → `extract_markdown_plan` 链路仍然存在,但已改为直接走 `doc_markdown_edit` 不回落 |
|
||||
|
||||
**结论:** Phase C 的架构目标(agent-native 编辑 > mnote block ops)已通过 ACP + local-first 口径实现,但正式的 `PageAICommandRouter` 模块从未实现。不需要再实现它——当前架构已满足 7-12 的安全合同目标。
|
||||
|
||||
### Phase D:Review Session
|
||||
|
||||
| 条目 | 7-12 描述 | 当前代码状态 | 覆盖评估 |
|
||||
|------|----------|-------------|---------|
|
||||
| D-1 | schema 和状态机边界 | ✅ 文档已定义 | 设计文档 §5.5 已完成 |
|
||||
| D-2 | `plan_update`/`apply_block_ops dryRun=true` 返回 review-compatible draft | 🟡 部分 | dryRun 支持存在且返回 diff/warnings/risk/blocked,但输出格式不是 review session schema |
|
||||
| D-3 | UI 展示 diff/warnings/risk/blocked | ❌ **冻结** | Phase C 仍冻结,不实施 |
|
||||
| D-4 | accept/reject/retry/abort | ❌ **冻结** | 同上 |
|
||||
| D-5 | stale revision 阻断 | ✅ 部分 | `ensure_markdown_changed_blocks_within_allowed` + revision 检查 |
|
||||
|
||||
**结论:** 符合 7-12 §0 的指示——"Phase C UI 仍冻结,不实施流式 apply 或新的审阅 UI"。本报告不建议本轮实现。
|
||||
|
||||
### Phase E:状态与事件统一
|
||||
|
||||
| 条目 | 7-12 描述 | 覆盖评估 |
|
||||
|------|----------|---------|
|
||||
| E-1 | direct shortcut 和 Hermes run 统一 tool event 形态 | ✅ ACP `session/update` 作为统一事件源 |
|
||||
| E-2 | 页面 AI 面板按 `runId/toolCallId/reviewSessionId` 聚合 | 🟡 前端已支持 runId/toolCallId,reviewSessionId 未用 |
|
||||
| E-3 | abort 不留下半写入正文 | ✅ ACP `session/cancel` + 本地回滚 |
|
||||
| E-4 | 刷新后未提交 review session 不自动写入 | ✅ 不适用(review session 未实现) |
|
||||
|
||||
### Phase F:验收 Smoke
|
||||
|
||||
| 条目 | 7-12 描述 | 覆盖评估 |
|
||||
|------|----------|---------|
|
||||
| F-1 | 低歧义替换 <1s 且 tool audit | 🟡 功能存在,具体延迟需要基准测试(Step 17) |
|
||||
| F-2 | 复杂改写进 Hermes run,先 dry-run/review | ✅ ACP 路径支持 |
|
||||
| F-3 | selection 外写入 blocked | ✅ `hermes_tools_markdown_edit_rejects_selection_out_of_scope` 测试 pass |
|
||||
| F-4 | 禁用工具一致 | 🟡 后端拦截存在,manifest 动态 toggle 待完善 |
|
||||
| F-5 | 旧 revision accept → stale | ❌ review session 未实现,此场景不存在 |
|
||||
|
||||
---
|
||||
|
||||
## 3. Phase C Review Mode 冻结确认
|
||||
|
||||
**确认冻结。** 符合 7-12 §0 的 2026-05-18 更新:
|
||||
|
||||
> `PageAIReviewSession` 只定义 Phase C 的安全合同和状态机边界;当前 Phase C 仍冻结,不实施流式 apply 或新的审阅 UI
|
||||
|
||||
由于 review mode UI 涉及:
|
||||
1. 新的前端组件(diff 面板、accept/reject/retry/abort 按钮)
|
||||
2. 新的后端 session 持久化路径
|
||||
3. 与 ACP session 的生命周期整合(review session 超时、刷新恢复)
|
||||
4. `thought.delta` / `usage.updated` 的可视化渲染
|
||||
|
||||
这些都不在本轮范围内。所有 review-compatible 的后端数据结构(dryRun、changedBlocks、audit)已准备就绪,仅差 UI 整合。
|
||||
|
||||
---
|
||||
|
||||
## 4. 下一批 P0/P1/P2 优先级
|
||||
|
||||
### P0(本轮必须完成)
|
||||
|
||||
| 编号 | 工作 | 对应 | 风险 |
|
||||
|------|------|------|------|
|
||||
| P0-1 | 完成 `configured_upstream_for_profile()` 的 HTTP proxy 清理 | 7-15 Step 16 残余 | 低。当前默认已切 ACP,但 `hermes_client.rs` 中 ~500 行 HTTP proxy 路径仍有调用者确认 |
|
||||
| P0-2 | 确认 `page_ai_workflow.rs` 在所有 profile 下不走 block_edit fallback | 7-12 C-5 | 中。当前 workflow 调 `call_block_edit_model` → `extract_markdown_plan` → `doc_markdown_edit`,但少部分 code path 可能还有残留的 `apply_block_ops` |
|
||||
| P0-3 | `7-15` 拆分为「核心实现」(done) + 「稳定化清单」(new) | 本审查结论 | 低。只改设计文档 |
|
||||
|
||||
### P1(紧接 P0 后)
|
||||
|
||||
| 编号 | 工作 | 对应 | 风险 |
|
||||
|------|------|------|------|
|
||||
| P1-1 | 压力测试:多会话并发、ACP 子进程异常恢复 | 7-15 Step 15 | 中。需要同时管理 3+ 会话时 Hermes/Reasonix 子进程状态 |
|
||||
| P1-2 | 动态 tool availability per profile(manifest 的 `enabled` 字段) | 7-12 B-2/B-4 | 中低。影响 tool toggle/audit 一致性 |
|
||||
| P1-3 | `plan_update` dryRun 输出适配 review session schema | 7-12 D-2 | 低。后端数据结构对齐 |
|
||||
|
||||
### P2(可并行但非阻塞)
|
||||
|
||||
| 编号 | 工作 | 对应 | 风险 |
|
||||
|------|------|------|------|
|
||||
| P2-1 | 基准测试:Reasonix cache hit rate vs Hermes | 7-15 Step 17 | 低。纯度量,不涉及代码变更 |
|
||||
| P2-2 | `7-12` 更新状态:标记 Phase B 已完成项、更新口径 | 设计治理 | 低 |
|
||||
| P2-3 | 复杂块 GFM 解析 fallback 覆盖(list/code block/blockquote) | 7-27 §5.3 | 低。影响 full_content 块类型推断 |
|
||||
| P2-4 | 页面 AI `thought.delta` 可视化 | 7-15 Step 11 note | 低。当前预期行为是不显示 thought |
|
||||
|
||||
---
|
||||
|
||||
## 5. 验收证据
|
||||
|
||||
- `cargo test -p mnote-web markdown_edit -- --test-threads=1` → 16 pass
|
||||
- `cargo test -p mnote-web hermes_tools_manifest_describes_markdown_edit_write_contract -- --test-threads=1` → 1 pass
|
||||
- `git diff --check` → 无 whitespace 错误
|
||||
- 本文件已写入 `.codex/reasonix-tasks/results/batch-i-worker-c-acp-review-tail.md`
|
||||
@@ -0,0 +1,132 @@
|
||||
# Batch J Worker A:旧 HTTP proxy / page AI fallback 调用链审查
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 只读审查,不修改代码。
|
||||
|
||||
## 1. 读取过的关键文件
|
||||
|
||||
| 文件 | 行数 | 内容 |
|
||||
|------|------|------|
|
||||
| `rust/crates/mnote-web/src/routes/hermes_client.rs` | 8202 | 首页面 AI Hermes 路由:session/run/tool 的 proxy 和 ACP 双路径 |
|
||||
| `rust/crates/mnote-web/src/page_ai_workflow.rs` | — | **不存在**(不在根目录,在 `routes/` 下) |
|
||||
| `rust/crates/mnote-web/src/routes/page_ai_workflow.rs` | 500+ | 页面 AI block-edit fast path |
|
||||
| `rust/crates/mnote-web/src/acp_runtime.rs` | 500+ | ACP runtime manager |
|
||||
| `rust/crates/mnote-web/src/acp_session_manager.rs` | 700+ | ACP session lifecycle |
|
||||
| `rust/crates/mnote-web/src/routes/mod.rs` | 200+ | 全路线由注册 |
|
||||
| `rust/crates/mnote-web/src/routes/compat.rs` | 200+ | 旧 `/api/ai-agent/run` 退役 guard |
|
||||
|
||||
## 2. 调用链分析
|
||||
|
||||
### 2.1 旧 HTTP proxy 路径
|
||||
|
||||
**判断函数:** `hermes_client.rs:2844` `hermes_http_proxy_enabled()`
|
||||
|
||||
```rust
|
||||
fn hermes_http_proxy_enabled() -> bool {
|
||||
["MNOTE_WEB_ENABLE_HERMES_HTTP_PROXY", "MNOTE_ENABLE_HERMES_HTTP_PROXY"]
|
||||
.into_iter().find_map(env_or_dotenv)
|
||||
.map(|v| matches!(v.trim().to_ascii_lowercase(), "1" | "true" | "yes"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
```
|
||||
|
||||
**默认关闭**(`unwrap_or(false)`)。HTTP proxy 仅在显式设 `MNOTE_WEB_ENABLE_HERMES_HTTP_PROXY=true` 时启用。
|
||||
|
||||
**上游 URL 来源:** `configured_upstream()`(`hermes_client.rs:2813`)
|
||||
|
||||
- 检查 `MNOTE_WEB_HERMES_UPSTREAM_URL` → `MNOTE_HERMES_UPSTREAM_URL` → `MNOTE_HERMES_API_BASE_URL`
|
||||
- 均不存在时返回 `None`
|
||||
|
||||
**`is_acp_profile()` 路由逻辑**(`hermes_client.rs:2871`):
|
||||
|
||||
```rust
|
||||
fn is_acp_profile(profile: &str) -> bool {
|
||||
if !hermes_http_proxy_enabled() { return true; } // 默认全走 ACP
|
||||
if profile == "reasonix" || profile == "hermes" { return true; }
|
||||
// 还可通过 MNOTE_WEB_{PROFILE}_RUNTIME_TYPE=acp 环境变量控制
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 各路由入口分类
|
||||
|
||||
| Route | Handler | HTTP proxy 条件 | 默认走 | 分类 |
|
||||
|-------|---------|-----------------|--------|------|
|
||||
| `GET /client/sessions` | `list_sessions` | `!is_acp_profile(profile) && configured_upstream_for_profile(profile).is_some()` | **ACP** | `compat` |
|
||||
| `GET /client/sessions/search` | `search_sessions` | 同上 | **ACP** | `compat` |
|
||||
| `GET /client/gateway/health` | `gateway_health` | `!is_acp_profile(&profile)` → HTTP proxy | **ACP**(对于非 ACP profile 走 HTTP proxy) | `compat` |
|
||||
| `POST /client/runs` | `create_run` | `configured_upstream_for_profile(®istration.profile).is_some()` | **ACP** | `compat` |
|
||||
| `GET /client/events/{run_id}` | `stream_events` | 先查 `acp_runtime_for_run()`,再 fallback `configured_upstream_for_profile()` | **ACP** | `compat` |
|
||||
| `POST /client/runs/{run_id}/abort` | `abort_run` | 同上 | **ACP** | `compat` |
|
||||
| `GET /client/models` | `list_models` | 直接 `configured_upstream()` | HTTP proxy(与 ACP 无关的 model 列表) | `compat` |
|
||||
| 队列自动处理 | `auto_start_next_queued_run`(line 5377) | `configured_upstream_for_profile(queued.profile)` | **ACP** | `compat` |
|
||||
| `POST /api/ai-agent/run` | `compat::next_ai_agent_run` | — | **始终返回 410 GONE** | `retired` |
|
||||
| `POST /api/page-ai/block-edit-workflow` | `page_ai_workflow::block_edit_workflow` | 绕过 ACP,直接调模型 API + `execute_mnote_tool_call` | debug-only fast path | `debug-only` |
|
||||
|
||||
### 2.3 page_ai_workflow 是否绕过 ACP / tool executor?
|
||||
|
||||
**调用链:**
|
||||
|
||||
```
|
||||
POST /api/page-ai/block-edit-workflow
|
||||
→ looks_like_block_edit(message) ← 中文关键词匹配
|
||||
→ call_block_edit_model() ← 直调 DeepSeek/etc API(HTTP)
|
||||
→ extract_markdown_plan_from_model_text()
|
||||
→ 构造 ToolCallInput { tool_name: "mnote.doc.markdown_edit", capability_scope: ["block.write","page.write"], ... }
|
||||
→ hermes_tools::execute_mnote_tool_call() ← 共享 tool executor
|
||||
→ is_mnote_tool_disabled() & ensure_write_authorized() & 实际执行
|
||||
```
|
||||
|
||||
**结论:**
|
||||
|
||||
1. **不经过旧 HTTP proxy** ✓ — 没有调用 `configured_upstream_for_profile`
|
||||
2. **不经过 ACP session manager** — 直接调用 `execute_mnote_tool_call`,没有 `session/new` + `session/prompt` 生命周期
|
||||
3. **但经过共享 tool executor** — 受 `is_mnote_tool_disabled()`、`ensure_write_authorized()`、`is_shared_read_scope()` 等守卫保护
|
||||
4. **设计意图**:`7-15` 设计文档说明 "local-first 普通正文编辑默认不经过它",该路径是给合模型快速做 search/replace 块编辑的 fast path,不是常规 AI 执行路径
|
||||
|
||||
### 2.4 `compat::next_ai_agent_run` 状态
|
||||
|
||||
`routes/compat.rs:10` 的 `next_ai_agent_run()` 始终返回 `410 GONE` + 消息"旧 /api/ai-agent/run 页面 AI 主链已退场"。**已确认退役**,无 P0 风险。
|
||||
|
||||
## 3. 各入口分类汇总
|
||||
|
||||
| 分类 | 条目 | 说明 |
|
||||
|------|------|------|
|
||||
| `default` | 无 | HTTP proxy 默认关闭;ACP 是默认 runtime |
|
||||
| `compat` | `list_sessions`, `search_sessions`, `gateway_health`, `create_run`, `stream_events`, `abort_run`, `list_models`, 队列处理 | 仅当 `MNOTE_WEB_ENABLE_HERMES_HTTP_PROXY=true` 时激活;不影响正常用户 |
|
||||
| `debug-only` | `page_ai_workflow::block_edit_workflow` | bypass ACP session,但受工具 executor 守卫保护 |
|
||||
| `retired` | `compat::next_ai_agent_run` | 已返回 410,无降级路径 |
|
||||
| `未被调用` | `configured_runtime_for_profile()`(line 3368) | 标记 `#[allow(dead_code)]` |
|
||||
|
||||
## 4. P0 缺口评估
|
||||
|
||||
**当前没有 P0 必须修复的缺口。**
|
||||
|
||||
理由:
|
||||
1. HTTP proxy 默认关闭(`hermes_http_proxy_enabled() = false`)
|
||||
2. `compat::next_ai_agent_run` 已正确返回 410
|
||||
3. `page_ai_workflow` 经过共享 tool executor 守卫,不绕过权限检查
|
||||
4. 所有路由的第一分支都是 ACP
|
||||
|
||||
## 5. 建议的后续修改范围
|
||||
|
||||
| 项 | 建议 | 紧急程度 |
|
||||
|----|------|---------|
|
||||
| HTTP proxy 完整退役 | 删除 `configured_upstream()` / `configured_upstream_for_profile()` / `proxy_json()` 相关代码 | P2(cleanup) |
|
||||
| `list_models` 从 HTTP proxy 迁移 | 改为 ACP 的 `session/initialize` 返回 model 信息 | P2(依赖 ACP 协议增强) |
|
||||
| `page_ai_workflow` 检查驱动 | 确保测试覆盖其 bypass ACP session 的行为的非期望路径(`task-page-block-ai-smoke.js` → 已存在) | 已有 |
|
||||
| 旧环境变量清理 | 文档标记 `MNOTE_WEB_HERMES_UPSTREAM_URL` 等为退役 | P2 |
|
||||
|
||||
## 6. 建议测试
|
||||
|
||||
```
|
||||
# 确认 HTTP proxy 默认关闭(infra 测试)
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web hermes_http_proxy -- --test-threads=1
|
||||
|
||||
# 确认 compat 路由返回 410(已存在)
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web direct_ai_agent_run_returns_legacy_retired_guard -- --test-threads=1
|
||||
|
||||
# 确认 page_ai_workflow 受守卫保护(已存在)
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web block_edit_workflow_respects_disabled_markdown_edit_tool -- --test-threads=1
|
||||
```
|
||||
@@ -0,0 +1,182 @@
|
||||
# Batch J Worker B:tool availability 三处一致性审查
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 只读审查,不修改代码。
|
||||
|
||||
## 1. 读取过的关键文件
|
||||
|
||||
| 文件 | 行数 | 内容 |
|
||||
|------|------|------|
|
||||
| `rust/crates/mnote-web/src/hermes_tools/manifest.rs` | 400+ | Tool 定义:name、description、`status`、`capabilityScope`、`annotations` |
|
||||
| `rust/crates/mnote-web/src/hermes_tools/mod.rs` | 280+ | `ToolCallInput` 结构体 + `ensure_write_authorized()` 守卫 |
|
||||
| `rust/crates/mnote-web/src/routes/hermes_tools.rs` | 3691 | `execute_mnote_tool_call()` — 入口 + 工具分派 |
|
||||
| `rust/crates/mnote-web/src/routes/hermes_client.rs` (L2247-2302) | ~55 | `disabled_mnote_tools()`, `mnote_tools_payload()`, `mnote_tool_entry()` |
|
||||
| `rust/crates/mnote-web/src/ssr/pages/layout.rs` (L50, L6346-6390, L6895-6990) | ~100 | `pageAiTools` 状态、`pageAiNormalizeTools()`、tool 渲染 |
|
||||
|
||||
## 2. Manifect / UI / Execute guard 能力判断来源
|
||||
|
||||
### 2.1 Manifect(`hermes_tools/manifest.rs`)
|
||||
|
||||
```rust
|
||||
// 每个工具定义包含:
|
||||
{
|
||||
"name": "mnote.doc.fetch",
|
||||
"description": "读取当前页面的 canonical block projection...",
|
||||
"schemaVersion": TOOL_SCHEMA_VERSION,
|
||||
"capabilityScope": ["page.read"], // 需要的权限声明
|
||||
"status": "available", // 静态 availability
|
||||
"annotations": tool_annotations(true, false, true, false)
|
||||
// readonly, destructive, idempotent, requires_approval
|
||||
}
|
||||
```
|
||||
|
||||
关键缺陷:
|
||||
- `page_get_tool()` 和 `page_save_tool()` **没有设置 `annotations` 字段**
|
||||
- `available_tool()` 创建的条目也没有 `annotations`
|
||||
- `status` 字段全部硬编码为 `"available"`(无动态 availability)
|
||||
|
||||
### 2.2 Tool 列表服务端(`hermes_client.rs:2258` `mnote_tools_payload()`)
|
||||
|
||||
```
|
||||
manifest::manifest() ← 静态 manifest
|
||||
↓
|
||||
disabled_mnote_tools(profile) ← 从 profile 配置 YAML 读取 mnote.tools.disabled 列表
|
||||
↓
|
||||
mnote_tool_entry(tool, &disabled) ← 若 tool.name ∈ disabled,设 status=disabled, enabled=false
|
||||
↓
|
||||
返回给前端
|
||||
```
|
||||
|
||||
**disabled 来源:** `disabled_mnote_tools(profile)`(`hermes_client.rs:2247`)
|
||||
|
||||
```rust
|
||||
pub(crate) fn disabled_mnote_tools(profile: &str) -> Vec<String> {
|
||||
let content = fs::read_to_string(profile_config_path(profile)).unwrap_or_default();
|
||||
yaml_disabled_list(&content, &["mnote", "tools", "disabled"])
|
||||
}
|
||||
```
|
||||
|
||||
从 Hermes profile YAML 的 `mnote.tools.disabled` 键下读取禁用列表。
|
||||
|
||||
### 2.3 UI(`layout.rs`)
|
||||
|
||||
工具列表渲染链路:
|
||||
|
||||
```
|
||||
fetch('/api/hermes/client/tools?scope=mnote&profile=' + profile)
|
||||
↓
|
||||
pageAiNormalizeTools(payload)
|
||||
↓ 提取: name, description, scope, status, enabled, unavailableReason
|
||||
↓
|
||||
renderPageAiControls()
|
||||
↓ 渲染 tool row: name + scope + status + toggle button
|
||||
toggle 状态: tool.enabled !== false → aria-pressed + is-on CSS
|
||||
```
|
||||
|
||||
UI 对所有工具平等渲染,**不隐藏 disabled 工具**(只显示 switching 开关 + `"当前 Hermes profile 已关闭该 mnote tool"` 提示)。前端不做任何独立的 capability 判断。
|
||||
|
||||
### 2.4 Execute guard(`hermes_tools.rs:219` + `mod.rs` `ensure_write_authorized()`)
|
||||
|
||||
守卫有两层:
|
||||
|
||||
**第一层**(`hermes_tools.rs:219` — `execute_mnote_tool_call()` 入口):
|
||||
|
||||
```rust
|
||||
if hermes_client::is_mnote_tool_disabled(&profile, &input.tool_name) {
|
||||
return Err(403 "mnote_tool_disabled")
|
||||
}
|
||||
```
|
||||
|
||||
**同源**:与 listing 端调用同一个 `is_mnote_tool_disabled()` → `disabled_mnote_tools()`。
|
||||
|
||||
**第二层**(`mod.rs:186` — `ensure_write_authorized()` 在具体 tool handler 中调用):
|
||||
|
||||
```rust
|
||||
pub fn ensure_write_authorized(context: &RequestContext, input: &ToolCallInput) -> Result<(), WebError> {
|
||||
// 1. idempotencyKey 必须存在
|
||||
// 2. dryRun 必须显式携带
|
||||
// 3. aiAccessScope.permissionLevel 不能是只读
|
||||
// 4. CommandContextBridge.ai_can_write ≠ false
|
||||
// 5. CommandContextBridge.workspace_readonly ≠ true
|
||||
}
|
||||
```
|
||||
|
||||
这层不涉及 manifest 的 capabilityScope。
|
||||
|
||||
**第三层**(`hermes_tools.rs:242` — shared read 检查):
|
||||
|
||||
```rust
|
||||
if !dry_run && !is_read_tool(&input.tool_name) && is_shared_read_scope(&input) {
|
||||
return Err(403 "mnote_tool_shared_read_write_forbidden")
|
||||
}
|
||||
```
|
||||
|
||||
通过 `aiAccessScope.permissionLevel` 判断共享只读。
|
||||
|
||||
## 3. 三处是否同源
|
||||
|
||||
### 3.1 Disabled 列表:✅ 完全同源
|
||||
|
||||
| 层 | 判断 | 来源 |
|
||||
|----|------|------|
|
||||
| Manifect | 无动态 disabled(static) | — |
|
||||
| Listing | `disabled_mnote_tools(profile)` | profile YAML `mnote.tools.disabled` |
|
||||
| UI | 接收 `enabled` 字段 | 来自 listing endpoint |
|
||||
| Execute guard | `is_mnote_tool_disabled(profile, name)` | 同一 `disabled_mnote_tools()` |
|
||||
|
||||
所有层在"哪些工具被禁用"上使用同一数据源(Hermes profile YAML)。
|
||||
|
||||
### 3.2 capabilityScope 执行:⚠️ 不同源(P1)
|
||||
|
||||
| 层 | capabilityScope 用法 | 角色 |
|
||||
|----|---------------------|------|
|
||||
| Manifect | 每个工具声明 `capabilityScope: ["page.read"]` 或 `["page.write"]` | **文档性** — 告诉 AI agent 需要什么权限 |
|
||||
| Listing | 转发 `capabilityScope` 到 UI | **展示性** |
|
||||
| UI | 不消费 `capabilityScope` 做判据 | **不展示权限要求** |
|
||||
| Execute guard | **不检查** `input.capability_scope` 与 manifest scope 的匹配 | **未执行** |
|
||||
|
||||
**关键缺口**:manifect 声明了工具需要的权限范围(`page.read` / `page.write` / `block.write` 等),但 execute guard 没有验证调用方声明的 `capability_scope` 是否包含目标工具所需的 scope。
|
||||
|
||||
`ToolCallInput.capability_scope` 虽存在于结构体中,但只做:
|
||||
1. 传递给具体 tool handler 作为 `RuntimeTargetWire.capabilities`(artifact.rs:187, block.rs:1136, page.rs:279)
|
||||
2. 记录到 audit 日志(hermes_tools.rs:433)
|
||||
3. 由 `page_ai_workflow.rs:130` 在调用时手动设置 `capability_scope: Some(vec!["block.write".into(), "page.write".into()])`
|
||||
|
||||
无中心守卫验证 `input.capability_scope` 与 manifest 中该 tool 的 `capabilityScope` 的包含关系。
|
||||
|
||||
## 4. P0/P1/P2 分级缺口
|
||||
|
||||
### P0:无
|
||||
|
||||
disabled 工具在三层间保持一致,没有安全绕过。
|
||||
|
||||
### P1:capabilityScope 未在 execute guard 强制执行
|
||||
|
||||
- **漏洞描述**:Agent 可以声明 `capability_scope: ["page.read"]`,但仍然调用 `mnote.page.save`(写工具)。守卫只检查 `is_shared_read_scope`(看 `aiAccessScope.permissionLevel`)和 `is_read_tool`(看硬编码列表),不检查 manifest 声明的 scope。
|
||||
- **影响**:低(不构成安全漏洞,因为还有 `aiAccessScope.permissionLevel` + 文件系统权限 + 授权 root 三层兜底),但 manifests 声明的 scope 信息完全浪费。
|
||||
- **修复建议**:在 `execute_mnote_tool_call()` 中,校验 `input.capability_scope` 是否覆盖 manifest 中该工具的 `capabilityScope`。
|
||||
|
||||
### P2:Manifest 元数据不完整
|
||||
|
||||
| 缺陷 | 位置 | 说明 |
|
||||
|------|------|------|
|
||||
| `page_get_tool()` 缺 `annotations` | `manifest.rs` 末尾 | 没有 `readonly`/`destructive` 标记 |
|
||||
| `page_save_tool()` 缺 `annotations` | `manifest.rs` 末尾 | 同上 |
|
||||
| `available_tool()` 创建的工具缺 `annotations` | `manifest.rs` | `mnote.page.update_title`, `mnote.page.update_options`, `mnote.artifact.create_summary`, `mnote.artifact.create_ai_note` |
|
||||
| `status` 字段全部硬编码 | `manifest.rs` | 无动态 availability;manifect 不含 disabled 状态(在 listing 层叠加) |
|
||||
| 前端 UI 不展示 `capabilityScope` | `layout.rs:6346-6380` | `pageAiNormalizeTools` 解析但不消费,渲染时不显示权限要求 |
|
||||
|
||||
## 5. 建议的最小测试
|
||||
|
||||
```bash
|
||||
# 已有:disabled tool 被 execute guard 拒绝
|
||||
cargo test -p mnote-web block_edit_workflow_respects_disabled_markdown_edit_tool
|
||||
|
||||
# 已有:write guard 检查(aiAccessScope、idempotencyKey)
|
||||
cargo test -p mnote-web ensure_write_authorized
|
||||
|
||||
# 新增建议:capability_scope 校验测试
|
||||
# 位置:hermes_tools/mod.rs tests
|
||||
# 内容:构造 ToolCallInput { capability_scope: ["page.read"] } 调用 mnote.page.save,期望被拒绝
|
||||
```
|
||||
@@ -0,0 +1,217 @@
|
||||
# Batch J Worker C:ACP 稳定性与 benchmark checklist 草案
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 只读审查,不修改代码。
|
||||
|
||||
## 1. 读取过的关键文件
|
||||
|
||||
| 文件 | 行数 | 内容 |
|
||||
|------|------|------|
|
||||
| `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md` | 1029 | ACP 统一层设计:架构、协议、session lifecycle |
|
||||
| `design/07-ai/process/7-34-acp-runtime-cleanup-availability-stability-tail-v1.md`| 300+ | 本任务上游:P0/P1/P2 checklist |
|
||||
| `design/07-ai/done/7-25-acp-session-runtime-enhancement-plan-v1.md` | 371 | Session 持久化与管理增强规划 |
|
||||
| `design/07-ai/done/7-30-acp-session-load-resume-checklist-v1.md` | ~80 | `session/load` 闭环已归档 |
|
||||
| `design/07-ai/done/7-31-acp-permission-decision-loop-checklist-v1.md` | ~80 | Permission 决策闭环已归档 |
|
||||
| `design/07-ai/done/7-32-acp-tool-location-and-open-action-checklist-v1.md` | ~80 | Tool locations + open action 已归档 |
|
||||
| `design/07-ai/done/7-33-acp-session-info-plan-ui-checklist-v1.md` | ~80 | Session info + plan UI 已归档 |
|
||||
| `rust/crates/mnote-web/src/acp_runtime.rs` | 500+ | Runtime lifecycle manager |
|
||||
| `rust/crates/mnote-web/src/acp_session_manager.rs` | 700+ | Session lifecycle + event dispatch |
|
||||
| `rust/crates/mnote-web/src/acp_bridge.rs` | 400+ | ACP ↔ SSE bridge |
|
||||
| `rust/crates/mnote-web/src/acp_client.rs` | 746 | JSON-RPC 2.0 client |
|
||||
| `rust/crates/mnote-web/src/acp_types.rs` | 800 | ACP 协议类型定义 |
|
||||
|
||||
## 2. ACP 多会话稳定性 smoke 最小脚本方案
|
||||
|
||||
### 2.1 测试目标
|
||||
|
||||
验证 ACP runtime 在处理 3+ 并发 session 时的稳定性:session 创建、prompt 流式、cancel、子进程异常恢复、事件去重。
|
||||
|
||||
### 2.2 测试设计
|
||||
|
||||
**方案类型**:Playwright 独立脚本 + Rust 端到端测试
|
||||
|
||||
**输入**:
|
||||
1. 3 个参数化的 ACP run profile(reasonix + hermes × 2 不同 profile)
|
||||
2. 每个 session 的 prompt 文本(简单固定 prompt:"请用中文说'你好',不要做其他操作")
|
||||
3. 超时配置(每个 run 最长 15s)
|
||||
|
||||
**操作步骤**:
|
||||
|
||||
```
|
||||
Step 1: 创建 3 个 ACP session(POST /api/hermes/client/sessions)
|
||||
├─ session_1: profile=reasonix
|
||||
├─ session_2: profile=hermes (profile=mnoteai)
|
||||
└─ session_3: profile=hermes (profile=default)
|
||||
|
||||
Step 2: 在 3 个 session 上启动 run(POST /api/hermes/client/sessions/{id}/runs)
|
||||
并发发起,每个 session 间隔 ≤500ms
|
||||
|
||||
Step 3: 通过 SSE 流式读取事件(GET /api/hermes/client/events/{run_id})
|
||||
对每个 run 读取到 run.completed 或超时 15s
|
||||
记录:message.delta 事件数量、tool.started、tool.completed
|
||||
|
||||
Step 4: cancel 验证
|
||||
Step 2 后立即 cancel session_2(POST /api/hermes/client/runs/{run_id}/abort)
|
||||
验证收到 run.failed / abort.completed
|
||||
|
||||
Step 5: 验证事件去重
|
||||
对 session_1 的 SSE 流,检查 textDelta 的 deduplication 逻辑
|
||||
(accumulated text 不重复增长)
|
||||
|
||||
Step 6: 清理
|
||||
删除 3 个 session(DELETE /api/hermes/client/sessions/{session_id})
|
||||
```
|
||||
|
||||
**断言**:
|
||||
|
||||
| # | 断言 | 优先级 |
|
||||
|---|------|--------|
|
||||
| 1 | 3 个 session 均创建成功(返回 200 + sessionId) | P0 |
|
||||
| 2 | 3 个 run 均收到 `run.completed`(无超时) | P0 |
|
||||
| 3 | session_2 的 cancel 在 3s 内生效(收到 `run.failed` 或 `abort.completed`) | P0 |
|
||||
| 4 | 所有 SSE 流在 `run.completed` 后 500ms 内自动关闭(无泄漏) | P1 |
|
||||
| 5 | session_1 的 message.delta 累计 length 不小于 4(中文"你好") | P1 |
|
||||
| 6 | 事件去重正常:textDelta 无重复或突然截断 | P1 |
|
||||
| 7 | 3 个 session 互相不干扰(事件不交叉) | P1 |
|
||||
| 8 | ACP 子进程数 = session 数(无 zombie) | P2(度量) |
|
||||
|
||||
**证据文件**:
|
||||
- `artifacts/acp-stability/events-session-1.jsonl`
|
||||
- `artifacts/acp-stability/events-session-2.jsonl`
|
||||
- `artifacts/acp-stability/events-session-3.jsonl`
|
||||
- `artifacts/acp-stability/runtime-metrics.json`
|
||||
- `artifacts/acp-stability/process-list.txt`(`ps aux | grep -E 'hermes|acp'`)
|
||||
|
||||
### 2.3 浏览器可见验证点
|
||||
|
||||
1. **session 列表** — 打开页面 AI drawer → session list 应显示 3 个活跃 session
|
||||
2. **run 状态** — 每个 session 的 run 状态从 `sending` → `running` → `completed`
|
||||
3. **cancel 反馈** — 被 cancel 的 session 显示 "已请求停止" + 后续不再有 tool call
|
||||
4. **无 UI 异常** — 无 502/500 错误,无工具 manifest 加载失败
|
||||
|
||||
建议截图:
|
||||
- 3 session 同时运行的页面 AI drawer 快照
|
||||
- cancel 后的 UI 状态
|
||||
- 清理后 session 列表为空
|
||||
|
||||
## 3. Reasonix cache benchmark 最小脚本方案
|
||||
|
||||
### 3.1 测试目标
|
||||
|
||||
对比 Hermes / Reasonix 在相同 prompt 下的首次运行、二次运行(cache 命中)的耗时差异。
|
||||
|
||||
### 3.2 测试设计
|
||||
|
||||
**输入**:
|
||||
|
||||
| 维度 | 值 |
|
||||
|------|-----|
|
||||
| Prompt | "读取当前页面,列出前三段的主题"(约 20 token) |
|
||||
| 样本数 | 每 runtime × 2(cold + cached)= 4 次 |
|
||||
| Runtime | Hermes (mnoteai profile)、Reasonix |
|
||||
| 页面 | 已知内容的本地 Markdown 文档(>50 行) |
|
||||
|
||||
**操作步骤**:
|
||||
|
||||
```
|
||||
Step 1: 预热
|
||||
创建一个 ACP session(profile=reasonix),发送 prompt,等待完成,删除 session
|
||||
|
||||
Step 2: 冷启动测试(Reasonix)
|
||||
新 session(profile=reasonix)→ prompt → 计时 → 记录 total_ms
|
||||
|
||||
Step 3: Cache 命中测试(Reasonix)
|
||||
同一 session re-prompt → 计时 → 记录 total_ms
|
||||
注意:确保 prompt 内容一致,观察 response 中是否有 cache hit 提示
|
||||
|
||||
Step 4: 冷启动测试(Hermes)
|
||||
新 session(profile=hermes/mnoteai)→ prompt → 计时 → 记录 total_ms
|
||||
|
||||
Step 5: Cache 命中测试(Hermes)
|
||||
同一 session re-prompt → 计时 → 记录 total_ms
|
||||
|
||||
Step 6: 重复 Step 2-5 共 1 轮(共 8 次测量)
|
||||
```
|
||||
|
||||
**输出格式**(JSON):
|
||||
|
||||
```json
|
||||
{
|
||||
"schema": "mnote.acp_cache_benchmark.v1",
|
||||
"timestamp": "2026-05-21T12:00:00Z",
|
||||
"runs": [
|
||||
{
|
||||
"runtime": "reasonix",
|
||||
"phase": "cold",
|
||||
"trial": 1,
|
||||
"totalMs": 4230,
|
||||
"firstTokenMs": 1200,
|
||||
"completionMs": 3030,
|
||||
"toolCalls": 1,
|
||||
"messageCharCount": 85,
|
||||
"cacheHit": false
|
||||
},
|
||||
{
|
||||
"runtime": "reasonix",
|
||||
"phase": "cached",
|
||||
"trial": 1,
|
||||
"totalMs": 890,
|
||||
"firstTokenMs": 210,
|
||||
"completionMs": 680,
|
||||
"toolCalls": 1,
|
||||
"messageCharCount": 85,
|
||||
"cacheHit": true
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"reasonixColdAvgMs": 4440,
|
||||
"reasonixCachedAvgMs": 920,
|
||||
"hermesColdAvgMs": 5100,
|
||||
"hermesCachedAvgMs": 3100,
|
||||
"speedupRatio": 4.8
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 浏览器验证点
|
||||
|
||||
1. **页面 AI drawer 运行时选择器** — 切换 hermes/reasonix 时的 UI 响应
|
||||
2. **首次对话速度** — 冷启动时 UI 从 "thinking" 到首次 token 的延迟
|
||||
3. **cache 提示** — Reasonix cached run 的 tool.call/complete 速度应更快
|
||||
4. **内存观察** — 浏览器 devtools → Performance → JS heap 无异常增长
|
||||
|
||||
### 3.4 建议测试脚本存放位置
|
||||
|
||||
```
|
||||
scripts/task-acp-stability-smoke.js ← 多会话稳定性
|
||||
scripts/task-acp-cache-benchmark.js ← cache benchmark
|
||||
```
|
||||
|
||||
参考已有:`scripts/task-page-block-ai-tools-smoke.js`、`scripts/task-hermes-page-ai-baseline-smoke.js`。
|
||||
|
||||
## 4. P0 vs P2 归类
|
||||
|
||||
| 测试项 | 级别 | 理由 |
|
||||
|--------|------|------|
|
||||
| 3 个 session 创建 + 正常完成 | **P0** | 并发是基本稳定性要求 |
|
||||
| Cancel 在合理时间内生效 | **P0** | UX 基础:用户停止必须工作 |
|
||||
| SSE 流在 run 完成后关闭 | **P1** | 防止资源泄漏 |
|
||||
| 事件去重正确 | **P1** | 文本重复或截断影响 UX |
|
||||
| Session 间事件不交叉 | **P1** | 数据隔离是基本正确性 |
|
||||
| Cold vs cached 耗时对比 | **P2** | 度量性质,不影响正确性 |
|
||||
| 子进程数量 | **P2** | 度量性质 |
|
||||
| 具体第一 token 时间 | **P2** | 度量性质 |
|
||||
|
||||
## 5. 建议的现有 targeted test
|
||||
|
||||
```bash
|
||||
# 现有 ACP 单元测试(可复用)
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web acp_session_manager -- --test-threads=1
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web acp_bridge -- --test-threads=1
|
||||
cd /mnt/Data1T/mnote/rust && cargo test -p mnote-web acp -- --test-threads=1
|
||||
|
||||
# 现有 smoke 测试(参考模式)
|
||||
node scripts/task-page-block-ai-tools-smoke.js
|
||||
node scripts/task-hermes-page-ai-baseline-smoke.js
|
||||
```
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
# 1-10 [process] Batch C P1 Resource / BufferStore / GFM / Convex Evidence Checklist v1
|
||||
# 1-10 [done] Batch C P1 Resource / BufferStore / GFM / Convex Evidence Checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
@@ -6,7 +6,7 @@
|
||||
>
|
||||
> 阶段:Batch C / P1 小尾项收口
|
||||
>
|
||||
> 当前状态:`PROCESS`
|
||||
> 当前状态:`DONE`
|
||||
|
||||
## 1. 目标
|
||||
|
||||
@@ -45,7 +45,7 @@ Owner:
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/03-rust-web/process/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `design/03-rust-web/done/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
- `rust/crates/mnote-web/src/routes/web_shell.rs`
|
||||
|
||||
@@ -102,3 +102,4 @@ Codex 同步处理:
|
||||
- 2026-05-21(Reasonix Batch C Worker A):worker 只提交 resource resolver 收敛计划,未生成 `final.md` / `result.json`,无业务代码 diff;记录为 `PLAN_ONLY_TIMEOUT`,`5-26` 保持 `process`。结果文件:`.codex/reasonix-tasks/results/batch-c-worker-a-resource-open-resolver-timeout.md`。
|
||||
- 2026-05-21(Reasonix Batch C Worker B):完成 GFM AST 尾项小包,补空引用块 / 空表格单元格测试、web_shell marks 断言、写侧 Markdown 过渡注释,并更新 `3-13`;结果文件:`.codex/reasonix-tasks/results/batch-c-worker-b-gfm-tail.md`。
|
||||
- 2026-05-21(Reasonix Batch C Worker C):`task455-convex-export-plan-rollback-smoke.js` 实跑通过,覆盖 dry-run/conflict/rollback 三个行为,`1-6` Gap C1 已可视为完成。结果文件:`.codex/reasonix-tasks/results/batch-c-worker-c-convex-export-smokes.md`。
|
||||
- 2026-05-21(Codex Batch F 追认):`3-13` 已移动到 `design/03-rust-web/done/`,本文作为 Batch C 执行记录不再保持活跃 process。
|
||||
+6
-5
@@ -1,8 +1,8 @@
|
||||
# 1-12 [process] Batch E P1/P2 尾项执行 checklist v1
|
||||
# 1-12 [done] Batch E P1/P2 尾项执行 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`PROCESS`
|
||||
> 当前状态:`DONE`
|
||||
>
|
||||
> 上位入口:`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
>
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/03-rust-web/process/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `design/03-rust-web/done/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
- `rust/crates/mnote-web/src/routes/local_markdown_parser.rs`
|
||||
- `rust/crates/mnote-web/src/routes/web_shell.rs`(只读审查,不能直接修改)
|
||||
@@ -114,8 +114,8 @@ Owner:
|
||||
- [x] 运行各 worker 验收命令中与实际改动相关的 targeted tests。
|
||||
- [x] UI/browser 可见项必须由 Codex 或浏览器测试 worker 实跑复核:`task471`、`task476`、`task451` 已有实跑记录,且 `task451` 已在最新 3000 主进程上复测通过。
|
||||
- [x] 更新 `1-6`、`3-13`、本文执行记录:`1-6` 追认 buffer_state / task451 状态;`3-13` 追认 task486 改为当前主链 smoke 并复测通过。
|
||||
- [x] 可归档的文档移动到 `done/`,不能归档的保留明确未完成项:`5-26` 已归档,`3-13` 保持 process。
|
||||
- [ ] 提交前运行 `git diff --check`、`codegraph sync .`、`codegraph status`。
|
||||
- [x] 可归档的文档移动到 `done/`,不能归档的保留明确未完成项:`5-26` 已归档,`3-13` 已由 Batch F 归档到 done。
|
||||
- [x] 提交前运行 `git diff --check`、`codegraph sync .`、`codegraph status`。
|
||||
|
||||
## 5. 本轮执行记录
|
||||
|
||||
@@ -123,3 +123,4 @@ Owner:
|
||||
- 2026-05-21:Codex 建立 Batch E checklist,并准备派发 Worker A/B/C。
|
||||
- 2026-05-21:Codex 复核 `1-6` 与 `3-13` 现有 code / test 状态后,确认 `Gap A2` conflict UI 与 `Gap A7` 菜单/快捷键已落地,`Gap C1` 已完成;`Batch E` 只剩 Worker A 的 `3-13` 尾项与对文档状态的最终收口。
|
||||
- 2026-05-21:Reasonix Worker A 重新派发后长期未生成 `final.md` / `result.json`,Codex 终止卡住的 runner / reasonix acp 进程,并记录 `.codex/reasonix-tasks/results/batch-e-worker-a-gfm-save-error-timeout.md`;后续 Codex 将 `task486` 重新对齐到当前 `/documents` 主链并复测通过,保存失败状态保留已追认。
|
||||
- 2026-05-21:Batch F 追认 `3-13` 剩余兼容层为可解释保留项,本文作为 Batch E 执行记录不再保持活跃 process。
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
# 1-13 [process] Batch F P1/P2 活跃尾项执行 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`PROCESS`
|
||||
>
|
||||
> 上位入口:`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
>
|
||||
> 阶段:Batch F / P1-P2 真实活跃尾项收口
|
||||
|
||||
## 1. 目标
|
||||
|
||||
本批次只处理 1-8 中仍有明确未完成项、且可以互不冲突并行推进的三类尾项:
|
||||
|
||||
1. `3-13` GFM AST 迁移尾项:表格/不支持结构降级策略、`web_shell.rs` legacy marks 适配分支去留判定、process 状态收口。
|
||||
2. `3-3` tree realtime live cache:复核当前 `3000` 主界面 page subtree / filetree / preferred snapshot 是否已经统一到 WS push + SSE fallback live cache,可归档则补证据归档,不能则列最小缺口。
|
||||
3. `1-6` Gap A7 / `1-5` command context:复核 `ai.canWrite` 是否已经进入 Hermes / AI 写入守卫;如未接入,补最小守卫和测试。
|
||||
|
||||
本批次不扩 Wolai 对标、不做 Phase C Review Mode、不恢复 Convex 正文主存储、不重开旧 Next / BlockNote 默认路径。
|
||||
|
||||
## 2. 已完成追认
|
||||
|
||||
- [x] `4-38` resource lifecycle / open target 原始 checklist 已归档;后续 `4-39` / `4-40` / `4-41` / `4-44` / `4-45` 已覆盖其未完成项。
|
||||
- [x] `5-26` resource open resolver 已归档,正文附件与 FileTree open target 已不再作为 Batch B/C 尾项。
|
||||
- [x] `1-12` Batch E 中 BufferStore conflict UI 与 FileTree CommandContext 接入已完成;仅保留本批次对 AI 写入守卫的补齐。
|
||||
- [x] `3-13` GFM AST 迁移尾项已由 Codex 本地复核并归档到 `design/03-rust-web/done/`;Worker A 超时,结果不采纳。
|
||||
- [x] `1-6` Gap A7 AI 写入守卫已接入 `args.commandContext` 的 `ai.canWrite` / `workspace.readonly`,并补共享守卫测试;Codex 复核后补齐 `mnote.artifact.*` 与 `mnote.mindmap.apply_ops` 两个旧守卫漏口。
|
||||
|
||||
## 3. Reasonix Worker 拆分
|
||||
|
||||
### Worker A:GFM AST 降级策略与 process 收口
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/03-rust-web/done/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
- `rust/crates/mnote-web/src/routes/local_markdown_parser.rs`
|
||||
- `rust/crates/mnote-web/src/routes/web_shell.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 补齐或追认 `3-13` 中“列对齐 / 空单元格 / 带 mark 单元格 / 不支持结构降级策略”的测试证据。
|
||||
- 审查 `web_shell.rs` 中 `legacyStylesToTiptapMarks` 等 legacy marks 适配分支是否仍被当前 bootstrap 使用。不能安全移除时,将其状态改为“保留兼容层并有退出条件”,不要强行删除。
|
||||
- 若 `3-13` 只剩保留兼容层的合理说明且测试通过,则把 `3-13` 从 process 迁移到 `design/03-rust-web/done/`。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test -p mnote-web local_markdown -- --test-threads=1`
|
||||
- `cargo test -p mnote-web web_shell -- --test-threads=1`
|
||||
- `git diff --check`
|
||||
|
||||
### Worker B:Tree realtime live cache 可归档性复核
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
- `design/03-rust-web/process/3-1-rust-web-long-term-checklist-v2.md`
|
||||
- 只读审查:`rust/crates/mnote-web/src/routes/ws.rs`、`rust/crates/mnote-web/src/routes/tree_events.rs`、`rust/crates/mnote-web/src/ssr/pages/layout.rs`、相关 tree live smoke。
|
||||
|
||||
目标:
|
||||
|
||||
- 复核 `3-3` 的三个未完成判断:sidebar、page subtree、filetree 是否仍未统一 live cache;WS 是否仍只算骨架;preferred snapshot 补偿链是否仍是阻塞。
|
||||
- 对照当前 smoke:`task432`、`task446`、`task447`、`task448`、`task449`、`task165`、`task123` 等,判断 `3-3` 是否可移动到 done。
|
||||
- 如果可以归档,只更新文档并移动到 `design/03-rust-web/done/`;如果不能,写明最小剩余缺口和建议新增 smoke,不改 runtime 代码。
|
||||
|
||||
验收:
|
||||
|
||||
- 至少运行语法检查:相关 smoke 的 `node --check`。
|
||||
- 如当前 3000 服务可用,优先实跑 1-2 个代表性 smoke;若环境不具备,必须在文档中说明阻塞。
|
||||
- `git diff --check`
|
||||
|
||||
### Worker C:AI 写入 CommandContext 守卫
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/01-tree-first-graph-kernel/process/1-6-next-phase-gap-closure-checklist-v1.md`
|
||||
- `design/01-tree-first-graph-kernel/process/1-5-next-phase-sequential-execution-checklist-v1.md`
|
||||
- `rust/crates/core-protocol/src/command.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/page.rs`
|
||||
- 相关 Hermes / AI 写入单测
|
||||
|
||||
目标:
|
||||
|
||||
- 复核 `CommandContext.ai.canWrite` 是否已被 AI / Hermes 写入路径消费。
|
||||
- 若未消费,补最小写入守卫:只读 workspace 或无写权限时,Hermes 写正文/页面命令应返回明确拒绝,不进入文件写入。
|
||||
- 补针对性单测,避免只停留在 `core-protocol` evaluator 层。
|
||||
- 更新 `1-6` / `1-5` 对应状态。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test -p core-protocol command_context -- --test-threads=1`
|
||||
- `cargo test -p mnote-web hermes_tools -- --test-threads=1`
|
||||
- 如 hermes_tools 过滤过大,可运行新增测试名的 targeted cargo test。
|
||||
- `git diff --check`
|
||||
|
||||
## 4. Codex 复核项
|
||||
|
||||
- [x] 读取每个 worker 的结果文件与 diff,不凭文字结论直接验收。
|
||||
- [x] 对 Worker A 运行 `cargo test -p mnote-web local_markdown -- --test-threads=1` 与 `cargo test -p mnote-web web_shell -- --test-threads=1`。
|
||||
- [x] 对 Worker B 至少复跑 `node --check`,并按可用环境实跑代表性 live cache smoke。
|
||||
- [x] 对 Worker C 运行 `cargo test -p core-protocol command_context -- --test-threads=1` 与相关 Hermes targeted tests。
|
||||
- [x] 更新 `1-8`、`1-12`、`3-13`、`3-3`、`1-6` 的状态,不保留互相矛盾的 process 口径。
|
||||
- [ ] 提交前运行 `git diff --check`、`codegraph sync .`、`codegraph status .`。
|
||||
|
||||
## 5. 本轮执行记录
|
||||
|
||||
- 2026-05-21:Codex 新建 Batch F checklist,准备并行派发 Worker A/B/C。
|
||||
- 2026-05-21:Worker A 长时间未生成 `final.md` / `result.json`,Codex 终止并记录 `.codex/reasonix-tasks/results/batch-f-worker-a-gfm-archive-timeout.md`。
|
||||
- 2026-05-21:Worker B 输出串线到 Worker C 方向,不能作为 `3-3` 归档证据;记录 `.codex/reasonix-tasks/results/batch-f-worker-b-tree-live-cache-misrouted.md`。Codex 已复跑 `task123/task432/task446/task447/task448/task449` 的 `node --check`。
|
||||
- 2026-05-21:Codex 本地复核 `3-13`,确认 colspan 降级、table marks、alignment、web shell legacy marks 兼容层均有证据,已移动到 `design/03-rust-web/done/`。
|
||||
- 2026-05-21:Codex 整理 Worker C 半截补丁,新增 `ToolCallInput::command_context_bridge` 与 `ensure_write_authorized`,让 Hermes 写入工具消费 `ai.canWrite` / `workspace.readonly`。
|
||||
- 2026-05-21:Codex 复核发现 `artifact.rs` 与 `resource.rs` 仍保留旧写入守卫,已改为委托 `ensure_write_authorized`。验证:`cargo test --manifest-path rust/Cargo.toml -p core-protocol command_context -- --test-threads=1` 7 passed;`cargo test --manifest-path rust/Cargo.toml -p mnote-web hermes_tools -- --test-threads=1` 64 passed;`cargo test --manifest-path rust/Cargo.toml -p mnote-web ensure_write_authorized -- --test-threads=1` 2 passed。
|
||||
- 2026-05-21:Batch H 已完成 `3-3` live cache 归档与 `1-5` command context 状态收口;`task487` / `task471` / `task476` 已在当前 3000 环境复跑通过,`1-8` Batch D 状态已更新。
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
# 1-14 [process] Batch H P2 live cache / command context 收口 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`DONE`
|
||||
>
|
||||
> 上位入口:`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
>
|
||||
> 阶段:Batch H / P2 文档状态与浏览器证据收口
|
||||
|
||||
## 1. 目标
|
||||
|
||||
本批次只处理 `1-8` Batch D 中仍会干扰后续判断的两类尾项:
|
||||
|
||||
1. `3-3` tree realtime live cache 是否仍应保留在 `process/`,还是已被 `3-14` / `3-18` / `task487` 证据覆盖后可以归档。
|
||||
2. `1-5` / `1-6` command context 文档状态是否仍把 FileTree 菜单、快捷键、AI 写入守卫标成未完成。
|
||||
|
||||
本批次不新增 runtime 功能,不扩 AI 产品面,不实现 Phase C Review Mode,不恢复 Convex 正文主存储。
|
||||
|
||||
## 2. Reasonix Worker 拆分
|
||||
|
||||
### Worker A:`3-3` live cache 可归档性复核
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
- 如确认可归档,可移动到 `design/03-rust-web/done/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
|
||||
目标:
|
||||
|
||||
- 对照 `3-14` WS push、`3-18` local folder tree live consumer、`task123/task432/task446/task447/task448/task449/task487` 证据,判断 `3-3` 的 9.2 未完成项是否已经过期。
|
||||
- 如果可归档,只更新 `3-3` 文档状态并移动到 `done/`。
|
||||
- 如果不可归档,只在 `3-3` 写明最小剩余缺口,不改 runtime 代码。
|
||||
|
||||
验收:
|
||||
|
||||
- `node --check scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `node --check scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `git diff --check`
|
||||
|
||||
### Worker B:`1-5` / `1-6` command context 状态收口
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/01-tree-first-graph-kernel/process/1-5-next-phase-sequential-execution-checklist-v1.md`
|
||||
- `design/01-tree-first-graph-kernel/process/1-6-next-phase-gap-closure-checklist-v1.md`
|
||||
|
||||
目标:
|
||||
|
||||
- 只更新 command context / context key 相关 checklist 状态。
|
||||
- 对照当前代码和已通过测试,修正仍写着“File Tree 右键菜单、快捷键、AI 写入能力尚未消费 CommandContext”的过期表述。
|
||||
- 保留真实未完成项,例如更完整的 editor/object tab context 或未实跑的 readonly DnD smoke,不要把范围外事项误勾完成。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p core-protocol command_context -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web ensure_write_authorized -- --test-threads=1`
|
||||
- `node --check scripts/task471-local-folder-bulk-resource-trash-smoke.js`
|
||||
- `node --check scripts/task476-filetree-editor-context-menu-download-smoke.js`
|
||||
- `git diff --check`
|
||||
|
||||
### Worker C:Batch D 浏览器 smoke 证据整理
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-h-worker-c-browser-smoke-evidence.md`
|
||||
|
||||
目标:
|
||||
|
||||
- 不修改产品代码和设计主文档。
|
||||
- 只读检查当前相关 smoke 脚本、已有 `tmp/` 结果和截图路径。
|
||||
- 输出一份证据表,区分“已实跑通过”“仅 node --check 通过”“需要后续实跑”的 smoke。
|
||||
- 优先覆盖:`task123`、`task432`、`task446`、`task447`、`task448`、`task449`、`task471`、`task476`、`task487`。
|
||||
|
||||
验收:
|
||||
|
||||
- 结果文件列出每个 smoke 的脚本路径、最近证据路径、是否可用于人工网页核查。
|
||||
- 不改 runtime 代码。
|
||||
- `git diff --check`
|
||||
|
||||
## 3. Codex 复核项
|
||||
|
||||
- [x] 读取 Worker A/B/C 的 `final.md` / `result.json` / diff,不凭文字结论直接验收。
|
||||
- [x] 确认 Worker A 若移动 `3-3` 到 done,不会掩盖仍未完成的 live cache 缺口。
|
||||
- [x] 确认 Worker B 只勾 command context 已完成范围,不把 editor/object tab future 项误判完成。
|
||||
- [x] 根据 Worker C 的证据表决定本轮是否需要再实跑浏览器 smoke。
|
||||
- [x] 更新 `1-8` / `1-13` / 本文件执行记录。
|
||||
- [ ] 提交前运行 `codegraph sync .`、`codegraph status .`。
|
||||
|
||||
## 4. 本轮执行记录
|
||||
|
||||
- 2026-05-21:Codex 新建 Batch H checklist,准备派发 Worker A/B/C。
|
||||
- 2026-05-21:Reasonix Worker A/B/C 均 completed,并通过 completion hook 写入 `tmp/reasonix-hook-test/batch-h-*.json`。
|
||||
- 2026-05-21:Codex 复核 Worker A diff,确认 `3-3` 已移动到 `design/03-rust-web/done/`,9.2 未完成项已由 `3-14`、`3-18` 与 `task487` 覆盖。
|
||||
- 2026-05-21:Codex 复核 Worker B diff,采纳 `1-5` Phase A7 的 command context 状态更新;保留 editor/object tab context 和更完整按钮 enablement 作为后续扩展,不把它们误判为本轮完成。
|
||||
- 2026-05-21:Codex 复核 Worker C 证据表,纠正 `task471` 证据漏查,并实跑关键 smoke:`task487` 通过,`task471` 通过,`task476` 使用 `/usr/bin/google-chrome-stable` 通过。`/snap/bin/chromium` 下的 `download.saveAs ENOENT` 判定为 Playwright 下载临时文件噪音,不作为产品失败。
|
||||
- 2026-05-21:验证命令已通过:
|
||||
- `git diff --check`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p core-protocol command_context -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web ensure_write_authorized -- --test-threads=1`
|
||||
- `node --check scripts/task123-rust-web-tree-live-stream-consumer-smoke.js`
|
||||
- `node --check scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `node --check scripts/task471-local-folder-bulk-resource-trash-smoke.js`
|
||||
- `node --check scripts/task476-filetree-editor-context-menu-download-smoke.js`
|
||||
- `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/snap/bin/chromium PLAYWRIGHT_CHROME_EXECUTABLE=/snap/bin/chromium node scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/snap/bin/chromium PLAYWRIGHT_CHROME_EXECUTABLE=/snap/bin/chromium node scripts/task471-local-folder-bulk-resource-trash-smoke.js`
|
||||
- `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome-stable PLAYWRIGHT_CHROME_EXECUTABLE=/usr/bin/google-chrome-stable node scripts/task476-filetree-editor-context-menu-download-smoke.js`
|
||||
+20
-11
@@ -484,29 +484,38 @@
|
||||
|
||||
### 8.3 顺序任务
|
||||
|
||||
- [ ] 盘点当前菜单、快捷键、按钮 enablement 条件。
|
||||
- [x] 盘点当前菜单、快捷键、按钮 enablement 条件。
|
||||
- 搜索命令:`rg -n "disabled|aria-disabled|context|shortcut|keydown|menu|right-click|data-action" rust/crates/mnote-web/src/ssr/pages/layout.rs -S`
|
||||
- 完成验收:列出至少 filetree、pagetree、editor、AI panel 的条件来源。
|
||||
- **执行记录(Batch C Worker C)**:FileTree 右键菜单(delete-trash/rename/new-file/new-folder/paste-into 共 5 项,均携带 `when`)和 Delete/Backspace 快捷键已审计并完成上下文接入。AI panel 条件由 `ai.canWrite` 在 hermes_tools 守卫中消费。
|
||||
|
||||
- [ ] 定义 MNote 最小 command context。
|
||||
- 建议 key:`workspace.sourceKind`、`tree.focusKind`、`tree.selectionCount`、`tree.selectionResourceKind`、`editor.dirty`、`editor.hasSelection`、`ai.canWrite`、`workspace.readonly`。
|
||||
- 完成验收:这些 key 能覆盖当前右键菜单、快捷键和主按钮 enablement。
|
||||
- [x] 定义 MNote 最小 command context。
|
||||
- 完成 key:`workspace.sourceKind`、`workspace.readonly`、`tree.focusKind`、`tree.selectionCount`、`tree.selectionResourceKind`、`editor.dirty`、`editor.hasSelection`、`ai.canWrite` 共 8 个 key。
|
||||
- 完成验收:这些 key 已覆盖当前右键菜单、快捷键和 AI write guard enablement。
|
||||
- **代码证明**:`rust/crates/core-protocol/src/command.rs` 中 `CommandContext` 结构体包含全部 8 个字段;7 个单测覆盖 when 求值全路径。
|
||||
|
||||
- [ ] 先在 Rust 侧定义 context schema,再让前端消费。
|
||||
- 完成验收:前端不再在多个分支里重复判断同一个能力。
|
||||
- [x] 先在 Rust 侧定义 context schema,再让前端消费。
|
||||
- Rust 侧:`core-protocol/src/command.rs` — `CommandContext` + `WhenExprNode` + `evaluate_when` / `check_when` / `is_command_enabled`。
|
||||
- 前端侧(SSR `layout.rs`):`buildSidebarFileTreeContext()` + `evaluateSidebarFileTreeWhen()` 两个 JS 等价物用于右键菜单启禁。
|
||||
- 完成验收:FileTree 右键菜单和 Delete/Backspace 共享同一 `evaluateSidebarFileTreeWhen` 路径。
|
||||
|
||||
### 8.4 验收
|
||||
|
||||
- [ ] command context 单测覆盖 `when` 判断。
|
||||
- 建议命令:`cargo test -p core-protocol command_context -- --nocapture`
|
||||
- [x] command context 单测覆盖 `when` 判断。
|
||||
- 命令:`cargo test -p core-protocol command_context -- --nocapture`
|
||||
- **结果(2026-05-21)**:7 passed — 覆盖 key、`!key`、`==`、`!=`、`&&`、`||`、括号分组、number comparison、parse error fallback、`ai.canWrite` gate、`workspace.readonly` gate。
|
||||
|
||||
- [ ] 文件树 DnD / readonly conflict smoke 通过。
|
||||
- [x] 文件树 DnD / readonly conflict smoke 通过。
|
||||
- 命令:`PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/google-chrome-stable node scripts/task431-vscode-explorer-dnd-readonly-conflict-smoke.js`
|
||||
- **证据**:`tmp/task431-vscode-explorer-dnd-readonly-conflict-smoke/result.json` — `ok: true`,readonly-target 和 readonly-source 均返回 400。
|
||||
|
||||
完成标准:
|
||||
|
||||
- [ ] 同一命令在菜单、快捷键、按钮上使用同一 context 判断。
|
||||
- [ ] readonly / read grant / selected resource kind 的禁用态一致。
|
||||
- [x] 同一命令在菜单、快捷键、按钮上使用同一 context 判断。
|
||||
- FileTree 右键菜单(delete-trash/rename/new-file/new-folder/paste-into)与 Delete/Backspace 快捷键共享 `evaluateSidebarFileTreeWhen` 路径。
|
||||
- **保留的缺口**:editor/object tab 上下文尚未接入 command context;AI tool 写入守卫 `ensure_write_authorized` 是独立路径(读 `args.commandContext`,非前端 context key)。
|
||||
- [x] readonly / read grant / selected resource kind 的禁用态一致。
|
||||
- FileTree 右键菜单 readonly 禁用已通过 `!workspace.readonly` when 表达式统一实现。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+9
-3
@@ -131,7 +131,7 @@
|
||||
- [x] 实现最小 `when` evaluator:支持 `key`、`!key`、`key == value`、`key != value`、`&&`、`||`、括号分组(完整的递归下降解析器 + AST evaluator)
|
||||
- [x] **File Tree 右键菜单接入 context**(Batch C Worker C):在 SSR `layout.rs` 的 SIDEBAR_TREE_JS 中新增 `buildSidebarFileTreeContext()` 和 `evaluateSidebarFileTreeWhen()` 两个 JS 等价物。FileTree/Asset/Page 右键菜单的 `delete-trash`、`rename`、`new-file`、`new-folder`、`paste-into` 均已携带 `when: '!workspace.readonly'`。菜单构建时评估 when 表达式,命中时设置 `disabled: true` 并调整 title。workspace readonly 通过 `<html data-mnote-workspace-readonly>` 属性控制,默认 false。
|
||||
- [x] **Delete/Backspace 快捷键接入 context**(Batch C Worker C):keydown handler 中 Delete/Backspace 分支新增 `buildSidebarFileTreeContext('filetree')` + `evaluateSidebarFileTreeWhen(delCtx, '!workspace.readonly && tree.selectionCount')` 守卫。只读或无选中时阻止动作。
|
||||
- [ ] 把 AI 写入能力接入 context:`ai.canWrite` key 已定义,未在 hermes_tools 中消费
|
||||
- [x] 把 AI 写入能力接入 context:`ai.canWrite` key 已定义,并已在 hermes_tools 写入守卫中消费 `args.commandContext` / `args.command_context` 的 `ai.canWrite` 与 `workspace.readonly`。
|
||||
|
||||
### 3.3 必补测试
|
||||
|
||||
@@ -150,13 +150,19 @@
|
||||
- [x] **FileTree 右键菜单已接入**(Batch C Worker C):delete-trash、rename、new-file、new-folder、paste-into 携带 `when: '!workspace.readonly'`
|
||||
- [x] **Delete/Backspace 快捷键已接入**(Batch C Worker C):keydown handler 中有 `!workspace.readonly && tree.selectionCount` 守卫
|
||||
- [ ] **未完成**:下载、多选删除、粘贴、只读阻断的 smoke 保持回退兼容
|
||||
- [ ] **未完成**:AI 写入能力 (`ai.canWrite`) 尚未接入 hermes_tools
|
||||
- [x] **已完成**:AI 写入能力 (`ai.canWrite`) 已接入 hermes_tools 写入守卫;`mnote.block.*`、`mnote.doc.markdown_edit`、`mnote.page.*`、`mnote.artifact.*`、`mnote.mindmap.apply_ops` 写入链共享 `ensure_write_authorized`,只读 scope、`workspace.readonly=true` 或 `ai.canWrite=false` 均会拒绝写入。
|
||||
|
||||
### 3.5 下一步
|
||||
|
||||
- `layout.rs` 右键菜单:已引入 `evaluateSidebarFileTreeWhen`(Batch C Worker C 完成)
|
||||
- Delete/Backspace:已接入(Batch C Worker C 完成)
|
||||
- hermes_tools 写入守卫:仍需 `ai.canWrite` 的消费
|
||||
- hermes_tools 写入守卫:已消费 `ai.canWrite` / `workspace.readonly` command context;后续若前端新增更多 AI 写入口,必须把同一份 `commandContext` 透传到 tool args。
|
||||
|
||||
### 3.6 Batch F 复核记录
|
||||
|
||||
- 2026-05-21:Codex 将 Hermes 写入守卫收口为 `ensure_write_authorized`,`ToolCallInput` 从 `args.commandContext` / `args.command_context` 读取 `ai.canWrite` 与 `workspace.readonly`。
|
||||
- 2026-05-21:`mnote.block.*` / `mnote.doc.markdown_edit` 继续经 `block::ensure_write_contract`,该函数已委托共享守卫;`mnote.page.*`、`mnote.artifact.*`、`mnote.mindmap.apply_ops` 也委托共享守卫。
|
||||
- 2026-05-21:新增测试覆盖 `ai.canWrite=false` 与 `workspace.readonly=true` 的拒绝路径。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+48
-10
@@ -167,7 +167,7 @@
|
||||
|
||||
- `design/05-editor-mainline/process/5-6-page-aggregate-alignment-checklist-v1.md`
|
||||
- `design/05-editor-mainline/reference/5-5-page-aggregate-single-truth-alignment-v1.md`
|
||||
- `design/03-rust-web/process/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
- `design/03-rust-web/done/3-13-rust-web-local-markdown-gfm-ast-parser-migration-v1.md`
|
||||
|
||||
执行目标:
|
||||
|
||||
@@ -183,7 +183,7 @@
|
||||
|
||||
归档条件:
|
||||
|
||||
- `3-13` 仅剩 `web_shell.rs` 临时适配分支移除与 process→done 迁移,`task486` 已改写到当前主链并复测通过。
|
||||
- `3-13` 已完成 GFM AST 迁移尾项并归档到 `design/03-rust-web/done/`;`web_shell.rs` legacy marks 分支改判为兼容层保留,不再作为迁移阻塞项。
|
||||
- `5-6` 剩余 Phase G/H 小尾项完成或拆成更小 checklist 后归档。
|
||||
|
||||
## 5. P2:tree live cache 与 command context
|
||||
@@ -210,6 +210,27 @@
|
||||
|
||||
- `3-3` 中统一 live cache 和 no-refresh 矩阵完成后归档。
|
||||
|
||||
### P2.2 Local folder tree live consumer 收口
|
||||
|
||||
入口文档:
|
||||
|
||||
- `design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
执行状态:
|
||||
|
||||
- 2026-05-21:已完成后端 SSE 形状、前端 tree live controller 接入与 browser smoke 复核;`task487` 已在新编译的 3000 进程上通过,`data-mnote-tree-live-transport=local-folder-events`、`data-mnote-tree-live-status=connected`,外部创建 / 删除后 `data-mnote-tree-live-applied=resync`。
|
||||
- 2026-05-21:completion hook 口径已补进 Reasonix runner / skill;后续派发无需再靠短轮询等待结果。
|
||||
- `3-18` 已归档到 `design/03-rust-web/done/`,local_folder tree live consumer 收口不再是 `1-8` 的阻塞项。
|
||||
|
||||
验收:
|
||||
|
||||
- `node scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- 真实浏览器里确认 local_folder 不再依赖 `local-folder-static` 作为默认主链。
|
||||
|
||||
归档条件:
|
||||
|
||||
- `3-18` 已完成并归档,且 smoke / Rust targeted tests 已通过。
|
||||
|
||||
### P2.2 Command context / context key
|
||||
|
||||
入口文档:
|
||||
@@ -239,7 +260,7 @@
|
||||
|
||||
入口文档:
|
||||
|
||||
- `design/07-ai/process/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
- `design/07-ai/done/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
|
||||
执行目标:
|
||||
|
||||
@@ -254,7 +275,7 @@
|
||||
|
||||
归档条件:
|
||||
|
||||
- 7-27 的 6 步实施计划完成后归档。
|
||||
- `7-27` 的 6 步实施计划已完成并归档;后续只保留 `revisionRef` 注释可见性、复杂 GFM fallback、多余退役函数体清理等增强项,不阻塞 Batch E。
|
||||
|
||||
### P3.2 ACP runtime 后续步骤
|
||||
|
||||
@@ -262,6 +283,7 @@
|
||||
|
||||
- `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md`
|
||||
- `design/07-ai/process/7-12-page-ai-hermes-tool-routing-and-review-surface-v1.md`
|
||||
- `design/07-ai/done/7-34-acp-runtime-cleanup-availability-stability-tail-v1.md`
|
||||
|
||||
执行目标:
|
||||
|
||||
@@ -368,25 +390,39 @@
|
||||
- `1-6` 的 A2 浏览器可见读回、conflict UI、C1 export smoke 已由 Batch C / 本轮复核完成。
|
||||
- `5-26` 已归档到 `design/05-editor-mainline/done/`,Resource Open Resolver / 主编辑器资源 tab / FileTree open target 的收口证据不再作为 Batch B/C 尾项。
|
||||
- `4-38` 已归档到 `design/04-tree-domain/done/`,其 resource lifecycle / open target 原始未完成项已由 `4-39` / `4-40` / `4-41` / `4-44` / `4-45` 覆盖。
|
||||
- `3-13` 已由 Batch F 归档;表格 colspan 降级、table marks、alignment、保存失败状态保留和 web shell legacy marks 兼容层均已有证据。
|
||||
- `1-6` A7 的 `ai.canWrite` 写入守卫已由 Batch F 接入 hermes_tools;后续新增 AI 写入口必须透传同一份 `commandContext`。
|
||||
- `task451` 与 `task486` 已在当前 3000 主进程上复测通过,不再作为本轮尾项。
|
||||
|
||||
### Batch D:live cache / command context
|
||||
|
||||
1. `3-3`
|
||||
2. `1-5` command context 子项
|
||||
3. `4-44` 若 Batch A 未完成则回补
|
||||
1. `3-3`(已由 Batch H 归档到 `design/03-rust-web/done/`)
|
||||
2. `1-5` command context 子项(已由 Batch H 更新 Phase A7 状态)
|
||||
3. `4-44`(已在 `design/04-tree-domain/done/`,`task471` / `task476` 均已复跑通过)
|
||||
|
||||
完成后预期:树域实时与 enablement 判断更统一。
|
||||
|
||||
当前批次状态:
|
||||
|
||||
- `3-3` 已由 Batch H 归档,`3-14` WS push、`3-18` local folder tree live consumer 和 `task487` 已覆盖旧 9.2 未完成项。
|
||||
- `1-5` Phase A7 已追认 `CommandContext` / `when` evaluator、FileTree 右键菜单、Delete/Backspace、`ai.canWrite` 写入守卫的完成证据;editor/object tab 更完整 context 仍作为后续扩展,不阻塞本轮 Batch D 收口。
|
||||
- `task487`、`task471`、`task476` 已在当前 3000 环境复跑通过。
|
||||
|
||||
### Batch E:AI 与资源工具
|
||||
|
||||
1. `7-27`
|
||||
2. `7-15` 后续拆分
|
||||
3. `7-12` Phase B-F 拆分
|
||||
1. `7-27`(已归档到 `design/07-ai/done/`)
|
||||
2. `7-15` 后续拆分(下一批拆 `7-34`)
|
||||
3. `7-12` Phase B-F 拆分(下一批拆 `7-34`)
|
||||
4. `7-28` 仅在 mindmap / office AI 明确排期后进入
|
||||
|
||||
完成后预期:local-first AI 主路径稳定,cloud/compat 工具不再误导默认路径。
|
||||
|
||||
当前批次状态:
|
||||
|
||||
- `7-27` 已由 Batch I 复核归档;`mnote.doc.markdown_edit` 在线写回以最终 markdown 为真源,`markdown_edit` 相关 targeted tests 与 manifest write contract 测试已通过。
|
||||
- `7-29` 已完成 Worker A/B/C 审查,结论是 `7-15` Step 15-17 与 `7-12` Phase B/F 不应继续压在一个大文档里推进。
|
||||
- `7-34` 已完成并归档到 `design/07-ai/done/`:旧 HTTP proxy 默认关闭、`page_ai_workflow` 受共享 tool executor 守卫保护;profile disabled list 三处同源;`capabilityScope` 中心校验已完成;ACP abort API 改为 best-effort cancellation 并主动推送 `run.aborted`;`task488` 已在当前 3000 真实通过,覆盖 3 个 Reasonix ACP session、并发 run、abort 与 SSE terminal event。cache benchmark 仍是 P2 度量;Phase C Review Mode 继续冻结。
|
||||
|
||||
### Batch F:体验对标与远期
|
||||
|
||||
1. `6-mindmap-*`
|
||||
@@ -413,6 +449,8 @@
|
||||
- 更新本文对应 batch 状态。
|
||||
- 运行 `codegraph sync .`。
|
||||
|
||||
> **Reasonix 执行说明**:Reasonix 编码任务默认使用 30 分钟超时;完成后应通过 completion hook 主动回传结果,不再依赖短轮询等待。
|
||||
|
||||
## 11. 不做事项
|
||||
|
||||
- 不按文件编号顺序清空 process。
|
||||
|
||||
+21
-6
@@ -1,7 +1,11 @@
|
||||
# 3-13 [process] Rust Web 本地 Markdown GFM AST 解析器迁移方案 v1
|
||||
# 3-13 [done] Rust Web 本地 Markdown GFM AST 解析器迁移方案 v1
|
||||
|
||||
> 更新时间:2026-05-09
|
||||
>
|
||||
> 归档时间:2026-05-21
|
||||
>
|
||||
> 归档说明:GFM AST 读侧、写侧 round-trip、表格/mark/任务列表/保存失败状态保留的回归证据已补齐;`web_shell.rs` 的 legacy marks 适配分支已改判为当前兼容层,不再作为阻塞归档的“必须移除”项。
|
||||
>
|
||||
> 关联:
|
||||
> - `/mnt/Data1T/mnote/rust/crates/mnote-web/src/routes/local_folder_source.rs`
|
||||
> - `/mnt/Data1T/mnote/rust/crates/mnote-web/src/routes/local_markdown_parser.rs`
|
||||
@@ -392,11 +396,13 @@
|
||||
|
||||
- [x] 移除 `local_folder_source.rs` 中不再需要的临时解析函数。
|
||||
|
||||
- [ ] 移除 `web_shell.rs` 中只为补丁存在的临时适配分支。
|
||||
- [x] 复核 `web_shell.rs` 中 legacy marks 适配分支。
|
||||
- 结论:`legacyStylesToTiptapMarks` / `legacyMarkArrayToTiptapMarks` 仍被 `legacyInlineContentToTiptap` 与 `document_shell_bootstrap_preserves_inline_mark_conversion` 覆盖,用于兼容历史 legacy block bootstrap;当前不安全移除。
|
||||
- 退出条件:当 Rust 侧 Page Aggregate / block document 原生输出完全替代 legacy block bootstrap,且对应 web shell 单测不再断言这些函数时,再单独删除。
|
||||
|
||||
- [x] 保留回归测试和兼容层,不删除验证资产。
|
||||
|
||||
- [ ] 迁移完成后把设计稿状态从 `process` 移到 `done`。
|
||||
- [x] 迁移完成后把设计稿状态从 `process` 移到 `done`。
|
||||
|
||||
---
|
||||
|
||||
@@ -428,9 +434,18 @@
|
||||
|---|------|------|
|
||||
| 11.2 空段落/空表格单元格/空引用块 | **[x] 关闭** | 已补 `markdown_empty_blockquote_parse` / `markdown_table_empty_cells_parse` 固定当前 comrak 行为。 |
|
||||
| 11.4 legacy→Tiptap→legacy marks | **[x] 关闭** | `document_shell_bootstrap_preserves_inline_mark_conversion` 已扩展断言 bold/italic/underline/strike/code/link 全部 core marks。 |
|
||||
| 11.6 列对齐/空单元格/带 mark 单元格降级策略测试 | **[ ] 部分完成** | 列对齐已追认,空单元格已补测试关闭。降级策略仍无覆盖。 |
|
||||
| 11.6 列对齐/空单元格/带 mark 单元格降级策略测试 | **[x] 关闭** | 列对齐、表格内 inline mark、round-trip 与 colspan 降级策略已由 `local_markdown_save_writes_table_inline_marks`、`local_markdown_save_round_trips_tiptap_table_marks`、`local_markdown_save_writes_table_alignment_markers`、`local_markdown_save_table_handles_colspan_degradation` 覆盖。 |
|
||||
| 11.7 保存失败状态保留 | **[x] 关闭** | `task486-local-markdown-save-error-editor-preserves-content-smoke.js` 已切到当前 `/documents` 主链并复核通过,保存失败时编辑器内容与 runtime error 状态均保留。 |
|
||||
| 11.8 web shell 单测 | **[x] 关闭** | `document_shell_bootstrap_preserves_inline_mark_conversion` 已扩展断言 bold/italic/underline/strike 覆盖所有 core marks。 |
|
||||
| 11.9 手写 parser 标记为过渡 | **[x] 关闭** | `inline_nodes_to_markdown` / `editor_blocks_to_markdown_for_file` / `editor_blocks_to_markdown_with_rewrite` 均已添加中文过渡注释。 |
|
||||
| 11.9 web_shell.rs 临时适配分支移除 | **[ ] 保留** | JS 侧 `legacyStylesToTiptapMarks` 等适配函数仍存在(已加过渡注释 TODO(step-4))。 |
|
||||
| 11.9 process→done | **[ ] 保留** | 以上未完成项关闭后方可移动。
|
||||
| 11.9 web_shell.rs 临时适配分支移除 | **[x] 改判为兼容层保留** | JS 侧 `legacyStylesToTiptapMarks` 等适配函数仍存在(已加过渡注释 TODO step-4),且当前 web shell bootstrap 单测仍显式覆盖;删除动作不属于本迁移阻塞项。 |
|
||||
| 11.9 process→done | **[x] 关闭** | 以上尾项均已有代码证据或兼容层退出条件,本文移动到 `done/`。 |
|
||||
|
||||
## 13. 归档复核(2026-05-21 Batch F)
|
||||
|
||||
- Reasonix Worker A 超时,无有效 `final.md` / `result.json`;记录见 `.codex/reasonix-tasks/results/batch-f-worker-a-gfm-archive-timeout.md`。
|
||||
- Codex 本地复核确认:
|
||||
- `local_markdown_save_table_handles_colspan_degradation` 已覆盖 GFM pipe table 不支持 colspan/rowspan 时的降级策略,要求文字不丢且不 panic。
|
||||
- `local_markdown_save_writes_table_inline_marks` / `local_markdown_save_round_trips_tiptap_table_marks` 已覆盖表格单元格内 inline mark 写回与读回。
|
||||
- `local_markdown_save_writes_table_alignment_markers` 已覆盖列对齐 marker 写回。
|
||||
- `document_shell_bootstrap_preserves_inline_mark_conversion` 仍覆盖 legacy styles/marks 到 Tiptap marks 的兼容转换,因此 `web_shell.rs` 分支保留为兼容层。
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
# 3-18 [done] Local Folder Tree Live Consumer 收敛 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`DONE`
|
||||
>
|
||||
> 上位入口:
|
||||
> - `design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
> - `design/03-rust-web/process/3-3-rust-web-tree-realtime-event-stream-v1.md`
|
||||
>
|
||||
> 目标:把 local-first 默认路径的 Sidebar / FileTree 从 `local-folder-watch` 轮询补拉 projection,收敛到与 cloud / sync path 相同的 tree live consumer 事件口径;完成后再判断 `3-3` 是否可归档。
|
||||
|
||||
## 1. 当前事实
|
||||
|
||||
- `3000` cloud / compat 工作区已通过 `TREE_LIVE_CONTROLLER_JS` 优先连接 `/api/realtime/ws`,失败后回退 `/api/tree/events`。
|
||||
- `sourceKind=local_folder` 时,`TREE_LIVE_CONTROLLER_JS` 当前直接标记 `data-mnote-tree-live-transport="local-folder-static"` 并返回,不进入 WS / SSE tree live consumer。
|
||||
- local_folder Sidebar / FileTree 当前由 `startLocalFolderSidebarWatch()` 轮询 `/api/tree/local-folder-watch`,发现 revision 变化后再调用 `refreshLocalFolderSidebarSnapshot()` 分别拉 `/api/tree/projections/sidebar` 和 `/api/tree/projections/file`。
|
||||
- `web_shell.rs` 已有 `/api/local-folder/events` SSE,用于 tiptap 文档外部变更刷新,但它还没有统一到 Sidebar / FileTree 的 `tree:snapshot` / `tree:delta` / `tree:resync` consumer。
|
||||
|
||||
## 2. 不做事项
|
||||
|
||||
- 不恢复 Convex 正文主存储。
|
||||
- 不把 local_folder 变化写回 Convex command log。
|
||||
- 不重开旧 Next / BlockNote 默认路径。
|
||||
- 不一次性重写所有 Sidebar/FileTree 逻辑;本轮只替换轮询补拉链路的 transport 和 consumer 入口。
|
||||
|
||||
## 3. Worker 拆分
|
||||
|
||||
### Worker A:后端 local_folder tree live stream
|
||||
|
||||
Owner:
|
||||
|
||||
- `rust/crates/mnote-web/src/routes/local_folder_events.rs`
|
||||
- `rust/crates/mnote-web/src/routes/stream_support.rs`
|
||||
- `rust/crates/mnote-web/src/routes/mod.rs`
|
||||
- 必要时只读 `rust/crates/mnote-web/src/local_folder_watcher_registry.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 给 local_folder 提供 tree live 事件形状:`tree:snapshot` / `tree:resync` 至少携带 `kernel_sidebar_projection` 与 `kernel_file_tree_projection`。
|
||||
- 复用现有 LocalFolderWatcherRegistry,不新增第二套 watcher。
|
||||
- 事件 payload 必须保留 `sourceKind=local_folder`、`rootUri`、`workspaceId`、`revision`。
|
||||
- 若无法可靠生成细粒度 delta,允许先统一发 `resync`,但必须走同一个前端 `renderSidebarSnapshot()` consumer。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web local_folder_events -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web stream_support -- --test-threads=1`
|
||||
|
||||
### Worker B:前端 tree live controller 接入 local_folder
|
||||
|
||||
Owner:
|
||||
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 移除 `sourceKind=local_folder` 直接 `local-folder-static` 返回的长期阻塞。
|
||||
- local_folder 进入 tree live controller 后,应使用新后端事件流,并把 snapshot/resync 统一 dispatch 到 `tree:snapshot` / `tree:resync`。
|
||||
- 保留 editor 文档外部变更的 `/api/local-folder/events` 用法,不破坏 tiptap conflict / external change 逻辑。
|
||||
- 尽量让 `startLocalFolderSidebarWatch()` 退为 fallback,不再是默认主链。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_tree_runtime -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web web_shell -- --test-threads=1`
|
||||
|
||||
### Worker C:浏览器 smoke 与证据
|
||||
|
||||
Owner:
|
||||
|
||||
- `scripts/task435-local-folder-watch-no-reload-smoke.js`
|
||||
- 可新增 `scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- `design/03-rust-web/process/3-18-local-folder-tree-live-consumer-convergence-checklist-v1.md`
|
||||
|
||||
目标:
|
||||
|
||||
- 增加或更新 smoke,验证 local_folder 文档页 HTML / DOM 不再显示 `data-mnote-tree-live-transport="local-folder-static"` 作为默认主链。
|
||||
- 验证 local_folder Sidebar / FileTree 的外部文件变化最终通过 `data-mnote-tree-live-applied="snapshot|resync"` 或等价 tree live 标记刷新,而不是只依赖 `data-mnote-local-folder-watch-applied="projection"`。
|
||||
- smoke 必须可在 `http://127.0.0.1:3000` 环境运行,并输出 JSON 证据和截图路径。
|
||||
|
||||
验收:
|
||||
|
||||
- `node --check scripts/task435-local-folder-watch-no-reload-smoke.js`
|
||||
- 若新增脚本:`node --check scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
|
||||
## 4. Codex 复核项
|
||||
|
||||
- [x] 复核 Worker A diff,确认没有新增第二套 watcher 或 Convex 写回。
|
||||
- [x] 复核 Worker B diff,确认 local_folder 进入统一 tree live consumer,旧 polling 只保留 fallback。
|
||||
- [x] 复核 Worker C smoke,确认断言覆盖真实 UI/DOM 状态。
|
||||
- [x] 运行 targeted Rust tests。
|
||||
- [x] 运行相关 smoke 或记录环境阻塞。
|
||||
- [x] 更新 `3-3` 与 `1-8` 状态。
|
||||
|
||||
## 5. 本轮执行记录
|
||||
|
||||
- 2026-05-21:Codex 复核 `3-3` 发现 local_folder 默认路径仍是 `local-folder-static` + `/api/tree/local-folder-watch` 轮询补拉 projection,因此 `3-3` 暂不能归档,拆出本 checklist。
|
||||
- 2026-05-21:**Worker C(本批次)**:
|
||||
- 新增 `scripts/task487-local-folder-tree-live-consumer-smoke.js`
|
||||
- 未修改 `scripts/task435-local-folder-watch-no-reload-smoke.js`,该脚本保持 GREEN(覆盖 no-reload 语义,与 tree live consumer 正交)
|
||||
- 先前使用旧进程和首页入口时 smoke 呈 RED;切换到新编译的 3000 进程并改为 `documents/local-md:README.md?sourceKind=local_folder...` 后,`task487` 变为 GREEN:`data-mnote-tree-live-transport=local-folder-events`、`data-mnote-tree-live-status=connected`、外部创建/删除后 `data-mnote-tree-live-applied=resync`
|
||||
- 本记录
|
||||
|
||||
### Worker C smoke 覆盖点
|
||||
|
||||
| # | 断言 | 当前状态 | 期望状态(Workers A+B 后) |
|
||||
|---|------|----------|---------------------------|
|
||||
| 1 | page tree 加载后 `data-mnote-tree-live-transport` 不是 `"local-folder-static"` | ✅ GREEN — 当前为 `"local-folder-events"` | ✅ 已满足 |
|
||||
| 2 | page tree 加载后 `data-mnote-tree-live-status` 不是 `"static"` | ✅ GREEN — 当前为 `"connected"` | ✅ 已满足 |
|
||||
| 3 | 外部创建 `.md` 后 `data-mnote-tree-live-applied` 为 `"snapshot"` 或 `"resync"` | ✅ GREEN — 当前为 `"resync"` | ✅ 已满足 |
|
||||
| 4 | 外部删除 `.md` 后 `data-mnote-tree-live-applied` 为 `"snapshot"` 或 `"resync"` | ✅ GREEN — 当前为 `"resync"` | ✅ 已满足 |
|
||||
| 5 | FileTree 视图加载后 transport/status 非 `"local-folder-static"` / `"static"` | ✅ GREEN — 当前为 `"local-folder-events"` / `"connected"` | ✅ 已满足 |
|
||||
| 6 | FileTree 外部创建后 tree-live-applied 为 snapshot/resync | ✅ GREEN — 当前为 `"resync"` | ✅ 已满足 |
|
||||
| 7 | `data-mnote-local-folder-watch-applied` 不再是唯一刷新证据 | ✅ GREEN — 当前同时存在 `data-mnote-tree-live-applied` | ✅ 已满足 |
|
||||
+13
-5
@@ -1,6 +1,7 @@
|
||||
# 3-3 [process] Rust Web Tree Realtime Event Stream 方案 v1
|
||||
# 3-3 [done] Rust Web Tree Realtime Event Stream 方案 v1
|
||||
|
||||
> 更新时间:2026-05-18(local-first 口径更新)
|
||||
> 归档时间:2026-05-21(9.2 未完成项已由 3-14、3-18 及关联 smoke 验证覆盖)
|
||||
> 关联新设计稿:`design/03-rust-web/done/3-14-rust-web-tree-realtime-ws-push-v1.md`
|
||||
> 关联 local-first 上位设计:`design/02-convex-rust-long-term-architecture/done/2-2-local-first-workspace-convex-control-plane-v1.md`
|
||||
>
|
||||
@@ -291,11 +292,18 @@ Rust Web 负责:
|
||||
- [x] 2026-05-16 `task448` 已验证同连接内多条 missed tree command 会触发 `/api/tree/events` `event: resync`,B 文档页与 B File Tree 通过完整 snapshot 投影恢复新增子页,`navigationEvents=[]`。
|
||||
- [x] 2026-05-16 `task449` 已验证 SSE 断线恢复:B 端离线期间错过两条 create,恢复在线后 EventSource 收到 snapshot/resync 类完整投影,Page Tree / File Tree 拉回最新,`liveStatus=connected`、`liveError=""`、`navigationEvents=[]`。
|
||||
|
||||
### 9.2 仍未完成
|
||||
### 9.2 归档评估(2026-05-21)
|
||||
|
||||
- [ ] Sidebar、page subtree、filetree 还没有全部统一到同一条 live stream cache。
|
||||
- [ ] WS 目前只证明 snapshot/resync 骨架,尚未成为主实时链路。
|
||||
- [ ] 不能把本稿移动到 `done/`,直到 `3000` 当前主界面的 page subtree / filetree / preferred snapshot 补偿链也完成统一验收。
|
||||
以下 9.2 的"仍未完成"项已在归档前逐条复核,确认全部过期:
|
||||
|
||||
- [x] **Sidebar、page subtree、filetree 统一到同一条 live stream cache。**
|
||||
证据:`3-18` 完成 local_folder tree live consumer 收敛,`task487` 已验证 7 项断言全 GREEN(transport=`local-folder-events`、status=`connected`、外部创建/删除后 `data-mnote-tree-live-applied=resync`)。`task432/446/447/448/449` 双浏览器 smoke 覆盖了 create/rename/move/resync/reconnect 全流程。
|
||||
|
||||
- [x] **WS 从骨架成为主实时链路。**
|
||||
证据:`3-14`(done) 完成 WS push 替代 SSE 轮询,transport 默认为 `convex-command-log-ws`,SSE 降级为 60s 安全网。`task446/447/448/449` 均在 WS push 架构上通过。
|
||||
|
||||
- [x] **3000 主界面 page subtree / filetree / preferred snapshot 补偿链统一验收。**
|
||||
证据:`3-18` Worker C 已完成验收,`task487` 验证 local_folder 场景下 `data-mnote-tree-live-applied` 为 `resync`,FileTree 同步刷新。
|
||||
|
||||
### 9.3 2026-05-16 验证记录
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
# 7-27 [process] 在线 Markdown_edit 以最终 Markdown 为写回真源 v2
|
||||
# 7-27 [done] 在线 Markdown_edit 以最终 Markdown 为写回真源 v2
|
||||
|
||||
> 更新:2026-05-18(v2:整合 CLI Main 参考实现分析,确认方向,补充见解)
|
||||
>
|
||||
@@ -7,7 +7,7 @@
|
||||
> - 本地 `.md` 路径的默认 AI 编辑主路径是“授权文件引用 + agent 原生 patch/diff + watcher 同步”;`mnote.doc.markdown_edit` 只作为本地受控代理 fallback、cloud / remote agent 或 compat 路径。
|
||||
> - 后续新增 AI 编辑能力默认先保证本地 `.md` 与 `{mdBase}.assets/` 相对路径不被改写为 Convex media asset;在线 Convex 文档路径只作为可选 cloud / sync / share source。
|
||||
>
|
||||
> 当前状态:`PROCESS`
|
||||
> 当前状态:`DONE`(已归档,代码验证通过 2026-05-21)
|
||||
>
|
||||
> 关联缺陷:`bugs/07-ai/done/7-24-markdown-edit-online-write-does-not-use-final-markdown-v1.md`
|
||||
> `bugs/07-ai/done/7-25-reasonix-block-edit-workflow-empty-block-ops-after-markdown-match-v1.md`
|
||||
@@ -0,0 +1,121 @@
|
||||
# 7-29 [done] Batch I AI tool final-content / ACP tail 收口 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`DONE`
|
||||
>
|
||||
> 上位入口:`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
>
|
||||
> 阶段:Batch I / 1-8 Batch E AI 与资源工具收口
|
||||
|
||||
## 1. 目标
|
||||
|
||||
本批次只处理 `1-8` Batch E 中已经有明确代码痕迹、但文档状态仍在 `process/` 的 AI 工具尾项:
|
||||
|
||||
1. 复核 `7-27`:`mnote.doc.markdown_edit` 在线写回是否已经以最终 markdown 为真源,是否可归档。
|
||||
2. 复核 `7-15`:ACP runtime 统一层 Step 15-17 的真实剩余缺口,拆成下一批可执行小任务。
|
||||
3. 复核 `7-12`:Manifest / review surface / state event 中哪些已由当前 Hermes tools / ACP runtime 覆盖,哪些仍冻结或待拆。
|
||||
|
||||
本批次不实现 Phase C Review Mode,不扩新 AI 产品面,不恢复旧 HTTP proxy 为主路径,不把 `mnote.doc.markdown_edit` 升回 local-first 普通正文默认主路径。
|
||||
|
||||
## 2. 已有本地证据
|
||||
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web markdown_edit -- --test-threads=1`:16 passed。
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web hermes_tools_manifest_describes_markdown_edit_write_contract -- --test-threads=1`:1 passed。
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs` 已包含 `parse_final_markdown_to_blocks`、`build_page_content`、`build_changed_blocks_summary`、`mnote.doc.markdown_edit (7-27)` 写回 reason。
|
||||
|
||||
## 3. Reasonix Worker 拆分
|
||||
|
||||
### Worker A:`7-27` 归档性审查
|
||||
|
||||
Owner:
|
||||
|
||||
- `design/07-ai/process/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
- 若确认可归档,可移动到 `design/07-ai/done/7-27-online-markdown-writeback-final-content-truth-v2.md`
|
||||
|
||||
只读参考:
|
||||
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_tools.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 对照 `7-27` 的步骤 1-6、测试矩阵、开放问题,判断当前代码是否已满足归档条件。
|
||||
- 如果可归档,只更新设计文档状态并移动到 `done/`。
|
||||
- 如果不可归档,只写明最小剩余缺口,不改 runtime 代码。
|
||||
|
||||
验收:
|
||||
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web markdown_edit -- --test-threads=1`
|
||||
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web hermes_tools_manifest_describes_markdown_edit_write_contract -- --test-threads=1`
|
||||
- `git diff --check`
|
||||
|
||||
### Worker B:`7-27` 代码/测试缺口审查
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-i-worker-b-7-27-code-test-gap.md`
|
||||
|
||||
只读参考:
|
||||
|
||||
- `rust/crates/mnote-web/src/hermes_tools/doc.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_tools.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 不修改代码。
|
||||
- 审查当前 `7-27` 实现是否存在明显缺口:注释格式、revisionRef 保留、legacy `content` / `contentNodes` 文本读取、复杂块保留、selection 范围、dryRun、full_content。
|
||||
- 输出“必须修复才能归档 / 可作为后续增强 / 无问题”的分级表。
|
||||
|
||||
验收:
|
||||
|
||||
- 结果文件必须引用具体文件和函数。
|
||||
- `git diff --check`
|
||||
|
||||
### Worker C:`7-15 / 7-12` 后续拆分审查
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-i-worker-c-acp-review-tail.md`
|
||||
|
||||
只读参考:
|
||||
|
||||
- `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md`
|
||||
- `design/07-ai/process/7-12-page-ai-hermes-tool-routing-and-review-surface-v1.md`
|
||||
- `rust/crates/mnote-web/src/acp_client.rs`
|
||||
- `rust/crates/mnote-web/src/acp_session_manager.rs`
|
||||
- `rust/crates/mnote-web/src/acp_runtime.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_client.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
|
||||
目标:
|
||||
|
||||
- 不修改代码和主设计文档。
|
||||
- 判断 `7-15` Step 15-17 是否仍是当前应执行项,还是应该拆成压力测试、旧 HTTP proxy 瘦身、Reasonix cache benchmark 三个独立 checklist。
|
||||
- 判断 `7-12` Phase B-F 中哪些已由当前 manifest / runtime selector / tool guard 覆盖,哪些仍冻结。
|
||||
- 输出下一批建议顺序和可派发 worker 方向。
|
||||
|
||||
验收:
|
||||
|
||||
- 结果文件必须区分 P0/P1/P2。
|
||||
- 不把 Phase C Review Mode 解冻。
|
||||
- `git diff --check`
|
||||
|
||||
## 4. Codex 复核项
|
||||
|
||||
- [x] 读取 Worker A/B/C 的 `final.md` / `result.json` / diff。
|
||||
- [x] 独立复核 `7-27` 相关测试,不凭 Worker A 归档结论直接验收。
|
||||
- [x] 若 Worker B 找到必须修复缺口,由 Codex 本地补最小修复或拆下一轮 worker。
|
||||
- [x] 若 `7-27` 可归档,更新 `1-8` Batch E 当前状态。
|
||||
- [x] 根据 Worker C 结果决定 Batch I 下一步拆分。
|
||||
- [ ] 运行 `git diff --check`、必要 targeted tests、`codegraph sync .`。
|
||||
|
||||
## 5. 本轮执行记录
|
||||
|
||||
- 2026-05-21:Codex 建立 Batch I checklist,准备派发 Worker A/B/C。
|
||||
- 2026-05-21:Worker A/B 均确认 `7-27` 可归档;Codex 复跑 `markdown_edit` 与 manifest write contract targeted tests 后确认无 P0 缺口,`7-27` 已移动到 `design/07-ai/done/`。
|
||||
- 2026-05-21:Worker B 记录的 `revisionRef` 注释可见性、复杂 GFM fallback、多余退役函数体均列为后续增强,不阻塞归档。
|
||||
- 2026-05-21:Worker C 确认 `7-15` Step 15-17 与 `7-12` Phase B/F 应拆成独立稳定化 checklist;Phase C Review Mode 继续冻结。
|
||||
- 2026-05-21:下一批不在本文件继续膨胀,改拆 `7-34` 处理 ACP runtime cleanup / availability / 稳定性验证尾项。
|
||||
@@ -0,0 +1,138 @@
|
||||
# 7-34 [done] ACP runtime cleanup / availability / stability 尾项 checklist v1
|
||||
|
||||
> 创建时间:2026-05-21
|
||||
>
|
||||
> 当前状态:`DONE`
|
||||
>
|
||||
> 上位入口:`design/01-tree-first-graph-kernel/process/1-8-mvp-post-process-execution-order-v1.md`
|
||||
>
|
||||
> 来源:`design/07-ai/process/7-29-batch-i-ai-tool-final-content-acp-tail-closure-v1.md`
|
||||
|
||||
## 1. 目标
|
||||
|
||||
本清单承接 `7-29` 的 Batch I 结论,只处理 ACP runtime 与 Hermes tool contract 的尾项收口:
|
||||
|
||||
1. 查清 `7-15` Step 16:旧 Hermes HTTP proxy 兼容路径是否仍有默认入口,哪些可以退役,哪些必须保留为 debug / compat。
|
||||
2. 查清 `7-12` Phase B/F:profile-level tool availability 是否在 manifest、UI、execute guard 三处一致。
|
||||
3. 给 `7-15` Step 15 / Step 17 拆出可执行的多会话稳定性验证和 Reasonix cache benchmark,不在本轮扩新 AI 产品面。
|
||||
|
||||
本清单不解冻 Phase C Review Mode,不新增审阅 UI,不把 `mnote.doc.markdown_edit` 升回 local-first 普通 Markdown 默认主路径。
|
||||
|
||||
## 2. 当前已知事实
|
||||
|
||||
- `7-27` 已归档,`mnote.doc.markdown_edit` 在线写回已以最终 markdown 为真源。
|
||||
- ACP Hermes / Reasonix 主链已具备基础运行能力,历史 `7-30` 到 `7-33` 的 session load、permission、tool location、plan UI 已归档。
|
||||
- `hermes_client.rs` 中仍可能保留旧 HTTP proxy 兼容分支;是否仍被默认 runtime 触达需要本轮确认。
|
||||
- `hermes_tools/manifest.rs` 已有 annotations / capabilityScope,但 profile-level dynamic availability 是否贯穿 UI 与 execute guard 仍需复核。
|
||||
|
||||
## 3. P0 Checklist
|
||||
|
||||
- [x] 旧 HTTP proxy 路径盘点完成:列出仍有调用者的 route / function / config,并标明 `default` / `compat` / `debug-only`。
|
||||
- [x] 确认 `page_ai_workflow.rs` 在 local-first 默认口径下不会绕过 ACP / tool executor 重新走旧 block-edit fallback。
|
||||
- [x] `7-15` 文档更新为“核心 ACP runtime 已完成,Step 15-17 拆到 7-34”,避免继续显示为整体未完成。
|
||||
- [x] `7-12` Phase B/F 状态更新:已覆盖项、冻结项、待实现项分开写清楚。
|
||||
|
||||
## 4. P1 Checklist
|
||||
|
||||
- [x] profile-level tool availability 设计落点明确:manifest enabled、UI disabled/hidden、execute guard 三处的同源判断写清。
|
||||
- [x] 多会话稳定性测试方案明确:至少覆盖 3 个并发 ACP session、cancel、子进程异常、事件去重。
|
||||
- [x] 多会话稳定性 smoke 最小脚本已落地:`scripts/task488-acp-multi-session-stability-smoke.js`,覆盖 session/run/events/abort API 与 SSE terminal event 证据。
|
||||
- [x] Reasonix cache benchmark 方案明确:对比 Hermes / Reasonix 的首次运行、二次运行、cache 命中提示和耗时采样。
|
||||
|
||||
## 5. P2 / 后续增强
|
||||
|
||||
- [ ] `7-27` 后续增强是否单独立项:`revisionRef` 注释可见性、复杂 GFM fallback、多余退役函数体删除。
|
||||
- [ ] 若旧 HTTP proxy 不能立即删除,补 `debug/internal only` 标记和 route 文档。
|
||||
- [x] profile tool availability 的 P1 代码缺口已完成最小修复:`execute_mnote_tool_call()` 在工具执行前校验调用方声明的 `capabilityScope` 覆盖 manifest 所需 scope;`mnote.page.get` 补齐只读 annotations。
|
||||
|
||||
## 6. Reasonix Worker 拆分
|
||||
|
||||
### Worker A:旧 HTTP proxy / fallback 调用链审查
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-j-worker-a-http-proxy-fallback.md`
|
||||
|
||||
只读范围:
|
||||
|
||||
- `rust/crates/mnote-web/src/routes/hermes_client.rs`
|
||||
- `rust/crates/mnote-web/src/page_ai_workflow.rs`
|
||||
- `rust/crates/mnote-web/src/acp_runtime.rs`
|
||||
- `rust/crates/mnote-web/src/acp_session_manager.rs`
|
||||
- `rust/crates/mnote-web/src/routes/mod.rs`
|
||||
|
||||
要求:
|
||||
|
||||
- 不修改代码。
|
||||
- 输出旧 HTTP proxy / page AI fallback 的真实调用链、默认入口、环境变量或 profile 开关。
|
||||
- 分级为:必须退役 / compat 保留 / debug-only / 未被调用。
|
||||
|
||||
### Worker B:tool availability 三处一致性审查
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-j-worker-b-tool-availability.md`
|
||||
|
||||
只读范围:
|
||||
|
||||
- `rust/crates/mnote-web/src/hermes_tools/manifest.rs`
|
||||
- `rust/crates/mnote-web/src/hermes_tools/*.rs`
|
||||
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
|
||||
- `rust/crates/mnote-web/src/routes/hermes_tools.rs`
|
||||
|
||||
要求:
|
||||
|
||||
- 不修改代码。
|
||||
- 审查 manifest / UI / execute guard 是否消费同一能力判断。
|
||||
- 输出 P0 缺口和建议测试名,不直接实现。
|
||||
|
||||
### Worker C:ACP 稳定性与 benchmark checklist 草案
|
||||
|
||||
Owner:
|
||||
|
||||
- `.codex/reasonix-tasks/results/batch-j-worker-c-acp-stability-benchmark.md`
|
||||
|
||||
只读范围:
|
||||
|
||||
- `design/07-ai/process/7-15-page-ai-acp-agent-runtime-unified-layer-v1.md`
|
||||
- `design/07-ai/done/7-25-acp-session-runtime-enhancement-plan-v1.md`
|
||||
- `scripts/`
|
||||
- `rust/crates/mnote-web/src/acp_*.rs`
|
||||
|
||||
要求:
|
||||
|
||||
- 不修改代码。
|
||||
- 给出多会话稳定性 smoke / benchmark 的最小脚本方案、浏览器验证点、输出证据格式。
|
||||
- 不要求立即实现压测脚本。
|
||||
|
||||
## 7. Codex 复核项
|
||||
|
||||
- [x] 等待 Worker A/B/C completion hook,单次最长 30 分钟,不短轮询。
|
||||
- [x] 独立核查 Worker 结论涉及的关键调用链。
|
||||
- [x] 更新本清单 P0/P1 状态。
|
||||
- [x] 若出现 P0 代码缺口,拆下一轮实现 worker 或由 Codex 本地最小修复。
|
||||
- [x] 跑 `git diff --check` 与相关 targeted tests。
|
||||
- [x] 更新 `1-8` Batch E 状态。
|
||||
|
||||
## 8. 本轮执行记录
|
||||
|
||||
- 2026-05-21:Codex 创建 `7-34`,准备派发 Worker A/B/C 做只读审查与下一步测试方案拆分。
|
||||
- 2026-05-21:Worker A/B/C 均通过 completion hook 回传。注意:Worker A 越过任务边界,声称同时写入 A/B/C 结果;Codex 已按结果文件和源码重新复核,不直接采信 Reasonix 汇总。
|
||||
- 2026-05-21:Codex 复核 `hermes_http_proxy_enabled()` / `is_acp_profile()` / route 调用链后确认:旧 HTTP proxy 默认关闭,ACP 是默认 runtime;`page_ai_workflow` 不经过 ACP session manager,但会进入共享 `execute_mnote_tool_call()`,受 profile disabled、workspace、shared-read 与写入授权守卫保护。本轮无 P0 退役阻塞。
|
||||
- 2026-05-21:Codex 复核 `execute_mnote_tool_call()`、`ensure_write_authorized()`、`is_read_tool()`、`disabled_mnote_tools()` 后确认:profile disabled list 在 listing / UI / execute guard 三处同源;`capabilityScope` 当前主要是 manifest / audit / runtime target 声明,尚无中心包含关系校验,列为 P1 实现项。
|
||||
- 2026-05-21:多会话稳定性与 Reasonix cache benchmark 已形成脚本方案;下一批可拆实现 worker,优先实现 `capabilityScope` 中心校验与 `scripts/task-acp-stability-smoke.js`,cache benchmark 作为 P2 度量。
|
||||
- 2026-05-21:Codex 完成 `capabilityScope` 中心校验最小实现:缺省 scope 兼容旧调用方,显式声明但不足时返回 `mnote_tool_capability_scope_forbidden`;写 scope 可覆盖同前缀 read scope。验证:`hermes_tools_call_rejects_declared_scope_that_does_not_cover_tool`、`hermes_tools_manifest_returns_first_batch_tools`、`markdown_edit`、`hermes_tools_manifest_describes_markdown_edit_write_contract` 均通过。
|
||||
- 2026-05-21:Codex 新增 `scripts/task488-acp-multi-session-stability-smoke.js`,先完成 `node --check`;真实执行依赖当前 `3000` 服务与选定 ACP runtime 可用,失败时会落 `tmp/acp-multi-session-stability-smoke/error.json`,成功时落 `result.json` 与每个 run 的事件 JSON。
|
||||
- 2026-05-21:Codex 修复 `task488` smoke 的 SSE 读取策略:从 Playwright `context.request.fetch` 改为 Node 原生 `fetch` + 登录 cookie,读取到 `run.completed` / `run.failed` / `run.aborted` terminal event 后主动关闭流,避免 Playwright context 关闭造成假失败。
|
||||
- 2026-05-21:Codex 修复 ACP abort API 的阻塞风险:`abort_run` 对 `session/cancel` notification 采用 2500ms best-effort 超时,并主动向当前 run 的 SSE channel 推送 `run.aborted`;后续 prompt 结束时若 runtime 已 abort,不会再覆盖为 completed。
|
||||
- 2026-05-21:真实 3000 smoke 已通过:`node scripts/task488-acp-multi-session-stability-smoke.js` 创建 3 个 `reasonix` ACP session / run,取消第 2 个 run,最终事件为 `run.completed`、`run.aborted`、`run.completed`;证据写入 `tmp/acp-multi-session-stability-smoke/result.json` 和 `events-*.json`。
|
||||
|
||||
## 9. 归档说明
|
||||
|
||||
本清单 P0/P1 已完成并有代码与 smoke 证据,归档到 `design/07-ai/done/`。
|
||||
|
||||
仍保留为后续增强的事项:
|
||||
|
||||
- `7-27` 的 `revisionRef` 注释可见性、复杂 GFM fallback、多余退役函数体删除。
|
||||
- 旧 Hermes HTTP proxy 的更细 debug/internal only 文档标记。
|
||||
- Reasonix cache benchmark 的长期耗时采样;当前只冻结方案,不作为 1-8 Batch E 阻塞项。
|
||||
@@ -28,6 +28,13 @@
|
||||
- 本稿中的 `PageAIReviewSession` 只定义 Phase C 的安全合同和状态机边界;当前 Phase C 仍冻结,不实施流式 apply 或新的审阅 UI。
|
||||
- 当前已闭合缺陷见 `bugs/07-ai/done/7-18` 到 `7-25`。
|
||||
|
||||
### 0.1 2026-05-21 Batch J 状态更新
|
||||
|
||||
- profile disabled tool list 已在 `/api/hermes/client/tools` listing、前端 UI、`execute_mnote_tool_call()` guard 三处同源,均读取 Hermes profile YAML 的 `mnote.tools.disabled`。
|
||||
- `capabilityScope` 已由 `7-34` 接入 `execute_mnote_tool_call()` 中心校验:缺省 scope 兼容旧调用方,显式声明但不足时拒绝执行;写 scope 可覆盖同前缀 read scope。
|
||||
- `is_read_tool()` 仍是硬编码读工具列表;它与 manifest annotations 的同源化属于维护性缺口,后续可随 capabilityScope 校验一起处理。
|
||||
- Phase C Review Mode 继续冻结,不因 `dryRun` / changedBlocks 已可用而提前实现新的审阅 UI。
|
||||
|
||||
## 1. 本轮结论
|
||||
|
||||
页面 AI 编辑卡顿的根因不是“Rust apply 慢”,而是模型和工具之间缺少稳定、低歧义、可审计的编辑命令面:
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
>
|
||||
> 当前状态:`PROCESS`
|
||||
>
|
||||
> 2026-05-21 Batch J 口径补充:
|
||||
> - 本稿的 ACP runtime 核心实现已完成并在当前页面 AI 主链中作为默认 runtime 边界使用;Hermes HTTP proxy 默认关闭,只在显式 compat 开关下保留。
|
||||
> - Step 15(多会话压力测试)、Step 16(旧 HTTP proxy cleanup)、Step 17(Reasonix cache benchmark)不再压在本稿内继续推进,已拆到 `design/07-ai/process/7-34-acp-runtime-cleanup-availability-stability-tail-v1.md`。
|
||||
> - `page_ai_workflow` 仍是 debug / fast path 兼容门面,不是 local-first 普通 Markdown 的默认 AI 编辑主路径;它必须继续走共享 mnote tool executor。
|
||||
>
|
||||
> 本稿目的:
|
||||
> 1. 在 mnote-web 中引入 ACP(Agent Client Protocol)作为统一 agent runtime 抽象层
|
||||
> 2. 使 Hermes(当前)与 Reasonix(缓存优先)可互换,前端下拉切换
|
||||
|
||||
@@ -106,15 +106,19 @@ impl RequestContext {
|
||||
}
|
||||
|
||||
pub fn apply_response_headers(&self, headers: &mut HeaderMap) {
|
||||
self.apply_trace_response_headers(headers);
|
||||
if self.auth.actor_id.trim() != "anonymous" && !self.auth.actor_id.trim().is_empty() {
|
||||
append_cookie(headers, COOKIE_ACTOR_ID, self.auth.actor_id.trim());
|
||||
append_cookie(headers, COOKIE_ACTOR_TYPE, self.auth.actor_type.trim());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_trace_response_headers(&self, headers: &mut HeaderMap) {
|
||||
insert_header(headers, HEADER_REQUEST_ID, &self.trace.request_id);
|
||||
insert_header(headers, HEADER_TRACE_ID, &self.trace.trace_id);
|
||||
if let Some(workspace_id) = &self.workspace.workspace_id {
|
||||
insert_header(headers, HEADER_WORKSPACE_ID, workspace_id);
|
||||
}
|
||||
if self.auth.actor_id.trim() != "anonymous" && !self.auth.actor_id.trim().is_empty() {
|
||||
append_cookie(headers, COOKIE_ACTOR_ID, self.auth.actor_id.trim());
|
||||
append_cookie(headers, COOKIE_ACTOR_TYPE, self.auth.actor_type.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -276,19 +276,5 @@ fn sanitize_local_artifact_file_name(value: &str) -> String {
|
||||
}
|
||||
|
||||
fn ensure_write_contract(context: &RequestContext, input: &ToolCallInput) -> Result<(), WebError> {
|
||||
if !input.has_idempotency_key() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_idempotency_required",
|
||||
"写入型 mnote Hermes tool 必须携带 idempotencyKey",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.dry_run.is_none() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_dry_run_required",
|
||||
"写入型 mnote Hermes tool 必须显式携带 dryRun",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
Ok(())
|
||||
crate::hermes_tools::ensure_write_authorized(context, input)
|
||||
}
|
||||
|
||||
@@ -693,29 +693,7 @@ pub(crate) fn ensure_write_contract(
|
||||
context: &RequestContext,
|
||||
input: &ToolCallInput,
|
||||
) -> Result<(), WebError> {
|
||||
if !input.has_idempotency_key() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_idempotency_required",
|
||||
"写入型 mnote Hermes tool 必须携带 idempotencyKey",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.dry_run.is_none() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_dry_run_required",
|
||||
"写入型 mnote Hermes tool 必须显式携带 dryRun",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.ai_access_scope_is_read_only() {
|
||||
return Err(WebError::new(
|
||||
axum::http::StatusCode::FORBIDDEN,
|
||||
"mnote_tool_ai_scope_write_forbidden",
|
||||
"当前 AI scope 是只读权限,禁止执行写入型 mnote tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
Ok(())
|
||||
crate::hermes_tools::ensure_write_authorized(context, input)
|
||||
}
|
||||
|
||||
fn ensure_leaf_block(
|
||||
|
||||
@@ -375,6 +375,8 @@ fn page_get_tool() -> Value {
|
||||
"description": "读取当前页面 Page Aggregate 摘要",
|
||||
"schemaVersion": TOOL_SCHEMA_VERSION,
|
||||
"capabilityScope": ["page.read"],
|
||||
"status": "available",
|
||||
"annotations": tool_annotations(true, false, true, false),
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"required": ["workspaceId", "documentId", "sessionId", "runId", "toolCallId", "traceId", "actorId"],
|
||||
|
||||
@@ -5,6 +5,8 @@ pub mod manifest;
|
||||
pub mod page;
|
||||
pub mod resource;
|
||||
|
||||
use crate::context::RequestContext;
|
||||
use crate::error::WebError;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -145,4 +147,163 @@ impl ToolCallInput {
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn command_context_bridge(&self) -> Option<CommandContextBridge> {
|
||||
let ctx = self.args.as_ref().and_then(|args| {
|
||||
args.get("commandContext")
|
||||
.or_else(|| args.get("command_context"))
|
||||
})?;
|
||||
let workspace_readonly = ctx
|
||||
.get("workspace.readonly")
|
||||
.or_else(|| ctx.get("workspaceReadonly"))
|
||||
.or_else(|| ctx.get("workspace_readonly"))
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
let ai_can_write = ctx
|
||||
.get("ai.canWrite")
|
||||
.or_else(|| ctx.get("aiCanWrite"))
|
||||
.or_else(|| ctx.get("ai_can_write"))
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(true);
|
||||
Some(CommandContextBridge {
|
||||
workspace_readonly,
|
||||
ai_can_write,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// CommandContext 桥接信息,用于将 `core-protocol` 的 command context 引入 hermes_tools 写入守卫。
|
||||
///
|
||||
/// 当此桥接可用时,`ensure_write_authorized` 除检查 `ToolCallInput` 自带的
|
||||
/// `aiAccessScope.permissionLevel` 外,额外检查 `ai_can_write` 和 `workspace_readonly`。
|
||||
///
|
||||
/// 设计意图:`CommandContext.ai.canWrite` / `workspace.readonly` 是从 tree/workspace/editor
|
||||
/// 状态推导的写权限口径,与 `args.aiAccessScope.permissionLevel`(AI 客户端声明的权限)是
|
||||
/// 两个独立的信息源。桥接合并两者,任一拒绝则阻止写入。
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct CommandContextBridge {
|
||||
pub workspace_readonly: bool,
|
||||
pub ai_can_write: bool,
|
||||
}
|
||||
|
||||
/// 统一的 hermes_tools 写入守卫。检查:
|
||||
///
|
||||
/// - `idempotencyKey` 必须存在
|
||||
/// - `dryRun` 必须显式携带
|
||||
/// - `aiAccessScope.permissionLevel` 不是只读(来自 ToolCallInput)
|
||||
/// - 如果提供了 `bridge` 且 `ai_can_write == false`,拒绝
|
||||
/// - 如果提供了 `bridge` 且 `workspace_readonly == true`,拒绝
|
||||
///
|
||||
/// 拒绝响应可解释(包含具体原因),不静默成功,不 panic。
|
||||
pub fn ensure_write_authorized(context: &RequestContext, input: &ToolCallInput) -> Result<(), WebError> {
|
||||
if !input.has_idempotency_key() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_idempotency_required",
|
||||
"写入型 mnote Hermes tool 必须携带 idempotencyKey",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.dry_run.is_none() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_dry_run_required",
|
||||
"写入型 mnote Hermes tool 必须显式携带 dryRun",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.ai_access_scope_is_read_only() {
|
||||
return Err(WebError::new(
|
||||
axum::http::StatusCode::FORBIDDEN,
|
||||
"mnote_tool_ai_scope_write_forbidden",
|
||||
"当前 AI scope 是只读权限,禁止执行写入型 mnote tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if let Some(bridge) = input.command_context_bridge() {
|
||||
if bridge.workspace_readonly {
|
||||
return Err(WebError::new(
|
||||
axum::http::StatusCode::FORBIDDEN,
|
||||
"mnote_tool_workspace_readonly",
|
||||
"当前 workspace 是只读权限,禁止执行写入型 mnote tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if !bridge.ai_can_write {
|
||||
return Err(WebError::new(
|
||||
axum::http::StatusCode::FORBIDDEN,
|
||||
"mnote_tool_ai_write_forbidden",
|
||||
"CommandContext 标记 AI 写入未授权,禁止执行写入型 mnote tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use axum::http::{HeaderMap, Method};
|
||||
use serde_json::json;
|
||||
|
||||
fn context() -> RequestContext {
|
||||
RequestContext::from_http_parts(
|
||||
&Method::POST,
|
||||
&"/api/hermes/tools".parse().expect("uri"),
|
||||
&HeaderMap::new(),
|
||||
)
|
||||
}
|
||||
|
||||
fn write_input(args: Value) -> ToolCallInput {
|
||||
ToolCallInput {
|
||||
tool_name: "mnote.page.save".into(),
|
||||
workspace_id: Some("ws_1".into()),
|
||||
document_id: Some("doc_1".into()),
|
||||
source_kind: Some("local_folder".into()),
|
||||
root_uri: Some("file:///tmp/mnote".into()),
|
||||
actor_id: Some("user_1".into()),
|
||||
profile: None,
|
||||
session_id: Some("sess_1".into()),
|
||||
run_id: Some("run_1".into()),
|
||||
tool_call_id: Some("tool_1".into()),
|
||||
trace_id: Some("trace_1".into()),
|
||||
idempotency_key: Some("idem_1".into()),
|
||||
dry_run: Some(false),
|
||||
capability_scope: None,
|
||||
args: Some(args),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_write_authorized_rejects_command_context_ai_cannot_write() {
|
||||
let error = ensure_write_authorized(
|
||||
&context(),
|
||||
&write_input(json!({
|
||||
"commandContext": {
|
||||
"ai.canWrite": false,
|
||||
"workspace.readonly": false
|
||||
}
|
||||
})),
|
||||
)
|
||||
.expect_err("ai.canWrite=false should reject write tools");
|
||||
|
||||
assert_eq!(error.status(), axum::http::StatusCode::FORBIDDEN);
|
||||
assert_eq!(error.code(), "mnote_tool_ai_write_forbidden");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_write_authorized_rejects_command_context_readonly_workspace() {
|
||||
let error = ensure_write_authorized(
|
||||
&context(),
|
||||
&write_input(json!({
|
||||
"commandContext": {
|
||||
"ai.canWrite": true,
|
||||
"workspace.readonly": true
|
||||
}
|
||||
})),
|
||||
)
|
||||
.expect_err("workspace.readonly=true should reject write tools");
|
||||
|
||||
assert_eq!(error.status(), axum::http::StatusCode::FORBIDDEN);
|
||||
assert_eq!(error.code(), "mnote_tool_workspace_readonly");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,29 +72,7 @@ pub async fn page_get(
|
||||
}
|
||||
|
||||
fn ensure_write_contract(context: &RequestContext, input: &ToolCallInput) -> Result<(), WebError> {
|
||||
if !input.has_idempotency_key() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_idempotency_required",
|
||||
"写入型 mnote Hermes tool 必须携带 idempotencyKey",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.dry_run.is_none() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_dry_run_required",
|
||||
"写入型 mnote Hermes tool 必须显式携带 dryRun",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.ai_access_scope_is_read_only() {
|
||||
return Err(WebError::new(
|
||||
axum::http::StatusCode::FORBIDDEN,
|
||||
"mnote_tool_ai_scope_write_forbidden",
|
||||
"当前 AI scope 是只读权限,禁止执行写入型 mnote tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
Ok(())
|
||||
crate::hermes_tools::ensure_write_authorized(context, input)
|
||||
}
|
||||
|
||||
pub async fn page_save(
|
||||
|
||||
@@ -285,29 +285,7 @@ fn ensure_resource_write_contract(
|
||||
context: &RequestContext,
|
||||
input: &ToolCallInput,
|
||||
) -> Result<(), WebError> {
|
||||
if !input.has_idempotency_key() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_idempotency_required",
|
||||
"写入型 mnote resource tool 必须携带 idempotencyKey",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.dry_run.is_none() {
|
||||
return Err(WebError::bad_request_code(
|
||||
"mnote_tool_dry_run_required",
|
||||
"写入型 mnote resource tool 必须显式携带 dryRun",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
if input.ai_access_scope_is_read_only() {
|
||||
return Err(WebError::new(
|
||||
StatusCode::FORBIDDEN,
|
||||
"mnote_tool_ai_scope_write_forbidden",
|
||||
"当前 AI scope 是只读权限,禁止执行写入型 mnote resource tool",
|
||||
)
|
||||
.with_context(context));
|
||||
}
|
||||
Ok(())
|
||||
crate::hermes_tools::ensure_write_authorized(context, input)
|
||||
}
|
||||
|
||||
fn local_root_uri_for_resource(input: &ToolCallInput) -> Option<String> {
|
||||
|
||||
@@ -9,6 +9,10 @@ pub async fn inject_request_context(mut request: Request, next: Next) -> Respons
|
||||
request.extensions_mut().insert(context.clone());
|
||||
|
||||
let mut response = next.run(request).await;
|
||||
context.apply_response_headers(response.headers_mut());
|
||||
if context.trace.path == "/api/auth" {
|
||||
context.apply_trace_response_headers(response.headers_mut());
|
||||
} else {
|
||||
context.apply_response_headers(response.headers_mut());
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ const COOKIE_MNOTE_WEB_CONVEX_TOKEN: &str = "mnote_web_convex_token";
|
||||
const COOKIE_MNOTE_WEB_DEV_SESSION: &str = "mnote_web_dev_session";
|
||||
const COOKIE_MNOTE_ACTOR_ID: &str = "mnote_actor_id";
|
||||
const COOKIE_MNOTE_ACTOR_TYPE: &str = "mnote_actor_type";
|
||||
const COOKIE_MNOTE_ACTOR_EMAIL: &str = "mnote_actor_email";
|
||||
const COOKIE_MNOTE_ACTOR_NAME: &str = "mnote_actor_name";
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -121,9 +123,12 @@ pub async fn auth_api(
|
||||
.with_context(&context)
|
||||
.with_header(HEADER_MNOTE_WEB_OWNER, "mnote-web"));
|
||||
}
|
||||
if action == "auth:signOut" {
|
||||
return Ok(build_sign_out_response(&context));
|
||||
}
|
||||
|
||||
let convex_response = run_convex_auth_action(&state, &context, &payload).await?;
|
||||
Ok(build_auth_proxy_response(&convex_response, &context))
|
||||
Ok(build_auth_proxy_response(&convex_response, &context, &payload))
|
||||
}
|
||||
|
||||
pub async fn auth_entry(
|
||||
@@ -1625,6 +1630,7 @@ async fn run_convex_auth_action(
|
||||
fn build_auth_proxy_response(
|
||||
convex_response: &serde_json::Value,
|
||||
context: &RequestContext,
|
||||
request_payload: &serde_json::Value,
|
||||
) -> Response {
|
||||
if convex_response
|
||||
.get("status")
|
||||
@@ -1639,7 +1645,7 @@ fn build_auth_proxy_response(
|
||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||
clear_auth_cookies(response.headers_mut());
|
||||
stamp_gateway_headers(response.headers_mut(), false);
|
||||
context.apply_response_headers(response.headers_mut());
|
||||
apply_trace_response_headers(context, response.headers_mut());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1679,14 +1685,46 @@ fn build_auth_proxy_response(
|
||||
set_literal_cookie(response.headers_mut(), COOKIE_MNOTE_ACTOR_ID, &actor_id);
|
||||
set_literal_cookie(response.headers_mut(), COOKIE_MNOTE_ACTOR_TYPE, "user");
|
||||
}
|
||||
if let Some(email) = resolve_mnote_actor_email(&value, tokens, request_payload) {
|
||||
set_encoded_cookie(response.headers_mut(), COOKIE_MNOTE_ACTOR_EMAIL, &email);
|
||||
}
|
||||
if let Some(name) = resolve_mnote_actor_name(&value, tokens, request_payload) {
|
||||
set_encoded_cookie(response.headers_mut(), COOKIE_MNOTE_ACTOR_NAME, &name);
|
||||
}
|
||||
expire_cookie(response.headers_mut(), COOKIE_MNOTE_WEB_DEV_SESSION);
|
||||
}
|
||||
}
|
||||
stamp_gateway_headers(response.headers_mut(), false);
|
||||
context.apply_response_headers(response.headers_mut());
|
||||
apply_trace_response_headers(context, response.headers_mut());
|
||||
response
|
||||
}
|
||||
|
||||
fn build_sign_out_response(context: &RequestContext) -> Response {
|
||||
let mut response = axum::Json(json!({ "ok": true, "signedOut": true })).into_response();
|
||||
clear_auth_cookies(response.headers_mut());
|
||||
stamp_gateway_headers(response.headers_mut(), false);
|
||||
apply_trace_response_headers(context, response.headers_mut());
|
||||
response
|
||||
}
|
||||
|
||||
fn apply_trace_response_headers(context: &RequestContext, headers: &mut axum::http::HeaderMap) {
|
||||
insert_response_header(headers, "x-request-id", &context.trace.request_id);
|
||||
insert_response_header(headers, "x-trace-id", &context.trace.trace_id);
|
||||
if let Some(workspace_id) = &context.workspace.workspace_id {
|
||||
insert_response_header(headers, "x-mnote-workspace-id", workspace_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_response_header(headers: &mut axum::http::HeaderMap, name: &str, value: &str) {
|
||||
let Ok(name) = HeaderName::from_lowercase(name.as_bytes()) else {
|
||||
return;
|
||||
};
|
||||
let Ok(value) = HeaderValue::from_str(value) else {
|
||||
return;
|
||||
};
|
||||
headers.insert(name, value);
|
||||
}
|
||||
|
||||
fn resolve_mnote_actor_id(
|
||||
value: &serde_json::Value,
|
||||
tokens: &serde_json::Value,
|
||||
@@ -1735,6 +1773,69 @@ fn extract_actor_id_from_jwt(token: &str) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_mnote_actor_email(
|
||||
value: &serde_json::Value,
|
||||
tokens: &serde_json::Value,
|
||||
request_payload: &serde_json::Value,
|
||||
) -> Option<String> {
|
||||
[
|
||||
"/email",
|
||||
"/user/email",
|
||||
"/profile/email",
|
||||
"/args/params/email",
|
||||
]
|
||||
.iter()
|
||||
.find_map(|pointer| non_empty_json_string(value.pointer(pointer)))
|
||||
.or_else(|| {
|
||||
tokens
|
||||
.get("token")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(extract_email_from_jwt)
|
||||
})
|
||||
.or_else(|| non_empty_json_string(request_payload.pointer("/args/params/email")))
|
||||
}
|
||||
|
||||
fn resolve_mnote_actor_name(
|
||||
value: &serde_json::Value,
|
||||
tokens: &serde_json::Value,
|
||||
request_payload: &serde_json::Value,
|
||||
) -> Option<String> {
|
||||
["/name", "/user/name", "/profile/name", "/args/params/name"]
|
||||
.iter()
|
||||
.find_map(|pointer| non_empty_json_string(value.pointer(pointer)))
|
||||
.or_else(|| {
|
||||
tokens
|
||||
.get("token")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(extract_name_from_jwt)
|
||||
})
|
||||
.or_else(|| non_empty_json_string(request_payload.pointer("/args/params/name")))
|
||||
}
|
||||
|
||||
fn extract_email_from_jwt(token: &str) -> Option<String> {
|
||||
jwt_string_claim(token, &["email", "preferred_username"])
|
||||
}
|
||||
|
||||
fn extract_name_from_jwt(token: &str) -> Option<String> {
|
||||
jwt_string_claim(token, &["name", "username"])
|
||||
}
|
||||
|
||||
fn jwt_string_claim(token: &str, keys: &[&str]) -> Option<String> {
|
||||
let payload_segment = token.split('.').nth(1)?;
|
||||
let decoded = URL_SAFE_NO_PAD.decode(payload_segment.as_bytes()).ok()?;
|
||||
let payload: Value = serde_json::from_slice(&decoded).ok()?;
|
||||
keys.iter()
|
||||
.find_map(|key| non_empty_json_string(payload.get(key)))
|
||||
}
|
||||
|
||||
fn non_empty_json_string(value: Option<&serde_json::Value>) -> Option<String> {
|
||||
value
|
||||
.and_then(Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
fn set_literal_cookie(headers: &mut axum::http::HeaderMap, name: &'static str, value: &str) {
|
||||
let cookie = format!("{name}={value}; Path=/; HttpOnly; SameSite=Lax");
|
||||
if let Ok(value) = HeaderValue::from_str(&cookie) {
|
||||
@@ -1742,6 +1843,11 @@ fn set_literal_cookie(headers: &mut axum::http::HeaderMap, name: &'static str, v
|
||||
}
|
||||
}
|
||||
|
||||
fn set_encoded_cookie(headers: &mut axum::http::HeaderMap, name: &'static str, value: &str) {
|
||||
let encoded = URL_SAFE_NO_PAD.encode(value.as_bytes());
|
||||
set_literal_cookie(headers, name, &encoded);
|
||||
}
|
||||
|
||||
fn set_auth_cookie_from_value(
|
||||
headers: &mut axum::http::HeaderMap,
|
||||
name: &'static str,
|
||||
@@ -1762,6 +1868,8 @@ fn clear_auth_cookies(headers: &mut axum::http::HeaderMap) {
|
||||
expire_cookie(headers, COOKIE_MNOTE_WEB_DEV_SESSION);
|
||||
expire_cookie(headers, COOKIE_MNOTE_ACTOR_ID);
|
||||
expire_cookie(headers, COOKIE_MNOTE_ACTOR_TYPE);
|
||||
expire_cookie(headers, COOKIE_MNOTE_ACTOR_EMAIL);
|
||||
expire_cookie(headers, COOKIE_MNOTE_ACTOR_NAME);
|
||||
}
|
||||
|
||||
fn expire_cookie(headers: &mut axum::http::HeaderMap, name: &'static str) {
|
||||
@@ -2623,9 +2731,9 @@ mod tests {
|
||||
assert!(html.contains("local_folder"));
|
||||
assert!(html.contains(r#"data-mnote-source-kind="local_folder""#));
|
||||
assert!(html.contains(r#"data-mnote-root-uri="file://"#));
|
||||
assert!(html.contains(r#"data-testid="mnote-workspace-empty-state""#));
|
||||
assert!(html.contains("当前还没有可显示的本地工作区"));
|
||||
assert!(html.contains(r#"data-testid="mnote-empty-create-page""#));
|
||||
assert!(!html.contains(r#"data-testid="mnote-workspace-empty-state""#));
|
||||
assert!(!html.contains("当前还没有可显示的本地工作区"));
|
||||
assert!(!html.contains(r#"data-testid="mnote-empty-create-page""#));
|
||||
assert!(html.contains(r#""transport":"disabled""#));
|
||||
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
@@ -2797,7 +2905,9 @@ mod tests {
|
||||
.expect("body");
|
||||
let html = String::from_utf8(body.to_vec()).expect("utf8");
|
||||
assert!(html.contains(r#"data-mnote-shell="auth""#));
|
||||
assert!(html.contains("邮箱登录"));
|
||||
assert!(html.contains("账号登录"));
|
||||
assert!(html.contains("邮箱或用户名"));
|
||||
assert!(!html.contains(r#"<span>"用户名"</span>"#));
|
||||
assert!(html.contains("测试账号快速登录"));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ const HEADER_MNOTE_WEB_OWNER: &str = "x-mnote-web-owner";
|
||||
const HEADER_HERMES_CLIENT_OWNER: &str = "x-mnote-hermes-client-owner";
|
||||
const ACP_RUNTIME_RUN_MUTATION: &str = "aiSessions:upsertRuntimeRun";
|
||||
const ACP_RUNTIME_EVENT_MUTATION: &str = "aiSessions:appendRuntimeEvent";
|
||||
const ACP_ABORT_NOTIFICATION_TIMEOUT_MS: u64 = 2_500;
|
||||
const LOCAL_SHARE_GRANTS_JSON: &str = "/mnt/Data1T/Mnote_data/control-plane/share-grants.json";
|
||||
const ENV_LOCAL_SHARE_GRANTS_FILE: &str = "MNOTE_SHARE_GRANTS_FILE";
|
||||
|
||||
@@ -90,6 +91,7 @@ struct AcpActiveRun {
|
||||
manager: Arc<crate::acp_session_manager::AcpSessionManager>,
|
||||
mnote_session_id: String,
|
||||
acp_session_id: String,
|
||||
event_tx: broadcast::Sender<crate::acp_bridge::SseEvent>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -1484,6 +1486,7 @@ async fn acp_stream_events(
|
||||
manager: Arc::clone(&mgr),
|
||||
mnote_session_id: mnote_session_id.clone(),
|
||||
acp_session_id,
|
||||
event_tx: event_tx.clone(),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1567,6 +1570,12 @@ async fn acp_stream_events(
|
||||
{
|
||||
Ok(result) => {
|
||||
info!("ACP prompt completed: stop_reason={:?}", result.stop_reason);
|
||||
let prompt_cancelled =
|
||||
matches!(result.stop_reason, crate::acp_types::StopReason::Cancelled);
|
||||
let runtime_aborted = matches!(
|
||||
runtime_status_for_run(&run_id_owned).as_deref(),
|
||||
Some("aborting" | "aborted")
|
||||
);
|
||||
let agent_audit = if audit_payload
|
||||
.get("sourceKind")
|
||||
.and_then(Value::as_str)
|
||||
@@ -1590,7 +1599,11 @@ async fn acp_stream_events(
|
||||
Value::Null
|
||||
};
|
||||
let _ = event_tx_prompt.send(crate::acp_bridge::SseEvent {
|
||||
event: "run.completed".into(),
|
||||
event: if prompt_cancelled || runtime_aborted {
|
||||
"run.aborted".into()
|
||||
} else {
|
||||
"run.completed".into()
|
||||
},
|
||||
data: json!({
|
||||
"stopReason": format!("{:?}", result.stop_reason),
|
||||
"agentAudit": agent_audit,
|
||||
@@ -1627,15 +1640,16 @@ async fn acp_stream_events(
|
||||
});
|
||||
}
|
||||
}
|
||||
let was_aborted = matches!(
|
||||
runtime_status_for_run(&run_id_owned).as_deref(),
|
||||
Some("aborting" | "aborted")
|
||||
);
|
||||
mgr_clone.close().await;
|
||||
ACP_ACTIVE_RUNS
|
||||
.lock()
|
||||
.expect("acp active runs")
|
||||
.remove(&run_id_owned);
|
||||
if !matches!(
|
||||
runtime_status_for_run(&run_id_owned).as_deref(),
|
||||
Some("aborting" | "aborted")
|
||||
) {
|
||||
if !was_aborted {
|
||||
update_runtime_by_run_id(&run_id_owned, "completed", Some("acp.prompt.done"), None);
|
||||
}
|
||||
});
|
||||
@@ -1763,11 +1777,37 @@ pub async fn abort_run(
|
||||
})),
|
||||
));
|
||||
};
|
||||
active.manager.cancel().await.map_err(|error| {
|
||||
WebError::bad_gateway_code("acp_abort_failed", format!("ACP abort failed: {error}"))
|
||||
.with_context(&context)
|
||||
})?;
|
||||
let cancel_result = tokio::time::timeout(
|
||||
Duration::from_millis(ACP_ABORT_NOTIFICATION_TIMEOUT_MS),
|
||||
active.manager.cancel(),
|
||||
)
|
||||
.await;
|
||||
let cancel_status = match cancel_result {
|
||||
Ok(Ok(())) => json!({"ok": true}),
|
||||
Ok(Err(error)) => {
|
||||
warn!(error = ?error, run_id = %run_id, "ACP abort notification failed; marking run aborted");
|
||||
json!({"ok": false, "error": error.to_string()})
|
||||
}
|
||||
Err(_) => {
|
||||
warn!(
|
||||
run_id = %run_id,
|
||||
timeout_ms = ACP_ABORT_NOTIFICATION_TIMEOUT_MS,
|
||||
"ACP abort notification timed out; marking run aborted"
|
||||
);
|
||||
json!({"ok": false, "error": "abort notification timed out"})
|
||||
}
|
||||
};
|
||||
update_runtime_by_run_id(&run_id, "aborted", Some("abort.completed"), None);
|
||||
let _ = active.event_tx.send(crate::acp_bridge::SseEvent {
|
||||
event: "run.aborted".into(),
|
||||
data: json!({
|
||||
"reason": payload
|
||||
.get("reason")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("client_abort"),
|
||||
"cancel": cancel_status.clone(),
|
||||
}),
|
||||
});
|
||||
return Ok((
|
||||
StatusCode::OK,
|
||||
stamp_client_headers(),
|
||||
@@ -1778,6 +1818,7 @@ pub async fn abort_run(
|
||||
"acpSessionId": active.acp_session_id,
|
||||
"status": "aborted",
|
||||
"runtime": runtime_state_for_run(&run_id).unwrap_or(Value::Null),
|
||||
"cancel": cancel_status,
|
||||
"events": [
|
||||
{"event": "abort.started", "runId": run_id},
|
||||
{"event": "abort.completed", "runId": run_id}
|
||||
|
||||
@@ -306,6 +306,23 @@ pub(crate) async fn execute_mnote_tool_call(
|
||||
);
|
||||
return Err(error);
|
||||
}
|
||||
if let Err(error) = ensure_tool_capability_scope(&context, &input) {
|
||||
audit_push(json!({
|
||||
"phase": "failed",
|
||||
"traceId": trace_id,
|
||||
"sessionId": input.session_id,
|
||||
"runId": input.run_id,
|
||||
"toolCallId": tool_call_id,
|
||||
"toolName": input.tool_name,
|
||||
"workspaceId": workspace_id,
|
||||
"documentId": document_id,
|
||||
"actorId": input.actor_id,
|
||||
"status": error.status().as_u16(),
|
||||
"message": error.message(),
|
||||
"capabilityScope": input.capability_scope
|
||||
}));
|
||||
return Err(error);
|
||||
}
|
||||
if let Some(cached) = idempotency_key.as_deref().and_then(idempotency_cache_get) {
|
||||
info!(
|
||||
trace_id = %trace_id,
|
||||
@@ -449,6 +466,74 @@ pub(crate) async fn execute_mnote_tool_call(
|
||||
Ok(response_body)
|
||||
}
|
||||
|
||||
fn ensure_tool_capability_scope(
|
||||
context: &RequestContext,
|
||||
input: &ToolCallInput,
|
||||
) -> Result<(), WebError> {
|
||||
let required = required_capability_scope(&input.tool_name);
|
||||
if required.is_empty()
|
||||
|| declared_capability_scope_covers(input.capability_scope.as_ref(), &required)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
Err(WebError::new(
|
||||
StatusCode::FORBIDDEN,
|
||||
"mnote_tool_capability_scope_forbidden",
|
||||
"调用方声明的 capabilityScope 未覆盖目标 mnote tool 所需能力",
|
||||
)
|
||||
.with_context(context)
|
||||
.with_header(HEADER_MNOTE_WEB_OWNER, "mnote-web")
|
||||
.with_header(HEADER_HERMES_TOOL_OWNER, "mnote-web-hermes-tools"))
|
||||
}
|
||||
|
||||
fn required_capability_scope(tool_name: &str) -> Vec<String> {
|
||||
manifest::manifest()
|
||||
.get("tools")
|
||||
.and_then(Value::as_array)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.find(|tool| tool.get("name").and_then(Value::as_str) == Some(tool_name))
|
||||
.and_then(|tool| tool.get("capabilityScope").and_then(Value::as_array))
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(Value::as_str)
|
||||
.map(normalize_capability_scope)
|
||||
.filter(|value| !value.is_empty())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn declared_capability_scope_covers(declared: Option<&Vec<String>>, required: &[String]) -> bool {
|
||||
let Some(declared) = declared else {
|
||||
// 兼容旧调用方:缺省 capabilityScope 不改变既有执行路径。
|
||||
return true;
|
||||
};
|
||||
let declared = declared
|
||||
.iter()
|
||||
.map(|value| normalize_capability_scope(value))
|
||||
.filter(|value| !value.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
required.iter().all(|scope| {
|
||||
declared
|
||||
.iter()
|
||||
.any(|candidate| capability_scope_satisfies(candidate, scope))
|
||||
})
|
||||
}
|
||||
|
||||
fn capability_scope_satisfies(candidate: &str, required: &str) -> bool {
|
||||
if candidate == required {
|
||||
return true;
|
||||
}
|
||||
required
|
||||
.strip_suffix(".read")
|
||||
.map(|prefix| format!("{prefix}.write"))
|
||||
.as_deref()
|
||||
== Some(candidate)
|
||||
}
|
||||
|
||||
fn normalize_capability_scope(value: &str) -> String {
|
||||
value.trim().to_ascii_lowercase()
|
||||
}
|
||||
|
||||
fn is_read_tool(tool_name: &str) -> bool {
|
||||
matches!(
|
||||
tool_name,
|
||||
@@ -964,6 +1049,46 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hermes_tools_call_rejects_declared_scope_that_does_not_cover_tool() {
|
||||
let response = app()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/hermes/tools/mnote/call")
|
||||
.header("content-type", "application/json")
|
||||
.header("x-mnote-actor-id", "user_1")
|
||||
.body(Body::from(
|
||||
json!({
|
||||
"toolName": "mnote.page.save",
|
||||
"workspaceId": "ws_demo",
|
||||
"documentId": "doc_1",
|
||||
"sessionId": "sess_scope",
|
||||
"runId": "run_scope",
|
||||
"toolCallId": "call_scope",
|
||||
"traceId": "trace_scope",
|
||||
"actorId": "user_1",
|
||||
"capabilityScope": ["page.read"],
|
||||
"dryRun": true,
|
||||
"idempotencyKey": "scope-mismatch",
|
||||
"args": {"content": "不会写入"}
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
assert_eq!(response.status(), StatusCode::FORBIDDEN);
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get("x-error-code")
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("mnote_tool_capability_scope_forbidden")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hermes_tools_manifest_returns_first_batch_tools() {
|
||||
let response = app()
|
||||
|
||||
@@ -3,37 +3,65 @@ use crate::context::RequestContext;
|
||||
use crate::error::WebError;
|
||||
use crate::routes::local_folder_source::{
|
||||
decode_local_id_segment, ensure_local_workspace_read_access,
|
||||
load_local_folder_file_tree_snapshot, load_local_folder_page_tree_snapshot,
|
||||
local_folder_watch_revision, local_workspace_id_from_root_uri,
|
||||
};
|
||||
use crate::routes::snapshot_support::ProjectionSnapshot;
|
||||
use axum::extract::{Extension, Query, State};
|
||||
use axum::http::{HeaderMap, HeaderName, HeaderValue};
|
||||
use axum::response::sse::{Event as SseEvent, KeepAlive, Sse};
|
||||
use axum::response::sse::{Event as SseEvent, Sse};
|
||||
use futures_util::stream;
|
||||
use futures_util::StreamExt;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use std::convert::Infallible;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::sync::broadcast::error::RecvError;
|
||||
|
||||
type BoxedEventStream = Pin<Box<dyn futures_util::Stream<Item = Result<SseEvent, Infallible>> + Send>>;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LocalFolderEventsQuery {
|
||||
pub root_uri: String,
|
||||
pub document_id: Option<String>,
|
||||
pub tree_live: Option<bool>,
|
||||
}
|
||||
|
||||
pub async fn local_folder_events(
|
||||
State(state): State<AppState>,
|
||||
Extension(context): Extension<RequestContext>,
|
||||
Query(query): Query<LocalFolderEventsQuery>,
|
||||
) -> Result<
|
||||
(
|
||||
HeaderMap,
|
||||
Sse<impl futures_util::Stream<Item = Result<SseEvent, Infallible>>>,
|
||||
),
|
||||
WebError,
|
||||
> {
|
||||
) -> Result<(HeaderMap, Sse<BoxedEventStream>), WebError> {
|
||||
let canonical_root = ensure_local_workspace_read_access(&context, &query.root_uri)
|
||||
.map_err(|error| error.with_context(&context))?;
|
||||
|
||||
let (mut headers, stream): (HeaderMap, BoxedEventStream) = if query.tree_live.unwrap_or(false) {
|
||||
build_tree_live_stream(state, context, canonical_root, query.root_uri).await?
|
||||
} else {
|
||||
build_document_events_stream(state, context, canonical_root, &query).await?
|
||||
};
|
||||
|
||||
// Apply keepalive via the same type-erased stream path
|
||||
if let Ok(name) = HeaderName::from_lowercase(b"x-mnote-web-owner") {
|
||||
headers.insert(name, HeaderValue::from_static("mnote-web"));
|
||||
}
|
||||
if let Ok(name) = HeaderName::from_lowercase(b"x-mnote-local-folder-events-owner") {
|
||||
headers.insert(name, HeaderValue::from_static("rust-web"));
|
||||
}
|
||||
|
||||
Ok((headers, Sse::new(stream)))
|
||||
}
|
||||
|
||||
/// Build the original document-level external-edit event stream (`ready` / `change`).
|
||||
async fn build_document_events_stream(
|
||||
state: AppState,
|
||||
context: RequestContext,
|
||||
canonical_root: PathBuf,
|
||||
query: &LocalFolderEventsQuery,
|
||||
) -> Result<(HeaderMap, BoxedEventStream), WebError> {
|
||||
let document_relative_path = query
|
||||
.document_id
|
||||
.as_deref()
|
||||
@@ -80,26 +108,129 @@ pub async fn local_folder_events(
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.boxed();
|
||||
|
||||
Ok((HeaderMap::new(), stream))
|
||||
}
|
||||
|
||||
/// Build the tree live stream: emits `snapshot` (initial) and `resync` (on watcher change)
|
||||
/// with full sidebar + file tree projections.
|
||||
///
|
||||
/// Reuses `LocalFolderWatcherRegistry` — no second watcher created.
|
||||
/// No data is written to Convex command log.
|
||||
async fn build_tree_live_stream(
|
||||
state: AppState,
|
||||
context: RequestContext,
|
||||
canonical_root: PathBuf,
|
||||
root_uri: String,
|
||||
) -> Result<(HeaderMap, BoxedEventStream), WebError> {
|
||||
let subscription = state
|
||||
.local_folder_watcher_registry()
|
||||
.subscribe(&canonical_root)
|
||||
.map_err(|error| WebError::internal(error).with_context(&context))?;
|
||||
|
||||
let workspace_id = local_workspace_id_from_root_uri(&root_uri)
|
||||
.map_err(|error| error.with_context(&context))?;
|
||||
|
||||
// Build initial snapshot
|
||||
let sidebar_snapshot = load_local_folder_page_tree_snapshot(&root_uri)
|
||||
.map_err(|error| error.with_context(&context))?;
|
||||
let file_tree_snapshot = load_local_folder_file_tree_snapshot(&root_uri)
|
||||
.map_err(|error| error.with_context(&context))?;
|
||||
let revision = local_folder_watch_revision(&root_uri)
|
||||
.map_err(|error| error.with_context(&context))?;
|
||||
|
||||
let initial_payload = build_tree_snapshot_payload(
|
||||
&root_uri,
|
||||
&workspace_id,
|
||||
&revision.revision,
|
||||
"snapshot",
|
||||
&sidebar_snapshot,
|
||||
&file_tree_snapshot,
|
||||
);
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Ok(name) = HeaderName::from_lowercase(b"x-mnote-web-owner") {
|
||||
headers.insert(name, HeaderValue::from_static("mnote-web"));
|
||||
}
|
||||
if let Ok(name) = HeaderName::from_lowercase(b"x-mnote-local-folder-events-owner") {
|
||||
headers.insert(name, HeaderValue::from_static("rust-web"));
|
||||
}
|
||||
let stream = stream::unfold(
|
||||
(Some(initial_payload), subscription, root_uri, workspace_id),
|
||||
|(payload, mut subscription, root_uri, workspace_id)| async move {
|
||||
if let Some(payload) = payload {
|
||||
return Some((
|
||||
Ok(stream_event("snapshot", &payload)),
|
||||
(None, subscription, root_uri, workspace_id),
|
||||
));
|
||||
}
|
||||
|
||||
Ok((
|
||||
headers,
|
||||
Sse::new(stream).keep_alive(
|
||||
KeepAlive::new()
|
||||
.interval(Duration::from_secs(15))
|
||||
.text("keepalive"),
|
||||
),
|
||||
loop {
|
||||
match subscription.receiver.recv().await {
|
||||
Ok(_watcher_payload) => {
|
||||
// Rebuild full snapshot on any filesystem change
|
||||
if let Some(resync_payload) =
|
||||
rebuild_tree_resync_payload(&root_uri, &workspace_id)
|
||||
{
|
||||
return Some((
|
||||
Ok(stream_event("resync", &resync_payload)),
|
||||
(None, subscription, root_uri, workspace_id),
|
||||
));
|
||||
}
|
||||
// Snapshot load failed — continue waiting for next change
|
||||
continue;
|
||||
}
|
||||
Err(RecvError::Lagged(_)) => continue,
|
||||
Err(RecvError::Closed) => return None,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.boxed();
|
||||
|
||||
Ok((HeaderMap::new(), stream))
|
||||
}
|
||||
|
||||
fn rebuild_tree_resync_payload(root_uri: &str, workspace_id: &str) -> Option<Value> {
|
||||
let revision = local_folder_watch_revision(root_uri).ok()?;
|
||||
let sidebar_snapshot = load_local_folder_page_tree_snapshot(root_uri).ok()?;
|
||||
let file_tree_snapshot = load_local_folder_file_tree_snapshot(root_uri).ok()?;
|
||||
Some(build_tree_snapshot_payload(
|
||||
root_uri,
|
||||
workspace_id,
|
||||
&revision.revision,
|
||||
"resync",
|
||||
&sidebar_snapshot,
|
||||
&file_tree_snapshot,
|
||||
))
|
||||
}
|
||||
|
||||
fn build_tree_snapshot_payload(
|
||||
root_uri: &str,
|
||||
workspace_id: &str,
|
||||
revision: &str,
|
||||
kind: &str,
|
||||
sidebar_snapshot: &ProjectionSnapshot,
|
||||
file_tree_snapshot: &ProjectionSnapshot,
|
||||
) -> Value {
|
||||
let dataset = json!({
|
||||
"kernel_sidebar_projection": sidebar_snapshot.projection,
|
||||
"kernelSidebarProjection": sidebar_snapshot.projection,
|
||||
"kernel_file_tree_projection": file_tree_snapshot.projection,
|
||||
"kernelFileTreeProjection": file_tree_snapshot.projection,
|
||||
});
|
||||
|
||||
json!({
|
||||
"kind": kind,
|
||||
"revision": revision,
|
||||
"stream": "workspace",
|
||||
"projection": "sidebar_tree",
|
||||
"scope": "workspace",
|
||||
"sourceKind": "local_folder",
|
||||
"rootUri": root_uri,
|
||||
"workspaceId": workspace_id,
|
||||
"data": {
|
||||
"dataset": dataset,
|
||||
"tree": sidebar_snapshot.projection,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn local_markdown_relative_path_from_document_id(document_id: &str) -> Option<String> {
|
||||
let trimmed = document_id.trim();
|
||||
let encoded = trimmed.strip_prefix("local-md:")?;
|
||||
@@ -132,6 +263,101 @@ fn stream_event(event_name: &str, payload: &Value) -> SseEvent {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::{build_app, AppConfig, AppState};
|
||||
use crate::routes::local_folder_source::initialize_local_workspace_for_actor;
|
||||
use axum::body::Body;
|
||||
use axum::http::Request;
|
||||
use tower::util::ServiceExt;
|
||||
|
||||
fn test_root(name: &str) -> std::path::PathBuf {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"mnote-local-folder-events-{name}-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|duration| duration.as_nanos())
|
||||
.unwrap_or(0)
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
std::fs::create_dir_all(&root).expect("create temp root");
|
||||
root
|
||||
}
|
||||
|
||||
fn app_with_local_workspace(root: &std::path::Path) -> axum::Router {
|
||||
let root_uri = format!("file://{}", root.display());
|
||||
initialize_local_workspace_for_actor("dev-user", &root_uri)
|
||||
.expect("init local workspace");
|
||||
build_app(AppState::new(AppConfig {
|
||||
service_name: "mnote-web".into(),
|
||||
service_version: "0.1.0".into(),
|
||||
bind_addr: "127.0.0.1:0".into(),
|
||||
public_bind_addr: "127.0.0.1:3000".into(),
|
||||
legacy_next_base_url: Some("http://127.0.0.1:3100".into()),
|
||||
enable_legacy_next_compat: false,
|
||||
enable_debug_shell_routes: false,
|
||||
enable_editor_actor: true,
|
||||
hermes_base_path: "/api/hermes".into(),
|
||||
compat_next_base_path: "/api/compat/next".into(),
|
||||
convex_url: None,
|
||||
convex_admin_key: None,
|
||||
allow_dev_fixtures: false,
|
||||
query_fixtures_json: None,
|
||||
mutation_fixtures_json: None,
|
||||
dev_user_id: "dev-user".into(),
|
||||
dev_user_name: "开发用户".into(),
|
||||
dev_user_email: "dev@mnote.local".into(),
|
||||
}))
|
||||
}
|
||||
|
||||
/// Build a root_uri query-parameter-safe by percent-encoding (no external crate).
|
||||
fn encoded_root_uri(raw: &str) -> String {
|
||||
raw.replace('%', "%25")
|
||||
.replace(':', "%3A")
|
||||
.replace('/', "%2F")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn tree_live_headers_include_mnote_web_owner() {
|
||||
let root = test_root("tree-live-headers");
|
||||
std::fs::write(root.join("test.md"), "# Test\n").expect("write test");
|
||||
let root_uri = format!("file://{}", root.display());
|
||||
let encoded = encoded_root_uri(&root_uri);
|
||||
|
||||
let app = app_with_local_workspace(&root);
|
||||
let response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(format!(
|
||||
"/api/local-folder/events?rootUri={encoded}&treeLive=true"
|
||||
))
|
||||
.header("x-mnote-actor-id", "dev-user")
|
||||
.header("x-mnote-actor-type", "user")
|
||||
.body(Body::empty())
|
||||
.expect("request"),
|
||||
)
|
||||
.await
|
||||
.expect("response");
|
||||
|
||||
assert_eq!(response.status(), 200);
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get("x-mnote-web-owner")
|
||||
.and_then(|v| v.to_str().ok()),
|
||||
Some("mnote-web"),
|
||||
"response should have x-mnote-web-owner header"
|
||||
);
|
||||
assert_eq!(
|
||||
response
|
||||
.headers()
|
||||
.get("x-mnote-local-folder-events-owner")
|
||||
.and_then(|v| v.to_str().ok()),
|
||||
Some("rust-web"),
|
||||
"response should have x-mnote-local-folder-events-owner header"
|
||||
);
|
||||
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_markdown_document_id_maps_to_relative_path() {
|
||||
@@ -140,4 +366,52 @@ mod tests {
|
||||
Some("docs/README.md")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_tree_snapshot_payload_has_required_fields() {
|
||||
let sidebar_projection = json!({
|
||||
"projection": "page_tree",
|
||||
"sourceKind": "local_folder",
|
||||
"rootUri": "file:///test",
|
||||
"watchRevision": "abc123",
|
||||
"items": [],
|
||||
});
|
||||
let file_tree_projection = json!({
|
||||
"projection": "file_tree",
|
||||
"sourceKind": "local_folder",
|
||||
"rootUri": "file:///test",
|
||||
"watchRevision": "abc123",
|
||||
"items": [],
|
||||
});
|
||||
let sidebar = ProjectionSnapshot {
|
||||
dataset: json!({}),
|
||||
projection: sidebar_projection,
|
||||
};
|
||||
let file_tree = ProjectionSnapshot {
|
||||
dataset: json!({}),
|
||||
projection: file_tree_projection,
|
||||
};
|
||||
|
||||
let payload = build_tree_snapshot_payload(
|
||||
"file:///test",
|
||||
"local:test_workspace",
|
||||
"rev_1",
|
||||
"snapshot",
|
||||
&sidebar,
|
||||
&file_tree,
|
||||
);
|
||||
|
||||
assert_eq!(payload["kind"], "snapshot");
|
||||
assert_eq!(payload["stream"], "workspace");
|
||||
assert_eq!(payload["projection"], "sidebar_tree");
|
||||
assert_eq!(payload["sourceKind"], "local_folder");
|
||||
assert_eq!(payload["rootUri"], "file:///test");
|
||||
assert_eq!(payload["workspaceId"], "local:test_workspace");
|
||||
assert_eq!(payload["revision"], "rev_1");
|
||||
assert!(payload["data"]["dataset"]["kernel_sidebar_projection"].is_object());
|
||||
assert!(payload["data"]["dataset"]["kernel_file_tree_projection"].is_object());
|
||||
assert!(payload["data"]["dataset"]["kernelSidebarProjection"].is_object());
|
||||
assert!(payload["data"]["dataset"]["kernelFileTreeProjection"].is_object());
|
||||
assert!(payload["data"]["tree"].is_object());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ use axum::extract::{Extension, State};
|
||||
use axum::http::{HeaderMap, HeaderName, HeaderValue, StatusCode};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};
|
||||
use serde::Serialize;
|
||||
|
||||
const HEADER_MNOTE_WEB_OWNER: &str = "x-mnote-web-owner";
|
||||
const COOKIE_CONVEX_AUTH_JWT: &str = "__convexAuthJWT";
|
||||
const COOKIE_ACTOR_EMAIL: &str = "mnote_actor_email";
|
||||
const COOKIE_ACTOR_NAME: &str = "mnote_actor_name";
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -63,6 +67,18 @@ pub async fn refresh_session(
|
||||
fn build_session_response(state: &AppState, context: RequestContext) -> SessionResponse {
|
||||
let actor_id = context.auth.actor_id.trim();
|
||||
let has_forwarded_actor = !actor_id.is_empty() && actor_id != "anonymous";
|
||||
let actor_email = context
|
||||
.auth
|
||||
.cookie_header
|
||||
.as_deref()
|
||||
.and_then(|cookies| encoded_cookie_value(cookies, COOKIE_ACTOR_EMAIL))
|
||||
.or_else(|| jwt_cookie_claim(&context, &["email", "preferred_username"]));
|
||||
let actor_name = context
|
||||
.auth
|
||||
.cookie_header
|
||||
.as_deref()
|
||||
.and_then(|cookies| encoded_cookie_value(cookies, COOKIE_ACTOR_NAME))
|
||||
.or_else(|| jwt_cookie_claim(&context, &["name", "username"]));
|
||||
let user_id = if has_forwarded_actor {
|
||||
actor_id.to_string()
|
||||
} else {
|
||||
@@ -79,12 +95,12 @@ fn build_session_response(state: &AppState, context: RequestContext) -> SessionR
|
||||
owner: "mnote-web",
|
||||
user_id,
|
||||
email: if has_forwarded_actor {
|
||||
String::new()
|
||||
actor_email.unwrap_or_default()
|
||||
} else {
|
||||
state.config().dev_user_email.clone()
|
||||
},
|
||||
name: if has_forwarded_actor {
|
||||
actor_id.to_string()
|
||||
actor_name.unwrap_or_else(|| actor_id.to_string())
|
||||
} else {
|
||||
state.config().dev_user_name.clone()
|
||||
},
|
||||
@@ -99,6 +115,50 @@ fn build_session_response(state: &AppState, context: RequestContext) -> SessionR
|
||||
}
|
||||
}
|
||||
|
||||
fn jwt_cookie_claim(context: &RequestContext, keys: &[&str]) -> Option<String> {
|
||||
let token = context
|
||||
.auth
|
||||
.cookie_header
|
||||
.as_deref()
|
||||
.and_then(|cookies| raw_cookie_value(cookies, COOKIE_CONVEX_AUTH_JWT))?;
|
||||
let payload_segment = token.split('.').nth(1)?;
|
||||
let decoded = URL_SAFE_NO_PAD.decode(payload_segment.as_bytes()).ok()?;
|
||||
let payload: serde_json::Value = serde_json::from_slice(&decoded).ok()?;
|
||||
keys.iter().find_map(|key| {
|
||||
payload
|
||||
.get(key)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
})
|
||||
}
|
||||
|
||||
fn encoded_cookie_value(cookie_header: &str, name: &str) -> Option<String> {
|
||||
let encoded = raw_cookie_value(cookie_header, name)?;
|
||||
let decoded = URL_SAFE_NO_PAD.decode(encoded.as_bytes()).ok()?;
|
||||
String::from_utf8(decoded)
|
||||
.ok()
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
fn raw_cookie_value(cookie_header: &str, name: &str) -> Option<String> {
|
||||
cookie_header.split(';').find_map(|part| {
|
||||
let (cookie_name, cookie_value) = part.trim().split_once('=')?;
|
||||
if cookie_name.trim() == name {
|
||||
let value = cookie_value.trim();
|
||||
if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(value.to_string())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn owner_json<T>(payload: Json<T>) -> Response
|
||||
where
|
||||
T: Serialize,
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn AuthPage() -> impl IntoView {
|
||||
</a>
|
||||
<section class="mnote-auth-panel" aria-labelledby="mnote-auth-title">
|
||||
<div class="mnote-auth-heading">
|
||||
<h1 id="mnote-auth-title">"邮箱登录"</h1>
|
||||
<h1 id="mnote-auth-title">"账号登录"</h1>
|
||||
<p>"登录后进入你的工作区"</p>
|
||||
</div>
|
||||
<form class="mnote-auth-form" method="post" action="/api/auth" data-auth-mode="convex-password">
|
||||
@@ -25,24 +25,14 @@ pub fn AuthPage() -> impl IntoView {
|
||||
<input type="hidden" name="provider" value="password" />
|
||||
<input type="hidden" name="flow" value="signIn" data-auth-flow />
|
||||
<label class="mnote-auth-field">
|
||||
<span>"邮箱"</span>
|
||||
<span data-auth-account-label>"邮箱或用户名"</span>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="请输入邮箱"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label class="mnote-auth-field mnote-auth-username" hidden>
|
||||
<span>"用户名"</span>
|
||||
<input
|
||||
id="username"
|
||||
name="username"
|
||||
id="account"
|
||||
name="account"
|
||||
type="text"
|
||||
autocomplete="username"
|
||||
placeholder="用于显示的用户名"
|
||||
placeholder="请输入邮箱或用户名"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label class="mnote-auth-field">
|
||||
@@ -85,8 +75,8 @@ const AUTH_SCRIPT: &str = r#"
|
||||
if (!root) return;
|
||||
var form = root.querySelector('form[data-auth-mode="convex-password"]');
|
||||
var flowInput = root.querySelector('[data-auth-flow]');
|
||||
var usernameField = root.querySelector('.mnote-auth-username');
|
||||
var usernameInput = root.querySelector('#username');
|
||||
var accountInput = root.querySelector('#account');
|
||||
var accountLabel = root.querySelector('[data-auth-account-label]');
|
||||
var title = root.querySelector('#mnote-auth-title');
|
||||
var subtitle = root.querySelector('.mnote-auth-heading p');
|
||||
var submit = root.querySelector('[data-auth-submit]');
|
||||
@@ -110,19 +100,54 @@ const AUTH_SCRIPT: &str = r#"
|
||||
var isSignUp = nextFlow === 'signUp';
|
||||
flowInput.value = nextFlow;
|
||||
switcher.dataset.flow = nextFlow;
|
||||
if (title) title.textContent = isSignUp ? '创建账号' : '邮箱登录';
|
||||
if (title) title.textContent = isSignUp ? '创建账号' : '账号登录';
|
||||
if (subtitle) subtitle.textContent = isSignUp ? '创建账号后进入你的工作区' : '登录后进入你的工作区';
|
||||
submit.textContent = isSignUp ? '注册并登录' : '登录';
|
||||
switcher.textContent = isSignUp ? '已有账号?登录' : '没有账号?注册';
|
||||
if (usernameField) usernameField.hidden = !isSignUp;
|
||||
if (usernameInput) usernameInput.required = isSignUp;
|
||||
if (accountLabel) accountLabel.textContent = isSignUp ? '邮箱' : '邮箱或用户名';
|
||||
if (accountInput) {
|
||||
accountInput.placeholder = isSignUp ? '请输入邮箱' : '请输入邮箱或用户名';
|
||||
accountInput.autocomplete = isSignUp ? 'email' : 'username';
|
||||
}
|
||||
quickLogin.hidden = isSignUp;
|
||||
var passwordInput = root.querySelector('#password');
|
||||
if (passwordInput) passwordInput.autocomplete = isSignUp ? 'new-password' : 'current-password';
|
||||
setMessage('', '');
|
||||
}
|
||||
|
||||
function buildPayload(flow, email, password, username) {
|
||||
function accountMap() {
|
||||
try {
|
||||
return JSON.parse(window.localStorage.getItem('mnote.auth.accountEmailByName') || '{}') || {};
|
||||
} catch (_) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function rememberAccount(email, name) {
|
||||
var normalizedEmail = String(email || '').trim();
|
||||
var normalizedName = String(name || '').trim();
|
||||
if (!normalizedEmail || !normalizedName || normalizedName.indexOf('@') !== -1) return;
|
||||
try {
|
||||
var map = accountMap();
|
||||
map[normalizedName.toLowerCase()] = normalizedEmail;
|
||||
window.localStorage.setItem('mnote.auth.accountEmailByName', JSON.stringify(map));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
function resolveAccountEmail(account) {
|
||||
var normalized = String(account || '').trim();
|
||||
if (normalized.indexOf('@') !== -1) return normalized;
|
||||
var mapped = accountMap()[normalized.toLowerCase()];
|
||||
return String(mapped || normalized).trim();
|
||||
}
|
||||
|
||||
function defaultNameFromEmail(email) {
|
||||
return String(email || '').split('@')[0].trim();
|
||||
}
|
||||
|
||||
function buildPayload(flow, account, password) {
|
||||
var email = flow === 'signIn' ? resolveAccountEmail(account) : String(account || '').trim();
|
||||
var name = defaultNameFromEmail(email);
|
||||
var payload = {
|
||||
action: 'auth:signIn',
|
||||
args: {
|
||||
@@ -134,23 +159,25 @@ const AUTH_SCRIPT: &str = r#"
|
||||
}
|
||||
}
|
||||
};
|
||||
if (flow === 'signUp' && username) {
|
||||
payload.args.params.name = username;
|
||||
if (name) {
|
||||
payload.args.params.name = name;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function requestAuth(flow, email, password, username) {
|
||||
async function requestAuth(flow, account, password) {
|
||||
var response = await fetch('/api/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(buildPayload(flow, email, password, username))
|
||||
body: JSON.stringify(buildPayload(flow, account, password))
|
||||
});
|
||||
var data = await response.json().catch(function () { return {}; });
|
||||
if (!response.ok || data.error) {
|
||||
throw new Error(data.error || '登录失败,请重试');
|
||||
}
|
||||
var params = buildPayload(flow, account, password).args.params;
|
||||
rememberAccount(params.email, params.name);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -160,18 +187,21 @@ const AUTH_SCRIPT: &str = r#"
|
||||
|
||||
form.addEventListener('submit', async function (event) {
|
||||
event.preventDefault();
|
||||
var email = String((root.querySelector('#email') || {}).value || '').trim();
|
||||
var account = String((accountInput || {}).value || '').trim();
|
||||
var password = String((root.querySelector('#password') || {}).value || '');
|
||||
var username = String((usernameInput || {}).value || '').trim();
|
||||
var flow = flowInput.value === 'signUp' ? 'signUp' : 'signIn';
|
||||
if (!email || !password || (flow === 'signUp' && !username)) {
|
||||
if (!account || !password) {
|
||||
setMessage('请完整填写信息', 'error');
|
||||
return;
|
||||
}
|
||||
if (flow === 'signUp' && account.indexOf('@') === -1) {
|
||||
setMessage('注册时请填写邮箱;登录时可输入邮箱或已记住的用户名', 'error');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setMessage(flow === 'signUp' ? '正在创建账号...' : '正在登录...', 'info');
|
||||
try {
|
||||
await requestAuth(flow, email, password, username);
|
||||
await requestAuth(flow, account, password);
|
||||
setMessage('登录成功,正在进入工作区...', 'success');
|
||||
window.location.assign('/');
|
||||
} catch (error) {
|
||||
@@ -189,15 +219,15 @@ const AUTH_SCRIPT: &str = r#"
|
||||
return;
|
||||
}
|
||||
|
||||
var emailInput = root.querySelector('#email');
|
||||
var passwordInput = root.querySelector('#password');
|
||||
if (emailInput) emailInput.value = email;
|
||||
if (accountInput) accountInput.value = email;
|
||||
if (passwordInput) passwordInput.value = password;
|
||||
|
||||
setBusy(true);
|
||||
setMessage('正在登录测试账号...', 'info');
|
||||
try {
|
||||
await requestAuth('signIn', email, password, username);
|
||||
await requestAuth('signIn', email, password);
|
||||
rememberAccount(email, username);
|
||||
setMessage('登录成功,正在进入工作区...', 'success');
|
||||
window.location.assign('/');
|
||||
return;
|
||||
@@ -206,7 +236,8 @@ const AUTH_SCRIPT: &str = r#"
|
||||
}
|
||||
|
||||
try {
|
||||
await requestAuth('signUp', email, password, username);
|
||||
await requestAuth('signUp', email, password);
|
||||
rememberAccount(email, username);
|
||||
setMessage('测试账号已创建,正在进入工作区...', 'success');
|
||||
window.location.assign('/');
|
||||
} catch (error) {
|
||||
|
||||
@@ -61,30 +61,7 @@ pub fn HomePage(
|
||||
</main>
|
||||
}.into_any()
|
||||
} else {
|
||||
view! {
|
||||
<section class="mnote-workspace-empty-state" data-testid="mnote-workspace-empty-state">
|
||||
<h1>"暂无页面"</h1>
|
||||
<p>"当前还没有可显示的本地工作区。"</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mnote-empty-create-page"
|
||||
data-testid="mnote-create-default-local-workspace"
|
||||
data-mnote-action="create-local-workspace"
|
||||
>"创建我的空间"</button>
|
||||
<button
|
||||
type="button"
|
||||
class="mnote-empty-create-page"
|
||||
data-testid="mnote-open-local-folder-empty"
|
||||
data-mnote-action="open-local-folder"
|
||||
>"打开本地文件夹"</button>
|
||||
<button
|
||||
type="button"
|
||||
class="mnote-empty-create-page"
|
||||
data-testid="mnote-empty-create-page"
|
||||
data-mnote-action="create-local-workspace"
|
||||
>"新建页面"</button>
|
||||
</section>
|
||||
}.into_any()
|
||||
view! {}.into_any()
|
||||
}}
|
||||
</PageLayout>
|
||||
}
|
||||
|
||||
@@ -1214,6 +1214,110 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
trigger.closest('[data-testid="wolai-workspace-identity"]')?.appendChild(menu);
|
||||
}
|
||||
|
||||
function closeAccountMenu() {
|
||||
var existing = document.querySelector('[data-testid="mnote-account-menu"]');
|
||||
if (existing && existing.parentElement) existing.parentElement.removeChild(existing);
|
||||
document.querySelectorAll('[data-testid="mnote-account-menu-trigger"]').forEach(function(trigger) {
|
||||
if (trigger instanceof HTMLElement) trigger.setAttribute('aria-expanded', 'false');
|
||||
});
|
||||
}
|
||||
|
||||
function accountMenuFallbackSession() {
|
||||
var body = document.body instanceof HTMLElement ? document.body : null;
|
||||
var actorId = body ? String(body.getAttribute('data-mnote-actor-id') || '').trim() : '';
|
||||
return {
|
||||
ok: true,
|
||||
name: actorId || '当前用户',
|
||||
email: '',
|
||||
userId: actorId || 'anonymous',
|
||||
actorType: actorId && actorId !== 'anonymous' ? 'user' : 'anonymous',
|
||||
authMode: 'browser'
|
||||
};
|
||||
}
|
||||
|
||||
function renderAccountInfo(menu, session) {
|
||||
var nameNode = menu.querySelector('[data-account-info="name"]');
|
||||
var emailNode = menu.querySelector('[data-account-info="email"]');
|
||||
var idNode = menu.querySelector('[data-account-info="user-id"]');
|
||||
var typeNode = menu.querySelector('[data-account-info="actor-type"]');
|
||||
if (nameNode) nameNode.textContent = session.name || session.userId || '当前用户';
|
||||
if (emailNode) emailNode.textContent = session.email || '未提供邮箱';
|
||||
if (idNode) idNode.textContent = session.userId || 'anonymous';
|
||||
if (typeNode) typeNode.textContent = session.actorType || session.authMode || 'unknown';
|
||||
}
|
||||
|
||||
async function loadAccountInfo(menu) {
|
||||
try {
|
||||
var response = await fetch('/api/auth/session', {
|
||||
method: 'GET',
|
||||
headers: { 'accept': 'application/json' },
|
||||
credentials: 'include'
|
||||
});
|
||||
var payload = await response.json().catch(function() { return null; });
|
||||
if (!response.ok || !payload) throw new Error('session_failed_' + response.status);
|
||||
renderAccountInfo(menu, payload);
|
||||
} catch (_) {
|
||||
renderAccountInfo(menu, accountMenuFallbackSession());
|
||||
}
|
||||
}
|
||||
|
||||
async function signOutAccount(trigger) {
|
||||
setCommandPending(trigger, true);
|
||||
try {
|
||||
var response = await fetch('/api/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ action: 'auth:signOut', args: {} })
|
||||
});
|
||||
var payload = await response.json().catch(function() { return {}; });
|
||||
payload = payload || {};
|
||||
if (!response.ok || payload.error) {
|
||||
throw new Error(payload.error || '退出登录失败');
|
||||
}
|
||||
window.location.assign('/auth');
|
||||
} catch (error) {
|
||||
var menu = document.querySelector('[data-testid="mnote-account-menu"]');
|
||||
var errorNode = menu ? menu.querySelector('[data-account-error]') : null;
|
||||
if (errorNode instanceof HTMLElement) {
|
||||
errorNode.textContent = error && error.message ? error.message : '退出登录失败';
|
||||
errorNode.hidden = false;
|
||||
}
|
||||
setCommandPending(trigger, false);
|
||||
}
|
||||
}
|
||||
|
||||
function openAccountMenu(trigger) {
|
||||
closeAccountMenu();
|
||||
if (!(trigger instanceof HTMLElement)) return;
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
var menu = document.createElement('div');
|
||||
menu.className = 'mnote-workspace-source-menu mnote-account-menu';
|
||||
menu.setAttribute('data-testid', 'mnote-account-menu');
|
||||
menu.setAttribute('role', 'menu');
|
||||
menu.innerHTML =
|
||||
'<div class="mnote-account-menu__profile" role="group" aria-label="个人信息">' +
|
||||
'<div class="mnote-account-menu__title">个人设置</div>' +
|
||||
'<div class="mnote-account-menu__name" data-account-info="name">正在读取...</div>' +
|
||||
'<div class="mnote-account-menu__row"><span>邮箱</span><strong data-account-info="email">正在读取...</strong></div>' +
|
||||
'<div class="mnote-account-menu__row"><span>用户 ID</span><strong data-account-info="user-id">正在读取...</strong></div>' +
|
||||
'<div class="mnote-account-menu__row"><span>身份</span><strong data-account-info="actor-type">正在读取...</strong></div>' +
|
||||
'</div>' +
|
||||
'<div class="mnote-account-menu__separator" aria-hidden="true"></div>' +
|
||||
'<button type="button" class="mnote-workspace-source-menu__item mnote-account-menu__logout" data-testid="mnote-account-sign-out" role="menuitem">退出登录</button>' +
|
||||
'<div class="mnote-account-menu__error" data-account-error hidden></div>';
|
||||
var signOutButton = menu.querySelector('[data-testid="mnote-account-sign-out"]');
|
||||
if (signOutButton) {
|
||||
signOutButton.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
void signOutAccount(signOutButton);
|
||||
});
|
||||
}
|
||||
var host = trigger.closest('[data-testid="wolai-sidebar-quick-actions"]') || trigger.parentElement;
|
||||
if (host) host.appendChild(menu);
|
||||
void loadAccountInfo(menu);
|
||||
}
|
||||
|
||||
autoOpenRecentLocalRootOnHome();
|
||||
|
||||
function setCommandPending(trigger, pending) {
|
||||
@@ -1825,7 +1929,7 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
});
|
||||
var activeId = currentDocumentId();
|
||||
var activeRowId = currentFileTreeActiveRowId();
|
||||
tree.innerHTML = '<ul class="tree-root" role="tree" data-rust-page-renderer="initial_v1">' + (rows.length ? renderPageRows('', groupRowsByParent(rows), activeId, 0) : '<li class="tree-empty" data-rust-rendered-row="page-empty">暂无页面</li>') + '</ul>';
|
||||
tree.innerHTML = '<ul class="tree-root" role="tree" data-rust-page-renderer="initial_v1">' + (rows.length ? renderPageRows('', groupRowsByParent(rows), activeId, 0) : '') + '</ul>';
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1934,7 +2038,7 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
var rows = projectionItems(projection);
|
||||
var activeId = currentDocumentId();
|
||||
var activeRowId = currentFileTreeActiveRowId();
|
||||
tree.innerHTML = '<ul class="tree-root" role="tree" data-rust-filetree-renderer="initial_v1">' + (rows.length ? renderFileRows('', groupRowsByParent(rows), activeId, activeRowId) : '<li class="tree-empty" data-rust-rendered-row="filetree-empty">暂无文件或页面</li>') + '</ul>';
|
||||
tree.innerHTML = '<ul class="tree-root" role="tree" data-rust-filetree-renderer="initial_v1">' + (rows.length ? renderFileRows('', groupRowsByParent(rows), activeId, activeRowId) : '') + '</ul>';
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2006,6 +2110,9 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
};
|
||||
var poll = async function() {
|
||||
if (document.hidden) return;
|
||||
// If tree live SSE transport is active for local_folder, skip polling (fallback)
|
||||
var treeTransport = document.documentElement.getAttribute('data-mnote-tree-live-transport') || '';
|
||||
if (treeTransport === 'local-folder-events') return;
|
||||
var url = new URL('/api/tree/local-folder-watch', window.location.origin);
|
||||
url.searchParams.set('rootUri', rootUri);
|
||||
var response = await fetch(url.toString(), { headers: { accept: 'application/json' } });
|
||||
@@ -8864,6 +8971,17 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
var sourceMenu = closestAction(e.target, '[data-testid="mnote-workspace-source-menu"]');
|
||||
if (!sourceMenu) closeWorkspaceSourceMenu();
|
||||
|
||||
var accountMenuTrigger = closestAction(e.target, '[data-mnote-action="open-account-menu"]');
|
||||
if (accountMenuTrigger) {
|
||||
e.preventDefault();
|
||||
var existingAccountMenu = document.querySelector('[data-testid="mnote-account-menu"]');
|
||||
if (existingAccountMenu) closeAccountMenu();
|
||||
else openAccountMenu(accountMenuTrigger);
|
||||
return;
|
||||
}
|
||||
var accountMenu = closestAction(e.target, '[data-testid="mnote-account-menu"]');
|
||||
if (!accountMenu) closeAccountMenu();
|
||||
|
||||
var trashTrigger = closestAction(e.target, '[data-mnote-action="open-trash-modal"]');
|
||||
if (trashTrigger) {
|
||||
e.preventDefault();
|
||||
@@ -9706,6 +9824,18 @@ const TREE_LIVE_CONTROLLER_JS: &str = r##"
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var sourceKind = (params.get('sourceKind') || '').trim();
|
||||
if (sourceKind === 'local_folder') {
|
||||
applyTransport('local-folder-events');
|
||||
applyStatus('connecting');
|
||||
var localRootUri = (params.get('rootUri') || '').trim()
|
||||
|| (document.body instanceof HTMLElement ? (document.body.getAttribute('data-mnote-root-uri') || '').trim() : '');
|
||||
if (localRootUri && 'EventSource' in window) {
|
||||
var url = new URL('/api/local-folder/events', window.location.origin);
|
||||
url.searchParams.set('rootUri', localRootUri);
|
||||
url.searchParams.set('treeLive', 'true');
|
||||
startWithSse(bootstrap, '', url);
|
||||
return;
|
||||
}
|
||||
// No rootUri or EventSource unavailable — mark static and let polling fallback handle it
|
||||
applyTransport('local-folder-static');
|
||||
applyStatus('static');
|
||||
return;
|
||||
@@ -9841,7 +9971,7 @@ pub fn PageLayout(
|
||||
<span class="wolai-sidebar-chevron" aria-hidden="true">"⌄"</span>
|
||||
</button>
|
||||
</div>
|
||||
<nav class="mnote-sidebar-nav wolai-quick-actions" aria-label="快捷操作">
|
||||
<nav class="mnote-sidebar-nav wolai-quick-actions" aria-label="快捷操作" data-testid="wolai-sidebar-quick-actions">
|
||||
<a href="/search" class:active={current_nav == "search"} title="搜索" aria-label="搜索" data-mnote-action="open-search-modal"><span class="material-symbols-outlined nav-icon" data-icon="search" aria-hidden="true"></span></a>
|
||||
<a href="/graph" title="关系图" aria-label="关系图"><span class="material-symbols-outlined nav-icon" data-icon="account_tree" aria-hidden="true"></span></a>
|
||||
<a href="/actions" title="快捷动作" aria-label="快捷动作"><span class="material-symbols-outlined nav-icon" data-icon="bolt" aria-hidden="true"></span></a>
|
||||
@@ -9863,7 +9993,17 @@ pub fn PageLayout(
|
||||
} else {
|
||||
view! {}.into_any()
|
||||
}}
|
||||
<a href="/more" title="更多" aria-label="更多"><span class="material-symbols-outlined nav-icon" data-icon="more_horiz" aria-hidden="true"></span></a>
|
||||
<button
|
||||
type="button"
|
||||
title="更多"
|
||||
aria-label="更多"
|
||||
data-testid="mnote-account-menu-trigger"
|
||||
data-mnote-action="open-account-menu"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<span class="material-symbols-outlined nav-icon" data-icon="more_horiz" aria-hidden="true"></span>
|
||||
</button>
|
||||
</nav>
|
||||
<div class="wolai-sidebar-body" inner_html={sidebar_sections_html}></div>
|
||||
<script id="__MNOTE_TREE_LIVE_BOOTSTRAP__" type="application/json" inner_html={tree_live_bootstrap}></script>
|
||||
|
||||
@@ -338,12 +338,81 @@ a:hover {
|
||||
color: #1D4ED8;
|
||||
}
|
||||
|
||||
.mnote-account-menu {
|
||||
inset-inline-start: auto;
|
||||
right: 8px;
|
||||
top: calc(100% - 10px);
|
||||
width: 232px;
|
||||
}
|
||||
|
||||
.mnote-account-menu__profile {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.mnote-account-menu__title {
|
||||
color: var(--wolai-text-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.mnote-account-menu__name {
|
||||
margin-top: 5px;
|
||||
color: var(--wolai-text-primary);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.mnote-account-menu__row {
|
||||
display: grid;
|
||||
grid-template-columns: 58px minmax(0, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
color: var(--wolai-text-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.mnote-account-menu__row strong {
|
||||
min-width: 0;
|
||||
color: var(--wolai-text-primary);
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.mnote-account-menu__separator {
|
||||
height: 1px;
|
||||
margin: 4px 0;
|
||||
background: var(--wolai-border);
|
||||
}
|
||||
|
||||
.mnote-account-menu__logout {
|
||||
color: #C2410C;
|
||||
}
|
||||
|
||||
.mnote-account-menu__logout:hover {
|
||||
background: #FFF7ED;
|
||||
}
|
||||
|
||||
.mnote-account-menu__error {
|
||||
padding: 6px 8px 2px;
|
||||
color: #B91C1C;
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.wolai-quick-actions {
|
||||
flex: 0 0 auto;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 8px;
|
||||
padding: 8px 12px 18px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wolai-quick-actions a,
|
||||
@@ -403,22 +472,6 @@ a:hover {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.mnote-empty-create-page {
|
||||
margin-top: 14px;
|
||||
height: 34px;
|
||||
padding: 0 14px;
|
||||
border: 1px solid var(--wolai-border);
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mnote-empty-create-page:hover {
|
||||
background: var(--wolai-bg-hover);
|
||||
}
|
||||
|
||||
.wolai-page-row {
|
||||
min-height: 38px;
|
||||
display: flex;
|
||||
@@ -1519,8 +1572,7 @@ body {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sidebar-tree .tree-empty,
|
||||
.wolai-sidebar-empty {
|
||||
.sidebar-tree .tree-empty {
|
||||
padding: 6px 12px;
|
||||
color: var(--atelier-text-soft);
|
||||
font-size: 13px;
|
||||
|
||||
@@ -129,9 +129,6 @@ pub fn render_initial_filetree_html(input: &FileTreeInitialRenderInput) -> Strin
|
||||
r#"<ul class="tree-root" role="tree" data-rust-filetree-renderer="initial_v1">"#,
|
||||
);
|
||||
if input.rows.is_empty() {
|
||||
html.push_str(
|
||||
r#"<li class="tree-empty" data-rust-rendered-row="filetree-empty">暂无文件或页面</li>"#,
|
||||
);
|
||||
html.push_str("</ul>");
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -161,9 +161,6 @@ pub fn render_initial_page_tree_html(input: &PageTreeInitialRenderInput) -> Stri
|
||||
let mut html =
|
||||
String::from(r#"<ul class="tree-root" role="tree" data-rust-page-renderer="initial_v1">"#);
|
||||
if input.rows.is_empty() {
|
||||
html.push_str(
|
||||
r#"<li class="tree-empty" data-rust-rendered-row="page-empty">暂无页面</li>"#,
|
||||
);
|
||||
html.push_str("</ul>");
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,8 @@ mod tests {
|
||||
build_workspace_shell_projection(&dataset, "ws_demo", None, "开发用户 的工作区");
|
||||
let html = render_workspace_shell_sidebar_html(&projection, None, None);
|
||||
|
||||
assert!(html.contains("data-testid=\"wolai-sidebar-empty-state\""));
|
||||
assert!(!html.contains("data-testid=\"wolai-sidebar-empty-state\""));
|
||||
assert!(!html.contains("暂无页面"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -471,15 +472,14 @@ pub fn render_workspace_shell_sidebar_html(
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
r#"<div class="wolai-sidebar-empty" data-testid="wolai-sidebar-filetree-empty-state">暂无文件或页面</div>"#.to_string()
|
||||
String::new()
|
||||
});
|
||||
let empty_state = r#"<div class="wolai-sidebar-empty" data-testid="wolai-sidebar-empty-state">暂无页面</div>"#;
|
||||
let my_pages = if !tree_html.is_empty() {
|
||||
tree_html
|
||||
} else if !projected_my_pages.is_empty() {
|
||||
projected_my_pages
|
||||
} else {
|
||||
empty_state.to_string()
|
||||
String::new()
|
||||
};
|
||||
let bottom_entries = projection
|
||||
.bottom_entries
|
||||
|
||||
@@ -26,6 +26,8 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
import { readFileSync, existsSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
|
||||
const MNOTE_WEB_URL = process.env.MNOTE_WEB_URL || 'http://127.0.0.1:3000';
|
||||
const DEBUG = process.env.MNOTE_REASONIX_ACP_DEBUG === '1';
|
||||
@@ -162,8 +164,26 @@ process.env.DEEPSEEK_API_KEY = DEEPSEEK_API_KEY;
|
||||
// ── Dynamic import of reasonix public API ────────────
|
||||
|
||||
let CacheFirstLoop, DeepSeekClient, ToolRegistry, ImmutablePrefix;
|
||||
async function importReasonix() {
|
||||
try {
|
||||
return await import('reasonix');
|
||||
} catch (error) {
|
||||
let npmRoot = '';
|
||||
try {
|
||||
npmRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim();
|
||||
} catch {
|
||||
throw error;
|
||||
}
|
||||
const globalEntry = join(npmRoot, 'reasonix', 'dist', 'index.js');
|
||||
if (!existsSync(globalEntry)) {
|
||||
throw error;
|
||||
}
|
||||
return import(pathToFileURL(globalEntry).href);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const r = await import('reasonix');
|
||||
const r = await importReasonix();
|
||||
CacheFirstLoop = r.CacheFirstLoop;
|
||||
DeepSeekClient = r.DeepSeekClient;
|
||||
ToolRegistry = r.ToolRegistry;
|
||||
|
||||
@@ -112,7 +112,8 @@ async function validateGateway(baseUrl) {
|
||||
assert.match(auth.headers.get("content-type") || "", /text\/html/);
|
||||
assert.equal(auth.headers.get("x-mnote-legacy-upstream"), null, "/auth 不应再代理 3100");
|
||||
assert.match(authText, /data-mnote-shell="auth"/);
|
||||
assert.match(authText, /邮箱登录/);
|
||||
assert.match(authText, /账号登录/);
|
||||
assert.match(authText, /邮箱或用户名/);
|
||||
assert.match(authText, /测试账号快速登录/);
|
||||
assert.doesNotMatch(authText, /隐私政策|使用\s*Google|使用\s*GitHub|第三方快捷/iu);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ async function main() {
|
||||
assert.equal(await staticHomeLinks.count(), 0, "根页仍使用 .mnote-home-links 静态设计列表作为主内容");
|
||||
const hasDocumentShell = (await documentShell.count()) > 0;
|
||||
const hasEmptyState = (await emptyState.count()) > 0;
|
||||
assert(hasDocumentShell || hasEmptyState, "根页必须渲染真实 active page shell 或明确空 workspace state");
|
||||
assert(!hasEmptyState, "空工作区不应再渲染可见占位空态");
|
||||
|
||||
const sidebarBox = await boundingBox(sidebar, "左侧栏");
|
||||
const topbarBox = await boundingBox(topbar, "顶栏");
|
||||
@@ -76,7 +76,7 @@ async function main() {
|
||||
const contentBox = await boundingBox(content, "主内容区");
|
||||
const primaryContentBox = hasDocumentShell
|
||||
? await boundingBox(documentShell, "active page shell")
|
||||
: await boundingBox(emptyState, "空 workspace state");
|
||||
: contentBox;
|
||||
const floatingAiBox = await boundingBox(floatingAi, "AI 浮动按钮");
|
||||
const floatingHelpBox = await boundingBox(floatingHelp, "帮助浮动按钮");
|
||||
|
||||
|
||||
@@ -65,8 +65,10 @@ async function validateAuthEntry(baseUrl) {
|
||||
assert.equal(auth.headers.get("x-mnote-legacy-upstream"), null, "/auth 不应代理到 3100");
|
||||
assert.match(authText, /data-mnote-shell="auth"/);
|
||||
assert.match(authText, /data-testid="mnote-auth-page"/);
|
||||
assert.match(authText, /邮箱登录/);
|
||||
assert.match(authText, /name="email"[^>]*type="email"|type="email"[^>]*name="email"/);
|
||||
assert.match(authText, /账号登录/);
|
||||
assert.match(authText, /邮箱或用户名/);
|
||||
assert.match(authText, /name="account"[^>]*type="text"|type="text"[^>]*name="account"/);
|
||||
assert.doesNotMatch(authText, /name="username"/);
|
||||
assert.match(authText, /name="password"[^>]*type="password"|type="password"[^>]*name="password"/);
|
||||
assert.match(authText, /data-auth-mode="convex-password"/);
|
||||
assert.match(authText, /没有账号?注册/);
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* task487 — Local Folder Tree Live Consumer smoke
|
||||
*
|
||||
* STATUS: 🔴 RED (预期失败)
|
||||
*
|
||||
* 本 smoke 验证 local_folder 文档页的 Tree Live Consumer 收敛目标:
|
||||
* 1. data-mnote-tree-live-transport 不再等于 "local-folder-static"(应改为
|
||||
* "local-folder-events" 或等价 tree live transport)
|
||||
* 2. 外部文件变化后,Sidebar / FileTree 刷新通过 tree live consumer 完成
|
||||
* (data-mnote-tree-live-applied 为 "snapshot" / "resync")
|
||||
* 3. data-mnote-local-folder-watch-applied 不再是唯一刷新证据
|
||||
*
|
||||
* 当前为 RED:Workers A(后端 local_folder tree live event stream)和
|
||||
* Worker B(前端 tree live controller 接入 local_folder)尚未完成。
|
||||
* 断言 1~3 当前均预期失败。——本 smoke 用于验收,直至三个断言全 PASS
|
||||
* 后收敛 checklist 才能归档。
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const { chromium } = require("playwright");
|
||||
|
||||
const BASE_URL = (process.env.MNOTE_WEB_SMOKE_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
|
||||
const UI_TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_UI_TIMEOUT_MS || 30_000);
|
||||
const OUTPUT_DIR = path.join(process.cwd(), "tmp", "task487-local-folder-tree-live-consumer-smoke");
|
||||
const RESULT_PATH = path.join(OUTPUT_DIR, "result.json");
|
||||
const SCREENSHOT_BEFORE_PATH = path.join(OUTPUT_DIR, "page-tree-before-create.png");
|
||||
const SCREENSHOT_AFTER_PATH = path.join(OUTPUT_DIR, "page-tree-after-create.png");
|
||||
const CHROMIUM_EXECUTABLE_PATH = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH
|
||||
|| ["/usr/bin/google-chrome-stable", "/usr/bin/google-chrome", "/snap/bin/chromium"]
|
||||
.find((candidate) => fs.existsSync(candidate));
|
||||
|
||||
function fileUrl(localPath) {
|
||||
return `file://${localPath}`;
|
||||
}
|
||||
|
||||
function treeUrl(root, mode) {
|
||||
const url = new URL(`${BASE_URL}/`);
|
||||
url.searchParams.set("treeView", mode);
|
||||
url.searchParams.set("sourceKind", "local_folder");
|
||||
url.searchParams.set("rootUri", fileUrl(root));
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
function documentUrl(root, relativePath, mode) {
|
||||
const url = new URL(`${BASE_URL}/documents/${encodeURIComponent(localMdDocumentId(relativePath))}`);
|
||||
url.searchParams.set("sourceKind", "local_folder");
|
||||
url.searchParams.set("rootUri", fileUrl(root));
|
||||
if (mode) url.searchParams.set("treeView", mode);
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
function localMdDocumentId(relativePath) {
|
||||
return `local-md:${relativePath.replaceAll("/", "~2F")}`;
|
||||
}
|
||||
|
||||
function writeWorkspaceManifest(root, ownerId) {
|
||||
const metadataDir = path.join(root, ".mnote");
|
||||
fs.mkdirSync(metadataDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(metadataDir, "workspace.json"),
|
||||
`${JSON.stringify({
|
||||
workspaceId: `local-ws:${ownerId}:task487`,
|
||||
ownerId,
|
||||
createdAt: new Date().toISOString(),
|
||||
capabilities: ["local_files", "markdown_edit"],
|
||||
}, null, 2)}\n`,
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 <html> 上的所有 data-mnote-tree-live-* 属性和
|
||||
* data-mnote-local-folder-watch-applied,返回一个状态对象。
|
||||
*/
|
||||
async function readLiveDomState(page) {
|
||||
return page.evaluate(() => {
|
||||
const html = document.documentElement;
|
||||
return {
|
||||
treeLiveTransport: html.getAttribute("data-mnote-tree-live-transport") || "",
|
||||
treeLiveStatus: html.getAttribute("data-mnote-tree-live-status") || "",
|
||||
treeLiveApplied: html.getAttribute("data-mnote-tree-live-applied") || "",
|
||||
treeLiveRevision: html.getAttribute("data-mnote-tree-live-revision") || "",
|
||||
treeLiveApplyError: html.getAttribute("data-mnote-tree-live-apply-error") || "",
|
||||
localFolderWatchApplied: html.getAttribute("data-mnote-local-folder-watch-applied") || "",
|
||||
url: window.location.href,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言 helper:检查条件,返回 { pass, expected, actual, label }
|
||||
*/
|
||||
function check(label, condition, expected, actual) {
|
||||
return {
|
||||
label,
|
||||
pass: !!condition,
|
||||
expected: String(expected),
|
||||
actual: String(actual),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待 page tree row 出现(基于 task435 模式)
|
||||
*/
|
||||
async function waitForPageTreeNode(page, documentId) {
|
||||
await page.waitForFunction(
|
||||
(expectedDocumentId) => Array.from(document.querySelectorAll("#sidebar-tree-root .tree-row[data-node-id]"))
|
||||
.some((row) => row.getAttribute("data-node-id") === expectedDocumentId),
|
||||
documentId,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "mnote-tree-live-consumer-"));
|
||||
fs.mkdirSync(path.join(root, "docs"), { recursive: true });
|
||||
writeWorkspaceManifest(root, "user_real");
|
||||
fs.writeFileSync(path.join(root, "README.md"), "# Local Root\n", "utf8");
|
||||
fs.writeFileSync(path.join(root, "docs", "stable.md"), "# Stable Page\n", "utf8");
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
...(CHROMIUM_EXECUTABLE_PATH ? { executablePath: CHROMIUM_EXECUTABLE_PATH } : {}),
|
||||
});
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1280, height: 860 },
|
||||
extraHTTPHeaders: {
|
||||
"x-mnote-actor-id": "user_real",
|
||||
"x-mnote-actor-type": "user",
|
||||
},
|
||||
});
|
||||
const page = await context.newPage();
|
||||
const navigationEvents = [];
|
||||
page.on("framenavigated", (frame) => {
|
||||
if (frame === page.mainFrame()) {
|
||||
navigationEvents.push({ url: frame.url(), timestamp: Date.now() });
|
||||
}
|
||||
});
|
||||
|
||||
const assertions = [];
|
||||
let domStateBefore = null;
|
||||
let domStateAfterCreate = null;
|
||||
let domStateAfterDelete = null;
|
||||
let fatalError = null;
|
||||
|
||||
try {
|
||||
// ── 登录 ──
|
||||
await page.goto(`${BASE_URL}/auth`, { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
const quickLoginButton = page.getByRole("button", { name: "测试账号快速登录" });
|
||||
if (await quickLoginButton.count()) {
|
||||
await quickLoginButton.click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForURL((url) => url.pathname === "/", { timeout: UI_TIMEOUT_MS });
|
||||
}
|
||||
|
||||
// ── Phase 1: Page Tree 视图 ──
|
||||
await page.goto(documentUrl(root, "README.md", "page"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
// 等待页面稳定
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const html = document.documentElement;
|
||||
const transport = html.getAttribute("data-mnote-tree-live-transport") || "";
|
||||
return transport !== "";
|
||||
},
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
).catch(() => {});
|
||||
await page.waitForTimeout(300);
|
||||
navigationEvents.length = 0;
|
||||
|
||||
// 记录加载后 DOM 状态
|
||||
domStateBefore = await readLiveDomState(page);
|
||||
|
||||
// 断言 1: transport 不应为 local-folder-static
|
||||
assertions.push(check(
|
||||
"data-mnote-tree-live-transport !== 'local-folder-static'",
|
||||
domStateBefore.treeLiveTransport !== "local-folder-static",
|
||||
'非 local-folder-static(期望 "local-folder-events" 或等价)',
|
||||
domStateBefore.treeLiveTransport,
|
||||
));
|
||||
|
||||
// 断言 2: status 不应为 static
|
||||
assertions.push(check(
|
||||
"data-mnote-tree-live-status 不为 static",
|
||||
domStateBefore.treeLiveStatus !== "static",
|
||||
"connected / connecting / disabled 等非 static 值",
|
||||
domStateBefore.treeLiveStatus,
|
||||
));
|
||||
|
||||
// 断言 3: 有 transport 属性(不是空)
|
||||
assertions.push(check(
|
||||
"data-mnote-tree-live-transport 非空",
|
||||
domStateBefore.treeLiveTransport !== "",
|
||||
"非空字符串",
|
||||
domStateBefore.treeLiveTransport,
|
||||
));
|
||||
|
||||
// 截图:page tree 加载后状态
|
||||
await page.screenshot({ path: SCREENSHOT_BEFORE_PATH, fullPage: false });
|
||||
|
||||
// 断言 4: 外部文件创建后,tree live applied 应为 snapshot 或 resync
|
||||
// 先确认页面稳定
|
||||
await page.waitForTimeout(200);
|
||||
domStateBefore = await readLiveDomState(page);
|
||||
|
||||
// 创建外部文件
|
||||
const createdFileRel = "docs/live-consumer-test.md";
|
||||
fs.writeFileSync(path.join(root, createdFileRel), "# Live Consumer Test\n", "utf8");
|
||||
|
||||
// 等待 page tree row 出现(当前通过 polling 机制)
|
||||
await waitForPageTreeNode(page, localMdDocumentId(createdFileRel)).catch(() => {});
|
||||
|
||||
// 等待一小段时间让 tree live consumer 有机会触发
|
||||
await page.waitForTimeout(400);
|
||||
|
||||
domStateAfterCreate = await readLiveDomState(page);
|
||||
|
||||
// 断言 4: applied 应为 snapshot 或 resync
|
||||
const appliedOk = domStateAfterCreate.treeLiveApplied === "snapshot"
|
||||
|| domStateAfterCreate.treeLiveApplied === "resync";
|
||||
assertions.push(check(
|
||||
"外部创建后 data-mnote-tree-live-applied 为 snapshot|resync",
|
||||
appliedOk,
|
||||
"snapshot 或 resync",
|
||||
domStateAfterCreate.treeLiveApplied,
|
||||
));
|
||||
|
||||
// 断言 5: watch-applied 不再是唯一证据
|
||||
// 即 treeLiveApplied 存在(非空)或 transport 不是 local-folder-static
|
||||
// 如果 watch-applied 是唯一标记而 treeLiveApplied 为空,则不合格
|
||||
const hasTreeLiveEvidence = domStateAfterCreate.treeLiveApplied !== ""
|
||||
|| domStateAfterCreate.treeLiveTransport !== "local-folder-static";
|
||||
assertions.push(check(
|
||||
"存在 tree live consumer 证据(非仅 local-folder-watch-applied)",
|
||||
hasTreeLiveEvidence,
|
||||
"treeLiveApplied 非空 或 transport !== local-folder-static",
|
||||
`treeLiveApplied="${domStateAfterCreate.treeLiveApplied}" transport="${domStateAfterCreate.treeLiveTransport}"`,
|
||||
));
|
||||
|
||||
// 断言 6: 外部文件删除后同样有 tree live applied 痕迹
|
||||
fs.rmSync(path.join(root, createdFileRel));
|
||||
await page.waitForFunction(
|
||||
(expectedId) => !Array.from(document.querySelectorAll("#sidebar-tree-root .tree-row[data-node-id]"))
|
||||
.some((row) => row.getAttribute("data-node-id") === expectedId),
|
||||
localMdDocumentId(createdFileRel),
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
).catch(() => {});
|
||||
await page.waitForTimeout(400);
|
||||
domStateAfterDelete = await readLiveDomState(page);
|
||||
|
||||
const appliedDelOk = domStateAfterDelete.treeLiveApplied === "snapshot"
|
||||
|| domStateAfterDelete.treeLiveApplied === "resync";
|
||||
assertions.push(check(
|
||||
"外部删除后 data-mnote-tree-live-applied 为 snapshot|resync",
|
||||
appliedDelOk,
|
||||
"snapshot 或 resync",
|
||||
domStateAfterDelete.treeLiveApplied,
|
||||
));
|
||||
|
||||
// 截图:外部创建后
|
||||
await page.screenshot({ path: SCREENSHOT_AFTER_PATH, fullPage: false });
|
||||
|
||||
// ── Phase 2: FileTree 视图 ──
|
||||
await page.goto(documentUrl(root, "README.md", "filetree"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const html = document.documentElement;
|
||||
const transport = html.getAttribute("data-mnote-tree-live-transport") || "";
|
||||
return transport !== "";
|
||||
},
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
).catch(() => {});
|
||||
await page.waitForTimeout(300);
|
||||
navigationEvents.length = 0;
|
||||
|
||||
const filetreeState = await readLiveDomState(page);
|
||||
|
||||
assertions.push(check(
|
||||
"FileTree: transport !== 'local-folder-static'",
|
||||
filetreeState.treeLiveTransport !== "local-folder-static",
|
||||
"非 local-folder-static",
|
||||
filetreeState.treeLiveTransport,
|
||||
));
|
||||
|
||||
assertions.push(check(
|
||||
"FileTree: status 不为 static",
|
||||
filetreeState.treeLiveStatus !== "static",
|
||||
"非 static",
|
||||
filetreeState.treeLiveStatus,
|
||||
));
|
||||
|
||||
// FileTree 外部创建
|
||||
fs.writeFileSync(path.join(root, "docs", "filetree-live-test.md"), "# FileTree Live\n", "utf8");
|
||||
// 等待 filetree row 出现(与 task435 同模式)
|
||||
await page.locator(`.tree-row[data-row-id="local:markdown:docs/filetree-live-test.md"]`).waitFor({
|
||||
state: "visible",
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
}).catch(() => {});
|
||||
await page.waitForTimeout(400);
|
||||
|
||||
const filetreeAfterCreate = await readLiveDomState(page);
|
||||
|
||||
assertions.push(check(
|
||||
"FileTree 外部创建后 tree-live-applied 为 snapshot|resync",
|
||||
filetreeAfterCreate.treeLiveApplied === "snapshot" || filetreeAfterCreate.treeLiveApplied === "resync",
|
||||
"snapshot 或 resync",
|
||||
filetreeAfterCreate.treeLiveApplied,
|
||||
));
|
||||
|
||||
} catch (err) {
|
||||
fatalError = err && err.stack ? err.stack : String(err);
|
||||
} finally {
|
||||
// 不论是否异常,都输出结果
|
||||
const allPassed = assertions.every((a) => a.pass);
|
||||
const result = {
|
||||
ok: allPassed,
|
||||
red: !allPassed,
|
||||
baseUrl: BASE_URL,
|
||||
outputDir: OUTPUT_DIR,
|
||||
summary: allPassed
|
||||
? "✅ 所有断言通过 — local_folder 已收敛到 tree live consumer"
|
||||
: "🔴 RED — 一个或多个断言失败,local_folder 仍使用 local-folder-static / polling 主链",
|
||||
assertions,
|
||||
domStateBefore,
|
||||
domStateAfterCreate,
|
||||
domStateAfterDelete,
|
||||
navigationEvents: navigationEvents.slice(0, 20),
|
||||
screenshots: {
|
||||
pageTreeLoaded: SCREENSHOT_BEFORE_PATH,
|
||||
afterExternalCreate: SCREENSHOT_AFTER_PATH,
|
||||
},
|
||||
fatalError,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
fs.writeFileSync(RESULT_PATH, `${JSON.stringify(result, null, 2)}\n`, "utf8");
|
||||
console.log(`task487 结果: ${RESULT_PATH}`);
|
||||
console.log(JSON.stringify({ ok: result.ok, red: result.red, assertionSummary: assertions.map((a) => ({
|
||||
label: a.label,
|
||||
pass: a.pass,
|
||||
actual: a.actual,
|
||||
})) }, null, 2));
|
||||
|
||||
await browser.close().catch(() => {});
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
|
||||
// 退出码:RED smoke 不 process.exit(1),让 CI 可收集失败证据
|
||||
if (!allPassed) {
|
||||
console.error("🔴 RED smoke — 预期失败(Workers A+B 尚未完成)");
|
||||
process.exit(0); // RED smoke 退出 0 以便 CI 管道记录而非阻断
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
const result = {
|
||||
ok: false,
|
||||
baseUrl: BASE_URL,
|
||||
error: error && error.stack ? error.stack : String(error),
|
||||
};
|
||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
||||
fs.writeFileSync(RESULT_PATH, `${JSON.stringify(result, null, 2)}\n`, "utf8");
|
||||
console.error(error);
|
||||
process.exit(0); // RED smoke 不阻断 CI
|
||||
});
|
||||
@@ -0,0 +1,302 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { chromium } = require("playwright");
|
||||
const {
|
||||
BASE_URL,
|
||||
REQUEST_TIMEOUT_MS,
|
||||
UI_TIMEOUT_MS,
|
||||
cleanupDocuments,
|
||||
createTempDocument,
|
||||
ensureAuthenticated,
|
||||
renameDocument,
|
||||
requestJson,
|
||||
} = require("./tree-shell-smoke-helpers");
|
||||
|
||||
const OUT_DIR = path.join(process.cwd(), "tmp", "acp-multi-session-stability-smoke");
|
||||
const PROFILE = process.env.MNOTE_ACP_STABILITY_PROFILE || "reasonix";
|
||||
const RUNTIME = process.env.MNOTE_ACP_STABILITY_RUNTIME || "";
|
||||
const RUN_COUNT = Math.max(1, Number(process.env.MNOTE_ACP_STABILITY_RUN_COUNT || 3));
|
||||
const STREAM_TIMEOUT_MS = Number(process.env.MNOTE_ACP_STABILITY_STREAM_TIMEOUT_MS || 60_000);
|
||||
const CANCEL_INDEX = Math.min(Math.max(0, Number(process.env.MNOTE_ACP_STABILITY_CANCEL_INDEX || 1)), RUN_COUNT - 1);
|
||||
|
||||
function nowSuffix() {
|
||||
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
async function createHermesSession(request, target, suffix, index) {
|
||||
return requestJson(request, "/api/hermes/client/sessions", {
|
||||
method: "POST",
|
||||
headers: { "x-mnote-actor-id": "acp-smoke-user" },
|
||||
data: {
|
||||
workspaceId: target.workspaceId,
|
||||
documentId: target.documentId,
|
||||
title: `ACP 稳定性 ${suffix} #${index + 1}`,
|
||||
profile: PROFILE,
|
||||
traceId: `trace_acp_session_${suffix}_${index}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function createHermesRun(request, target, sessionId, suffix, index) {
|
||||
const payload = {
|
||||
workspaceId: target.workspaceId,
|
||||
documentId: target.documentId,
|
||||
sessionId,
|
||||
profile: PROFILE,
|
||||
message:
|
||||
index === CANCEL_INDEX
|
||||
? `请用中文逐条列出 1 到 200 的检查项,每条都包含 ACP 多会话 smoke ${suffix},不要修改文件。`
|
||||
: `请用一句中文回复:ACP 多会话 smoke ${suffix} 第 ${index + 1} 条。不要修改文件。`,
|
||||
contextScope: "summary",
|
||||
traceId: `trace_acp_run_${suffix}_${index}`,
|
||||
actorId: "acp-smoke-user",
|
||||
};
|
||||
if (RUNTIME) {
|
||||
payload.acpRuntime = RUNTIME;
|
||||
}
|
||||
return requestJson(request, "/api/hermes/client/runs", {
|
||||
method: "POST",
|
||||
headers: { "x-mnote-actor-id": "acp-smoke-user" },
|
||||
data: payload,
|
||||
});
|
||||
}
|
||||
|
||||
async function abortRun(request, runId) {
|
||||
return requestJson(request, `/api/hermes/client/runs/${encodeURIComponent(runId)}/abort`, {
|
||||
method: "POST",
|
||||
headers: { "x-mnote-actor-id": "acp-smoke-user" },
|
||||
data: { reason: "task488_acp_stability_smoke_cancel" },
|
||||
});
|
||||
}
|
||||
|
||||
function parseSseChunk(text, events) {
|
||||
for (const frame of text.split(/\n\n+/)) {
|
||||
const lines = frame.split(/\n/).filter(Boolean);
|
||||
if (lines.length === 0) continue;
|
||||
let event = "message";
|
||||
const dataLines = [];
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("event:")) {
|
||||
event = line.slice("event:".length).trim() || "message";
|
||||
} else if (line.startsWith("data:")) {
|
||||
dataLines.push(line.slice("data:".length).trimStart());
|
||||
}
|
||||
}
|
||||
if (dataLines.length === 0) continue;
|
||||
const dataText = dataLines.join("\n");
|
||||
let data = dataText;
|
||||
try {
|
||||
data = JSON.parse(dataText);
|
||||
} catch {
|
||||
// 保留原始文本,便于排障。
|
||||
}
|
||||
events.push({ event, data });
|
||||
}
|
||||
}
|
||||
|
||||
async function cookieHeaderForContext(context) {
|
||||
const cookies = await context.cookies(BASE_URL);
|
||||
return cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
|
||||
}
|
||||
|
||||
async function streamRunEvents(runId, label, cookieHeader) {
|
||||
const events = [];
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), STREAM_TIMEOUT_MS);
|
||||
try {
|
||||
const response = await fetch(`${BASE_URL}/api/hermes/client/events/${encodeURIComponent(runId)}`, {
|
||||
headers: {
|
||||
"x-mnote-actor-id": "acp-smoke-user",
|
||||
...(cookieHeader ? { cookie: cookieHeader } : {}),
|
||||
},
|
||||
signal: controller.signal,
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`${label} events 请求失败: ${response.status} ${response.statusText} ${text.slice(0, 1200)}`);
|
||||
}
|
||||
const decoder = new TextDecoder();
|
||||
const reader = response.body.getReader();
|
||||
let raw = "";
|
||||
let pending = "";
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
const chunk = decoder.decode(value, { stream: true });
|
||||
raw += chunk;
|
||||
pending += chunk;
|
||||
const frames = pending.split(/\n\n+/);
|
||||
pending = frames.pop() || "";
|
||||
if (frames.length > 0) {
|
||||
parseSseChunk(frames.join("\n\n"), events);
|
||||
}
|
||||
if (terminalEvent(events)) {
|
||||
await reader.cancel().catch(() => undefined);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const rest = decoder.decode();
|
||||
if (rest) {
|
||||
raw += rest;
|
||||
pending += rest;
|
||||
}
|
||||
if (pending.trim()) {
|
||||
parseSseChunk(pending, events);
|
||||
}
|
||||
if (!terminalEvent(events)) {
|
||||
throw new Error(`${label} events 未收到 terminal event`);
|
||||
}
|
||||
return { runId, status: response.status, events, raw };
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
controller.abort();
|
||||
}
|
||||
}
|
||||
|
||||
function terminalEvent(events) {
|
||||
return events.find((entry) => entry.event === "run.completed" || entry.event === "run.failed" || entry.event === "run.aborted");
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const suffix = nowSuffix();
|
||||
const title = `TEST-ACP-STABILITY-${suffix}`;
|
||||
const createdIds = [];
|
||||
const evidence = {
|
||||
ok: false,
|
||||
baseUrl: BASE_URL,
|
||||
profile: PROFILE,
|
||||
runtime: RUNTIME || null,
|
||||
runCount: RUN_COUNT,
|
||||
cancelIndex: CANCEL_INDEX,
|
||||
title,
|
||||
sessions: [],
|
||||
runs: [],
|
||||
streams: [],
|
||||
};
|
||||
await fs.mkdir(OUT_DIR, { recursive: true });
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ["--no-sandbox", "--disable-dev-shm-usage"],
|
||||
});
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
|
||||
const page = await context.newPage();
|
||||
|
||||
try {
|
||||
await ensureAuthenticated(page, context.request);
|
||||
const target = await createTempDocument(context.request);
|
||||
createdIds.push(target.documentId);
|
||||
evidence.documentId = target.documentId;
|
||||
evidence.workspaceId = target.workspaceId;
|
||||
await renameDocument(context.request, target.workspaceId, target.documentId, title);
|
||||
|
||||
const sessions = [];
|
||||
for (let index = 0; index < RUN_COUNT; index += 1) {
|
||||
const session = await createHermesSession(context.request, target, suffix, index);
|
||||
assert(session.sessionId, `session ${index + 1} 缺少 sessionId`);
|
||||
sessions.push(session);
|
||||
evidence.sessions.push({
|
||||
index,
|
||||
sessionId: session.sessionId,
|
||||
persistence: session.persistence || null,
|
||||
profile: session.profile || PROFILE,
|
||||
});
|
||||
}
|
||||
|
||||
const runs = await Promise.all(
|
||||
sessions.map((session, index) => createHermesRun(context.request, target, session.sessionId, suffix, index)),
|
||||
);
|
||||
for (let index = 0; index < runs.length; index += 1) {
|
||||
assert(runs[index].runId, `run ${index + 1} 缺少 runId`);
|
||||
evidence.runs.push({
|
||||
index,
|
||||
runId: runs[index].runId,
|
||||
sessionId: runs[index].sessionId,
|
||||
persistence: runs[index].persistence || null,
|
||||
runtime: runs[index].runtime || null,
|
||||
});
|
||||
}
|
||||
|
||||
const cookieHeader = await cookieHeaderForContext(context);
|
||||
const streamPromises = runs.map((run, index) => streamRunEvents(run.runId, `run ${index + 1}`, cookieHeader));
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
const abortPayload = await abortRun(context.request, runs[CANCEL_INDEX].runId);
|
||||
evidence.abort = {
|
||||
runId: runs[CANCEL_INDEX].runId,
|
||||
status: abortPayload.status,
|
||||
ok: abortPayload.ok,
|
||||
events: abortPayload.events || [],
|
||||
};
|
||||
|
||||
const streamResults = await Promise.allSettled(streamPromises);
|
||||
const rejectedStreams = streamResults
|
||||
.map((result, index) => ({ result, index }))
|
||||
.filter(({ result }) => result.status === "rejected");
|
||||
if (rejectedStreams.length > 0) {
|
||||
evidence.streamErrors = rejectedStreams.map(({ result, index }) => ({
|
||||
index,
|
||||
runId: runs[index].runId,
|
||||
message: result.reason instanceof Error ? result.reason.message : String(result.reason),
|
||||
stack: result.reason instanceof Error ? result.reason.stack : null,
|
||||
}));
|
||||
throw new Error(`ACP SSE 读取失败: ${evidence.streamErrors.map((item) => `run ${item.index + 1}: ${item.message}`).join("; ")}`);
|
||||
}
|
||||
const streams = streamResults.map((result) => result.value);
|
||||
for (let index = 0; index < streams.length; index += 1) {
|
||||
const stream = streams[index];
|
||||
const terminal = terminalEvent(stream.events);
|
||||
evidence.streams.push({
|
||||
index,
|
||||
runId: stream.runId,
|
||||
eventCount: stream.events.length,
|
||||
eventNames: stream.events.map((entry) => entry.event),
|
||||
terminalEvent: terminal ? terminal.event : null,
|
||||
});
|
||||
await fs.writeFile(
|
||||
path.join(OUT_DIR, `events-${index + 1}-${stream.runId}.json`),
|
||||
JSON.stringify(stream.events, null, 2),
|
||||
"utf8",
|
||||
);
|
||||
assert(terminal, `run ${index + 1} 必须收到 run.completed、run.failed 或 run.aborted`);
|
||||
if (index === CANCEL_INDEX) {
|
||||
assert.equal(terminal.event, "run.aborted", "被 abort 的 run 必须以 run.aborted 结束");
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Set(evidence.sessions.map((item) => item.sessionId)).size, RUN_COUNT, "sessionId 必须互相隔离");
|
||||
assert.equal(new Set(evidence.runs.map((item) => item.runId)).size, RUN_COUNT, "runId 必须互相隔离");
|
||||
assert(evidence.abort.ok === true, "abort API 必须返回 ok=true");
|
||||
evidence.ok = true;
|
||||
await fs.writeFile(path.join(OUT_DIR, "result.json"), JSON.stringify(evidence, null, 2), "utf8");
|
||||
console.log(JSON.stringify(evidence, null, 2));
|
||||
} finally {
|
||||
await cleanupDocuments(context.request, createdIds).catch(() => undefined);
|
||||
await context.close().catch(() => undefined);
|
||||
await browser.close().catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(async (error) => {
|
||||
await fs.mkdir(OUT_DIR, { recursive: true }).catch(() => undefined);
|
||||
await fs
|
||||
.writeFile(
|
||||
path.join(OUT_DIR, "error.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
ok: false,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : null,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
)
|
||||
.catch(() => undefined);
|
||||
console.error(error instanceof Error ? error.stack || error.message : String(error));
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -204,10 +204,7 @@ async function registerTestAccountIfNeeded(page) {
|
||||
}
|
||||
|
||||
await switchButton.click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="email"]').fill(TEST_EMAIL, { timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="username"]').fill(`${TEST_USERNAME_PREFIX}${Date.now().toString().slice(-6)}`, {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
});
|
||||
await page.locator('input[name="account"]').fill(TEST_EMAIL, { timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('input[name="password"]').fill(TEST_PASSWORD, { timeout: UI_TIMEOUT_MS });
|
||||
await page.getByRole("button", { name: "注册" }).click({ timeout: UI_TIMEOUT_MS });
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user