# 2026-03-15 (Sunday)

## 06:00 Memory Review (cron)

Reviewed daily logs Mar 8-14. MEMORY.md updated.

### Week Summary (Mar 8-14)

**Mar 8-9:** Illumination Google Ads major session (auto-apply off, brand exclusion, ROAS target 150%, bid schedules, location bid adjustments). AI Visibility Checker built + deployed. Dream 100 dashboards (6 pages on tilt.ie). Security hardening Tradeify (8 issues fixed). SUPABASE_SERVICE_KEY added.

**Mar 10-11:** Advisory council flagged Rob-gated paralysis. GCP "Tilt AI Projects" created (Gemini key fixed for Retail Targeting). Big voice note from Rob (10 tasks). Invoice UI improved (Edit + Credit Note). SendGrid template v2 deployed. Illumination ROAS check cron fired.

**Mar 12:** Zavi project kickoff. EUR 17-21B market, no local AI competitor. Monday Mar 17 MVP target set.

**Mar 13 (~4am):** Zavi autonomous 5-phase overnight build. Live at zavi-app.pages.dev. All 10 tables + RLS + storage. Weekly advisory council again flagged execution paralysis. Zavi major fixes: theme provider, AI metadata extraction, multi-file upload, Excel/CSV, async_hooks crash, column name mismatches.

**Mar 14:** Memory review. Then Rob live in Telegram group ~12pm: Resend email set up for Zavi (not SendGrid -- max@tilt.ie already on Resend), zavi.ie domain DNS configured via Cloudflare API (zone: fd655f799dabc7778e2dde6f0a0c22c7), app URL updated to zavi.ie. Service category feature built and deployed (13 types, AI auto-detects from PDF, manual override). "Built for Irish SMEs" badge removed from landing. Zavi auth was already wired (Mar 14 earlier session).

### Critical Flags (as of Mar 15 6am)

- **Google Ads identity verification: TODAY or TOMORROW (deadline Mar 16).** Rob must log in. Both accounts blocked. Illumination €633/day. FIRE ALERT.
- **GitHub PAT: expires Mar 17.** Rob must regenerate. All Cloudflare Pages deploys will break.
- **Zavi MVP: Mon Mar 17.** Known blockers: storage bug (getPublicUrl on private bucket), parsed_text empty (no PDF extraction), drafting engine not wired to category filter.
- **Dream 100 Coole Swan email: 7 days unsent.** Needs data/numbers rework then send.
- **10 tasks from Rob's Mar 11 voice note: almost all still open.**

## 08:00-10:30 Zavi Debug Session (Rob live in Telegram group)

### Draft Generation Fix
- Original problem: `/api/tenders/[id]/draft` endpoint timed out on Cloudflare Workers (~95s for 17 sections). AI call works locally but CF kills it.
- Claude Code spawned: created `/api/draft-section/[tenderId]` endpoint that generates ONE section at a time (~13s each). Uses streaming fetch to Anthropic (not SDK).
- Route worked at `/api/draft-section/[tenderId]` but NOT at `/api/tenders/[id]/draft-section` (CF routing quirk with nested dynamic segments).
- Front-end updated to call working endpoint. Draft generation confirmed working: proper content, confidence scores, source citations, gap flags.

### Anthropic SDK vs Fetch -- Major Lesson
- **Root cause of most 500 errors:** 6 API routes imported `@anthropic-ai/sdk` directly. The SDK doesn't work on Cloudflare Workers edge runtime.
- **Working pattern:** `generateContent()` in `@/lib/ai/client` uses raw `fetch` with SSE streaming to `api.anthropic.com`. This works on CF edge.
- **Build cache gotcha:** After editing source files, Next.js cache served OLD compiled code. Must `rm -rf .next .vercel/output` before rebuild. Wasted ~30min debugging phantom 500s where source was correct but deployed code was stale.
- **Fixed all 6 files:** analyze, fill, populate, assemble, extract-case-studies, research sync-to-tender, research create-for-tender. All now use `generateContent()`.

### Workspace vs Draft -- Two Separate Flows
- **Draft page** (`/tenders/[id]/draft`): uses `requirements` array + `response_sections` table. Per-section endpoint.
- **Workspace page** (`/tenders/[id]/workspace`): uses `tender_asks` table. "Fill All with AI" calls `/populate`, individual fills call `/asks/[askId]/fill`.
- The workspace is the primary user-facing flow Rob wants. The draft page is secondary.
- Analyze endpoint (`/analyze`, American spelling) creates `tender_asks`. The analyse endpoint (`/analyse`, British spelling) creates `requirements`. Both exist but serve different flows.

### Human Input Guard (Rob's Rule)
- Rob's voice note: case studies, insurance, financials, references, accreditations MUST NOT be AI-generated. AI fabricating that a company has insurance it doesn't have = liability.
- Added `REQUIRES_HUMAN_INPUT` guard to `/asks/[askId]/fill`: blocks `case_study`, `insurance`, `financial`, `references`, `accreditation` types with 422 error.
- AI CAN fill: methodology, quality_assurance, experience, gdpr_data_protection, health_safety, company profiles.
- AI CAN edit/improve uploaded content for any type.

### Current State (10:30)
- Analyze: extracts 13 sections from UCD tender. Working.
- Populate: checks knowledge base, correctly shows all 13 as "missing" (no content uploaded yet). Working.
- Fill: methodology filled successfully (652 words, 85% confidence, 13 KB sections used). Insurance correctly blocked.
- No Gemini anywhere in the codebase (Rob asked to confirm). All AI calls go through Anthropic Claude Sonnet 4 via fetch streaming.
- Build process: must always `rm -rf .next .vercel/output` then `npm run build` then `npx @cloudflare/next-on-pages` then `npx wrangler pages deploy`.

### MEMORY.md Changes Made
- Zavi section: updated domain to zavi.ie (live), added Resend email setup, added service category feature, removed outdated "auth not wired" flag (auth was wired), updated known bugs
- Urgent section: refreshed deadlines (Google Ads now "tomorrow"), added Zavi drafting engine category filter as new task, removed the "auth not wired" item
- Outstanding tasks: added note that these remain open as of Mar 15

## Zavi Session - Part 2 (15:30-19:30)

### Fixes Deployed
- Case studies: now generates ALL requested (3 distinct blocks with detail)
- Team CVs: all 7 team members in separate blocks (1,004 words)
- Word count: respects previous tender length, not 80-120 words
- Knowledge base extraction: individual case studies/team members, not lumps
- Markdown: stripped ** from all AI output (draft-section + fill endpoints)
- Badge colours: white text on solid backgrounds (green/red/yellow)
- Sort order: completed sections first, gaps to bottom
- Research: changed from market surveys to internal checklists
- Workspace tab: added to tender nav (replaced Draft), workspace button on tenders list
- Review page: actual requirement titles instead of "Section 1", compact cards
- Analyse page: mobile-responsive card layout
- Delete tender: now cascades (asks, research, sections, documents)
- Upload: PDFs deferred to analyse step (instant upload, no timeout)
- Parse-document endpoint: parses one file at a time
- History extract: document-by-document with progress
- FK fix: tender_documents FK points to tenders table, not tender_responses -- added matching insert

### Known Issues Still Open
- Browser upload creates tender_responses + tenders records but documents still sometimes fail to link (FK timing?)
- Rate limiting on Anthropic (30k tokens/min) limits extraction speed
- Old content with ** needs regeneration to clean up

## Zavi Tender Knowledge Bank (23:37)
Downloaded all MN Group tender data from Zavi Supabase to local knowledge files:
- memory/knowledge/mn-tender-knowledge.md -- 77k chars, all 45 KB sections + doc summaries
- memory/knowledge/tenders/ -- 10 full parsed documents (528k chars total)

Tenders indexed:
1. DPS Creative Campaign Services (WON) -- OGP Ref MMP080F, public sector DPS
2. Solas Creative and Digital Campaign (WON) -- Ref CWTUJ25BCQRD, commercial waste update
3. ComReg Brand Strategy (LOST) -- T10191, brand guidelines/templates FWA
4. DOA DPS Creative Campaign (PENDING) -- MMP071F-21, qualitative TRD
5. DETE Creative Campaign Services (LOST) -- MMP071F-22, qualitative TRD
6. UCD Strategic Creative Marketing (ACTIVE) -- deadline Apr 8 2026

Knowledge base: 45 sections (8 team, 9 methodology, 7 case study, 9 capability, 3 company history, 3 financial, 3 insurance, etc)
Key team: Kieran Killeen (Account Director), Elsie Arayes (Creative Director), Padraig Smith (Account Manager), Robert Doran (Digital Strategist), Graham Stewart (Sr Copywriter), Paul Lucaci (Digital Designer), Conor O'Neill (Account Manager), Valda Boardman (Planner & PR)
