🐝 ClankerHive
Shared context store for OpenClaw multi-session coordination. Three primitives:
- 1. Facts — key/value pairs with optional TTL (auto-expire)
- Alerts — cross-session notification queue (producer/consumer)
- Tasks — claim-based deduplication for in-flight work
All backed by a single SQLite database in WAL mode (safe for concurrent access).
Setup
No dependencies beyond Python 3 stdlib. The DB is created automatically on first use.
CODEBLOCK0
Resolve the script path relative to this skill directory:
CODEBLOCK1
Facts — Key/Value with TTL
Store short-lived coordination state. Expired facts are auto-pruned on every read.
CODEBLOCK2
Pattern: Skip-if-recent
Before doing expensive work, check if it was done recently:
CODEBLOCK3
Alerts — Cross-Session Queue
Cron jobs or sub-agents produce alerts; the main session consumes them.
CODEBLOCK4
Pattern: Cron → Main Session Handoff
Cron job detects something important:
CODEBLOCK5
Main session heartbeat checks for alerts:
CODEBLOCK6
Tasks — Deduplication
Prevent multiple sessions from doing the same work simultaneously.
CODEBLOCK7
Pattern: Idempotent Cron
CODEBLOCK8
Stats
Quick summary of the hive state:
CODEBLOCK9
Returns JSON with counts for facts, pending/claimed alerts, and claimed/done tasks.
Replacing heartbeat-state.json
Instead of maintaining a separate memory/heartbeat-state.json file, use ClankerHive facts:
CODEBLOCK10
Notes
- - DB path configurable via
CLANKERHIVE_DB env var (default: ~/.openclaw/hive.db) - WAL mode ensures safe concurrent reads/writes from multiple processes
- All list/query commands output JSON; scalar commands output plain text
- Exit code 0 = success, 1 = error (already-claimed, not-found, etc.)
- No external dependencies — pure Python stdlib
System Access
Reads: Nothing — no files, env vars, or network beyond the SQLite DB.
Writes: Only to the SQLite database file at $CLANKERHIVE_DB (default ~/.openclaw/hive.db). Creates parent directories if they don't exist. The default path (~/.openclaw/) is typically mode 700 on OpenClaw installs, meaning only the owning user can read the DB. If you change CLANKERHIVE_DB to a shared or world-readable location, restrict permissions manually: chmod 600 hive.db.
Network: None. No outbound connections of any kind.
Imports: argparse, json, os, sqlite3, sys, time, typing — all Python stdlib. No third-party packages, no subprocess calls, no eval/exec.
Source:
🐝 ClankerHive
用于OpenClaw多会话协调的共享上下文存储。三种原语:
- 1. 事实 — 带可选TTL(自动过期)的键值对
- 告警 — 跨会话通知队列(生产者/消费者)
- 任务 — 基于声明的去重机制,用于处理进行中的工作
全部由单个WAL模式下的SQLite数据库支持(支持安全并发访问)。
设置
除Python 3标准库外无其他依赖。数据库在首次使用时自动创建。
bash
默认数据库位置:~/.openclaw/hive.db
通过环境变量覆盖:
export CLANKERHIVE_DB=/path/to/custom/hive.db
相对于此技能目录解析脚本路径:
bash
HIVE=python3 $(dirname $0)/../scripts/clankerhive.py
或使用技能安装位置的绝对路径
事实 — 带TTL的键值对
存储短期的协调状态。每次读取时自动清理过期的事实。
bash
设置一个事实(除非指定--ttl,否则永久存在)
python3 scripts/clankerhive.py set email.last_check $(date +%s) --ttl 900
读取事实(如果缺失/过期则输出为空)
python3 scripts/clankerhive.py get email.last_check
列出所有匹配前缀的事实
python3 scripts/clankerhive.py list --prefix email
删除一个事实
python3 scripts/clankerhive.py delete email.last_check
标记设置者(便于调试)
python3 scripts/clankerhive.py set weather.checked 1 --ttl 3600 --source heartbeat
模式:最近跳过检查
在执行耗时操作前,检查是否最近已执行过:
bash
LAST=$(python3 scripts/clankerhive.py get email.last_check)
if [ -z $LAST ]; then
# 执行工作,然后记录
python3 scripts/clankerhive.py set email.last_check $(date +%s) --ttl 900
fi
告警 — 跨会话队列
定时任务或子代理产生告警;主会话消费它们。
bash
排队一个告警(来自定时任务)
python3 scripts/clankerhive.py queue-alert email 紧急:服务器宕机 — 来自监控的生产告警
列出未认领的告警
python3 scripts/clankerhive.py list-alerts
认领并返回所有待处理告警(标记为已认领)
python3 scripts/clankerhive.py pop-alerts
仅认领特定主题的告警
python3 scripts/clankerhive.py pop-alerts --topic email
清理旧的已认领告警(默认:超过24小时)
python3 scripts/clankerhive.py purge-alerts --age 86400
模式:定时任务 → 主会话交接
定时任务检测到重要事件:
bash
python3 scripts/clankerhive.py queue-alert calendar 30分钟后与平台团队进行站会
主会话心跳检查告警:
bash
ALERTS=$(python3 scripts/clankerhive.py pop-alerts)
如果非空则处理并通知用户
任务 — 去重
防止多个会话同时执行相同的工作。
bash
尝试认领一个任务(退出码0=成功,退出码1=已被他人认领)
python3 scripts/clankerhive.py claim-task daily-briefing-2026-04-01
stdout: ok 或 already-claimed by <所有者>
完成后释放
python3 scripts/clankerhive.py release-task daily-briefing-2026-04-01 --result 已发送至Telegram
检查状态
python3 scripts/clankerhive.py task-status daily-briefing-2026-04-01
模式:幂等定时任务
bash
if python3 scripts/clankerhive.py claim-task morning-briefing-$(date +%Y-%m-%d); then
# 执行工作...
python3 scripts/clankerhive.py release-task morning-briefing-$(date +%Y-%m-%d) --result 完成
else
echo 已在运行或已完成
fi
统计信息
蜂巢状态的快速摘要:
bash
python3 scripts/clankerhive.py stats
返回包含事实数量、待处理/已认领告警数量以及已认领/已完成任务数量的JSON。
替代heartbeat-state.json
无需维护单独的memory/heartbeat-state.json文件,使用ClankerHive事实:
bash
旧方式:读写JSON文件
新方式:
python3 scripts/clankerhive.py set heartbeat.email $(date +%s) --ttl 1800
python3 scripts/clankerhive.py set heartbeat.calendar $(date +%s) --ttl 3600
python3 scripts/clankerhive.py set heartbeat.weather $(date +%s) --ttl 7200
检查某项操作上次执行时间:
python3 scripts/clankerhive.py get heartbeat.email
为空 = 需要再次检查
注意事项
- - 数据库路径可通过CLANKERHIVE_DB环境变量配置(默认:~/.openclaw/hive.db)
- WAL模式确保多个进程的安全并发读写
- 所有列表/查询命令输出JSON;标量命令输出纯文本
- 退出码0=成功,1=错误(已认领、未找到等)
- 无外部依赖 — 纯Python标准库
系统访问
读取: 无 — 除SQLite数据库外,不读取任何文件、环境变量或网络。
写入: 仅写入$CLANKERHIVEDB(默认~/.openclaw/hive.db)处的SQLite数据库文件。如果父目录不存在则自动创建。默认路径(~/.openclaw/)在OpenClaw安装中通常为700模式,意味着只有拥有者用户才能读取数据库。如果将CLANKERHIVEDB更改为共享或全局可读位置,请手动限制权限:chmod 600 hive.db。
网络: 无。没有任何类型的出站连接。
导入: argparse、json、os、sqlite3、sys、time、typing — 全部为Python标准库。无第三方包,无子进程调用,无eval/exec。
来源: