Skip to content

feat(ckpt): init openclaw and hermes plugin#599

Merged
yummypeng merged 8 commits into
alibaba:mainfrom
Ziqi002:feat/ckpt/openclaw-plugin
May 22, 2026
Merged

feat(ckpt): init openclaw and hermes plugin#599
yummypeng merged 8 commits into
alibaba:mainfrom
Ziqi002:feat/ckpt/openclaw-plugin

Conversation

@Ziqi002
Copy link
Copy Markdown
Collaborator

@Ziqi002 Ziqi002 commented May 21, 2026

Description

1. 新增 OpenClaw 插件实现 (src/ws-ckpt/src/plugins/openclaw/)

ws-ckpt OpenClaw 插件能力一览

一、对外能力:7 个 Tool(仅 Tool Calling,不注册 Slash Command)

源码来自 registerTools():

Tool 名 功能 关键参数
ws-ckpt-checkpoint 为当前 workspace 创建快照 id(必填)、message
ws-ckpt-rollback 回滚 workspace 到指定快照 target(必填,快照 hash)
ws-ckpt-list 列出当前 workspace 所有快照(强制完整展示)
ws-ckpt-diff 对比两个快照间的文件变更 fromto(均必填)
ws-ckpt-delete 删除指定快照 snapshot(必填)、workspace
ws-ckpt-status 查询 daemon 与 workspace 状态
ws-ckpt-config 查看/更新插件配置 action(view/update)、keyvalue

注:所有 Tool 直接与 ws-ckpt daemon 通信,不再依赖 CLI 二次校验

二、生命周期钩子(自动快照)

源码来自 registerHooks():

  • message_received:记录最近一条用户消息(前 80 字符),作为后续快照的上下文 message。
  • session_start:若 autoCheckpoint=true,会话开始时对 workspace 做初始化并创建一个 "initial" 自动快照。
  • agent_end:若 autoCheckpoint=true,每个 agent 任务结束时创建一个 "turn_end" 自动快照(用户消息作为 message,UUID 前 8 位作为 id)。
  • 自动快照在无变更时会被 daemon 跳过(skipped/no changes)。
  • 注意:webchat 等 IM 通道走 channel reply pipeline,不会触发 agent_end,因此不会自动快照。

三、可配置项

来自 openclaw.plugin.json 的 configSchema 与 ws-ckpt-config Tool:

  • autoCheckpoint(boolean):插件私有配置,开关 session_start / agent_end 自动快照;通过 ws-ckpt-config 更新后持久化至 ~/.openclaw/ws-ckpt/plugin-state.json不进入 OpenClaw 通用配置,变更不触发 gateway reload。
  • maxSnapshotsNum / maxSnapshotsDuration:通过 ws-ckpt-config 透传给 daemon 持久化(写入 /etc/ws-ckpt/config.toml),两者均 unset 时自动禁用 auto-cleanup。

2. 新增 Hermes 插件实现 (src/ws-ckpt/src/plugins/hermes/)

ws-ckpt Hermes 插件能力一览

一、对外能力:7 个 Tool(与 OpenClaw 插件 Tool 表完全对齐)

源码来自 tools.py,通过 register(ctx)hermes/init.py 一次性注入:

Tool 名 功能 关键参数
ws-ckpt-checkpoint 为当前 workspace 创建快照 id(必填)、message
ws-ckpt-rollback 回滚 workspace 到指定快照 target(必填,快照 hash)
ws-ckpt-list 列出当前 workspace 所有快照(强制完整展示)
ws-ckpt-diff 对比两个快照间的文件变更 fromto(均必填)
ws-ckpt-delete 删除指定快照 snapshot(必填)、workspace
ws-ckpt-status 查询 workspace 与服务状态
ws-ckpt-config 查看/更新插件与 daemon 配置 action(view/update)、keyvalue

二、生命周期钩子(自动快照,每轮对话粒度)

源码来自 hermes/init.py:

  • on_session_start:若 autoCheckpoint=true,先幂等执行 ws-ckpt init(已注册的 workspace 是 no-op),再创建 event=session_startturn=0 的基线快照;init 失败会打印诊断日志并跳过本次基线。
  • pre_llm_call:线程安全(threading.Lock)地缓存本轮 user_message,作为后续 on_session_end 的 commit message。
  • on_session_end:若 autoCheckpoint=true,每轮对话结束(注:Hermes 在每次 run_conversation() 收尾触发 on_session_end,语义上是 per-turn 而非 per-session)创建 event=turn_end 快照,id 用 secrets.token_hex(6),message 取缓存的用户消息前 80 字符(超长追加 ...);成功/失败均输出 [ws-ckpt] Turn N snapshot ... 日志。

三、可配置项

来自 config.pyws-ckpt-config Tool,优先级 env > yaml > 默认值:

  • autoCheckpoint(bool)与 workspace(path):插件私有配置,ws-ckpt-config update 时同时写入 ~/.hermes/config.yamlplugins.ws-ckpt 节点,并就地刷新单例 CheckpointManager 的内存配置(无需重启 Hermes 即生效)。
  • maxSnapshotsNum / maxSnapshotsDuration:透传 ws-ckpt config --enable-auto-cleanup --auto-cleanup-keep <v> 持久化到 daemon;传 unset 时执行 --disable-auto-cleanup
  • 环境变量直通:WS_CKPT_WORKSPACEWS_CKPT_AUTO_CHECKPOINTTERMINAL_CWD(workspace fallback 链)。
  • 托管模式保护:若 Hermes 检测到 is_managed()=true,拒绝写入 config.yaml 并返回明确错误,避免破坏受管理副本的不可变性。

3. 构建 / 打包 / 安装链路改造

  • Makefile 新增 install-plugins 目标,按 system/user 模式分别落到 /usr/lib/openclaw/extensions/...~/.openclaw/extensions/...
  • adapter-manifest.json 增加 plugin 声明
  • build-rpm.shplugins/adapter-manifest.json 一并打入 tarball
  • ws-ckpt.spec.in 同步插件路径与文件清单
  • 新增 scripts/{install,uninstall}-openclaw.sh:完成插件目录拷贝、依赖安装、openclaw plugins install/enable 调用

Related Issue

no-issue: new feature

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • cosh (copilot-shell)
  • sec-core (agent-sec-core)
  • skill (os-skills)
  • sight (agentsight)
  • tokenless (tokenless)
  • ckpt (ws-ckpt)
  • Multiple / Project-wide

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • For cosh: Lint passes, type check passes, and tests pass
  • For sec-core (Rust): cargo clippy -- -D warnings and cargo fmt --check pass
  • For sec-core (Python): Ruff format and pytest pass
  • For skill: Skill directory structure is valid and shell scripts pass syntax check
  • For sight: cargo clippy -- -D warnings and cargo fmt --check pass
  • For tokenless: cargo clippy -- -D warnings and cargo fmt --check pass
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

场景 9:Openclaw Plugin

验证目标:自动快照+tools可以正常使用(checkpoint/rollback/delete/diff/status/list/config)

安装:

# 执行脚本安装 openclaw 插件
/usr/share/anolisa/adapters/ws-ckpt/scripts/install-openclaw.sh

自然语言交互

"开启自动快照"
"查看快照配置"   //看看开启成功没
"新建文件auto_ckpt.txt 内容是v1"  //快照 a
"修改文件auto_ckpt.txt 内容是v2"  //快照 b
"新建文件auto_ckpt_2.txt 内容是v2"   //快照c
"列出所有快照"  //看看自动快照不
"查看快照xxx和xxx的差异"  //快照 a 和快照 c 差异
"关闭自动快照"
"查看快照配置"  //看看关闭成功没
"列出所有快照"  //看看还自动快照不
"回滚到快照xxx"  //快照a
"查看auto_ckpt.txt内容"  //输出v1
"回滚到session_start"  //清理环境
"删除所有快照"  //清理环境

场景 10:Hermes Plugin

验证目标:自动快照+tools可以正常使用(checkpoint/rollback/delete/diff/status/list/config)

安装:

# 执行脚本安装 hermes 插件
/usr/share/anolisa/adapters/ws-ckpt/scripts/install-hermes.sh

自然语言交互

"指定工作区路径为 ~/.hermes/workspace"
"向工作区写入3个文件a.txt b.txt c.txt"
"开启自动快照"
"查看快照配置"   //看看开启成功没
"新建文件auto_ckpt.txt 内容是v1"  //快照 a
"修改文件auto_ckpt.txt 内容是v2"  //快照 b
"新建文件auto_ckpt_2.txt 内容是v2"   //快照c
"列出所有快照"  //看看自动快照不
"查看快照xxx和xxx的差异"  //快照 a 和快照 c 差异
"关闭自动快照"
"查看快照配置"  //看看关闭成功没
"列出所有快照"  //看看还自动快照不
"回滚到快照xxx"  //快照a
"查看auto_ckpt.txt内容"  //输出v1
"回滚到xxx"  //首个快照,清理环境
"删除所有快照"  //清理环境

Additional Notes

@Ziqi002 Ziqi002 requested a review from casparant as a code owner May 21, 2026 12:15
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from 5c221e8 to 6dcef88 Compare May 21, 2026 12:16
@Ziqi002 Ziqi002 requested review from kongche-jbw and yummypeng and removed request for casparant May 21, 2026 12:16
@github-actions github-actions Bot added component:ckpt scope:documentation ./docs/|./*.md|./NOTICE labels May 21, 2026
Comment thread src/ws-ckpt/src/plugins/openclaw/package.json
Comment thread src/ws-ckpt/adapter-manifest.json
Comment thread src/ws-ckpt/scripts/install-openclaw.sh Outdated
Comment thread src/ws-ckpt/Makefile
Copy link
Copy Markdown
Collaborator

@yummypeng yummypeng left a comment

Choose a reason for hiding this comment

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

为什么没有src/plugins/hermes?

Comment thread src/ws-ckpt/ws-ckpt.spec.in
Comment thread src/ws-ckpt/scripts/install-hermes.sh
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch 2 times, most recently from 29fa999 to cc6158f Compare May 22, 2026 07:02
Ziqi002 added 4 commits May 22, 2026 15:32
- add install scripts dir
- add openclaw plugins build
- opt script file

Signed-off-by: Ziqi Huang <[email protected]>
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch 3 times, most recently from 3123173 to 0c1204b Compare May 22, 2026 08:04
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from 0c1204b to f5cf7c6 Compare May 22, 2026 08:26
@yummypeng
Copy link
Copy Markdown
Collaborator

@Ziqi002 判断下这个问题
image

Comment thread src/ws-ckpt/src/plugins/openclaw/src/environment-check.ts Outdated
Comment thread src/ws-ckpt/docs/RPM-PACKAGING.md Outdated
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from f5cf7c6 to 14f06da Compare May 22, 2026 09:20
- fix docs /usr/bin to /usr/local/bin
- change whitelist.ts import style to EMS
- fix env check error omission
- hasChanges fail return true
- ensureWorkspace fail make env-check fail

Signed-off-by: Ziqi Huang <[email protected]>
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from 14f06da to e94f19a Compare May 22, 2026 09:23
@Ziqi002
Copy link
Copy Markdown
Collaborator Author

Ziqi002 commented May 22, 2026

已补充hermes代码
对于图片问题:
OpenClaw 是用 jiti 加载 plugin 的,不是原生 import()。jiti 是 unjs 出的运行时 TS/ESM 转译器:它把 ESM 转译成 CJS-style 代码后用 vm 跑,会自动注入 require 到模块作用域。所以 require("node:fs") 在 OpenClaw 里没问题。但确实有违规范 已修改。

@Ziqi002 Ziqi002 requested a review from yummypeng May 22, 2026 09:35
Comment thread src/ws-ckpt/Makefile Outdated
Comment thread src/ws-ckpt/scripts/lib-discover.sh Outdated
Comment thread src/ws-ckpt/scripts/install-openclaw.sh Outdated
Copy link
Copy Markdown
Collaborator

@yummypeng yummypeng left a comment

Choose a reason for hiding this comment

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

LGTM

@yummypeng
Copy link
Copy Markdown
Collaborator

@kongche-jbw review 没问题之后合并掉吧

@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from 934f787 to 5948f50 Compare May 22, 2026 10:07
Ziqi002 added 2 commits May 22, 2026 18:08
- derive RUNTIME_DIR/COSH_SKILLS_DIR from DATADIR
-  rename TARGET_DIR to ANOLISA_TARGET_DIR in lib-discover
- openclaw cmd add env OPENCLAW_HOME "$OPENCLAW_BIN"

Signed-off-by: Ziqi002 <[email protected]>
@Ziqi002 Ziqi002 force-pushed the feat/ckpt/openclaw-plugin branch from 5948f50 to e986609 Compare May 22, 2026 10:08
@Ziqi002 Ziqi002 changed the title feat(ckpt): init openclaw plugin feat(ckpt): init openclaw and hermes plugin May 22, 2026
@kongche-jbw
Copy link
Copy Markdown
Collaborator

@yummypeng 可以合了

@Ziqi002 Ziqi002 requested review from kongche-jbw and yummypeng May 22, 2026 10:13
@yummypeng yummypeng merged commit 577f3ff into alibaba:main May 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants