当用户发送 /diag 指令时,直接执行脚本,不做额外解释:
用户输入执行命令说明/diag``-s今日摘要(默认)/diag full``(无-s)完整报告(含 Run 详情 + 错误列表)/diag full -l 3``-l 3最近 3 个 Run 完整详情/diag -a waicode``-s -a waicode指定 agent 摘要/diag -a main full``-a main指定 agent 完整报告/diag 2026-03-19``-s 2026-03-19指定日期摘要/diag errors``(无-s)执行完整报告,只提取错误部分汇总
规则:
无参数时默认 -s(摘要模式,最简洁)
full 关键词 → 去掉 -s,输出含 Run 详情
errors 关键词 → 执行完整报告,只摘出错误列表
-a、 -l、日期参数直接透传给脚本
去除 ANSI 颜色码:管道 | sed 's/\x1b\[[0-9;]*m//g'
不支持 -f(实时跟踪),该模式需在 SSH 终端运行
直出模式:脚本输出直接用 message 工具原样发送给用户,不经过模型总结。
具体做法:
message(action="send", message=output) 发送原始输出NO_REPLY(避免重复发送)当用户用自然语言询问(如"运行状态怎么样"、"waicode今天干了啥")时, 自行选择合适参数执行脚本,并用中文汇总关键信息。
bash
# 诊断今天的数据
bash scripts/openclaw-diag.sh
# 诊断指定日期
bash scripts/openclaw-diag.sh 2026-03-19
# 只看摘要
bash scripts/openclaw-diag.sh -s
# 实时跟踪(类似 tail -f)
bash scripts/openclaw-diag.sh -f
# 高级实时跟踪(自动开启 debug 日志,退出时恢复)
bash scripts/openclaw-diag.sh -f --advanced
# 只看指定 agent
bash scripts/openclaw-diag.sh -a waicode
# 最近 5 个 Run
bash scripts/openclaw-diag.sh -l 5
模式参数说明摘要统计-s(默认)KPI 概览,最简洁完整报告无 -s含 Run 详情 + 时间线 + 错误列表Agent 过滤-a <name>只看指定 agent限制数量-l N只显示最近 N 个 Run指定日期YYYY-MM-DD默认今天
参数可组合: -s -a main、 -l 3 -a wairesearch。
实时跟踪(
-f)和高级模式(--advanced)需在 SSH 终端运行, 详见 references/advanced-mode.md。
脚本有两种数据源,自动切换:
数据源路径需要配置精度Debug 日志/tmp/openclaw/openclaw-YYYY-MM-DD.log``diagnostics.enabled: true精确 Run 边界Session 文件~/.openclaw/agents/*/sessions/*.jsonl无需配置虚拟 Run(消息时间戳推算)
无 debug 日志时自动降级为 session 模式,核心指标(推理耗时、Token、工具统计)仍然准确。
bash
# 快速了解今天的运行概况
bash scripts/openclaw-diag.sh -s
bash
# 查看某天详细 Run 数据,找到慢查询
bash scripts/openclaw-diag.sh 2026-03-19 -l 10
bash
# 只看 waicode 的活动
bash scripts/openclaw-diag.sh -a waicode -s
bash
# 需在 SSH 终端运行,不适合 Telegram/聊天
bash scripts/openclaw-diag.sh -f
bash scripts/openclaw-diag.sh -f --advanced
python3(3.7+,使用 datetime.fromisoformat)和 bash--advanced)会临时修改 openclaw.json 并重启 Gateway,退出时自动恢复