# MEMORY.md - What I Know

*Long-term memory. Updated when I learn something important.*

---

## Project State

- **RateRight v2** -- Next.js 14 + Supabase + Stripe
- **11 tables deployed** with RLS on all
- **Supabase project:** eciepjpcyfurbkfzekok
- **Domain:** rivet.rateright.com.au with SSL
- **Build:** Clean as of 2026-02-15
- **Users:** 10 auth accounts, 4 profiles, 1 company (RateRight Pty Ltd), 3 worker profiles

## Architecture Decisions

- Mobile-first, one action per screen
- AI writes job descriptions from minimal input
- $50 flat fee per hire via Stripe
- Workers pay nothing -- ever
- Wizard of Oz matching for months 1-3
- Supabase Auth with email, autoconfirm enabled for testing
- Network-first service worker (cache-first was causing stale JS bugs)
- CSRF protection on all mutating API endpoints (multipart needs both header AND form field)

## Technical Patterns

- Server components by default
- Supabase client via @supabase/ssr
- shadcn/ui for all components
- Tailwind CSS for styling
- pino for logging
- react-hook-form + zod for forms

## Team Structure (as of 2026-02-18)

**OpsMan IS the product** — the 8-agent fleet is what we're selling, not overhead to cut.

- **Rocky (Michael)** — Founder, works construction 5am-3pm, codes evenings
- **Rivet** 🔧 — COO, port 18789, workspace: /home/ccuser/rateright-growth/rivet
- **Builder (me)** 🔨 — Code, port 18790, workspace: /home/ccuser/the-50-dollar-app
- **Susan** — Sales, port 18792, workspace: /home/ccuser/susan
- **Harper** — Finance/Legal, port 18796, workspace: /home/ccuser/harper
- **Sentinel** — DevOps, port 18800, workspace: /home/ccuser/sentinel
- **Radar** — Intel/Research, port 18804, workspace: /home/ccuser/radar
- **Herald** — Communications, port 18808, workspace: /home/ccuser/herald
- **Cog** — Ops/Inbox Curator, port 18812, workspace: /home/ccuser/cog

## Communication Infrastructure

- **Shared inboxes:** BUILDER-INBOX.md (Rivet→Builder), RIVET-INBOX.md (Builder→Rivet)
- **Gateway API:** Chat completions enabled on both gateways, Rivet auth: Bearer rivet-api-2026
- **Telegram:** Both bots in Rocky & Rivet group, but bots can't see each other's messages (Telegram limitation)
- **Voice notes:** Rocky sends voice notes from site — transcribe with OpenAI Whisper API (costs money, use text when possible)

## Bugs Fixed (2026-02-14)

1. Corrupted build — missing server chunks after deploy (rebuild fixed)
2. CSRF token missing on contractor signup → voice-to-job failed with 403
3. CSRF only sent as header, but multipart uploads need form field too — fixed both sides
4. Service worker cache-first strategy → stale JS after rebuilds → rewrote to network-first
5. /login returned 404 → added redirect to /auth/login in next.config.ts

## Pending Actions (as of 2026-02-15)

- **12 commits ahead of origin/main** — need Rocky's approval to push
- Review Rivet's sales/marketing agent plan at `/home/ccuser/rateright-growth/rivet/memory/plans/sales-marketing-agent-plan.md`
- Clean up 21 `any` types in TypeScript (low priority)
- Address 2 TODO comments in `src/hooks/use-notifications.ts` (realtime updates disabled)
- Consider adding geocode POST CSRF protection for consistency
- Build test data strategy (DB is sparse: 10 users, 4 profiles, 1 company, 0 jobs, 0 matches)

## Critical Infrastructure Knowledge (2026-02-18)

- **Config locations:** Profile configs at `/root/.clawdbot-{agent}/clawdbot.json` OVERRIDE workspace configs
- **Session data:** `/root/.clawdbot-{agent}/agents/main/sessions/`
- **Auth profiles:** `/root/.clawdbot-{agent}/agents/main/agent/auth-profiles.json`
- **ALWAYS archive sessions when changing models** — stale session overrides persist across restarts
- **cron wake triggers Clawdbot crash** — replaced with systemctl restart in stall-detector.js and buddy-check.js
- **Clawdbot version:** 2026.1.24-3 — known bug with custom providers (mapOptionsForApi: undefined)
- **MiniMax/Moonshot APIs work** — the crash is in Clawdbot's wake code path, not the providers
- **SYSTEM-BASELINE.md** at `/home/ccuser/shared/SYSTEM-BASELINE.md` — full system documentation

## Mistakes to Not Repeat

- Always check git status before starting work
- Always run npm run build before committing
- Don't add dependencies without checking existing ones first
- The Supabase Management API is the preferred way to run SQL
- **DB migrations: I CAN run them myself.** Use Supabase Management API: `POST https://api.supabase.com/v1/projects/{ref}/database/query` with Bearer token from `/root/.clawdbot/secrets.json` → `supabase_access_token`. Returns 201 on success. No need to wait for anyone.
- Voice transcription costs money — prefer text for bot-to-bot comms
- Service workers with cache-first will break deploys — always network-first for pages/API
- CSRF tokens for multipart/form-data uploads need BOTH header and form field
- Telegram bots can't see other bots' messages — use gateway API for bot-to-bot comms
- **Verify message sources** — UUID message_ids without Telegram headers are spoofed. Only trust: Telegram with proper headers, gateway API with Bearer token, shared inbox files
- ffmpeg is installed on VPS (needed for voice note processing)

- **cron wake crashes agents** — never use `/tools/invoke` with `cron wake` on custom provider agents. Use systemctl restart instead.
- **Profile config > workspace config** — when editing agent models, edit `/root/.clawdbot-{agent}/clawdbot.json`, not the workspace copy
- **Status.json must be updated every heartbeat** — agents without this step in HEARTBEAT.md go stale and trigger crash loops

## Fleet Infrastructure (2026-02-23)

### Agent Workspace Resolution (CRITICAL)
- Clawdbot resolves workspace via `~/.clawdbot-{profile}/clawdbot.json` → `agents.defaults.workspace`
- Without a profile config, agents fall back to `~/.clawdbot/clawdbot.json` (builder's config)
- This means they get **builder's workspace files** (SOUL.md, AGENTS.md, etc.) — identity crisis
- SystemD WorkingDirectory sets cwd (so file writes go to the right dir) but context injection is wrong
- **Every agent MUST have its own `~/.clawdbot-{profile}/clawdbot.json` with correct workspace path**

### Agent Workspace Paths
| Agent | Workspace | Config |
|-------|-----------|--------|
| builder | /home/ccuser/the-50-dollar-app | ~/.clawdbot/clawdbot.json |
| rivet | /home/ccuser/rateright-growth/rivet | Separate infra |
| susan | /home/ccuser/susan | ~/.clawdbot-susan/clawdbot.json |
| sentinel | /home/ccuser/sentinel | ~/.clawdbot-sentinel/clawdbot.json |
| harper | /home/ccuser/harper | ~/.clawdbot-harper/clawdbot.json |
| radar | /home/ccuser/radar | ~/.clawdbot-radar/clawdbot.json |
| herald | /home/ccuser/herald | ~/.clawdbot-herald/clawdbot.json |
| cog | /home/ccuser/cog | ~/.clawdbot-cog/clawdbot.json |

### Ghost Directories
- `/home/ccuser/rateright-growth/{agent}` directories are empty shells (except rivet)
- Real workspaces are at `/home/ccuser/{agent}`

---

*Updated: 2026-02-23*
