ai-collaboration ยท diff
git:20260330.dd1a8a9 to git:20260401.56e571e
94 added, 16 removed. Audit A to A.
What this update changes in the checks
No check changed: every fixed check gives the same answer before and after this update.
A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.
---
description: Instructions for AI agent code generation workflow
globs: ["*"]
+ alwaysApply: true
---
# AI Collaboration Guidelines
- The 3-stage agentic loop:
+ ## The 3-Stage Agentic Loop
- 1. **PLAN:**
- "Analyze the current codebase and plan how to implement [feature]. List the files you'll modify and why. Don't write code yet."
+ Every code generation task MUST follow this loop:
- 2. **IMPLEMENT:**
- "Implement the plan. Follow all `.cursor/rules/` guidelines. If you're unsure about auth or RLS, check `supabase-auth-security.mdc`."
+ ### Stage 1: PLAN (gather context first)
- 3. **REVIEW:**
- "Review what you just generated. Check for:
- - `getSession()` usage (MUST be `getUser()`)
- - Missing error boundaries or `loading.tsx`
- - Next.js 15 async layout/page params
- - TypeScript `any` types (use `unknown` or define interface)
- Report any issues before I run it."
+ Before writing ANY code, the AI MUST:
+ 1. Read the relevant source files to verify current state โ do NOT rely on memory
+ 2. Identify which `.cursor/rules/` files apply to this task
+ 3. List the files to modify and explain why
+ 4. Do NOT write code yet
- Constraints:
- - NEVER give the AI a task longer than 200 words.
- - NEVER let the AI implement more than 3-4 files in one turn.
- - ALWAYS review the Git diff before committing.
+ Prompt template:
+ ```
+ Analyze the current codebase and plan how to implement [feature].
+ List the files you'll modify and why. Don't write code yet.
+ ```
+
+ ### Stage 2: IMPLEMENT (follow constraints)
+
+ When generating code:
+ - Follow ALL active `.cursor/rules/` constraints
+ - If unsure about auth patterns, re-read `supabase-auth-security.mdc`
+ - If unsure about params/layouts, re-read `nextjs15-params.mdc`
+ - Use `unknown` + Zod validation instead of `any` for external data
+ - Return `ActionResponse<T>` from all Server Actions (see below)
+
+ ### Stage 3: VERIFY (confirm before declaring done)
+
+ After generating code, the AI MUST self-check:
+ - [ ] No `getSession()` on the server (MUST be `getUser()`)
+ - [ ] No synchronous `params` or `searchParams` access
+ - [ ] No `@supabase/auth-helpers-nextjs` imports
+ - [ ] No `any` types โ use `unknown` + type narrowing
+ - [ ] Every API route has Zod validation
+ - [ ] Every error is caught and returns `{ error: string }`
+ - [ ] New tables have RLS enabled
+ - [ ] `loading.tsx` and `error.tsx` exist for data-fetching pages
+
+ Report issues BEFORE the developer runs the code.
+
+ ## Skeptical Retrieval Rule
+
+ NEVER trust stored knowledge about the codebase. Before modifying a file:
+ 1. Re-read the file to verify its current contents
+ 2. Check imports and exports to ensure they match expectations
+ 3. Verify that function signatures haven't changed
+
+ This prevents generating code that references stale function signatures,
+ deleted files, or renamed exports.
+
+ ## Standard Patterns
+
+ ### ActionResponse Type (use for all Server Actions)
+ ```typescript
+ type ActionResponse<T = void> =
+ | { success: true; data: T }
+ | { success: false; error: string }
+ ```
+
+ ### Standard Server Action Structure
+ ```typescript
+ 'use server'
+ import { createClient } from '@/lib/supabase/server'
+ import { z } from 'zod'
+
+ const Schema = z.object({ /* ... */ })
+
+ export async function myAction(input: unknown): Promise<ActionResponse<MyType>> {
+ // 1. Auth
+ const supabase = await createClient()
+ const { data: { user } } = await supabase.auth.getUser()
+ if (!user) return { success: false, error: 'Unauthorized' }
+
+ // 2. Validate
+ const result = Schema.safeParse(input)
+ if (!result.success) return { success: false, error: 'Invalid input' }
+
+ // 3. Execute
+ try {
+ const { data, error } = await supabase.from('table').insert(result.data).select().single()
+ if (error) throw error
+ return { success: true, data }
+ } catch {
+ return { success: false, error: 'Operation failed' }
+ }
+ }
+ ```
+
+ ## Task Constraints
+
+ - NEVER give the AI a task longer than 200 words
+ - NEVER let the AI implement more than 3-4 files in one turn
+ - NEVER let the AI skip the verification checklist
+ - ALWAYS review the Git diff before committing
+ - When uncertain, ask the developer โ do NOT guess
+