Skip to content

fix(memory): stop sending CLI arguments as analytics command actions - #566

Open
Anson-Se wants to merge 1 commit into
MemTensor:memmy_1031/v1.2.0from
Anson-Se:fix-cli-analytics-command-action
Open

Anson-Se wants to merge 1 commit into
MemTensor:memmy_1031/v1.2.0from
Anson-Se:fix-cli-analytics-command-action

Conversation

@Anson-Se

Copy link
Copy Markdown
Contributor

任务与行为

  • **关联记录:**Memmy 问题清单第 39 条"命令行工具的埋点把查询词、记忆正文和记忆 ID 当作'动作名'发到云端"。
  • **触发场景:**Agent 或用户执行 memmy-memory search "<查询词>"、memmy-memory add "<记忆正文>"、memmy-memory get <id>、memmy-memory delete <id>。Memmy 装给 Agent 的 Skill 教的就是这种写法。
  • **修改前:**每次执行都会向云端统计接口上报 memmy_cli_* 事件。resolveCommandIdentity 无条件把第二个词当作 command_action,本意是记录 session close 里的 close。可是 search、add、get、delete 没有子命令,第二个词就是查询词、记忆正文或记忆 ID,于是被原样发了出去。另外,第一个词不是已知命令时,原文会被当作 command_group 发出去。
  • **修改后:**只有第一个词是有子命令的命令组(service、session、turn、raw),且第二个词是该组已知的子命令时,才上报 command_action。raw 的方法名和 runRaw 一样不区分大小写。第一个词不是已知命令时,command_group 记为 unknown。has_session_id、has_turn_id 的判断不变。

修改范围

  • Memory/src/cli/analytics.ts:新增一张已知命令表,对应 commands.ts 里的 runCommand 和 mapTopLevelCommand,注释写明两边要保持一致;resolveCommandIdentity 改为按这张表判断。没有直接引用 commands.ts,因为 analytics.ts 还被 plugin-runtime-analytics、memory-add-analytics、memmy-runtime-config 这三个 CLI 以外的模块引用,反向引用会把 setup、runtime-installer 等模块一起带进来。
  • Memory/tests/analytics-contract.test.ts:新增用例,覆盖以下几点:
    • search、add、get、delete 的参数不作为 command_action 上报;
    • session close、turn complete、service start、raw GET、raw get 照常上报子命令,未知子命令不上报;
    • 未知命令记为 unknown;
    • 实际发出的事件参数里不含命令行参数。
  • 无前置依赖。只改上报字段的取值,命令本身的行为不变,不迁移数据。

验证证据

  • 分支 fix-cli-analytics-command-action,起点 d101fd58(即当前 memmy_1031/v1.2.0),提交 7ff1188b。提 PR 前已 fetch 并 merge 集成分支(Already up to date)。
  • 环境:macOS arm64,Node v25.1.0,npm 11.6.2。
  • 新增用例在修改前 7 个失败,第一条是 command_action: "some private query" 被原样上报;修改后全部通过。
  • npm run memory:test:106 个测试文件中 104 个通过、1 个跳过(仅在 Windows 上运行的安装器集成测试)、1 个失败;927 个用例中 925 个通过。失败的是 l3-world-model.test.ts 的 "keeps source IDs in evidence order and caps them at the latest 256…",原因是超时:上限 20 秒,这台机器跑全量时它要 35 秒左右。这个失败和本 PR 无关:
    • 在不含本 PR 改动的 d101fd58 上,同样条件下跑全量,也是这一条超时(35.4 秒,920 个用例中 918 个通过)。
    • 单独运行这条用例能通过,用时 13.5 秒。
  • npm run lint、npm run typecheck 通过。
  • git diff --check upstream/memmy_1031/v1.2.0...HEAD 无输出;交付差异只含上面两个文件。
  • 和 upstream/v1.1.9 做过试合并(git merge-tree),没有冲突。

已知限制

  • 失败事件(memmy_cli_failed)的 error_code 取的是报错原文的前 64 个字符,可能带出记忆 ID、未知命令的原文或 --body 的正文片段。这是另一个字段,需要另外修,本 PR 没有改。
  • 已经发出去的事件,客户端撤不回来。
  • 命令表是复制过来的。以后新增命令时如果没有同步更新这张表,这个命令只会被记为 unknown,不会漏发原文。

🤖 Generated with Claude Code

Every memmy-memory run reports memmy_cli_* events to the cloud analytics
endpoint. resolveCommandIdentity took the second positional word as
command_action unconditionally, which was meant for subcommands such as
`session close`. For search, add, get and delete that word is the search
query, the memory text or the memory id, so it was sent verbatim. An
unrecognized first word was also sent verbatim as command_group.

command_action is now reported only when the first word is a group with
subcommands (service, session, turn, raw) and the second word is one of
that group's known subcommands; raw methods match case-insensitively, as
runRaw does. An unrecognized first word is reported as command_group
"unknown". The known commands live in a small table in analytics.ts that
mirrors runCommand and mapTopLevelCommand. has_session_id and has_turn_id
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Anson-Se

Copy link
Copy Markdown
Contributor Author

@origami-chen 麻烦审核一下这个 PR:修复 memmy-memory 的埋点把查询词、记忆正文和记忆 ID 当作动作名发到云端的问题。现在只上报已知的子命令名,未知命令记为 unknown。细节见 PR 描述。谢谢!

This branch has not been deployed

No deployments
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.

2 participants