feat(adapter): 新增 Claude Code 记忆适配#477
Conversation
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
|
Scope cleanup triage for #235: This PR has useful Claude Code hook material, but it currently bundles several layers that already have canonical or narrower PRs:
As written, this PR carries a new Recommendation: do not review/merge this as-is. Rebase after #316/#372 are resolved and split the remaining value into a narrow Claude Code adapter PR: lifecycle hook mapping, transcript parsing/fallback, executable hook packaging, and focused Claude Code tests. Keep shared Gateway client and recall-response behavior on the approved base PRs, and keep Hermes-specific config recovery as a separate follow-up unless it is strictly required for the Claude Code hook. |
当前状态
本 PR 是 issue #235 的 Claude Code 平台适配增量,复用现有 TDAI Gateway 和 TdaiCore,不新增第二套记忆引擎。
当前实现包含通用 Gateway 客户端、Claude Code Hook、可执行命令、完整 recall 响应以及 Hermes 配置修正。PR #316 已被 maintainer 作为共享 Gateway Client 候选基线,PR #372 是 MCP 与 recall response 候选基线;如果它们先合并,本 PR 可以在其上 rebase,并移除重叠的通用层代码,只保留 Claude Code 特有增量。
Refs #235、#316 和 #372。
要解决的问题
当前 main 已支持 OpenClaw 和 Hermes,但 Claude Code 还没有可直接安装的生命周期适配层,主要缺口包括:
UserPromptSubmit无法在模型调用前执行记忆召回。Stop只读取异步落盘的 transcript 时,可能漏掉当前回复,或者把tool_result错当成用户输入。SessionEnd缺少可靠的 session flush,重复执行 capture 还会写入两次最后一轮。context只包含稳定上下文,L1 动态召回结果没有通过 HTTP 完整暴露。tsx启动。MEMORY_TENCENTDB_*与 Node Gateway 实际读取的TDAI_*环境变量没有完整对齐。本 PR 的方案
新增基于 TDAI Gateway 的 Claude Code Hook 适配器,并保持平台层尽可能薄:
UserPromptSubmit调用/recall,把 L1 动态记忆与 Persona/Scene 稳定上下文注入additionalContext。Stop使用 Claude Code 提供的prompt_id和last_assistant_message精确配对当前回合。tool_result、meta 和 sidechain 行,避免把工具输出写成用户记忆。SessionEnd只调用/session/end,不重复 capture。started_at,复用核心原子 checkpoint 处理 Hook 重试。具体改动
src/adapters/coding-agent/:补充 Gateway HTTP 客户端、超时、鉴权、搜索和 session 生命周期映射。src/adapters/claude-code/:新增 Hook handler、stdio CLI 和回归测试。src/gateway/recall-response.ts:分别返回prepend_context和append_system_context,同时保留 legacycontext。package.json/tsdown.config.ts:发布memory-tencentdb-claude-hook可执行命令,并把适配文档纳入 npm 包。hermes-plugin/memory/memory_tencentdb/:对齐 Gateway host、port、LLM 环境变量,并消费完整 recall 上下文。docs/、README.md、README_CN.md:新增 Claude Code、Hermes、通用 Coding Agent 和跨平台对比文档入口。与现有 PR 的关系
非目标
验证
npm test npm run build npm pack --dry-run --json git diff --check本地验证结果:
git diff --check通过。当前 PR 没有 GitHub status check。
Assisted-by: Codex:GPT-5