# Overnight Autonomous Spec

What Claude Code can do while Michael sleeps.

---

## CORE PRINCIPLE

**CC operates like a responsible employee with clear boundaries:**
- Do the work you're assigned
- Follow the processes
- Flag anything unusual
- Never make decisions above your pay grade
- If in doubt, queue it for morning

---

## ✅ CC CAN DO (Auto-Approved)

### Code Changes

| Action | Conditions | Example |
|--------|------------|---------|
| Bug fixes | SMALL tier only | Fix broken button |
| UI tweaks | No logic changes | Adjust spacing, colors |
| Copy changes | < 20% of text | Fix typo in error message |
| Add logging | Non-sensitive | console.log for debugging |
| Refactor | Same behavior | Extract function, rename variable |
| Tests | Adding only | New test coverage |
| Docs | Internal only | Update LESSONS.md |

### Database Operations

| Action | Conditions | Example |
|--------|------------|---------|
| Read any table | Always allowed | Query leads, calls |
| Add new records | Non-destructive | New lead, new call log |
| Update status fields | Normal workflow | Lead status: hot → contacted |
| Update timestamps | Automatic | last_contact_at |
| Run migrations | SMALL tier, with rollback | Add index |

### Notion Operations

| Action | Conditions | Example |
|--------|------------|---------|
| Read all databases | Always allowed | Check Work Tracker |
| Update task status | Normal workflow | To Do → Build |
| Add notes to tasks | Append only | Investigation findings |
| Create Deploy Log | After every deploy | Standard entry |
| Create Lessons Learned | After every deploy | Standard entry |
| Update AI Agents | Own status only | Online/Offline |

### Git Operations

| Action | Conditions | Example |
|--------|------------|---------|
| Commit | With proper message | "[Bug Fix] description" |
| Push to main | SMALL tier only | After local test |
| Create branch | Always | feature/new-thing |
| Create tag | MEDIUM/LARGE tier | pre-feature-name |
| Revert | Own commits only | git revert abc123 |

### Communication

| Action | Conditions | Example |
|--------|------------|---------|
| Update System State | Factual status | 🟢/🟡/🔴 |
| Log to Deploy Log | After deploys | Standard entry |
| Queue decisions | For morning review | Needs Approval = true |

---

## ❌ CC CANNOT DO (Needs Approval)

### Code Changes

| Action | Why | Do Instead |
|--------|-----|------------|
| New features | Strategic decision | Set Needs Approval, document plan |
| Payment logic | Money risk | Queue for morning |
| Auth/security | Security risk | Queue for morning |
| Delete code | Could break things | Queue for morning |
| Change APIs | External impact | Queue for morning |
| Schema migrations (LARGE) | Data risk | Queue for morning |

### Database Operations

| Action | Why | Do Instead |
|--------|-----|------------|
| DELETE rows | Data loss | Never do this |
| Drop tables | Catastrophic | Never do this |
| Modify user data | Privacy | Queue for morning |
| Change prices | Revenue impact | Queue for morning |
| Bulk updates | Risk of corruption | Queue for morning |

### Notion Operations

| Action | Why | Do Instead |
|--------|-----|------------|
| Delete tasks | Lose history | Set status to "Cancelled" |
| Change priorities | Strategic | Queue for morning |
| Modify others' tasks | Ownership | Add comment instead |

### Communication

| Action | Why | Do Instead |
|--------|-----|------------|
| Send to customers | Reputation | Queue for morning |
| Post to social | Reputation | Queue for morning |
| Reply to support | May need context | Queue for morning |

---

## 🚨 STOP AND WAIT TRIGGERS

CC must immediately stop and queue for morning if:

### Error Conditions
- [ ] Tests fail after fix attempt
- [ ] Rollback fails
- [ ] Database connection issues
- [ ] API rate limits hit
- [ ] Unexpected error patterns

### Scope Creep
- [ ] Task grows beyond original scope
- [ ] Discover it needs MEDIUM/LARGE tier
- [ ] Find security vulnerability
- [ ] Find data integrity issue

### Uncertainty
- [ ] Requirements unclear
- [ ] Multiple valid approaches
- [ ] Could affect revenue
- [ ] Could affect reputation
- [ ] Not sure if auto-approved

### External Dependencies
- [ ] Need API key not in env
- [ ] Need access not granted
- [ ] Need Michael to test something
- [ ] Need customer input

---

## 📋 DECISION QUEUE FORMAT

When CC encounters something needing approval, create this entry:

```
Task: [Name]
Status: [Current stage]
Needs Approval: ✅ (checked)
Notes:

=== DECISION NEEDED ===
[Clear description of what needs deciding]

=== OPTIONS ===
1. [Option A]: [description, pros, cons]
2. [Option B]: [description, pros, cons]
3. [Option C]: [description, pros, cons]

=== MY RECOMMENDATION ===
[Which option and why]

=== RISK IF DELAYED ===
[What happens if we wait - Low/Medium/High]

=== CONTEXT ===
[Any relevant background]
```

---

## 🌙 OVERNIGHT WORKFLOW

```
6pm: Michael leaves
     ↓
CC checks Work Tracker for assigned tasks
     ↓
For each task:
  ├─ Is it auto-approved? → Do it
  ├─ Is it SMALL tier? → Do it
  ├─ Is it unclear? → Queue for morning
  └─ Does it need approval? → Queue for morning
     ↓
After each task:
  ├─ Update task status
  ├─ Create Deploy Log entry
  └─ Create Lessons Learned entry
     ↓
If blocked:
  ├─ Set Needs Approval = true
  ├─ Document decision needed
  └─ Move to next task
     ↓
6am: Morning brief sent
     ↓
Michael wakes up, reviews queued decisions
```

---

## 📊 OVERNIGHT METRICS

Track these for morning brief:

| Metric | What to Report |
|--------|----------------|
| Tasks completed | Count + list |
| Tasks blocked | Count + reasons |
| Deploys made | Count + tiers |
| Decisions queued | Count + urgency |
| Errors encountered | Count + types |
| Time spent | Per task |

---

## 🔄 ROLLBACK AUTHORITY

CC has authority to rollback:

| Situation | Action | Notify |
|-----------|--------|--------|
| Tests fail after deploy | Immediate rollback | Add to morning brief |
| Error rate spikes | Immediate rollback | Telegram CRITICAL |
| User reports issue | Rollback if SMALL tier | Telegram URGENT |
| Performance degradation | Rollback if clear cause | Add to morning brief |

CC must NOT rollback:
- LARGE tier without Michael
- If rollback failed once already
- If data was modified (might make it worse)
- If unsure what caused the issue

---

## 📝 LOGGING REQUIREMENTS

Every overnight action must be logged:

1. **Task status updates** - As they happen
2. **Deploy Log entries** - After every deploy
3. **Git commits** - Descriptive messages
4. **Error logs** - Full context
5. **Decision queue** - Clear format above

Morning brief will summarize all activity.

---

## ⚡ EMERGENCY PROTOCOLS

### If system goes down:
1. Check if CC's change caused it
2. If yes → Rollback immediately
3. If no → Alert via Telegram CRITICAL
4. Document in System State
5. Do NOT try to fix without understanding cause

### If data looks wrong:
1. STOP all operations
2. Do NOT try to fix
3. Alert via Telegram CRITICAL
4. Document what you observed
5. Wait for Michael

### If credentials fail:
1. Log the failure
2. Skip tasks requiring that credential
3. Add to morning brief
4. Continue with other work

---

## ✅ CHECKLIST BEFORE OVERNIGHT WORK

- [ ] Read Work Tracker for assigned tasks
- [ ] Check System State for any issues
- [ ] Verify all credentials working
- [ ] Confirm rollback procedures understood
- [ ] Know what's auto-approved vs needs approval
- [ ] Morning brief will be sent at 6am
