Skip to content

fix: Hook无法自动更新 - #574

Open
Orsted290 wants to merge 2 commits into
MemTensor:v1.2.1from
Orsted290:fix-hook-auto-update
Open

Orsted290 wants to merge 2 commits into
MemTensor:v1.2.1from
Orsted290:fix-hook-auto-update

Conversation

@Orsted290

Copy link
Copy Markdown

这次修的是:Memmy 更新后,已经接入的 Hook 仍停在首次安装时的脚本。分支 fix-hook-auto-update,提交 32c34374,基线是 upstream/memmy_1031/v1.2.0。尚未推送,也没有建 PR。

问题定位

截图版本是 1.1.5。新版本里的 Hook 不会写进用户已经接入的 Agent,除非手动卸载再安装。

桌面端启动、打开或激活主窗口时,只会调用自动接入。agent-source-auto-inject-service.ts 里,状态不是 not_connected 就直接跳过。第一次安装会把 memmy-resume-hook.mjs 和 memmy-workspace-bridge.mjs 写到 Agent 目录,并把状态记成 plugin_installed。之后应用更新只换包内模板,不会再调用 installPlugin。installPlugin 本身可以覆盖这两个文件,缺的是更新后的检查。

修复方案

用当前包会写出的 Hook 脚本和桥接文件计算 SHA-256,安装时写入旁边的 memmy-memory-config.json,字段是 hook_revision。服务地址和 token 不参与计算。

启动时对已经安装 Hook 的 Cursor、Claude Code、Codex 做比较。指纹缺失、不一致,或脚本文件不在,就直接再执行 installPlugin,不必先卸载。指纹相同则跳过。「发现新 Agent 时自动接入」关闭时,这次检查仍然会做。检查发生在窗口创建之后,不挡启动。

自测样例

这是代表性样例,不是原用户环境的复现。后端 7 个文件、88 项测试通过,npm run lint 和 npm run typecheck 通过。合入集成分支后树没有变化,同一组测试再跑了一次,仍是 88 项通过。

  • 旧安装没有 hook_revision、指纹被改成过期值,或 Hook 脚本被删掉时,判定为需要更新。再次安装后判定为当前版本。Cursor、Claude Code、Codex 都测了。
  • 自动接入关闭时,过期的 Cursor Hook 仍会重装。指纹已是当前版本的 Hook 不会重写。
  • Hermes、OpenCode 这类插件不会被当成 Hook 刷新。Agent 不可用或没有写入权限时跳过。某一个 Hook 更新失败时,其他 Agent 继续安装。

本地打包安装自测

安装包:

/Users/haoyang/Documents/ChatGPT/memmy debug/memmy-agent/App/shell/desktop/release/Memmy-1.1.8-darwin-arm64-cn-unsigned.dmg

约 375MB,Apple 芯片、中国区、未签名,版本号 1.1.8。包内包含这次的 hook_revision 检查。

本机「应用程序」里原来是 9 月 23 日的 Memmy,Cursor 和 Codex 的 Hook 没有指纹。Claude Code 没有已安装的 Hook。退出旧应用后换成今天的包,并把这两份配置的 hook_revision 改成 stale。

第一次启动后,两份 Hook 都被重写,配置里的指纹与磁盘上的脚本、桥接文件一致:

  • Cursor:88c2a7de405de42e57742829446a8e617563a44bd4549d59fa096bd160aaa8bd
  • Codex:e2d12413a5fc101aa94ad1a5889e68e2a66c63397d8e74de5dd2cb05e619e6f5

退出后再打开一次,这 6 个文件的修改时间都没有变。

App updates left previously installed Cursor, Claude Code, and Codex hooks on the first-install script. Startup now compares the stored hook fingerprint and reinstalls when it is missing or stale.

Co-authored-by: Cursor <cursoragent@cursor.com>
@syzsunshine219
syzsunshine219 changed the base branch from memmy_1031/v1.2.0 to release/v1.2.0 September 30, 2026 09:21
@syzsunshine219
syzsunshine219 changed the base branch from release/v1.2.0 to v1.2.1 September 30, 2026 09:42
Keep the hook revision test beside the Cursor resume test renamed on v1.2.1.

Co-authored-by: Cursor <cursoragent@cursor.com>

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.

1 participant