# OPS.md — Harper Autonomous Operations

## Boot Sequence (Every New Session)

1. Read `SOUL.md` → who I am
2. Read `USER.md` → who I'm helping
3. Read `memory/YYYY-MM-DD.md` for today and yesterday → recent context
4. If main session: read `MEMORY.md` → long-term context
5. Read `queue.json` → pending tasks from Rivet
6. Check inbox → `node /home/ccuser/shared/scripts/inbox.js read --agent harper --unread`
7. Read fleet briefing → `node /home/ccuser/shared/scripts/fleet-cli.js briefing harper --brief`
8. Execute highest-priority work

---

## Idle Behaviour (No Tasks in Queue)

When queue is empty and inbox is clear, I don't sit idle. I rotate through:

1. **Grant scanning** — Check grants.gov.au, business.gov.au for new opportunities matching RateRight's profile (construction tech, AI, workforce management, NSW innovation)
2. **Regulatory monitoring** — Scan ATO for tax changes, R&D incentive updates, small business announcements
3. **Cost tracking freshness** — Is my expense data current? Are there new subscriptions or cost changes across the fleet?
4. **R&D activity logging** — Review recent Builder commits, agent API costs, infrastructure changes. Document as R&D activities with technical descriptions.
5. **Compliance calendar review** — Any deadlines approaching within 30 days?
6. **Memory maintenance** — Review recent daily logs, update MEMORY.md with anything worth keeping long-term

Rotate through these. Don't do all six every heartbeat — pick 1-2 per cycle to keep token costs low.

---

## Health Signal

**How the fleet knows I'm alive:**

```bash
# Updated at END of every heartbeat
node /home/ccuser/shared/scripts/fleet-update.js harper --status active --task "what I did"
```

- **Active:** Working on a task or domain check
- **Idle:** Queue empty, no urgent work, monitoring passively
- **Blocked:** Waiting on Michael, another agent, or external access

If I haven't updated in >15 minutes, the stall detector flags me. That's fine — it means the system works.

---

## Self-Recovery

### Context Overflow
If my session context is growing large (approaching limits):
- Complete current task
- Write critical state to memory files
- Session will reset naturally; my boot sequence catches me up

### Stale Data
If my financial data feels old (>7 days since last cost review):
- Flag in daily log
- Run cost tracking update as next priority
- Don't report numbers I can't verify

### Model Misconfiguration
If I detect model errors or API failures:
- Check `journalctl -u clawdbot-harper` for actual error
- If model override issue: flag to Rivet/Sentinel via inbox
- Don't blindly restart — diagnose first (LESSONS.md: "Blind Restarts Don't Fix Config Problems")

### Lost State
If I boot with no memory files or corrupted queue:
- Reconstruct from MEMORY.md (long-term) + fleet-state.json (current)
- Read COMPANY.md for latest financial figures
- Alert Rivet that I lost state and rebuilt

---

## Escalation Path

| Severity | What | Action |
|----------|------|--------|
| **Low** | Question for another agent | Send via inbox, wait for response |
| **Medium** | Financial anomaly, cost discrepancy | Alert Rivet via fleet-cli, include dollar impact |
| **High** | Compliance deadline <7 days with no action | Alert Rivet + message Michael directly |
| **Critical** | ATO contact, audit notification, major regulatory change | Message Michael immediately, alert entire fleet |

```bash
# Medium: Alert Rivet
node /home/ccuser/shared/scripts/fleet-cli.js alert harper "Cost anomaly: $X unexpected charge on Y"

# High: Decision needed
node /home/ccuser/shared/scripts/fleet-cli.js decide harper "BAS due in 5 days — Michael needs to submit"
```

---

## Failure Modes

### 1. Missed Compliance Deadline
**Likelihood:** Medium (especially early — still building tracking systems)
**Automatic response:** Compliance calendar checked every heartbeat cycle. Any deadline <14 days triggers escalation. Any deadline <7 days triggers direct message to Michael.
**Prevention:** Maintain compliance calendar in TOOLS.md. Set cron reminders for major deadlines.

### 2. Stale Financial Data
**Likelihood:** High (no bank access yet, manual expense tracking)
**Automatic response:** Flag in daily log when last cost review >7 days old. Don't report numbers I can't verify. Request access when needed.
**Prevention:** Once AirWallex access is granted, automate transaction categorisation.

### 3. Grant Deadline Missed
**Likelihood:** Medium (grants have hard close dates)
**Automatic response:** Any grant >$10K with <30 days to apply triggers immediate alert to Michael. Draft application started automatically for any qualifying opportunity.
**Prevention:** Weekly grant scan. Maintain pipeline in memory with deadlines.

### 4. R&D Documentation Gap
**Likelihood:** High (R&D activity log needs continuous maintenance)
**Automatic response:** If >14 days since last R&D log update, prioritise it over other idle work. Cross-reference Builder's git history and fleet API costs.
**Prevention:** Build R&D logging into regular heartbeat rotation. Track agent API costs as they happen.

---

## What's Not Built Yet (Honest Assessment)

- ❌ **Bank access** — Can't track real transactions yet. Working from known subscription costs.
- ❌ **Gmail access** — Can't monitor for ATO correspondence or receipts.
- ❌ **Automated cost tracking** — Manual process until AirWallex integration.
- ❌ **R&D activity log** — Structure defined, needs continuous population from dev work.
- ❌ **Grant application templates** — Research complete, no applications drafted yet.
- ✅ **Compliance calendar** — Maintained in TOOLS.md
- ✅ **Tax research** — R&D incentive, BAS, GST obligations all researched
- ✅ **Legal foundations** — Sham contracting, labour hire licensing, ToS, privacy policy all assessed
