Skip to content

feat(claude-code): verify Cowork source composition - #660

Merged
evan-ak merged 3 commits into
NevaMind-AI:mainfrom
XnneHangLab-Mirror:feat/cowork-verify
Aug 21, 2026
Merged

evan-ak merged 3 commits into
NevaMind-AI:mainfrom
XnneHangLab-Mirror:feat/cowork-verify

Conversation

@xnne-bot

@xnne-bot xnne-bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

📝 Pull Request Summary

为 memu-claude-code 增加一个只读的 Cowork 组合数据验证命令:

memu-claude-code cowork verify

用户更新 memu-cli 后,可通过一个命令验证 Cowork 数据是否可读、是否与 Claude Code 数据重叠,以及组合后的文件级时间线是否满足当前契约。


✅ What does this PR do?

  • 通过 Claude Code adapter 现有的 HostSpec.register_extra 扩展点注册 cowork verify,不向共享 host_cli.py 添加 Cowork 特例。
  • 提供三个聚合验证维度:
    • Readable:报告 roots、每个 root 的 session 数、可读/不可读 session 数,以及规范化 record/message 数。
    • Separation:报告 Code/Cowork session ID 交集,并以内存中的 (timestamp, role, content) SHA-256 fingerprint 检查精确消息重叠。
    • File timeline:验证 composite 数量可加、路径唯一、文件 mtime 非递增,并报告 Code/Cowork source transitions。
  • 支持可重复的 --root PATH,供 staging 和非标准 Claude Desktop 安装执行一次性显式探测。
  • 输出仅包含聚合元数据,不打印 transcript 内容或 fingerprint;不调用 prepare、不推进 cursor、不访问 memory backend,也不修改 scheduler/config。
  • 将无 root、无 session 或证据不足表示为 WARN 且退出码为 0;读取或组合契约失败表示为 FAIL 且退出码为 1;参数错误保持 argparse 的退出码 2。
  • 增加 CLI、PASS/WARN/FAIL、隐私与零写入测试。

🤔 Why is this change needed?

#639 将 Cowork audit 数据作为独立只读 source 合入 Claude Code bridge,但用户更新 memu-cli 后,当前只能通过运行 prepare 或导入 Python 内部接口来确认 discovery 和 composition 是否正确。

这个命令提供一个小而明确的只读验证入口,使用户和 staging 测试者无需触发 ingestion,就能直接检查 Cowork reader 与 Claude Code composite source 的关键契约。

Closes #657

@xnne-bot

Copy link
Copy Markdown
Contributor Author

Windows 实机只读验证结果:

Cowork sessions            15              # 自动发现到 15 个 Cowork 外层 session
readable sessions          15 / 15         # 所有发现的 audit.jsonl 均可读取并完成规范化
Claude Code files          1413            # Claude Code source 共发现 1,413 个 transcript 文件
Claude Code session IDs    655             # 这些文件归属于 655 个 Claude Code owner session
session-ID intersection    0               # Cowork 外层 session ID 与 Claude Code owner session ID 无交集
exact message overlap      0               # 两侧规范化 (timestamp, role, content) fingerprint 无精确重叠
composite files            1428 = 1413 + 15 # composite discovery 数量严格等于 Code 与 Cowork 之和
mtime order                non-increasing  # 合并后的 session-file 时间线按文件 mtime 非递增排列
Code/Cowork transitions    18              # composite 时间线中相邻文件发生 18 次 source 切换,证明两侧可正确交错

RESULT PASS                                 # Readable、Separation、File timeline 三个维度全部通过

该命令仅执行 discovery、读取与内存比较;未运行 prepare、未推进 cursor、未访问 memory backend,也未修改 scheduler/config。

@xnne-bot

xnne-bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

如何验证 Cowork 数据

推荐按下面的路径逐步验证;绝大多数情况下,第一步就会结束:

直接运行 cowork verify
  └─ PASS:完成,什么都不用改
  └─ 没用过 Cowork 且为 0:正常,完成
  └─ 用过 Cowork 但为 0:再用 --root 定位一次
       └─ --root 后正常:反馈实际 root,帮助补充自动发现路径
       └─ 仍发现不到:反馈脱敏目录结构,帮助适配 discovery layout
       └─ 能发现但读不到:反馈聚合结果,帮助适配读取或 record schema

绝大多数情况下,只需要更新到包含本 PR 的 memu-cli,然后运行一次:

memu-claude-code cowork verify

如果看到与下面类似的结果,验证就完成了,不需要修改任何配置或代码:

Cowork sessions            15
readable sessions          15 / 15
session-ID intersection    0
exact message overlap      0
composite files            1428 = 1413 + 15
mtime order                non-increasing

RESULT PASS

具体数量因机器而异。主要确认:Cowork sessions 能被发现且全部可读、两个 source 没有重叠、composite 数量可加、mtime 顺序正常,最终为 RESULT PASS。

Code/Cowork transitions 只是展示两个 source 在文件级时间线中的交错情况,没有固定合格值;即使为 0,也不一定表示异常。

只有自动发现与实际情况不符时,才需要继续

如果本机没有使用过 Cowork,那么 Cowork sessions 0 / RESULT WARN 是正常结果,到这里即可结束。

只有在本机确实使用过 Cowork,Desktop 观测本地会话不为空,但自动验证仍显示 0 sessions 时,才需要找到 Claude Desktop 的实际数据根目录,并临时用 --root 再试一次:

memu-claude-code cowork verify --root "/path/to/Claude-or-Claude-3p"

root 应当是包含 local-agent-mode-sessions 的 Claude Desktop 数据目录,而不是某个具体的 audit.jsonl。如有多个候选目录,可以重复传入:

memu-claude-code cowork verify --root "/path/one" --root "/path/two"

当前自动检查的 Windows、macOS 和 Linux 候选目录定义在 sessions.py 的 platform root providers。

--root 后能够正常发现

如果显式指定 root 后得到正常数据或 RESULT PASS,验证已经完成。这说明 Cowork 文件本身能够被现有 reader 解析,只是当前平台或安装方式的自动候选路径还没有覆盖该位置。

此时可以把以下信息反馈到 issue/PR,帮助维护者补充对应平台的自动 root list:

  • 操作系统和 Claude Desktop 安装方式;
  • 实际 root(可隐藏用户名等个人信息);
  • verify 的聚合输出。

不需要提供 transcript 内容,也不需要测试者自行修改源码。对应的候选路径代码分别位于 windows_data_roots()、macos_data_roots() 和 linux_data_roots()。

--root 指向正确目录后仍然发现不到

如果 root 下确实存在 Cowork audit 数据,但仍显示 0 sessions,只需反馈脱敏后的目录层级。当前 CoworkTranscriptSource.discover() 预期的结构是:

<root>/local-agent-mode-sessions/<account>/<organization>/local_<session-id>/audit.jsonl

这类结果可以帮助维护者判断 macOS、Linux、不同安装方式或新版 Claude Desktop 是否采用了不同的目录结构,并据此补充对应的 discovery walk 和测试。

能发现 sessions,但无法全部读取

如果 Cowork sessions 大于 0,但 readable sessions 少于发现数,或者 normalized messages 一直为 0,则 discovery 已经成功,差异更可能来自文件权限、编码或 audit record schema。读取与规范化逻辑位于 read_records() / _normalize()。

此时同样只需提交聚合输出、系统/Claude Desktop 版本,以及经过脱敏的最小文件结构或 record shape;verify 本身不会打印消息正文、fingerprint 或 audit key。

@MrXnneHang MrXnneHang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@wutongyuonce

Copy link
Copy Markdown
Contributor

macOS field verification found one concrete compatibility gap and I opened a patch against this PR branch: XnneHangLab-Mirror#1

Automatic discovery found 5 Cowork sessions and all 5 were readable, but 31 of 32 normalized Cowork messages had timestamp: null: these macOS records omit timestamp while carrying a valid ISO _audit_timestamp. That made Separation report WARN.

The patch preserves a normal message timestamp when present and falls back to _audit_timestamp only when missing, with a regression test. On the same real data after the change: 0 unfingerprintable messages, 0 session-ID intersections, 0 exact message overlaps, additive/unique/ordered timeline, and RESULT PASS.

Focused verification: 23 tests passed; Ruff format/check, mypy, and diff check passed. Only aggregate counts were inspected or reported; no transcript content or fingerprint was printed.

fix(claude-code): fall back to Cowork audit timestamps

@MrXnneHang MrXnneHang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@evan-ak
evan-ak merged commit 42f566a into NevaMind-AI:main Aug 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add a read-only Cowork discovery status command

4 participants