Skip to content

Commit 6565e9f

Browse files
feat: update Copilot instructions and enhance testing guidelines
1 parent 5190ecc commit 6565e9f

File tree

3 files changed

+197
-51
lines changed

3 files changed

+197
-51
lines changed

.github/copilot-instructions.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,78 @@
1-
# Turn-Based Games Platform - AI Developer Guide
1+
# Turn-Based Games Platform
22

3-
## Architecture Overview
3+
## Purpose
44

5-
This is a **monorepo workspace** with three packages that work together to create a turn-based games platform:
5+
These instructions guide Copilot across all files in this monorepo. Language-specific and framework-specific rules are in separate instruction files under `.github/instructions/`.
66

7-
- **`shared/`** - Core game logic, types, and SQLite storage (TypeScript library)
8-
- **`web/`** - Next.js 15 frontend with API routes (React + TailwindCSS)
9-
- **`mcp-server/`** - Model Context Protocol server providing AI opponents (Node.js service)
7+
## Repository Structure
108

11-
**Key Integration Pattern**: The MCP server communicates with the web app via HTTP calls to `/api/games/*` endpoints, not direct database access. This maintains clear service boundaries.
9+
- `shared/` - Core game logic, types, and SQLite storage (TypeScript library)
10+
- `web/` - Next.js 15 frontend with API routes (React + TailwindCSS)
11+
- `mcp-server/` - Model Context Protocol server providing AI opponents (Node.js service)
1212

13-
## Development Workflow
13+
## Code Standards
1414

15-
**Essential build order** (shared must be built first):
16-
```bash
17-
npm run build --workspace=shared # Always run first
18-
npm run dev --workspace=web # Starts Next.js dev server (port 3000)
19-
npm run dev --workspace=mcp-server # Starts MCP server (stdio)
20-
```
15+
### Required Before Each Commit
16+
17+
- Run `npm run lint` to check for linting issues
18+
- Run `npm run test` to ensure all tests pass
19+
- Build shared package first when making cross-package changes
20+
21+
### Development Flow
22+
23+
- Build shared: `npm run build --workspace=shared` (always run first)
24+
- Dev web: `npm run dev --workspace=web` (starts Next.js on port 3000)
25+
- Dev MCP: `npm run dev --workspace=mcp-server` (starts MCP server via stdio)
26+
- Full test: `npm run test` (runs all workspace tests)
27+
- Full lint: `npm run lint` (runs all workspace linting)
2128

22-
**Database location**: SQLite file is at `web/games.db` by default, controlled by `GAMES_DB_PATH` env var.
29+
### Database
2330

24-
## Core Architecture Patterns
31+
- SQLite file location: `web/games.db` (default)
32+
- Controlled by `GAMES_DB_PATH` environment variable
2533

26-
### Game Implementation Pattern
27-
All games follow the `Game<TGameState, TMove>` interface in `shared/src/types/game.ts`:
28-
- `validateMove()` - Check if move is legal
29-
- `applyMove()` - Apply move and return new state
30-
- `checkGameEnd()` - Determine win/draw/continue
31-
- `getValidMoves()` - Get available moves
32-
- `getInitialState()` - Create starting game state
34+
## Architecture Guidelines
3335

34-
### Storage Pattern
35-
Games use a dual-storage approach:
36-
- **Web app**: Direct SQLite access via `shared/src/storage/sqlite-storage.ts`
37-
- **MCP server**: HTTP calls to web API endpoints (no direct DB access)
36+
### Service Boundaries
3837

39-
### AI Integration Pattern
40-
The MCP server exposes tools like `play_tic_tac_toe` and `create_tic_tac_toe_game`. It calls the web API to:
41-
1. Fetch current game state
42-
2. Calculate AI move using algorithms in `mcp-server/src/ai/`
43-
3. Submit move back via API POST
38+
- MCP server communicates with web app via HTTP calls to `/api/games/*` endpoints
39+
- MCP server never accesses the database directly
40+
- Web app uses direct SQLite access via `shared/src/storage/sqlite-storage.ts`
4441

45-
## File Organization Conventions
42+
### Game Interface
4643

47-
### API Routes Structure
48-
- `web/src/app/api/games/[game-type]/route.ts` - Create/list games
49-
- `web/src/app/api/games/[game-type]/[id]/move/route.ts` - Make moves
44+
All games implement `Game<TGameState, TMove>` interface in `shared/src/types/game.ts`:
5045

51-
### Game-Specific Types
52-
Game states extend `BaseGameState` and are defined in `shared/src/types/games.ts`:
53-
- `TicTacToeGameState` includes `board: Board` and `playerSymbols`
54-
- `RPSGameState` includes `rounds` and `scores`
46+
```typescript
47+
// Required methods for all game implementations
48+
validateMove(state, move) // Check if move is legal
49+
applyMove(state, move) // Apply move and return new state
50+
checkGameEnd(state) // Determine win/draw/continue
51+
getValidMoves(state) // Get available moves
52+
getInitialState(config) // Create starting game state
53+
```
54+
55+
### API Routes Pattern
5556

56-
### Component Organization
57-
- `web/src/components/games/` - Game-specific UI components
58-
- `web/src/app/games/[game-type]/` - Game-specific pages
57+
- Create/list games: `web/src/app/api/games/[game-type]/route.ts`
58+
- Make moves: `web/src/app/api/games/[game-type]/[id]/move/route.ts`
5959

60-
## Development Guidelines
60+
## Adding New Games
6161

62-
### Adding New Games
6362
1. Define types in `shared/src/types/games.ts`
6463
2. Implement game class in `shared/src/games/`
6564
3. Add API routes in `web/src/app/api/games/[new-game]/`
6665
4. Create AI implementation in `mcp-server/src/ai/`
6766
5. Add MCP tools in `mcp-server/src/server.ts`
6867
6. Build UI components in `web/src/components/games/`
6968

70-
### Environment Variables
69+
## Environment Variables
70+
7171
- `WEB_API_BASE` - MCP server's web app URL (default: `http://localhost:3000`)
7272
- `GAMES_DB_PATH` - SQLite database location (default: `./games.db`)
7373

74-
### Key Dependencies
75-
- `@modelcontextprotocol/sdk` - MCP server framework
76-
- `sqlite3` - Database (shared between web/mcp-server)
77-
- `@turn-based-mcp/shared` - Internal workspace dependency
74+
## Security Considerations
75+
76+
- Never hardcode credentials or API keys
77+
- Validate all user inputs in API routes
78+
- Sanitize game IDs and player names before database operations
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
applyTo: "**/{copilot-instructions.md,*.instructions.md,AGENTS.md,CLAUDE.md,GEMINI.md}"
3+
description: Guidelines for writing GitHub Copilot custom instruction files
4+
---
5+
6+
# Writing GitHub Copilot Custom Instructions
7+
8+
Follow these guidelines when creating or modifying Copilot instruction files.
9+
10+
## File Types and Their Purpose
11+
12+
### Repository-Wide Instructions (`copilot-instructions.md`)
13+
14+
Use for:
15+
- General project standards that apply to all files
16+
- Cross-cutting concerns (error handling philosophy, architecture patterns)
17+
- Build, test, and lint commands
18+
- Security requirements
19+
- Environment variable documentation
20+
21+
Do NOT include:
22+
- Language-specific coding standards
23+
- Framework-specific patterns
24+
- Rules that only apply to certain file types
25+
26+
### Path-Specific Instructions (`*.instructions.md`)
27+
28+
Use for:
29+
- Language-specific coding standards (TypeScript, Python, etc.)
30+
- Framework-specific patterns (React, Next.js, etc.)
31+
- Technology-specific concerns (testing, API routes, etc.)
32+
- Different rules for different parts of the codebase
33+
34+
Always include frontmatter:
35+
```yaml
36+
---
37+
applyTo: "glob/pattern/**/*.{ts,tsx}"
38+
description: Brief description of what these instructions cover
39+
---
40+
```
41+
42+
## Writing Effective Instructions
43+
44+
### Structure and Formatting
45+
46+
- Use distinct headings to separate topics
47+
- Use bullet points for easy scanning
48+
- Write short, imperative directives (not narrative paragraphs)
49+
- Keep any single file under 1,000 lines
50+
51+
```markdown
52+
<!-- ❌ Avoid: Narrative style -->
53+
When you're reviewing code, it would be good if you could try to look
54+
for situations where developers might have accidentally left in
55+
sensitive information like passwords or API keys.
56+
57+
<!-- ✅ Prefer: Imperative bullet points -->
58+
## Security
59+
- Check for hardcoded secrets, API keys, or credentials
60+
- Validate all user inputs
61+
- Use parameterized queries to prevent SQL injection
62+
```
63+
64+
### Provide Concrete Examples
65+
66+
Include code snippets showing correct and incorrect patterns:
67+
68+
```markdown
69+
## Naming Conventions
70+
71+
```typescript
72+
// ❌ Avoid
73+
const d = new Date();
74+
const x = users.filter(u => u.active);
75+
76+
// ✅ Prefer
77+
const currentDate = new Date();
78+
const activeUsers = users.filter(user => user.isActive);
79+
```
80+
```
81+
82+
### Be Specific and Actionable
83+
84+
```markdown
85+
<!-- ❌ Vague -->
86+
- Write good tests
87+
- Use proper error handling
88+
89+
<!-- ✅ Specific -->
90+
- Test names should follow: "should [expected behavior] when [condition]"
91+
- Wrap async operations in try/catch and return appropriate error responses
92+
```
93+
94+
## What NOT to Include
95+
96+
Instructions that Copilot cannot follow:
97+
98+
- Formatting changes: "Use bold text for critical issues"
99+
- External links: "Follow standards at https://example.com" (copy content instead)
100+
- Vague quality requests: "Be more accurate", "Don't miss any issues"
101+
- UI modifications: "Add emoji to comments"
102+
103+
## Glob Pattern Examples
104+
105+
```yaml
106+
# All TypeScript files
107+
applyTo: "**/*.{ts,tsx}"
108+
109+
# Test files (both patterns)
110+
applyTo: "**/{*.test.{ts,tsx,js,jsx},__tests__/**/*.{ts,tsx,js,jsx}}"
111+
112+
# Specific directory
113+
applyTo: "web/src/components/**/*.{tsx,ts}"
114+
115+
# API routes
116+
applyTo: "web/src/app/api/**/*.{ts,js}"
117+
118+
# Multiple specific paths
119+
applyTo: "{shared,mcp-server}/src/**/*.ts"
120+
```
121+
122+
## Recommended Section Order
123+
124+
1. **Purpose** - Brief statement of what the file covers
125+
2. **Naming Conventions** - How to name things
126+
3. **Code Style** - Formatting and structure rules
127+
4. **Patterns** - Common patterns to follow (with examples)
128+
5. **Error Handling** - How to handle errors
129+
6. **Security** - Security considerations
130+
7. **Testing** - Testing expectations
131+
8. **Performance** - Performance considerations
132+
133+
## Iteration Process
134+
135+
1. Start with 10-20 specific instructions
136+
2. Note which instructions are followed or missed
137+
3. Refine wording for missed instructions
138+
4. Add new instructions incrementally based on needs

.github/instructions/testing.instructions.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
applyTo: "**/*.test.{ts,tsx,js,jsx}"
2+
applyTo: "**/{*.test.{ts,tsx,js,jsx},__tests__/**/*.{ts,tsx,js,jsx}}"
33
description: Testing guidelines and patterns for the turn-based games platform
44
---
55

@@ -94,3 +94,10 @@ const localMockGameState = { /* duplicated data */ } // Use shared mocks instea
9494
- Test loading states and error boundaries
9595
- Include integration tests for complex workflows
9696
- Verify all game states (playing, finished, error)
97+
98+
## General Principles
99+
100+
- New features require unit tests
101+
- Tests should cover edge cases and error conditions
102+
- Test names should clearly describe what they test
103+
- Use table-driven tests when testing multiple similar scenarios

0 commit comments

Comments
 (0)