Skip to content

Add cron scheduler and heartbeat runner#42

Open
danbao wants to merge 2 commits intofastclaw-ai:mainfrom
danbao:feature/cron-heartbeat
Open

Add cron scheduler and heartbeat runner#42
danbao wants to merge 2 commits intofastclaw-ai:mainfrom
danbao:feature/cron-heartbeat

Conversation

@danbao
Copy link
Copy Markdown
Contributor

@danbao danbao commented Mar 31, 2026

Summary

Add two automation features: Cron Scheduler and Heartbeat Runner.

Cron Scheduler

Schedule recurring or one-shot tasks via chat commands:

/cron add "standup" every:24h "summarize yesterday's work"
/cron add "check" */30 * * * * "check for new PRs"
/cron add "reminder" at:2026-04-01T09:00:00 "sprint review today"
/cron list / delete / enable / disable
  • Supports cron expressions, fixed intervals (every:5m), and one-shot (at:...)
  • Jobs persisted to ~/.weclaw/cron/jobs.json
  • Uses robfig/cron/v3 for expression parsing

Heartbeat Runner

Periodic agent check-in driven by ~/.weclaw/HEARTBEAT.md:

  • Reads checklist on configurable interval
  • Sends to default agent; suppresses HEARTBEAT_OK replies
  • 24h dedup to avoid noise
  • Configurable active hours and timezone

Config

{
  "heartbeat": {
    "enabled": true,
    "interval": "30m",
    "active_hours": "09:00-18:00",
    "timezone": "Asia/Shanghai",
    "target_user": "wechat_user_id"
  }
}

Changes

  • messaging/cron.go — CronScheduler with tick loop
  • messaging/cron_store.go — JSON persistence
  • messaging/cron_commands.go/cron chat command parser
  • messaging/heartbeat.go — HeartbeatRunner
  • config/config.go — HeartbeatConfig type
  • cmd/start.go — Start scheduler + heartbeat using first account's client
  • messaging/handler.go/cron routing, exported GetDefaultAgent/GetAgent
  • 30+ tests, all passing with -race
  • Updated both READMEs

danbao and others added 2 commits March 31, 2026 23:33
- messaging/cron.go: CronScheduler with tick loop, robfig/cron parser
- messaging/cron_store.go: JSON persistence at ~/.weclaw/cron/jobs.json
- messaging/cron_commands.go: /cron add/list/delete/enable/disable commands
- messaging/heartbeat.go: HeartbeatRunner with active hours, dedup, HEARTBEAT_OK suppression
- config/config.go: HeartbeatConfig with target_user for iLink
- cmd/start.go: start scheduler + heartbeat using first account client
- messaging/handler.go: /cron routing, SetCronStore, exported GetDefaultAgent/GetAgent
- 30+ tests, all passing with race detector
- Updated both READMEs with Cron and Heartbeat sections

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- P1: Record userID on new cron jobs so results go to originating user
- P1: Prevent concurrent duplicate execution with running map + pre-advance NextRunAt
- P2: Reject non-positive heartbeat interval (prevents panic from time.NewTicker)
- P2: Retry one-shot cron jobs when agent not ready instead of permanently disabling

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant