Skip to content

feat(plugins): add Codex and Claude Code memory integrations#453

Open
soongao wants to merge 2 commits into
TencentCloud:mainfrom
soongao:feat/agent-memory-plugins
Open

feat(plugins): add Codex and Claude Code memory integrations#453
soongao wants to merge 2 commits into
TencentCloud:mainfrom
soongao:feat/agent-memory-plugins

Conversation

@soongao

@soongao soongao commented Jul 9, 2026

Copy link
Copy Markdown

概述

本 PR 新增 TencentDB Agent Memory 的 Codex / Claude Code plugin 集成层。

它把已有的 MCP memory search 能力和 CLI hook adapter 能力接入到具体 agent runtime 中,让 Codex 和 Claude Code 可以通过 plugin 安装后获得:

  • MCP 记忆检索工具
  • 会话 hook 自动预取和捕获
  • agent 使用记忆工具的静态指导说明
  • 本地安装脚本和 plugin metadata

关联 Issue

Part of #235

前置依赖

本 PR 是 Codex / Claude Code 的 plugin 集成层,依赖前置 PR 提供的两个底层 adapter:

前置 PR 前置能力 说明
#451 MCP memory search server 提供 tdai_memory_search / tdai_conversation_search 两个 MCP 检索工具
#452 CLI memory hook adapter 提供 tdai-memory / tdai-memory-hook 命令,用于 hook 预取、捕获和 session flush

建议合并顺序:

MCP server PR (#451)
  -> CLI adapter PR (#452)
  -> Codex / Claude Code plugin PR

本 PR 的安装脚本会安装并注册上述两个 adapter,然后把它们接入 Codex / Claude Code 的 MCP、hooks、skill 和静态指导文件。

提供的 Plugin 能力

Runtime Plugin 目录 安装脚本 主要能力
Codex plugins/tdai-memory/ scripts/install-codex.sh Codex plugin metadata、MCP server 声明、Codex hooks、skill、AGENTS.md 记忆工具说明
Claude Code plugins/tdai-memory-claude-code/ scripts/install-claude-code.sh Claude Code plugin metadata、MCP server 声明、Claude Code hooks、skill、CLAUDE.md 记忆工具说明

MCP 能力接入

两个 plugin 都会注册同一个 tdai-memory MCP server,并向 agent 暴露记忆检索工具:

MCP tool 能力
tdai_memory_search 检索结构化长期记忆,适合查询用户偏好、项目上下文、历史事实和长期沉淀信息
tdai_conversation_search 检索原始会话历史,适合回溯之前的对话过程、任务细节和上下文片段

Codex plugin 会在安装时配置 tdai-memory MCP server 的 tool approval policy,默认允许这两个只读检索工具自动调用。

Hooks 能力接入

两个 plugin 都提供 runtime 对应的 hook 配置,把 agent 生命周期事件接到 tdai-memory-hook 命令:

Hook 事件 CLI 调用 能力
SessionStart tdai-memory-hook session-start 会话开始、恢复或压缩后检查 Gateway 连通性
UserPromptSubmit tdai-memory-hook prefetch 用户输入进入模型前预取相关记忆上下文
Stop tdai-memory-hook sync-turn assistant 输出完成后捕获本轮 user / assistant turn

Codex 和 Claude Code 的 hook 注册格式不同,因此本 PR 分别提供对应 runtime 的 plugin 配置:

  • plugins/tdai-memory/hooks/hooks.json
  • plugins/tdai-memory-claude-code/hooks/hooks.json

两边 hook 最终调用的是同一组 CLI adapter 命令,行为保持一致。

静态指导说明

两个安装脚本都会在用户本地 agent 指导文件中写入一段带 marker 的 TencentDB Agent Memory 说明:

Runtime 默认写入文件 内容
Codex ~/.codex/AGENTS.md 告诉 Codex 何时使用 tdai_memory_search / tdai_conversation_search,并限制单轮最多 3 次检索
Claude Code ~/.claude/CLAUDE.md 告诉 Claude Code 何时使用 tdai_memory_search / tdai_conversation_search,并限制单轮最多 3 次检索

写入逻辑是幂等的:如果目标文件已有 TDAI marker block,则替换该 block;如果没有,则追加一段新的 TDAI memory block。

安装时做了什么

本 PR 提供的安装脚本会完成本地 plugin 集成所需的配置写入。安装过程是幂等的,重复执行会更新已有的 TDAI 配置块,而不是重复追加。

Runtime 安装脚本 安装时写入/修改
Codex scripts/install-codex.sh 安装 MCP / CLI Python 包、注册本地 Codex plugin、注册 tdai-memory MCP server、写入 Codex hook 配置、更新 ~/.codex/AGENTS.md、配置 MCP tool approval policy、配置 hook diagnostic log 路径
Claude Code scripts/install-claude-code.sh 安装 MCP / CLI Python 包、注册本地 Claude Code plugin、写入 plugin MCP 配置、写入 Claude Code hook 配置、更新 ~/.claude/CLAUDE.md、配置 hook diagnostic log 路径

AGENTS.md / CLAUDE.md 的修改只发生在安装阶段:

Runtime 默认目标文件 修改方式 写入内容
Codex ~/.codex/AGENTS.md 使用 <!-- TDAI_MEMORY_START --> / <!-- TDAI_MEMORY_END --> marker block 幂等更新 说明 Codex 何时调用 tdai_memory_search / tdai_conversation_search,并限制单轮最多 3 次检索
Claude Code ~/.claude/CLAUDE.md 使用 <!-- TDAI_MEMORY_START --> / <!-- TDAI_MEMORY_END --> marker block 幂等更新 说明 Claude Code 何时调用 tdai_memory_search / tdai_conversation_search,并限制单轮最多 3 次检索

安装后的运行时 hook 命令不会动态创建、重写或注入 AGENTS.md / CLAUDE.md 内容。

安装入口

Codex

scripts/install-codex.sh

安装脚本会执行:

  • editable install packages/tdai-memory-mcp
  • editable install packages/tdai-memory-cli
  • 注册本地 Codex plugin marketplace
  • 安装 tdai-memory@tdai-memory-local
  • 注册 tdai-memory MCP server
  • 写入 plugin hooks
  • 更新 ~/.codex/AGENTS.md
  • 配置 MCP tool approval policy
  • 配置 hook diagnostic log 路径

Claude Code

scripts/install-claude-code.sh

安装脚本会执行:

  • editable install packages/tdai-memory-mcp
  • editable install packages/tdai-memory-cli
  • 注册本地 Claude Code plugin marketplace
  • 安装 tdai-memory-claude-code@tdai-memory-local
  • 写入 plugin MCP 配置
  • 写入 plugin hooks
  • 更新 ~/.claude/CLAUDE.md
  • 配置 hook diagnostic log 路径

运行链路

MCP 检索链路:

Codex / Claude Code
  -> tdai-memory plugin
  -> tdai-memory MCP server
  -> TDAI Gateway HTTP API
  -> TencentDB Agent Memory

Hook 捕获链路:

Codex / Claude Code hook event
  -> plugin hook command
  -> tdai-memory-hook
  -> tdai-memory CLI
  -> TDAI Gateway HTTP API
  -> TencentDB Agent Memory

自测结果

检查项 命令 结果
Plugin install scripts syntax check bash -n scripts/install-codex.sh scripts/install-claude-code.sh passed
CLI unit tests cd packages/tdai-memory-cli && python3 -m pytest tests/unit -q 16 passed
MCP unit tests cd packages/tdai-memory-mcp && python3 -m pytest tests/unit -q 16 passed

端到端安装验证需要本机已有 Codex / Claude Code CLI、可写的用户配置目录,以及已经运行的 TDAI Gateway,因此不作为默认单元自测的一部分。

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

@YOMXXX

YOMXXX commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Duplicate/scope cleanup triage for #235:

This PR currently depends on #451 and #452, both of which duplicate or extend the adapter foundation outside the approved #235 lanes. The current plugin layer also combines multiple concerns at once: MCP registration, CLI hook installation, Codex plugin metadata, Claude Code plugin metadata, marketplace writes, install scripts, and AGENTS/CLAUDE guidance updates.

The existing canonical boundaries are:

Recommendation: close this as a stacked integration PR for now. After #316/#372 land, reopen smaller follow-ups per runtime if needed: one Codex plugin wrapper and one Claude Code plugin wrapper, each using the approved MCP/Gateway pieces and with install-script/config writes reviewed as their own risk surface.

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.

3 participants