Overnight Factory
Configure this agent as an autonomous ticket-to-PR operator. Human reviews PRs; agent handles everything else.
Architecture
CODEBLOCK0
Setup Steps
1. Identity & Credentials
Create workspace files:
IDENTITY.md,
USER.md (who you're helping),
SOUL.md.
Add .env to workspace:
CODEBLOCK1
Configure git:
CODEBLOCK2
2. Verify Claude Code
/path/to/claude --version
/path/to/claude -p --dangerously-skip-permissions --output-format text "echo hello"
Note the exact path — you'll need it.
3. Create the Cron Job
CODEBLOCK4
See references/cron-prompt.md for the full prompt template.
4. Keep HEARTBEAT.md Lightweight
The cron handles email. Heartbeat should only contain tasks that need main-session context (e.g., PR monitoring).
Critical Rules
Cron delivery: Always use --to <explicit-chat-id>. Never --channel last — it doesn't resolve in isolated sessions.
Cron timeout: Keep the prompt fast. Check email → spawn subagents → log → exit. Never wait for subagents inline. 120s is enough.
Error backoff: After 5+ consecutive errors the cron backs off exponentially. Delete and recreate to reset: INLINECODE7
Fire-and-forget: Subagents don't reliably call back to Telegram. Have the cron itself announce dispatches in its own reply (the cron reply is what gets delivered).
Validation Checklist
Before going live:
- - [ ] Send test email to support address — cron picks it up within 15 min
- [ ] Cron dispatch reply arrives on Telegram
- [ ] Subagent opens a real branch + PR
- [ ] Assign a GitHub issue to bot manually — GitHub poll catches it
- [ ]
lastDelivered: false on empty runs is expected (HEARTBEAT_OK is silent by design)
Debugging
CODEBLOCK5
Reference Files
- -
references/cron-prompt.md — full cron job prompt template with email check + GitHub poll references/ticket-pipeline.md — how to instruct subagents to handle tickets end-to-endreferences/lessons-learned.md — real failure modes and fixes from production use
隔夜工厂
将此代理配置为自主的工单到PR操作员。人类审核PR;代理处理其他所有事务。
架构
TinyDesk/支持系统
→ GitHub问题(分配给机器人账户)
→ 发送邮件通知至代理收件箱
↓
定时任务(每15分钟,隔离会话)
├─ 邮件检查:检测分配邮件
├─ GitHub轮询:捕获遗漏邮件(安全网)
└─ 调度:为每个工单生成子代理
↓
子代理(Claude Code)
├─ 分析问题+截图
├─ 探索代码库
├─ 在问题上发布分析评论
├─ 实施修复(分支→提交→推送)
└─ 创建PR→通知人类
设置步骤
1. 身份与凭证
创建工作区文件:IDENTITY.md、USER.md(你正在帮助的对象)、SOUL.md。
将.env添加到工作区:
GITHUBTOKEN=ghp...
EMAIL_USER=support@yourdomain.com
EMAIL_PASSWORD=...
配置git:
bash
git config --global user.name 你的机器人名称
git config --global user.email bot@yourdomain.com
echo https://bot-username:${GITHUB_TOKEN}@github.com > ~/.git-credentials
git config --global credential.helper store
2. 验证Claude Code
bash
/path/to/claude --version
/path/to/claude -p --dangerously-skip-permissions --output-format text echo hello
记下确切路径——后续会用到。
3. 创建定时任务
bash
openclaw cron add \
--name 邮件检查 \
--every 15m \
--session isolated \
--announce \
--to <你的-TELEGRAM-聊天-ID> \ # 显式ID,而非--channel last
--timeout-seconds 120 \
--description 检查邮件+GitHub的工单分配 \
--message $(cat /path/to/cron-prompt.txt)
完整提示模板请参见references/cron-prompt.md。
4. 保持HEARTBEAT.md轻量
定时任务处理邮件。心跳应仅包含需要主会话上下文的任务(例如PR监控)。
关键规则
定时任务投递:始终使用--to <显式聊天ID>。切勿使用--channel last——它在隔离会话中无法解析。
定时任务超时:保持提示快速。检查邮件→生成子代理→记录→退出。切勿内联等待子代理。120秒足够。
错误回退:连续5次以上错误后,定时任务会指数级回退。删除并重新创建以重置:openclaw cron delete && openclaw cron add ...
即发即弃:子代理不会可靠地回调Telegram。让定时任务自身在其回复中宣布调度(定时任务回复即被投递的内容)。
验证清单
上线前:
- - [ ] 向支持地址发送测试邮件——定时任务在15分钟内捕获
- [ ] 定时任务调度回复到达Telegram
- [ ] 子代理创建真实分支+PR
- [ ] 手动将GitHub问题分配给机器人——GitHub轮询捕获
- [ ] 空运行时lastDelivered: false是预期的(HEARTBEAT_OK默认静默)
调试
bash
检查定时任务状态
openclaw cron list --json | jq .jobs[0].state
关键检查字段:
lastRunStatus: ok 或 error
consecutiveErrors: 应为0
lastDelivered: 空运行时为false是正常的;工单调度运行时为false是bug
lastDeliveryStatus: not-delivered = 投递配置错误
检查最近日志
tail -20 memory/heartbeat-log.jsonl
直接检查收件箱
python3 -c
import imaplib, ssl
ctx = ssl.create
defaultcontext()
M = imaplib.IMAP4
SSL(imap.ionos.com, 993, sslcontext=ctx)
M.login(user@domain.com, password)
M.select(INBOX)
print(未读:, len(M.search(None, UNSEEN)[1][0].split()))
M.logout()
参考文件
- - references/cron-prompt.md — 完整的定时任务提示模板,包含邮件检查+GitHub轮询
- references/ticket-pipeline.md — 如何指导子代理端到端处理工单
- references/lessons-learned.md — 生产使用中的真实故障模式与修复方案