MO§ES™ Coordinator — Lightweight daemon that monitors OpenClaw Gateway WebSocket for session events, detects sequence violations (Primary → Secondary → Observer), and logs them. Optional component of the moses-governance bundle. Requires background process.
协调器是外部序列执行器。它通过OpenClaw网关WebSocket监控会话事件,检测代理响应顺序错误、模式违规或宪法漂移。
这是可选的。技能家族通过提示指令执行治理。协调器通过事件监控增加了第二层执行。
保存为技能目录中的 scripts/coordinator.py:
python
#!/usr/bin/env python3
MO§ES™ 协调器守护进程 — WebSocket会话监控器
检测序列违规并将其记录到审计跟踪
import asyncio
import json
import os
import subprocess
import sys
GATEWAY_WS = ws://127.0.0.1:18789
AUDIT_SCRIPT = os.path.expanduser(
~/.openclaw/workspace/skills/moses-governance/scripts/audit_stub.py
)
STATE_PATH = os.path.expanduser(~/.openclaw/governance/state.json)
SEQUENCE = [primary, secondary, observer]
async def monitor():
try:
import websockets
except ImportError:
print([COORDINATOR] 安装websockets:pip3 install websockets)
sys.exit(1)
sessionstate = {} # sessionid → lastagentindex
print(f[COORDINATOR] 正在连接到 {GATEWAY_WS})
async with websockets.connect(GATEWAY_WS) as ws:
await ws.send(json.dumps({type: subscribe, events: [session_update]}))
print([COORDINATOR] 已订阅会话事件。正在监控...)
async for message in ws:
event = json.loads(message)
if event.get(type) != session_update:
continue
sessionid = event.get(sessionid)
agent = event.get(agent, ).lower()
if agent not in SEQUENCE:
continue
current_index = SEQUENCE.index(agent)
lastindex = sessionstate.get(session_id, -1)
if currentindex != lastindex + 1 and current_index != 0:
# 序列违规
expected = SEQUENCE[lastindex + 1] if lastindex + 1 < len(SEQUENCE) else primary
detail = f会话 {session_id} 中发生序列违规:{agent} 响应,但预期应为 {expected}
print(f[COORDINATOR] 违规 — {detail})
subprocess.run([
python3, AUDIT_SCRIPT, log,
--agent, coordinator,
--action, sequence_violation,
--detail, detail,
--outcome, blockedandlogged
])
else:
sessionstate[sessionid] = current_index
if current_index == len(SEQUENCE) - 1:
# 完整周期完成,重置
sessionstate[sessionid] = -1
if name == main:
asyncio.run(monitor())
手动(开发):
bash
python3 ~/.openclaw/workspace/skills/moses-coordinator/scripts/coordinator.py &
持久化(macOS launchd):
创建 ~/Library/LaunchAgents/com.elloCello.moses-coordinator.plist:
xml
然后:launchctl load ~/Library/LaunchAgents/com.elloCello.moses-coordinator.plist
bash
pip3 install websockets
当发生序列违规时,协调器通过子进程调用 audit_stub.py 记录事件。此脚本是 moses-governance 技能包的一部分,并在此仓库中提供:
~/.openclaw/workspace/skills/moses-governance/scripts/audit_stub.py
它将写入本地账本 ~/.openclaw/audits/moses/audit_ledger.jsonl。无需网络调用。无需凭证。源代码包含在内且可审查。
MOSESOPERATORSECRET 不被此技能使用。请勿提供它 — 协调器不需要它。
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 moses-coordinator-1776104851 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 moses-coordinator-1776104851 技能
skillhub install moses-coordinator-1776104851
文件大小: 4.35 KB | 发布时间: 2026-4-15 13:28