名称: ops-framework
描述: >-
OpenClaw 的零令牌作业与监控框架:通过脚本运行长时间读取任务,安全地检查点/恢复,并向 Telegram 发送周期性进度报告和即时告警。默认阻止写入作业,必须经过显式批准和验证。
版本: 0.1.0
作者: Zjianru
许可证: MIT
compatibility: >-
要求网关主机具备 Python 3.10+。优先使用 openclaw message send 命令;否则回退到使用 openclaw.json 中机器人令牌的 Telegram HTTP API。
目标:将“长任务执行 / 断点续跑 / 进度汇报 / 异常告警”构建为 零令牌 的可复用能力。
本框架包含两个核心组件:
ops-monitor.py:一个纯本地脚本,负责运行状态检查、检测任务停滞、发送 Telegram 快报。ops-jobs.json:一个声明式的作业配置文件(包含类型、风险、命令、策略)。推荐作为“外挂”使用:长任务尽量通过脚本执行,避免让模型持续监控进度消耗令牌。
ACTION REQUIRED / ALERT 或失败时报告。1) 将文件复制到您的 OpenClaw 主机(建议目录结构):
- ~/.openclaw/net/tools/ops-monitor.py
- ~/.openclaw/net/config/ops-jobs.json
- ~/.openclaw/net/state/ops-monitor.json (自动创建)
您也可以从任何目录运行脚本,只要 OPENCLAW_HOME 环境变量指向您的 OpenClaw 状态目录(默认为 ~/.openclaw)。
2) 从示例配置开始:
- ops-jobs.example.json
3) 验证配置和功能:
bash
python3 ops-monitor.py validate-config --config-file ~/.openclaw/net/config/ops-jobs.json
python3 ops-monitor.py selftest
4) 运行一次监控周期(仅打印,不发送消息):
bash
python3 ops-monitor.py tick --print-only
5) 通过操作系统调度器(launchd/systemd/cron)定期运行监控周期。脚本设计为高频调用;它会根据策略和状态决定是否报告。
kind 可以是以下之一:
- long_running_read (长时间运行读取)
- one_shot_read (一次性读取)
- one_shot_write (一次性写入,ops-monitor 永远不会自动执行)
risk 可以是以下之一:
- read_only (只读)
- write_local (本地写入)
- write_external (外部写入)
MVP 阶段规则:
- long_running_read 作业仅在 risk=read_only 且 policy.autoResume=true 时可能自动恢复。
- one_shot_read 作业可以显式运行或通过队列运行(仅限只读风险)。
- one_shot_write 作业始终被阻止自动运行;它作为一个声明式的“批准 + 验证链”占位符存在。
您的 commands.status 命令必须向标准输出打印 JSON,至少包含:
- running (布尔值)
- completed (布尔值)
推荐包含:
- pid (数字)
- stopReason (字符串)
- progress (对象)
- progressKey (字符串)— 用于停滞检测的稳定键
- level (ok|warn|alert)
- message (字符串)
# 验证配置文件
python3 ops-monitor.py validate-config --config-file ~/.openclaw/net/config/ops-jobs.json
# 打印当前所有作业状态(不发送到 Telegram)
python3 ops-monitor.py status --config-file ~/.openclaw/net/config/ops-jobs.json
# 执行一次监控周期
python3 ops-monitor.py tick --config-file ~/.openclaw/net/config/ops-jobs.json
# 显式启动/停止一个长任务
python3 ops-monitor.py start <job_id> --config-file ~/.openclaw/net/config/ops-jobs.json
python3 ops-monitor.py stop <job_id> --config-file ~/.openclaw/net/config/ops-jobs.json
# 显式运行一个一次性读取作业
python3 ops-monitor.py run <job_id> --config-file ~/.openclaw/net/config/ops-jobs.json
OPS_FRAMEWORK.md