Comprehensive guidelines for AI agents working on Cookie Jar protocol
Cookie Jar uses modular .mdc rules that automatically apply based on file context:
- Root Standards:
.cursor/rules/root-standards.mdc- Always active - Web3 Patterns:
.cursor/rules/web3-patterns.mdc- For Web3 code - Testing Patterns:
.cursor/rules/testing-patterns.mdc- For test files - Deployment:
.cursor/rules/deployment.mdc- For deployment scripts
Subdirectory Rules (auto-attached when working in specific areas):
- Frontend:
client/.cursor/rules/frontend-standards.mdc - Contracts:
contracts/.cursor/rules/solidity-standards.mdc - E2E:
e2e/.cursor/rules/e2e-standards.mdc
All documentation is in flat structure in /docs/:
docs/
├── ACCESS_CONTROL.md # 6 access control methods
├── DEVELOPMENT.md # Dev workflow & commands
├── DEPLOYMENT.md # Production deployment
├── TESTING.md # Testing strategies
├── ARCHITECTURE.md # High-level system architecture
├── CONTRACTS.md # Smart contract design
├── FRONTEND.md # Frontend architecture
├── INTEGRATIONS.md # Protocol integrations (Superfluid, Uniswap, etc.)
├── NFT_INTEGRATION.md # Comprehensive NFT functionality
├── FOUNDRY_SETUP.md # Foundry configuration
├── AI_AGENTS.md # AI agent configuration (this doc's details)
├── RELEASES.md # Release history
├── MIGRATIONS.md # Migration guides
└── SUBMODULE_MIGRATION.md # Submodule migration (historical)
# Zero-configuration start
git clone https://github.com/greenpill-dev-guild/cookie-jar.git
cd cookie-jar
npm install # Auto-installs Foundry
bun install # Install dependencies
bun dev # Starts everything# Fast TypeScript checking (use this first!)
bun type-check
# Full testing suite
bun test # All tests
bun test:client # Frontend only
bun test:contracts # Contracts only
bun test:e2e # End-to-end
# Code quality
bun lint # ESLint + Solhint
bun format # PrettierRules automatically apply based on context:
| Working On | Active Rules |
|---|---|
| Any file | root-standards.mdc |
| React/TypeScript | + frontend-standards.mdc + web3-patterns.mdc |
| Solidity | + solidity-standards.mdc |
| Test files | + testing-patterns.mdc |
| Deploy scripts | + deployment.mdc |
Use these hooks:
useQueryfrom TanStack Query for blockchain stateuseWriteContractfrom wagmi for transactionsuseChainIdto validate network- Custom hooks in
hooks/for domain logic
Component pattern:
export function JarCard({ address }: JarCardProps) {
const { data, isLoading, error } = useJarData({ address })
if (isLoading) return <Skeleton />
if (error) return <ErrorCard error={error} />
return <Card>{/* content */}</Card>
}Contract structure:
- Imports
- Type declarations
- State variables
- Events
- Custom errors
- Modifiers
- Constructor
- External functions
- Public functions
- Internal functions
- Private functions
Security checklist:
- ✅ ReentrancyGuard on external calls
- ✅ Access control modifiers
- ✅ Input validation with custom errors
- ✅ Checks-Effects-Interactions pattern
- ✅ NatSpec documentation
Coverage requirements:
- New code: 90%+
- Critical paths: 100%
- Error scenarios: 80%+
Test types:
- Unit: Component/function logic
- Integration: Multi-component flows
- E2E: Complete user journeys
- Contract: Foundry tests with fuzzing
- ALWAYS validate chain ID before transactions
- NEVER use ethers.js - use viem + wagmi only
- Default to testnets - require explicit mainnet acknowledgment
- Gas limits - include to prevent griefing
- ReentrancyGuard: All external value transfers
- Access control: OpenZeppelin patterns only
- Input validation: Custom errors, no require strings
- Emergency functions: Pausable for critical contracts
All PRs must pass:
- ✅
bun test- All tests passing - ✅
bun type-check- No TypeScript errors - ✅
bun lint- Clean linting - ✅
bun test:coverage- Coverage maintained - ✅
bun build- Successful build
- ✅ viem + wagmi for Web3
- ✅ TanStack Query for async state
- ✅ OpenZeppelin for contracts
- ✅ TypeScript strict mode
- ✅ Functional React components
- ✅ Mobile-first responsive design
- ❌ ethers.js (use viem instead)
- ❌ Class components (use functional)
- ❌
anytypes (use explicit types) - ❌ Inline styles (use Tailwind)
- ❌ require() in Solidity (use custom errors)
Use conventional commits:
feat:- New featuresfix:- Bug fixeschore:- Maintenancedocs:- Documentationtest:- Test updatesrefactor:- Code refactoring
- Read:
client/.cursor/rules/frontend-standards.mdc - Reference: docs/ACCESS_CONTROL.md and docs/FRONTEND.md
- Check: Existing components in
client/components/
- Read:
contracts/.cursor/rules/solidity-standards.mdc - Reference: docs/CONTRACTS.md
- Check: Existing contracts in
contracts/src/
- Read:
.cursor/rules/testing-patterns.mdc - Reference: docs/TESTING.md
- Ensure: 90%+ coverage maintained
- Read:
.cursor/rules/deployment.mdc - Reference: docs/DEPLOYMENT.md
- Follow: Security checklist completely
- Contract: Create interface in
contracts/src/interfaces/ - Library: Add validation in
contracts/src/libraries/AccessControl.sol - Frontend: Create hook in
client/hooks/nft/ - Component: Add selector in
client/components/nft/ - Tests: Add coverage in
__tests__/hooks/andcontracts/test/ - Docs: Update docs/guides/PROTOCOLS.md
- Reproduce: Write failing test first
- Fix: Implement fix following patterns
- Test: Ensure test passes + no regressions
- Document: Update docs if behavior changed
- Measure: Use profiler/gas reporter
- Optimize: Apply relevant patterns
- Verify: Confirm improvement with metrics
- Document: Add notes about optimization
- Main README - Get running in 5 minutes
- Development Guide - Development workflow
- Architecture Overview - System design
- Access Control - 6 access control methods
- Deployment Guide - Production deployment
- Example Components - Well-tested components
- Example Hooks - Reusable hooks
- Contract Tests - Comprehensive test examples
- E2E Tests - User flow examples
- viem - Web3 library docs
- wagmi - React hooks docs
- Foundry - Contract framework
- Next.js - Frontend framework
- Use
bun type-checkinstead of full builds for TypeScript validation - it's 10x faster - Start with
bun devfrom project root - it handles everything - Check existing patterns before creating new ones
- Write tests first for complex logic
- Reference rule files when unsure about patterns
- Mobile-first - design for mobile, then scale up
- Security first - especially for contract changes
bun install # Reinstall dependencies
bun generate # Regenerate contract typesbun dev:stop # Stop all services
bun dev # Restartbun deploy:local # Redeploy contracts
bun generate # Regenerate typesbun test:coverage # See what's not covered
bun test:watch # Debug in watch mode- Follow the rules - They're optimized for consistency
- Write tests - 90%+ coverage is mandatory
- Document changes - Future you will thank present you
- Security first - Especially for Web3 code
- Mobile-first - Design for smallest screen first
- Ask questions - Better to clarify than assume
These guidelines ensure high-quality, consistent, and secure code across the Cookie Jar protocol.