# 2026-02-02 - Symph Agency Build Day

## Major Accomplishments

### Symph Agency Core Infrastructure
- Built complete agency file structure in `agency/`
- Created 8 agent specs: Discovery, Research, Design, Builder, QA, Marketing, Sales, Ops
- Established `agency/Learnings/corrections.md` for continuous improvement
- Created product templates and workflow state machine (14 states)

### Discovery Phase Complete
- Built `discovery-agent` skill with trend scanning
- First real scan: `agency/artifacts/trend-scan-2026-02-02.md`
- Sources: TikTok, X/Twitter, Hacker News, Product Hunt

### Design Phase Complete  
- Built `design-agent` skill with Figma integration
- Figma API connected (read-only - can't create/rename/delete)
- Browser automation tested for duplication
- **Learning:** Figma rename requires human handoff (API limitation)

### Build Phase Complete
- Created `build-agent/SKILL.md` with two-stage flow: UI first → Logic second
- Created `qa-agent/SKILL.md` for browser-based testing
- Created `agency/templates/build-progress.yaml` for tracking

### Symph Agency UI (In Progress)
- Spawned sub-agent to build Next.js dashboard
- Port 3002, domain: `agency.symph.co`
- Auth via email check against `agency/People/users.yaml`
- Pages: Login, Dashboard, Inbox, Products
- Components created: sidebar, card, progress-bar, empty-state
- Dark theme with lime accent (#d4ff00)

## Key Learnings

### Figma Integration
- REST API is **read-only** for file operations
- Cannot: create, duplicate, rename, delete files via API
- Can: read file structure, get thumbnails, export assets
- Workaround: Browser automation for duplication, human handoff for rename

### Browser Automation
- Profile `openclaw` logged into Figma as designers@symph.co
- Click actions can timeout (20000ms limit)
- Right-click context menu lacks "Rename" option
- Plan: Open file in editor, rename via title bar

### Architecture Decisions
- **Two-stage build flow**: Visual approval before logic coding
- **File-system as database**: No traditional DB needed
- **Human gates**: Never auto-advance between phases
- **Sub-agents for long tasks**: Keeps main session responsive

## Files Created/Modified
- `agency/Agents/*.md` (8 agents)
- `agency/People/users.yaml` (5 authorized users)
- `agency/templates/build-progress.yaml`
- `skills/build-agent/SKILL.md`
- `skills/qa-agent/SKILL.md`
- `skills/design-agent/references/figma-integration.md`

## Active Sub-Agent
- Session: `agent:main:subagent:c9971f8e-d7f4-43ef-81ce-49a789ccfd1c`
- Task: Building Symph Agency UI
- Status: Actively writing components

## Evening Session - Discovery Scan Rework

### Changes Made
- **New Product Modal**: Shows cached opportunities immediately with progress banner while fresh scan runs
- **Active Scan Tracking**: Scans recorded in `agency/discovery/active-scan.yaml`
- **Dashboard Polling**: Real-time active scan banner, polls every 3s
- **New API Endpoint**: `/api/discovery/active` for scan status
- **Commit**: `541e5ab` "feat: Real-time discovery with active scan tracking"

### Key Files
- `agency/discovery/active-scan.yaml` — tracks currently running scan
- `agency/discovery/scans/scan-{id}.yaml` — individual scan status files
- `agency/discovery/opportunities.yaml` — cached opportunities

### UX Flow
1. User opens New Product modal → sees cached results immediately
2. Fresh scan starts in background via subagent
3. Banner shows "Scanning in progress" with link to Dashboard
4. Dashboard shows active scan progress until complete

## Products Created Today
- `demo-app` — test product
- `dental-clinics` — Space in Mind flow test
- `pet-clinic-management-system` — full discovery with market research (score 4.0/5)

## Real Opportunities Found (from trend scan)
1. Health Tracking Ring Dashboard (4.3/5)
2. AI Music Generator (4.1/5)
3. Workflow Automation (3.9/5)
4. AI Teacher Assistant (3.7/5)
5. Agricultural Marketplace (3.4/5)

## Late Night Session - Real-Time Infrastructure

### SSE File Watcher System
Built real-time update infrastructure replacing polling:

- **File Watcher** (`src/lib/file-watcher.ts`) — chokidar watching `agency/products/`
- **SSE Endpoints**:
  - `/api/events` — global product changes
  - `/api/events/[slug]` — per-product changes
- **React Hook** (`src/hooks/use-realtime.ts`) — `useProductRealtime(slug)` returns `{ lastUpdate, connected }`
- **Server Boot** (`src/instrumentation.ts`) — watcher starts automatically
- **Systemd Service** (`deploy/symph-agency.service`) — survives VPS restarts

### Products Caching Layer
Performance fix for slow directory scans:

- **Cache File**: `agency/.cache/products.json`
- **Regeneration**: On file changes (via watcher) or if stale
- **APIs Updated**: `/api/products`, `/api/products/[slug]` read from cache
- **Lighthouse**: Reduced load time from 8+ seconds

### Discovery Report Auto-Generation
New skill that triggers when all discovery artifacts exist:

- **Skill**: `skills/discovery-report/SKILL.md` + `prompt.md`
- **Trigger**: File watcher detects all 5 artifacts + workflow complete
- **Output**: `discovery-report.html` in discovery folder
- **UI**: Results tab with iframe, loading state, polling fallback

### Key Files Created/Modified
- `src/lib/file-watcher.ts` — chokidar watcher with SSE broadcast
- `src/lib/cache.ts` — products caching layer
- `src/instrumentation.ts` — server boot initialization
- `src/hooks/use-realtime.ts` — SSE subscription hook
- `src/app/api/events/route.ts` — global SSE endpoint
- `src/app/api/events/[slug]/route.ts` — per-product SSE
- `src/app/api/products/[slug]/proceed/route.ts` — phase advancement
- `skills/discovery-report/SKILL.md` + `prompt.md` — report generation
- `deploy/symph-agency.service` — systemd unit file
- `deploy/install.sh` — production deployment script

### Architecture Decisions
- **SSE over WebSocket**: Simpler, built-in reconnection, sufficient for file changes
- **Instrumentation hook**: Ensures watcher starts on server boot without lazy init
- **Cache file**: Single file read vs directory scanning per request
- **5s polling fallback**: While report generates, in case SSE misses event

### Commits
- `b889d53` — Discovery report feature
- `46205b1` — UI loading states
- Previous: `541e5ab` — Real-time discovery scanning

### In Progress (next turn)
- Generate discovery report for AI Teacher Assistant (artifacts exist, pre-dates auto-trigger)
- Update Progress tab UI with connected indicator (Wifi/WifiOff icons)
- Clean up old polling variables: `autoRefresh`, `lastRefresh` → `lastUpdate`

## Next Session
1. Complete discovery report generation for AI Teacher Assistant
2. Test full SSE flow with server restart
3. Run Lighthouse to confirm performance improvement
4. Add connected status indicator to Progress tab

---

## Standing Instructions
- **Don't git commit** unless Raven explicitly tells me to
- **ALWAYS update cache** when creating/updating/deleting products → `agency/.cache/products.json`
  - On CREATE: Update cache at START (so product shows in UI during discovery)
  - On CREATE: **ALWAYS dedupe by slug** after adding (use `jq '.products |= unique_by(.slug)'`)
  - On DELETE: Update cache immediately after deletion
  - On DELETE: Also clean up inbox items related to the deleted product (files in `agency/inbox/` mentioning the product slug)
