Skip to content

Claude Code Plugin Adapter #6

@YOMXXX

Description

@YOMXXX

Proposal: Claude Code Plugin Adapter

背景 / Motivation

Roadmap 中"记忆可迁移:跨 Agent / 跨框架 / 跨设备"目前仅完成 OpenClaw 与 Hermes 两个宿主集成。Claude Code(cc)已成为开发者高频使用的编码 Agent,并提供成熟的 /plugin install 分发机制。原生 cc 适配可让长期记忆能力直达大量 cc 用户,无需让他们再安装 OpenClaw 或部署 Hermes。

方案概述 / Approach

新增 claude-code-plugin/ 目录(与 hermes-plugin/ 平级),通过 cc 官方 plugin 系统分发,不修改用户 ~/.claude/settings.json。运行时通过 HTTP + Bearer Token 调用既有的 TdaiGateway,复用现有 /recall / /capture / /search/* 接口,仅在 src/gateway/server.ts 增加约 13 行的可选 Bearer 鉴权中间件。

核心设计要点:

  1. cc Plugin 分发:通过 /plugin install tdai-memory 启用,声明式卸载,无全局配置污染
  2. Gateway 可选 Bearer:仅当 TDAI_GATEWAY_TOKEN 环境变量被设置时启用鉴权;未设置则行为不变,与 Hermes 完全向后兼容
  3. sessionKey = hash(cwd):cc 无显式 session 结束信号,按项目目录分区与用户心智模型一致;TDAI_SESSION_KEY 可覆盖
  4. Hook 失败静默:记忆系统永远不在对话关键路径上;失败写 hook.log,对话不受影响
  5. daemon 生命周期绑定父 ccgateway-entry.ts wrapper 通过 process.kill(ccPid, 0) 60s 探活 + 5s 优雅关闭

范围 / Scope

本 PR 包含:

  • claude-code-plugin/(约 900 行 TypeScript 源码:lib/ 6 模块 + hooks.json + 4 个 skill + README EN/CN)
  • src/gateway/server.ts 可选 Bearer 鉴权(约 13 行,env-gated,完全向后兼容)
  • 47 单元测试 + 3 smoke e2e
  • CHANGELOG 条目

后续 PR:

  • MCP server(解锁 Cursor / Cline 等非 cc 客户端)
  • Codex host adapter
  • PostToolUse per-tool 捕获(当前 capture 由 Stop hook 读 transcript 完成)
  • 跨 Agent 记忆迁移工具

希望维护者反馈 / Asking for input

  1. src/gateway/server.ts 增加可选 Bearer 鉴权是否可接受?(env-gated 完全向后兼容;Hermes 流程不受影响)
  2. commit scope 命名:当前使用现有 scope plugingateway;如希望使用其他 scope(如 claude-code)请告知
  3. 版本号策略plugin.json 当前独立版本 0.1.0,主包仍为 0.3.x;是否需要对齐?
  4. 当前未实现需要 disclosure 的点:(a) PostToolUse 已从 hooks.json 移除(仅 SessionStart/UserPromptSubmit/Stop),per-tool 捕获留作后续 PR;(b) daemon ccPid liveness 仅追踪首个 cc 进程,多 cc 终端同时跑时首个退出会触发关闭(已记在 risk)

实现状态 / Status

  • 分支 feat/claude-code-plugin 位于 fork YOMXXX/TencentDB-Agent-Memory
  • 3 个 logical commits,全部 DCO sign-off
  • pnpm vitest run:47/47 通过(6 个 test 文件)
  • pnpm test:cc-plugin:e2e:3/3 通过(in-process 真实 Gateway 启动 + 真实 capture)
  • pnpm build:pluginpnpm build:cc-plugin:均通过

如方向 OK,将开 PR;如有调整意见请在 issue 内反馈。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions