/root/.openclaw/workspace/tasks/task-log-script-v5/task.md/root/.openclaw/workspace/tasks/task-log-script-v5/session.md升级 log-to-channel.sh,修复三个问题:
start 事件中 @${FIRST} 用的是 parse_first 取到的原始字符串(如 reviewer),未经 label_to_name 翻译,应显示为 Ai.Rev 📋start 开始就把 session 链接放在消息最底部,中间事件行插入到 session 链接上方,方便全程点击监控coder → reviewer → 爱衣质检
agent:coder:main)任务:按以下规格实现 log-to-channel.sh v5,在任务目录中操作,不得直接修改原始文件。
开始时:
1. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh coder receive "日志脚本v5" task-log-script-v5
实现步骤:
Step 1:复制原始文件到任务目录
cp /root/.openclaw/workspace/scripts/log-to-channel.sh \
/root/.openclaw/workspace/tasks/task-log-script-v5/log-to-channel.v5.sh
Step 2:实现以下四处修改
修改 A:顶部注释更新版本号
# log-to-channel.sh — Agent 工作日志发送脚本(v5)
修改 B:新增 tg_delete() 函数(在 tg_edit 后面加)
# Telegram 删除消息
tg_delete() {
local msg_id="$1"
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/deleteMessage" \
-d "chat_id=${CHANNEL_ID}" \
-d "message_id=${msg_id}" > /dev/null 2>&1
}
修改 C:append_to_message 改为插入到 session 链接上方
当前逻辑是直接追加到末尾。新逻辑:
- content_file 中用固定分隔行 <!--TAIL--> 区分 body 和 tail(session 链接)
- 追加新行时,插入到 <!--TAIL--> 之前
- 重建消息时,把 <!--TAIL--> 替换为 tail 内容
新的 append_to_message 函数签名不变,内部实现改为:
append_to_message() {
local task_id="$1" new_line="$2"
local msgid_file="${MSGID_DIR}/${task_id}.msgid"
local content_file="${MSGID_DIR}/${task_id}.txt"
if [[ -f "$msgid_file" ]]; then
local msg_id current new_content
msg_id=$(cat "$msgid_file")
current=$(cat "$content_file")
# 在 <!--TAIL--> 前插入新行
new_content="${current/<!--TAIL-->/${new_line}
<!--TAIL-->}"
printf '%s' "$new_content" > "$content_file"
# 渲染:把 <!--TAIL--> 替换为实际 tail
local tail_file="${MSGID_DIR}/${task_id}.tail"
local tail=""
[[ -f "$tail_file" ]] && tail=$(cat "$tail_file")
local rendered="${new_content/<!--TAIL-->/${tail}}"
tg_edit "$msg_id" "$rendered"
else
local msg_id
msg_id=$(tg_send "$new_line")
if [[ -n "$msg_id" && -n "$task_id" ]]; then
echo "$msg_id" > "$msgid_file"
printf '%s' "$new_line" > "$content_file"
fi
fi
}
修改 D:新增 resend_message 函数(done/fail 时调用)
# 删除旧消息并重发为新消息(触发频道通知)
resend_message() {
local task_id="$1"
local msgid_file="${MSGID_DIR}/${task_id}.msgid"
local content_file="${MSGID_DIR}/${task_id}.txt"
local tail_file="${MSGID_DIR}/${task_id}.tail"
local current tail rendered new_msg_id old_msg_id
current=$(cat "$content_file" 2>/dev/null || echo "")
tail=$(cat "$tail_file" 2>/dev/null || echo "")
rendered="${current/<!--TAIL-->/${tail}}"
# 删旧消息
if [[ -f "$msgid_file" ]]; then
old_msg_id=$(cat "$msgid_file")
tg_delete "$old_msg_id"
fi
# 发新消息
new_msg_id=$(tg_send "$rendered")
if [[ -n "$new_msg_id" ]]; then
echo "$new_msg_id" > "$msgid_file"
printf '%s' "$current" > "$content_file"
fi
}
修改 E:start 事件三处改动
1. FIRST=$(parse_first "$CHAIN") → 加翻译:FIRST=$(label_to_name "$(parse_first "$CHAIN")")
2. 消息结构加入 session 链接(底部),body 和 tail 分别存储:
start)
TASK_NAME="$1"; CHAIN="$2"; TASK_ID="$3"
[[ -z "$TASK_NAME" || -z "$CHAIN" || -z "$TASK_ID" ]] \
&& echo "Usage: main start <task_name> <chain> <task_id>" >&2 && exit 1
FIRST=$(label_to_name "$(parse_first "$CHAIN")")
LINE1=$(tpl_line "$TS" "▶️" "$ROLE_NAME" "规划执行链:${CHAIN}。")
LINE2=$(tpl_line "$TS" "▶️" "$ROLE_NAME" "任务规划完成, 开始任务, 移交给 @${FIRST}。")
TAIL=$(tpl_session_url "$TASK_ID")
BODY="$(tpl_title "$TASK_NAME")
$(tpl_task_url "$TASK_ID")
${LINE1}
${LINE2}
<!--TAIL-->"
FULL="${BODY/<!--TAIL-->/${TAIL}}"
msgid_file="${MSGID_DIR}/${TASK_ID}.msgid"
content_file="${MSGID_DIR}/${TASK_ID}.txt"
tail_file="${MSGID_DIR}/${TASK_ID}.tail"
MSG_ID=$(tg_send "$FULL")
if [[ -n "$MSG_ID" ]]; then
echo "$MSG_ID" > "$msgid_file"
printf '%s' "$BODY" > "$content_file"
printf '%s' "$TAIL" > "$tail_file"
fi
;;
修改 F:done 和 fail 改为调用 resend_message
done:
done)
TASK_NAME="$1"; TASK_ID="$2"
[[ -z "$TASK_NAME" || -z "$TASK_ID" ]] \
&& echo "Usage: main done <task_name> <task_id>" >&2 && exit 1
LINE=$(tpl_line "$TS" "✅" "$ROLE_NAME" "评估通过,任务完成,整合结果通知主人。")
# 先把完成行追加到 body(插入 <!--TAIL--> 前)
append_to_message "$TASK_ID" "$LINE"
# 删旧消息重发,触发频道通知
resend_message "$TASK_ID"
;;
fail:
fail)
TASK_NAME="$1"; TASK_ID="$2"
[[ -z "$TASK_NAME" || -z "$TASK_ID" ]] \
&& echo "Usage: main fail <task_name> <task_id>" >&2 && exit 1
LINE=$(tpl_line "$TS" "❌" "$ROLE_NAME" "超过重试上限,任务终止,通知主人。")
append_to_message "$TASK_ID" "$LINE"
resend_message "$TASK_ID"
;;
Step 3:自测
测试 start → receive → handoff → done 完整流程:
SCRIPT=/root/.openclaw/workspace/tasks/task-log-script-v5/log-to-channel.v5.sh
bash $SCRIPT main start "v5测试任务" "coder → reviewer → Ai" test-v5-001
bash $SCRIPT coder receive "v5测试任务" test-v5-001
bash $SCRIPT coder handoff "v5测试任务" reviewer test-v5-001
bash $SCRIPT reviewer receive "v5测试任务" test-v5-001
bash $SCRIPT reviewer handoff "v5测试任务" main test-v5-001
bash $SCRIPT main done "v5测试任务" test-v5-001
验证要点:
- start 时 @mention 显示 Ai.Dev 💻(而非 coder)
- 中间 receive/handoff 事件行出现在 session 链接上方
- done 时旧消息被删除,新消息出现在频道底部(触发通知)
完成后:
1. 将执行日志追加到 session.md
2. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh coder handoff "日志脚本v5" reviewer task-log-script-v5
3. sessions_send 通知 Ai.Rev(agent:reviewer:main,必须传 timeoutSeconds=0,禁止省略):
task_id=task-log-script-v5
task=/root/.openclaw/workspace/tasks/task-log-script-v5/task.md
agent:reviewer:main)任务:审查 /root/.openclaw/workspace/tasks/task-log-script-v5/log-to-channel.v5.sh,对照原始文件和本 task.md 的规格,评估实现是否正确、有无 bug 或遗漏。
开始时:
1. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh reviewer receive "日志脚本v5" task-log-script-v5
审查要点:
- 修改 A-F 是否完整实现?
- <!--TAIL--> 分隔符的 body/tail 拆分逻辑是否正确?
- resend_message 删旧发新是否有异常处理?
- append_to_message 插入逻辑是否会破坏已有内容?
- 自测结果是否符合预期?
完成后:
1. 将审查意见写入 /root/.openclaw/workspace/tasks/task-log-script-v5/review.md
2. 将执行日志追加到 session.md
3. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh reviewer handoff "日志脚本v5" main task-log-script-v5
4. sessions_send 通知爱衣(agent:main:main,必须传 timeoutSeconds=0,禁止省略):
task_id=task-log-script-v5
task=/root/.openclaw/workspace/tasks/task-log-script-v5/task.md
du -sb /root/.openclaw/workspace/tasks/task-log-script-v5/
wc -l /root/.openclaw/workspace/tasks/task-log-script-v5/session.md
读 session.md 全文,再读 review.md。
通用检查:
- 审查是否覆盖全部修改 A-F?
- 是否给出明确结论?
任务特定检查:
- 若审查通过 → 将 log-to-channel.v5.sh 覆盖到原始位置:
bash
cp /root/.openclaw/workspace/tasks/task-log-script-v5/log-to-channel.v5.sh \
/root/.openclaw/workspace/scripts/log-to-channel.sh
- 若有修改建议 → 通知主人确认后再执行
审查通过 →
1. 执行上述 cp 覆盖
2. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh main done "日志脚本v5" task-log-script-v5
3. 用 message 工具通知主人(telegram, 92763607),附简要说明
⚠️ 必须调用 message 工具,不能只在主对话回复
审查有修改建议 →
1. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh main done "日志脚本v5" task-log-script-v5
2. 用 message 工具通知主人:附审查建议,询问是否调整后再执行
不通过(rejectCount == 0) →
1. 创建新的 task.md(task_id 加后缀 -retry1),session.md 独立
2. 在原 session.md 末尾追加一行 rejectCount=1
3. sessions_send 给 coder 重新实现
4. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh main retry "日志脚本v5" "coder → reviewer → Ai" coder 1 task-log-script-v5
rejectCount >= 1 →
1. 发工作日志:
bash
/root/.openclaw/workspace/scripts/log-to-channel.sh main fail "日志脚本v5" task-log-script-v5
2. message 主人,请主人裁决