---
created: 2026-03-12
source: Rivet
tags: [agent-archive, rivet]
---

# Task Executor - Heartbeat Integration

## Quick Start

Add this to your `HEARTBEAT.md` to enable autonomous task execution:

```markdown
## Autonomous Work (Every 4th Heartbeat)

Check if it's time for autonomous work:
- Read `/home/ccuser/rateright-growth/rivet/scripts/task-executor-state.json`
- If `last_run` was more than 6 hours ago, execute:

```bash
cd /home/ccuser/rateright-growth/rivet
python3 scripts/task-executor.py --max-tasks 1
```

Log results to today's memory file.
```

## Heartbeat Logic Example

```python
import json
from pathlib import Path
from datetime import datetime, timedelta

STATE_FILE = Path("/home/ccuser/rateright-growth/rivet/scripts/task-executor-state.json")

def should_run_tasks():
    """Check if enough time has passed since last run"""
    if not STATE_FILE.exists():
        return True
    
    with open(STATE_FILE, 'r') as f:
        state = json.load(f)
    
    last_run = datetime.fromisoformat(state.get('last_run', '2020-01-01'))
    hours_since = (datetime.now() - last_run).total_seconds() / 3600
    
    return hours_since >= 6  # Run every 6 hours

def update_state():
    """Update last run timestamp"""
    STATE_FILE.parent.mkdir(exist_ok=True)
    with open(STATE_FILE, 'w') as f:
        json.dump({'last_run': datetime.now().isoformat()}, f)

# In your heartbeat:
if should_run_tasks():
    # Run task executor
    import subprocess
    result = subprocess.run(
        ['python3', 'scripts/task-executor.py', '--max-tasks', '1'],
        cwd='/home/ccuser/rateright-growth/rivet',
        capture_output=True
    )
    update_state()
```

## Simple Bash Version

Add to HEARTBEAT.md:

```bash
# Check if task executor should run (every 6 hours)
LAST_RUN=$(cat /home/ccuser/rateright-growth/rivet/scripts/.last-run 2>/dev/null || echo 0)
NOW=$(date +%s)
HOURS_SINCE=$(( (NOW - LAST_RUN) / 3600 ))

if [ $HOURS_SINCE -ge 6 ]; then
    cd /home/ccuser/rateright-growth/rivet
    python3 scripts/task-executor.py --max-tasks 1
    date +%s > scripts/.last-run
fi
```

## Cron Alternative

Or set up a dedicated cron job for overnight work:

```bash
# Edit crontab
crontab -e

# Add these lines:
# Run task executor at 11pm and 3am (during low-activity hours)
0 23 * * * cd /home/ccuser/rateright-growth/rivet && python3 scripts/task-executor.py --max-tasks 2 >> /tmp/task-executor-$(date +\%Y-\%m-\%d).log 2>&1
0 3 * * * cd /home/ccuser/rateright-growth/rivet && python3 scripts/task-executor.py --max-tasks 2 >> /tmp/task-executor-$(date +\%Y-\%m-\%d).log 2>&1
```

## Monitoring

Check execution status:
```bash
python3 scripts/task-executor.py --status
```

View recent logs:
```bash
tail -100 memory/$(date +%Y-%m-%d).md | grep "task-executor"
```

Check if tasks are stuck:
```bash
grep "⏳" TODO.md
```

## Best Practices

1. **Start slow**: Run `--max-tasks 1` until proven reliable
2. **Monitor daily**: Check `memory/YYYY-MM-DD.md` for execution logs
3. **Review tasks**: Ensure TODO.md tasks are well-defined
4. **Adjust frequency**: Start with 2x/day, increase as confidence grows
5. **Use dry-run**: Test new tasks with `--dry-run` before live execution

## Safety

The task executor will NEVER execute:
- External communications (emails, posts, SMS)
- Deploys or releases
- Production changes
- Social media posts
- Meta/self-referential tasks

If a task is unsafe, it will be skipped automatically.
