This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
AI-powered Werewolf game framework - a monorepo implementing an AI-driven multiplayer werewolf game with distinct AI personalities.
- Package Manager: Bun (no build step needed for backend, direct execution)
- Frontend: Vite + React + MobX + TailwindCSS
- Backend: Node.js/Bun + Express
- AI Integration: OpenAI SDK, Langfuse telemetry
- State Management: MobX with global stores
- 我用bun,不需要build
- TypeScript: NEVER use
anytype - always use proper typing - Always use ultrathink for complex reasoning tasks
- Player IDs: Always use numbers for Player IDs
- Shared Types: Only put types in shared/ if needed by Player services (e.g., API types called by game master)
# Start all 6 AI players (ports 3001-3006)
./scripts/dev-players.sh
# OR
bun run dev:players
# Start game master frontend (port 3000)
bun run dev:game-master
# Start individual player with config
bun run dev:player:aggressive
bun run dev:player:conservative
bun run dev:player:witty
bun run dev:player:default# Type checking (entire monorepo)
bun run typecheck
bunx tsc --build
# Type checking specific packages
bun run typecheck:frontend
bun run typecheck:backend
# Linting
bun run lint
# Testing (when tests exist)
bun test
bun run test:packages
bun run test:coveragepackages/
├── game-master-vite/ # Frontend UI (Vite + React + MobX)
│ └── src/
│ ├── components/ # React components with observer HOC
│ ├── stores/ # MobX global stores
│ └── lib/ # GameMaster class
├── player/ # AI player server
│ └── src/
│ ├── services/ # AIService, PersonalityFactory
│ └── configs/ # Player personality configs
shared/
├── types/ # Shared TypeScript types & schemas
│ └── src/
│ ├── api.ts # API request/response types
│ └── schemas.ts # Zod schemas for AI responses
├── lib/ # Shared utilities & Langfuse integration
└── prompts/ # AI prompt templates
- Game Creation: Frontend calls
gameMaster.createGame(6)→ adds 6 AI players → assigns roles - Game Phases: Day (discussion + voting) → Night (role abilities) → repeat
- AI Players: Each runs on separate port (3001-3006), receives game state via HTTP API
- Role System: 4 roles only - VILLAGER, WEREWOLF, SEER, WITCH (no HUNTER/GUARD)
// ✅ ALWAYS use this pattern
import { observer } from 'mobx-react-lite';
import { gameMaster } from '@/stores/gameStore';
export const Component = observer(function Component() {
const data = gameMaster.computedProperty; // Direct global state access
return <div>{data}</div>;
});- Global State First: Access state directly from global stores, never pass through props
- Observer Wrapper: ALL components using MobX state MUST use
observerHOC - Computed Properties: Use
computedfor derived data to optimize performance - Avoid Redundant APIs: Get data directly from state, don't make unnecessary network requests
- Located in
shared/lib/src/langfuse.ts - Key exports:
getAITelemetryConfig,shutdownLangfuse,langfuseobject - Browser-safe implementation (no-op flush in frontend)
AIServiceclass handles all AI interactions- Personality system via
PersonalityFactory - Each player has configurable personality affecting decisions
- Zod schemas validate AI responses (see
shared/types/src/schemas.ts)
- Frontend: Global
GameMasterinstance inpackages/game-master-vite/src/stores/gameStore.ts - Players maintain local state, receive updates via API
- State sync through HTTP endpoints, no WebSocket
AI players run on ports 3001-3006 with personalities defined in YAML configs:
- Port 3001-3006: Individual AI players with unique personalities
- Config files:
config/player[1-6].yaml - Each player has strategy (aggressive/conservative/balanced), speech style (casual/formal/witty)
- Game Controls: Blue create, green start, purple next phase, red end buttons
- Player Cards: Show role icons (🐺🔮🧪👤), alive/dead status
- Auto-setup: "Create New Game" button automatically configures 6 AI players
- Langfuse Integration:
getAITelemetryConfigmust be exported fromshared/lib/src/langfuse.ts - Create Game: Must add players and assign roles after game creation
- Type Imports: Always import
PersonalityTypewhen using AI services